EFI 1:1 mapping
Borislav Petkov
maintainercover EFI 1:1 mapping
From: Borislav Petkov <[email protected]>
Hi all,
this one is 64-bit only for now and it has been tested only in kvm with OVMF.
Keeping in mind the ihnerent efi b0rkedness left and right, I'd like to be very cautious and conservative with this and not hurry anything until it has been actually very well tested on a variety of baremetal boxes.
Please take a closer look and let me know.
Thanks.
Borislav Petkov (4):
efi: Convert runtime services function ptrs x86, cpa: Map in an arbitrary pgd
x86, efi: Add an efi= kernel command line parameter x86, efi: Map runtime services 1:1
arch/x86/boot/compressed/eboot.c | 2 +- arch/x86/include/asm/efi.h | 30 +++--- arch/x86/include/asm/pgtable_types.h | 3 +- arch/x86/mm/pageattr.c | 80 ++++++++++++---- arch/x86/platform/efi/efi.c | 177 +++++++++++++++++++++++++++++------ arch/x86/platform/efi/efi_stub_64.S | 48 ++++++++++ include/linux/efi.h | 28 +++--- 7 files changed, 290 insertions(+), 78 deletions(-)
Signature · 1 line
1.8.3.rc1.25.g423ecb0
Borislav Petkov
maintainerPATCH 1/4 efi: Convert runtime services function ptrs
From: Borislav Petkov <[email protected]>
... to void * like the boot services and lose all the void * casts. No functionality change.
--- arch/x86/boot/compressed/eboot.c | 2 +- arch/x86/include/asm/efi.h | 28 ++++++++++++++-------------- include/linux/efi.h | 28 ++++++++++++++-------------- 3 files changed, 29 insertions(+), 29 deletions(-)
arch/x86/boot/compressed/eboot.c +1 -1
@@ -266,7 +266,7 @@ static efi_status_t setup_efi_vars(struct boot_params *params)while (data && data->next) data = (struct setup_data *)(unsigned long )data->next; - status = efi_call_phys4((void *)sys_table->runtime->query_variable_info, + status = efi_call_phys4(sys_table->runtime->query_variable_info, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, &store_size,
arch/x86/include/asm/efi.h +14 -14
@@ -52,40 +52,40 @@ extern u64 efi_call6(void *fp, u64 arg1, u64 arg2, u64 arg3, u64 arg4, u64 arg5, u64 arg6);#define efi_call_phys0 (f) \ - efi_call0((void *)(f)) + efi_call0((f))#define efi_call_phys1 (f, a1) \ - efi_call1((void *)(f), (u64)(a1)) + efi_call1((f), (u64)(a1))#define efi_call_phys2 (f, a1, a2) \ - efi_call2((void *)(f), (u64)(a1), (u64)(a2)) + efi_call2((f), (u64)(a1), (u64)(a2))#define efi_call_phys3 (f, a1, a2, a3) \ - efi_call3((void *)(f), (u64)(a1), (u64)(a2), (u64)(a3)) + efi_call3((f), (u64)(a1), (u64)(a2), (u64)(a3))#define efi_call_phys4 (f, a1, a2, a3, a4) \ - efi_call4((void *)(f), (u64)(a1), (u64)(a2), (u64)(a3), \ + efi_call4((f), (u64)(a1), (u64)(a2), (u64)(a3), \ (u64)(a4))#define efi_call_phys5 (f, a1, a2, a3, a4, a5) \ - efi_call5((void *)(f), (u64)(a1), (u64)(a2), (u64)(a3), \ + efi_call5((f), (u64)(a1), (u64)(a2), (u64)(a3), \ (u64)(a4), (u64)(a5))#define efi_call_phys6 (f, a1, a2, a3, a4, a5, a6) \ - efi_call6((void *)(f), (u64)(a1), (u64)(a2), (u64)(a3), \ + efi_call6((f), (u64)(a1), (u64)(a2), (u64)(a3), \ (u64)(a4), (u64)(a5), (u64)(a6))#define efi_call_virt0 (f) \ - efi_call0((void *)(efi.systab->runtime->f)) + efi_call0((efi.systab->runtime->f))#define efi_call_virt1 (f, a1) \ - efi_call1((void *)(efi.systab->runtime->f), (u64)(a1)) + efi_call1((efi.systab->runtime->f), (u64)(a1))#define efi_call_virt2 (f, a1, a2) \ - efi_call2((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2)) + efi_call2((efi.systab->runtime->f), (u64)(a1), (u64)(a2))#define efi_call_virt3 (f, a1, a2, a3) \ - efi_call3((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ + efi_call3((efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ (u64)(a3))#define efi_call_virt4 (f, a1, a2, a3, a4) \ - efi_call4((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ + efi_call4((efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ (u64)(a3), (u64)(a4))#define efi_call_virt5 (f, a1, a2, a3, a4, a5) \ - efi_call5((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ + efi_call5((efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ (u64)(a3), (u64)(a4), (u64)(a5))#define efi_call_virt6 (f, a1, a2, a3, a4, a5, a6) \ - efi_call6((void *)(efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ + efi_call6((efi.systab->runtime->f), (u64)(a1), (u64)(a2), \ (u64)(a3), (u64)(a4), (u64)(a5), (u64)(a6)) extern void __iomem *efi_ioremap(unsigned long addr, unsigned long size,
include/linux/efi.h +14 -14
@@ -287,20 +287,20 @@ typedef struct {typedef struct {efi_table_hdr_t hdr; -unsigned long get_time; -unsigned long set_time; -unsigned long get_wakeup_time; -unsigned long set_wakeup_time; -unsigned long set_virtual_address_map; -unsigned long convert_pointer; -unsigned long get_variable; -unsigned long get_next_variable; -unsigned long set_variable; -unsigned long get_next_high_mono_count; -unsigned long reset_system; -unsigned long update_capsule; -unsigned long query_capsule_caps; -unsigned long query_variable_info; +void *get_time; +void *set_time; +void *get_wakeup_time; +void *set_wakeup_time; +void *set_virtual_address_map; +void *convert_pointer; +void *get_variable; +void *get_next_variable; +void *set_variable; +void *get_next_high_mono_count; +void *reset_system; +void *update_capsule; +void *query_capsule_caps; +void *query_variable_info; }efi_runtime_services_t ;typedef efi_status_t efi_get_time_t (efi_time_t *tm,efi_time_cap_t *tc);
Signature · 1 line
1.8.3.rc1.25.g423ecb0
Re: [PATCH 1/4] efi: Convert runtime services function ptrs
Quoted 11 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
... to void * like the boot services and lose all the void * casts. No functionality change.
Signed-off-by Borislav Petkov <[email protected]>--- arch/x86/boot/compressed/eboot.c | 2 +- arch/x86/include/asm/efi.h | 28 ++++++++++++++-------------- include/linux/efi.h | 28 ++++++++++++++-------------- 3 files changed, 29 insertions(+), 29 deletions(-)
Thanks! I've chucked this into my 'urgent' queue because it's a pretty straight forward cleanup and there's no point in allowing it to bitrot any further (the change to eboot.c is already stale).
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
Re: [PATCH 1/4] efi: Convert runtime services function ptrs
Quoted 3 lines · Matt Fleming
Thanks! I've chucked this into my 'urgent' queue because it's a pretty straight forward cleanup and there's no point in allowing it to bitrot any further (the change to
eboot.cis already stale).
OK, I chickened out of sending this in my latest pull request after reading Linus' -rc5 email about him not wanting to see any non-critical changes. I've stuck it in the 'next' branch with the rest of the stuff for v3.11.
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
Borislav Petkov
maintainerRe: [PATCH 1/4] efi: Convert runtime services function ptrs
Quoted 4 lines · Matt Fleming
OK, I chickened out of sending this in my latest pull request after reading Linus' -rc5 email about him not wanting to see any non-critical changes. I've stuck it in the 'next' branch with the rest of the stuff for v3.11.
Yep, did the same with a couple of edac patches too - cleanups can wait.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Borislav Petkov
maintainerPATCH 2/4 x86, cpa: Map in an arbitrary pgd
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Add the ability to map pages in an arbitrary pgd.
--- arch/x86/include/asm/pgtable_types.h | 3 +- arch/x86/mm/pageattr.c | 80 ++++++++++++++++++++++++++++-------- 2 files changed, 65 insertions(+), 18 deletions(-)
arch/x86/include/asm/pgtable_types.h +2 -1
@@ -352,7 +352,8 @@ static inline void update_page_count(int level, unsigned long pages) { }*/ extern pte_t *lookup_address (unsigned long address,unsigned int *level);extern phys_addr_t slow_virt_to_phys (void *__address); - +extern void kernel_map_pages_in_pgd (pgd_t *pgd,unsigned long address, +unsigned numpages,unsigned long page_flags);#endif /* !__ASSEMBLY__ */ #endif /* _ASM_X86_PGTABLE_DEFS_H */
arch/x86/mm/pageattr.c +63 -17
155 lines not on this page · raw message
Signature · 1 line
1.8.3.rc1.25.g423ecb0
Re: [PATCH 2/4] x86, cpa: Map in an arbitrary pgd
Quoted 36 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
Add the ability to map pages in an arbitrary pgd.
Signed-off-by Borislav Petkov <[email protected]>--- arch/x86/include/asm/pgtable_types.h | 3 +- arch/x86/mm/pageattr.c | 80 ++++++++++++++++++++++++++++-------- 2 files changed, 65 insertions(+), 18 deletions(-)arch/x86/include/asm/pgtable_types.h +2
-1@@ -352,7 +352,8 @@ static inline void update_page_count(int level, unsigned long pages) { }*/ extern pte_t *lookup_address (unsigned long address,unsigned int *level);extern phys_addr_t slow_virt_to_phys (void *__address); - +extern void kernel_map_pages_in_pgd (pgd_t *pgd,unsigned long address, +unsigned numpages,unsigned long page_flags);#endif /* !__ASSEMBLY__ */ #endif /* _ASM_X86_PGTABLE_DEFS_H */ arch/x86/mm/pageattr.c +1
-0@@ -30,6 +30,7 @@*/ struct cpa_data {unsigned long *vaddr; +pgd_t *pgd;pgprot_t mask_set;pgprot_t mask_clr;int numpages;
[...]
arch/x86/mm/pageattr.c static int __change_page_attr(struct cpa_data *cpa, int primary) · line 720
Quoted 9 lines
arch/x86/mm/pageattr.c +4
-1@@ -697,7 +714,10 @@ static int __change_page_attr(struct cpa_data *cpa, int primary)else address = *cpa->vaddr; repeat: - kpte =lookup_address (address, &level); +if (cpa->pgd) + kpte =__lookup_address_in_pgd (cpa->pgd, address, &level); +else + kpte =_lookup_address_cpa (cpa, address, &level);
Don't you also need to initialise .pgd in __set_pages_p() and __set_pages_np()?
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
Borislav Petkov
maintainerRe: [PATCH 2/4] x86, cpa: Map in an arbitrary pgd
Quoted 4 lines · Matt Fleming
Quoted 4 lines
arch/x86/mm/pageattr.c +0
-0@@ -697,7 +714,10 @@ static int __change_page_attr(struct cpa_data *cpa, int primary)else address = *cpa->vaddr; repeat:
Quoted 8 lines
arch/x86/mm/pageattr.c static int __change_page_attr(struct cpa_data *cpa, int primary) · line 720
Quoted 5 lines
arch/x86/mm/pageattr.c +4
-1- kpte =lookup_address (address, &level); +if (cpa->pgd) + kpte =__lookup_address_in_pgd (cpa->pgd, address, &level); +else + kpte =_lookup_address_cpa (cpa, address, &level);Don't you also need to initialise .pgd in
__set_pages_p()and__set_pages_np()?
Hmm, I don't think so. The idea is to leave the current functionality in pageattr.c untouched. Currently, it maps PTEs in init_mm.pgd by default because this is the kernel PGD.
For EFI, we switch the PGD and we want to map the PTEs in this other PGD, thus we have our own kernel_map_pages_in_pgd() which passes in the PGD we want to map in through struct cpa_data.
Then, we differentiate the PGD down that code by looking at cpa->pgd.
This was at least the idea.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Re: [PATCH 2/4] x86, cpa: Map in an arbitrary pgd
Quoted 14 lines · Borislav Petkov
Quoted 4 lines · Matt Fleming
Quoted 4 lines
arch/x86/mm/pageattr.c +0
-0@@ -697,7 +714,10 @@ static int __change_page_attr(struct cpa_data *cpa, int primary)else address = *cpa->vaddr; repeat:Quoted 8 lines
arch/x86/mm/pageattr.c static int __change_page_attr(struct cpa_data *cpa, int primary) · line 720
Quoted 5 lines
arch/x86/mm/pageattr.c +4
-1- kpte =lookup_address (address, &level); +if (cpa->pgd) + kpte =__lookup_address_in_pgd (cpa->pgd, address, &level); +else + kpte =_lookup_address_cpa (cpa, address, &level);Don't you also need to initialise .pgd in
__set_pages_p()and__set_pages_np()?
Quoted 3 lines
Hmm, I don't think so. The idea is to leave the current functionality in
pageattr.cuntouched. Currently, it maps PTEs in init_mm.pgd by default because this is the kernel PGD.
I meant because the .pgd member is uninitialised and contains garbage.
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
Borislav Petkov
maintainerRe: [PATCH 2/4] x86, cpa: Map in an arbitrary pgd
Quoted 1 line · Matt Fleming
I meant because the .pgd member is uninitialised and contains garbage.
Oh yeah, good catch! Fixed.
Thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Borislav Petkov
maintainerPATCH 3/4 x86, efi: Add an efi= kernel command line parameter
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
.. for passing miscellaneous options from the kernel command line.
--- arch/x86/platform/efi/efi.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/x86/platform/efi/efi.c +16 -0
@@ -88,6 +88,11 @@ static u64 active_size;unsigned long x86_efi_facility; +/* 1:1 mapping of services regions */ +#define EFI_CFG_MAP11 BIT(0) + +static unsigned long efi_config; +/* * Returns 1 if 'facility' is enabled, 0 otherwise. */
@@ -1167,3 +1172,14 @@ efi_status_t efi_query_variable_store(u32 attributes, unsigned long size)return EFI_SUCCESS ; }EXPORT_SYMBOL_GPL (efi_query_variable_store); + +static int __init parse_efi_cmdline (char *str) +{ +if (*str =='=' ) + str++; +if (!strncmp (str,"1:1_map" ,7 )) + efi_config |=EFI_CFG_MAP11 ; + +return 0 ; +} +early_param ("efi" , parse_efi_cmdline);
Signature · 1 line
1.8.3.rc1.25.g423ecb0
Borislav Petkov
maintainerRe: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 26 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
.. for passing miscellaneous options from the kernel command line.
Signed-off-by Borislav Petkov <[email protected]>--- arch/x86/platform/efi/efi.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)arch/x86/platform/efi/efi.c +5
-0@@ -88,6 +88,11 @@ static u64 active_size;unsigned long x86_efi_facility; +/* 1:1 mapping of services regions */ +#define EFI_CFG_MAP11 BIT(0) + +static unsigned long efi_config; +/* * Returns 1 if 'facility' is enabled, 0 otherwise. */
arch/x86/platform/efi/efi.c efi_status_t efi_query_variable_store(u32 attributes, unsigned long size) · line 1176
Quoted 5 lines
arch/x86/platform/efi/efi.c +2
-0@@ -1167,3 +1172,14 @@ efi_status_t efi_query_variable_store(u32 attributes, unsigned long size)return EFI_SUCCESS ; }EXPORT_SYMBOL_GPL (efi_query_variable_store); + +static int __init parse_efi_cmdline (char *str)
note to self:
#ifdef CONFIG_X86_64
arch/x86/platform/efi/efi.c efi_status_t efi_query_variable_store(u32 attributes, unsigned long size) · line 1181
Quoted 5 lines
arch/x86/platform/efi/efi.c +5
-0+{ +if (*str =='=' ) + str++; +if (!strncmp (str,"1:1_map" ,7 )) + efi_config |=EFI_CFG_MAP11 ;
#endif
to temporarily workaround the 64-bit only requirement.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Re: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
In reply to Borislav Petkovarch/x86/platform/efi/efi.c efi_status_t efi_query_variable_store(u32 attributes, unsigned long size) · line 1185
Quoted 11 lines · Borislav Petkov
arch/x86/platform/efi/efi.c +11
-0+ +static int __init parse_efi_cmdline (char *str) +{ +if (*str =='=' ) + str++; +if (!strncmp (str,"1:1_map" ,7 )) + efi_config |=EFI_CFG_MAP11 ; + +return 0 ; +} +early_param ("efi" , parse_efi_cmdline);
This is fine for testing, but I genuinely think that this should be on by default once these patches are final.
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
Borislav Petkov
maintainerRe: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 15 lines · Matt Fleming
arch/x86/platform/efi/efi.c efi_status_t efi_query_variable_store(u32 attributes, unsigned long size) · line 1185
Quoted 11 lines · Borislav Petkov
arch/x86/platform/efi/efi.c +11
-0+ +static int __init parse_efi_cmdline (char *str) +{ +if (*str =='=' ) + str++; +if (!strncmp (str,"1:1_map" ,7 )) + efi_config |=EFI_CFG_MAP11 ; + +return 0 ; +} +early_param ("efi" , parse_efi_cmdline);This is fine for testing, but I genuinely think that this should be on by default once these patches are final.
This would break the Macs, remember?
We could make it be the default though and flip the logic so that users can fall back to the current ioremap functionality, i.e. boot with "efi=no_1:1_map".
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Re: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 17 lines · Borislav Petkov
Quoted 15 lines · Matt Fleming
arch/x86/platform/efi/efi.c efi_status_t efi_query_variable_store(u32 attributes, unsigned long size) · line 1185
Quoted 11 lines · Borislav Petkov
arch/x86/platform/efi/efi.c +11
-0+ +static int __init parse_efi_cmdline (char *str) +{ +if (*str =='=' ) + str++; +if (!strncmp (str,"1:1_map" ,7 )) + efi_config |=EFI_CFG_MAP11 ; + +return 0 ; +} +early_param ("efi" , parse_efi_cmdline);This is fine for testing, but I genuinely think that this should be on by default once these patches are final.
Quoted 5 lines
This would break the Macs, remember?
We could make it be the default though and flip the logic so that users can fall back to the current ioremap functionality, i.e. boot with "efi=no_1:1_map".
Yeah, or white/blacklist them. We've already had enough of "Oh, your machine used to work but now it's bust? Yeah, turn on this cmdline parameter to get things working again".
But the point is that the funnies that have been seen on the Macs should be treated as the unusual case. The number of machines I've seen that require this 1:1 map is staggering, especially once you start poking at some of the other runtime services, like UpdateCapsule().
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
Re: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
In reply to Borislav PetkovQuoted 1 line · Borislav Petkov
This would break the Macs, remember?
I think the Macs will be fine as long as we're passing the high mappings into SetVirtualAddressMap().
Signature · 1 line
Matthew Garrett | [email protected]
Borislav Petkov
maintainerRe: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 6 lines · Matthew Garrett
Quoted 1 line · Borislav Petkov
This would break the Macs, remember?
I think the Macs will be fine as long as we're passing the high mappings into
SetVirtualAddressMap().
Right, on those we'll fall back to the current mappings and simply not have the 1:1 thing.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Re: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 10 lines · Borislav Petkov
Quoted 6 lines · Matthew Garrett
Quoted 1 line · Borislav Petkov
This would break the Macs, remember?
I think the Macs will be fine as long as we're passing the high mappings into
SetVirtualAddressMap().Right, on those we'll fall back to the current mappings and simply not have the 1:1 thing.
No, I think that's the wrong thing to do. We should set up the current mappings and the 1:1 mappings, and pass the current mappings through SetVirtualAddressMap(). That matches the behaviour of Windows.
Signature · 1 line
Matthew Garrett | [email protected]
Borislav Petkov
maintainerRe: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 3 lines · Matthew Garrett
No, I think that's the wrong thing to do. We should set up the current mappings and the 1:1 mappings, and pass the current mappings through
SetVirtualAddressMap(). That matches the behaviour of Windows.
And when do we use the 1:1 mappings and when the current mappings when doing runtime calls?
Also, would the 1:1 mappings even work if not passed through SetVirtualAddressMap? I'm sensing a "yes" but I don't know...
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Re: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 7 lines · Borislav Petkov
Quoted 3 lines · Matthew Garrett
No, I think that's the wrong thing to do. We should set up the current mappings and the 1:1 mappings, and pass the current mappings through
SetVirtualAddressMap(). That matches the behaviour of Windows.And when do we use the 1:1 mappings and when the current mappings when doing runtime calls?
We want both to be available when we're making the call, but I think we should probably enter via the high addresses. The only reason we're doing this at all is that some systems don't update all of their pointers from physical mode, and we'd prefer them to work rather than fault...
Signature · 1 line
Matthew Garrett | [email protected]
Borislav Petkov
maintainerRe: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 5 lines · Matthew Garrett
We want both to be available when we're making the call, but I think we should probably enter via the high addresses. The only reason we're doing this at all is that some systems don't update all of their pointers from physical mode, and we'd prefer them to work rather than fault...
Actually, we do the 1:1 thing so that EFI runtime works in a kexec kernel too. Which won't work if we use the high addresses.
However, if we can use the 1:1 map *after* SetVirtualAddressMap() has been called with the high mappings, then my issue is solved - we drop to using 1:1 in the kexec kernel only. But I don't think that is the case...
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Re: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 9 lines · Borislav Petkov
Quoted 5 lines · Matthew Garrett
We want both to be available when we're making the call, but I think we should probably enter via the high addresses. The only reason we're doing this at all is that some systems don't update all of their pointers from physical mode, and we'd prefer them to work rather than fault...
Actually, we do the 1:1 thing so that EFI runtime works in a kexec kernel too. Which won't work if we use the high addresses.
kexec seems like a lower priority than compatibility. Perhaps keep the efi argument for people who want to use kexec? hpa suggested allocating a fixed high area for UEFI mappings, which would also solve this.
Quoted 4 lines
However, if we can use the 1:1 map *after*
SetVirtualAddressMap()has been called with the high mappings, then my issue is solved - we drop to using 1:1 in the kexec kernel only. But I don't think that is the case...
Yeah, calling SetVirtualAddressMap() with high addresses is going to result in the firmware having a bunch of pointers to high addresses.
Signature · 1 line
Matthew Garrett | [email protected]
Borislav Petkov
maintainerRe: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 2 lines · Matthew Garrett
kexec seems like a lower priority than compatibility. Perhaps keep the efi argument for people who want to use kexec?
This is what I currently have in the code: if you boot with efi=1:1_map, you get them.
Quoted 2 lines
hpa suggested allocating a fixed high area for UEFI mappings, which would also solve this.
I guess we can do that too.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Re: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 6 lines · Borislav Petkov
Quoted 2 lines · Matthew Garrett
kexec seems like a lower priority than compatibility. Perhaps keep the efi argument for people who want to use kexec?
This is what I currently have in the code: if you boot with efi=1:1_map, you get them.
Well, we want the 1:1 mappings to exist all the time. The only thing the option should change is whether they're passed to SetVirtualAddressMap() or not.
Signature · 1 line
Matthew Garrett | [email protected]
Borislav Petkov
maintainerRe: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 3 lines · Matthew Garrett
Well, we want the 1:1 mappings to exist all the time. The only thing the option should change is whether they're passed to
SetVirtualAddressMap()or not.
But can you call them even if they haven't been passed through SetVirtualAddressMap, *after* SetVirtualAddressMap has been called?
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Re: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 7 lines · Borislav Petkov
Quoted 3 lines · Matthew Garrett
Well, we want the 1:1 mappings to exist all the time. The only thing the option should change is whether they're passed to
SetVirtualAddressMap()or not.But can you call them even if they haven't been passed through SetVirtualAddressMap, *after* SetVirtualAddressMap has been called?
What do you mean by "call them"? I don't think we ever want to call by physical address, other than maybe in the kexec case. The only reason we really care about the physical addresses being mapped 1:1 is that some pointers may not have been updated.
Signature · 1 line
Matthew Garrett | [email protected]
Borislav Petkov
maintainerRe: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 4 lines · Matthew Garrett
What do you mean by "call them"? I don't think we ever want to call by physical address, other than maybe in the kexec case. The only reason we really care about the physical addresses being mapped 1:1 is that some pointers may not have been updated.
I want to be able to call the runtime services in the kexec kernel. Which means, the kexec kernel would simply map the runtime code/data regions 1:1 and then use the physical addresses to call the runtime services.
Question is: would that work even if SetVirtualAddressMap has already run in the original kernel and with virtual addresses?
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Re: [PATCH 3/4] x86, efi: Add an efi= kernel command line parameter
Quoted 6 lines · Borislav Petkov
Quoted 4 lines · Matthew Garrett
What do you mean by "call them"? I don't think we ever want to call by physical address, other than maybe in the kexec case. The only reason we really care about the physical addresses being mapped 1:1 is that some pointers may not have been updated.
Quoted 7 lines
I want to be able to call the runtime services in the kexec kernel. Which means, the kexec kernel would simply map the runtime code/data regions 1:1 and then use the physical addresses to call the runtime services.
Question is: would that work even if SetVirtualAddressMap has already run in the original kernel and with virtual addresses?
No. You'll need to have an option for that case.
Signature · 1 line
Matthew Garrett | [email protected]
Borislav Petkov
maintainerPATCH 4/4 x86, efi: Map runtime services 1:1
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Due to the braindead design of EFI, we cannot map runtime services more than once for the duration of a booted system. Thus, if we want to use EFI runtime services in a kexec'ed kernel, maybe the only possible and sensible approach would be to map them 1:1 so that when the kexec kernel loads, it can simply call those addresses without the need for remapping (which doesn't work anyway).
Furthermore, this mapping approach could be of help with b0rked EFI implementations for a different set of reasons.
This implementation is 64-bit only for now and it boots fine in kvm with OVMF BIOS.
--- arch/x86/include/asm/efi.h | 2 + arch/x86/platform/efi/efi.c | 161 +++++++++++++++++++++++++++++------- arch/x86/platform/efi/efi_stub_64.S | 48 +++++++++++ 3 files changed, 180 insertions(+), 31 deletions(-)
arch/x86/include/asm/efi.h +2 -0
@@ -41,6 +41,8 @@ extern unsigned long asmlinkage efi_call_phys(void *, ...);#define EFI_LOADER_SIGNATURE "EL64" +extern pgd_t *efi_pgt; +extern u64 efi_call0 (void *fp);extern u64 efi_call1 (void *fp,u64 arg1);extern u64 efi_call2 (void *fp,u64 arg1,u64 arg2);
arch/x86/platform/efi/efi.c +130 -31
213 lines not on this page · raw message
arch/x86/platform/efi/efi_stub_64.S +48 -0
101 lines not on this page · raw message
Signature · 1 line
1.8.3.rc1.25.g423ecb0
Re: [PATCH 4/4] x86, efi: Map runtime services 1:1
Quoted 15 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
Due to the braindead design of EFI, we cannot map runtime services more than once for the duration of a booted system. Thus, if we want to use EFI runtime services in a kexec'ed kernel, maybe the only possible and sensible approach would be to map them 1:1 so that when the kexec kernel loads, it can simply call those addresses without the need for remapping (which doesn't work anyway).
Furthermore, this mapping approach could be of help with b0rked EFI implementations for a different set of reasons.
This implementation is 64-bit only for now and it boots fine in kvm with OVMF BIOS.
Quoted 6 lines
Signed-off-by Borislav Petkov <[email protected]>--- arch/x86/include/asm/efi.h | 2 + arch/x86/platform/efi/efi.c | 161 +++++++++++++++++++++++++++++------- arch/x86/platform/efi/efi_stub_64.S | 48 +++++++++++ 3 files changed, 180 insertions(+), 31 deletions(-)
This patch makes my TunnelMountain machine spin in handle_pte_fault() when triggering one of the "firmware makes references to physical addresses" code paths.
I'll try and dig into this tomorrow to figure out what's going on.
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
Borislav Petkov
maintainerRe: [PATCH 4/4] x86, efi: Map runtime services 1:1
Quoted 5 lines · Matt Fleming
This patch makes my TunnelMountain machine spin in
handle_pte_fault()when triggering one of the "firmware makes references to physical addresses" code paths.I'll try and dig into this tomorrow to figure out what's going on.
Hmmm, looks like we have forgotten to map an EFI region and we do a #PF when executing the EFI code.
If so, I'm thinking we don't want to touch the #PF code and teach it about EFI so maybe we should make sure we've mapped *everything* EFI runtime would need before we switch PGDs...
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Borislav Petkov
maintainerRe: [PATCH 4/4] x86, efi: Map runtime services 1:1
Quoted 9 lines · Borislav Petkov
Quoted 5 lines · Matt Fleming
This patch makes my TunnelMountain machine spin in
handle_pte_fault()when triggering one of the "firmware makes references to physical addresses" code paths.I'll try and dig into this tomorrow to figure out what's going on.
Hmmm, looks like we have forgotten to map an EFI region and we do a #PF when executing the EFI code.
How about this one - I don't know whether it would flood dmesg, I guess you'll have to try.
We could try using blockconsole to catch dmesg to an usb drive, though, even if you don't have serial or netconsole or such. :-).
--
arch/x86/mm/fault.c +3 -0
@@ -1021,6 +1021,9 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)/* Get the faulting address: */ address =read_cr2 (); +if (read_cr3 () == (unsigned long )real_mode_header->trampoline_pgd) +pr_err ("%s: #PF addr: 0x%lx\n" , __func__, address); +/* * Detect and handle instructions that would cause a page fault for * both a tracked kernel page and a userspace page.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--H. Peter Anvin
reviewerRe: [PATCH 4/4] x86, efi: Map runtime services 1:1
Quoted 7 lines · Borislav Petkov
--
arch/x86/mm/fault.c +0
-0
arch/x86/mm/fault.c __do_page_fault(struct pt_regs *regs, unsigned long error_code) · line 1029
Quoted 9 lines
arch/x86/mm/fault.c +3
-0@@ -1021,6 +1021,9 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)/* Get the faulting address: */ address =read_cr2 (); +if (read_cr3 () == (unsigned long )real_mode_header->trampoline_pgd) +pr_err ("%s: #PF addr: 0x%lx\n" , __func__, address); +/* * Detect and handle instructions that would cause a page fault for * both a tracked kernel page and a userspace page.
Or we could materialize mappings for this specific PGD. However, adding a read of %cr3 in __do_page_fault sounds expensive.
-hpa
Borislav Petkov
maintainerRe: [PATCH 4/4] x86, efi: Map runtime services 1:1
Quoted 2 lines · H. Peter Anvin
Or we could materialize mappings for this specific PGD. However, adding a read of %cr3 in
__do_page_faultsounds expensive.
Yes, I think we want to make sure all mappings are there when we do an EFI runtime call so that we never #PF while it executes.
Matt mentioned on IRC that the it could be that his EFI runtime is referencing EFI_RESERVED area which we don't map. However, we need to confirm/disprove that first, as it is currently only a hunch.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--H. Peter Anvin
reviewerRe: [PATCH 4/4] x86, efi: Map runtime services 1:1
Quoted 10 lines · Borislav Petkov
Quoted 2 lines · H. Peter Anvin
Or we could materialize mappings for this specific PGD. However, adding a read of %cr3 in
__do_page_faultsounds expensive.Yes, I think we want to make sure all mappings are there when we do an EFI runtime call so that we never #PF while it executes.
Matt mentioned on IRC that the it could be that his EFI runtime is referencing
EFI_RESERVEDarea which we don't map. However, we need to confirm/disprove that first, as it is currently only a hunch.
If it is true, then maybe a #PF handler which materializes mappings on demand might be the right thing to do.
Again, it would be interesting to stop a WinX VM in the process of doing an EFI call and see exactly what it has set up in its page tables.
-hpa
Borislav Petkov
maintainerRe: [PATCH 4/4] x86, efi: Map runtime services 1:1
Quoted 11 lines · H. Peter Anvin
Quoted 10 lines · Borislav Petkov
Quoted 2 lines · H. Peter Anvin
Or we could materialize mappings for this specific PGD. However, adding a read of %cr3 in
__do_page_faultsounds expensive.Yes, I think we want to make sure all mappings are there when we do an EFI runtime call so that we never #PF while it executes.
Matt mentioned on IRC that the it could be that his EFI runtime is referencing
EFI_RESERVEDarea which we don't map. However, we need to confirm/disprove that first, as it is currently only a hunch.
FWIW,
booting the patchset on my Dell looks good here. Booting at least, I don't know about other stuff. If you have an EFI test suite or want me to try stuff out, let me know. efibootmgr output looks sane too.
Btw, I've added a printk to the code so that we know that we've managed switching to the 1:1 thing:
[ 0.073119] efi: Using 1:1 map.
Thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--I've just run Windows 8 under a hacked up copy of OVMF that dumps the data passed to SetVirtualAddressMap. It seems that Windows *is* mapping the runtime services to higher addresses - so presumably the 1:1 mapping is in addition to the virtual mapping.
Signature · 1 line
Matthew Garrett | [email protected]
Borislav Petkov
maintainerQuoted 4 lines · Matthew Garrett
I've just run Windows 8 under a hacked up copy of OVMF that dumps the data passed to SetVirtualAddressMap. It seems that Windows *is* mapping the runtime services to higher addresses - so presumably the 1:1 mapping is in addition to the virtual mapping.
But but, once we call SetVirtualAddressMap with the set of addresses of the runtime services, only those can be used after, right? If so, we can't have both (this is at least my understanding)...
Thanks.
Quoted 9 lines · Borislav Petkov
Quoted 4 lines · Matthew Garrett
I've just run Windows 8 under a hacked up copy of OVMF that dumps the data passed to SetVirtualAddressMap. It seems that Windows *is* mapping the runtime services to higher addresses - so presumably the 1:1 mapping is in addition to the virtual mapping.
But but, once we call SetVirtualAddressMap with the set of addresses of the runtime services, only those can be used after, right? If so, we can't have both (this is at least my understanding)...
That's correct. I think not calling SetVirtualAddressMap() and just using a 1:1 mapping is far safer (having looked at what tianocore does for SetVirtualAddressMap()). The chances are that all the UEFI bioses are only tested with windows, so the pointer chases it has to do to switch address maps only work with the operations windows does.
James
Quoted 5 lines · James Bottomley
That's correct. I think not calling
SetVirtualAddressMap()and just using a 1:1 mapping is far safer (having looked at what tianocore does forSetVirtualAddressMap()). The chances are that all the UEFI bioses are only tested with windows, so the pointer chases it has to do to switch address maps only work with the operations windows does.
Windows calls SetVirtualAddressMap(), so the only way these systems have been tested is with SetVirtualAddressMap().
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · James Bottomley
That's correct. I think not calling
SetVirtualAddressMap()and just using a 1:1 mapping is far safer (having looked at what tianocore does forSetVirtualAddressMap()). The chances are that all the UEFI bioses are only tested with windows, so the pointer chases it has to do to switch address maps only work with the operations windows does.Windows calls
SetVirtualAddressMap(), so the only way these systems have been tested is withSetVirtualAddressMap().
I know, but that's not what I said.
If you look at the implementation, SetVirtualAddressMap() does a massive pointer chase through the images. It not only tries to relocate the text and data, but it also tries to relocate all the users of the data. Some of these sources of data are boot time and some runtime. Those both need to be relocated by a separate pointer chase. What we saw with the QueryVariableInfo() problem was that a boot time pointer wasn't relocated. That's got to mean that windows only calls QueryVariableInfo from runtime.
My point is that if we elect to call SetVirtualAddressMap() we'll be restricted to only making the calls at boot time that windows does otherwise we'll end up with these unrelocated pointers. That's a huge nasty verification burden on us. Alternatively, if we never call SetVirtualAddressMap() it seems to me that we just don't have to worry about pointer relocation issues. Thus, I think it would be better we use the 1:1 mapping instead of calling SetVirtualAddressMap().
James
Quoted 6 lines · James Bottomley
Quoted 2 lines · Matthew Garrett
Windows calls
SetVirtualAddressMap(), so the only way these systems have been tested is withSetVirtualAddressMap().I know, but that's not what I said.
Quoted 8 lines
If you look at the implementation,
SetVirtualAddressMap()does a massive pointer chase through the images. It not only tries to relocate the text and data, but it also tries to relocate all the users of the data. Some of these sources of data are boot time and some runtime. Those both need to be relocated by a separate pointer chase. What we saw with theQueryVariableInfo()problem was that a boot time pointer wasn't relocated. That's got to mean that windows only calls QueryVariableInfo from runtime.
Sure.
Quoted 7 lines
My point is that if we elect to call
SetVirtualAddressMap()we'll be restricted to only making the calls at boot time that windows does otherwise we'll end up with these unrelocated pointers. That's a huge nasty verification burden on us. Alternatively, if we never callSetVirtualAddressMap()it seems to me that we just don't have to worry about pointer relocation issues. Thus, I think it would be better we use the 1:1 mapping instead of callingSetVirtualAddressMap().
Some hardware just arbitrarily fails some calls if SetVirtualAddressMap() isn't called. As you pointed out, the only situation that these systems are ever tested in is the one where calls are made in roughly the same order as Windows, ie:
Calls made in boot services:
GetTime()Getvariable()ExitBootServices()
Calls made in runtime:
SetVirtualAddressMap()GetNextVariable()GetVariable()SetVariable()
So far I haven't been able to convince Windows to make any other runtime calls, which makes me a little unhappy about even calling QueryVariableInfo() during runtime, but on the other hand our options there are either to call it or to kill Samsungs, so I think we're stuck with it. But, overall, refusing to call SetVirtualAddressMap() simply isn't an option.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 44 lines · Matthew Garrett
Quoted 6 lines · James Bottomley
Quoted 2 lines · Matthew Garrett
Windows calls
SetVirtualAddressMap(), so the only way these systems have been tested is withSetVirtualAddressMap().I know, but that's not what I said.
Quoted 8 lines
If you look at the implementation,
SetVirtualAddressMap()does a massive pointer chase through the images. It not only tries to relocate the text and data, but it also tries to relocate all the users of the data. Some of these sources of data are boot time and some runtime. Those both need to be relocated by a separate pointer chase. What we saw with theQueryVariableInfo()problem was that a boot time pointer wasn't relocated. That's got to mean that windows only calls QueryVariableInfo from runtime.Sure.
Quoted 7 lines
My point is that if we elect to call
SetVirtualAddressMap()we'll be restricted to only making the calls at boot time that windows does otherwise we'll end up with these unrelocated pointers. That's a huge nasty verification burden on us. Alternatively, if we never callSetVirtualAddressMap()it seems to me that we just don't have to worry about pointer relocation issues. Thus, I think it would be better we use the 1:1 mapping instead of callingSetVirtualAddressMap().Some hardware just arbitrarily fails some calls if
SetVirtualAddressMap()isn't called. As you pointed out, the only situation that these systems are ever tested in is the one where calls are made in roughly the same order as Windows, ie:Calls made in boot services:
GetTime()Getvariable()ExitBootServices()Calls made in runtime:
SetVirtualAddressMap()GetNextVariable()GetVariable()SetVariable()
Quoted 6 lines
So far I haven't been able to convince Windows to make any other runtime calls, which makes me a little unhappy about even calling
QueryVariableInfo()during runtime, but on the other hand our options there are either to call it or to kill Samsungs, so I think we're stuck with it. But, overall, refusing to callSetVirtualAddressMap()simply isn't an option.
I don't entirely buy that. All EFI programs run with the physical address map, therefore every API an EFI program uses is also tested, at boot time only, obviously. However, the ExitBootServices() code seems to be much simpler, so I don't think it will cause too many bugs. The UEFI test suites also seem to try UEFI calls before and after ExitBootServices(), so I think relying on a 1:1 mapping looks safer to me.
James
Quoted 3 lines · James Bottomley
I don't entirely buy that. All EFI programs run with the physical address map, therefore every API an EFI program uses is also tested, at boot time only, obviously.
That seems optimistic. Windows never calls QueryVariableInfo() during boot services, so what makes you think doing so has ever been tested?
Quoted 4 lines
However, the
ExitBootServices()code seems to be much simpler, so I don't think it will cause too many bugs. The UEFI test suites also seem to try UEFI calls before and afterExitBootServices(), so I think relying on a 1:1 mapping looks safer to me.
I have no expectation that the majority of system vendors run the test suite, but I have every expectation that every system vendor runs Windows. We should behave as close to the tested mechanism as possible, ie do what Windows does - and that includes calling SetVirtualAddressMap().
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Matthew Garrett
Quoted 3 lines · James Bottomley
I don't entirely buy that. All EFI programs run with the physical address map, therefore every API an EFI program uses is also tested, at boot time only, obviously.
That seems optimistic. Windows never calls
QueryVariableInfo()during boot services, so what makes you think doing so has ever been tested?
It's used by the UEFI shell package ... every system which boots to the shell automatically tests this. I know no locked down UEFI system ships with a shell but almost every system in test has a Shell in some form, so I think its fairly safe to call it from boot services.
Quoted 10 lines
Quoted 4 lines
However, the
ExitBootServices()code seems to be much simpler, so I don't think it will cause too many bugs. The UEFI test suites also seem to try UEFI calls before and afterExitBootServices(), so I think relying on a 1:1 mapping looks safer to me.I have no expectation that the majority of system vendors run the test suite, but I have every expectation that every system vendor runs Windows. We should behave as close to the tested mechanism as possible, ie do what Windows does - and that includes calling
SetVirtualAddressMap().
OK, so we basically agree to disagree. When I looked at the actual SetVirtualAddressMap() implementation, my heart skipped several beats:
it's a massive set of pointer chasing heuristics which is bound to be incorrect in some instance, just because its so complex and easy to get wrong. Every time it's incorrect, we'll get a physical pointer used in a virtual space and an oops within the UEFI code. Conversely, I think the engineering risk that a particular UEFI call is expecting to have had SetVirtualAddressMap called is much lower.
However, what about a compromise: why don't we implement 1:1 mapping and then call SetVirtualAddressMap with the 1:1 map ... in theory the pointer chases should then be nops (it will be replacing the physical address with the same virtual address), so everything should just work and anything the UEFI vendor missed will still work because the physical address will work also in this scenario.
James
Quoted 8 lines · James Bottomley
Quoted 2 lines · Matthew Garrett
That seems optimistic. Windows never calls
QueryVariableInfo()during boot services, so what makes you think doing so has ever been tested?It's used by the UEFI shell package ... every system which boots to the shell automatically tests this. I know no locked down UEFI system ships with a shell but almost every system in test has a Shell in some form, so I think its fairly safe to call it from boot services.
Why do you persist in this belief that all system vendors are going to have run a shell, let alone any kind of test suite? That runs counter to everything we've learned about x86 firmware. People verify that it runs Windows and then ship it.
Quoted 6 lines
However, what about a compromise: why don't we implement 1:1 mapping and then call SetVirtualAddressMap with the 1:1 map ... in theory the pointer chases should then be nops (it will be replacing the physical address with the same virtual address), so everything should just work and anything the UEFI vendor missed will still work because the physical address will work also in this scenario.
The problem there is that you're saying "In theory". We know that Windows doesn't behave this way, so we have no legitimate expectation that it'll work. We know that it doesn't on some Apple hardware.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 10 lines · Matthew Garrett
Quoted 8 lines · James Bottomley
Quoted 2 lines · Matthew Garrett
That seems optimistic. Windows never calls
QueryVariableInfo()during boot services, so what makes you think doing so has ever been tested?It's used by the UEFI shell package ... every system which boots to the shell automatically tests this. I know no locked down UEFI system ships with a shell but almost every system in test has a Shell in some form, so I think its fairly safe to call it from boot services.
Quoted 4 lines
Why do you persist in this belief that all system vendors are going to have run a shell, let alone any kind of test suite? That runs counter to everything we've learned about x86 firmware. People verify that it runs Windows and then ship it.
I don't, but I find it hard to believe no vendor ever runs an EFI shell on their systems. The feedback I got from a couple of OEMs is that they use the shell mostly for internal testing.
Quoted 10 lines
Quoted 6 lines
However, what about a compromise: why don't we implement 1:1 mapping and then call SetVirtualAddressMap with the 1:1 map ... in theory the pointer chases should then be nops (it will be replacing the physical address with the same virtual address), so everything should just work and anything the UEFI vendor missed will still work because the physical address will work also in this scenario.
The problem there is that you're saying "In theory". We know that Windows doesn't behave this way, so we have no legitimate expectation that it'll work. We know that it doesn't on some Apple hardware.
Fine, you say we need to call SetVirtualAddressMap because windows does, I agree, I'm just saying we get additional safety from calling it with the 1:1 map ... I don't see what the problem is.
James
Quoted 9 lines · James Bottomley
Quoted 4 lines · Matthew Garrett
Why do you persist in this belief that all system vendors are going to have run a shell, let alone any kind of test suite? That runs counter to everything we've learned about x86 firmware. People verify that it runs Windows and then ship it.
I don't, but I find it hard to believe no vendor ever runs an EFI shell on their systems. The feedback I got from a couple of OEMs is that they use the shell mostly for internal testing.
There are vendors that do, and I expect that there are vendors who don't. There are vendors who will make changes to firmware and run the EFI test suite, and there are vendors who will make changes to firmware and run Windows.
Quoted 7 lines
Quoted 3 lines
The problem there is that you're saying "In theory". We know that Windows doesn't behave this way, so we have no legitimate expectation that it'll work. We know that it doesn't on some Apple hardware.
Fine, you say we need to call SetVirtualAddressMap because windows does, I agree, I'm just saying we get additional safety from calling it with the 1:1 map ... I don't see what the problem is.
No. I'm saying that calling it with the 1:1 map is something very different to the behaviour of Windows, and I'm saying that doing so is known to cause variable writes on some Apple hardware to stop working. If we're aiming for maximum compatibility, we need to call SetVirtualAddressMap() with addresses above the canonicalisation hole.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Matthew Garrett
Quoted 7 lines
Quoted 3 lines
The problem there is that you're saying "In theory". We know that Windows doesn't behave this way, so we have no legitimate expectation that it'll work. We know that it doesn't on some Apple hardware.
Fine, you say we need to call SetVirtualAddressMap because windows does, I agree, I'm just saying we get additional safety from calling it with the 1:1 map ... I don't see what the problem is.
Quoted 5 lines
No. I'm saying that calling it with the 1:1 map is something very different to the behaviour of Windows, and I'm saying that doing so is known to cause variable writes on some Apple hardware to stop working. If we're aiming for maximum compatibility, we need to call
SetVirtualAddressMap()with addresses above the canonicalisation hole.
OK, so tell me this problem: it's a new one one me. I think you're saying if we don't call SetVirtualAddressMap with a mapping above a certain value, some Apple system breaks somehow? (how?).
James
Quoted 10 lines · James Bottomley
Quoted 5 lines · Matthew Garrett
No. I'm saying that calling it with the 1:1 map is something very different to the behaviour of Windows, and I'm saying that doing so is known to cause variable writes on some Apple hardware to stop working. If we're aiming for maximum compatibility, we need to call
SetVirtualAddressMap()with addresses above the canonicalisation hole.OK, so tell me this problem: it's a new one one me. I think you're saying if we don't call SetVirtualAddressMap with a mapping above a certain value, some Apple system breaks somehow? (how?).
SetVariable() returns an error. Digging through disassembly of the code generating the error got me to the point of realising it was doing some sort of pointer arithmetic and then giving up.
Signature · 1 line
Matthew Garrett | [email protected]
Linux, UEFI, and Chromebooks (was RE: [PATCH 0/4] EFI 1:1 mapping)
In reply to Matthew GarrettQuoted 10 lines · James Bottomley
Quoted 8 lines · Matthew Garrett
Quoted 2 lines
That seems optimistic. Windows never calls
QueryVariableInfo()during boot services, so what makes you think doing so has ever been tested?It's used by the UEFI shell package ... every system which boots to the shell automatically tests this. I know no locked down UEFI system ships with a shell but almost every system in test has a Shell in some form, so I think its fairly safe to call it from boot services.
Quoted 4 lines
Why do you persist in this belief that all system vendors are going to have run a shell, let alone any kind of test suite? That runs counter to everything we've learned about x86 firmware. People verify that it runs Windows and then ship it.
What is frustrating here is that Google decided that x86 Chromebooks should use different firmware, otherwise it would be easier to convince vendor to fix these firmware bugs.
Yuhong Bao --
To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Borislav Petkov
Quoted 4 lines · Matthew Garrett
I've just run Windows 8 under a hacked up copy of OVMF that dumps the data passed to SetVirtualAddressMap. It seems that Windows *is* mapping the runtime services to higher addresses - so presumably the 1:1 mapping is in addition to the virtual mapping.
But but, once we call SetVirtualAddressMap with the set of addresses of the runtime services, only those can be used after, right? If so, we can't have both (this is at least my understanding)...
We can only pass one set of addresses to SetVirtualAddressMap(), but it doesn't seem like there's any intrinsic reason we can't the runtime regions mapped to multiple virtual addresses.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 3 lines · Matthew Garrett
We can only pass one set of addresses to
SetVirtualAddressMap(), but it doesn't seem like there's any intrinsic reason we can't the runtime regions mapped to multiple virtual addresses.
Indeed. That's the approach I took with my 1:1 series from last year. If Windows is mapping things at higher addresses like you said, then they're probably doing the same.
Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
Borislav Petkov
maintainerQuoted 8 lines · Matt Fleming
Quoted 3 lines · Matthew Garrett
We can only pass one set of addresses to
SetVirtualAddressMap(), but it doesn't seem like there's any intrinsic reason we can't the runtime regions mapped to multiple virtual addresses.Indeed. That's the approach I took with my 1:1 series from last year. If Windows is mapping things at higher addresses like you said, then they're probably doing the same.
Right, the way I've done it now is to do the virtual mapping unconditionally, then do the 1:1 mapping and call SetVirtualAddressMap (f*cking camelcase is so nasty to type - that's why they need whole IDEs to program :-)) with that map, if "efi=1:1_map" has been passed on the cmd line.
After the call, we use *only* the 1:1 map but the virtual mapping is still there.
The initial approach to addressing the b0rked Macs would then be to never use the 1:1 map on them.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--