[V3,12/60] x86/of: Fix the APIC address registration

Message ID 20230801103815.818545643@linutronix.de
State New
Headers
Series [V3,01/60] x86/cpu: Make identify_boot_cpu() static |

Commit Message

Thomas Gleixner Aug. 1, 2023, 10:46 a.m. UTC
  The device tree APIC parser tries to force enable the local APIC when it is
not set in CPUID. apic_force_enable() registers the boot CPU apic on
success.

If that succeeds then dtb_lapic_setup() registers the local APIC again
eventually with a different address.

Rewrite the code so that it only registers it once.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/kernel/devicetree.c |   14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
  

Comments

Dave Hansen Aug. 3, 2023, 10:42 p.m. UTC | #1
On 8/1/23 03:46, Thomas Gleixner wrote:
> The device tree APIC parser tries to force enable the local APIC when it is
> not set in CPUID. apic_force_enable() registers the boot CPU apic on
> success.

I went looking for how this registration happens.  I was expecting to
see something apic_force_enable() do something similar to
register_lapic_address().

But the apic_force_enable()=>apic_verify() call chain is pretty shallow
and I'm not seeing a lot of overlap.

Am I reading the "registers" part of this too literally?
  
Thomas Gleixner Aug. 3, 2023, 11:35 p.m. UTC | #2
On Thu, Aug 03 2023 at 15:42, Dave Hansen wrote:
> On 8/1/23 03:46, Thomas Gleixner wrote:
>> The device tree APIC parser tries to force enable the local APIC when it is
>> not set in CPUID. apic_force_enable() registers the boot CPU apic on
>> success.
>
> I went looking for how this registration happens.  I was expecting to
> see something apic_force_enable() do something similar to
> register_lapic_address().
>
> But the apic_force_enable()=>apic_verify() call chain is pretty shallow
> and I'm not seeing a lot of overlap.

apic_verify() ends up invoking register_lapic_address() on success, no?
  

Patch

--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -157,19 +157,15 @@  static void __init dtb_lapic_setup(void)
 
 	/* Did the boot loader setup the local APIC ? */
 	if (!boot_cpu_has(X86_FEATURE_APIC)) {
+		/* Try force enabling, which registers the APIC address */
 		if (apic_force_enable(lapic_addr))
 			return;
-	}
-	smp_found_config = 1;
-	if (of_property_read_bool(dn, "intel,virtual-wire-mode")) {
-		pr_info("Virtual Wire compatibility mode.\n");
-		pic_mode = 0;
 	} else {
-		pr_info("IMCR and PIC compatibility mode.\n");
-		pic_mode = 1;
+		register_lapic_address(lapic_addr);
 	}
-
-	register_lapic_address(lapic_addr);
+	smp_found_config = 1;
+	pic_mode = !of_property_read_bool(dn, "intel,virtual-wire-mode");
+	pr_info("%s compatibility mode.\n", pic_mode ? "IMCR and PIC" : "Virtual Wire");
 }
 
 #endif /* CONFIG_X86_LOCAL_APIC */