head64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * prepare to run common code
  4. *
  5. * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
  6. */
  7. #define DISABLE_BRANCH_PROFILING
  8. /* cpu_feature_enabled() cannot be used this early */
  9. #define USE_EARLY_PGTABLE_L5
  10. #include <linux/init.h>
  11. #include <linux/linkage.h>
  12. #include <linux/types.h>
  13. #include <linux/kernel.h>
  14. #include <linux/string.h>
  15. #include <linux/percpu.h>
  16. #include <linux/start_kernel.h>
  17. #include <linux/io.h>
  18. #include <linux/memblock.h>
  19. #include <linux/cc_platform.h>
  20. #include <linux/pgtable.h>
  21. #include <asm/asm.h>
  22. #include <asm/page_64.h>
  23. #include <asm/processor.h>
  24. #include <asm/proto.h>
  25. #include <asm/smp.h>
  26. #include <asm/setup.h>
  27. #include <asm/desc.h>
  28. #include <asm/tlbflush.h>
  29. #include <asm/sections.h>
  30. #include <asm/kdebug.h>
  31. #include <asm/e820/api.h>
  32. #include <asm/bios_ebda.h>
  33. #include <asm/bootparam_utils.h>
  34. #include <asm/microcode.h>
  35. #include <asm/kasan.h>
  36. #include <asm/fixmap.h>
  37. #include <asm/realmode.h>
  38. #include <asm/extable.h>
  39. #include <asm/trapnr.h>
  40. #include <asm/sev.h>
  41. #include <asm/tdx.h>
  42. #include <asm/init.h>
  43. /*
  44. * Manage page tables very early on.
  45. */
  46. extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES][PTRS_PER_PMD];
  47. static unsigned int __initdata next_early_pgt;
  48. pmdval_t early_pmd_flags = __PAGE_KERNEL_LARGE & ~(_PAGE_GLOBAL | _PAGE_NX);
  49. #ifdef CONFIG_X86_5LEVEL
  50. unsigned int __pgtable_l5_enabled __ro_after_init;
  51. unsigned int pgdir_shift __ro_after_init = 39;
  52. EXPORT_SYMBOL(pgdir_shift);
  53. unsigned int ptrs_per_p4d __ro_after_init = 1;
  54. EXPORT_SYMBOL(ptrs_per_p4d);
  55. #endif
  56. #ifdef CONFIG_DYNAMIC_MEMORY_LAYOUT
  57. unsigned long page_offset_base __ro_after_init = __PAGE_OFFSET_BASE_L4;
  58. EXPORT_SYMBOL(page_offset_base);
  59. unsigned long vmalloc_base __ro_after_init = __VMALLOC_BASE_L4;
  60. EXPORT_SYMBOL(vmalloc_base);
  61. unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4;
  62. EXPORT_SYMBOL(vmemmap_base);
  63. #endif
  64. static inline bool check_la57_support(void)
  65. {
  66. if (!IS_ENABLED(CONFIG_X86_5LEVEL))
  67. return false;
  68. /*
  69. * 5-level paging is detected and enabled at kernel decompression
  70. * stage. Only check if it has been enabled there.
  71. */
  72. if (!(native_read_cr4() & X86_CR4_LA57))
  73. return false;
  74. RIP_REL_REF(__pgtable_l5_enabled) = 1;
  75. RIP_REL_REF(pgdir_shift) = 48;
  76. RIP_REL_REF(ptrs_per_p4d) = 512;
  77. RIP_REL_REF(page_offset_base) = __PAGE_OFFSET_BASE_L5;
  78. RIP_REL_REF(vmalloc_base) = __VMALLOC_BASE_L5;
  79. RIP_REL_REF(vmemmap_base) = __VMEMMAP_BASE_L5;
  80. return true;
  81. }
  82. static unsigned long __head sme_postprocess_startup(struct boot_params *bp, pmdval_t *pmd)
  83. {
  84. unsigned long vaddr, vaddr_end;
  85. int i;
  86. /* Encrypt the kernel and related (if SME is active) */
  87. sme_encrypt_kernel(bp);
  88. /*
  89. * Clear the memory encryption mask from the .bss..decrypted section.
  90. * The bss section will be memset to zero later in the initialization so
  91. * there is no need to zero it after changing the memory encryption
  92. * attribute.
  93. */
  94. if (sme_get_me_mask()) {
  95. vaddr = (unsigned long)__start_bss_decrypted;
  96. vaddr_end = (unsigned long)__end_bss_decrypted;
  97. for (; vaddr < vaddr_end; vaddr += PMD_SIZE) {
  98. /*
  99. * On SNP, transition the page to shared in the RMP table so that
  100. * it is consistent with the page table attribute change.
  101. *
  102. * __start_bss_decrypted has a virtual address in the high range
  103. * mapping (kernel .text). PVALIDATE, by way of
  104. * early_snp_set_memory_shared(), requires a valid virtual
  105. * address but the kernel is currently running off of the identity
  106. * mapping so use __pa() to get a *currently* valid virtual address.
  107. */
  108. early_snp_set_memory_shared(__pa(vaddr), __pa(vaddr), PTRS_PER_PMD);
  109. i = pmd_index(vaddr);
  110. pmd[i] -= sme_get_me_mask();
  111. }
  112. }
  113. /*
  114. * Return the SME encryption mask (if SME is active) to be used as a
  115. * modifier for the initial pgdir entry programmed into CR3.
  116. */
  117. return sme_get_me_mask();
  118. }
  119. /* Code in __startup_64() can be relocated during execution, but the compiler
  120. * doesn't have to generate PC-relative relocations when accessing globals from
  121. * that function. Clang actually does not generate them, which leads to
  122. * boot-time crashes. To work around this problem, every global pointer must
  123. * be accessed using RIP_REL_REF().
  124. */
  125. unsigned long __head __startup_64(unsigned long physaddr,
  126. struct boot_params *bp)
  127. {
  128. pmd_t (*early_pgts)[PTRS_PER_PMD] = RIP_REL_REF(early_dynamic_pgts);
  129. unsigned long pgtable_flags;
  130. unsigned long load_delta;
  131. pgdval_t *pgd;
  132. p4dval_t *p4d;
  133. pudval_t *pud;
  134. pmdval_t *pmd, pmd_entry;
  135. bool la57;
  136. int i;
  137. la57 = check_la57_support();
  138. /* Is the address too large? */
  139. if (physaddr >> MAX_PHYSMEM_BITS)
  140. for (;;);
  141. /*
  142. * Compute the delta between the address I am compiled to run at
  143. * and the address I am actually running at.
  144. */
  145. load_delta = physaddr - (unsigned long)(_text - __START_KERNEL_map);
  146. RIP_REL_REF(phys_base) = load_delta;
  147. /* Is the address not 2M aligned? */
  148. if (load_delta & ~PMD_MASK)
  149. for (;;);
  150. /* Include the SME encryption mask in the fixup value */
  151. load_delta += sme_get_me_mask();
  152. /* Fixup the physical addresses in the page table */
  153. pgd = &RIP_REL_REF(early_top_pgt)->pgd;
  154. pgd[pgd_index(__START_KERNEL_map)] += load_delta;
  155. if (la57) {
  156. p4d = (p4dval_t *)&RIP_REL_REF(level4_kernel_pgt);
  157. p4d[MAX_PTRS_PER_P4D - 1] += load_delta;
  158. pgd[pgd_index(__START_KERNEL_map)] = (pgdval_t)p4d | _PAGE_TABLE;
  159. }
  160. RIP_REL_REF(level3_kernel_pgt)[PTRS_PER_PUD - 2].pud += load_delta;
  161. RIP_REL_REF(level3_kernel_pgt)[PTRS_PER_PUD - 1].pud += load_delta;
  162. for (i = FIXMAP_PMD_TOP; i > FIXMAP_PMD_TOP - FIXMAP_PMD_NUM; i--)
  163. RIP_REL_REF(level2_fixmap_pgt)[i].pmd += load_delta;
  164. /*
  165. * Set up the identity mapping for the switchover. These
  166. * entries should *NOT* have the global bit set! This also
  167. * creates a bunch of nonsense entries but that is fine --
  168. * it avoids problems around wraparound.
  169. */
  170. pud = &early_pgts[0]->pmd;
  171. pmd = &early_pgts[1]->pmd;
  172. RIP_REL_REF(next_early_pgt) = 2;
  173. pgtable_flags = _KERNPG_TABLE_NOENC + sme_get_me_mask();
  174. if (la57) {
  175. p4d = &early_pgts[RIP_REL_REF(next_early_pgt)++]->pmd;
  176. i = (physaddr >> PGDIR_SHIFT) % PTRS_PER_PGD;
  177. pgd[i + 0] = (pgdval_t)p4d + pgtable_flags;
  178. pgd[i + 1] = (pgdval_t)p4d + pgtable_flags;
  179. i = physaddr >> P4D_SHIFT;
  180. p4d[(i + 0) % PTRS_PER_P4D] = (pgdval_t)pud + pgtable_flags;
  181. p4d[(i + 1) % PTRS_PER_P4D] = (pgdval_t)pud + pgtable_flags;
  182. } else {
  183. i = (physaddr >> PGDIR_SHIFT) % PTRS_PER_PGD;
  184. pgd[i + 0] = (pgdval_t)pud + pgtable_flags;
  185. pgd[i + 1] = (pgdval_t)pud + pgtable_flags;
  186. }
  187. i = physaddr >> PUD_SHIFT;
  188. pud[(i + 0) % PTRS_PER_PUD] = (pudval_t)pmd + pgtable_flags;
  189. pud[(i + 1) % PTRS_PER_PUD] = (pudval_t)pmd + pgtable_flags;
  190. pmd_entry = __PAGE_KERNEL_LARGE_EXEC & ~_PAGE_GLOBAL;
  191. /* Filter out unsupported __PAGE_KERNEL_* bits: */
  192. pmd_entry &= RIP_REL_REF(__supported_pte_mask);
  193. pmd_entry += sme_get_me_mask();
  194. pmd_entry += physaddr;
  195. for (i = 0; i < DIV_ROUND_UP(_end - _text, PMD_SIZE); i++) {
  196. int idx = i + (physaddr >> PMD_SHIFT);
  197. pmd[idx % PTRS_PER_PMD] = pmd_entry + i * PMD_SIZE;
  198. }
  199. /*
  200. * Fixup the kernel text+data virtual addresses. Note that
  201. * we might write invalid pmds, when the kernel is relocated
  202. * cleanup_highmap() fixes this up along with the mappings
  203. * beyond _end.
  204. *
  205. * Only the region occupied by the kernel image has so far
  206. * been checked against the table of usable memory regions
  207. * provided by the firmware, so invalidate pages outside that
  208. * region. A page table entry that maps to a reserved area of
  209. * memory would allow processor speculation into that area,
  210. * and on some hardware (particularly the UV platform) even
  211. * speculative access to some reserved areas is caught as an
  212. * error, causing the BIOS to halt the system.
  213. */
  214. pmd = &RIP_REL_REF(level2_kernel_pgt)->pmd;
  215. /* invalidate pages before the kernel image */
  216. for (i = 0; i < pmd_index((unsigned long)_text); i++)
  217. pmd[i] &= ~_PAGE_PRESENT;
  218. /* fixup pages that are part of the kernel image */
  219. for (; i <= pmd_index((unsigned long)_end); i++)
  220. if (pmd[i] & _PAGE_PRESENT)
  221. pmd[i] += load_delta;
  222. /* invalidate pages after the kernel image */
  223. for (; i < PTRS_PER_PMD; i++)
  224. pmd[i] &= ~_PAGE_PRESENT;
  225. return sme_postprocess_startup(bp, pmd);
  226. }
  227. /* Wipe all early page tables except for the kernel symbol map */
  228. static void __init reset_early_page_tables(void)
  229. {
  230. memset(early_top_pgt, 0, sizeof(pgd_t)*(PTRS_PER_PGD-1));
  231. next_early_pgt = 0;
  232. write_cr3(__sme_pa_nodebug(early_top_pgt));
  233. }
  234. /* Create a new PMD entry */
  235. bool __init __early_make_pgtable(unsigned long address, pmdval_t pmd)
  236. {
  237. unsigned long physaddr = address - __PAGE_OFFSET;
  238. pgdval_t pgd, *pgd_p;
  239. p4dval_t p4d, *p4d_p;
  240. pudval_t pud, *pud_p;
  241. pmdval_t *pmd_p;
  242. /* Invalid address or early pgt is done ? */
  243. if (physaddr >= MAXMEM || read_cr3_pa() != __pa_nodebug(early_top_pgt))
  244. return false;
  245. again:
  246. pgd_p = &early_top_pgt[pgd_index(address)].pgd;
  247. pgd = *pgd_p;
  248. /*
  249. * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
  250. * critical -- __PAGE_OFFSET would point us back into the dynamic
  251. * range and we might end up looping forever...
  252. */
  253. if (!pgtable_l5_enabled())
  254. p4d_p = pgd_p;
  255. else if (pgd)
  256. p4d_p = (p4dval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
  257. else {
  258. if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
  259. reset_early_page_tables();
  260. goto again;
  261. }
  262. p4d_p = (p4dval_t *)early_dynamic_pgts[next_early_pgt++];
  263. memset(p4d_p, 0, sizeof(*p4d_p) * PTRS_PER_P4D);
  264. *pgd_p = (pgdval_t)p4d_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
  265. }
  266. p4d_p += p4d_index(address);
  267. p4d = *p4d_p;
  268. if (p4d)
  269. pud_p = (pudval_t *)((p4d & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
  270. else {
  271. if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
  272. reset_early_page_tables();
  273. goto again;
  274. }
  275. pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
  276. memset(pud_p, 0, sizeof(*pud_p) * PTRS_PER_PUD);
  277. *p4d_p = (p4dval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
  278. }
  279. pud_p += pud_index(address);
  280. pud = *pud_p;
  281. if (pud)
  282. pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
  283. else {
  284. if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
  285. reset_early_page_tables();
  286. goto again;
  287. }
  288. pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
  289. memset(pmd_p, 0, sizeof(*pmd_p) * PTRS_PER_PMD);
  290. *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
  291. }
  292. pmd_p[pmd_index(address)] = pmd;
  293. return true;
  294. }
  295. static bool __init early_make_pgtable(unsigned long address)
  296. {
  297. unsigned long physaddr = address - __PAGE_OFFSET;
  298. pmdval_t pmd;
  299. pmd = (physaddr & PMD_MASK) + early_pmd_flags;
  300. return __early_make_pgtable(address, pmd);
  301. }
  302. void __init do_early_exception(struct pt_regs *regs, int trapnr)
  303. {
  304. if (trapnr == X86_TRAP_PF &&
  305. early_make_pgtable(native_read_cr2()))
  306. return;
  307. if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT) &&
  308. trapnr == X86_TRAP_VC && handle_vc_boot_ghcb(regs))
  309. return;
  310. if (trapnr == X86_TRAP_VE && tdx_early_handle_ve(regs))
  311. return;
  312. early_fixup_exception(regs, trapnr);
  313. }
  314. /* Don't add a printk in there. printk relies on the PDA which is not initialized
  315. yet. */
  316. void __init clear_bss(void)
  317. {
  318. memset(__bss_start, 0,
  319. (unsigned long) __bss_stop - (unsigned long) __bss_start);
  320. memset(__brk_base, 0,
  321. (unsigned long) __brk_limit - (unsigned long) __brk_base);
  322. }
  323. static unsigned long get_cmd_line_ptr(void)
  324. {
  325. unsigned long cmd_line_ptr = boot_params.hdr.cmd_line_ptr;
  326. cmd_line_ptr |= (u64)boot_params.ext_cmd_line_ptr << 32;
  327. return cmd_line_ptr;
  328. }
  329. static void __init copy_bootdata(char *real_mode_data)
  330. {
  331. char * command_line;
  332. unsigned long cmd_line_ptr;
  333. /*
  334. * If SME is active, this will create decrypted mappings of the
  335. * boot data in advance of the copy operations.
  336. */
  337. sme_map_bootdata(real_mode_data);
  338. memcpy(&boot_params, real_mode_data, sizeof(boot_params));
  339. sanitize_boot_params(&boot_params);
  340. cmd_line_ptr = get_cmd_line_ptr();
  341. if (cmd_line_ptr) {
  342. command_line = __va(cmd_line_ptr);
  343. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  344. }
  345. /*
  346. * The old boot data is no longer needed and won't be reserved,
  347. * freeing up that memory for use by the system. If SME is active,
  348. * we need to remove the mappings that were created so that the
  349. * memory doesn't remain mapped as decrypted.
  350. */
  351. sme_unmap_bootdata(real_mode_data);
  352. }
  353. asmlinkage __visible void __init __noreturn x86_64_start_kernel(char * real_mode_data)
  354. {
  355. /*
  356. * Build-time sanity checks on the kernel image and module
  357. * area mappings. (these are purely build-time and produce no code)
  358. */
  359. BUILD_BUG_ON(MODULES_VADDR < __START_KERNEL_map);
  360. BUILD_BUG_ON(MODULES_VADDR - __START_KERNEL_map < KERNEL_IMAGE_SIZE);
  361. BUILD_BUG_ON(MODULES_LEN + KERNEL_IMAGE_SIZE > 2*PUD_SIZE);
  362. BUILD_BUG_ON((__START_KERNEL_map & ~PMD_MASK) != 0);
  363. BUILD_BUG_ON((MODULES_VADDR & ~PMD_MASK) != 0);
  364. BUILD_BUG_ON(!(MODULES_VADDR > __START_KERNEL));
  365. MAYBE_BUILD_BUG_ON(!(((MODULES_END - 1) & PGDIR_MASK) ==
  366. (__START_KERNEL & PGDIR_MASK)));
  367. BUILD_BUG_ON(__fix_to_virt(__end_of_fixed_addresses) <= MODULES_END);
  368. cr4_init_shadow();
  369. /* Kill off the identity-map trampoline */
  370. reset_early_page_tables();
  371. clear_bss();
  372. /*
  373. * This needs to happen *before* kasan_early_init() because latter maps stuff
  374. * into that page.
  375. */
  376. clear_page(init_top_pgt);
  377. /*
  378. * SME support may update early_pmd_flags to include the memory
  379. * encryption mask, so it needs to be called before anything
  380. * that may generate a page fault.
  381. */
  382. sme_early_init();
  383. kasan_early_init();
  384. /*
  385. * Flush global TLB entries which could be left over from the trampoline page
  386. * table.
  387. *
  388. * This needs to happen *after* kasan_early_init() as KASAN-enabled .configs
  389. * instrument native_write_cr4() so KASAN must be initialized for that
  390. * instrumentation to work.
  391. */
  392. __native_tlb_flush_global(this_cpu_read(cpu_tlbstate.cr4));
  393. idt_setup_early_handler();
  394. /* Needed before cc_platform_has() can be used for TDX */
  395. tdx_early_init();
  396. copy_bootdata(__va(real_mode_data));
  397. /*
  398. * Load microcode early on BSP.
  399. */
  400. load_ucode_bsp();
  401. /* set init_top_pgt kernel high mapping*/
  402. init_top_pgt[511] = early_top_pgt[511];
  403. x86_64_start_reservations(real_mode_data);
  404. }
  405. void __init __noreturn x86_64_start_reservations(char *real_mode_data)
  406. {
  407. /* version is always not zero if it is copied */
  408. if (!boot_params.hdr.version)
  409. copy_bootdata(__va(real_mode_data));
  410. x86_early_init_platform_quirks();
  411. switch (boot_params.hdr.hardware_subarch) {
  412. case X86_SUBARCH_INTEL_MID:
  413. x86_intel_mid_early_setup();
  414. break;
  415. default:
  416. break;
  417. }
  418. start_kernel();
  419. }
  420. /*
  421. * Data structures and code used for IDT setup in head_64.S. The bringup-IDT is
  422. * used until the idt_table takes over. On the boot CPU this happens in
  423. * x86_64_start_kernel(), on secondary CPUs in start_secondary(). In both cases
  424. * this happens in the functions called from head_64.S.
  425. *
  426. * The idt_table can't be used that early because all the code modifying it is
  427. * in idt.c and can be instrumented by tracing or KASAN, which both don't work
  428. * during early CPU bringup. Also the idt_table has the runtime vectors
  429. * configured which require certain CPU state to be setup already (like TSS),
  430. * which also hasn't happened yet in early CPU bringup.
  431. */
  432. static gate_desc bringup_idt_table[NUM_EXCEPTION_VECTORS] __page_aligned_data;
  433. /* This may run while still in the direct mapping */
  434. static void __head startup_64_load_idt(void *vc_handler)
  435. {
  436. struct desc_ptr desc = {
  437. .address = (unsigned long)&RIP_REL_REF(bringup_idt_table),
  438. .size = sizeof(bringup_idt_table) - 1,
  439. };
  440. struct idt_data data;
  441. gate_desc idt_desc;
  442. /* @vc_handler is set only for a VMM Communication Exception */
  443. if (vc_handler) {
  444. init_idt_data(&data, X86_TRAP_VC, vc_handler);
  445. idt_init_desc(&idt_desc, &data);
  446. native_write_idt_entry((gate_desc *)desc.address, X86_TRAP_VC, &idt_desc);
  447. }
  448. native_load_idt(&desc);
  449. }
  450. /* This is used when running on kernel addresses */
  451. void early_setup_idt(void)
  452. {
  453. void *handler = NULL;
  454. if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
  455. setup_ghcb();
  456. handler = vc_boot_ghcb;
  457. }
  458. startup_64_load_idt(handler);
  459. }
  460. /*
  461. * Setup boot CPU state needed before kernel switches to virtual addresses.
  462. */
  463. void __head startup_64_setup_gdt_idt(void)
  464. {
  465. struct desc_struct *gdt = (void *)(__force unsigned long)init_per_cpu_var(gdt_page.gdt);
  466. void *handler = NULL;
  467. struct desc_ptr startup_gdt_descr = {
  468. .address = (unsigned long)&RIP_REL_REF(*gdt),
  469. .size = GDT_SIZE - 1,
  470. };
  471. /* Load GDT */
  472. native_load_gdt(&startup_gdt_descr);
  473. /* New GDT is live - reload data segment registers */
  474. asm volatile("movl %%eax, %%ds\n"
  475. "movl %%eax, %%ss\n"
  476. "movl %%eax, %%es\n" : : "a"(__KERNEL_DS) : "memory");
  477. if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT))
  478. handler = &RIP_REL_REF(vc_no_ghcb);
  479. startup_64_load_idt(handler);
  480. }