From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.79]) by mx.groups.io with SMTP id smtpd.web12.4091.1663826871075045611 for ; Wed, 21 Sep 2022 23:07:51 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=u8Fo6oIV; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.93.79, mailfrom: ying-tsun.huang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XzIvtjgS5v3tlt95Ep+IJ9+afNmnRhjU5nJJLD5Suj/tTdyG9TI8E1dwNNLPC5CUk7cEsO/fHYNCyaLFrcPwguSlw96pA267q1V6vZ89nGDO7cExnYXuqP5fcyvugPgj7mMkQBgU+oy2v3ThaMAdo90kbGFY8jK+mlhC6PIKyRz9wqE7FHlB3MeGY904xmBujAMsc3mMmUJ8SySNkCGObpoGUtKAyEReOMJiiKTnoPqEQTHe9XFT/yeJ93JozJ2gnlTlD5TYaqFEa0F+dUlunDb/IDvQobi8xE1pr8jNfN4QFMDB8m88Xu2i/X/D+/qqmVqpGayOVDsKGAXwBLlUFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ynIcS/PPRnH2/Y5hj8TT1Rx9Vq5j0OEbZxmh1k0dslU=; b=mDkUQiS8uQweg6qHtK+txPQXUxvFZwhWrDunTK/NAzA5VjP53Wxu73XTRM9LFkhSJck5eliGUosMcWkkebLm0TUTIhiAgpBTflB5uoi60BmFCYC4QXJAz2u2tLQO0IxSOsWh5MAmrPV7hYNWK0X2rYspnkoyE9BA/0yY2dAj6aWDTulwv/mpQj/K/G6gLyxHYqm1jXuBlJxInC9oCVhY9oUjIfR+ly/oovnDuX19fjpyZM3noVtou4PITccjv/IRQnWqpW+PzdKxXuDtpHwNRYAATRRcp/3zvgQIGbSiRthZeTFo39nnpKCPKuOQPZN+8jiRaSGZEu6uaNJ8LeB93w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ynIcS/PPRnH2/Y5hj8TT1Rx9Vq5j0OEbZxmh1k0dslU=; b=u8Fo6oIVs9VeB2hVqrr/y2b2g2e38hk/qRgIwj0ySR43HRXsrrN30dfaJWEgPQV/yLYFdkLoXJLPY8TJF3j3uJ5oYmEdauDbIcH1XQMXg2q4EhVcJo997V8K3rVedzbfpbLVdqJafnp/GzRvZoNWFI8PMEbe3K+Y1a6Tkshw19c= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN9PR12MB5305.namprd12.prod.outlook.com (2603:10b6:408:102::5) by CO6PR12MB5443.namprd12.prod.outlook.com (2603:10b6:303:13a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.18; Thu, 22 Sep 2022 06:07:49 +0000 Received: from BN9PR12MB5305.namprd12.prod.outlook.com ([fe80::2d3d:180b:df02:3433]) by BN9PR12MB5305.namprd12.prod.outlook.com ([fe80::2d3d:180b:df02:3433%9]) with mapi id 15.20.5654.018; Thu, 22 Sep 2022 06:07:49 +0000 From: "Ying-Tsun Huang" To: devel@edk2.groups.io CC: Jian J Wang , Dandan Bi , Liming Gao Subject: [PATCH v2 1/1] MdeModulePkg/Core: Fix the potential hang of calling SetTimer. Date: Thu, 22 Sep 2022 14:07:13 +0800 Message-ID: <20220922060713.14217-2-ying-tsun.huang@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220922060713.14217-1-ying-tsun.huang@amd.com> References: <20220922060713.14217-1-ying-tsun.huang@amd.com> X-ClientProxiedBy: SG2PR04CA0167.apcprd04.prod.outlook.com (2603:1096:4::29) To BN9PR12MB5305.namprd12.prod.outlook.com (2603:10b6:408:102::5) Return-Path: Ying-Tsun.Huang@amd.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN9PR12MB5305:EE_|CO6PR12MB5443:EE_ X-MS-Office365-Filtering-Correlation-Id: a3fdf27a-ef78-494c-d13a-08da9c60c676 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: epC6bWSKx8PTGD5CRZghKn0lVEYH7Eot4khpYECUZeqtlN4JqPfJ6BVxDRgEBILOD4CvT+zmyECjyc/mUU6EoiKtlaAX0tkXfhDzCIgs7PSZAhl/7/Sz/ihe4jeBhDqep8wfNTQCHQgkQ8h8n5rAVRx/4fy1AhijZE8SkHsrLFt9550Poh6I3TPB6WZjgMDvPkSY/2aEHZz+LfkuDqwbKi7hlKO7uOYPLFghQTUA8alX/MFglb40sXOf8CQGy4RaNlwT5+Sc8F6tSXNXFpRyhUVTpyFlkmoXMQ38Rpi+yN7jsLOu/ONmiNFuNdZts4h99q7gBMWp9g4CKhZGSzt3UQ4/h7QqEkkaWDiyxldTUs6BvLPLYNO/en1UaYHPbBsv4t7XA3BMzT9fJQgTlR0bFLX8vedoipz597EddDikHP1+MZ0+oQUBZf5fr5HPYfMs4TyM2WR/wtEh7Sjs/HPnNRh5DBncKRx+3hB3iHSrpnLsb0N8h1Z25K68MNj/d8WK8dydgTXL+xaVFrS5uL9VZzwaNWsMf0s15Iewpm79ALjdzcpmLpfkjOCzfpRN0SBo77FKxpg2KeQLZzsyzGnhxhxM1FLos03xfskwJDKLKW/S3kujo2po/FUBKhomL7lS/wlY+O06BKruVGXBma8HMx1Bw97cnlUzuLv9thzh9WSczowoVmOtlJ8O1cBQgcndYeHU6us8MLeRMlGcS+PjItsWQP6aVprFHkyoViLpCyv0V7gg4xosVZMEOGUPFJgmJW29aK/O8VicTOhf53sCTQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN9PR12MB5305.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(366004)(346002)(376002)(396003)(39860400002)(451199015)(26005)(6512007)(316002)(36756003)(2616005)(478600001)(6506007)(6666004)(6916009)(54906003)(6486002)(52116002)(186003)(38350700002)(38100700002)(86362001)(1076003)(83380400001)(4326008)(8676002)(66476007)(66556008)(8936002)(5660300002)(2906002)(41300700001)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?FKWLyCErsY1Tc31Xnr/pqb8XvQbLkzKF9hFTDuMSkTg1Qy7mnU/Jxl/jxgTE?= =?us-ascii?Q?CnDZzYcS0f7RXkQ+qWAf3186FOBJlyAlD2vbZJYUEvqaynWxoqyZOYLKKu4S?= =?us-ascii?Q?vuf8Jp08/QSvX9u4fVabrClUNoexiqyGnj5CVV8JQZS7NDsLRjqJHFaIy5iY?= =?us-ascii?Q?N79nyCd9gLxRVIbK0LQ+UUVnTGGpp6/g6Cxs9i1rPSHoWHteVpjJ+vGajI6A?= =?us-ascii?Q?iM+40T1wKXBIwHYwC5KYG1kMgRTpQWazRKzd0XgAlsgewk0aG/og5QTJ+jxK?= =?us-ascii?Q?572yx6ul3CVXrUM+FfKVpMWG8pkay3an8Y1K56yvdpR2zwfv1in64LAZZ8ed?= =?us-ascii?Q?aJYTPLWclU4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pVH2hVsiao?= =?us-ascii?Q?5zhAMUDyfiugtogYUKk/gwRjh6uh4/N2/ePvm39fN+f6VPxspnkOFtb4N+zc?= =?us-ascii?Q?7x8i8oH5ddSfE1/b3coJ8cA1gCc4IgAfwJjc+LIoD7CU5DTidjIhrw0mCWki?= =?us-ascii?Q?BdApQAPXAoKfqUcrAOEb5MZnvWX9k22fPgYntat59WkW7O5IJ/AXPppbgyFY?= =?us-ascii?Q?KI0zTbwxtJJKeoAZGY0T9N2kjJWd0kbsZfoSuafC1WL2VupFw3BXfLjurMVD?= =?us-ascii?Q?4s1aud6Y2+tHvm7Y0JNpCuqzH010ZvQcw+AAEmhR9W0wkSSK5fWL8+ZAlUeJ?= =?us-ascii?Q?c3kNrn93236R+hwo/H0lxNM3FFtYI9+XAvAywnXq?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3fdf27a-ef78-494c-d13a-08da9c60c676 X-MS-Exchange-CrossTenant-AuthSource: BN9PR12MB5305.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2022 06:07:48.9918 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TlH65Z8Pszwpw8ZiJjHH7s/3AtTA3sxhWN5nd6vADFYbgfQ3N6l93gGkzqsG75Gn7Xkq3ODpygcNQfosTTb2KA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5443 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain When calling SetTimer with Type is not TimerCancel and TriggerTime is 0, gTimer is used to get the timer period. However, gTimer is NULL before EFI_TIMER_ARCH_PROTOCOL is installed. Adding the check of gTimer and return EFI_NOT_READY to avoid the hang. Cc: Jian J Wang Cc: Dandan Bi Cc: Liming Gao Signed-off-by: Ying-Tsun Huang --- MdeModulePkg/Core/Dxe/DxeMain.h | 3 +++ MdeModulePkg/Core/Dxe/Event/Timer.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMai= n.h index 815a6b4bd844..182d9c3537ad 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -3,6 +3,7 @@ internal structure and functions used by DxeCore module. =20 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2022, AMD Incorporated. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -1538,6 +1539,8 @@ CoreCreateEventInternal ( @retval EFI_SUCCESS The event has been set to be signaled at = the requested time @retval EFI_INVALID_PARAMETER Event or Type is not valid + @retval EFI_NOT_READY Type is not TimerCancel, TriggerTime is 0= , but + EFI_TIMER_ARCH_PROTOCOL is not installed = yet =20 **/ EFI_STATUS diff --git a/MdeModulePkg/Core/Dxe/Event/Timer.c b/MdeModulePkg/Core/Dxe/Ev= ent/Timer.c index 29e507c67c50..f630cf5dad61 100644 --- a/MdeModulePkg/Core/Dxe/Event/Timer.c +++ b/MdeModulePkg/Core/Dxe/Event/Timer.c @@ -2,6 +2,7 @@ Core Timer Services =20 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2022, AMD Incorporated. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -229,6 +230,8 @@ CoreTimerTick ( @retval EFI_SUCCESS The event has been set to be signaled at = the requested time @retval EFI_INVALID_PARAMETER Event or Type is not valid + @retval EFI_NOT_READY Type is not TimerCancel, TriggerTime is 0= , but + EFI_TIMER_ARCH_PROTOCOL is not installed = yet =20 **/ EFI_STATUS @@ -255,6 +258,16 @@ CoreSetTimer ( return EFI_INVALID_PARAMETER; } =20 + if ((Type !=3D TimerCancel) && (TriggerTime =3D=3D 0)) { + if (gTimer) { + gTimer->GetTimerPeriod (gTimer, &TriggerTime); + } else { + DEBUG ((DEBUG_ERROR, "EFI_TIMER_ARCH_PROTOCOL is not installed. Unab= le to get timer period.\n")); + ASSERT (FALSE); + return EFI_NOT_READY; + } + } + CoreAcquireLock (&mEfiTimerLock); =20 // @@ -270,10 +283,6 @@ CoreSetTimer ( =20 if (Type !=3D TimerCancel) { if (Type =3D=3D TimerPeriodic) { - if (TriggerTime =3D=3D 0) { - gTimer->GetTimerPeriod (gTimer, &TriggerTime); - } - Event->Timer.Period =3D TriggerTime; } =20 --=20 2.25.1