• David Woodhouse's avatar
    x86/smpboot: Support parallel startup of secondary CPUs · 7e75178a
    David Woodhouse authored
    In parallel startup mode the APs are kicked alive by the control CPU
    quickly after each other and run through the early startup code in
    parallel. The real-mode startup code is already serialized with a
    bit-spinlock to protect the real-mode stack.
    
    In parallel startup mode the smpboot_control variable obviously cannot
    contain the Linux CPU number so the APs have to determine their Linux CPU
    number on their own. This is required to find the CPUs per CPU offset in
    order to find the idle task stack and other per CPU data.
    
    To achieve this, export the cpuid_to_apicid[] array so that each AP can
    find its own CPU number by searching therein based on its APIC ID.
    
    Introduce a flag in the top bits of smpboot_control which indicates that
    the AP should find its CPU number by reading the APIC ID from the APIC.
    
    This is required because CPUID based APIC ID retrieval can only provide the
    initial APIC ID, which might have been overruled by the firmware. Some AMD
    APUs come up with APIC ID = initial APIC ID + 0x10, so the APIC ID to CPU
    number lookup would fail miserably if based on CPUID. Also virtualization
    can make its own APIC ID assignements. The only requirement is that the
    APIC IDs are consistent with the APCI/MADT table.
    
    For the boot CPU or in case parallel bringup is disabled the control bits
    are empty and the CPU number is directly available in bit 0-23 of
    smpboot_control.
    
    [ tglx: Initial proof of concept patch with bitlock and APIC ID lookup ]
    [ dwmw2: Rework and testing, commit message, CPUID 0x1 and CPU0 support ]
    [ seanc: Fix stray override of initial_gs in common_cpu_up() ]
    [ Oleksandr Natalenko: reported suspend/resume issue fixed in
      x86_acpi_suspend_lowlevel ]
    [ tglx: Make it read the APIC ID from the APIC instead of using CPUID,
      	split the bitlock part out ]
    Co-developed-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Co-developed-by: default avatarBrian Gerst <brgerst@gmail.com>
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Signed-off-by: default avatarBrian Gerst <brgerst@gmail.com>
    Signed-off-by: default avatarDavid Woodhouse <dwmw@amazon.co.uk>
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Tested-by: default avatarMichael Kelley <mikelley@microsoft.com>
    Tested-by: default avatarOleksandr Natalenko <oleksandr@natalenko.name>
    Tested-by: Helge Deller <deller@gmx.de> # parisc
    Tested-by: Guilherme G. Piccoli <gpiccoli@igalia.com> # Steam Deck
    Link: https://lore.kernel.org/r/20230512205257.411554373@linutronix.de
    7e75178a
smp.h 5.34 KB