Skip to contentSkip to conversation

efi: Always map EfiRuntimeServicesCode and EfiRuntimeServicesData

PATCH Superseded Sergey Temerkhanov 2 participants 4 messages Sep 3, 2020 – Sep 7, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: Always map EfiRuntimeServicesCode and EfiRuntimeServicesData

This helps overcome problems observed with some UEFI implementations which don't set the Attributes field in memery descriptors properly

---
 xen/common/efi/boot.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
xen/common/efi/boot.c +3 -1
index 5a520bf21d..4644ce2525 100644
@@ -1521,7 +1521,9 @@ void __init efi_init_memory(void)
         }
 
         if ( !efi_enabled(EFI_RS) ||
-             (!(desc->Attribute & EFI_MEMORY_RUNTIME) &&
+             ((!(desc->Attribute & EFI_MEMORY_RUNTIME) &&
+                (desc->Type != EfiRuntimeServicesCode &&
+                 desc->Type != EfiRuntimeServicesData)) &&
               (!map_bs ||
                (desc->Type != EfiBootServicesCode &&
                 desc->Type != EfiBootServicesData))) )
Signature · 1 line
2.26.2
#1 lore raw

xen/common/efi/boot.c void __init efi_init_memory(void)

Quoted 3 lines · Sergey Temerkhanov
xen/common/efi/boot.c +0 -0
@@ -1521,7 +1521,9 @@ void __init efi_init_memory(void)

Looking at the line numbers - is this patch against the master or staging branch? I ask because about as far away from the line number above as the chunk of cose you mean to change there's a very similar conditional, which has caused some slight confusion over here.

xen/common/efi/boot.c void __init efi_init_memory(void) · line 1529

Quoted 10 lines
xen/common/efi/boot.c +3 -1
         }
 
         if ( !efi_enabled(EFI_RS) ||
-             (!(desc->Attribute & EFI_MEMORY_RUNTIME) &&
+             ((!(desc->Attribute & EFI_MEMORY_RUNTIME) &&
+                (desc->Type != EfiRuntimeServicesCode &&
+                 desc->Type != EfiRuntimeServicesData)) &&
               (!map_bs ||
                (desc->Type != EfiBootServicesCode &&
                 desc->Type != EfiBootServicesData))) )

I'm in principle okay with a workaround like this, but I don't think it should go silently. I'd therefore like to suggest you add a new if() ahead of this one and then set EFI_MEMORY_RUNTIME in affected descriptors (to keep things consistent with other consumers of the memory map without having to update every one of those checking for the flag) alongside issuing a log message.

There's nevertheless another piece of code you need to adjust, inside a CONFIG_EFI_SET_VIRTUAL_ADDRESS_MAP conditional in efi_exit_boot(). But you shouldn't adjust the descriptor there, yet - this should happen only after its logging in efi_init_memory().

Additionally I'd like it to be at least considered to also check that EFI_MEMORY_WB (or at the very least one of the cachability flags) is set, so that we won't run into the path further down complaining about a lack thereof in this case.

Jan

#2 lore raw
Quoted 11 lines · Jan Beulich

xen/common/efi/boot.c void __init efi_init_memory(void)

Quoted 3 lines · Sergey Temerkhanov
xen/common/efi/boot.c +0 -0
@@ -1521,7 +1521,9 @@ void __init efi_init_memory(void)

Looking at the line numbers - is this patch against the master or staging branch? I ask because about as far away from the line number above as the chunk of cose you mean to change there's a very similar conditional, which has caused some slight confusion over here.

it was the latest tag, AFAIR.

Quoted 26 lines

xen/common/efi/boot.c void __init efi_init_memory(void) · line 1529

Quoted 11 lines
xen/common/efi/boot.c +3 -1
         }
 
         if ( !efi_enabled(EFI_RS) ||
-             (!(desc->Attribute & EFI_MEMORY_RUNTIME) &&
+             ((!(desc->Attribute & EFI_MEMORY_RUNTIME) &&
+                (desc->Type != EfiRuntimeServicesCode &&
+                 desc->Type != EfiRuntimeServicesData)) &&
               (!map_bs ||
                (desc->Type != EfiBootServicesCode &&
                 desc->Type != EfiBootServicesData))) )

I'm in principle okay with a workaround like this, but I don't think it should go silently. I'd therefore like to suggest you add a new if() ahead of this one and then set EFI_MEMORY_RUNTIME in affected descriptors (to keep things consistent with other consumers of the memory map without having to update every one of those checking for the flag) alongside issuing a log message.

There's nevertheless another piece of code you need to adjust, inside a CONFIG_EFI_SET_VIRTUAL_ADDRESS_MAP conditional in efi_exit_boot(). But you shouldn't adjust the descriptor there, yet - this should happen only after its logging in efi_init_memory().

Quoted 5 lines

Additionally I'd like it to be at least considered to also check that EFI_MEMORY_WB (or at the very least one of the cachability flags) is set, so that we won't run into the path further down complaining about a lack thereof in this case.

Makes sense. I'm making it set the UC for data and WP for code as the most conservative option in such a case.

Quoted 2 lines

Jan

#3 lore raw
Quoted 13 lines · Sergei Temerkhanov
Quoted 11 lines · Jan Beulich

xen/common/efi/boot.c void __init efi_init_memory(void)

Quoted 3 lines · Sergey Temerkhanov
xen/common/efi/boot.c +0 -0
@@ -1521,7 +1521,9 @@ void __init efi_init_memory(void)

Looking at the line numbers - is this patch against the master or staging branch? I ask because about as far away from the line number above as the chunk of cose you mean to change there's a very similar conditional, which has caused some slight confusion over here.

Quoted 1 line

it was the latest tag, AFAIR.

That's definitely not sufficient for a patch submission, or - if you absolutely can't work with master / staging for some reason - should be explicitly pointed out in the submission.

Quoted 26 lines
Quoted 26 lines

xen/common/efi/boot.c void __init efi_init_memory(void) · line 1529

Quoted 11 lines
xen/common/efi/boot.c +3 -1
         }
 
         if ( !efi_enabled(EFI_RS) ||
-             (!(desc->Attribute & EFI_MEMORY_RUNTIME) &&
+             ((!(desc->Attribute & EFI_MEMORY_RUNTIME) &&
+                (desc->Type != EfiRuntimeServicesCode &&
+                 desc->Type != EfiRuntimeServicesData)) &&
               (!map_bs ||
                (desc->Type != EfiBootServicesCode &&
                 desc->Type != EfiBootServicesData))) )

I'm in principle okay with a workaround like this, but I don't think it should go silently. I'd therefore like to suggest you add a new if() ahead of this one and then set EFI_MEMORY_RUNTIME in affected descriptors (to keep things consistent with other consumers of the memory map without having to update every one of those checking for the flag) alongside issuing a log message.

There's nevertheless another piece of code you need to adjust, inside a CONFIG_EFI_SET_VIRTUAL_ADDRESS_MAP conditional in efi_exit_boot(). But you shouldn't adjust the descriptor there, yet - this should happen only after its logging in efi_init_memory().

Quoted 8 lines
Quoted 5 lines

Additionally I'd like it to be at least considered to also check that EFI_MEMORY_WB (or at the very least one of the cachability flags) is set, so that we won't run into the path further down complaining about a lack thereof in this case.

Makes sense. I'm making it set the UC for data and WP for code as the most conservative option in such a case.

Please don't: I intentionally said "check", not "correct". Unless of course you have proof of both aspects being got wrong on a single piece of firmware at the same time.

Jan