Skip to content

Commit

Permalink
x86/boot/compressed/64: Cleanup exception handling before booting kernel
Browse files Browse the repository at this point in the history
Disable the exception handling before booting the kernel to make sure
any exceptions that happen during early kernel boot are not directed to
the pre-decompression code.

Signed-off-by: Joerg Roedel <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
  • Loading branch information
joergroedel authored and suryasaimadhu committed Mar 18, 2021
1 parent afb4a37 commit b099155
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
14 changes: 14 additions & 0 deletions arch/x86/boot/compressed/idt_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@ void load_stage2_idt(void)

load_boot_idt(&boot_idt_desc);
}

void cleanup_exception_handling(void)
{
/*
* Flush GHCB from cache and map it encrypted again when running as
* SEV-ES guest.
*/
sev_es_shutdown_ghcb();

/* Set a null-idt, disabling #PF and #VC handling */
boot_idt_desc.size = 0;
boot_idt_desc.address = 0;
load_boot_idt(&boot_idt_desc);
}
7 changes: 2 additions & 5 deletions arch/x86/boot/compressed/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,8 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
handle_relocations(output, output_len, virt_addr);
debug_putstr("done.\nBooting the kernel.\n");

/*
* Flush GHCB from cache and map it encrypted again when running as
* SEV-ES guest.
*/
sev_es_shutdown_ghcb();
/* Disable exception handling before booting the kernel */
cleanup_exception_handling();

return output;
}
Expand Down
6 changes: 6 additions & 0 deletions arch/x86/boot/compressed/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ extern pteval_t __default_kernel_pte_mask;
extern gate_desc boot_idt[BOOT_IDT_ENTRIES];
extern struct desc_ptr boot_idt_desc;

#ifdef CONFIG_X86_64
void cleanup_exception_handling(void);
#else
static inline void cleanup_exception_handling(void) { }
#endif

/* IDT Entry Points */
void boot_page_fault(void);
void boot_stage1_vc(void);
Expand Down

0 comments on commit b099155

Please sign in to comment.