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