From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.52]) by mx.groups.io with SMTP id smtpd.web10.2175.1663728575197990344 for ; Tue, 20 Sep 2022 19:49:35 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=REN9c4im; 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.237.52, mailfrom: ying-tsun.huang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nhzB/7rt81wCUrydkK9MrvN0IQMyod1/Kex8VvRRXT7ZhamMq2lumI/or765FsDyne6vZ0LdT6ynG+Kjqjs0ApGX3L594Q/tCzE9wlBe1SXzLRJLFvzcpljVUk+gjcB7ZY80IfWrWWP3J11J/UUsKVwhG5EVcGzk4f2sCnyPgm0f5cW+jb0OAIn7/zYS2buBZHu4QLzqRcHS4yadavQp+gkOseShc1uL8VQWZcv5tQteEudc9Nc7/V7c605GyssYd5ox1VUz5YGdEiCpZc6wYDDN7mPovmWdLL18Hnrme5+nYCeGMs97dsEVWPrBeOCLlGoz7XuqeS4qdzyWRd1CVw== 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=m4DnFfIMuWmQOpaLIvG0cPuNjyANKj6XNxuzDHeHGgk=; b=LQyoyZ4yxgZ+MqatWnRUUChzEnRZSkp1S8RJqcpZLf34bDupHhBJWiFP5WSXQ4fT1O0nA3LIVSYOzgQI4g9fWr5EKEdaTtfH7ITqm+hsQGhqpyMiGv3EjcqJm9Fw31IUPqOP+d5j9lca2fU/k+qckk0/uIhYnUMhchjFXVsTtGpKPWFNL8Ogls2M+l5qh8JOAYYZwBR7c+vdECKsVviSuwojrzhUJpGdQyPAD6+noPLqN4LO5VEYSKUG4Z0qT7GPOn3plPHa/ng0XtleqUoBntU8nbo72omnokRyH/61KFZQOSc0DvzE4CWRZvHp/Altd5B1M6uMzilL9gZFkN1VYQ== 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=m4DnFfIMuWmQOpaLIvG0cPuNjyANKj6XNxuzDHeHGgk=; b=REN9c4im7L2my/bdX0aSv8WIyaCovzXCDsARA9IVwiWTpRqv5ikKydGBvQ/NwmdX/mjV1Vs2WlHQ3Ijydlq4pTBMwu5fTouepQBgZP2+30Xzx4KekzdoC8AuFNvqUVpUW9qqvosmKAt4oUzCwPSj0XaTAEb8j7iBpJ8BWj/mwJU= 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 MW3PR12MB4460.namprd12.prod.outlook.com (2603:10b6:303:2f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.16; Wed, 21 Sep 2022 02:49:30 +0000 Received: from BN9PR12MB5305.namprd12.prod.outlook.com ([fe80::2d3d:180b:df02:3433]) by BN9PR12MB5305.namprd12.prod.outlook.com ([fe80::2d3d:180b:df02:3433%7]) with mapi id 15.20.5632.021; Wed, 21 Sep 2022 02:49:30 +0000 From: "Ying-Tsun Huang" To: devel@edk2.groups.io CC: Jian J Wang , Dandan Bi , Liming Gao Subject: [PATCH v1 1/1] MdeModulePkg/Core: Fix the potential hang of calling SetTimer. Date: Wed, 21 Sep 2022 10:49:00 +0800 Message-ID: <20220921024900.4179-2-ying-tsun.huang@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220921024900.4179-1-ying-tsun.huang@amd.com> References: <20220921024900.4179-1-ying-tsun.huang@amd.com> X-ClientProxiedBy: SI2PR01CA0033.apcprd01.prod.exchangelabs.com (2603:1096:4:192::23) 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_|MW3PR12MB4460:EE_ X-MS-Office365-Filtering-Correlation-Id: 675f06fd-1683-4362-f122-08da9b7be7c7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wTSLyOhC3u07aAlogDeGg+eVqls+4kwKUyUQ1RazTjOl09FqsEFPzhwFFEXfJ6Bxilk/I/mq6hKbAeyZMBl2AMVIQq84dWM7qecmYu6DeapQULIDVUr0rLw2SEmQ+73sZXZpwsnTtPyaA+9ry7t+0Cm90vxa8cRIOBjTXFygA7Ltbjjc3u6BzlHxmmT2CXAA7ncaE7WknRIksftRdSqV6metHBGoUBXAU1ArCZGnN49aYUS/8kcL4PuO61fPp4lA6BUzINnuSXVdvVulArbnwa2GYT7UARdicNSbTjRVUDk56CSi3TnPFuGsOpKJzLfx9Uf+XyuAdZBPHPE6pMNAVeYS9nLnWTcbXcwC8c0ssT9q5P+QDvHabuHY7DvKI2UpI2IFtsCQv9IycfhA4vo/KOUMyBAEpl3lBX2BSdivyHxAzQOa2Tg96RCCL0YcVxiqK1sfjSKlWRZwttKGbH987dSXwfvSyhiv9zI5wR7ECChskJsg86FC6zvD4feo/NdU2yiPQMIvfe0gPKLwOynN8rCr4mWjXARcw/vKiFDoUwQwGGc4+kW0Vydb3/IKo+WRcaAcWq/l2y5LogPOW2GhKZPvQ6umib7+G2L0sN0Y3d5HOtSflmhRhHJvsYGNuDEzJ0uX7KpQ/CafFX6IIYZmEd/0MtxGnQH9moW1AeijHEjHzTBCjImGLnC7VaADmuNXT+z5Ktn/5T+jT0Vij+n1U/wJkV74prDAjbs2w+DeZnDW1d6aEv8jVlRrN7FPFc+ZORN7nZOasGjb/ne4SX+rTA== 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)(39860400002)(396003)(136003)(366004)(346002)(376002)(451199015)(38350700002)(38100700002)(2906002)(478600001)(6486002)(6916009)(8676002)(8936002)(66946007)(66476007)(66556008)(4326008)(54906003)(316002)(5660300002)(36756003)(26005)(6512007)(6666004)(41300700001)(6506007)(52116002)(83380400001)(2616005)(1076003)(186003)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?bcvN3dTOaNe933uvGrOL+h3Ck8eCboyLzEk/knc6y/A4G3hEH/8HL35FVou8?= =?us-ascii?Q?5HXy4/BUiwwkzLf6N0VX0uDWb54gyoaPLwt9JhRSOb0ar8PBu91k0+3ekH6m?= =?us-ascii?Q?Xim3H91DVd9pI54J4XibLi/kMskwEFh71A5bdaESBVNvoHI59uYaJb3uZ8+/?= =?us-ascii?Q?a+EvEDp8nngNpKyQsR1do4drPMUkZxGO6dEQNTeHoWhoK1IF4LmtdJzcmy6H?= =?us-ascii?Q?1BTjZjTETwfi/nUqK+FMyrk+JrCdXCIf86+oBst6l2B8W+TiVkSmBgWLUcsf?= =?us-ascii?Q?AjfrcfgccEQhDbZey8VuXOpor/cuB/4tTs97YUZ/ikvLSiL908jUp+hOHS04?= =?us-ascii?Q?RIy6sQfgbubOcqI04G5VrSvMJgWG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?us-ascii?Q?8AV/jLNPWPNPe1L/FQdGHk1jnyw7B/4ZId3tOvf6mZGs8qUp4u6HRHSxxt2D?= =?us-ascii?Q?6OFaS2vjdeQPfTE/qoQU1qlXD1jplFpqzpGnnYHaF6TWo4AjelxiceZSp/r1?= =?us-ascii?Q?GBs9IHkY9gnlEtJOESj0ptWbN9vd8DwwFZzCgbsTD2Hn8Tn2Fq20ec72kozM?= =?us-ascii?Q?Qb/G9uirULjjfgY22PLoundy69wAv0Gbe80iptrgM3s7Dj1Zduc9eKTtUD0T?= =?us-ascii?Q?tWte3y294ZlQ4rSijcfZdLnooeaUFqkThdPwBZ3ZLRGFsck1GHyULYTs4tJC?= =?us-ascii?Q?xAfzo5KBzDEV0f/R68YFCXwpBk3PNgEfWM6F6wdC?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 675f06fd-1683-4362-f122-08da9b7be7c7 X-MS-Exchange-CrossTenant-AuthSource: BN9PR12MB5305.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2022 02:49:30.1877 (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: eI/fNeyAjmmyO0pcEj2BUJDu4vHE/zovPuNBPiX+gM7/Qx3fvAIpeIveya2LoqYNwAYMdrrnUHO5GqiZT1m56Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4460 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 | 2 ++ MdeModulePkg/Core/Dxe/Event/Timer.c | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMai= n.h index 815a6b4bd844..acf0b244aeda 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -1538,6 +1538,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..1621814ef3c5 100644 --- a/MdeModulePkg/Core/Dxe/Event/Timer.c +++ b/MdeModulePkg/Core/Dxe/Event/Timer.c @@ -229,6 +229,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 +257,14 @@ CoreSetTimer ( return EFI_INVALID_PARAMETER; } =20 + if ((Type !=3D TimerCancel) && (TriggerTime =3D=3D 0)) { + if (gTimer) { + gTimer->GetTimerPeriod (gTimer, &TriggerTime); + } else { + return EFI_NOT_READY; + } + } + CoreAcquireLock (&mEfiTimerLock); =20 // @@ -270,10 +280,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