Skip to content

Commit da9803d

Browse files
committed
Merge tag 'x86_seves_for_v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 SEV-ES support from Borislav Petkov: "SEV-ES enhances the current guest memory encryption support called SEV by also encrypting the guest register state, making the registers inaccessible to the hypervisor by en-/decrypting them on world switches. Thus, it adds additional protection to Linux guests against exfiltration, control flow and rollback attacks. With SEV-ES, the guest is in full control of what registers the hypervisor can access. This is provided by a guest-host exchange mechanism based on a new exception vector called VMM Communication Exception (#VC), a new instruction called VMGEXIT and a shared Guest-Host Communication Block which is a decrypted page shared between the guest and the hypervisor. Intercepts to the hypervisor become #VC exceptions in an SEV-ES guest so in order for that exception mechanism to work, the early x86 init code needed to be made able to handle exceptions, which, in itself, brings a bunch of very nice cleanups and improvements to the early boot code like an early page fault handler, allowing for on-demand building of the identity mapping. With that, !KASLR configurations do not use the EFI page table anymore but switch to a kernel-controlled one. The main part of this series adds the support for that new exchange mechanism. The goal has been to keep this as much as possibly separate from the core x86 code by concentrating the machinery in two SEV-ES-specific files: arch/x86/kernel/sev-es-shared.c arch/x86/kernel/sev-es.c Other interaction with core x86 code has been kept at minimum and behind static keys to minimize the performance impact on !SEV-ES setups. Work by Joerg Roedel and Thomas Lendacky and others" * tag 'x86_seves_for_v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (73 commits) x86/sev-es: Use GHCB accessor for setting the MMIO scratch buffer x86/sev-es: Check required CPU features for SEV-ES x86/efi: Add GHCB mappings when SEV-ES is active x86/sev-es: Handle NMI State x86/sev-es: Support CPU offline/online x86/head/64: Don't call verify_cpu() on starting APs x86/smpboot: Load TSS and getcpu GDT entry before loading IDT x86/realmode: Setup AP jump table x86/realmode: Add SEV-ES specific trampoline entry point x86/vmware: Add VMware-specific handling for VMMCALL under SEV-ES x86/kvm: Add KVM-specific VMMCALL handling under SEV-ES x86/paravirt: Allow hypervisor-specific VMMCALL handling under SEV-ES x86/sev-es: Handle #DB Events x86/sev-es: Handle #AC Events x86/sev-es: Handle VMMCALL Events x86/sev-es: Handle MWAIT/MWAITX Events x86/sev-es: Handle MONITOR/MONITORX Events x86/sev-es: Handle INVD Events x86/sev-es: Handle RDPMC Events x86/sev-es: Handle RDTSC(P) Events ...
2 parents 6873139 + 0ddfb1c commit da9803d

68 files changed

Lines changed: 4035 additions & 451 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,7 @@ config AMD_MEM_ENCRYPT
15231523
select DYNAMIC_PHYSICAL_MASK
15241524
select ARCH_USE_MEMREMAP_PROT
15251525
select ARCH_HAS_FORCE_DMA_UNENCRYPTED
1526+
select INSTRUCTION_DECODER
15261527
help
15271528
Say yes to enable support for the encryption of system memory.
15281529
This requires an AMD processor that supports Secure Memory

arch/x86/boot/compressed/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ KBUILD_CFLAGS := -m$(BITS) -O2
3232
KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
3333
KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
3434
cflags-$(CONFIG_X86_32) := -march=i386
35-
cflags-$(CONFIG_X86_64) := -mcmodel=small
35+
cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
3636
KBUILD_CFLAGS += $(cflags-y)
3737
KBUILD_CFLAGS += -mno-mmx -mno-sse
3838
KBUILD_CFLAGS += -ffreestanding
@@ -47,6 +47,11 @@ KBUILD_CFLAGS += -D__DISABLE_EXPORTS
4747
KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no)
4848
KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
4949

50+
# sev-es.c indirectly inludes inat-table.h which is generated during
51+
# compilation and stored in $(objtree). Add the directory to the includes so
52+
# that the compiler finds it even with out-of-tree builds (make O=/some/path).
53+
CFLAGS_sev-es.o += -I$(objtree)/arch/x86/lib/
54+
5055
KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5156
GCOV_PROFILE := n
5257
UBSAN_SANITIZE :=n
@@ -81,9 +86,11 @@ vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o
8186
vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
8287
vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
8388
ifdef CONFIG_X86_64
84-
vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr_64.o
89+
vmlinux-objs-y += $(obj)/ident_map_64.o
90+
vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o
8591
vmlinux-objs-y += $(obj)/mem_encrypt.o
8692
vmlinux-objs-y += $(obj)/pgtable_64.o
93+
vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev-es.o
8794
endif
8895

8996
vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// SPDX-License-Identifier: GPL-2.0
2-
#ifdef CONFIG_RANDOMIZE_BASE
3-
42
#include "../cpuflags.c"
53

64
bool has_cpuflag(int flag)
@@ -9,5 +7,3 @@ bool has_cpuflag(int flag)
97

108
return test_bit(flag, cpu.flags);
119
}
12-
13-
#endif

arch/x86/boot/compressed/head_64.S

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <asm/processor-flags.h>
3434
#include <asm/asm-offsets.h>
3535
#include <asm/bootparam.h>
36+
#include <asm/desc_defs.h>
3637
#include "pgtable.h"
3738

3839
/*
@@ -415,6 +416,10 @@ SYM_CODE_START(startup_64)
415416

416417
.Lon_kernel_cs:
417418

419+
pushq %rsi
420+
call load_stage1_idt
421+
popq %rsi
422+
418423
/*
419424
* paging_prepare() sets up the trampoline and checks if we need to
420425
* enable 5-level paging.
@@ -527,6 +532,21 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated)
527532
shrq $3, %rcx
528533
rep stosq
529534

535+
/*
536+
* If running as an SEV guest, the encryption mask is required in the
537+
* page-table setup code below. When the guest also has SEV-ES enabled
538+
* set_sev_encryption_mask() will cause #VC exceptions, but the stage2
539+
* handler can't map its GHCB because the page-table is not set up yet.
540+
* So set up the encryption mask here while still on the stage1 #VC
541+
* handler. Then load stage2 IDT and switch to the kernel's own
542+
* page-table.
543+
*/
544+
pushq %rsi
545+
call set_sev_encryption_mask
546+
call load_stage2_idt
547+
call initialize_identity_maps
548+
popq %rsi
549+
530550
/*
531551
* Do the extraction, and jump to the new kernel..
532552
*/
@@ -659,10 +679,21 @@ SYM_DATA_START_LOCAL(gdt)
659679
.quad 0x0000000000000000 /* TS continued */
660680
SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end)
661681

682+
SYM_DATA_START(boot_idt_desc)
683+
.word boot_idt_end - boot_idt - 1
684+
.quad 0
685+
SYM_DATA_END(boot_idt_desc)
686+
.balign 8
687+
SYM_DATA_START(boot_idt)
688+
.rept BOOT_IDT_ENTRIES
689+
.quad 0
690+
.quad 0
691+
.endr
692+
SYM_DATA_END_LABEL(boot_idt, SYM_L_GLOBAL, boot_idt_end)
693+
662694
#ifdef CONFIG_EFI_STUB
663695
SYM_DATA(image_offset, .long 0)
664696
#endif
665-
666697
#ifdef CONFIG_EFI_MIXED
667698
SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0)
668699
SYM_DATA(efi_is64, .byte 1)

0 commit comments

Comments
 (0)