1 | From: Ard Biesheuvel <ardb@kernel.org> | 1 | From: Ard Biesheuvel <ardb@kernel.org> |
---|---|---|---|
2 | 2 | ||
3 | Start refactoring the x86 startup code so we keep all the code that is | 3 | v2: |
4 | shared between different boot stages (EFI stub, decompressor, early | 4 | - drop queued patches #1 - #4 |
5 | startup in the core kernel *) and/or needs to be built in a special way | 5 | - keep exported symbols out of startup/ |
6 | (due to the fact that it is C code that runs from the 1:1 mapping of | 6 | - rebase onto tip/x86/boot |
7 | RAM) in a single place, sharing all the C flags and other runes that are | ||
8 | needed to disable instrumentation, sanitizers, etc. | ||
9 | 7 | ||
10 | This is an RFC so I have left some things for later, e.g., the SEV-SNP | 8 | Ard Biesheuvel (2): |
11 | init code in arch/x86/coco that is shared between all of the above [*] | ||
12 | and will be tricky to disentangle; there are also some known issues in | ||
13 | that code related to EFI boot that we are addressing in parallel. | ||
14 | |||
15 | Cc: Tom Lendacky <thomas.lendacky@amd.com> | ||
16 | Cc: Dionna Amalie Glaze <dionnaglaze@google.com> | ||
17 | Cc: Kevin Loughlin <kevinloughlin@google.com> | ||
18 | |||
19 | Ard Biesheuvel (6): | ||
20 | x86/boot/compressed: Merge local pgtable.h include into asm/boot.h | ||
21 | x86/boot: Move 5-level paging trampoline into startup code | ||
22 | x86/boot: Move EFI mixed mode startup code back under arch/x86 | ||
23 | x86/boot: Move early GDT/IDT setup code into startup/ | ||
24 | x86/boot: Move early kernel mapping code into startup/ | 9 | x86/boot: Move early kernel mapping code into startup/ |
25 | x86/boot: Move early SME init code into startup/ | 10 | x86/boot: Move early SME init code into startup/ |
26 | 11 | ||
27 | arch/x86/Makefile | 1 + | 12 | arch/x86/boot/startup/Makefile | 3 +- |
28 | arch/x86/boot/compressed/Makefile | 4 +- | 13 | arch/x86/boot/startup/map_kernel.c | 215 ++++++++++++++++++++ |
29 | arch/x86/boot/compressed/head_64.S | 1 - | 14 | arch/x86/{mm/mem_encrypt_identity.c => boot/startup/sme.c} | 45 ++-- |
30 | arch/x86/boot/compressed/misc.c | 1 - | 15 | arch/x86/include/asm/mem_encrypt.h | 2 +- |
31 | arch/x86/boot/compressed/pgtable.h | 18 -- | 16 | arch/x86/kernel/head64.c | 211 +------------------ |
32 | arch/x86/boot/compressed/pgtable_64.c | 1 - | 17 | arch/x86/mm/Makefile | 6 - |
33 | arch/x86/boot/startup/Makefile | 22 ++ | 18 | 6 files changed, 240 insertions(+), 242 deletions(-) |
34 | drivers/firmware/efi/libstub/x86-mixed.S => arch/x86/boot/startup/efi-mixed.S | 0 | ||
35 | arch/x86/boot/startup/gdt_idt.c | 82 ++++++ | ||
36 | arch/x86/boot/{compressed => startup}/la57toggle.S | 1 - | ||
37 | arch/x86/boot/startup/map_kernel.c | 232 +++++++++++++++ | ||
38 | arch/x86/{mm/mem_encrypt_identity.c => boot/startup/sme.c} | 45 ++- | ||
39 | arch/x86/include/asm/boot.h | 10 + | ||
40 | arch/x86/include/asm/mem_encrypt.h | 2 +- | ||
41 | arch/x86/kernel/head64.c | 302 +------------------- | ||
42 | arch/x86/mm/Makefile | 6 - | ||
43 | drivers/firmware/efi/libstub/Makefile | 1 - | ||
44 | 17 files changed, 372 insertions(+), 357 deletions(-) | ||
45 | delete mode 100644 arch/x86/boot/compressed/pgtable.h | ||
46 | create mode 100644 arch/x86/boot/startup/Makefile | ||
47 | rename drivers/firmware/efi/libstub/x86-mixed.S => arch/x86/boot/startup/efi-mixed.S (100%) | ||
48 | create mode 100644 arch/x86/boot/startup/gdt_idt.c | ||
49 | rename arch/x86/boot/{compressed => startup}/la57toggle.S (99%) | ||
50 | create mode 100644 arch/x86/boot/startup/map_kernel.c | 19 | create mode 100644 arch/x86/boot/startup/map_kernel.c |
51 | rename arch/x86/{mm/mem_encrypt_identity.c => boot/startup/sme.c} (92%) | 20 | rename arch/x86/{mm/mem_encrypt_identity.c => boot/startup/sme.c} (92%) |
52 | 21 | ||
22 | |||
23 | base-commit: cc34e658c6db493c1524077e95b42d478de58f2b | ||
53 | -- | 24 | -- |
54 | 2.49.0.472.ge94155a9ec-goog | 25 | 2.49.0.504.g3bcea36a83-goog | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Ard Biesheuvel <ardb@kernel.org> | ||
2 | 1 | ||
3 | Merge the local include "pgtable.h" -which declares the API of the | ||
4 | 5-level paging trampoline- into <asm/boot.h> so that its implementation | ||
5 | in la57toggle.S as well as the calling code can be decoupled from the | ||
6 | traditional decompressor. | ||
7 | |||
8 | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||
9 | --- | ||
10 | arch/x86/boot/compressed/head_64.S | 1 - | ||
11 | arch/x86/boot/compressed/la57toggle.S | 1 - | ||
12 | arch/x86/boot/compressed/misc.c | 1 - | ||
13 | arch/x86/boot/compressed/pgtable.h | 18 ------------------ | ||
14 | arch/x86/boot/compressed/pgtable_64.c | 1 - | ||
15 | arch/x86/include/asm/boot.h | 10 ++++++++++ | ||
16 | 6 files changed, 10 insertions(+), 22 deletions(-) | ||
17 | |||
18 | diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/arch/x86/boot/compressed/head_64.S | ||
21 | +++ b/arch/x86/boot/compressed/head_64.S | ||
22 | @@ -XXX,XX +XXX,XX @@ | ||
23 | #include <asm/bootparam.h> | ||
24 | #include <asm/desc_defs.h> | ||
25 | #include <asm/trapnr.h> | ||
26 | -#include "pgtable.h" | ||
27 | |||
28 | /* | ||
29 | * Fix alignment at 16 bytes. Following CONFIG_FUNCTION_ALIGNMENT will result | ||
30 | diff --git a/arch/x86/boot/compressed/la57toggle.S b/arch/x86/boot/compressed/la57toggle.S | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/arch/x86/boot/compressed/la57toggle.S | ||
33 | +++ b/arch/x86/boot/compressed/la57toggle.S | ||
34 | @@ -XXX,XX +XXX,XX @@ | ||
35 | #include <asm/boot.h> | ||
36 | #include <asm/msr.h> | ||
37 | #include <asm/processor-flags.h> | ||
38 | -#include "pgtable.h" | ||
39 | |||
40 | /* | ||
41 | * This is the 32-bit trampoline that will be copied over to low memory. It | ||
42 | diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/arch/x86/boot/compressed/misc.c | ||
45 | +++ b/arch/x86/boot/compressed/misc.c | ||
46 | @@ -XXX,XX +XXX,XX @@ | ||
47 | |||
48 | #include "misc.h" | ||
49 | #include "error.h" | ||
50 | -#include "pgtable.h" | ||
51 | #include "../string.h" | ||
52 | #include "../voffset.h" | ||
53 | #include <asm/bootparam_utils.h> | ||
54 | diff --git a/arch/x86/boot/compressed/pgtable.h b/arch/x86/boot/compressed/pgtable.h | ||
55 | deleted file mode 100644 | ||
56 | index XXXXXXX..XXXXXXX | ||
57 | --- a/arch/x86/boot/compressed/pgtable.h | ||
58 | +++ /dev/null | ||
59 | @@ -XXX,XX +XXX,XX @@ | ||
60 | -#ifndef BOOT_COMPRESSED_PAGETABLE_H | ||
61 | -#define BOOT_COMPRESSED_PAGETABLE_H | ||
62 | - | ||
63 | -#define TRAMPOLINE_32BIT_SIZE (2 * PAGE_SIZE) | ||
64 | - | ||
65 | -#define TRAMPOLINE_32BIT_CODE_OFFSET PAGE_SIZE | ||
66 | -#define TRAMPOLINE_32BIT_CODE_SIZE 0xA0 | ||
67 | - | ||
68 | -#ifndef __ASSEMBLER__ | ||
69 | - | ||
70 | -extern unsigned long *trampoline_32bit; | ||
71 | - | ||
72 | -extern void trampoline_32bit_src(void *trampoline, bool enable_5lvl); | ||
73 | - | ||
74 | -extern const u16 trampoline_ljmp_imm_offset; | ||
75 | - | ||
76 | -#endif /* __ASSEMBLER__ */ | ||
77 | -#endif /* BOOT_COMPRESSED_PAGETABLE_H */ | ||
78 | diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compressed/pgtable_64.c | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/arch/x86/boot/compressed/pgtable_64.c | ||
81 | +++ b/arch/x86/boot/compressed/pgtable_64.c | ||
82 | @@ -XXX,XX +XXX,XX @@ | ||
83 | #include <asm/bootparam_utils.h> | ||
84 | #include <asm/e820/types.h> | ||
85 | #include <asm/processor.h> | ||
86 | -#include "pgtable.h" | ||
87 | #include "../string.h" | ||
88 | #include "efi.h" | ||
89 | |||
90 | diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h | ||
91 | index XXXXXXX..XXXXXXX 100644 | ||
92 | --- a/arch/x86/include/asm/boot.h | ||
93 | +++ b/arch/x86/include/asm/boot.h | ||
94 | @@ -XXX,XX +XXX,XX @@ | ||
95 | # define BOOT_STACK_SIZE 0x1000 | ||
96 | #endif | ||
97 | |||
98 | +#define TRAMPOLINE_32BIT_SIZE (2 * PAGE_SIZE) | ||
99 | + | ||
100 | +#define TRAMPOLINE_32BIT_CODE_OFFSET PAGE_SIZE | ||
101 | +#define TRAMPOLINE_32BIT_CODE_SIZE 0xA0 | ||
102 | + | ||
103 | #ifndef __ASSEMBLER__ | ||
104 | extern unsigned int output_len; | ||
105 | extern const unsigned long kernel_text_size; | ||
106 | @@ -XXX,XX +XXX,XX @@ unsigned long decompress_kernel(unsigned char *outbuf, unsigned long virt_addr, | ||
107 | void (*error)(char *x)); | ||
108 | |||
109 | extern struct boot_params *boot_params_ptr; | ||
110 | +extern unsigned long *trampoline_32bit; | ||
111 | +extern const u16 trampoline_ljmp_imm_offset; | ||
112 | + | ||
113 | +void trampoline_32bit_src(void *trampoline, bool enable_5lvl); | ||
114 | + | ||
115 | #endif | ||
116 | |||
117 | #endif /* _ASM_X86_BOOT_H */ | ||
118 | -- | ||
119 | 2.49.0.472.ge94155a9ec-goog | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Ard Biesheuvel <ardb@kernel.org> | ||
2 | 1 | ||
3 | The 5-level paging trampoline is used by both the EFI stub and the | ||
4 | traditional decompressor. Move it out of the decompressor sources into | ||
5 | the newly minted arch/x86/boot/startup/ sub-directory which will hold | ||
6 | startup code that may be shared between the decompressor, the EFI stub | ||
7 | and the kernel proper, and needs to tolerate being called during early | ||
8 | boot, before the kernel virtual mapping has been created. | ||
9 | |||
10 | This will allow the 5-level paging trampoline to be used by EFI boot | ||
11 | images such as zboot that omit the traditional decompressor entirely. | ||
12 | |||
13 | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||
14 | --- | ||
15 | arch/x86/Makefile | 1 + | ||
16 | arch/x86/boot/compressed/Makefile | 2 +- | ||
17 | arch/x86/boot/startup/Makefile | 3 +++ | ||
18 | arch/x86/boot/{compressed => startup}/la57toggle.S | 0 | ||
19 | 4 files changed, 5 insertions(+), 1 deletion(-) | ||
20 | |||
21 | diff --git a/arch/x86/Makefile b/arch/x86/Makefile | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/arch/x86/Makefile | ||
24 | +++ b/arch/x86/Makefile | ||
25 | @@ -XXX,XX +XXX,XX @@ archprepare: $(cpufeaturemasks.hdr) | ||
26 | ### | ||
27 | # Kernel objects | ||
28 | |||
29 | +core-y += arch/x86/boot/startup/ | ||
30 | libs-y += arch/x86/lib/ | ||
31 | |||
32 | # drivers-y are linked after core-y | ||
33 | diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/arch/x86/boot/compressed/Makefile | ||
36 | +++ b/arch/x86/boot/compressed/Makefile | ||
37 | @@ -XXX,XX +XXX,XX @@ ifdef CONFIG_X86_64 | ||
38 | vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/mem_encrypt.o | ||
39 | vmlinux-objs-y += $(obj)/pgtable_64.o | ||
40 | vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev.o | ||
41 | - vmlinux-objs-y += $(obj)/la57toggle.o | ||
42 | endif | ||
43 | |||
44 | vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o | ||
45 | @@ -XXX,XX +XXX,XX @@ vmlinux-objs-$(CONFIG_UNACCEPTED_MEMORY) += $(obj)/mem.o | ||
46 | |||
47 | vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o | ||
48 | vmlinux-libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a | ||
49 | +vmlinux-libs-$(CONFIG_X86_64) += $(objtree)/arch/x86/boot/startup/lib.a | ||
50 | |||
51 | $(obj)/vmlinux: $(vmlinux-objs-y) $(vmlinux-libs-y) FORCE | ||
52 | $(call if_changed,ld) | ||
53 | diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile | ||
54 | new file mode 100644 | ||
55 | index XXXXXXX..XXXXXXX | ||
56 | --- /dev/null | ||
57 | +++ b/arch/x86/boot/startup/Makefile | ||
58 | @@ -XXX,XX +XXX,XX @@ | ||
59 | +# SPDX-License-Identifier: GPL-2.0 | ||
60 | + | ||
61 | +lib-$(CONFIG_X86_64) += la57toggle.o | ||
62 | diff --git a/arch/x86/boot/compressed/la57toggle.S b/arch/x86/boot/startup/la57toggle.S | ||
63 | similarity index 100% | ||
64 | rename from arch/x86/boot/compressed/la57toggle.S | ||
65 | rename to arch/x86/boot/startup/la57toggle.S | ||
66 | -- | ||
67 | 2.49.0.472.ge94155a9ec-goog | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Ard Biesheuvel <ardb@kernel.org> | ||
2 | 1 | ||
3 | Linus expressed a strong preference for arch-specific asm code (i.e., | ||
4 | virtually all of it) to reside under arch/ rather than anywhere else. | ||
5 | |||
6 | So move the EFI mixed mode startup code back, and put it under | ||
7 | arch/x86/boot/startup/ where all shared x86 startup code is going to | ||
8 | live. | ||
9 | |||
10 | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||
11 | --- | ||
12 | arch/x86/boot/startup/Makefile | 3 +++ | ||
13 | drivers/firmware/efi/libstub/x86-mixed.S => arch/x86/boot/startup/efi-mixed.S | 0 | ||
14 | drivers/firmware/efi/libstub/Makefile | 1 - | ||
15 | 3 files changed, 3 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/arch/x86/boot/startup/Makefile | ||
20 | +++ b/arch/x86/boot/startup/Makefile | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | # SPDX-License-Identifier: GPL-2.0 | ||
23 | |||
24 | +KBUILD_AFLAGS += -D__DISABLE_EXPORTS | ||
25 | + | ||
26 | lib-$(CONFIG_X86_64) += la57toggle.o | ||
27 | +lib-$(CONFIG_EFI_MIXED) += efi-mixed.o | ||
28 | diff --git a/drivers/firmware/efi/libstub/x86-mixed.S b/arch/x86/boot/startup/efi-mixed.S | ||
29 | similarity index 100% | ||
30 | rename from drivers/firmware/efi/libstub/x86-mixed.S | ||
31 | rename to arch/x86/boot/startup/efi-mixed.S | ||
32 | diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/drivers/firmware/efi/libstub/Makefile | ||
35 | +++ b/drivers/firmware/efi/libstub/Makefile | ||
36 | @@ -XXX,XX +XXX,XX @@ lib-$(CONFIG_EFI_GENERIC_STUB) += efi-stub.o string.o intrinsics.o systable.o \ | ||
37 | lib-$(CONFIG_ARM) += arm32-stub.o | ||
38 | lib-$(CONFIG_ARM64) += kaslr.o arm64.o arm64-stub.o smbios.o | ||
39 | lib-$(CONFIG_X86) += x86-stub.o smbios.o | ||
40 | -lib-$(CONFIG_EFI_MIXED) += x86-mixed.o | ||
41 | lib-$(CONFIG_X86_64) += x86-5lvl.o | ||
42 | lib-$(CONFIG_RISCV) += kaslr.o riscv.o riscv-stub.o | ||
43 | lib-$(CONFIG_LOONGARCH) += loongarch.o loongarch-stub.o | ||
44 | -- | ||
45 | 2.49.0.472.ge94155a9ec-goog | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Ard Biesheuvel <ardb@kernel.org> | ||
2 | 1 | ||
3 | Move the early GDT/IDT setup code that runs long before the kernel | ||
4 | virtual mapping is up into arch/x86/boot/startup/, and build it in a way | ||
5 | that ensures that the code tolerates being called from the 1:1 mapping | ||
6 | of memory. | ||
7 | |||
8 | This allows the RIP_REL_REF() macro uses to be dropped, and removes the | ||
9 | need for emitting the code into the special .head.text section. | ||
10 | |||
11 | Also tweak the sed symbol matching pattern in the decompressor to match | ||
12 | on lower case 't' or 'b', as these will be emitted by Clang for symbols | ||
13 | with hidden linkage. | ||
14 | |||
15 | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | ||
16 | --- | ||
17 | arch/x86/boot/compressed/Makefile | 2 +- | ||
18 | arch/x86/boot/startup/Makefile | 15 ++++ | ||
19 | arch/x86/boot/startup/gdt_idt.c | 82 ++++++++++++++++++++ | ||
20 | arch/x86/kernel/head64.c | 74 ------------------ | ||
21 | 4 files changed, 98 insertions(+), 75 deletions(-) | ||
22 | |||
23 | diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/arch/x86/boot/compressed/Makefile | ||
26 | +++ b/arch/x86/boot/compressed/Makefile | ||
27 | @@ -XXX,XX +XXX,XX @@ LDFLAGS_vmlinux += -T | ||
28 | hostprogs := mkpiggy | ||
29 | HOST_EXTRACFLAGS += -I$(srctree)/tools/include | ||
30 | |||
31 | -sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__start_rodata\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' | ||
32 | +sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__start_rodata\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' | ||
33 | |||
34 | quiet_cmd_voffset = VOFFSET $@ | ||
35 | cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@ | ||
36 | diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/arch/x86/boot/startup/Makefile | ||
39 | +++ b/arch/x86/boot/startup/Makefile | ||
40 | @@ -XXX,XX +XXX,XX @@ | ||
41 | # SPDX-License-Identifier: GPL-2.0 | ||
42 | |||
43 | KBUILD_AFLAGS += -D__DISABLE_EXPORTS | ||
44 | +KBUILD_CFLAGS += -D__DISABLE_EXPORTS -mcmodel=small -fPIC \ | ||
45 | + -Os -DDISABLE_BRANCH_PROFILING \ | ||
46 | + $(DISABLE_STACKLEAK_PLUGIN) \ | ||
47 | + -fno-stack-protector -D__NO_FORTIFY \ | ||
48 | + -include $(srctree)/include/linux/hidden.h | ||
49 | + | ||
50 | +# disable ftrace hooks | ||
51 | +KBUILD_CFLAGS := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) | ||
52 | +KASAN_SANITIZE := n | ||
53 | +KCSAN_SANITIZE := n | ||
54 | +KMSAN_SANITIZE := n | ||
55 | +UBSAN_SANITIZE := n | ||
56 | +KCOV_INSTRUMENT := n | ||
57 | + | ||
58 | +obj-$(CONFIG_X86_64) += gdt_idt.o | ||
59 | |||
60 | lib-$(CONFIG_X86_64) += la57toggle.o | ||
61 | lib-$(CONFIG_EFI_MIXED) += efi-mixed.o | ||
62 | diff --git a/arch/x86/boot/startup/gdt_idt.c b/arch/x86/boot/startup/gdt_idt.c | ||
63 | new file mode 100644 | ||
64 | index XXXXXXX..XXXXXXX | ||
65 | --- /dev/null | ||
66 | +++ b/arch/x86/boot/startup/gdt_idt.c | ||
67 | @@ -XXX,XX +XXX,XX @@ | ||
68 | +// SPDX-License-Identifier: GPL-2.0 | ||
69 | + | ||
70 | +#include <linux/linkage.h> | ||
71 | +#include <linux/types.h> | ||
72 | + | ||
73 | +#include <asm/desc.h> | ||
74 | +#include <asm/setup.h> | ||
75 | +#include <asm/sev.h> | ||
76 | +#include <asm/trapnr.h> | ||
77 | + | ||
78 | +/* | ||
79 | + * Data structures and code used for IDT setup in head_64.S. The bringup-IDT is | ||
80 | + * used until the idt_table takes over. On the boot CPU this happens in | ||
81 | + * x86_64_start_kernel(), on secondary CPUs in start_secondary(). In both cases | ||
82 | + * this happens in the functions called from head_64.S. | ||
83 | + * | ||
84 | + * The idt_table can't be used that early because all the code modifying it is | ||
85 | + * in idt.c and can be instrumented by tracing or KASAN, which both don't work | ||
86 | + * during early CPU bringup. Also the idt_table has the runtime vectors | ||
87 | + * configured which require certain CPU state to be setup already (like TSS), | ||
88 | + * which also hasn't happened yet in early CPU bringup. | ||
89 | + */ | ||
90 | +static gate_desc bringup_idt_table[NUM_EXCEPTION_VECTORS] __page_aligned_data; | ||
91 | + | ||
92 | +/* This may run while still in the direct mapping */ | ||
93 | +static void startup_64_load_idt(void *vc_handler) | ||
94 | +{ | ||
95 | + struct desc_ptr desc = { | ||
96 | + .address = (unsigned long)bringup_idt_table, | ||
97 | + .size = sizeof(bringup_idt_table) - 1, | ||
98 | + }; | ||
99 | + struct idt_data data; | ||
100 | + gate_desc idt_desc; | ||
101 | + | ||
102 | + /* @vc_handler is set only for a VMM Communication Exception */ | ||
103 | + if (vc_handler) { | ||
104 | + init_idt_data(&data, X86_TRAP_VC, vc_handler); | ||
105 | + idt_init_desc(&idt_desc, &data); | ||
106 | + native_write_idt_entry((gate_desc *)desc.address, X86_TRAP_VC, &idt_desc); | ||
107 | + } | ||
108 | + | ||
109 | + native_load_idt(&desc); | ||
110 | +} | ||
111 | + | ||
112 | +/* This is used when running on kernel addresses */ | ||
113 | +void early_setup_idt(void) | ||
114 | +{ | ||
115 | + void *handler = NULL; | ||
116 | + | ||
117 | + if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { | ||
118 | + setup_ghcb(); | ||
119 | + handler = vc_boot_ghcb; | ||
120 | + } | ||
121 | + | ||
122 | + startup_64_load_idt(handler); | ||
123 | +} | ||
124 | + | ||
125 | +/* | ||
126 | + * Setup boot CPU state needed before kernel switches to virtual addresses. | ||
127 | + */ | ||
128 | +void __init startup_64_setup_gdt_idt(void) | ||
129 | +{ | ||
130 | + void *handler = NULL; | ||
131 | + | ||
132 | + struct desc_ptr startup_gdt_descr = { | ||
133 | + .address = (__force unsigned long)gdt_page.gdt, | ||
134 | + .size = GDT_SIZE - 1, | ||
135 | + }; | ||
136 | + | ||
137 | + /* Load GDT */ | ||
138 | + native_load_gdt(&startup_gdt_descr); | ||
139 | + | ||
140 | + /* New GDT is live - reload data segment registers */ | ||
141 | + asm volatile("movl %%eax, %%ds\n" | ||
142 | + "movl %%eax, %%ss\n" | ||
143 | + "movl %%eax, %%es\n" : : "a"(__KERNEL_DS) : "memory"); | ||
144 | + | ||
145 | + if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) | ||
146 | + handler = vc_no_ghcb; | ||
147 | + | ||
148 | + startup_64_load_idt(handler); | ||
149 | +} | ||
150 | diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c | ||
151 | index XXXXXXX..XXXXXXX 100644 | ||
152 | --- a/arch/x86/kernel/head64.c | ||
153 | +++ b/arch/x86/kernel/head64.c | ||
154 | @@ -XXX,XX +XXX,XX @@ void __init __noreturn x86_64_start_reservations(char *real_mode_data) | ||
155 | |||
156 | start_kernel(); | ||
157 | } | ||
158 | - | ||
159 | -/* | ||
160 | - * Data structures and code used for IDT setup in head_64.S. The bringup-IDT is | ||
161 | - * used until the idt_table takes over. On the boot CPU this happens in | ||
162 | - * x86_64_start_kernel(), on secondary CPUs in start_secondary(). In both cases | ||
163 | - * this happens in the functions called from head_64.S. | ||
164 | - * | ||
165 | - * The idt_table can't be used that early because all the code modifying it is | ||
166 | - * in idt.c and can be instrumented by tracing or KASAN, which both don't work | ||
167 | - * during early CPU bringup. Also the idt_table has the runtime vectors | ||
168 | - * configured which require certain CPU state to be setup already (like TSS), | ||
169 | - * which also hasn't happened yet in early CPU bringup. | ||
170 | - */ | ||
171 | -static gate_desc bringup_idt_table[NUM_EXCEPTION_VECTORS] __page_aligned_data; | ||
172 | - | ||
173 | -/* This may run while still in the direct mapping */ | ||
174 | -static void __head startup_64_load_idt(void *vc_handler) | ||
175 | -{ | ||
176 | - struct desc_ptr desc = { | ||
177 | - .address = (unsigned long)&RIP_REL_REF(bringup_idt_table), | ||
178 | - .size = sizeof(bringup_idt_table) - 1, | ||
179 | - }; | ||
180 | - struct idt_data data; | ||
181 | - gate_desc idt_desc; | ||
182 | - | ||
183 | - /* @vc_handler is set only for a VMM Communication Exception */ | ||
184 | - if (vc_handler) { | ||
185 | - init_idt_data(&data, X86_TRAP_VC, vc_handler); | ||
186 | - idt_init_desc(&idt_desc, &data); | ||
187 | - native_write_idt_entry((gate_desc *)desc.address, X86_TRAP_VC, &idt_desc); | ||
188 | - } | ||
189 | - | ||
190 | - native_load_idt(&desc); | ||
191 | -} | ||
192 | - | ||
193 | -/* This is used when running on kernel addresses */ | ||
194 | -void early_setup_idt(void) | ||
195 | -{ | ||
196 | - void *handler = NULL; | ||
197 | - | ||
198 | - if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { | ||
199 | - setup_ghcb(); | ||
200 | - handler = vc_boot_ghcb; | ||
201 | - } | ||
202 | - | ||
203 | - startup_64_load_idt(handler); | ||
204 | -} | ||
205 | - | ||
206 | -/* | ||
207 | - * Setup boot CPU state needed before kernel switches to virtual addresses. | ||
208 | - */ | ||
209 | -void __head startup_64_setup_gdt_idt(void) | ||
210 | -{ | ||
211 | - struct desc_struct *gdt = (void *)(__force unsigned long)gdt_page.gdt; | ||
212 | - void *handler = NULL; | ||
213 | - | ||
214 | - struct desc_ptr startup_gdt_descr = { | ||
215 | - .address = (unsigned long)&RIP_REL_REF(*gdt), | ||
216 | - .size = GDT_SIZE - 1, | ||
217 | - }; | ||
218 | - | ||
219 | - /* Load GDT */ | ||
220 | - native_load_gdt(&startup_gdt_descr); | ||
221 | - | ||
222 | - /* New GDT is live - reload data segment registers */ | ||
223 | - asm volatile("movl %%eax, %%ds\n" | ||
224 | - "movl %%eax, %%ss\n" | ||
225 | - "movl %%eax, %%es\n" : : "a"(__KERNEL_DS) : "memory"); | ||
226 | - | ||
227 | - if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) | ||
228 | - handler = &RIP_REL_REF(vc_no_ghcb); | ||
229 | - | ||
230 | - startup_64_load_idt(handler); | ||
231 | -} | ||
232 | -- | ||
233 | 2.49.0.472.ge94155a9ec-goog | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
11 | placing this code in a dedicated startup section. | 11 | placing this code in a dedicated startup section. |
12 | 12 | ||
13 | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> | 13 | Signed-off-by: Ard Biesheuvel <ardb@kernel.org> |
14 | --- | 14 | --- |
15 | arch/x86/boot/startup/Makefile | 2 +- | 15 | arch/x86/boot/startup/Makefile | 2 +- |
16 | arch/x86/boot/startup/map_kernel.c | 232 ++++++++++++++++++++ | 16 | arch/x86/boot/startup/map_kernel.c | 215 ++++++++++++++++++++ |
17 | arch/x86/kernel/head64.c | 228 +------------------ | 17 | arch/x86/kernel/head64.c | 211 +------------------ |
18 | 3 files changed, 234 insertions(+), 228 deletions(-) | 18 | 3 files changed, 217 insertions(+), 211 deletions(-) |
19 | 19 | ||
20 | diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile | 20 | diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile |
21 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/arch/x86/boot/startup/Makefile | 22 | --- a/arch/x86/boot/startup/Makefile |
23 | +++ b/arch/x86/boot/startup/Makefile | 23 | +++ b/arch/x86/boot/startup/Makefile |
... | ... | ||
48 | +#include <asm/setup.h> | 48 | +#include <asm/setup.h> |
49 | +#include <asm/sev.h> | 49 | +#include <asm/sev.h> |
50 | + | 50 | + |
51 | +extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES][PTRS_PER_PMD]; | 51 | +extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES][PTRS_PER_PMD]; |
52 | +extern unsigned int next_early_pgt; | 52 | +extern unsigned int next_early_pgt; |
53 | + | ||
54 | +#ifdef CONFIG_X86_5LEVEL | ||
55 | +unsigned int __pgtable_l5_enabled __ro_after_init; | ||
56 | +unsigned int pgdir_shift __ro_after_init = 39; | ||
57 | +EXPORT_SYMBOL(pgdir_shift); | ||
58 | +unsigned int ptrs_per_p4d __ro_after_init = 1; | ||
59 | +EXPORT_SYMBOL(ptrs_per_p4d); | ||
60 | +#endif | ||
61 | + | ||
62 | +#ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT | ||
63 | +unsigned long page_offset_base __ro_after_init = __PAGE_OFFSET_BASE_L4; | ||
64 | +EXPORT_SYMBOL(page_offset_base); | ||
65 | +unsigned long vmalloc_base __ro_after_init = __VMALLOC_BASE_L4; | ||
66 | +EXPORT_SYMBOL(vmalloc_base); | ||
67 | +unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4; | ||
68 | +EXPORT_SYMBOL(vmemmap_base); | ||
69 | +#endif | ||
70 | + | 53 | + |
71 | +static inline bool check_la57_support(void) | 54 | +static inline bool check_la57_support(void) |
72 | +{ | 55 | +{ |
73 | + if (!IS_ENABLED(CONFIG_X86_5LEVEL)) | 56 | + if (!IS_ENABLED(CONFIG_X86_5LEVEL)) |
74 | + return false; | 57 | + return false; |
... | ... | ||
278 | extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES][PTRS_PER_PMD]; | 261 | extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES][PTRS_PER_PMD]; |
279 | -static unsigned int __initdata next_early_pgt; | 262 | -static unsigned int __initdata next_early_pgt; |
280 | +unsigned int __initdata next_early_pgt; | 263 | +unsigned int __initdata next_early_pgt; |
281 | pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX); | 264 | pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX); |
282 | 265 | ||
283 | -#ifdef CONFIG_X86_5LEVEL | 266 | #ifdef CONFIG_X86_5LEVEL |
284 | -unsigned int __pgtable_l5_enabled __ro_after_init; | 267 | @@ -XXX,XX +XXX,XX @@ unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4; |
285 | -unsigned int pgdir_shift __ro_after_init = 39; | 268 | EXPORT_SYMBOL(vmemmap_base); |
286 | -EXPORT_SYMBOL(pgdir_shift); | 269 | #endif |
287 | -unsigned int ptrs_per_p4d __ro_after_init = 1; | 270 | |
288 | -EXPORT_SYMBOL(ptrs_per_p4d); | ||
289 | -#endif | ||
290 | - | ||
291 | -#ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT | ||
292 | -unsigned long page_offset_base __ro_after_init = __PAGE_OFFSET_BASE_L4; | ||
293 | -EXPORT_SYMBOL(page_offset_base); | ||
294 | -unsigned long vmalloc_base __ro_after_init = __VMALLOC_BASE_L4; | ||
295 | -EXPORT_SYMBOL(vmalloc_base); | ||
296 | -unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4; | ||
297 | -EXPORT_SYMBOL(vmemmap_base); | ||
298 | -#endif | ||
299 | - | ||
300 | -static inline bool check_la57_support(void) | 271 | -static inline bool check_la57_support(void) |
301 | -{ | 272 | -{ |
302 | - if (!IS_ENABLED(CONFIG_X86_5LEVEL)) | 273 | - if (!IS_ENABLED(CONFIG_X86_5LEVEL)) |
303 | - return false; | 274 | - return false; |
304 | - | 275 | - |
... | ... | ||
508 | - | 479 | - |
509 | /* Wipe all early page tables except for the kernel symbol map */ | 480 | /* Wipe all early page tables except for the kernel symbol map */ |
510 | static void __init reset_early_page_tables(void) | 481 | static void __init reset_early_page_tables(void) |
511 | { | 482 | { |
512 | -- | 483 | -- |
513 | 2.49.0.472.ge94155a9ec-goog | 484 | 2.49.0.504.g3bcea36a83-goog | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
259 | obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt_amd.o | 259 | obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt_amd.o |
260 | 260 | ||
261 | -obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt_identity.o | 261 | -obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt_identity.o |
262 | obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt_boot.o | 262 | obj-$(CONFIG_AMD_MEM_ENCRYPT) += mem_encrypt_boot.o |
263 | -- | 263 | -- |
264 | 2.49.0.472.ge94155a9ec-goog | 264 | 2.49.0.504.g3bcea36a83-goog | diff view generated by jsdifflib |