|
22 | 22 | #include <linux/cc_platform.h>
|
23 | 23 | #include <linux/pgtable.h>
|
24 | 24 |
|
| 25 | +#include <asm/asm.h> |
25 | 26 | #include <asm/processor.h>
|
26 | 27 | #include <asm/proto.h>
|
27 | 28 | #include <asm/smp.h>
|
@@ -76,15 +77,6 @@ static struct desc_struct startup_gdt[GDT_ENTRIES] __initdata = {
|
76 | 77 | [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(DESC_DATA64, 0, 0xfffff),
|
77 | 78 | };
|
78 | 79 |
|
79 |
| -/* |
80 |
| - * Address needs to be set at runtime because it references the startup_gdt |
81 |
| - * while the kernel still uses a direct mapping. |
82 |
| - */ |
83 |
| -static struct desc_ptr startup_gdt_descr __initdata = { |
84 |
| - .size = sizeof(startup_gdt)-1, |
85 |
| - .address = 0, |
86 |
| -}; |
87 |
| - |
88 | 80 | static void __head *fixup_pointer(void *ptr, unsigned long physaddr)
|
89 | 81 | {
|
90 | 82 | return ptr - (void *)_text + (void *)physaddr;
|
@@ -569,68 +561,61 @@ void __init __noreturn x86_64_start_reservations(char *real_mode_data)
|
569 | 561 | */
|
570 | 562 | static gate_desc bringup_idt_table[NUM_EXCEPTION_VECTORS] __page_aligned_data;
|
571 | 563 |
|
572 |
| -static struct desc_ptr bringup_idt_descr = { |
573 |
| - .size = (NUM_EXCEPTION_VECTORS * sizeof(gate_desc)) - 1, |
574 |
| - .address = 0, /* Set at runtime */ |
575 |
| -}; |
576 |
| - |
577 |
| -static void set_bringup_idt_handler(gate_desc *idt, int n, void *handler) |
| 564 | +/* This may run while still in the direct mapping */ |
| 565 | +static void __head startup_64_load_idt(void *vc_handler) |
578 | 566 | {
|
579 |
| -#ifdef CONFIG_AMD_MEM_ENCRYPT |
| 567 | + struct desc_ptr desc = { |
| 568 | + .address = (unsigned long)&RIP_REL_REF(bringup_idt_table), |
| 569 | + .size = sizeof(bringup_idt_table) - 1, |
| 570 | + }; |
580 | 571 | struct idt_data data;
|
581 |
| - gate_desc desc; |
582 |
| - |
583 |
| - init_idt_data(&data, n, handler); |
584 |
| - idt_init_desc(&desc, &data); |
585 |
| - native_write_idt_entry(idt, n, &desc); |
586 |
| -#endif |
587 |
| -} |
| 572 | + gate_desc idt_desc; |
588 | 573 |
|
589 |
| -/* This runs while still in the direct mapping */ |
590 |
| -static void __head startup_64_load_idt(unsigned long physbase) |
591 |
| -{ |
592 |
| - struct desc_ptr *desc = fixup_pointer(&bringup_idt_descr, physbase); |
593 |
| - gate_desc *idt = fixup_pointer(bringup_idt_table, physbase); |
594 |
| - |
595 |
| - |
596 |
| - if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { |
597 |
| - void *handler; |
598 |
| - |
599 |
| - /* VMM Communication Exception */ |
600 |
| - handler = fixup_pointer(vc_no_ghcb, physbase); |
601 |
| - set_bringup_idt_handler(idt, X86_TRAP_VC, handler); |
| 574 | + /* @vc_handler is set only for a VMM Communication Exception */ |
| 575 | + if (vc_handler) { |
| 576 | + init_idt_data(&data, X86_TRAP_VC, vc_handler); |
| 577 | + idt_init_desc(&idt_desc, &data); |
| 578 | + native_write_idt_entry((gate_desc *)desc.address, X86_TRAP_VC, &idt_desc); |
602 | 579 | }
|
603 | 580 |
|
604 |
| - desc->address = (unsigned long)idt; |
605 |
| - native_load_idt(desc); |
| 581 | + native_load_idt(&desc); |
606 | 582 | }
|
607 | 583 |
|
608 | 584 | /* This is used when running on kernel addresses */
|
609 | 585 | void early_setup_idt(void)
|
610 | 586 | {
|
611 |
| - /* VMM Communication Exception */ |
| 587 | + void *handler = NULL; |
| 588 | + |
612 | 589 | if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
|
613 | 590 | setup_ghcb();
|
614 |
| - set_bringup_idt_handler(bringup_idt_table, X86_TRAP_VC, vc_boot_ghcb); |
| 591 | + handler = vc_boot_ghcb; |
615 | 592 | }
|
616 | 593 |
|
617 |
| - bringup_idt_descr.address = (unsigned long)bringup_idt_table; |
618 |
| - native_load_idt(&bringup_idt_descr); |
| 594 | + startup_64_load_idt(handler); |
619 | 595 | }
|
620 | 596 |
|
621 | 597 | /*
|
622 | 598 | * Setup boot CPU state needed before kernel switches to virtual addresses.
|
623 | 599 | */
|
624 |
| -void __head startup_64_setup_env(unsigned long physbase) |
| 600 | +void __head startup_64_setup_gdt_idt(void) |
625 | 601 | {
|
| 602 | + void *handler = NULL; |
| 603 | + |
| 604 | + struct desc_ptr startup_gdt_descr = { |
| 605 | + .address = (unsigned long)&RIP_REL_REF(startup_gdt), |
| 606 | + .size = sizeof(startup_gdt) - 1, |
| 607 | + }; |
| 608 | + |
626 | 609 | /* Load GDT */
|
627 |
| - startup_gdt_descr.address = (unsigned long)fixup_pointer(startup_gdt, physbase); |
628 | 610 | native_load_gdt(&startup_gdt_descr);
|
629 | 611 |
|
630 | 612 | /* New GDT is live - reload data segment registers */
|
631 | 613 | asm volatile("movl %%eax, %%ds\n"
|
632 | 614 | "movl %%eax, %%ss\n"
|
633 | 615 | "movl %%eax, %%es\n" : : "a"(__KERNEL_DS) : "memory");
|
634 | 616 |
|
635 |
| - startup_64_load_idt(physbase); |
| 617 | + if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) |
| 618 | + handler = &RIP_REL_REF(vc_no_ghcb); |
| 619 | + |
| 620 | + startup_64_load_idt(handler); |
636 | 621 | }
|
0 commit comments