EFI mixed mode
cover EFI mixed mode
From: Matt Fleming <[email protected]>
This patch series enables booting a 64-bit kernel on 32-bit EFI firmware.
Note that no boot loader changes should be necessary to take advantage of these patches, and if your bootloader of choice uses the EFI handover protocol (Syslinux, efilinux, Grub) you should automatically be able to boot a CONFIG_X86_64 kernel on 32-bit EFI by enabling CONFIG_EFI_MIXED.
This series does not implement mixed mode support for the EFI boot stub, so it won't work with gummiboot or directly from the EFI shell.
The full series is available on the 'mixed-mode' branch here,
git://git.kernel.org/pub/scm/linux/kernel/git/mfleming/efi.git
Matt Fleming (13):
x86/boot: Cleanup header.S by removing some #ifdefs x86, tools: Consolidate #ifdef code
x86/mm/pageattr: Always dump the right page table in an oops x86/efi: Delete dead code when checking for non-native
efi: Add separate 32-bit/64-bit definitions
x86/efi: Build our own EFI services pointer table x86/efi: Add early thunk code to go from 64-bit to 32-bit x86/efi: Split the boot stub into 32/64 code paths x86/efi: Firmware agnostic handover entry points x86/efi: Add mixed runtime services support
x86/efi: Wire up CONFIG_EFI_MIXED
x86/boot: Don't overwrite cr4 when enabling PAE x86/efi: Re-disable interrupts after calling firmware services
arch/x86/Kconfig | 14 + arch/x86/boot/Makefile | 2 +- arch/x86/boot/compressed/eboot.c | 1044 ++++++++++++++++++++++++++------ arch/x86/boot/compressed/eboot.h | 60 ++ arch/x86/boot/compressed/efi_stub_64.S | 29 + arch/x86/boot/compressed/head_32.S | 50 +- arch/x86/boot/compressed/head_64.S | 108 +++- arch/x86/boot/header.S | 23 +- arch/x86/boot/tools/build.c | 76 ++- arch/x86/include/asm/efi.h | 38 +- arch/x86/include/asm/pgtable_types.h | 2 + arch/x86/kernel/setup.c | 2 +- arch/x86/mm/fault.c | 7 +- arch/x86/mm/pageattr.c | 12 +- arch/x86/platform/efi/Makefile | 1 + arch/x86/platform/efi/efi.c | 170 +++--- arch/x86/platform/efi/efi_64.c | 328 +++++++++- arch/x86/platform/efi/efi_stub_64.S | 157 +++++ arch/x86/platform/efi/efi_thunk_64.S | 65 ++ drivers/firmware/efi/efi-stub-helper.c | 148 ++--- include/linux/efi.h | 252 ++++++++ 21 files changed, 2140 insertions(+), 448 deletions(-) create mode 100644 arch/x86/platform/efi/efi_thunk_64.S
Signature · 1 line
1.8.5.3
PATCH 1/13 x86/boot: Cleanup header.S by removing some #ifdefs
In reply to a message not in the archiveFrom: Matt Fleming <[email protected]>
handover_offset is now filled out by build.c. Don't set a default value as it will be overwritten anyway.
--- arch/x86/boot/header.S | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
arch/x86/boot/header.S +1 -7
@@ -426,13 +426,7 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr #define INIT_SIZE VO_INIT_SIZE #endif init_size: .long INIT_SIZE # kernel initialization size -handover_offset: -#ifdef CONFIG_EFI_STUB - .long 0x30 # offset to the handover - # protocol entry point -#else - .long 0 -#endif +handover_offset: .long 0 # Filled in by build.c # End of setup header #####################################################
Signature · 1 line
1.8.5.3
PATCH 2/13 x86, tools: Consolidate #ifdef code
In reply to a message not in the archiveFrom: Matt Fleming <[email protected]>
Instead of littering main() with #ifdef CONFIG_EFI_STUB, move the logic into separate functions that do nothing if the config option isn't set. This makes main() much easier to read.
--- arch/x86/boot/tools/build.c | 64 +++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 22 deletions(-)
arch/x86/boot/tools/build.c +42 -22
@@ -219,6 +219,45 @@ static void update_pecoff_text(unsigned int text_start, unsigned int file_sz)update_pecoff_section_header (".text" , text_start, text_sz); } +static int reserve_pecoff_reloc_section (int c) +{ +/* Reserve 0x20 bytes for .reloc section */ +memset (buf+c,0 ,PECOFF_RELOC_RESERVE ); +return PECOFF_RELOC_RESERVE ; +} + +static void efi_stub_defaults (void ) +{ +/* Defaults for old kernel */ +#ifdef CONFIG_X86_32 + efi_pe_entry =0x10 ; + efi_stub_entry =0x30 ; +#else + efi_pe_entry =0x210 ; + efi_stub_entry =0x230 ; + startup_64 =0x200 ; +#endif +} + +static void efi_stub_entry_update (void ) +{ +#ifdef CONFIG_X86_64 /* Yes, this is really how we defined it :( */ + efi_stub_entry -=0x200 ; +#endif +put_unaligned_le32 (efi_stub_entry, &buf[0x264 ]); +} + +#else + +static inline void update_pecoff_setup_and_reloc (unsigned int ) {} +static inline void update_pecoff_text (unsigned int ,unsigned int ) {} +static inline void efi_stub_defaults (void ) {} +static inline void efi_stup_entry_update (void ) {} + +static inline int reserve_pecoff_reloc_section (int c) +{ +return 0 ; +}#endif /* CONFIG_EFI_STUB */
@@ -271,15 +310,7 @@ int main(int argc, char ** argv)void *kernel;u32 crc =0xffffffffUL ; -/* Defaults for old kernel */ -#ifdef CONFIG_X86_32 - efi_pe_entry =0x10 ; - efi_stub_entry =0x30 ; -#else - efi_pe_entry =0x210 ; - efi_stub_entry =0x230 ; - startup_64 =0x200 ; -#endif +efi_stub_defaults ();if (argc !=5 )usage ();
@@ -302,11 +333,7 @@ int main(int argc, char ** argv)die ("Boot block hasn't got boot flag (0xAA55)" );fclose (file); -#ifdef CONFIG_EFI_STUB -/* Reserve 0x20 bytes for .reloc section */ -memset (buf+c,0 ,PECOFF_RELOC_RESERVE ); - c +=PECOFF_RELOC_RESERVE ; -#endif + c +=reserve_pecoff_reloc_section (c);/* Pad unused space with zeros */ setup_sectors = (c +511 ) /512 ;
@@ -315,9 +342,7 @@ int main(int argc, char ** argv) i = setup_sectors*512 ;memset (buf+c,0 , i-c); -#ifdef CONFIG_EFI_STUB update_pecoff_setup_and_reloc (i); -#endif /* Set the default root device */ put_unaligned_le16 (DEFAULT_ROOT_DEV , &buf[508 ]);
@@ -342,14 +367,9 @@ int main(int argc, char ** argv) buf[0x1f1 ] = setup_sectors-1 ;put_unaligned_le32 (sys_size, &buf[0x1f4 ]); -#ifdef CONFIG_EFI_STUB update_pecoff_text (setup_sectors *512 , sz + i + ((sys_size *16 ) - sz)); -#ifdef CONFIG_X86_64 /* Yes, this is really how we defined it :( */ - efi_stub_entry -=0x200 ; -#endif -put_unaligned_le32 (efi_stub_entry, &buf[0x264 ]); -#endif +efi_stub_entry_update (); crc =partial_crc32 (buf, i, crc);if (fwrite (buf,1 , i, dest) != i)
Signature · 1 line
1.8.5.3
PATCH 3/13 x86/mm/pageattr: Always dump the right page table in an oops
In reply to a message not in the archiveFrom: Matt Fleming <[email protected]>
Now that we have EFI-specific page tables we need to lookup the pgd when dumping those page tables, rather than assuming that swapper_pgdir is the current pgdir.
Remove the double underscore prefix, which is usually reserved for static functions.
--- arch/x86/include/asm/pgtable_types.h | 2 ++ arch/x86/mm/fault.c | 7 ++++++- arch/x86/mm/pageattr.c | 12 ++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-)
arch/x86/include/asm/pgtable_types.h +2 -0
@@ -381,6 +381,8 @@ static inline void update_page_count(int level, unsigned long pages) { }* as a pte too. */ extern pte_t *lookup_address (unsigned long address,unsigned int *level); +extern pte_t *lookup_address_in_pgd (pgd_t *pgd,unsigned long address, +unsigned int *level);extern phys_addr_t slow_virt_to_phys (void *__address);extern int kernel_map_pages_in_pgd (pgd_t *pgd,u64 pfn,unsigned long address,unsigned numpages,unsigned long page_flags);
arch/x86/mm/fault.c +6 -1
@@ -584,8 +584,13 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,if (error_code &PF_INSTR ) {unsigned int level; +pgd_t *pgd; +pte_t *pte; -pte_t *pte =lookup_address (address, &level); + pgd =__va (read_cr3 () &PHYSICAL_PAGE_MASK ); + pgd +=pgd_index (address); + + pte =lookup_address_in_pgd (pgd, address, &level);if (pte &&pte_present (*pte) && !pte_exec (*pte))printk (nx_warning,from_kuid (&init_user_ns,current_uid ()));
arch/x86/mm/pageattr.c +8 -4
@@ -323,8 +323,12 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,return prot; } -static pte_t *__lookup_address_in_pgd (pgd_t *pgd,unsigned long address, -unsigned int *level) +/* +* Lookup the page table entry for a virtual address in a specific pgd. +* Return a pointer to the entry and the level of the mapping. +*/ +pte_t *lookup_address_in_pgd (pgd_t *pgd,unsigned long address, +unsigned int *level) {pud_t *pud;pmd_t *pmd;
@@ -365,7 +369,7 @@ static pte_t *__lookup_address_in_pgd(pgd_t *pgd, unsigned long address,*/ pte_t *lookup_address (unsigned long address,unsigned int *level) { -return __lookup_address_in_pgd (pgd_offset_k (address), address, level); +return lookup_address_in_pgd (pgd_offset_k (address), address, level); }EXPORT_SYMBOL_GPL (lookup_address);
@@ -373,7 +377,7 @@ static pte_t *_lookup_address_cpa(struct cpa_data *cpa, unsigned long address, unsigned int *level) {if (cpa->pgd) -return __lookup_address_in_pgd (cpa->pgd +pgd_index (address), +return lookup_address_in_pgd (cpa->pgd +pgd_index (address), address, level);return lookup_address (address, level);
Signature · 1 line
1.8.5.3
PATCH 4/13 x86/efi: Delete dead code when checking for non-native
In reply to a message not in the archiveFrom: Matt Fleming <[email protected]>
Both efi_free_boot_services() and efi_enter_virtual_mode() are invoked from init/main.c, but only if the EFI runtime services are available. This is not the case for non-native boots, e.g. where a 64-bit kernel is booted with 32-bit EFI firmware.
Delete the dead code.
--- arch/x86/platform/efi/efi.c | 21 --------------------- 1 file changed, 21 deletions(-)
arch/x86/platform/efi/efi.c +0 -21
@@ -452,9 +452,6 @@ void __init efi_free_boot_services(void) {void *p; -if (!efi_is_native ()) -return ; -for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {efi_memory_desc_t *md = p;unsigned long long start = md->phys_addr;
@@ -979,15 +976,6 @@ static void __init kexec_enter_virtual_mode(void) efi.systab =NULL ;/* -* We don't do virtual mode, since we don't do runtime services, on -* non-native EFI -*/ -if (!efi_is_native ()) { -efi_unmap_memmap (); -return ; - } - -/* * Map efi regions which were passed via setup_data. The virt_addr is a * fixed addr which was used in first kernel of a kexec boot. */
@@ -1066,15 +1054,6 @@ static void __init __efi_enter_virtual_mode(void) efi.systab =NULL ; -/* -* We don't do virtual mode, since we don't do runtime services, on -* non-native EFI -*/ -if (!efi_is_native ()) { -efi_unmap_memmap (); -return ; - } -efi_merge_regions (); new_memmap =efi_map_regions (&count, &pg_shift);if (!new_memmap) {
Signature · 1 line
1.8.5.3
PATCH 5/13 efi: Add separate 32-bit/64-bit definitions
In reply to a message not in the archiveFrom: Matt Fleming <[email protected]>
The traditional approach of using machine-specific types such as 'unsigned long' does not allow the kernel to interact with firmware running in a different CPU mode, e.g. 64-bit kernel with 32-bit EFI.
Add distinct EFI structure definitions for both 32-bit and 64-bit so that we can use them in the 32-bit and 64-bit code paths.
--- arch/x86/boot/compressed/eboot.h | 44 +++++++ include/linux/efi.h | 252 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 296 insertions(+)
arch/x86/boot/compressed/eboot.h +44 -0
@@ -37,6 +37,24 @@ struct efi_graphics_output_mode_info {u32 pixels_per_scan_line; } __packed; +struct efi_graphics_output_protocol_mode_32 { +u32 max_mode; +u32 mode; +u32 info; +u32 size_of_info; +u64 frame_buffer_base; +u32 frame_buffer_size; +} __packed; + +struct efi_graphics_output_protocol_mode_64 { +u32 max_mode; +u32 mode; +u64 info; +u64 size_of_info; +u64 frame_buffer_base; +u64 frame_buffer_size; +} __packed; +struct efi_graphics_output_protocol_mode {u32 max_mode;u32 mode;
@@ -46,6 +64,20 @@ struct efi_graphics_output_protocol_mode {unsigned long frame_buffer_size; } __packed; +struct efi_graphics_output_protocol_32 { +u32 query_mode; +u32 set_mode; +u32 blt; +u32 mode; +}; + +struct efi_graphics_output_protocol_64 { +u64 query_mode; +u64 set_mode; +u64 blt; +u64 mode; +}; +struct efi_graphics_output_protocol {void *query_mode;unsigned long set_mode;
@@ -53,6 +85,18 @@ struct efi_graphics_output_protocol {struct efi_graphics_output_protocol_mode *mode; }; +struct efi_uga_draw_protocol_32 { +u32 get_mode; +u32 set_mode; +u32 blt; +}; + +struct efi_uga_draw_protocol_64 { +u64 get_mode; +u64 set_mode; +u64 blt; +}; +struct efi_uga_draw_protocol {void *get_mode;void *set_mode;
include/linux/efi.h +252 -0
294 lines not on this page · raw message
Signature · 1 line
1.8.5.3