~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/boot/compressed/idt_64.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 #include <asm/trap_pf.h>
  3 #include <asm/segment.h>
  4 #include <asm/trapnr.h>
  5 #include "misc.h"
  6 
  7 static void set_idt_entry(int vector, void (*handler)(void))
  8 {
  9         unsigned long address = (unsigned long)handler;
 10         gate_desc entry;
 11 
 12         memset(&entry, 0, sizeof(entry));
 13 
 14         entry.offset_low    = (u16)(address & 0xffff);
 15         entry.segment       = __KERNEL_CS;
 16         entry.bits.type     = GATE_TRAP;
 17         entry.bits.p        = 1;
 18         entry.offset_middle = (u16)((address >> 16) & 0xffff);
 19         entry.offset_high   = (u32)(address >> 32);
 20 
 21         memcpy(&boot_idt[vector], &entry, sizeof(entry));
 22 }
 23 
 24 /* Have this here so we don't need to include <asm/desc.h> */
 25 static void load_boot_idt(const struct desc_ptr *dtr)
 26 {
 27         asm volatile("lidt %0"::"m" (*dtr));
 28 }
 29 
 30 /* Setup IDT before kernel jumping to  .Lrelocated */
 31 void load_stage1_idt(void)
 32 {
 33         boot_idt_desc.address = (unsigned long)boot_idt;
 34 
 35 
 36         if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT))
 37                 set_idt_entry(X86_TRAP_VC, boot_stage1_vc);
 38 
 39         load_boot_idt(&boot_idt_desc);
 40 }
 41 
 42 /*
 43  * Setup IDT after kernel jumping to  .Lrelocated.
 44  *
 45  * initialize_identity_maps() needs a #PF handler to be setup
 46  * in order to be able to fault-in identity mapping ranges; see
 47  * do_boot_page_fault().
 48  *
 49  * This #PF handler setup needs to happen in load_stage2_idt() where the
 50  * IDT is loaded and there the #VC IDT entry gets setup too.
 51  *
 52  * In order to be able to handle #VCs, one needs a GHCB which
 53  * gets setup with an already set up pagetable, which is done in
 54  * initialize_identity_maps(). And there's the catch 22: the boot #VC
 55  * handler do_boot_stage2_vc() needs to call early_setup_ghcb() itself
 56  * (and, especially set_page_decrypted()) because the SEV-ES setup code
 57  * cannot initialize a GHCB as there's no #PF handler yet...
 58  */
 59 void load_stage2_idt(void)
 60 {
 61         boot_idt_desc.address = (unsigned long)boot_idt;
 62 
 63         set_idt_entry(X86_TRAP_PF, boot_page_fault);
 64         set_idt_entry(X86_TRAP_NMI, boot_nmi_trap);
 65 
 66 #ifdef CONFIG_AMD_MEM_ENCRYPT
 67         /*
 68          * Clear the second stage #VC handler in case guest types
 69          * needing #VC have not been detected.
 70          */
 71         if (sev_status & BIT(1))
 72                 set_idt_entry(X86_TRAP_VC, boot_stage2_vc);
 73         else
 74                 set_idt_entry(X86_TRAP_VC, NULL);
 75 #endif
 76 
 77         load_boot_idt(&boot_idt_desc);
 78 }
 79 
 80 void cleanup_exception_handling(void)
 81 {
 82         /*
 83          * Flush GHCB from cache and map it encrypted again when running as
 84          * SEV-ES guest.
 85          */
 86         sev_es_shutdown_ghcb();
 87 
 88         /* Set a null-idt, disabling #PF and #VC handling */
 89         boot_idt_desc.size    = 0;
 90         boot_idt_desc.address = 0;
 91         load_boot_idt(&boot_idt_desc);
 92 }
 93 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php