From: Andrew Cooper Date: Wed, 1 Jan 2025 13:23:15 +0000 (+0000) Subject: x86/traps: Fold init_idt_traps() and trap_init() into their single callers X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=e3ee5c4770089fdadaa1a2f971d7027bb138cc19;p=people%2Fandrewcoop%2Fxen.git x86/traps: Fold init_idt_traps() and trap_init() into their single callers --- diff --git a/xen/arch/x86/include/asm/system.h b/xen/arch/x86/include/asm/system.h index 73364056c7..8ceaaf45d1 100644 --- a/xen/arch/x86/include/asm/system.h +++ b/xen/arch/x86/include/asm/system.h @@ -263,8 +263,6 @@ static inline int local_irq_is_enabled(void) #define BROKEN_ACPI_Sx 0x0001 #define BROKEN_INIT_AFTER_S1 0x0002 -void trap_init(void); -void init_idt_traps(void); void load_system_tables(void); void subarch_percpu_traps_init(void); diff --git a/xen/arch/x86/traps-init.c b/xen/arch/x86/traps-init.c index 90338d561b..2858cc4ab9 100644 --- a/xen/arch/x86/traps-init.c +++ b/xen/arch/x86/traps-init.c @@ -3,6 +3,7 @@ * Configuration of event handling for all CPUs. */ #include +#include #include #include @@ -12,13 +13,63 @@ DEFINE_PER_CPU_READ_MOSTLY(idt_entry_t *, idt); +static bool __initdata opt_ler; +boolean_param("ler", opt_ler); + +void nocall entry_PF(void); + +static void __init init_ler(void) +{ + unsigned int msr = 0; + + if ( !opt_ler ) + return; + + /* + * Intel Pentium 4 is the only known CPU to not use the architectural MSR + * indicies. + */ + switch ( boot_cpu_data.x86_vendor ) + { + case X86_VENDOR_INTEL: + if ( boot_cpu_data.x86 == 0xf ) + { + msr = MSR_P4_LER_FROM_LIP; + break; + } + fallthrough; + case X86_VENDOR_AMD: + case X86_VENDOR_HYGON: + msr = MSR_IA32_LASTINTFROMIP; + break; + } + + if ( msr == 0 ) + { + printk(XENLOG_WARNING "LER disabled: failed to identify MSRs\n"); + return; + } + + ler_msr = msr; + setup_force_cpu_cap(X86_FEATURE_XEN_LBR); +} + /* * Configure basic exception handling. This is prior to parsing the command * line or configuring a console, and needs to be as simple as possible. */ void __init early_traps_init(void) { - init_idt_traps(); + /* Specify dedicated interrupt stacks for NMI, #DF, and #MC. */ + enable_each_ist(bsp_idt); + + /* CPU0 uses the master IDT. */ + this_cpu(idt) = bsp_idt; + + this_cpu(gdt) = boot_gdt; + if ( IS_ENABLED(CONFIG_PV32) ) + this_cpu(compat_gdt) = boot_compat_gdt; + load_system_tables(); } @@ -27,7 +78,19 @@ void __init early_traps_init(void) */ void __init traps_init(void) { - trap_init(); + /* Replace early pagefault with real pagefault handler. */ + _update_gate_addr_lower(&bsp_idt[X86_EXC_PF], entry_PF); + + init_ler(); + + /* Cache {,compat_}gdt_l1e now that physically relocation is done. */ + this_cpu(gdt_l1e) = + l1e_from_pfn(virt_to_mfn(boot_gdt), __PAGE_HYPERVISOR_RW); + if ( IS_ENABLED(CONFIG_PV32) ) + this_cpu(compat_gdt_l1e) = + l1e_from_pfn(virt_to_mfn(boot_compat_gdt), __PAGE_HYPERVISOR_RW); + + percpu_traps_init(); } /* diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index ce01630e90..9e4843ee16 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -106,9 +106,6 @@ DEFINE_PER_CPU_PAGE_ALIGNED(struct tss_page, tss_page); static int debug_stack_lines = 20; integer_param("debug_stack_lines", debug_stack_lines); -static bool __initdata opt_ler; -boolean_param("ler", opt_ler); - /* LastExceptionFromIP on this hardware. Zero if LER is not in use. */ unsigned int __ro_after_init ler_msr; @@ -1862,74 +1859,6 @@ void asmlinkage do_entry_CP(struct cpu_user_regs *regs) panic("CONTROL-FLOW PROTECTION FAULT: #CP[%04x] %s\n", ec, err); } -void nocall entry_PF(void); - -void __init init_idt_traps(void) -{ - /* Specify dedicated interrupt stacks for NMI, #DF, and #MC. */ - enable_each_ist(bsp_idt); - - /* CPU0 uses the master IDT. */ - this_cpu(idt) = bsp_idt; - - this_cpu(gdt) = boot_gdt; - if ( IS_ENABLED(CONFIG_PV32) ) - this_cpu(compat_gdt) = boot_compat_gdt; -} - -static void __init init_ler(void) -{ - unsigned int msr = 0; - - if ( !opt_ler ) - return; - - /* - * Intel Pentium 4 is the only known CPU to not use the architectural MSR - * indicies. - */ - switch ( boot_cpu_data.x86_vendor ) - { - case X86_VENDOR_INTEL: - if ( boot_cpu_data.x86 == 0xf ) - { - msr = MSR_P4_LER_FROM_LIP; - break; - } - fallthrough; - case X86_VENDOR_AMD: - case X86_VENDOR_HYGON: - msr = MSR_IA32_LASTINTFROMIP; - break; - } - - if ( msr == 0 ) - { - printk(XENLOG_WARNING "LER disabled: failed to identify MSRs\n"); - return; - } - - ler_msr = msr; - setup_force_cpu_cap(X86_FEATURE_XEN_LBR); -} - -void __init trap_init(void) -{ - /* Replace early pagefault with real pagefault handler. */ - _update_gate_addr_lower(&bsp_idt[X86_EXC_PF], entry_PF); - - init_ler(); - - /* Cache {,compat_}gdt_l1e now that physically relocation is done. */ - this_cpu(gdt_l1e) = - l1e_from_pfn(virt_to_mfn(boot_gdt), __PAGE_HYPERVISOR_RW); - if ( IS_ENABLED(CONFIG_PV32) ) - this_cpu(compat_gdt_l1e) = - l1e_from_pfn(virt_to_mfn(boot_compat_gdt), __PAGE_HYPERVISOR_RW); - - percpu_traps_init(); -} - void asm_domain_crash_synchronous(unsigned long addr) { /*