From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=15.233.44.27; helo=g2t2354.austin.hpe.com; envelope-from=sunnywang@hpe.com; receiver=edk2-devel@lists.01.org Received: from g2t2354.austin.hpe.com (g2t2354.austin.hpe.com [15.233.44.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CF4A9209574E3 for ; Mon, 26 Feb 2018 00:50:57 -0800 (PST) Received: from G2W6311.americas.hpqcorp.net (g2w6311.austin.hp.com [16.197.64.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g2t2354.austin.hpe.com (Postfix) with ESMTPS id ADCA3CC; Mon, 26 Feb 2018 08:57:01 +0000 (UTC) Received: from G4W9329.americas.hpqcorp.net (16.208.32.99) by G2W6311.americas.hpqcorp.net (16.197.64.53) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Mon, 26 Feb 2018 08:57:01 +0000 Received: from G4W10204.americas.hpqcorp.net (2002:10cf:5210::10cf:5210) by G4W9329.americas.hpqcorp.net (2002:10d0:2063::10d0:2063) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Mon, 26 Feb 2018 08:56:52 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (15.241.52.11) by G4W10204.americas.hpqcorp.net (16.207.82.16) with Microsoft SMTP Server (TLS) id 15.0.1178.4 via Frontend Transport; Mon, 26 Feb 2018 08:56:52 +0000 Received: from DF4PR8401MB0650.NAMPRD84.PROD.OUTLOOK.COM (10.169.84.148) by DF4PR8401MB1116.NAMPRD84.PROD.OUTLOOK.COM (10.169.92.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.527.15; Mon, 26 Feb 2018 08:56:50 +0000 Received: from DF4PR8401MB0650.NAMPRD84.PROD.OUTLOOK.COM ([fe80::1952:1670:248c:6c]) by DF4PR8401MB0650.NAMPRD84.PROD.OUTLOOK.COM ([fe80::1952:1670:248c:6c%17]) with mapi id 15.20.0527.021; Mon, 26 Feb 2018 08:56:50 +0000 From: "Wang, Sunny (HPS SW)" To: Heyi Guo , "edk2-devel@lists.01.org" CC: Ruiyu Ni , Eric Dong , Star Zeng , "Wang, Sunny (HPS SW)" Thread-Topic: [edk2] [PATCH 1/1] MdeModulePkg/UefiBootManagerLib: limit recursive call depth Thread-Index: AQHTrtwg4UZA42133U6oveLDHmPTPKO2XqbQ Date: Mon, 26 Feb 2018 08:56:50 +0000 Message-ID: References: <1519633779-130687-1-git-send-email-heyi.guo@linaro.org> In-Reply-To: <1519633779-130687-1-git-send-email-heyi.guo@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=sunnywang@hpe.com; x-originating-ip: [16.242.247.135] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DF4PR8401MB1116; 7:DSJ1BKnxj2H1Z9M0+IVMVDS/SayzWd/1BL4ElxVNYzYw8GVDanYNg6SyOoE2Ov6VToXxL73irvdRQFFlikvUCBw25266UYJZWJgD3Pwtq3K4BDDMlXUDueQk0pnOAxjvhUDTxTcDWgBCyy4QQQ4zTBw1BD4swJd8LQwn+A3s1+kE6lpNONPilhT2s15Ct6HHuimo8c4miFPicFQ2UUTHwVz6AFHCPa1g2DcvMg5myBvKChouwiRCdoX1L56wL+M+ x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI; SCL:-1; SFV:NSPM; SFS:(10019020)(396003)(376002)(39860400002)(39380400002)(366004)(346002)(13464003)(199004)(189003)(3846002)(3660700001)(305945005)(6246003)(9686003)(5660300001)(97736004)(2900100001)(74316002)(53936002)(25786009)(6306002)(55016002)(7736002)(4326008)(6436002)(2501003)(105586002)(229853002)(14454004)(5250100002)(2950100002)(76176011)(99286004)(66066001)(33656002)(106356001)(7696005)(54906003)(316002)(110136005)(186003)(3280700002)(68736007)(6116002)(53546011)(86362001)(81156014)(8676002)(8936002)(6506007)(102836004)(478600001)(81166006)(2906002)(26005)(966005)(59450400001); DIR:OUT; SFP:1102; SCL:1; SRVR:DF4PR8401MB1116; H:DF4PR8401MB0650.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 4651c749-8d72-47d7-92d0-08d57cf6e014 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(8989060)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(8990040)(5600026)(4604075)(3008032)(2017052603307)(7153060)(7193020); SRVR:DF4PR8401MB1116; x-ms-traffictypediagnostic: DF4PR8401MB1116: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(162533806227266)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040501)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231220)(944501161)(52105095)(93006095)(93001095)(6055026)(6041288)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:DF4PR8401MB1116; BCL:0; PCL:0; RULEID:; SRVR:DF4PR8401MB1116; x-forefront-prvs: 05954A7C45 received-spf: None (protection.outlook.com: hpe.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Y4k4c9NZBja5DDyZoiwfDnUdYagiX35r8Lvigi7oQ5rSHAJSJWTS8l/XtqcaF375UO8yDypNWkroc1F01CFx1YgZbJPVsh/oNkmDQ8ObA6ul8ygz59FVaEsi2kf01wReZDhk6VfDmTKvUwIe+37MiItJ8nD26BvIVAGuTLv49J8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 4651c749-8d72-47d7-92d0-08d57cf6e014 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Feb 2018 08:56:50.5255 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR8401MB1116 X-OriginatorOrg: hpe.com Subject: Re: [PATCH 1/1] MdeModulePkg/UefiBootManagerLib: limit recursive call depth X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Feb 2018 08:50:58 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Heyi,=20 Just a suggestion.=20 Is it better to use a PCD instead of a define for MAX_RECONNECT_REPAIR? So = that we can easily override it in our platform dsc file. Regards, Sunny Wang -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Heyi= Guo Sent: Monday, February 26, 2018 4:30 PM To: edk2-devel@lists.01.org Cc: Ruiyu Ni ; Heyi Guo ; Eric Don= g ; Star Zeng Subject: [edk2] [PATCH 1/1] MdeModulePkg/UefiBootManagerLib: limit recursiv= e call depth Function BmRepairAllControllers may recursively call itself if some driver = health protocol returns EfiDriverHealthStatusReconnectRequired. However, driver health protocol of some buggy third party driver may always= return such status even after one and another reconnect. The endless itera= tion will cause stack overflow and then system exception, and it may be not= easy to find that the exception is actually caused by stack overflow. So we limit the number of reconnect retry to 10 to improve code robustness. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo Cc: Star Zeng Cc: Eric Dong Cc: Ruiyu Ni --- MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h | 6 ++++++ MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c | 17 ++++++++++++= ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h b/MdeModu= lePkg/Library/UefiBootManagerLib/InternalBm.h index 25a1d522fe84..9aa86b096525 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h +++ b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h @@ -108,6 +108,12 @@ CHAR16 * #define BM_OPTION_NAME_LEN sizeof ("PlatformRecov= ery####") extern CHAR16 *mBmLoadOptionName[]; =20 +// +// Maximum number of reconnect retry to repair controller; it is to=20 +limit the // number of recursive call of BmRepairAllControllers. +// +#define MAX_RECONNECT_REPAIR 10 + /** Visitor function to be called by BmForEachVariable for each variable in variable storage. diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c b/Mde= ModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c index ddcee8b0676f..30d70f32af84 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c @@ -26,6 +26,12 @@ GLOBAL_REMOVE_IF_UNREFERENCED L"Reboot Required" }; =20 +// +// Counter of reconnect retry to repair controller; it is to limit the=20 +// number of recursive call of BmRepairAllControllers. +// +STATIC UINTN mReconnectRepairCount; + /** Return the controller name. =20 @@ -549,7 +555,16 @@ BmRepairAllControllers ( =20 =20 if (ReconnectRequired) { - BmRepairAllControllers (); + if (mReconnectRepairCount < MAX_RECONNECT_REPAIR) { + mReconnectRepairCount++; + BmRepairAllControllers (); + } else { + DEBUG ((DEBUG_ERROR, "[%a:%d] Repair failed after %d retries.\n", + __FUNCTION__, __LINE__, mReconnectRepairCount)); + // Reset counter so that it will not affect calling + // BmRepairAllControllers() somewhere else + mReconnectRepairCount =3D 0; + } } =20 DEBUG_CODE ( -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel