projects/linux·commit da9803df

Merge tag 'x86_seves_for_v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

da9803df · Linus Torvalds <[email protected]> · 2020-10-14 10:21:34 -07:00

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
  ...
Commit
da9803dfd3955bd2f9909d55e23f188ad76dbe58
Parents
6873139e · 0ddfb1cf

Merge commit. Changes below are compared with the first parent: 6873139e.

Changes

67 files changed · +3906 −322

FileStatusAddDelContent
arch/x86/Kconfigmodified+1−0View file
arch/x86/boot/compressed/Makefilemodified+9−2View file
arch/x86/boot/compressed/cpuflags.cmodified+0−4View file
arch/x86/boot/compressed/head_64.Smodified+32−1View file
arch/x86/boot/compressed/kaslr_64.c → arch/x86/boot/compressed/ident_map_64.crenamed+220−24View file
arch/x86/boot/compressed/idt_64.cadded+54−0View file
arch/x86/boot/compressed/idt_handlers_64.Sadded+77−0View file
arch/x86/boot/compressed/kaslr.cmodified+1−35View file
arch/x86/boot/compressed/misc.cmodified+7−0View file
arch/x86/boot/compressed/misc.hmodified+38−12View file
arch/x86/boot/compressed/sev-es.cadded+214−0View file
arch/x86/entry/entry_64.Smodified+80−0View file
arch/x86/include/asm/cpu_entry_area.hmodified+21−12View file
arch/x86/include/asm/cpufeatures.hmodified+1−0View file
arch/x86/include/asm/desc.hmodified+27−0View file
arch/x86/include/asm/desc_defs.hmodified+10−0View file
arch/x86/include/asm/fpu/internal.hmodified+1−29View file
arch/x86/include/asm/fpu/xcr.hadded+34−0View file
arch/x86/include/asm/idtentry.hmodified+50−0View file
arch/x86/include/asm/insn-eval.hmodified+6−0View file
arch/x86/include/asm/mem_encrypt.hmodified+5−0View file
arch/x86/include/asm/msr-index.hmodified+3−0View file
arch/x86/include/asm/page_64_types.hmodified+1−0View file
arch/x86/include/asm/pgtable.hmodified+1−1View file
arch/x86/include/asm/processor.hmodified+1−0View file
arch/x86/include/asm/proto.hmodified+1−0View file
arch/x86/include/asm/realmode.hmodified+7−0View file
arch/x86/include/asm/segment.hmodified+1−1View file
arch/x86/include/asm/setup.hmodified+5−1View file
arch/x86/include/asm/sev-es.hadded+114−0View file
arch/x86/include/asm/stacktrace.hmodified+2−0View file
arch/x86/include/asm/svm.hmodified+98−8View file
arch/x86/include/asm/trap_pf.hadded+24−0View file
arch/x86/include/asm/trapnr.hmodified+1−0View file
arch/x86/include/asm/traps.hmodified+2−18View file
arch/x86/include/asm/x86_init.hmodified+15−1View file
arch/x86/include/uapi/asm/svm.hmodified+11−0View file
arch/x86/kernel/Makefilemodified+3−0View file
arch/x86/kernel/cpu/amd.cmodified+2−1View file
arch/x86/kernel/cpu/common.cmodified+25−0View file
arch/x86/kernel/cpu/scattered.cmodified+1−0View file
arch/x86/kernel/cpu/vmware.cmodified+45−5View file
arch/x86/kernel/dumpstack.cmodified+4−3View file
arch/x86/kernel/dumpstack_64.cmodified+28−18View file
arch/x86/kernel/head64.cmodified+118−4View file
arch/x86/kernel/head_64.Smodified+128−37View file
arch/x86/kernel/idt.cmodified+8−33View file
arch/x86/kernel/kvm.cmodified+29−6View file
arch/x86/kernel/nmi.cmodified+15−0View file
arch/x86/kernel/sev-es-shared.cadded+507−0View file
arch/x86/kernel/sev-es.cadded+1404−0View file
arch/x86/kernel/smpboot.cmodified+1−1View file
arch/x86/kernel/traps.cmodified+48−0View file
arch/x86/kernel/umip.cmodified+7−42View file
arch/x86/kvm/svm/nested.cmodified+33−14View file
arch/x86/kvm/svm/svm.cmodified+2−0View file
arch/x86/lib/insn-eval.cmodified+130−0View file
arch/x86/mm/cpu_entry_area.cmodified+2−1View file
arch/x86/mm/extable.cmodified+1−0View file
arch/x86/mm/mem_encrypt.cmodified+34−4View file
arch/x86/mm/mem_encrypt_identity.cmodified+3−0View file
arch/x86/platform/efi/efi_64.cmodified+10−0View file
arch/x86/realmode/init.cmodified+22−2View file
arch/x86/realmode/rm/header.Smodified+3−0View file
arch/x86/realmode/rm/trampoline_64.Smodified+20−0View file
arch/x86/tools/gen-insn-attr-x86.awkmodified+49−1View file
tools/arch/x86/tools/gen-insn-attr-x86.awkmodified+49−1View file

Only the first 600 diff lines are shown. Download the complete patch.

arch/x86/Kconfig

View file
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 255084c..f6946b8 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1523,6 +1523,7 @@ config AMD_MEM_ENCRYPT
select DYNAMIC_PHYSICAL_MASK
select ARCH_USE_MEMREMAP_PROT
select ARCH_HAS_FORCE_DMA_UNENCRYPTED
+ select INSTRUCTION_DECODER
help
Say yes to enable support for the encryption of system memory.
This requires an AMD processor that supports Secure Memory

arch/x86/boot/compressed/Makefile

View file
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 4fb989e..ee24908 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -32,7 +32,7 @@ KBUILD_CFLAGS := -m$(BITS) -O2
KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
cflags-$(CONFIG_X86_32) := -march=i386
-cflags-$(CONFIG_X86_64) := -mcmodel=small
+cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone
KBUILD_CFLAGS += $(cflags-y)
KBUILD_CFLAGS += -mno-mmx -mno-sse
KBUILD_CFLAGS += -ffreestanding
@@ -47,6 +47,11 @@ KBUILD_CFLAGS += -D__DISABLE_EXPORTS
KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no)
KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h
+# sev-es.c indirectly inludes inat-table.h which is generated during
+# compilation and stored in $(objtree). Add the directory to the includes so
+# that the compiler finds it even with out-of-tree builds (make O=/some/path).
+CFLAGS_sev-es.o += -I$(objtree)/arch/x86/lib/
+
KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
GCOV_PROFILE := n
UBSAN_SANITIZE :=n
@@ -81,9 +86,11 @@ vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/kernel_info.o $(obj)/head_$(BITS).o
vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
ifdef CONFIG_X86_64
- vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr_64.o
+ vmlinux-objs-y += $(obj)/ident_map_64.o
+ vmlinux-objs-y += $(obj)/idt_64.o $(obj)/idt_handlers_64.o
vmlinux-objs-y += $(obj)/mem_encrypt.o
vmlinux-objs-y += $(obj)/pgtable_64.o
+ vmlinux-objs-$(CONFIG_AMD_MEM_ENCRYPT) += $(obj)/sev-es.o
endif
vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o

arch/x86/boot/compressed/cpuflags.c

View file
diff --git a/arch/x86/boot/compressed/cpuflags.c b/arch/x86/boot/compressed/cpuflags.c
index 6448a81..0cc1323 100644
--- a/arch/x86/boot/compressed/cpuflags.c
+++ b/arch/x86/boot/compressed/cpuflags.c
@@ -1,6 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
-#ifdef CONFIG_RANDOMIZE_BASE
-
#include "../cpuflags.c"
bool has_cpuflag(int flag)
@@ -9,5 +7,3 @@ bool has_cpuflag(int flag)
return test_bit(flag, cpu.flags);
}
-
-#endif

arch/x86/boot/compressed/head_64.S

View file
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index 9e46729..1c80f17 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -33,6 +33,7 @@
#include <asm/processor-flags.h>
#include <asm/asm-offsets.h>
#include <asm/bootparam.h>
+#include <asm/desc_defs.h>
#include "pgtable.h"
/*
@@ -415,6 +416,10 @@ SYM_CODE_START(startup_64)
.Lon_kernel_cs:
+ pushq %rsi
+ call load_stage1_idt
+ popq %rsi
+
/*
* paging_prepare() sets up the trampoline and checks if we need to
* enable 5-level paging.
@@ -528,6 +533,21 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated)
rep stosq
/*
+ * If running as an SEV guest, the encryption mask is required in the
+ * page-table setup code below. When the guest also has SEV-ES enabled
+ * set_sev_encryption_mask() will cause #VC exceptions, but the stage2
+ * handler can't map its GHCB because the page-table is not set up yet.
+ * So set up the encryption mask here while still on the stage1 #VC
+ * handler. Then load stage2 IDT and switch to the kernel's own
+ * page-table.
+ */
+ pushq %rsi
+ call set_sev_encryption_mask
+ call load_stage2_idt
+ call initialize_identity_maps
+ popq %rsi
+
+/*
* Do the extraction, and jump to the new kernel..
*/
pushq %rsi /* Save the real mode argument */
@@ -659,10 +679,21 @@ SYM_DATA_START_LOCAL(gdt)
.quad 0x0000000000000000 /* TS continued */
SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end)
+SYM_DATA_START(boot_idt_desc)
+ .word boot_idt_end - boot_idt - 1
+ .quad 0
+SYM_DATA_END(boot_idt_desc)
+ .balign 8
+SYM_DATA_START(boot_idt)
+ .rept BOOT_IDT_ENTRIES
+ .quad 0
+ .quad 0
+ .endr
+SYM_DATA_END_LABEL(boot_idt, SYM_L_GLOBAL, boot_idt_end)
+
#ifdef CONFIG_EFI_STUB
SYM_DATA(image_offset, .long 0)
#endif
-
#ifdef CONFIG_EFI_MIXED
SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0)
SYM_DATA(efi_is64, .byte 1)

arch/x86/boot/compressed/ident_map_64.c

View file
diff --git a/arch/x86/boot/compressed/kaslr_64.c b/arch/x86/boot/compressed/ident_map_64.c
similarity index 57%
rename from arch/x86/boot/compressed/kaslr_64.c
rename to arch/x86/boot/compressed/ident_map_64.c
index f9c5c13..063a60e 100644
--- a/arch/x86/boot/compressed/kaslr_64.c
+++ b/arch/x86/boot/compressed/ident_map_64.c
@@ -19,16 +19,29 @@
/* No PAGE_TABLE_ISOLATION support needed either: */
#undef CONFIG_PAGE_TABLE_ISOLATION
+#include "error.h"
#include "misc.h"
/* These actually do the work of building the kernel identity maps. */
#include <linux/pgtable.h>
+#include <asm/cmpxchg.h>
+#include <asm/trap_pf.h>
+#include <asm/trapnr.h>
#include <asm/init.h>
/* Use the static base for this part of the boot process */
#undef __PAGE_OFFSET
#define __PAGE_OFFSET __PAGE_OFFSET_BASE
#include "../../mm/ident_map.c"
+#ifdef CONFIG_X86_5LEVEL
+unsigned int __pgtable_l5_enabled;
+unsigned int pgdir_shift = 39;
+unsigned int ptrs_per_p4d = 1;
+#endif
+
+/* Used by PAGE_KERN* macros: */
+pteval_t __default_kernel_pte_mask __read_mostly = ~0;
+
/* Used to track our page table allocation area. */
struct alloc_pgt_data {
unsigned char *pgt_buf;
@@ -74,12 +87,28 @@ phys_addr_t physical_mask = (1ULL << __PHYSICAL_MASK_SHIFT) - 1;
*/
static struct x86_mapping_info mapping_info;
+/*
+ * Adds the specified range to the identity mappings.
+ */
+static void add_identity_map(unsigned long start, unsigned long end)
+{
+ int ret;
+
+ /* Align boundary to 2M. */
+ start = round_down(start, PMD_SIZE);
+ end = round_up(end, PMD_SIZE);
+ if (start >= end)
+ return;
+
+ /* Build the mapping. */
+ ret = kernel_ident_mapping_init(&mapping_info, (pgd_t *)top_level_pgt, start, end);
+ if (ret)
+ error("Error: kernel_ident_mapping_init() failed\n");
+}
+
/* Locates and clears a region for a new top level page table. */
void initialize_identity_maps(void)
{
- /* If running as an SEV guest, the encryption mask is required. */
- set_sev_encryption_mask();
-
/* Exclude the encryption mask from __PHYSICAL_MASK */
physical_mask &= ~sme_me_mask;
@@ -109,37 +138,22 @@ void initialize_identity_maps(void)
*/
top_level_pgt = read_cr3_pa();
if (p4d_offset((pgd_t *)top_level_pgt, 0) == (p4d_t *)_pgtable) {
- debug_putstr("booted via startup_32()\n");
pgt_data.pgt_buf = _pgtable + BOOT_INIT_PGT_SIZE;
pgt_data.pgt_buf_size = BOOT_PGT_SIZE - BOOT_INIT_PGT_SIZE;
memset(pgt_data.pgt_buf, 0, pgt_data.pgt_buf_size);
} else {
- debug_putstr("booted via startup_64()\n");
pgt_data.pgt_buf = _pgtable;
pgt_data.pgt_buf_size = BOOT_PGT_SIZE;
memset(pgt_data.pgt_buf, 0, pgt_data.pgt_buf_size);
top_level_pgt = (unsigned long)alloc_pgt_page(&pgt_data);
}
-}
-
-/*
- * Adds the specified range to what will become the new identity mappings.
- * Once all ranges have been added, the new mapping is activated by calling
- * finalize_identity_maps() below.
- */
-void add_identity_map(unsigned long start, unsigned long size)
-{
- unsigned long end = start + size;
- /* Align boundary to 2M. */
- start = round_down(start, PMD_SIZE);
- end = round_up(end, PMD_SIZE);
- if (start >= end)
- return;
-
- /* Build the mapping. */
- kernel_ident_mapping_init(&mapping_info, (pgd_t *)top_level_pgt,
- start, end);
+ /*
+ * New page-table is set up - map the kernel image and load it
+ * into cr3.
+ */
+ add_identity_map((unsigned long)_head, (unsigned long)_end);
+ write_cr3(top_level_pgt);
}
/*
@@ -151,3 +165,185 @@ void finalize_identity_maps(void)
{
write_cr3(top_level_pgt);
}
+
+static pte_t *split_large_pmd(struct x86_mapping_info *info,
+ pmd_t *pmdp, unsigned long __address)
+{
+ unsigned long page_flags;
+ unsigned long address;
+ pte_t *pte;
+ pmd_t pmd;
+ int i;
+
+ pte = (pte_t *)info->alloc_pgt_page(info->context);
+ if (!pte)
+ return NULL;
+
+ address = __address & PMD_MASK;
+ /* No large page - clear PSE flag */
+ page_flags = info->page_flag & ~_PAGE_PSE;
+
+ /* Populate the PTEs */
+ for (i = 0; i < PTRS_PER_PMD; i++) {
+ set_pte(&pte[i], __pte(address | page_flags));
+ address += PAGE_SIZE;
+ }
+
+ /*
+ * Ideally we need to clear the large PMD first and do a TLB
+ * flush before we write the new PMD. But the 2M range of the
+ * PMD might contain the code we execute and/or the stack
+ * we are on, so we can't do that. But that should be safe here
+ * because we are going from large to small mappings and we are
+ * also the only user of the page-table, so there is no chance
+ * of a TLB multihit.
+ */
+ pmd = __pmd((unsigned long)pte | info->kernpg_flag);
+ set_pmd(pmdp, pmd);
+ /* Flush TLB to establish the new PMD */
+ write_cr3(top_level_pgt);
+
+ return pte + pte_index(__address);
+}
+
+static void clflush_page(unsigned long address)
+{
+ unsigned int flush_size;
+ char *cl, *start, *end;
+
+ /*
+ * Hardcode cl-size to 64 - CPUID can't be used here because that might
+ * cause another #VC exception and the GHCB is not ready to use yet.
+ */
+ flush_size = 64;
+ start = (char *)(address & PAGE_MASK);
+ end = start + PAGE_SIZE;
+
+ /*
+ * First make sure there are no pending writes on the cache-lines to
+ * flush.
+ */
+ asm volatile("mfence" : : : "memory");
+
+ for (cl = start; cl != end; cl += flush_size)
+ clflush(cl);
+}
+
+static int set_clr_page_flags(struct x86_mapping_info *info,
+ unsigned long address,
+ pteval_t set, pteval_t clr)
+{
+ pgd_t *pgdp = (pgd_t *)top_level_pgt;
+ p4d_t *p4dp;
+ pud_t *pudp;
+ pmd_t *pmdp;
+ pte_t *ptep, pte;
+
+ /*
+ * First make sure there is a PMD mapping for 'address'.
+ * It should already exist, but keep things generic.
+ *
+ * To map the page just read from it and fault it in if there is no
+ * mapping yet. add_identity_map() can't be called here because that
+ * would unconditionally map the address on PMD level, destroying any
+ * PTE-level mappings that might already exist. Use assembly here so
+ * the access won't be optimized away.
+ */
+ asm volatile("mov %[address], %%r9"
+ :: [address] "g" (*(unsigned long *)address)
+ : "r9", "memory");
+
+ /*
+ * The page is mapped at least with PMD size - so skip checks and walk
+ * directly to the PMD.
+ */
+ p4dp = p4d_offset(pgdp, address);
+ pudp = pud_offset(p4dp, address);
+ pmdp = pmd_offset(pudp, address);
+
+ if (pmd_large(*pmdp))
+ ptep = split_large_pmd(info, pmdp, address);
+ else
+ ptep = pte_offset_kernel(pmdp, address);
+
+ if (!ptep)
+ return -ENOMEM;
+
+ /*
+ * Changing encryption attributes of a page requires to flush it from
+ * the caches.
+ */
+ if ((set | clr) & _PAGE_ENC)
+ clflush_page(address);
+
+ /* Update PTE */
+ pte = *ptep;
+ pte = pte_set_flags(pte, set);
+ pte = pte_clear_flags(pte, clr);
+ set_pte(ptep, pte);
+
+ /* Flush TLB after changing encryption attribute */
+ write_cr3(top_level_pgt);
+
+ return 0;
+}
+
+int set_page_decrypted(unsigned long address)
+{
+ return set_clr_page_flags(&mapping_info, address, 0, _PAGE_ENC);
+}
+
+int set_page_encrypted(unsigned long address)
+{
+ return set_clr_page_flags(&mapping_info, address, _PAGE_ENC, 0);
+}
+
+int set_page_non_present(unsigned long address)
+{
+ return set_clr_page_flags(&mapping_info, address, 0, _PAGE_PRESENT);
+}
+
+static void do_pf_error(const char *msg, unsigned long error_code,
+ unsigned long address, unsigned long ip)
+{
+ error_putstr(msg);
+
+ error_putstr("\nError Code: ");
+ error_puthex(error_code);
+ error_putstr("\nCR2: 0x");
+ error_puthex(address);
+ error_putstr("\nRIP relative to _head: 0x");
+ error_puthex(ip - (unsigned long)_head);
+ error_putstr("\n");
+
+ error("Stopping.\n");
+}
+
+void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code)
+{
+ unsigned long address = native_read_cr2();
+ unsigned long end;
+ bool ghcb_fault;
+
+ ghcb_fault = sev_es_check_ghcb_fault(address);
+
+ address &= PMD_MASK;
+ end = address + PMD_SIZE;
+
+ /*
+ * Check for unexpected error codes. Unexpected are:
+ * - Faults on present pages
+ * - User faults
+ * - Reserved bits set
+ */
+ if (error_code & (X86_PF_PROT | X86_PF_USER | X86_PF_RSVD))
+ do_pf_error("Unexpected page-fault:", error_code, address, regs->ip);
+ else if (ghcb_fault)
+ do_pf_error("Page-fault on GHCB page:", error_code, address, regs->ip);
+
+ /*
+ * Error code is sane - now identity map the 2M region around
+ * the faulting address.
+ */
+ add_identity_map(address, end);
+}

arch/x86/boot/compressed/idt_64.c

View file
diff --git a/arch/x86/boot/compressed/idt_64.c b/arch/x86/boot/compressed/idt_64.c
new file mode 100644
index 0000000..804a502
--- /dev/null
+++ b/arch/x86/boot/compressed/idt_64.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <asm/trap_pf.h>
+#include <asm/segment.h>
+#include <asm/trapnr.h>
+#include "misc.h"
+
+static void set_idt_entry(int vector, void (*handler)(void))
+{
+ unsigned long address = (unsigned long)handler;
+ gate_desc entry;
+
+ memset(&entry, 0, sizeof(entry));
+
+ entry.offset_low = (u16)(address & 0xffff);
+ entry.segment = __KERNEL_CS;
+ entry.bits.type = GATE_TRAP;
+ entry.bits.p = 1;
+ entry.offset_middle = (u16)((address >> 16) & 0xffff);
+ entry.offset_high = (u32)(address >> 32);
+
+ memcpy(&boot_idt[vector], &entry, sizeof(entry));
+}
+
+/* Have this here so we don't need to include <asm/desc.h> */
+static void load_boot_idt(const struct desc_ptr *dtr)
+{
+ asm volatile("lidt %0"::"m" (*dtr));
+}
+
+/* Setup IDT before kernel jumping to .Lrelocated */
+void load_stage1_idt(void)
+{
+ boot_idt_desc.address = (unsigned long)boot_idt;
+
+
+ if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT))
+ set_idt_entry(X86_TRAP_VC, boot_stage1_vc);
+
+ load_boot_idt(&boot_idt_desc);
+}
+
+/* Setup IDT after kernel jumping to .Lrelocated */
+void load_stage2_idt(void)
+{
+ boot_idt_desc.address = (unsigned long)boot_idt;
+
+ set_idt_entry(X86_TRAP_PF, boot_page_fault);
+
+#ifdef CONFIG_AMD_MEM_ENCRYPT
+ set_idt_entry(X86_TRAP_VC, boot_stage2_vc);
+#endif
+
+ load_boot_idt(&boot_idt_desc);
+}

arch/x86/boot/compressed/idt_handlers_64.S

View file
diff --git a/arch/x86/boot/compressed/idt_handlers_64.S b/arch/x86/boot/compressed/idt_handlers_64.S
new file mode 100644
index 0000000..22890e1
--- /dev/null
+++ b/arch/x86/boot/compressed/idt_handlers_64.S
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Early IDT handler entry points
+ *
+ * Copyright (C) 2019 SUSE
+ *
+ * Author: Joerg Roedel <[email protected]>
+ */
+
+#include <asm/segment.h>
+
+/* For ORIG_RAX */
+#include "../../entry/calling.h"
+
+.macro EXCEPTION_HANDLER name function error_code=0
+SYM_FUNC_START(\name)
+
+ /* Build pt_regs */
+ .if \error_code == 0
+ pushq $0
+ .endif
+
+ pushq %rdi
+ pushq %rsi
+ pushq %rdx
+ pushq %rcx
+ pushq %rax
+ pushq %r8
+ pushq %r9
+ pushq %r10
+ pushq %r11
+ pushq %rbx
+ pushq %rbp
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+
+ /* Call handler with pt_regs */
+ movq %rsp, %rdi
+ /* Error code is second parameter */
+ movq ORIG_RAX(%rsp), %rsi
+ call \function
+
+ /* Restore regs */
+ popq %r15
+ popq %r14
+ popq %r13
+ popq %r12
+ popq %rbp
+ popq %rbx
+ popq %r11
+ popq %r10
+ popq %r9
+ popq %r8
+ popq %rax
+ popq %rcx
+ popq %rdx
+ popq %rsi
+ popq %rdi
+
+ /* Remove error code and return */
+ addq $8, %rsp
+
+ iretq
+SYM_FUNC_END(\name)
+ .endm
+
+ .text
+ .code64
+
+EXCEPTION_HANDLER boot_page_fault do_boot_page_fault error_code=1
+
+#ifdef CONFIG_AMD_MEM_ENCRYPT
+EXCEPTION_HANDLER boot_stage1_vc do_vc_no_ghcb error_code=1
+EXCEPTION_HANDLER boot_stage2_vc do_boot_stage2_vc error_code=1
+#endif

arch/x86/boot/compressed/kaslr.c

View file
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 877970d..b59547c 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -40,17 +40,8 @@
#include <asm/setup.h> /* For COMMAND_LINE_SIZE */
#undef _SETUP
-#ifdef CONFIG_X86_5LEVEL
-unsigned int __pgtable_l5_enabled;
-unsigned int pgdir_shift __ro_after_init = 39;
-unsigned int ptrs_per_p4d __ro_after_init = 1;
-#endif
-
extern unsigned long get_cmd_line_ptr(void);
-/* Used by PAGE_KERN* macros: */
-pteval_t __default_kernel_pte_mask __read_mostly = ~0;
-
/* Simplified build-specific string for starting entropy. */
static const char build_str[] = UTS_RELEASE " (" LINUX_COMPILE_BY "@"
LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION;
@@ -406,8 +397,6 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,

This diff is incomplete. Download the complete patch.

arch/x86/boot/compressed/misc.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/boot/compressed/misc.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/boot/compressed/sev-es.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/entry/entry_64.S

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/cpu_entry_area.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/cpufeatures.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/desc.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/desc_defs.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/fpu/internal.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/fpu/xcr.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/idtentry.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/insn-eval.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/mem_encrypt.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/msr-index.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/page_64_types.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/pgtable.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/processor.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/proto.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/realmode.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/segment.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/setup.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/sev-es.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/stacktrace.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/svm.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/trap_pf.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/trapnr.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/traps.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/asm/x86_init.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/include/uapi/asm/svm.h

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/Makefile

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/cpu/amd.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/cpu/common.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/cpu/scattered.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/cpu/vmware.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/dumpstack.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/dumpstack_64.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/head64.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/head_64.S

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/idt.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/kvm.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/nmi.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/sev-es-shared.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/sev-es.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/smpboot.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/traps.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kernel/umip.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kvm/svm/nested.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/kvm/svm/svm.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/lib/insn-eval.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/mm/cpu_entry_area.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/mm/extable.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/mm/mem_encrypt.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/mm/mem_encrypt_identity.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/platform/efi/efi_64.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/realmode/init.c

View file

This diff is incomplete. Download the complete patch.

arch/x86/realmode/rm/header.S

View file

This diff is incomplete. Download the complete patch.

arch/x86/realmode/rm/trampoline_64.S

View file

This diff is incomplete. Download the complete patch.

arch/x86/tools/gen-insn-attr-x86.awk

View file

This diff is incomplete. Download the complete patch.

tools/arch/x86/tools/gen-insn-attr-x86.awk

View file

This diff is incomplete. Download the complete patch.