From patchwork Tue Jan 31 04:03:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin He X-Patchwork-Id: 50585 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2552751wrn; Mon, 30 Jan 2023 20:28:43 -0800 (PST) X-Google-Smtp-Source: AK7set/Z2YemM4F02qO8AWykvrukuucFoTGpr5Ep19THmoLtgWosKoztLU1IMj+zlACWChResLHU X-Received: by 2002:a62:a515:0:b0:593:e6d9:d4c0 with SMTP id v21-20020a62a515000000b00593e6d9d4c0mr2039938pfm.32.1675139323452; Mon, 30 Jan 2023 20:28:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675139323; cv=none; d=google.com; s=arc-20160816; b=SUmKLoaymg+RFi07xYx+fbcRB9LVXFZ1OUtzBzQquAwk3RgK/ym3Z4vRbKQy3697dn qWwDxgpwiWqNxl726u3EfFrkiCzrPBvEXZEqB+o+vF53DCimtvqd3JCIMGg3dVV94E3s TIhiuSAI3l8rmy/5S1QyT/mFWL9XBAFbR+zBR5MQXAWibOe0OCj9FUwn5R4P3Hbr07I3 Q3C/pHoFNvQPRAIPjHOYeVzmm3y5wiTMadIfQrGb6eDP7H2pdfapY20nJ2ZviDOvqP3y orWhy6diYTWLzzNP8S+mPcMeldnNpl5cUwzLowS82RvecvxkfiKiI6Utpr+UWua/RU9j EPuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PZv7Fgis4FYUVVv9uHAOg2JhEcCtaIMt3xECCmMaXRU=; b=lbsO/UH5DN57Q5DY2+/KjsvrEaBOk7sLP8rxhv5I5Pioq+72vy+V1aU3w6fSiYzeS2 yUJanhL9ThZgMogBjtGgb0Qcq0g/y55hHZM8i7v1vQSl4uzhFW0p1hYUMnxRbSpPNpQj 3pkewNfvbNDm1hyNsO8m3kZcUOFIDDFZIrbWLahQu1fmrFFNqVk9CStWRWD0mjeFUal5 NoStFhjj/nJX3bwfxGt4CCnteyUQXsiu71SM1jDirYObuPb3teFZImC8Bhxak5fUfnwj R97oisKJZH3a1WQwoWulNP60+UwY9KOnSEEBVPEZqZz+GzRAl6l0OzZunFBlg+Ca1pQr uLvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a056a00138800b0050d80e4935fsi17570238pfg.256.2023.01.30.20.28.30; Mon, 30 Jan 2023 20:28:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230433AbjAaEEJ (ORCPT + 99 others); Mon, 30 Jan 2023 23:04:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230267AbjAaEEI (ORCPT ); Mon, 30 Jan 2023 23:04:08 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C5F44113CB; Mon, 30 Jan 2023 20:04:07 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9D0AC1713; Mon, 30 Jan 2023 20:04:49 -0800 (PST) Received: from entos-ampere-02.shanghai.arm.com (entos-ampere-02.shanghai.arm.com [10.169.214.132]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 648883F64C; Mon, 30 Jan 2023 20:04:05 -0800 (PST) From: Jia He To: Ard Biesheuvel Cc: Huacai Chen , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandru Elisei , Jia He Subject: [PATCH 1/2] efi: libstub: Fix the retriving of supported rutime services Date: Tue, 31 Jan 2023 04:03:54 +0000 Message-Id: <20230131040355.3116-2-justin.he@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230131040355.3116-1-justin.he@arm.com> References: <20230131040355.3116-1-justin.he@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756510891386684013?= X-GMAIL-MSGID: =?utf-8?q?1756510891386684013?= If retrieving UEFI configuration table is failed, the supported runtime services mask should be regarded as 0 instead of EFI_RT_SUPPORTED_ALL. Otherwise efi_novamap might be incorrectly assigned to "false" on the Ampere Emag server. Signed-off-by: Jia He --- drivers/firmware/efi/libstub/efi-stub.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index 2955c1ac6a36..f24b5436729c 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -111,6 +111,8 @@ static u32 get_supported_rt_services(void) rt_prop_table = get_efi_config_table(EFI_RT_PROPERTIES_TABLE_GUID); if (rt_prop_table) supported &= rt_prop_table->runtime_services_supported; + else + supported = 0; return supported; } From patchwork Tue Jan 31 04:03:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin He X-Patchwork-Id: 50586 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2552917wrn; Mon, 30 Jan 2023 20:29:16 -0800 (PST) X-Google-Smtp-Source: AK7set9VwIjPgcMviEWVOMm0cXIjD8TDEREzVp0GO/NI4GlswjaSZPOasCdn4WgaFoXilgPq2qyZ X-Received: by 2002:a17:90b:1b0b:b0:22c:94a7:c48a with SMTP id nu11-20020a17090b1b0b00b0022c94a7c48amr7571920pjb.31.1675139356562; Mon, 30 Jan 2023 20:29:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675139356; cv=none; d=google.com; s=arc-20160816; b=g2oSqS44Yb3tihq+0dE0D4phk7tmJUbPl9Wko5JKepxZ2pz/v7HaNZlaY1CkrhHNRS MBufme6fkLmXxnYkx4KvfA699u2jg4VgJX51BS/gLIsyITEyz9dZx+fjjDj/4gkcHOVe 36GioqSHjz5xtewoC/tjkZqIiXTER19IQK5JwfgXl5HeW603Z+bP7E/1SqIS9F8CWKaf /GdPkdoE58ZU/iFxreX/EukYjsy1+PZd+956PqEdAJ/m6H5pHJGprqZtJipqZF47UUlB lBHK8X0DuarTdeJqLiQ4iEh9t3c3N3wS6QTwzWtMFtoWPe5Ct/JyTGJghBZynk7NhAfb tcIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=MMlEzAQM3jyt6sElFx3M6HRd+L3BszmYBDe0TNirrkM=; b=wcYVrQ8YBkzuaA+wQ0UTs6VSNvj9DZMUwudid2UGv55Lo2A2uJIyhulehffsR7Or4D X9BDwl92259sO85qhIpKpYoD0txQx5UQA4kl5nlfsrbuz7F7T5YRLaCXZMk2qVKJ+P6b hSmmEJD1a0bJwKtWTaq2lNlH8hO48XMlm0ivvRzvQsb/tXrr2Zi9/D290Y6UGetXY/KZ CEzqq8IuwEv7LrW0G6Zmwm52XuMMAe8pBp6/9Ib192KFHdvYIMmiVf0a6s5rkg1hoYT2 6m7Wvl6WiJAV44cclD2zqOmQvlIJOEVhna//IqsNGd2A13YaRHHsy8/8jYoekaFeyWFX tyAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jx13-20020a17090b46cd00b0022bfcb7ba8dsi18834528pjb.21.2023.01.30.20.29.04; Mon, 30 Jan 2023 20:29:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbjAaEEO (ORCPT + 99 others); Mon, 30 Jan 2023 23:04:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbjAaEEL (ORCPT ); Mon, 30 Jan 2023 23:04:11 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 830573801E; Mon, 30 Jan 2023 20:04:10 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 503882F4; Mon, 30 Jan 2023 20:04:52 -0800 (PST) Received: from entos-ampere-02.shanghai.arm.com (entos-ampere-02.shanghai.arm.com [10.169.214.132]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 206E83F64C; Mon, 30 Jan 2023 20:04:07 -0800 (PST) From: Jia He To: Ard Biesheuvel Cc: Huacai Chen , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandru Elisei , Jia He Subject: [PATCH 2/2] efi: Introduce efi_get_supported_rt_services() to get the runtime services mask Date: Tue, 31 Jan 2023 04:03:55 +0000 Message-Id: <20230131040355.3116-3-justin.he@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230131040355.3116-1-justin.he@arm.com> References: <20230131040355.3116-1-justin.he@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756510925946990004?= X-GMAIL-MSGID: =?utf-8?q?1756510925946990004?= Previously, efi.runtime_supported_mask will always be the initial value EFI_RT_SUPPORTED_ALL and can't be retrieved in efi_config_parse_tables() if rt_prop is EFI_INVALID_TABLE_ADDR. Thus this can cause the wrong return value of efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE) on the Ampere Emag server. Besides, abstract the runtime services retrieving into a new exported helper efi_get_supported_rt_services() to set or clear the runtime service bit of efi.flags. Signed-off-by: Jia He --- drivers/firmware/efi/arm-runtime.c | 5 ++++- drivers/firmware/efi/efi.c | 28 +++++++++++++++++++--------- include/linux/efi.h | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 83f5bb57fa4c..ce93133f9abc 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -146,7 +146,10 @@ static int __init arm_enable_runtime_services(void) /* Set up runtime services function pointers */ efi_native_runtime_setup(); - set_bit(EFI_RUNTIME_SERVICES, &efi.flags); + if (efi_get_supported_rt_services()) + set_bit(EFI_RUNTIME_SERVICES, &efi.flags); + else + clear_bit(EFI_RUNTIME_SERVICES, &efi.flags); return 0; } diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index a2b0cbc8741c..96475cb8088e 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -595,6 +595,24 @@ static __init int match_config_table(const efi_guid_t *guid, return 0; } +unsigned int __init efi_get_supported_rt_services(void) +{ + unsigned int runtime_supported_mask = EFI_RT_SUPPORTED_ALL; + + if (rt_prop != EFI_INVALID_TABLE_ADDR) { + efi_rt_properties_table_t *tbl; + + tbl = early_memremap(rt_prop, sizeof(*tbl)); + if (tbl) { + runtime_supported_mask &= tbl->runtime_services_supported; + early_memunmap(tbl, sizeof(*tbl)); + } + } else + runtime_supported_mask = 0; + + return runtime_supported_mask; +} + int __init efi_config_parse_tables(const efi_config_table_t *config_tables, int count, const efi_config_table_type_t *arch_tables) @@ -695,15 +713,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables, } } - if (rt_prop != EFI_INVALID_TABLE_ADDR) { - efi_rt_properties_table_t *tbl; - - tbl = early_memremap(rt_prop, sizeof(*tbl)); - if (tbl) { - efi.runtime_supported_mask &= tbl->runtime_services_supported; - early_memunmap(tbl, sizeof(*tbl)); - } - } + efi.runtime_supported_mask &= efi_get_supported_rt_services(); if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && initrd != EFI_INVALID_TABLE_ADDR && phys_initrd_size == 0) { diff --git a/include/linux/efi.h b/include/linux/efi.h index 4b27519143f5..fcaf0d7fc07e 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -717,6 +717,7 @@ extern void __init efi_esrt_init(void); #else static inline void efi_esrt_init(void) { } #endif +extern unsigned int efi_get_supported_rt_services(void); extern int efi_config_parse_tables(const efi_config_table_t *config_tables, int count, const efi_config_table_type_t *arch_tables);