From patchwork Mon Feb 26 08:29:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 129606 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3361828lja; Mon, 26 Feb 2018 00:30:38 -0800 (PST) X-Google-Smtp-Source: AH8x224GVJqxcItEufoP59vgcuk96Z2jOH4sJ1QWpJykj1KHeUjetDozKSthKPnAQahxZsRMmM+a X-Received: by 2002:a17:902:bd83:: with SMTP id q3-v6mr10195202pls.13.1519633838182; Mon, 26 Feb 2018 00:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633838; cv=none; d=google.com; s=arc-20160816; b=EsHQAGNNTLTzALvLS4pVIhv6AMTYQZ4odTuRk0zCyIikrfcKMypCI79NySkOi43oLZ BqVtXSUTISQQMVBlwM9/FQwjUOZTCLHO3hsFRqL+QFLnOVVrr80q3HJUByHcToNNOHkq 8AF3U/iUnkXnZS4L1Gie5dCwb/5W7vSepq0in3TjC8hyad3+he5qiNT17YcvDWycRX5C HYll/uCYlIKpfxRDpjleLjoIf5dmMkLQM8Bq9mz/slej/4NB59sqlQ5vRZUrbBHtAeJ4 hUGHXO9QjuWVGbNVw6ba5QasLIsY3IAWwnJYq6WaZ3F5/tWwe7mmHtRAHJY5R4Hab278 kfQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=QxrQhd6gSmnUOiU54RESM2cnM/tPIJhDWNUrlDgJUS8=; b=XFZflwHipSWiU6u+rwefuB3On3oWK/LhOdh3DejUjj5Z7GE7NfAUX1lnkek/B/Xcl1 Lzb33qEqNcabjcrGy5fC9wqYsDxCW0FxHLl8vFq5ZL0GE6kYUjeH3tYHU6Dc5kL08HKj 3DE3bIv5e/YYxjrxMO2Ac7tVMdZRIU2DX90RiSNwoQ4SZG2vpkwdmduTPaVZMXfYCdmc HnKfQn/vnzv/PT/xHcsZcxEVdJllJ1pSfBqmpgorDwf9iOTG2z3B85tqVO33Ny4BOurP WXo9U38ZexfJz63QGn7QqEWNWpNap6OX1dwbtrOTEuo31Unm1FkI23wes3TbdB2wxr8m Lm8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=C8Hl5tGD; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id k14si5118203pgt.32.2018.02.26.00.30.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 00:30:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=C8Hl5tGD; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 50674209574D7; Mon, 26 Feb 2018 00:24:32 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c05::241; helo=mail-pg0-x241.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg0-x241.google.com (mail-pg0-x241.google.com [IPv6:2607:f8b0:400e:c05::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E8E44209574C0 for ; Mon, 26 Feb 2018 00:24:30 -0800 (PST) Received: by mail-pg0-x241.google.com with SMTP id g12so5916882pgs.0 for ; Mon, 26 Feb 2018 00:30:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=4dfEogB+auFTfI/5z0bw1T3IblVEJ8801hxh98S1+Sk=; b=C8Hl5tGD6n0Enb21mf7jQ9ZXOp0mhMKWVU4sCMj6K5SNf8L+vsv3NVYIoIDOFbQsW6 t4bxH6x2p1/slJkxMe5609Z7EpmGdtHAY6O7h+hsaxINZT0KiuUoLJZzIHCs9I4Qe5Oj pVQG+LRil4Fd96butETJP/99avqWKIohrCiDM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4dfEogB+auFTfI/5z0bw1T3IblVEJ8801hxh98S1+Sk=; b=pjDjYTwV7cP/8oSROPckkAkftK028FRzlhy8JUvpRy0uEU6Y1IPVL728AaHPPClIm2 MMGbAZA4hc5vIc5R63tLcZQCkNbmKN8UP2JExoDvn66bvzDZ/sh+xDosqiIWe5OagTuK S2GkrKjlcI96JBIxOC06o/AtGLlxldyradbAJI0RioJ4tLOhgLlWItcoALI6fc3nrDpd h4PB2BYdmk7R3A56P/AMmssmzo8Swt/XOUxHYQud5xiuJVofs267eyfv9Xzh02Q/KVad zicHpU71PzLUOAx3mOgCJ++1cYkVCSjvpX6TYiQjDdvdga/FXu6mni8PL6Y2uuRBPPyb RUZA== X-Gm-Message-State: APf1xPABw40otSN9lRP9ltWbbePlIOwl5Ca3ph0DRAR/mgvX437kL0+R GQZVS5FZHAPPijZNxgerltW6ckMcJAU= X-Received: by 10.101.97.139 with SMTP id c11mr7816389pgv.443.1519633835207; Mon, 26 Feb 2018 00:30:35 -0800 (PST) Received: from localhost.localdomain ([104.237.91.49]) by smtp.gmail.com with ESMTPSA id r78sm17723145pfb.24.2018.02.26.00.30.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:30:34 -0800 (PST) From: Heyi Guo To: edk2-devel@lists.01.org Date: Mon, 26 Feb 2018 16:29:39 +0800 Message-Id: <1519633779-130687-1-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [edk2] [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: , Cc: Ruiyu Ni , Heyi Guo , Eric Dong , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 iteration 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(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Signed-off-by: Heyi Guo diff --git a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h b/MdeModulePkg/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 ("PlatformRecovery####") extern CHAR16 *mBmLoadOptionName[]; +// +// Maximum number of reconnect retry to repair controller; it is to 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/MdeModulePkg/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" }; +// +// Counter of reconnect retry to repair controller; it is to limit the +// number of recursive call of BmRepairAllControllers. +// +STATIC UINTN mReconnectRepairCount; + /** Return the controller name. @@ -549,7 +555,16 @@ BmRepairAllControllers ( 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 = 0; + } } DEBUG_CODE (