From: Yinghai Lu <yinghai@kernel.org>
To: Kees Cook <keescook@chromium.org>,
"H. Peter Anvin" <hpa@zytor.com>, Baoquan He <bhe@redhat.com>
Cc: linux-kernel@vger.kernel.org, Yinghai Lu <yinghai@kernel.org>
Subject: [PATCH 28/42] x86, boot: Allow 64bit EFI kernel to be loaded above 4G
Date: Tue, 7 Jul 2015 13:20:14 -0700 [thread overview]
Message-ID: <1436300428-21163-29-git-send-email-yinghai@kernel.org> (raw)
In-Reply-To: <1436300428-21163-1-git-send-email-yinghai@kernel.org>
Now could use kexec to place kernel/boot_params/cmd_line/initrd
above 4G, but that is with legacy interface with startup_64 directly.
This patch will allow 64bit EFI kernel to be loaded above 4G
and use EFI HANDOVER PROTOCOL to start the kernel.
Current 32bit code32_start is used for passing around load address,
so it will overflow when kernel is loaded abover 4G.
The patch mainly add ext_code32_start to take load address high 32bits.
After this patch, could use patched grub2-x86_64.efi to place
kernel/boot_params/cmd_line/initrd all above 4G and execute the kernel
above 4G.
bootlog like:
kernel: done [ linux 9.25MiB 100% 6.66MiB/s ]
params: [1618fc000,1618fffff]
cmdline: [1618fb000,1618fb7fe]
kernel: [15e000000,161385fff]
initrd: [15bcbe000,15dffffbb]
initrd: 1 file done [ initrd.img 35.26MiB 100% 11.93MiB/s ]
early console in decompress_kernel
decompress_kernel:
input: [0x15fd0b3b4-0x16063c803], output: 0x15e000000, heap: [0x160645b00-0x16064daff]
Decompressing Linux... xz... Parsing ELF... done.
Booting the kernel.
[ 0.000000] bootconsole [uart0] enabled
[ 0.000000] real_mode_data : phys 00000001618fc000
[ 0.000000] real_mode_data : virt ffff8801618fc000
[ 0.000000] Kernel Layout:
[ 0.000000] .text: [0x15e000000-0x15f08f72c]
[ 0.000000] .rodata: [0x15f200000-0x15fa44fff]
[ 0.000000] .data: [0x15fc00000-0x15fe545ff]
[ 0.000000] .init: [0x15fe56000-0x16021afff]
[ 0.000000] .bss: [0x160229000-0x16135ffff]
[ 0.000000] .brk: [0x161360000-0x161385fff]
[ 0.000000] memblock_reserve: [0x0000000009f000-0x000000000fffff] flags 0x0 * BIOS reserved
...
[ 0.000000] memblock_reserve: [0x0000015e000000-0x0000016135ffff] flags 0x0 TEXT DATA BSS
[ 0.000000] memblock_reserve: [0x0000015bcbe000-0x0000015dffffff] flags 0x0 RAMDISK
-v2: add cast to avoid warning with 32bit, also update description for
ext_code32_start in boot.txt
-v3: change to 4.0 from 3.20.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
Documentation/x86/boot.txt | 19 +++++++++++++++++++
arch/x86/boot/compressed/eboot.c | 15 ++++++++++-----
arch/x86/boot/compressed/head_64.S | 7 ++++++-
| 3 ++-
arch/x86/include/uapi/asm/bootparam.h | 1 +
arch/x86/kernel/asm-offsets.c | 1 +
6 files changed, 39 insertions(+), 7 deletions(-)
diff --git a/Documentation/x86/boot.txt b/Documentation/x86/boot.txt
index 9da6f35..90efaa2 100644
--- a/Documentation/x86/boot.txt
+++ b/Documentation/x86/boot.txt
@@ -61,6 +61,9 @@ Protocol 2.12: (Kernel 3.8) Added the xloadflags field and extension fields
to struct boot_params for loading bzImage and ramdisk
above 4G in 64bit.
+Protocol 2.14: (Kernel 4.0) Added the ext_code32_start to support 64bit
+ EFI kernel to be loaded above 4G.
+
**** MEMORY LAYOUT
The traditional memory map for the kernel loader, used for Image or
@@ -197,6 +200,7 @@ Offset Proto Name Meaning
0258/8 2.10+ pref_address Preferred loading address
0260/4 2.10+ init_size Linear memory required during initialization
0264/4 2.11+ handover_offset Offset of handover entry point
+0268/4 2.14+ ext_code32_start Extended part for code32_start
(1) For backwards compatibility, if the setup_sects field contains 0, the
real value is 4.
@@ -744,6 +748,14 @@ Offset/size: 0x264/4
See EFI HANDOVER PROTOCOL below for more details.
+Field name: ext_code32_start
+Type: modify (optional, reloc)
+Offset/size: 0x268/4
+Protocol: 2.14+
+
+ This field is the upper 32bits of load address when EFI 64bit kernel
+ is loaded above 4G. And it is used with code32_start to compare to
+ pref_address to decide if kernel need to be relocated further.
**** THE IMAGE CHECKSUM
@@ -1127,4 +1139,11 @@ The boot loader *must* fill out the following fields in bp,
o hdr.ramdisk_image (if applicable)
o hdr.ramdisk_size (if applicable)
+for 64bit, when loading above 4G, *must* fill out the following fields,
+
+ o hdr.ext_code32_start
+ o ext_cmd_line_ptr
+ o ext_ramdisk_image (if applicable)
+ o ext_ramdisk_size (if applicable)
+
All other fields should be zero.
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 2c82bd1..05d77a5 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -1394,6 +1394,7 @@ struct boot_params *efi_main(struct efi_config *c,
void *handle;
efi_system_table_t *_table;
bool is64;
+ unsigned long loaded_addr;
efi_early = c;
@@ -1435,9 +1436,12 @@ struct boot_params *efi_main(struct efi_config *c,
* If the kernel isn't already loaded at the preferred load
* address, relocate it.
*/
- if (hdr->pref_address != hdr->code32_start) {
- unsigned long bzimage_addr = hdr->code32_start;
- status = efi_relocate_kernel(sys_table, &bzimage_addr,
+ loaded_addr = hdr->code32_start;
+ loaded_addr |= (unsigned long)((u64)hdr->ext_code32_start << 32);
+ if (hdr->pref_address != loaded_addr) {
+ unsigned long loaded_addr_orig = loaded_addr;
+
+ status = efi_relocate_kernel(sys_table, &loaded_addr,
hdr->init_size, hdr->init_size,
hdr->pref_address,
hdr->kernel_alignment);
@@ -1446,8 +1450,9 @@ struct boot_params *efi_main(struct efi_config *c,
goto fail;
}
- hdr->pref_address = hdr->code32_start;
- hdr->code32_start = bzimage_addr;
+ hdr->pref_address = loaded_addr_orig;
+ hdr->code32_start = loaded_addr & 0xffffffff;
+ hdr->ext_code32_start = (unsigned long)((u64)loaded_addr >> 32);
}
status = exit_boot(boot_params, handle, is64);
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index 075bb15..ab52d2c 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -266,6 +266,8 @@ ENTRY(efi_pe_entry)
mov %rax, %rsi
leaq startup_32(%rip), %rax
movl %eax, BP_code32_start(%rsi)
+ shr $32, %rax
+ movl %eax, BP_ext_code32_start(%rsi)
jmp 2f /* Skip the relocation */
handover_entry:
@@ -289,7 +291,10 @@ fail:
hlt
jmp fail
2:
- movl BP_code32_start(%esi), %eax
+ movl BP_code32_start(%rsi), %eax
+ movl BP_ext_code32_start(%rsi), %ebx
+ shl $32, %rbx
+ orq %rbx, %rax
leaq preferred_addr(%rax), %rax
jmp *%rax
--git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
index 99204e5..09e7c69 100644
--- a/arch/x86/boot/header.S
+++ b/arch/x86/boot/header.S
@@ -301,7 +301,7 @@ _start:
# Part 2 of the header, from the old setup.S
.ascii "HdrS" # header signature
- .word 0x020d # header version number (>= 0x0105)
+ .word 0x020e # header version number (>= 0x0105)
# or else old loadlin-1.5 will fail)
.globl realmode_swtch
realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
@@ -478,6 +478,7 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
#endif
init_size: .long INIT_SIZE # kernel initialization size
handover_offset: .long 0 # Filled in by build.c
+ext_code32_start: .long 0 # werid one!
# End of setup header #####################################################
diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index ab456dc..bb9973d 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -84,6 +84,7 @@ struct setup_header {
__u64 pref_address;
__u32 init_size;
__u32 handover_offset;
+ __u32 ext_code32_start;
} __attribute__((packed));
struct sys_desc_table {
diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
index d2e00bc..3f9789f 100644
--- a/arch/x86/kernel/asm-offsets.c
+++ b/arch/x86/kernel/asm-offsets.c
@@ -90,6 +90,7 @@ void common(void) {
OFFSET(BP_init_size, boot_params, hdr.init_size);
OFFSET(BP_pref_address, boot_params, hdr.pref_address);
OFFSET(BP_code32_start, boot_params, hdr.code32_start);
+ OFFSET(BP_ext_code32_start, boot_params, hdr.ext_code32_start);
BLANK();
DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
--
1.8.4.5
next prev parent reply other threads:[~2015-07-07 20:22 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-07 20:19 [PATCH 00/42] x86: updated patches for kaslr and setup_data etc for v4.3 Yinghai Lu
2015-07-07 20:19 ` [PATCH 01/42] x86, kasl: Remove not needed parameter for choose_kernel_location Yinghai Lu
2015-07-07 20:57 ` Kees Cook
2015-07-07 20:19 ` [PATCH 02/42] x86, boot: Move compressed kernel to end of buffer before decompressing Yinghai Lu
2015-07-07 21:22 ` Kees Cook
2015-07-07 20:19 ` [PATCH 03/42] x86, boot: Fix run_size calculation Yinghai Lu
2015-07-07 22:15 ` Kees Cook
2015-07-07 20:19 ` [PATCH 04/42] x86, kaslr: Kill not needed and wrong run_size calculation code Yinghai Lu
2015-07-07 22:18 ` Kees Cook
2015-07-07 20:19 ` [PATCH 05/42] x86, kaslr: rename output_size to output_run_size Yinghai Lu
2015-07-07 20:19 ` [PATCH 06/42] x86, kaslr: Consolidate mem_avoid array filling Yinghai Lu
2015-07-07 22:36 ` Kees Cook
2015-07-07 20:19 ` [PATCH 07/42] x86, boot: Move z_extract_offset calculation to header.S Yinghai Lu
2015-07-07 20:19 ` [PATCH 08/42] x86, kaslr: Get correct max_addr for relocs pointer Yinghai Lu
2015-07-07 22:40 ` Kees Cook
2015-07-07 20:19 ` [PATCH 09/42] x86, boot: Split kernel_ident_mapping_init to another file Yinghai Lu
2015-07-07 20:19 ` [PATCH 10/42] x86, 64bit: Set ident_mapping for kaslr Yinghai Lu
2015-07-07 20:19 ` [PATCH 11/42] x86, boot: Add checking for memcpy Yinghai Lu
2015-07-07 20:19 ` [PATCH 12/42] x86, kaslr: Fix a bug that relocation can not be handled when kernel is loaded above 2G Yinghai Lu
2015-07-07 22:42 ` Kees Cook
2015-07-07 20:19 ` [PATCH 13/42] x86, kaslr: Introduce struct slot_area to manage randomization slot info Yinghai Lu
2015-07-07 20:20 ` [PATCH 14/42] x86, kaslr: Add two functions which will be used later Yinghai Lu
2015-07-07 20:20 ` [PATCH 15/42] x86, kaslr: Introduce fetch_random_virt_offset to randomize the kernel text mapping address Yinghai Lu
2015-07-07 20:20 ` [PATCH 16/42] x86, kaslr: Randomize physical and virtual address of kernel separately Yinghai Lu
2015-07-07 20:20 ` [PATCH 17/42] x86, kaslr: Add support of kernel physical address randomization above 4G Yinghai Lu
2015-07-07 20:20 ` [PATCH 18/42] x86, kaslr: Remove useless codes Yinghai Lu
2015-07-07 20:20 ` [PATCH 19/42] x86, kaslr: Allow random address could be below loaded address Yinghai Lu
2015-07-07 20:20 ` [PATCH 20/42] x86, boot: Add printf support for early console in compressed/misc.c Yinghai Lu
2015-07-07 20:20 ` [PATCH 21/42] x86, boot: Add more debug printout " Yinghai Lu
2015-07-07 20:20 ` [PATCH 22/42] x86, setup: Check early serial console per string instead of one char Yinghai Lu
2015-07-07 22:59 ` Kees Cook
2015-07-07 20:20 ` [PATCH 23/42] x86, setup: Use puts() instead of printf() in edd code Yinghai Lu
2015-07-07 20:20 ` [PATCH 24/42] x86: Setup early console as early as possible in x86_start_kernel() Yinghai Lu
2015-07-07 20:20 ` [PATCH 25/42] x86, boot: print compression suffix in decompress stage Yinghai Lu
2015-07-07 23:13 ` Kees Cook
2015-07-07 20:20 ` [PATCH 26/42] x86: remove not needed clear_page calling Yinghai Lu
2015-07-07 23:14 ` Kees Cook
2015-07-07 20:20 ` [PATCH 27/42] x86: restore end_of_ram to E820_RAM Yinghai Lu
2015-07-08 17:44 ` Matt Fleming
2015-07-09 1:41 ` Dan Williams
2015-07-09 7:45 ` Christoph Hellwig
2015-07-09 11:17 ` Matt Fleming
2015-07-07 20:20 ` Yinghai Lu [this message]
2015-07-07 23:12 ` [PATCH 28/42] x86, boot: Allow 64bit EFI kernel to be loaded above 4G Kees Cook
2015-07-08 18:00 ` Matt Fleming
2015-07-07 20:20 ` [PATCH 29/42] x86: Find correct 64 bit ramdisk address for microcode early update Yinghai Lu
2015-07-07 23:08 ` Kees Cook
2015-07-07 20:20 ` [PATCH 30/42] x86: Kill E820_RESERVED_KERN Yinghai Lu
2015-07-07 20:20 ` [PATCH 31/42] x86, efi: Copy SETUP_EFI data and access directly Yinghai Lu
2015-07-22 10:58 ` Matt Fleming
2015-07-24 2:07 ` Dave Young
2015-07-07 20:20 ` [PATCH 32/42] x86, of: Let add_dtb reserve setup_data locally Yinghai Lu
2015-07-07 20:20 ` [PATCH 33/42] x86, boot: Add add_pci handler for SETUP_PCI Yinghai Lu
2015-07-14 22:30 ` Bjorn Helgaas
2015-07-07 20:20 ` [PATCH 34/42] x86: Kill not used setup_data handling code Yinghai Lu
2015-07-07 20:20 ` [PATCH 35/42] x86, boot, PCI: Convert SETUP_PCI data to list Yinghai Lu
2015-07-14 22:35 ` Bjorn Helgaas
2015-07-15 1:57 ` Yinghai Lu
2015-07-07 20:20 ` [PATCH 36/42] x86, boot, PCI: Copy SETUP_PCI rom to kernel space Yinghai Lu
2015-07-07 20:20 ` [PATCH 37/42] x86, boot, PCI: Export SETUP_PCI data via sysfs Yinghai Lu
2015-07-07 20:20 ` [PATCH 38/42] x86: Fix typo in mark_rodata_ro Yinghai Lu
2015-07-07 23:05 ` Kees Cook
2015-07-07 20:20 ` [PATCH 39/42] x86, 64bit: add pfn_range_is_highmapped() Yinghai Lu
2015-07-07 20:20 ` [PATCH 40/42] x86, 64bit: remove highmap for not needed ranges Yinghai Lu
2015-07-07 23:17 ` Kees Cook
2015-07-07 20:20 ` [PATCH 41/42] x86, 64bit: Add __pa_high/__va_high Yinghai Lu
2015-07-07 20:20 ` [PATCH 42/42] x86: fix msr print again Yinghai Lu
2015-07-07 23:21 ` [PATCH 00/42] x86: updated patches for kaslr and setup_data etc for v4.3 Kees Cook
2015-10-02 20:16 ` Kees Cook
2016-02-06 11:50 ` Baoquan He
2016-02-09 4:31 ` Kees Cook
2016-02-15 7:29 ` Baoquan He
2016-02-16 23:50 ` Kees Cook
2015-07-08 10:51 ` Ingo Molnar
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=1436300428-21163-29-git-send-email-yinghai@kernel.org \
--to=yinghai@kernel.org \
--cc=bhe@redhat.com \
--cc=hpa@zytor.com \
--cc=keescook@chromium.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
Powered by JetHome