From patchwork Mon Feb 7 15:16:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Adamski X-Patchwork-Id: 12737564 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE92BC433EF for ; Mon, 7 Feb 2022 16:03:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=lHjnvGdxaqBJZQ7nDrP6sfOqRxjzXT0nR9kht9NNVSM=; b=Tflb/OffEgvxWq la28qNczBC9OVVIZHIj2DMwvVOXs4SEx9/tLSUhq4BM/+Mi+MDtqhuMZCMj3nMmyHmw9utJ849zOC 8QnMiLpoaDGmZNh0p5okCC4XJZafyQLF1YxWYsc1tNpLu9Ku2TchV6mX4yDn0s7Jw6RYVt03uEgM2 vx+88uXHZI4tESc+JAVFbU/O2hj2T3gLMR9g+6c8NemY/DLJ6+U1l4CX4wEPwJMWK2ZM4d4VRiM3B +cf4bvuNsXCodq7hYhEMaXbeoVKJNDw2F7liWXTmQIceKwHbgN4fFHpVDUfrFt8tHbyFk0428IEjT kY2UZNLHVwZdsygmG14Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nH6S7-00AvgO-KM; Mon, 07 Feb 2022 16:01:21 +0000 Received: from mail-db8eur05on2121.outbound.protection.outlook.com ([40.107.20.121] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nH5yi-00AjKw-TC for linux-arm-kernel@lists.infradead.org; Mon, 07 Feb 2022 15:30:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bayUOjcoHtK85S8v59ZX66HCrXsLU49XAH6AY9qYuBeVXFXmiLXRWpe921XxuTpHBPNGP0p2DqL6jHBQVYovhvO0P99OwpN4Yy4kTkC88097NlyS5Xuj+ba8bvH8gPacX5bjwEZ2h+8i59cD8fxe5cmwZww6cqNpUmzNAspn1zsMZOfS5WSN9JeaBYpNh7PbmMBV1WD9zHeq8DFbbOM8TiImr+DtmFVjSnXeLvUBpe2wt6MX3+BsHUZ3kBv5xs4ZrtbphTeBW4nouhAU4ETZViXeC1fOkuLJ6RpVQ9ixxNd04Mf1WuDjVa7dfoKNWUTbK3ec3AJONzFbSB/ZEguLuw== 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=FxxUza5IJqoiR3BTA15it9jQlxEd3ohaGe2dqt4Zn/A=; b=FN1kCkge4a5dlHdGRuWbEfuCa2GZQahBmy/fp+nNUOeq/YsGshAx6K3/fe2NaLKEsDEJ91IumfAnEbk086y7JTNrGFcTJUgCRxSP8tN36LmJYwrSIvB3h7x6O/DPMKbON9a7HE9/1VnVCFizSQnt4XlIBg/lfyjcKAUIwO+GVgi4qWMfRFy/gFveIh3s+X413z1Y6ovhJvjKzhxTfsbcKTD4R/4HlKGu4TdHGmucK9oriTgul/Daqi49igErpZIOwan39ho35k+ha7vvDMP7bclELx7mYRFxcV/YthkqewvYlFoM7lM28OxGaQBSjwpIuAfs1ao6ZRvdEg4fOLbz4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FxxUza5IJqoiR3BTA15it9jQlxEd3ohaGe2dqt4Zn/A=; b=C+txKzoKLGAaS1XHXhp89tpDOt8OE8XAUmiIawweiBtbDu3sDn9egRQjcjWassdNjILoMJ9wPN1fwYrvZrVUr3nP8qr0GH7pICMcp9XtUFFKDCWmX8kqw3Hiu92RN/Gj4WNHdsE8duxCwXEJWF5LtGKuEdKxcQCOWfjUrS2LDbw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nokia.com; Received: from AS8PR07MB8104.eurprd07.prod.outlook.com (2603:10a6:20b:373::6) by DB7PR07MB5227.eurprd07.prod.outlook.com (2603:10a6:10:6e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.10; Mon, 7 Feb 2022 15:16:29 +0000 Received: from AS8PR07MB8104.eurprd07.prod.outlook.com ([fe80::add0:5657:466d:4803]) by AS8PR07MB8104.eurprd07.prod.outlook.com ([fe80::add0:5657:466d:4803%8]) with mapi id 15.20.4951.018; Mon, 7 Feb 2022 15:16:23 +0000 Date: Mon, 7 Feb 2022 16:16:18 +0100 From: Krzysztof Adamski To: Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , Guenter Roeck , Wolfram Sang , Ard Biesheuvel Cc: Alexander Sverdlin , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v3] arm64: move efi_reboot to restart handler Message-ID: Content-Disposition: inline X-ClientProxiedBy: HE1PR09CA0080.eurprd09.prod.outlook.com (2603:10a6:7:3d::24) To AS8PR07MB8104.eurprd07.prod.outlook.com (2603:10a6:20b:373::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 97f76af9-a26a-4a42-ca24-08d9ea4ccd43 X-MS-TrafficTypeDiagnostic: DB7PR07MB5227:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hIvGRlwTU4cj39cA5endG8tI2MZ7s95FcoV/QJcvXhBvmnvRIBMNxgQAHGBRKtotqx1uRSgC3DH2VArl0VaN0C01Q9U0LKiMzkiVx6YJd0pLurb9t4Kz34YGHBAd+iQ/4ZbHXVe9J/+uFqzRGWhMiR+Wr7L1W+nmmfPHB5az694EXNvbdsg6XimioEA935k/FuTManF58MuG1zSrgqtSCZzAzQjzzp0woRyv3vGpuRiZsZ0zion8Bd99wlrNB/EKxrVjNtH5sgwCUCMTS7FpnpdDHwJwE1Zj6iFomIRba4GlIjFeXUgYdFQtnlUf1c/Pdw6jLWIIDRQ2S48KSZRpjl2e78ZVYZhavqSklUoR+ynl7/YbAhdZz0yrHsLzU+1NkUTjC8AHULqli5rbN7VFwq+5X+OMz5+6SY94GQW42PlbtvURBk2u0Gf069A4R3/1Je7DPlwBTeN/NYifkQ5R0kVFkH8cr2vHnPX5Y0HwWv0licb3BjkWcwWzZEx8YTsQ90JtEoHxDX1r5HZOm0xj30c89f63xSiyg5QstASPlv+grLty45F97hxQ5FSTECf7vXI+OMHby274cYvHGPfjUeHG3LF5daSATwZNzS78IKZq8mZWBHvgCT1aU7Uve9E0mAeJXF83ioeuKguiGN3rqd78it5o5QTWYS7KE4IYp4L4h2YY30JyaYl7w3VS5BKRDrdh74UxpLKaPoGcAXTjAwbgzjd919BxdrhpmDuV9HY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR07MB8104.eurprd07.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(6512007)(83380400001)(7416002)(9686003)(186003)(26005)(38100700002)(38350700002)(5660300002)(44832011)(6486002)(8936002)(6666004)(4326008)(82960400001)(8676002)(66556008)(6506007)(66476007)(86362001)(66946007)(52116002)(2906002)(110136005)(508600001)(316002)(69594002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: izEmHuRBb32Sgf9pcvGVztFFkcgY8y9NOgZ+Iq9B3/6N9Wt/3OZlLoO6QL4yJZtnJuYt8V21RdltEI0wMdbpiKM8e3Gx1ok5VvatNhi/YbDuduz8+A33c1NXl8QtG+F42JayCDFK3y2WCF2FXCeCm113kB8KJnqJEvnIo+jkVupBM4rwTuYy+/a7UH54SuQt8N3fHOlQLRX3oBUClU3H3SQSiLXXyVyTWB2U5bLI1rxgUrqrsqjKlVutVAhe8oNhtQtV0os+/Fux355ZYmSgOCS46rmcv5puJPg5fTz3ppN/gsY02A1458vD0tlLR7BLCO/FNj5OkVl4yvdb6mD2sxZTVKlzC/fYFEodyk49MfLEckISCpBFS2BN1b2AAiJjQPPOqOB8nKWYh823c+nvur5OzH+f7ik554UOxH/AfupzK7VqWCiG0hVnfQLewGQSnvKNf8R4ies8nwMlEyi3DHLlyK/HYKgMT7R4iHMGdRPyrhktRGb8NnZcy/CwewtBLykMHBjmuQAWb0KMfF21C29yZSON0Hq254NKVGXKsGT22no2gXw6SingLZv5RT2tHstNq0yiRK6i2J529lBalPpuBjZoYzCV83zi/QtrfRnFhs8K0WoFYDO9ipsG3vcHFuMcx165JrG3Ui4oV9sW3UqXAmZa7fn/92/WjMnjbhpvupz4elUmSQy9GR3XW1MkahhatNZ8kRH8htiSew+ZCtZKIggnT3cl/2e2hwFMHCFcJ2zP2cCMmc1xSN5u3jpjBni5TKX428/xSO32KUhUnsab3gjI0OkeIX66W+g0muPb0oNwNVSY56qr7tHe7+06bXBEHGaE0zXAyBWQlS+WAXja9jOdpP8G6Vonjo14+p6y/6R1l237+6+VMn4StDIGqF3XdyZanvtzpS5ulxeC2CuCWBz4LQdCONj/ap0mbvJsveWEfLCeFygaBTDtK45hN1HVuqe8z6l9T6c0Z8KcgmX2pL5noYATtDdv+q7s5CA9ycAr+GIxAy+WGqRT8BkLivJFGHn0oPlYQFRXvd8pFstxa02rTs763V1QeOh8vm93ImWQgTqW6pTTtudyRoJ5KNtKAaKPSR/dU7zd/GX6jcZM3ppN+tyWuVQm+ENHRqyeIe8MxWi5MAfmrMtk9oTy/uMgqWne5RTCkzoCa7/1yh/kvwx0EsW2NqJm8BUiXaToVCG+tCSUzSDiOydmBKBzuHVcJp6eFvFNUrJcNm3JVHnzSP22Zq64YhHVc9pIF9FWu8/2XtIiEUkJIERPd6mM8RBBxsJ+wFblPc7lxfcbwggz82KK3KKR0X0Rp8KdLaIu6xzNtM4SRUiFTXf6JTAMIh1ZpfB1IKivgXWfkUqqTiK0G64h1oBVmYCqlycOwA3cqpvBvQVO8okOE00rRtJHvLRi7ltNUkFTRNOgl3E8ZWaJMHuemJn3R8ToTxpKrrP5xMYqjFwMlk1PIPz5tx4rOCfWcL539sk4Hmqjnj48PnmrW0TPd/JtKiZhkozVPz67BIa0wwm40zwDX7HCo+Vl6Ms4qM5Avg3NnIEvY3juFgMj6nMWBKJWRzFmFvyk8MTZE37uftFYHOcHL0UzdABr6RBw4E6LK8sN3VBjXz4LiWwbMoeHWzr7WUBualqxikG65cLffCHcPDScZBuCEsR32c2Nif8Q/1y9z9/OYCAKLA== X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97f76af9-a26a-4a42-ca24-08d9ea4ccd43 X-MS-Exchange-CrossTenant-AuthSource: AS8PR07MB8104.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 15:16:23.4447 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6rQmAi3eRy5EuVx4tDrmHYYKvMFQOwcpJ81OxXMpjMbeMnAI+KZKEKQZMlUHqC8ki8OHv/OU/+vajxiVVVhL5v570hs5mQBoncupyICnWoM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR07MB5227 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220207_073056_966008_2486E009 X-CRM114-Status: GOOD ( 25.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On EFI enabled arm64 systems, efi_reboot was called before do_kernel_restart, completely omitting the reset_handlers functionality. By registering efi_reboot as part of the chain with elevated priority, we make it run before the default handler but still allow plugging in other handlers. This is useful in two scenarios: - Abusing the restart handler as a notification mechanism similar to reboot notifiers, but working in wider spectrum of cases, (notably also at emergency_restart) and just before reset. This is useful for things like in-kernel pwrseq_emmc, or any other place where it is beneficial for an *external* component to know about the restart, but not performing the reset itself. - Providing higher priority reset handler, where resetting the SoC is not enough, and reset of the whole board should be orchestrated by some external component, that the firmware is not aware of (like an FPGA or some PMIC). This change moves the conditional efi_reboot() call from arm64 specific machine_restart() function to an arm efi initialization code where it is registered as a restart handler with a very high (but not the highest) priority, leaving a small window of opportunity for some code to be run prior to the actual reset, like on other architectures. The restart handlers mechanism is proven to work reliably as we depend on it heavily on other platforms so there is almost no cost for this change but it adds flexibility and unifies our infrastructure with other ports (where one can depend on restart handlers working). Signed-off-by: Krzysztof Adamski --- While previous attempts got mixed feedback, my explanations did not seen counterarguments so I am trying another round: Changes in v3: - Bump the priority much higher, to almost maximal value - Add a comment discouraging from registering higher prio handlers - Update the commit message to contain some more justifications Changes in v2: - Register the handler in EFI code, instead of arm64 setup.c - Remove the contdition from the handler - it should be run in all cases when it is registered - Bump the priority to 130 to make it completly obious this should be run before PSCI (which has priority of 129) arch/arm64/kernel/process.c | 7 ------- drivers/firmware/efi/arm-runtime.c | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 5369e649fa79..b86ef77bb0c8 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -130,13 +130,6 @@ void machine_restart(char *cmd) local_irq_disable(); smp_send_stop(); - /* - * UpdateCapsule() depends on the system being reset via - * ResetSystem(). - */ - if (efi_enabled(EFI_RUNTIME_SERVICES)) - efi_reboot(reboot_mode, NULL); - /* Now call the architecture specific reboot code. */ do_kernel_restart(cmd); diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 3359ae2adf24..b29f47783bbc 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -80,6 +80,28 @@ static bool __init efi_virtmap_init(void) return true; } +static int efi_restart(struct notifier_block *nb, unsigned long action, + void *data) +{ + /* + * UpdateCapsule() depends on the system being reset via + * ResetSystem(). + */ + efi_reboot(reboot_mode, NULL); + + return NOTIFY_DONE; +} + +static struct notifier_block efi_restart_nb = { + .notifier_call = efi_restart, + /** + * If you are running UEFI based system, you most certainly should let + * efi_reboot() do a reset for you. If you think you know better, we + * leave you a window of opportunity here by not using maximal priority. + */ + .priority = 251, +}; + /* * Enable the UEFI Runtime Services if all prerequisites are in place, i.e., * non-early mapping of the UEFI system table and virtual mappings for all @@ -148,6 +170,9 @@ static int __init arm_enable_runtime_services(void) efi_native_runtime_setup(); set_bit(EFI_RUNTIME_SERVICES, &efi.flags); + if (IS_ENABLED(CONFIG_ARM64)) + register_restart_handler(&efi_restart_nb); + return 0; } early_initcall(arm_enable_runtime_services);