x86/apic: Prepare x2APIC for using apic::max_apic_id
authorThomas Gleixner <tglx@linutronix.de>
Tue, 8 Aug 2023 22:04:11 +0000 (15:04 -0700)
committerDave Hansen <dave.hansen@linux.intel.com>
Wed, 9 Aug 2023 18:58:31 +0000 (11:58 -0700)
In order to remove the apic::apic_id_valid() callback and switch to
checking apic::max_apic_id, it is required to update apic::max_apic_id when
the APIC initialization code overrides it via x2apic_set_max_apicid().

Make the existing booleans a bitfield and add a flag which lets the update
function and the core code which switches the driver detect whether the
apic instance wants to have that update or not and apply it if required.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Michael Kelley <mikelley@microsoft.com>
Tested-by: Sohil Mehta <sohil.mehta@intel.com>
Tested-by: Juergen Gross <jgross@suse.com> # Xen PV (dom0 and unpriv. guest)
arch/x86/include/asm/apic.h
arch/x86/kernel/apic/local.h
arch/x86/kernel/apic/probe_64.c
arch/x86/kernel/apic/x2apic_cluster.c
arch/x86/kernel/apic/x2apic_phys.c

index 42d3240f4f899469f3eff70fb516199b5343dfc8..2e79c13d3c65e9fbc17d6d0201efe136dbad4772 100644 (file)
@@ -266,10 +266,11 @@ struct apic {
        void    (*send_IPI_all)(int vector);
        void    (*send_IPI_self)(int vector);
 
-       u32     disable_esr;
-
        enum apic_delivery_modes delivery_mode;
-       bool    dest_mode_logical;
+
+       u32     disable_esr             : 1,
+               dest_mode_logical       : 1,
+               x2apic_set_max_apicid   : 1;
 
        u32     (*calc_dest_apicid)(unsigned int cpu);
 
index a250675cd97ec5d418abd2c54897cc5f657a8345..e576b3a4d29c2851495e5999b32783e35253af0c 100644 (file)
@@ -23,6 +23,7 @@ int x2apic_phys_pkg_id(int initial_apicid, int index_msb);
 void x2apic_send_IPI_all(int vector);
 void x2apic_send_IPI_allbutself(int vector);
 void x2apic_send_IPI_self(int vector);
+extern u32 x2apic_max_apicid;
 
 /* IPI */
 
index a82bb52d5c698dab3e4f57960c0f8e4cb6f201f6..a12a379280a861aaac3adb7e8450b4122b8a9886 100644 (file)
@@ -19,6 +19,10 @@ static __init void apic_install_driver(struct apic *driver)
                return;
 
        apic = driver;
+
+       if (IS_ENABLED(CONFIG_X86_X2APIC) && apic->x2apic_set_max_apicid)
+               apic->max_apic_id = x2apic_max_apicid;
+
        pr_info("Switched APIC routing to %s:\n", apic->name);
 }
 
index 036dd1c3a60bd931129c33adeec19bbab232cd42..a164764cb166bd35e39cc74b93db09422b993232 100644 (file)
@@ -240,6 +240,7 @@ static struct apic apic_x2apic_cluster __ro_after_init = {
        .phys_pkg_id                    = x2apic_phys_pkg_id,
 
        .max_apic_id                    = UINT_MAX,
+       .x2apic_set_max_apicid          = true,
        .get_apic_id                    = x2apic_get_apic_id,
        .set_apic_id                    = x2apic_set_apic_id,
 
index d292ec311c19258e37b834d3748aace8095bcac3..3aabfd336f1e32fc2492fc140f887b46f90d8109 100644 (file)
@@ -8,11 +8,13 @@
 int x2apic_phys;
 
 static struct apic apic_x2apic_phys;
-static u32 x2apic_max_apicid __ro_after_init = UINT_MAX;
+u32 x2apic_max_apicid __ro_after_init = UINT_MAX;
 
 void __init x2apic_set_max_apicid(u32 apicid)
 {
        x2apic_max_apicid = apicid;
+       if (apic->x2apic_set_max_apicid)
+               apic->max_apic_id = apicid;
 }
 
 static int __init set_x2apic_phys_mode(char *arg)
@@ -161,6 +163,7 @@ static struct apic apic_x2apic_phys __ro_after_init = {
        .phys_pkg_id                    = x2apic_phys_pkg_id,
 
        .max_apic_id                    = UINT_MAX,
+       .x2apic_set_max_apicid          = true,
        .get_apic_id                    = x2apic_get_apic_id,
        .set_apic_id                    = x2apic_set_apic_id,