x86/apic: Move TSC deadline timer debug printk

Leon reported that the printk_once() in __setup_APIC_LVTT() triggers a
lockdep splat due to a lock order violation between hrtimer_base::lock and
console_sem, when the 'once' condition is reset via
/sys/kernel/debug/clear_warn_once after boot.

The initial printk cannot trigger this because that happens during boot
when the local APIC timer is set up on the boot CPU.

Prevent it by moving the printk to a place which is guaranteed to be only
called once during boot.

Mark the deadline timer check related functions and data __init while at
it.

Reported-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/87y2qhoshi.fsf@nanos.tec.linutronix.de

Changed files
+14 -13
arch
x86
kernel
apic
+14 -13
arch/x86/kernel/apic/apic.c
··· 352 * According to Intel, MFENCE can do the serialization here. 353 */ 354 asm volatile("mfence" : : : "memory"); 355 - 356 - printk_once(KERN_DEBUG "TSC deadline timer enabled\n"); 357 return; 358 } 359 ··· 544 }; 545 static DEFINE_PER_CPU(struct clock_event_device, lapic_events); 546 547 - static u32 hsx_deadline_rev(void) 548 { 549 switch (boot_cpu_data.x86_stepping) { 550 case 0x02: return 0x3a; /* EP */ ··· 554 return ~0U; 555 } 556 557 - static u32 bdx_deadline_rev(void) 558 { 559 switch (boot_cpu_data.x86_stepping) { 560 case 0x02: return 0x00000011; ··· 566 return ~0U; 567 } 568 569 - static u32 skx_deadline_rev(void) 570 { 571 switch (boot_cpu_data.x86_stepping) { 572 case 0x03: return 0x01000136; ··· 579 return ~0U; 580 } 581 582 - static const struct x86_cpu_id deadline_match[] = { 583 X86_MATCH_INTEL_FAM6_MODEL( HASWELL_X, &hsx_deadline_rev), 584 X86_MATCH_INTEL_FAM6_MODEL( BROADWELL_X, 0x0b000020), 585 X86_MATCH_INTEL_FAM6_MODEL( BROADWELL_D, &bdx_deadline_rev), ··· 601 {}, 602 }; 603 604 - static void apic_check_deadline_errata(void) 605 { 606 const struct x86_cpu_id *m; 607 u32 rev; 608 609 - if (!boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER) || 610 - boot_cpu_has(X86_FEATURE_HYPERVISOR)) 611 - return; 612 613 m = x86_match_cpu(deadline_match); 614 if (!m) 615 - return; 616 617 /* 618 * Function pointers will have the MSB set due to address layout, ··· 625 rev = (u32)m->driver_data; 626 627 if (boot_cpu_data.microcode >= rev) 628 - return; 629 630 setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER); 631 pr_err(FW_BUG "TSC_DEADLINE disabled due to Errata; " 632 "please update microcode to version: 0x%x (or later)\n", rev); 633 } 634 635 /* ··· 2092 { 2093 unsigned int new_apicid; 2094 2095 - apic_check_deadline_errata(); 2096 2097 if (x2apic_mode) { 2098 boot_cpu_physical_apicid = read_apic_id();
··· 352 * According to Intel, MFENCE can do the serialization here. 353 */ 354 asm volatile("mfence" : : : "memory"); 355 return; 356 } 357 ··· 546 }; 547 static DEFINE_PER_CPU(struct clock_event_device, lapic_events); 548 549 + static __init u32 hsx_deadline_rev(void) 550 { 551 switch (boot_cpu_data.x86_stepping) { 552 case 0x02: return 0x3a; /* EP */ ··· 556 return ~0U; 557 } 558 559 + static __init u32 bdx_deadline_rev(void) 560 { 561 switch (boot_cpu_data.x86_stepping) { 562 case 0x02: return 0x00000011; ··· 568 return ~0U; 569 } 570 571 + static __init u32 skx_deadline_rev(void) 572 { 573 switch (boot_cpu_data.x86_stepping) { 574 case 0x03: return 0x01000136; ··· 581 return ~0U; 582 } 583 584 + static const struct x86_cpu_id deadline_match[] __initconst = { 585 X86_MATCH_INTEL_FAM6_MODEL( HASWELL_X, &hsx_deadline_rev), 586 X86_MATCH_INTEL_FAM6_MODEL( BROADWELL_X, 0x0b000020), 587 X86_MATCH_INTEL_FAM6_MODEL( BROADWELL_D, &bdx_deadline_rev), ··· 603 {}, 604 }; 605 606 + static __init bool apic_validate_deadline_timer(void) 607 { 608 const struct x86_cpu_id *m; 609 u32 rev; 610 611 + if (!boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER)) 612 + return false; 613 + if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) 614 + return true; 615 616 m = x86_match_cpu(deadline_match); 617 if (!m) 618 + return true; 619 620 /* 621 * Function pointers will have the MSB set due to address layout, ··· 626 rev = (u32)m->driver_data; 627 628 if (boot_cpu_data.microcode >= rev) 629 + return true; 630 631 setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER); 632 pr_err(FW_BUG "TSC_DEADLINE disabled due to Errata; " 633 "please update microcode to version: 0x%x (or later)\n", rev); 634 + return false; 635 } 636 637 /* ··· 2092 { 2093 unsigned int new_apicid; 2094 2095 + if (apic_validate_deadline_timer()) 2096 + pr_debug("TSC deadline timer available\n"); 2097 2098 if (x2apic_mode) { 2099 boot_cpu_physical_apicid = read_apic_id();