linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap
@ 2021-03-05  9:39 Ard Biesheuvel
  2021-03-05  9:39 ` [PATCH 1/1] efi: stub: omit SetVirtualAddressMap() if marked unsupported in RT_PROP table Ard Biesheuvel
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2021-03-05  9:39 UTC (permalink / raw)
  To: linux-efi
  Cc: linux-arm-kernel, Ard Biesheuvel, Jeffrey Hugo, Bjorn Andersson,
	Shawn Guo, Rob Clark, Leif Lindholm, linux-arm-msm

This patch addresses an oversight on my part when I implemented Linux
side support for the EFI RT properties table: SetVirtualAddressMap() is
itself a runtime service which is only callable at runtime to begin with,
and so the EFI stub should only call it if it is not marked as unsupported.

This may be useful for the Snapdragon EFI based laptops, which already rely
on a special EFI driver to expose the correct DT based on metadata exposed
by EFI. These systems ship with a broken implementation of SetVirtualAddressMap,
which is currently being worked around by passing efi=novamap on the kernel.
command line.

After applying this patch (which I intend to propose for backporting to 5.10),
the same can be achieved by exposing a RT_PROP table that marks SetVAMap() as
unsupported. And while at it, better mark the variable services as unsupported
as well, since they don't work under Linux either.

I'm open to extending this with a Linux specific override value kept in a
EFI variable, so that platforms that cannot support DtbLoader are able to
implement something similar.

Cc: Jeffrey Hugo <jhugo@codeaurora.org>,
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: linux-arm-msm@vger.kernel.org

Ard Biesheuvel (1):
  efi: stub: omit SetVirtualAddressMap() if marked unsupported in
    RT_PROP table

 drivers/firmware/efi/libstub/efi-stub.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

-- 
2.30.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] efi: stub: omit SetVirtualAddressMap() if marked unsupported in RT_PROP table
  2021-03-05  9:39 [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap Ard Biesheuvel
@ 2021-03-05  9:39 ` Ard Biesheuvel
  2021-03-06  9:45   ` Shawn Guo
  2021-03-05 11:44 ` [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap Ard Biesheuvel
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2021-03-05  9:39 UTC (permalink / raw)
  To: linux-efi
  Cc: linux-arm-kernel, Ard Biesheuvel, Jeffrey Hugo, Bjorn Andersson,
	Shawn Guo, Rob Clark, Leif Lindholm, linux-arm-msm

The EFI_RT_PROPERTIES_TABLE contains a mask of runtime services that are
available after ExitBootServices(). This mostly does not concern the EFI
stub at all, given that it runs before that. However, there is one call
that is made at runtime, which is the call to SetVirtualAddressMap()
(which is not even callable at boot time to begin with)

So add the missing handling of the RT_PROP table to ensure that we only
call SetVirtualAddressMap() if it is not being advertised as unsupported
by the firmware.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/libstub/efi-stub.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
index ec2f3985bef3..26e69788f27a 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -96,6 +96,18 @@ static void install_memreserve_table(void)
 		efi_err("Failed to install memreserve config table!\n");
 }
 
+static u32 get_supported_rt_services(void)
+{
+	const efi_rt_properties_table_t *rt_prop_table;
+	u32 supported = EFI_RT_SUPPORTED_ALL;
+
+	rt_prop_table = get_efi_config_table(EFI_RT_PROPERTIES_TABLE_GUID);
+	if (rt_prop_table)
+		supported &= rt_prop_table->runtime_services_supported;
+
+	return supported;
+}
+
 /*
  * EFI entry point for the arm/arm64 EFI stubs.  This is the entrypoint
  * that is described in the PE/COFF header.  Most of the code is the same
@@ -250,6 +262,10 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
 			  (prop_tbl->memory_protection_attribute &
 			   EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA);
 
+	/* force efi_novamap if SetVirtualAddressMap() is unsupported */
+	efi_novamap |= !(get_supported_rt_services() &
+			 EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP);
+
 	/* hibernation expects the runtime regions to stay in the same place */
 	if (!IS_ENABLED(CONFIG_HIBERNATION) && !efi_nokaslr && !flat_va_mapping) {
 		/*
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap
  2021-03-05  9:39 [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap Ard Biesheuvel
  2021-03-05  9:39 ` [PATCH 1/1] efi: stub: omit SetVirtualAddressMap() if marked unsupported in RT_PROP table Ard Biesheuvel
@ 2021-03-05 11:44 ` Ard Biesheuvel
  2021-03-06 10:05 ` Shawn Guo
  2021-05-26 19:03 ` patchwork-bot+linux-arm-msm
  3 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2021-03-05 11:44 UTC (permalink / raw)
  To: linux-efi
  Cc: Linux ARM, Jeffrey Hugo, Bjorn Andersson, Shawn Guo, Rob Clark,
	Leif Lindholm, linux-arm-msm

On Fri, 5 Mar 2021 at 10:40, Ard Biesheuvel <ardb@kernel.org> wrote:
>
> This patch addresses an oversight on my part when I implemented Linux
> side support for the EFI RT properties table: SetVirtualAddressMap() is
> itself a runtime service which is only callable at runtime to begin with,
> and so the EFI stub should only call it if it is not marked as unsupported.
>
> This may be useful for the Snapdragon EFI based laptops, which already rely
> on a special EFI driver to expose the correct DT based on metadata exposed
> by EFI. These systems ship with a broken implementation of SetVirtualAddressMap,
> which is currently being worked around by passing efi=novamap on the kernel.
> command line.
>
> After applying this patch (which I intend to propose for backporting to 5.10),
> the same can be achieved by exposing a RT_PROP table that marks SetVAMap() as
> unsupported. And while at it, better mark the variable services as unsupported
> as well, since they don't work under Linux either.
>
> I'm open to extending this with a Linux specific override value kept in a
> EFI variable, so that platforms that cannot support DtbLoader are able to
> implement something similar.
>

... or perhaps even in a DT property that gets AND'ed with the
supported RT services mask bu the EFI stub before it boots the kernel
proper.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] efi: stub: omit SetVirtualAddressMap() if marked unsupported in RT_PROP table
  2021-03-05  9:39 ` [PATCH 1/1] efi: stub: omit SetVirtualAddressMap() if marked unsupported in RT_PROP table Ard Biesheuvel
@ 2021-03-06  9:45   ` Shawn Guo
  0 siblings, 0 replies; 6+ messages in thread
From: Shawn Guo @ 2021-03-06  9:45 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, linux-arm-kernel, Jeffrey Hugo, Bjorn Andersson,
	Rob Clark, Leif Lindholm, linux-arm-msm

On Fri, Mar 05, 2021 at 10:39:58AM +0100, Ard Biesheuvel wrote:
> The EFI_RT_PROPERTIES_TABLE contains a mask of runtime services that are
> available after ExitBootServices(). This mostly does not concern the EFI
> stub at all, given that it runs before that. However, there is one call
> that is made at runtime, which is the call to SetVirtualAddressMap()
> (which is not even callable at boot time to begin with)
> 
> So add the missing handling of the RT_PROP table to ensure that we only
> call SetVirtualAddressMap() if it is not being advertised as unsupported
> by the firmware.
> 
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

On Lenovo Yoga C630 laptop:

Tested-by: Shawn Guo <shawn.guo@linaro.org>

It's a great help to dropping 'efi=novamap' kernel cmdline, which is a
very nice thing for distros to support Snapdragon laptops.

Thanks much, Ard!

Shawn

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap
  2021-03-05  9:39 [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap Ard Biesheuvel
  2021-03-05  9:39 ` [PATCH 1/1] efi: stub: omit SetVirtualAddressMap() if marked unsupported in RT_PROP table Ard Biesheuvel
  2021-03-05 11:44 ` [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap Ard Biesheuvel
@ 2021-03-06 10:05 ` Shawn Guo
  2021-05-26 19:03 ` patchwork-bot+linux-arm-msm
  3 siblings, 0 replies; 6+ messages in thread
From: Shawn Guo @ 2021-03-06 10:05 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, linux-arm-kernel, Jeffrey Hugo, Bjorn Andersson,
	Rob Clark, Leif Lindholm, linux-arm-msm

On Fri, Mar 05, 2021 at 10:39:57AM +0100, Ard Biesheuvel wrote:
> This patch addresses an oversight on my part when I implemented Linux
> side support for the EFI RT properties table: SetVirtualAddressMap() is
> itself a runtime service which is only callable at runtime to begin with,
> and so the EFI stub should only call it if it is not marked as unsupported.
> 
> This may be useful for the Snapdragon EFI based laptops, which already rely
> on a special EFI driver to expose the correct DT based on metadata exposed
> by EFI. These systems ship with a broken implementation of SetVirtualAddressMap,
> which is currently being worked around by passing efi=novamap on the kernel.
> command line.
> 
> After applying this patch (which I intend to propose for backporting to 5.10),
> the same can be achieved by exposing a RT_PROP table that marks SetVAMap() as
> unsupported. And while at it, better mark the variable services as unsupported
> as well, since they don't work under Linux either.
> 
> I'm open to extending this with a Linux specific override value kept in a
> EFI variable, so that platforms that cannot support DtbLoader are able to
> implement something similar.

Yes, that will be much appreciated!  IMHO, this is definitely an useful
addition, as DtbLoader shouldn't be mandated.  In some cases, people may
choose to load DTB with other means, or DTB is not required at all.
Yeah, ACPI kernel is already useful for these laptops, not only for
running installer but also as a console based native arm64 machine.

Looking forward to something for testing :)

Shawn

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap
  2021-03-05  9:39 [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap Ard Biesheuvel
                   ` (2 preceding siblings ...)
  2021-03-06 10:05 ` Shawn Guo
@ 2021-05-26 19:03 ` patchwork-bot+linux-arm-msm
  3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+linux-arm-msm @ 2021-05-26 19:03 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: linux-arm-msm

Hello:

This patch was applied to qcom/linux.git (refs/heads/for-next):

On Fri,  5 Mar 2021 10:39:57 +0100 you wrote:
> This patch addresses an oversight on my part when I implemented Linux
> side support for the EFI RT properties table: SetVirtualAddressMap() is
> itself a runtime service which is only callable at runtime to begin with,
> and so the EFI stub should only call it if it is not marked as unsupported.
> 
> This may be useful for the Snapdragon EFI based laptops, which already rely
> on a special EFI driver to expose the correct DT based on metadata exposed
> by EFI. These systems ship with a broken implementation of SetVirtualAddressMap,
> which is currently being worked around by passing efi=novamap on the kernel.
> command line.
> 
> [...]

Here is the summary with links:
  - [1/1] efi: stub: omit SetVirtualAddressMap() if marked unsupported in RT_PROP table
    https://git.kernel.org/qcom/c/9e9888a0fe97

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-26 19:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05  9:39 [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap Ard Biesheuvel
2021-03-05  9:39 ` [PATCH 1/1] efi: stub: omit SetVirtualAddressMap() if marked unsupported in RT_PROP table Ard Biesheuvel
2021-03-06  9:45   ` Shawn Guo
2021-03-05 11:44 ` [PATCH 0/1] use RT_PROPERTIES table to implement efi=novamap Ard Biesheuvel
2021-03-06 10:05 ` Shawn Guo
2021-05-26 19:03 ` patchwork-bot+linux-arm-msm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).