Linux EFI development
 help / color / mirror / Atom feed
From: Jia He <justin.he@arm.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Huacai Chen <chenhuacai@kernel.org>,
	linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Alexandru Elisei <alexandru.elisei@arm.com>,
	Jia He <justin.he@arm.com>
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	[thread overview]
Message-ID: <20230131040355.3116-3-justin.he@arm.com> (raw)
In-Reply-To: <20230131040355.3116-1-justin.he@arm.com>

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 <justin.he@arm.com>
---
 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);
-- 
2.25.1


  parent reply	other threads:[~2023-01-31  4:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-31  4:03 [PATCH 0/2] Fix boot hang issue on Ampere Emag server Jia He
2023-01-31  4:03 ` [PATCH 1/2] efi: libstub: Fix the retriving of supported rutime services Jia He
2023-01-31  7:04   ` Ard Biesheuvel
2023-01-31  4:03 ` Jia He [this message]
2023-01-31  7:06   ` [PATCH 2/2] efi: Introduce efi_get_supported_rt_services() to get the runtime services mask Ard Biesheuvel
2023-01-31  7:18 ` [PATCH 0/2] Fix boot hang issue on Ampere Emag server Ard Biesheuvel
     [not found]   ` <DBBPR08MB45383B479656BA18FEFFB7D5F7D09@DBBPR08MB4538.eurprd08.prod.outlook.com>
2023-01-31 15:31     ` Justin He
2023-01-31 18:23     ` Jason A. Donenfeld
2023-02-02 10:50       ` Justin He
2023-02-07  3:21         ` Justin He
2023-02-07  8:44           ` Ard Biesheuvel
2023-02-07  8:49             ` Justin He
2023-02-07  8:54               ` Ard Biesheuvel
2023-02-07  9:02                 ` Justin He
2023-02-07  9:03                   ` Ard Biesheuvel
2023-02-07  9:08                     ` Justin He
2023-02-07  9:09                       ` Ard Biesheuvel
2023-02-08  3:10                         ` Justin He
2023-01-31 18:03   ` Jason A. Donenfeld
2023-01-31 18:13     ` Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230131040355.3116-3-justin.he@arm.com \
    --to=justin.he@arm.com \
    --cc=alexandru.elisei@arm.com \
    --cc=ardb@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox