Skip to contentSkip to conversation

x86: APIC related clean up

PATCH In review Yinghai Lu 3 participants 32 messages Oct 24, 2010 – Oct 29, 2010

Subsystems (3)
lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

cover x86: APIC related clean up

1. Merge acpi_register_lapic_address, smp_register_lapic_address, sfi_register_lapic_address

2. nox2apic support: disable x2apic for preenabled system or kexec path.

Thanks

Yinghai Lu

71fee2d: x86: Disabling x2apic if nox2apic is specified
017b8d0: acpi: Reverse uid and apic_id print out for x2apic 0c2a5ca: x86, apic, acpi: Handle xapic/x2apic entries in MADT at same time 88c4f93: x86, x2apic: Don't map lapic addr for preenabled x2apic 7084cf3: x86, ioapic: Only print mapping for ioapic in right place
d4c4263: x86, apic: Set fixmap only one time
19fafd5: x86: on !find_smp_config path use smp_register_lapic_address 74c3593: x86, visws: Set_fixmap in find_smp_config
039ff68: x86, sfi: Use smp_register_lapic_address()
6f13e6a: x86, apic: Use smp_register_lapic_address in init_apic_mapping 48c02b1: x86: Call smp_register_lapic_address for contruct_default mptable path
d2f3d61: x86, apic: Remove early_init_lapic_mapping
3887e09: x86, apic: Merge two register_lapic_address()
703583d: x86, apic: Fix lapic mapping with construct ISA and visws mptable path
a2bd134: x86, apic: Don't write io_apic ID if it is not changed

 arch/x86/include/asm/apic.h    |    8 +++-
 arch/x86/include/asm/apicdef.h |    1 +
 arch/x86/kernel/acpi/boot.c    |   61 +++++++++++++---------
 arch/x86/kernel/apic/apic.c    |  110 +++++++++++++++++++++++++---------------
 arch/x86/kernel/apic/io_apic.c |   19 ++++---
 arch/x86/kernel/mpparse.c      |   24 ++-------
 arch/x86/kernel/sfi.c          |   13 +----
 arch/x86/kernel/visws_quirks.c |    1 +
 arch/x86/mm/k8topology_64.c    |    1 -
 arch/x86/mm/srat_64.c          |   12 ++++-
 drivers/acpi/numa.c            |   18 +++++--
 drivers/acpi/tables.c          |   60 ++++++++++++++++------
 include/linux/acpi.h           |    8 +++
 13 files changed, 207 insertions(+), 129 deletions(-)
author
#1 lore raw

PATCH 1/15 x86, apic: Don't write io_apic ID if it is not changed

For 32bit mptable path, setup_ids_from_mpc() always write io apic id register, even there is no change needed.

So try to do that when they are different bewteen reading out and mptable

---
 arch/x86/kernel/apic/io_apic.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/kernel/apic/io_apic.c +5 -3
index ce3c6fb..0579b3b 100644
@@ -2006,7 +2006,6 @@ void __init setup_ioapic_ids_from_mpc(void)
 			physids_or(phys_id_present_map, phys_id_present_map, tmp);
 		}
 
-
 		/*
 		 * We need to adjust the IRQ routing table
 		 * if the ID changed.
@@ -2018,9 +2017,12 @@ void __init setup_ioapic_ids_from_mpc(void)
 						= mp_ioapics[apic_id].apicid;
 
 		/*
-		 * Read the right value from the MPC table and
-		 * write it into the ID register.
+		 * Update the ID register according to the right value from
+		 *  the MPC table if they are different.
 		 */
+		if (mp_ioapics[apic_id].apicid == reg_00.bits.ID)
+			continue;
+
 		apic_printk(APIC_VERBOSE, KERN_INFO
 			"...changing IO-APIC physical APIC ID to %d ...",
 			mp_ioapics[apic_id].apicid);
Signature · 1 line
1.7.1
author
#2 lore raw

PATCH 2/15 x86, apic: Fix lapic mapping with construct ISA and visws mptable path

In reply to Yinghai Lu

Do need to set lapic mapping for them

in arch/x86/kernel/visws_quirks.c:
we only have visws_find_smp_config() to set mp_lapic_addr to APIC_DEFAULT_PHYS_BASE visws_get_smp_config() is nop call. default_get_smp_config/check_physptr/smp_read_mpc is not called in the path. So smp_register_lapic_address() is not called, and lapic is not mapped.

in arch/x86/kernel/mpparse.c
if mpf->feature1 != 0, it will go through contruct_default_ISA_mptable instead of check_phystr path, so smp_register_lapic_address is not called.

Those pathes all have smp_found_config set.

So need to remove !smp_found_config checking

---
 arch/x86/kernel/apic/apic.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/apic/apic.c +1 -1
index 4638396..193e407 100644
@@ -1677,7 +1677,7 @@ void __init init_apic_mappings(void)
 		 * acpi lapic path already maps that address in
 		 * acpi_register_lapic_address()
 		 */
-		if (!acpi_lapic && !smp_found_config)
+		if (!acpi_lapic)
 			set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
 
 		apic_printk(APIC_VERBOSE, "mapped APIC to %08lx (%08lx)\n",
Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH 02/15] x86, apic: Fix lapic mapping with construct ISA and visws mptable path

Quoted 7 lines · Yinghai Lu

Do need to set lapic mapping for them

in arch/x86/kernel/visws_quirks.c:
we only have visws_find_smp_config() to set mp_lapic_addr to APIC_DEFAULT_PHYS_BASE visws_get_smp_config() is nop call. default_get_smp_config/check_physptr/smp_read_mpc is not called in the path. So smp_register_lapic_address() is not called, and lapic is not mapped.

-ENOPARSE. visws maps the APIC itself already in cobalt_init()

Quoted 7 lines

in arch/x86/kernel/mpparse.c
if mpf->feature1 != 0, it will go through contruct_default_ISA_mptable instead of check_phystr path, so smp_register_lapic_address is not called.

Those pathes all have smp_found_config set.

So need to remove !smp_found_config checking

Need ? You can, because the check is redundant if I understand the above correctly.

Thanks,

tglx

Quoted 21 lines
---
 arch/x86/kernel/apic/apic.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/apic/apic.c +1 -1
index 4638396..193e407 100644
@@ -1677,7 +1677,7 @@ void __init init_apic_mappings(void)
 		 * acpi lapic path already maps that address in
 		 * acpi_register_lapic_address()
 		 */
-		if (!acpi_lapic && !smp_found_config)
+		if (!acpi_lapic)
 			set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
 
 		apic_printk(APIC_VERBOSE, "mapped APIC to %08lx (%08lx)\n",
Signature · 1 line
1.7.1
author
#4 lore raw

PATCH 3/15 x86, apic: Merge two register_lapic_address()

In reply to Yinghai Lu

They are the same, move it to apic.c

---
 arch/x86/include/asm/apic.h |    1 +
 arch/x86/kernel/acpi/boot.c |   16 ++--------------
 arch/x86/kernel/apic/apic.c |   12 ++++++++++++
 arch/x86/kernel/mpparse.c   |   12 ------------
 4 files changed, 15 insertions(+), 26 deletions(-)
arch/x86/include/asm/apic.h +1 -0
index ad50aaa..dcc5f48 100644
@@ -234,6 +234,7 @@ extern void init_bsp_APIC(void);
 extern void setup_local_APIC(void);
 extern void end_local_APIC_setup(void);
 extern void init_apic_mappings(void);
+void smp_register_lapic_address(unsigned long address);
 extern void setup_boot_APIC_clock(void);
 extern void setup_secondary_APIC_clock(void);
 extern int APIC_init_uniprocessor(void);
arch/x86/kernel/acpi/boot.c +2 -14
index c05872a..f9f1bc5 100644
@@ -820,18 +820,6 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
  * returns 0 on success, < 0 on error
  */
 
-static void __init acpi_register_lapic_address(unsigned long address)
-{
-	mp_lapic_addr = address;
-
-	set_fixmap_nocache(FIX_APIC_BASE, address);
-	if (boot_cpu_physical_apicid == -1U) {
-		boot_cpu_physical_apicid  = read_apic_id();
-		apic_version[boot_cpu_physical_apicid] =
-			 GET_APIC_VERSION(apic_read(APIC_LVR));
-	}
-}
-
 static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
 {
 	int count;
@@ -853,7 +841,7 @@ static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
 		return count;
 	}
 
-	acpi_register_lapic_address(acpi_lapic_addr);
+	smp_register_lapic_address(acpi_lapic_addr);
 
 	return count;
 }
@@ -880,7 +868,7 @@ static int __init acpi_parse_madt_lapic_entries(void)
 		return count;
 	}
 
-	acpi_register_lapic_address(acpi_lapic_addr);
+	smp_register_lapic_address(acpi_lapic_addr);
 
 	count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
 				      acpi_parse_sapic, MAX_APICS);
arch/x86/kernel/apic/apic.c +12 -0
index 193e407..4827c17 100644
@@ -1703,6 +1703,18 @@ void __init init_apic_mappings(void)
 	}
 }
 
+void __init smp_register_lapic_address(unsigned long address)
+{
+	mp_lapic_addr = address;
+
+	set_fixmap_nocache(FIX_APIC_BASE, address);
+	if (boot_cpu_physical_apicid == -1U) {
+		boot_cpu_physical_apicid  = read_apic_id();
+		apic_version[boot_cpu_physical_apicid] =
+			 GET_APIC_VERSION(apic_read(APIC_LVR));
+	}
+}
+
 /*
  * This initializes the IO-APIC and APIC hardware if this is
  * a UP kernel.
arch/x86/kernel/mpparse.c +0 -12
index 9af64d9..1fefb7f 100644
@@ -275,18 +275,6 @@ static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
 
 void __init default_smp_read_mpc_oem(struct mpc_table *mpc) { }
 
-static void __init smp_register_lapic_address(unsigned long address)
-{
-	mp_lapic_addr = address;
-
-	set_fixmap_nocache(FIX_APIC_BASE, address);
-	if (boot_cpu_physical_apicid == -1U) {
-		boot_cpu_physical_apicid  = read_apic_id();
-		apic_version[boot_cpu_physical_apicid] =
-			 GET_APIC_VERSION(apic_read(APIC_LVR));
-	}
-}
-
 static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
 {
 	char str[16];
Signature · 1 line
1.7.1
#5 lore raw

Re: [PATCH 03/15] x86, apic: Merge two register_lapic_address()

Quoted 15 lines · Yinghai Lu

They are the same, move it to apic.c

---
 arch/x86/include/asm/apic.h |    1 +
 arch/x86/kernel/acpi/boot.c |   16 ++--------------
 arch/x86/kernel/apic/apic.c |   12 ++++++++++++
 arch/x86/kernel/mpparse.c   |   12 ------------
 4 files changed, 15 insertions(+), 26 deletions(-)
arch/x86/include/asm/apic.h +0 -0
index ad50aaa..dcc5f48 100644

arch/x86/include/asm/apic.h extern void init_bsp_APIC(void); · line 237

Quoted 4 lines
arch/x86/include/asm/apic.h +1 -0
@@ -234,6 +234,7 @@ extern void init_bsp_APIC(void);
 extern void setup_local_APIC(void);
 extern void end_local_APIC_setup(void);
 extern void init_apic_mappings(void);
+void smp_register_lapic_address(unsigned long address);

And why must this be restricted to smp ?

Thanks,

tglx

author
#6 lore raw

PATCH 4/15 x86, apic: Remove early_init_lapic_mapping

In reply to Yinghai Lu

It is almost the same as smp_register_lapic_addr()

Just need to make smp_read_mpc() call smp_register_lapic_addr when early==1.

also add printing out in smp_register_lapic_address()

---
 arch/x86/include/asm/apic.h |    1 -
 arch/x86/kernel/apic/apic.c |   24 ++----------------------
 arch/x86/kernel/mpparse.c   |    8 ++------
 arch/x86/mm/k8topology_64.c |    1 -
 4 files changed, 4 insertions(+), 30 deletions(-)
arch/x86/include/asm/apic.h +0 -1
index dcc5f48..69879dd 100644
@@ -245,7 +245,6 @@ extern int apic_force_enable(void);
  * On 32bit this is mach-xxx local
  */
 #ifdef CONFIG_X86_64
-extern void early_init_lapic_mapping(void);
 extern int apic_is_clustered_box(void);
 #else
 static inline int apic_is_clustered_box(void)
arch/x86/kernel/apic/apic.c +2 -22
index 4827c17..05b8bf7 100644
@@ -1631,28 +1631,6 @@ no_apic:
 }
 #endif
 
-#ifdef CONFIG_X86_64
-void __init early_init_lapic_mapping(void)
-{
-	/*
-	 * If no local APIC can be found then go out
-	 * : it means there is no mpatable and MADT
-	 */
-	if (!smp_found_config)
-		return;
-
-	set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
-	apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
-		    APIC_BASE, mp_lapic_addr);
-
-	/*
-	 * Fetch the APIC ID of the BSP in case we have a
-	 * default configuration (or the MP table is broken).
-	 */
-	boot_cpu_physical_apicid = read_apic_id();
-}
-#endif
-
 /**
  * init_apic_mappings - initialize APIC mappings
  */
@@ -1708,6 +1686,8 @@ void __init smp_register_lapic_address(unsigned long address)
 	mp_lapic_addr = address;
 
 	set_fixmap_nocache(FIX_APIC_BASE, address);
+	apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
+		    APIC_BASE, mp_lapic_addr);
 	if (boot_cpu_physical_apicid == -1U) {
 		boot_cpu_physical_apicid  = read_apic_id();
 		apic_version[boot_cpu_physical_apicid] =
arch/x86/kernel/mpparse.c +2 -6
index 1fefb7f..a550315 100644
@@ -289,17 +289,13 @@ static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
 #ifdef CONFIG_X86_32
 	generic_mps_oem_check(mpc, oem, str);
 #endif
-	/* save the local APIC address, it might be non-default */
+	/* Initialize the lapic mapping */
 	if (!acpi_lapic)
-		mp_lapic_addr = mpc->lapic;
+		smp_register_lapic_address(mpc->lapic);
 
 	if (early)
 		return 1;
 
-	/* Initialize the lapic mapping */
-	if (!acpi_lapic)
-		smp_register_lapic_address(mpc->lapic);
-
 	if (mpc->oemptr)
 		x86_init.mpparse.smp_read_mpc_oem(mpc);
 
arch/x86/mm/k8topology_64.c +0 -1
index 804a3b6..446bae2 100644
@@ -66,7 +66,6 @@ static __init void early_get_boot_cpu_id(void)
 	if (smp_found_config)
 		early_get_smp_config();
 #endif
-	early_init_lapic_mapping();
 }
 
 int __init k8_get_nodes(struct bootnode *physnodes)
Signature · 1 line
1.7.1
#7 lore raw

Re: [PATCH 04/15] x86, apic: Remove early_init_lapic_mapping

arch/x86/kernel/mpparse.c static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early) · line 294

Quoted 13 lines · Yinghai Lu

It is almost the same as smp_register_lapic_addr()

Just need to make smp_read_mpc() call smp_register_lapic_addr when early==1.

arch/x86/kernel/mpparse.c +2 -2
@@ -289,17 +289,13 @@ static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
 #ifdef CONFIG_X86_32
 	generic_mps_oem_check(mpc, oem, str);
 #endif
-	/* save the local APIC address, it might be non-default */
+	/* Initialize the lapic mapping */
 	if (!acpi_lapic)
-		mp_lapic_addr = mpc->lapic;
+		smp_register_lapic_address(mpc->lapic);

How is this restricted to early == 1 ? It's called unconditionally which is nonsense.

Thanks,

tglx

author
#8 lore raw

PATCH 5/15 x86: Call smp_register_lapic_address for contruct_default mptable path

In reply to Yinghai Lu

It already finds smp config, make it like other find_smp_config path

---
 arch/x86/kernel/mpparse.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/mpparse.c +2 -2
index a550315..7b72904 100644
@@ -481,7 +481,7 @@ static inline void __init construct_default_ISA_mptable(int mpc_default_type)
 	/*
 	 * local APIC has default address
 	 */
-	mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
+	smp_register_lapic_address(APIC_DEFAULT_PHYS_BASE);
 
 	/*
 	 * 2 CPUs, numbered 0 & 1.
@@ -617,7 +617,7 @@ void __init default_get_smp_config(unsigned int early)
 			/*
 			 * local APIC has default address
 			 */
-			mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
+			smp_register_lapic_address(APIC_DEFAULT_PHYS_BASE);
 			return;
 		}
 
Signature · 1 line
1.7.1
author
#9 lore raw

PATCH 6/15 x86, apic: Use smp_register_lapic_address in init_apic_mapping

In reply to Yinghai Lu

So if set_fixmap_nocache is not called, don't print out anything

---
 arch/x86/kernel/apic/apic.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
arch/x86/kernel/apic/apic.c +1 -4
index 05b8bf7..a5ce130 100644
@@ -1656,10 +1656,7 @@ void __init init_apic_mappings(void)
 		 * acpi_register_lapic_address()
 		 */
 		if (!acpi_lapic)
-			set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
-
-		apic_printk(APIC_VERBOSE, "mapped APIC to %08lx (%08lx)\n",
-					APIC_BASE, apic_phys);
+			smp_register_lapic_address(apic_phys);
 	}
 
 	/*
Signature · 1 line
1.7.1
author
#10 lore raw

PATCH 7/15 x86, sfi: Use smp_register_lapic_address()

In reply to Yinghai Lu

kill mp_sfi_register_lapic_address, they are the same

---
 arch/x86/kernel/sfi.c |   13 +------------
 1 files changed, 1 insertions(+), 12 deletions(-)
arch/x86/kernel/sfi.c +1 -12
index dd4c281..4dc8065 100644
@@ -34,17 +34,6 @@
 #ifdef CONFIG_X86_LOCAL_APIC
 static unsigned long sfi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
 
-static void __init mp_sfi_register_lapic_address(unsigned long address)
-{
-	mp_lapic_addr = address;
-
-	set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
-	if (boot_cpu_physical_apicid == -1U)
-		boot_cpu_physical_apicid = read_apic_id();
-
-	pr_info("Boot CPU = %d\n", boot_cpu_physical_apicid);
-}
-
 /* All CPUs enumerated by SFI must be present and enabled */
 static void __cpuinit mp_sfi_register_lapic(u8 id)
 {
@@ -110,7 +99,7 @@ static int __init sfi_parse_ioapic(struct sfi_table_header *table)
 int __init sfi_platform_init(void)
 {
 #ifdef CONFIG_X86_LOCAL_APIC
-	mp_sfi_register_lapic_address(sfi_lapic_addr);
+	smp_register_lapic_address(sfi_lapic_addr);
 	sfi_table_parse(SFI_SIG_CPUS, NULL, NULL, sfi_parse_cpus);
 #endif
 #ifdef CONFIG_X86_IO_APIC
Signature · 1 line
1.7.1
#11 lore raw

Re: [PATCH 07/15] x86, sfi: Use smp_register_lapic_address()

Quoted 1 line · Yinghai Lu

kill mp_sfi_register_lapic_address, they are the same

Except for the difference.

Quoted 12 lines
---
 arch/x86/kernel/sfi.c |   13 +------------
 1 files changed, 1 insertions(+), 12 deletions(-)
arch/x86/kernel/sfi.c +0 -0
index dd4c281..4dc8065 100644
@@ -34,17 +34,6 @@
 #ifdef CONFIG_X86_LOCAL_APIC
 static unsigned long sfi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;

arch/x86/kernel/sfi.c line 45

Quoted 10 lines
arch/x86/kernel/sfi.c +0 -9
 
-static void __init mp_sfi_register_lapic_address(unsigned long address)
-{
-	mp_lapic_addr = address;
-
-	set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
-	if (boot_cpu_physical_apicid == -1U)
-		boot_cpu_physical_apicid = read_apic_id();
-
-	pr_info("Boot CPU = %d\n", boot_cpu_physical_apicid);

That pr_info is not really important, but it makes the function different in the first place.

Quoted 17 lines
arch/x86/kernel/sfi.c +1 -3
-}
-
 /* All CPUs enumerated by SFI must be present and enabled */
 static void __cpuinit mp_sfi_register_lapic(u8 id)
 {
@@ -110,7 +99,7 @@ static int __init sfi_parse_ioapic(struct sfi_table_header *table)
 int __init sfi_platform_init(void)
 {
 #ifdef CONFIG_X86_LOCAL_APIC
-	mp_sfi_register_lapic_address(sfi_lapic_addr);
+	smp_register_lapic_address(sfi_lapic_addr);
 	sfi_table_parse(SFI_SIG_CPUS, NULL, NULL, sfi_parse_cpus);
 #endif
 #ifdef CONFIG_X86_IO_APIC
Signature · 1 line
1.7.1
author
#12 lore raw

PATCH 8/15 x86, visws: Set_fixmap in find_smp_config

In reply to Yinghai Lu
---
 arch/x86/kernel/visws_quirks.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/kernel/visws_quirks.c +1 -0
index 3371bd0..a70bc71 100644
@@ -211,6 +211,7 @@ static void __init visws_find_smp_config(void)
 		MP_processor_info(mp++);
 
 	mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
+	set_fixmap(FIX_APIC_BASE, APIC_DEFAULT_PHYS_BASE);
 }
 
 static void visws_trap_init(void);
Signature · 1 line
1.7.1
#13 lore raw

Re: [PATCH 08/15] x86, visws: Set_fixmap in find_smp_config

On Sat, 23 Oct 2010, Yinghai Lu wrote:

-ENOREASON.

Also visws does it set already in cobalt_init(). So this is redundant crap.

Quoted 20 lines
---
 arch/x86/kernel/visws_quirks.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/kernel/visws_quirks.c +1 -0
index 3371bd0..a70bc71 100644
@@ -211,6 +211,7 @@ static void __init visws_find_smp_config(void)
 		MP_processor_info(mp++);
 
 	mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
+	set_fixmap(FIX_APIC_BASE, APIC_DEFAULT_PHYS_BASE);
 }
 
 static void visws_trap_init(void);
Signature · 1 line
1.7.1
author
#14 lore raw

PATCH 9/15 x86: on !find_smp_config path use smp_register_lapic_address

In reply to Yinghai Lu

So fixmap will be setup there.

---
 arch/x86/kernel/apic/apic.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/kernel/apic/apic.c +5 -3
index a5ce130..3a4e770 100644
@@ -1527,7 +1527,7 @@ static int __init detect_init_APIC(void)
 		return -1;
 	}
 
-	mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
+	smp_register_lapic_address(APIC_DEFAULT_PHYS_BASE);
 	return 0;
 }
 #else
@@ -1535,6 +1535,7 @@ static int __init detect_init_APIC(void)
 static int apic_verify(void)
 {
 	u32 features, h, l;
+	unsigned long lapic_addr;
 
 	/*
 	 * The APIC feature bit should now be enabled
@@ -1546,13 +1547,14 @@ static int apic_verify(void)
 		return -1;
 	}
 	set_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC);
-	mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
+	lapic_addr = APIC_DEFAULT_PHYS_BASE;
 
 	/* The BIOS may have set up the APIC at some other address */
 	rdmsr(MSR_IA32_APICBASE, l, h);
 	if (l & MSR_IA32_APICBASE_ENABLE)
-		mp_lapic_addr = l & MSR_IA32_APICBASE_BASE;
+		lapic_addr = l & MSR_IA32_APICBASE_BASE;
 
+	smp_register_lapic_address(lapic_addr);
 	pr_info("Found and enabled local APIC!\n");
 	return 0;
 }
Signature · 1 line
1.7.1
#15 lore raw

Re: [PATCH 09/15] x86: on !find_smp_config path use smp_register_lapic_address

Quoted 21 lines · Yinghai Lu

So fixmap will be setup there.

---
 arch/x86/kernel/apic/apic.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/kernel/apic/apic.c +1 -1
index a5ce130..3a4e770 100644
@@ -1527,7 +1527,7 @@ static int __init detect_init_APIC(void)
 		return -1;
 	}
 
-	mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
+	smp_register_lapic_address(APIC_DEFAULT_PHYS_BASE);
 	return 0;
 }
 #else

arch/x86/kernel/apic/apic.c static int __init detect_init_APIC(void) · line 1538

Quoted 4 lines
arch/x86/kernel/apic/apic.c +1 -0
@@ -1535,6 +1535,7 @@ static int __init detect_init_APIC(void)
 static int apic_verify(void)
 {
 	u32 features, h, l;
+	unsigned long lapic_addr;

Swap lines as we do anywhere else.

Quoted 22 lines
arch/x86/kernel/apic/apic.c +3 -2
 	/*
 	 * The APIC feature bit should now be enabled
@@ -1546,13 +1547,14 @@ static int apic_verify(void)
 		return -1;
 	}
 	set_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC);
-	mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
+	lapic_addr = APIC_DEFAULT_PHYS_BASE;
 
 	/* The BIOS may have set up the APIC at some other address */
 	rdmsr(MSR_IA32_APICBASE, l, h);
 	if (l & MSR_IA32_APICBASE_ENABLE)
-		mp_lapic_addr = l & MSR_IA32_APICBASE_BASE;
+		lapic_addr = l & MSR_IA32_APICBASE_BASE;
 
+	smp_register_lapic_address(lapic_addr);
 	pr_info("Found and enabled local APIC!\n");
 	return 0;
 }
Signature · 1 line
1.7.1
author
#16 lore raw

PATCH 10/15 x86, apic: Set fixmap only one time

In reply to Yinghai Lu

Check if mp_lapic_addr is assigned or not.

---
 arch/x86/kernel/apic/apic.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
arch/x86/kernel/apic/apic.c +3 -0
index 3a4e770..2cfa622 100644
@@ -1682,6 +1682,9 @@ void __init init_apic_mappings(void)
 
 void __init smp_register_lapic_address(unsigned long address)
 {
+	if (mp_lapic_addr)
+		return;
+
 	mp_lapic_addr = address;
 
 	set_fixmap_nocache(FIX_APIC_BASE, address);
Signature · 1 line
1.7.1
#17 lore raw

Re: [PATCH 10/15] x86, apic: Set fixmap only one time

Quoted 1 line · Yinghai Lu

Check if mp_lapic_addr is assigned or not.

Why is it called twice in the first place ? Because you messed up that other patch ?

Quoted 22 lines
---
 arch/x86/kernel/apic/apic.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
arch/x86/kernel/apic/apic.c +3 -0
index 3a4e770..2cfa622 100644
@@ -1682,6 +1682,9 @@ void __init init_apic_mappings(void)
 
 void __init smp_register_lapic_address(unsigned long address)
 {
+	if (mp_lapic_addr)
+		return;
+
 	mp_lapic_addr = address;
 
 	set_fixmap_nocache(FIX_APIC_BASE, address);
Signature · 1 line
1.7.1
author
#18 lore raw

PATCH 11/15 x86, ioapic: Only print mapping for ioapic in right place

In reply to Yinghai Lu

When mapping does happen.

And only map ioapic address one time when mp_register_ioapic() is called.

---
 arch/x86/kernel/apic/io_apic.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
arch/x86/kernel/apic/io_apic.c +7 -4
index 0579b3b..1853494 100644
@@ -3980,11 +3980,11 @@ fake_ioapic_page:
 #endif
 			ioapic_phys = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
 			ioapic_phys = __pa(ioapic_phys);
+			set_fixmap_nocache(idx, ioapic_phys);
+			apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n",
+				__fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK),
+				ioapic_phys);
 		}
-		set_fixmap_nocache(idx, ioapic_phys);
-		apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n",
-			__fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK),
-			ioapic_phys);
 		idx++;
 
 		ioapic_res->start = ioapic_phys;
@@ -4068,6 +4068,9 @@ void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
 	mp_ioapics[idx].apicaddr = address;
 
 	set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
+	apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08x)\n",
+			__fix_to_virt(FIX_IO_APIC_BASE_0 + idx) + (address & ~PAGE_MASK),
+			address);
 	mp_ioapics[idx].apicid = io_apic_unique_id(id);
 	mp_ioapics[idx].apicver = io_apic_get_version(idx);
 
Signature · 1 line
1.7.1
author
#19 lore raw

PATCH 1/1 x86, ioapic: Add debug printing when mapping for ioapic

It is in mp_register_ioapic().

---
 arch/x86/kernel/apic/io_apic.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
arch/x86/kernel/apic/io_apic.c +3 -0
Index: linux-2.6/arch/x86/kernel/apic/io_apic.c
===================================================================
@@ -4068,6 +4068,9 @@ void __init mp_register_ioapic(int id, u
 	mp_ioapics[idx].apicaddr = address;
 
 	set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
+	apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08x)\n",
+			__fix_to_virt(FIX_IO_APIC_BASE_0 + idx) + (address & ~PAGE_MASK),
+			address);
 	mp_ioapics[idx].apicid = io_apic_unique_id(id);
 	mp_ioapics[idx].apicver = io_apic_get_version(idx);
 
author
#20 lore raw

PATCH 1/1 x86, ioapic: Don't map ioapic regs two times

Normal path: When mptable or madt is used, and ioapic address is correct, We already set mapping in mp_register_ioapic().

So only set_fixmap for dummy case.

---
 arch/x86/kernel/apic/io_apic.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/apic/io_apic.c +4 -4
Index: linux-2.6/arch/x86/kernel/apic/io_apic.c
===================================================================
@@ -3980,11 +3980,11 @@ fake_ioapic_page:
 #endif
 			ioapic_phys = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
 			ioapic_phys = __pa(ioapic_phys);
+			set_fixmap_nocache(idx, ioapic_phys);
+			apic_printk(APIC_VERBOSE, "mapped dummy IOAPIC to %08lx (%08lx)\n",
+				__fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK),
+				ioapic_phys);
 		}
-		set_fixmap_nocache(idx, ioapic_phys);
-		apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n",
-			__fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK),
-			ioapic_phys);
 		idx++;
 
 		ioapic_res->start = ioapic_phys;
author
#21 lore raw

PATCH 12/15 x86, x2apic: Don't map lapic addr for preenabled x2apic

In reply to Yinghai Lu

If x2apic is reenabled, and used in kernel, We don't need to map that lapic address. That mapping will never be used.

So just skip that in smp_register_lapic_address()

---
 arch/x86/kernel/apic/apic.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
arch/x86/kernel/apic/apic.c +5 -3
index 2cfa622..d286db1 100644
@@ -1687,9 +1687,11 @@ void __init smp_register_lapic_address(unsigned long address)
 
 	mp_lapic_addr = address;
 
-	set_fixmap_nocache(FIX_APIC_BASE, address);
-	apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
-		    APIC_BASE, mp_lapic_addr);
+	if (!x2apic_mode) {
+		set_fixmap_nocache(FIX_APIC_BASE, address);
+		apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
+			    APIC_BASE, mp_lapic_addr);
+	}
 	if (boot_cpu_physical_apicid == -1U) {
 		boot_cpu_physical_apicid  = read_apic_id();
 		apic_version[boot_cpu_physical_apicid] =
Signature · 1 line
1.7.1
author
#22 lore raw

PATCH 13/15 x86, apic, acpi: Handle xapic/x2apic entries in MADT at same time

In reply to Yinghai Lu

One system have mixing xapic and x2apic entries in MADT and SRAT.

Need to handle every entry in MADT at same time with xapic and x2apic. so we can honor sequence in MADT.

We can use max_cpus= command line to use thread0 in every core, because recent MADT always have all thread0 at first. Also it could make the cpu to node mapping more sane.

---
 arch/x86/kernel/acpi/boot.c |   35 ++++++++++++++++++++-------
 drivers/acpi/numa.c         |   18 ++++++++++---
 drivers/acpi/tables.c       |   56 +++++++++++++++++++++++++++++++-----------
 include/linux/acpi.h        |    8 ++++++
 4 files changed, 89 insertions(+), 28 deletions(-)
arch/x86/kernel/acpi/boot.c +26 -9
index f9f1bc5..8e13ec8 100644
@@ -850,6 +850,7 @@ static int __init acpi_parse_madt_lapic_entries(void)
 {
 	int count;
 	int x2count = 0;
+	struct acpi_subtable_proc madt_proc;
 
 	if (!cpu_has_apic)
 		return -ENODEV;
@@ -874,10 +875,19 @@ static int __init acpi_parse_madt_lapic_entries(void)
 				      acpi_parse_sapic, MAX_APICS);
 
 	if (!count) {
-		x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
-						acpi_parse_x2apic, MAX_APICS);
-		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
-					      acpi_parse_lapic, MAX_APICS);
+
+		memset(&madt_proc, 0, sizeof(madt_proc));
+		madt_proc.id[0] = ACPI_MADT_TYPE_LOCAL_APIC;
+		madt_proc.handler[0] = acpi_parse_lapic;
+		madt_proc.num++;
+		madt_proc.id[1] = ACPI_MADT_TYPE_LOCAL_X2APIC;
+		madt_proc.handler[1] = acpi_parse_x2apic;
+		madt_proc.num++;
+		acpi_table_parse_entries_x(ACPI_SIG_MADT,
+					    sizeof(struct acpi_table_madt),
+					    &madt_proc, MAX_APICS);
+		count = madt_proc.count[0];
+		x2count = madt_proc.count[1];
 	}
 	if (!count && !x2count) {
 		printk(KERN_ERR PREFIX "No LAPIC entries present\n");
@@ -889,11 +899,18 @@ static int __init acpi_parse_madt_lapic_entries(void)
 		return count;
 	}
 
-	x2count =
-	    acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
-				  acpi_parse_x2apic_nmi, 0);
-	count =
-	    acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
+	memset(&madt_proc, 0, sizeof(madt_proc));
+	madt_proc.id[0] = ACPI_MADT_TYPE_LOCAL_APIC_NMI;
+	madt_proc.handler[0] = acpi_parse_lapic_nmi;
+	madt_proc.num++;
+	madt_proc.id[1] = ACPI_MADT_TYPE_LOCAL_X2APIC_NMI;
+	madt_proc.handler[1] = acpi_parse_x2apic_nmi;
+	madt_proc.num++;
+	acpi_table_parse_entries_x(ACPI_SIG_MADT,
+				    sizeof(struct acpi_table_madt),
+				    &madt_proc, MAX_APICS);
+	count = madt_proc.count[0];
+	x2count = madt_proc.count[1];
 	if (count < 0 || x2count < 0) {
 		printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
 		/* TBD: Cleanup to allow fallback to MPS */
drivers/acpi/numa.c +14 -4
index 5718566..0891071 100644
@@ -278,10 +278,20 @@ int __init acpi_numa_init(void)
 
 	/* SRAT: Static Resource Affinity Table */
 	if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
-		acpi_table_parse_srat(ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY,
-				     acpi_parse_x2apic_affinity, nr_cpu_ids);
-		acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
-				     acpi_parse_processor_affinity, nr_cpu_ids);
+		struct acpi_subtable_proc srat_proc;
+
+		memset(&srat_proc, 0, sizeof(srat_proc));
+		srat_proc.id[0] = ACPI_SRAT_TYPE_CPU_AFFINITY;
+		srat_proc.handler[0] = acpi_parse_processor_affinity;
+		srat_proc.num++;
+		srat_proc.id[1] = ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY;
+		srat_proc.handler[1] = acpi_parse_x2apic_affinity;
+		srat_proc.num++;
+
+		acpi_table_parse_entries_x(ACPI_SIG_SRAT,
+					    sizeof(struct acpi_table_srat),
+					    &srat_proc, nr_cpu_ids);
+
 		ret = acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY,
 					    acpi_parse_memory_affinity,
 					    NR_NODE_MEMBLKS);
drivers/acpi/tables.c +41 -15

94 lines not on this page · raw message

include/linux/acpi.h +8 -0
index c227757..9c7cf47 100644
@@ -76,6 +76,13 @@ typedef int (*acpi_table_handler) (struct acpi_table_header *table);
 
 typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, const unsigned long end);
 
+struct acpi_subtable_proc {
+	int id[2];
+	acpi_table_entry_handler handler[2];
+	int count[2];
+	int num;
+};
+
 char * __acpi_map_table (unsigned long phys_addr, unsigned long size);
 void __acpi_unmap_table(char *map, unsigned long size);
 int early_acpi_boot_init(void);
@@ -86,6 +93,7 @@ int acpi_numa_init (void);
 
 int acpi_table_init (void);
 int acpi_table_parse (char *id, acpi_table_handler handler);
+int acpi_table_parse_entries_x(char *id, unsigned long table_size, struct acpi_subtable_proc *proc, unsigned int max_entries);
 int __init acpi_table_parse_entries(char *id, unsigned long table_size,
 	int entry_id, acpi_table_entry_handler handler, unsigned int max_entries);
 int acpi_table_parse_madt (enum acpi_madt_type id, acpi_table_entry_handler handler, unsigned int max_entries);
Signature · 1 line
1.7.1
#23 lore raw

Re: [PATCH 13/15] x86, apic, acpi: Handle xapic/x2apic entries in MADT at same time

Quoted 7 lines · Yinghai Lu

One system have mixing xapic and x2apic entries in MADT and SRAT.

Need to handle every entry in MADT at same time with xapic and x2apic. so we can honor sequence in MADT.

We can use max_cpus= command line to use thread0 in every core, because recent MADT always have all thread0 at first.

That's a completely bogus argument. Just because you have access to MADTs which have that first, does not prove anything.

These damned tables are not what we expect often enough, so we have to deal with it and not making stupid assumptions which will blow up in no time.

arch/x86/kernel/acpi/boot.c static int __init acpi_parse_madt_lapic_entries(void) · line 853

Quoted 9 lines
arch/x86/kernel/acpi/boot.c +1 -0
index f9f1bc5..8e13ec8 100644
@@ -850,6 +850,7 @@ static int __init acpi_parse_madt_lapic_entries(void)
 {
 	int count;
 	int x2count = 0;
+	struct acpi_subtable_proc madt_proc;

You titled this patch series cleanup. So what about doing

	struct acpi_subtable_proc madt_proc;
	int count, x2count = 0;

instead of blindly slapping your new stuff in ?

Quoted 9 lines
arch/x86/kernel/acpi/boot.c +0 -3
 	if (!cpu_has_apic)
 		return -ENODEV;
@@ -874,10 +875,19 @@ static int __init acpi_parse_madt_lapic_entries(void)
 				      acpi_parse_sapic, MAX_APICS);
 
 	if (!count) {
-		x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
-						acpi_parse_x2apic, MAX_APICS);
-		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,

arch/x86/kernel/acpi/boot.c static int __init acpi_parse_madt_lapic_entries(void) · line 886

Quoted 10 lines
arch/x86/kernel/acpi/boot.c +9 -1
-					      acpi_parse_lapic, MAX_APICS);
+
+		memset(&madt_proc, 0, sizeof(madt_proc));
+		madt_proc.id[0] = ACPI_MADT_TYPE_LOCAL_APIC;
+		madt_proc.handler[0] = acpi_parse_lapic;
+		madt_proc.num++;
+		madt_proc.id[1] = ACPI_MADT_TYPE_LOCAL_X2APIC;
+		madt_proc.handler[1] = acpi_parse_x2apic;
+		madt_proc.num++;
+		acpi_table_parse_entries_x(ACPI_SIG_MADT,

What the hell is acpi_table_parse_entries_x?

I tell you: Just slapping an _x at an existing function name is sloppy, lazy and disgusting CRAP. Period.

I just removed a bunch of these complete misnomers and you have been told to use sensible function names several times before.

Don't do that ever again, really. It's just a prove of complete and wilful ignorance of reviewers comments.

arch/x86/kernel/acpi/boot.c static int __init acpi_parse_madt_lapic_entries(void) · line 892

Quoted 6 lines
arch/x86/kernel/acpi/boot.c +4 -0
+					    sizeof(struct acpi_table_madt),
+					    &madt_proc, MAX_APICS);
+		count = madt_proc.count[0];
+		x2count = madt_proc.count[1];
 	}
 	if (!count && !x2count) {

Does anything check here for count < 0 or x2count < 0 ?

Quoted 15 lines
drivers/acpi/numa.c +3 -4
index 5718566..0891071 100644
@@ -278,10 +278,20 @@ int __init acpi_numa_init(void)
 
 	/* SRAT: Static Resource Affinity Table */
 	if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
-		acpi_table_parse_srat(ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY,
-				     acpi_parse_x2apic_affinity, nr_cpu_ids);
-		acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
-				     acpi_parse_processor_affinity, nr_cpu_ids);
+		struct acpi_subtable_proc srat_proc;
+
+		memset(&srat_proc, 0, sizeof(srat_proc));

drivers/acpi/numa.c int __init acpi_numa_init(void) · line 293

Quoted 10 lines
drivers/acpi/numa.c +10 -0
+		srat_proc.id[0] = ACPI_SRAT_TYPE_CPU_AFFINITY;
+		srat_proc.handler[0] = acpi_parse_processor_affinity;
+		srat_proc.num++;
+		srat_proc.id[1] = ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY;
+		srat_proc.handler[1] = acpi_parse_x2apic_affinity;
+		srat_proc.num++;
+
+		acpi_table_parse_entries_x(ACPI_SIG_SRAT,
+					    sizeof(struct acpi_table_srat),
+					    &srat_proc, nr_cpu_ids);

What happens with the return value of this function ?

Quoted 22 lines
drivers/acpi/numa.c +1 -0
+
 		ret = acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY,
 					    acpi_parse_memory_affinity,
 					    NR_NODE_MEMBLKS);
drivers/acpi/tables.c +2 -3
index f336bca..3e4a60e 100644
@@ -201,10 +201,9 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
 
 
 int __init
-acpi_table_parse_entries(char *id,
+acpi_table_parse_entries_x(char *id,
 			     unsigned long table_size,
-			     int entry_id,
-			     acpi_table_entry_handler handler,
+			     struct acpi_subtable_proc *proc,
 			     unsigned int max_entries)
 {
 	struct acpi_table_header *table_header = NULL;

drivers/acpi/tables.c acpi_table_parse_entries(char *id, · line 217

Quoted 8 lines
drivers/acpi/tables.c +3 -1
@@ -212,12 +211,12 @@ acpi_table_parse_entries(char *id,
 	unsigned int count = 0;
 	unsigned long table_end;
 	acpi_size tbl_size;
+	int i;
 
-	if (acpi_disabled)
+	if (acpi_disabled) {
+		proc->count[0] = -ENODEV;

Why isn't it sufficient to return -ENODEV and check the return value of the function ?

drivers/acpi/tables.c acpi_table_parse_entries(char *id, · line 220

Quoted 4 lines
drivers/acpi/tables.c +0 -3
 		return -ENODEV;
-
-	if (!handler)
-		return -EINVAL;

Wat makes sure that all subtable entries have a handler set ?

drivers/acpi/tables.c acpi_table_parse_entries(char *id, · line 228

Quoted 9 lines
drivers/acpi/tables.c +2 -0
+	}
 
 	if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
 		acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
@@ -226,6 +225,7 @@ acpi_table_parse_entries(char *id,
 
 	if (!table_header) {
 		printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
+		proc->count[0] = -ENODEV;

See above

Quoted 11 lines
drivers/acpi/tables.c +0 -4
 		return -ENODEV;
 	}
 
@@ -238,19 +238,25 @@ acpi_table_parse_entries(char *id,
 
 	while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
 	       table_end) {
-		if (entry->type == entry_id
-		    && (!max_entries || count++ < max_entries))
-			if (handler(entry, table_end)) {
-				early_acpi_os_unmap_memory((char *)table_header, tbl_size);

drivers/acpi/tables.c acpi_table_parse_entries(char *id, · line 248

Quoted 10 lines
drivers/acpi/tables.c +8 -2
-				return -EINVAL;
-			}
+		for (i = 0; i < proc->num; i++) {
+			if (entry->type != proc->id[i])
+				continue;
+			if (!max_entries || count++ < max_entries)
+				if (proc->handler[i](entry, table_end)) {
+					early_acpi_os_unmap_memory((char *)table_header, tbl_size);
+					proc->count[i] = -EINVAL;
+					return -EINVAL;

See above

Quoted 28 lines
drivers/acpi/tables.c +14 -2
+				}
+			proc->count[i]++;
+			break;
+		}
 
 		entry = (struct acpi_subtable_header *)
 		    ((unsigned long)entry + entry->length);
 	}
 	if (max_entries && count > max_entries) {
-		printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of "
-		       "%i found\n", id, entry_id, count - max_entries, count);
+		printk(KERN_WARNING PREFIX "[%4.4s:0x%02x 0x%02x] ignored %i entries of "
+		       "%i found\n", id, proc->id[0], proc->id[1], count - max_entries, count);
 	}
 
 	early_acpi_os_unmap_memory((char *)table_header, tbl_size);
@@ -258,6 +264,26 @@ acpi_table_parse_entries(char *id,
 }
 
 int __init
+acpi_table_parse_entries(char *id,
+			     unsigned long table_size,
+			     int entry_id,
+			     acpi_table_entry_handler handler,
+			     unsigned int max_entries)
+{
+	struct acpi_subtable_proc proc;
+

drivers/acpi/tables.c acpi_table_parse_entries(char *id, · line 284

Quoted 10 lines
drivers/acpi/tables.c +10 -0
+	if (!handler)
+		return -EINVAL;
+
+	memset(&proc, 0, sizeof(proc));
+	proc.id[0] = entry_id;
+	proc.handler[0] = handler;
+	proc.num++;
+
+	return acpi_table_parse_entries_x(id, table_size, &proc, max_entries);
+}

And this needs to be split into two patches. One introducing the new function and one making use of it.

Thanks,

tglx

author
#24 lore raw

PATCH 14/15 acpi: Reverse uid and apic_id print out for x2apic

In reply to Yinghai Lu

So make it have same sequence like old apic.

---
 drivers/acpi/tables.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/tables.c +2 -2
index 3e4a60e..4dffce0 100644
@@ -67,8 +67,8 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
 			struct acpi_madt_local_x2apic *p =
 			    (struct acpi_madt_local_x2apic *)header;
 			printk(KERN_INFO PREFIX
-			       "X2APIC (apic_id[0x%02x] uid[0x%02x] %s)\n",
-			       p->local_apic_id, p->uid,
+			       "X2APIC (uid[0x%02x] apic_id[0x%02x] %s)\n",
+			       p->uid, p->local_apic_id,
 			       (p->lapic_flags & ACPI_MADT_ENABLED) ?
 			       "enabled" : "disabled");
 		}
Signature · 1 line
1.7.1
author
#25 lore raw

PATCH 15/15 x86: Disabling x2apic if nox2apic is specified

In reply to Yinghai Lu

For
1. x2apic preenabled system
2. first kernel have x2apic enabled, and try to boot second kernel with "nox2apic"

Will put back cpu with apic id < 255 into xapic mode, instead of panic.

---
 arch/x86/include/asm/apic.h    |    6 ++++
 arch/x86/include/asm/apicdef.h |    1 +
 arch/x86/kernel/acpi/boot.c    |   10 ++++++-
 arch/x86/kernel/apic/apic.c    |   54 +++++++++++++++++++++++++++++++--------
 arch/x86/mm/srat_64.c          |   12 ++++++++-
 5 files changed, 69 insertions(+), 14 deletions(-)
arch/x86/include/asm/apic.h +6 -0
index 69879dd..522f39b 100644
@@ -176,6 +176,7 @@ static inline u64 native_x2apic_icr_read(void)
 }
 
 extern int x2apic_phys;
+extern int nox2apic;
 extern void check_x2apic(void);
 extern void enable_x2apic(void);
 extern void x2apic_icr_write(u32 low, u32 id);
@@ -186,6 +187,10 @@ static inline int x2apic_enabled(void)
 	if (!cpu_has_x2apic)
 		return 0;
 
+	/* avoid to read msr */
+	if (nox2apic)
+		return 0;
+
 	rdmsr(MSR_IA32_APICBASE, msr, msr2);
 	if (msr & X2APIC_ENABLE)
 		return 1;
@@ -214,6 +219,7 @@ static inline void x2apic_force_phys(void)
 
 #define	x2apic_preenabled 0
 #define	x2apic_supported()	0
+#define	nox2apic	1
 #endif
 
 extern void enable_IR_x2apic(void);
arch/x86/include/asm/apicdef.h +1 -0
index a859ca4..f28feba 100644
@@ -141,6 +141,7 @@
 
 #define APIC_BASE (fix_to_virt(FIX_APIC_BASE))
 #define APIC_BASE_MSR	0x800
+#define XAPIC_ENABLE	(1UL << 11)
 #define X2APIC_ENABLE	(1UL << 10)
 
 #ifdef CONFIG_X86_32
arch/x86/kernel/acpi/boot.c +8 -2
index 8e13ec8..5a4e67e 100644
@@ -213,6 +213,8 @@ static int __init
 acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
 {
 	struct acpi_madt_local_x2apic *processor = NULL;
+	int apic_id;
+	u8 enabled;
 
 	processor = (struct acpi_madt_local_x2apic *)header;
 
@@ -221,6 +223,8 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
 
 	acpi_table_print_madt_entry(header);
 
+	apic_id = processor->local_apic_id;
+	enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
 #ifdef CONFIG_X86_X2APIC
 	/*
 	 * We need to register disabled CPU as well to permit
@@ -229,8 +233,10 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
 	 * to not preallocating memory for all NR_CPUS
 	 * when we use CPU hotplug.
 	 */
-	acpi_register_lapic(processor->local_apic_id,	/* APIC ID */
-			    processor->lapic_flags & ACPI_MADT_ENABLED);
+	if (nox2apic && (apic_id >= 0xff) && enabled)
+		printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
+	else
+		acpi_register_lapic(apic_id, enabled);
 #else
 	printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
 #endif
arch/x86/kernel/apic/apic.c +43 -11

112 lines not on this page · raw message

arch/x86/mm/srat_64.c +11 -1
index a35cb9d..baa9eab 100644
@@ -126,6 +126,13 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
 	if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
 		return;
 	pxm = pa->proximity_domain;
+	apic_id = pa->apic_id;
+#ifdef CONFIG_X86_X2APIC
+	if (nox2apic && (apic_id >= 0xff)) {
+		printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
+			 pxm, apic_id);
+		return;
+	}
 	node = setup_node(pxm);
 	if (node < 0) {
 		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
@@ -133,12 +140,15 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
 		return;
 	}
 
-	apic_id = pa->apic_id;
 	apicid_to_node[apic_id] = node;
 	node_set(node, cpu_nodes_parsed);
 	acpi_numa = 1;
 	printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n",
 	       pxm, apic_id, node);
+#else
+	printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
+		 pxm, apic_id);
+#endif
 }
 
 /* Callback for Proximity Domain -> LAPIC mapping */
Signature · 1 line
1.7.1
#26 lore raw

Re: [PATCH 15/15] x86: Disabling x2apic if nox2apic is specified

Quoted 20 lines · Yinghai Lu

For
1. x2apic preenabled system
2. first kernel have x2apic enabled, and try to boot second kernel with "nox2apic"

Will put back cpu with apic id < 255 into xapic mode, instead of panic.

---
 arch/x86/include/asm/apic.h    |    6 ++++
 arch/x86/include/asm/apicdef.h |    1 +
 arch/x86/kernel/acpi/boot.c    |   10 ++++++-
 arch/x86/kernel/apic/apic.c    |   54 +++++++++++++++++++++++++++++++--------
 arch/x86/mm/srat_64.c          |   12 ++++++++-
 5 files changed, 69 insertions(+), 14 deletions(-)
arch/x86/include/asm/apic.h +0 -0
index 69879dd..522f39b 100644

arch/x86/include/asm/apic.h static inline u64 native_x2apic_icr_read(void) · line 179

Quoted 4 lines
arch/x86/include/asm/apic.h +1 -0
@@ -176,6 +176,7 @@ static inline u64 native_x2apic_icr_read(void)
 }
 
 extern int x2apic_phys;
+extern int nox2apic;

Can you please use a sensible variable name like x2apic_disabled ?

arch/x86/include/asm/apic.h static inline int x2apic_enabled(void) · line 190

Quoted 8 lines
arch/x86/include/asm/apic.h +1 -0
 extern void check_x2apic(void);
 extern void enable_x2apic(void);
 extern void x2apic_icr_write(u32 low, u32 id);
@@ -186,6 +187,10 @@ static inline int x2apic_enabled(void)
 	if (!cpu_has_x2apic)
 		return 0;
 
+	/* avoid to read msr */

That comment is useless. I wish you would add comments to complex code not to obvious one.

Also it can be folded into the above check

     if (!cpu_has_x2apic || x2apic_disabled)
Quoted 19 lines
arch/x86/include/asm/apic.h +3 -0
+	if (nox2apic)
+		return 0;
+
 	rdmsr(MSR_IA32_APICBASE, msr, msr2);
 	if (msr & X2APIC_ENABLE)
 		return 1;
arch/x86/kernel/apic/apic.c +1 -1
index d286db1..ebb13e8 100644
@@ -138,15 +138,14 @@ int x2apic_mode;
 #ifdef CONFIG_X86_X2APIC
 /* x2apic enabled before OS handover */
 static int x2apic_preenabled;
+int nox2apic;
 static __init int setup_nox2apic(char *str)
 {
-	if (x2apic_enabled()) {

arch/x86/kernel/apic/apic.c int x2apic_mode; · line 149

Quoted 10 lines
arch/x86/kernel/apic/apic.c +4 -5
-		pr_warning("Bios already enabled x2apic, "
-			   "can't enforce nox2apic");
-		return 0;
-	}
+	if (x2apic_enabled())
+		pr_warning("Bios already enabled x2apic, will disable it");
+
+	nox2apic = 1;
 
-	setup_clear_cpu_cap(X86_FEATURE_X2APIC);

Why is this removed ?

Quoted 50 lines
arch/x86/kernel/apic/apic.c +30 -0
 	return 0;
 }
 early_param("nox2apic", setup_nox2apic);
@@ -1393,8 +1392,33 @@ void __cpuinit end_local_APIC_setup(void)
 }
 
 #ifdef CONFIG_X86_X2APIC
+
+static void disable_x2apic(void)
+{
+	int msr, msr2;
+
+	if (!cpu_has_x2apic)
+		return;
+
+	rdmsr(MSR_IA32_APICBASE, msr, msr2);
+	if (msr & X2APIC_ENABLE) {
+		pr_info("Disabling x2apic\n");
+		/*
+		 * Need to disable xapic and x2apic at the same time at first
+		 *  then enable xapic
+		 */
+		wrmsr(MSR_IA32_APICBASE, msr & ~(X2APIC_ENABLE | XAPIC_ENABLE),
+			 0);
+		wrmsr(MSR_IA32_APICBASE, msr & ~X2APIC_ENABLE, 0);
+	}
+}
 void check_x2apic(void)
 {
+	if (nox2apic) {
+		disable_x2apic();
+		return;
+	}
+
 	if (x2apic_enabled()) {
 		pr_info("x2apic enabled by BIOS, switching to x2apic ops\n");
 		x2apic_preenabled = x2apic_mode = 1;
@@ -1405,6 +1429,11 @@ void enable_x2apic(void)
 {
 	int msr, msr2;
 
+	if (nox2apic) {
+		disable_x2apic();
+		return;
+	}
+
 	if (!x2apic_mode)
 		return;
 

arch/x86/kernel/apic/apic.c int __init enable_IR(void) · line 1462

Quoted 5 lines
arch/x86/kernel/apic/apic.c +1 -1
@@ -1430,7 +1459,7 @@ int __init enable_IR(void)
 		return 0;
 	}
 
-	if (enable_intr_remapping(x2apic_supported()))
+	if (enable_intr_remapping(x2apic_supported() && !nox2apic))

Do we really need all these extra checks ? Can't we simply make all this one variable wich is set to 1 when x2apic is available and not disabled on the kernel command line ?

arch/x86/mm/srat_64.c acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa) · line 130

Quoted 10 lines
arch/x86/mm/srat_64.c +2 -0
index a35cb9d..baa9eab 100644
@@ -126,6 +126,13 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
 	if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
 		return;
 	pxm = pa->proximity_domain;
+	apic_id = pa->apic_id;
+#ifdef CONFIG_X86_X2APIC

Why conditional? No need to duplicate the printk. It just needs some thought.

Quoted 28 lines
arch/x86/mm/srat_64.c +9 -1
+	if (nox2apic && (apic_id >= 0xff)) {
+		printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
+			 pxm, apic_id);
+		return;
+	}
 	node = setup_node(pxm);
 	if (node < 0) {
 		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
@@ -133,12 +140,15 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
 		return;
 	}
 
-	apic_id = pa->apic_id;
 	apicid_to_node[apic_id] = node;
 	node_set(node, cpu_nodes_parsed);
 	acpi_numa = 1;
 	printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n",
 	       pxm, apic_id, node);
+#else
+	printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
+		 pxm, apic_id);
+#endif
 }
 
 /* Callback for Proximity Domain -> LAPIC mapping */
Signature · 1 line
1.7.1
author
#27 lore raw

Re: [PATCH 15/15] x86: Disabling x2apic if nox2apic is specified

Quoted 21 lines · Thomas Gleixner
Quoted 21 lines
arch/x86/kernel/apic/apic.c +5 -5
index d286db1..ebb13e8 100644
@@ -138,15 +138,14 @@ int x2apic_mode;
 #ifdef CONFIG_X86_X2APIC
 /* x2apic enabled before OS handover */
 static int x2apic_preenabled;
+int nox2apic;
 static __init int setup_nox2apic(char *str)
 {
-	if (x2apic_enabled()) {
-		pr_warning("Bios already enabled x2apic, "
-			   "can't enforce nox2apic");
-		return 0;
-	}
+	if (x2apic_enabled())
+		pr_warning("Bios already enabled x2apic, will disable it");
+
+	nox2apic = 1;
 
Quoted 4 lines

arch/x86/kernel/apic/apic.c int x2apic_mode; · line 149

Quoted 1 line
arch/x86/kernel/apic/apic.c +0 -1
-	setup_clear_cpu_cap(X86_FEATURE_X2APIC);

Why is this removed ?

need to check that bit with disable_x2apic.

+static void disable_x2apic(void)
+{
+ int msr, msr2;
+
+ if (!cpu_has_x2apic)
+ return;

other concern should be addressed. please check -v2.

Thanks

Yinghai

[PATCH -v2] x86: Disable x2apic if nox2apic is specified

For
1. x2apic preenabled system
2. first kernel have x2apic enabled, and try to kexec second kernel with "nox2apic"

Will put back cpu with apic id < 255 into xapic mode, instead of panic.

-v2: use x2apic_disabled instead of nox2apic, Suggested by Thomas
update x2apic_supported with x2apic_disabled, Suggested by Thomas

---
 arch/x86/include/asm/apic.h    |    6 +++--
 arch/x86/include/asm/apicdef.h |    1 
 arch/x86/kernel/acpi/boot.c    |   10 +++++++-
 arch/x86/kernel/apic/apic.c    |   46 ++++++++++++++++++++++++++++++++++-------
 arch/x86/mm/srat_64.c          |    7 +++++-
 5 files changed, 58 insertions(+), 12 deletions(-)
arch/x86/include/asm/apic.h +4 -2
Index: linux-2.6/arch/x86/include/asm/apic.h
===================================================================
@@ -176,6 +176,7 @@ static inline u64 native_x2apic_icr_read
 }
 
 extern int x2apic_phys;
+extern int x2apic_disabled;
 extern void check_x2apic(void);
 extern void enable_x2apic(void);
 extern void x2apic_icr_write(u32 low, u32 id);
@@ -183,7 +184,7 @@ static inline int x2apic_enabled(void)
 {
 	int msr, msr2;
 
-	if (!cpu_has_x2apic)
+	if (!cpu_has_x2apic || x2apic_disabled)
 		return 0;
 
 	rdmsr(MSR_IA32_APICBASE, msr, msr2);
@@ -192,7 +193,7 @@ static inline int x2apic_enabled(void)
 	return 0;
 }
 
-#define x2apic_supported()	(cpu_has_x2apic)
+#define x2apic_supported()	(cpu_has_x2apic && !x2apic_disabled)
 static inline void x2apic_force_phys(void)
 {
 	x2apic_phys = 1;
@@ -214,6 +215,7 @@ static inline void x2apic_force_phys(voi
 
 #define	x2apic_preenabled 0
 #define	x2apic_supported()	0
+#define	x2apic_disabled	1
 #endif
 
 extern void enable_IR_x2apic(void);
arch/x86/kernel/acpi/boot.c +8 -2
Index: linux-2.6/arch/x86/kernel/acpi/boot.c
===================================================================
@@ -213,6 +213,8 @@ static int __init
 acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
 {
 	struct acpi_madt_local_x2apic *processor = NULL;
+	int apic_id;
+	u8 enabled;
 
 	processor = (struct acpi_madt_local_x2apic *)header;
 
@@ -221,6 +223,8 @@ acpi_parse_x2apic(struct acpi_subtable_h
 
 	acpi_table_print_madt_entry(header);
 
+	apic_id = processor->local_apic_id;
+	enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
 #ifdef CONFIG_X86_X2APIC
 	/*
 	 * We need to register disabled CPU as well to permit
@@ -229,8 +233,10 @@ acpi_parse_x2apic(struct acpi_subtable_h
 	 * to not preallocating memory for all NR_CPUS
 	 * when we use CPU hotplug.
 	 */
-	acpi_register_lapic(processor->local_apic_id,	/* APIC ID */
-			    processor->lapic_flags & ACPI_MADT_ENABLED);
+	if (x2apic_disabled && (apic_id >= 0xff) && enabled)
+		printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
+	else
+		acpi_register_lapic(apic_id, enabled);
 #else
 	printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
 #endif
arch/x86/kernel/apic/apic.c +39 -7

81 lines not on this page · raw message

arch/x86/mm/srat_64.c +6 -1
Index: linux-2.6/arch/x86/mm/srat_64.c
===================================================================
@@ -126,6 +126,12 @@ acpi_numa_x2apic_affinity_init(struct ac
 	if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
 		return;
 	pxm = pa->proximity_domain;
+	apic_id = pa->apic_id;
+	if (x2apic_disabled && (apic_id >= 0xff)) {
+		printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
+			 pxm, apic_id);
+		return;
+	}
 	node = setup_node(pxm);
 	if (node < 0) {
 		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
@@ -133,7 +139,6 @@ acpi_numa_x2apic_affinity_init(struct ac
 		return;
 	}
 
-	apic_id = pa->apic_id;
 	apicid_to_node[apic_id] = node;
 	node_set(node, cpu_nodes_parsed);
 	acpi_numa = 1;
arch/x86/include/asm/apicdef.h +1 -0
Index: linux-2.6/arch/x86/include/asm/apicdef.h
===================================================================
@@ -141,6 +141,7 @@
 
 #define APIC_BASE (fix_to_virt(FIX_APIC_BASE))
 #define APIC_BASE_MSR	0x800
+#define XAPIC_ENABLE	(1UL << 11)
 #define X2APIC_ENABLE	(1UL << 10)
 
 #ifdef CONFIG_X86_32
#28 lore raw

Re: [PATCH 15/15] x86: Disabling x2apic if nox2apic is specified

Quoted 6 lines · Yinghai Lu

[PATCH -v2] x86: Disable x2apic if nox2apic is specified

For
1. x2apic preenabled system
2. first kernel have x2apic enabled, and try to kexec second kernel with "nox2apic"

Quoted 6 lines

Will put back cpu with apic id < 255 into xapic mode, instead of panic.

-v2: use x2apic_disabled instead of nox2apic, Suggested by Thomas
update x2apic_supported with x2apic_disabled, Suggested by Thomas

Yinghai, Have you validated this patch on a system having apicid's > 255 and when the bios has enabled x2apic? When a bios enables x2apic (typically when it finds processors with apic id's > 255), it also enables interrupt-remapping before enabling x2apic in the bios.

So not sure what is the behavior with this patch(along with the nox2apic boot option). Does the kernel boot with cpu's having < 255 apicid, and also use the interrupt-remapping but with xapic mode?

Also, the boot cpu's apic id might be already > 8 bit, but by forcing to use xapic, the lower 8 bit portion of it might conflict with another AP (whose 32bit apic id value is < 255). So we need to be careful in this case aswell. Have you validated this scenario aswell? May be we should (or already does) skip that AP having the same 8bit apic id etc.

thanks,
suresh

Quoted 213 lines
---
 arch/x86/include/asm/apic.h    |    6 +++--
 arch/x86/include/asm/apicdef.h |    1 
 arch/x86/kernel/acpi/boot.c    |   10 +++++++-
 arch/x86/kernel/apic/apic.c    |   46 ++++++++++++++++++++++++++++++++++-------
 arch/x86/mm/srat_64.c          |    7 +++++-
 5 files changed, 58 insertions(+), 12 deletions(-)

Index: linux-2.6/arch/x86/include/asm/apic.h
===================================================================

arch/x86/include/asm/apic.h +4 -2
@@ -176,6 +176,7 @@ static inline u64 native_x2apic_icr_read
 }
 
 extern int x2apic_phys;
+extern int x2apic_disabled;
 extern void check_x2apic(void);
 extern void enable_x2apic(void);
 extern void x2apic_icr_write(u32 low, u32 id);
@@ -183,7 +184,7 @@ static inline int x2apic_enabled(void)
 {
 	int msr, msr2;
 
-	if (!cpu_has_x2apic)
+	if (!cpu_has_x2apic || x2apic_disabled)
 		return 0;
 
 	rdmsr(MSR_IA32_APICBASE, msr, msr2);
@@ -192,7 +193,7 @@ static inline int x2apic_enabled(void)
 	return 0;
 }
 
-#define x2apic_supported()	(cpu_has_x2apic)
+#define x2apic_supported()	(cpu_has_x2apic && !x2apic_disabled)
 static inline void x2apic_force_phys(void)
 {
 	x2apic_phys = 1;
@@ -214,6 +215,7 @@ static inline void x2apic_force_phys(voi
 
 #define	x2apic_preenabled 0
 #define	x2apic_supported()	0
+#define	x2apic_disabled	1
 #endif
 
 extern void enable_IR_x2apic(void);

Index: linux-2.6/arch/x86/kernel/acpi/boot.c
===================================================================

arch/x86/kernel/acpi/boot.c +8 -2
@@ -213,6 +213,8 @@ static int __init
 acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
 {
 	struct acpi_madt_local_x2apic *processor = NULL;
+	int apic_id;
+	u8 enabled;
 
 	processor = (struct acpi_madt_local_x2apic *)header;
 
@@ -221,6 +223,8 @@ acpi_parse_x2apic(struct acpi_subtable_h
 
 	acpi_table_print_madt_entry(header);
 
+	apic_id = processor->local_apic_id;
+	enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
 #ifdef CONFIG_X86_X2APIC
 	/*
 	 * We need to register disabled CPU as well to permit
@@ -229,8 +233,10 @@ acpi_parse_x2apic(struct acpi_subtable_h
 	 * to not preallocating memory for all NR_CPUS
 	 * when we use CPU hotplug.
 	 */
-	acpi_register_lapic(processor->local_apic_id,	/* APIC ID */
-			    processor->lapic_flags & ACPI_MADT_ENABLED);
+	if (x2apic_disabled && (apic_id >= 0xff) && enabled)
+		printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
+	else
+		acpi_register_lapic(apic_id, enabled);
 #else
 	printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
 #endif

Index: linux-2.6/arch/x86/kernel/apic/apic.c
===================================================================

arch/x86/kernel/apic/apic.c +39 -7
@@ -138,15 +138,14 @@ int x2apic_mode;
 #ifdef CONFIG_X86_X2APIC
 /* x2apic enabled before OS handover */
 static int x2apic_preenabled;
+int x2apic_disabled;
 static __init int setup_nox2apic(char *str)
 {
-	if (x2apic_enabled()) {
-		pr_warning("Bios already enabled x2apic, "
-			   "can't enforce nox2apic");
-		return 0;
-	}
+	if (x2apic_enabled())
+		pr_warning("Bios already enabled x2apic, will disable it");
+
+	x2apic_disabled = 1;
 
-	setup_clear_cpu_cap(X86_FEATURE_X2APIC);
 	return 0;
 }
 early_param("nox2apic", setup_nox2apic);
@@ -1393,8 +1392,33 @@ void __cpuinit end_local_APIC_setup(void
 }
 
 #ifdef CONFIG_X86_X2APIC
+
+static void disable_x2apic(void)
+{
+	int msr, msr2;
+
+	if (!cpu_has_x2apic)
+		return;
+
+	rdmsr(MSR_IA32_APICBASE, msr, msr2);
+	if (msr & X2APIC_ENABLE) {
+		pr_info("Disabling x2apic\n");
+		/*
+		 * Need to disable xapic and x2apic at the same time at first
+		 *  then enable xapic
+		 */
+		wrmsr(MSR_IA32_APICBASE, msr & ~(X2APIC_ENABLE | XAPIC_ENABLE),
+			 0);
+		wrmsr(MSR_IA32_APICBASE, msr & ~X2APIC_ENABLE, 0);
+	}
+}
 void check_x2apic(void)
 {
+	if (x2apic_disabled) {
+		disable_x2apic();
+		return;
+	}
+
 	if (x2apic_enabled()) {
 		pr_info("x2apic enabled by BIOS, switching to x2apic ops\n");
 		x2apic_preenabled = x2apic_mode = 1;
@@ -1405,6 +1429,11 @@ void enable_x2apic(void)
 {
 	int msr, msr2;
 
+	if (x2apic_disabled) {
+		disable_x2apic();
+		return;
+	}
+
 	if (!x2apic_mode)
 		return;
 
@@ -1473,6 +1502,9 @@ void __init enable_IR_x2apic(void)
 	else
 		ret = enable_IR();
 
+	if (x2apic_disabled)
+		goto nox2apic;
+
 	if (!ret) {
 		/* IR is required if there is APIC ID > 255 even when running
 		 * under KVM
@@ -1509,7 +1541,7 @@ out:
 
 	if (x2apic_preenabled)
 		panic("x2apic: enabled by BIOS but kernel init failed.");
-	else if (cpu_has_x2apic)
+	else if (cpu_has_x2apic && !x2apic_disabled)
 		pr_info("Not enabling x2apic, Intr-remapping init failed.\n");
 }
 

Index: linux-2.6/arch/x86/mm/srat_64.c
===================================================================

arch/x86/mm/srat_64.c +6 -1
@@ -126,6 +126,12 @@ acpi_numa_x2apic_affinity_init(struct ac
 	if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
 		return;
 	pxm = pa->proximity_domain;
+	apic_id = pa->apic_id;
+	if (x2apic_disabled && (apic_id >= 0xff)) {
+		printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
+			 pxm, apic_id);
+		return;
+	}
 	node = setup_node(pxm);
 	if (node < 0) {
 		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
@@ -133,7 +139,6 @@ acpi_numa_x2apic_affinity_init(struct ac
 		return;
 	}
 
-	apic_id = pa->apic_id;
 	apicid_to_node[apic_id] = node;
 	node_set(node, cpu_nodes_parsed);
 	acpi_numa = 1;

Index: linux-2.6/arch/x86/include/asm/apicdef.h
===================================================================

arch/x86/include/asm/apicdef.h +1 -1
@@ -141,6 +141,7 @@
 
 #define APIC_BASE (fix_to_virt(FIX_APIC_BASE))
 #define APIC_BASE_MSR	0x800
+#define XAPIC_ENABLE	(1UL << 11)
 #define X2APIC_ENABLE	(1UL << 10)
 
 #ifdef CONFIG_X86_32
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

author
#29 lore raw

PATCH 1/1 x86: Disable x2apic if nox2apic is specified

For
1. x2apic preenabled system
2. first kernel have x2apic enabled, and try to kexec second kernel with "nox2apic"

Will put back cpu with apic id < 255 into xapic mode, instead of panic.

-v2: use x2apic_disabled instead of nox2apic, Suggested by Thomas
update x2apic_supported with x2apic_disabled, Suggested by Thomas

-v3: add checking for boot cpu apic id > 255. in that case will just panic
--- pointed out by Suresh.

---
 arch/x86/include/asm/apic.h      |    6 +++-
 arch/x86/include/asm/apicdef.h   |    1 
 arch/x86/include/asm/processor.h |    1 
 arch/x86/kernel/acpi/boot.c      |   10 ++++++-
 arch/x86/kernel/apic/apic.c      |   51 +++++++++++++++++++++++++++++++++------
 arch/x86/kernel/cpu/topology.c   |   21 ++++++++++++++++
 arch/x86/mm/srat_64.c            |    7 ++++-
 7 files changed, 85 insertions(+), 12 deletions(-)
arch/x86/include/asm/apic.h +4 -2
Index: linux-2.6/arch/x86/include/asm/apic.h
===================================================================
@@ -176,6 +176,7 @@ static inline u64 native_x2apic_icr_read
 }
 
 extern int x2apic_phys;
+extern int x2apic_disabled;
 extern void check_x2apic(void);
 extern void enable_x2apic(void);
 extern void x2apic_icr_write(u32 low, u32 id);
@@ -183,7 +184,7 @@ static inline int x2apic_enabled(void)
 {
 	int msr, msr2;
 
-	if (!cpu_has_x2apic)
+	if (!cpu_has_x2apic || x2apic_disabled)
 		return 0;
 
 	rdmsr(MSR_IA32_APICBASE, msr, msr2);
@@ -192,7 +193,7 @@ static inline int x2apic_enabled(void)
 	return 0;
 }
 
-#define x2apic_supported()	(cpu_has_x2apic)
+#define x2apic_supported()	(cpu_has_x2apic && !x2apic_disabled)
 static inline void x2apic_force_phys(void)
 {
 	x2apic_phys = 1;
@@ -214,6 +215,7 @@ static inline void x2apic_force_phys(voi
 
 #define	x2apic_preenabled 0
 #define	x2apic_supported()	0
+#define	x2apic_disabled	1
 #endif
 
 extern void enable_IR_x2apic(void);
arch/x86/kernel/acpi/boot.c +8 -2
Index: linux-2.6/arch/x86/kernel/acpi/boot.c
===================================================================
@@ -213,6 +213,8 @@ static int __init
 acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
 {
 	struct acpi_madt_local_x2apic *processor = NULL;
+	int apic_id;
+	u8 enabled;
 
 	processor = (struct acpi_madt_local_x2apic *)header;
 
@@ -221,6 +223,8 @@ acpi_parse_x2apic(struct acpi_subtable_h
 
 	acpi_table_print_madt_entry(header);
 
+	apic_id = processor->local_apic_id;
+	enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
 #ifdef CONFIG_X86_X2APIC
 	/*
 	 * We need to register disabled CPU as well to permit
@@ -229,8 +233,10 @@ acpi_parse_x2apic(struct acpi_subtable_h
 	 * to not preallocating memory for all NR_CPUS
 	 * when we use CPU hotplug.
 	 */
-	acpi_register_lapic(processor->local_apic_id,	/* APIC ID */
-			    processor->lapic_flags & ACPI_MADT_ENABLED);
+	if (x2apic_disabled && (apic_id >= 0xff) && enabled)
+		printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
+	else
+		acpi_register_lapic(apic_id, enabled);
 #else
 	printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
 #endif
arch/x86/kernel/apic/apic.c +44 -7

86 lines not on this page · raw message

arch/x86/mm/srat_64.c +6 -1
Index: linux-2.6/arch/x86/mm/srat_64.c
===================================================================
@@ -126,6 +126,12 @@ acpi_numa_x2apic_affinity_init(struct ac
 	if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
 		return;
 	pxm = pa->proximity_domain;
+	apic_id = pa->apic_id;
+	if (x2apic_disabled && (apic_id >= 0xff)) {
+		printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
+			 pxm, apic_id);
+		return;
+	}
 	node = setup_node(pxm);
 	if (node < 0) {
 		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
@@ -133,7 +139,6 @@ acpi_numa_x2apic_affinity_init(struct ac
 		return;
 	}
 
-	apic_id = pa->apic_id;
 	apicid_to_node[apic_id] = node;
 	node_set(node, cpu_nodes_parsed);
 	acpi_numa = 1;
arch/x86/include/asm/apicdef.h +1 -0
Index: linux-2.6/arch/x86/include/asm/apicdef.h
===================================================================
@@ -141,6 +141,7 @@
 
 #define APIC_BASE (fix_to_virt(FIX_APIC_BASE))
 #define APIC_BASE_MSR	0x800
+#define XAPIC_ENABLE	(1UL << 11)
 #define X2APIC_ENABLE	(1UL << 10)
 
 #ifdef CONFIG_X86_32
arch/x86/include/asm/processor.h +1 -0
Index: linux-2.6/arch/x86/include/asm/processor.h
===================================================================
@@ -172,6 +172,7 @@ extern void init_scattered_cpuid_feature
 extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c);
 extern unsigned short num_cache_leaves;
 
+u32 x2apic_cpuid_initial_apicid(void);
 extern void detect_extended_topology(struct cpuinfo_x86 *c);
 extern void detect_ht(struct cpuinfo_x86 *c);
 
arch/x86/kernel/cpu/topology.c +21 -0
Index: linux-2.6/arch/x86/kernel/cpu/topology.c
===================================================================
@@ -21,6 +21,27 @@
 #define BITS_SHIFT_NEXT_LEVEL(eax)	((eax) & 0x1f)
 #define LEVEL_MAX_SIBLINGS(ebx)		((ebx) & 0xffff)
 
+u32 x2apic_cpuid_initial_apicid(void)
+{
+	unsigned int eax, ebx, ecx, edx;
+
+	if (boot_cpu_data.cpuid_level < 0xb)
+		return 0;
+
+	cpuid_count(0xb, SMT_LEVEL, &eax, &ebx, &ecx, &edx);
+
+	/*
+	 * check if the cpuid leaf 0xb is actually implemented.
+	 */
+	if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE))
+		return 0;
+
+	/*
+	 * initial apic id, which also represents 32-bit extended x2apic id.
+	 */
+	return edx;
+}
+
 /*
  * Check for extended topology enumeration cpuid leaf 0xb and if it
  * exists, use it for populating initial_apicid and cpu topology
#30 lore raw

Re: [PATCH -v3] x86: Disable x2apic if nox2apic is specified

Review

Quoted 12 lines · Yinghai Lu

For
1. x2apic preenabled system
2. first kernel have x2apic enabled, and try to kexec second kernel with "nox2apic"

Will put back cpu with apic id < 255 into xapic mode, instead of panic.

(quoted diff) +0 -2
-v2: use x2apic_disabled instead of nox2apic, Suggested by Thomas
     update x2apic_supported with x2apic_disabled, Suggested by Thomas
 
-v3: add checking for boot cpu apic id > 255. in that case will just panic
     --- pointed out by Suresh.

Can we please hold off in merging this patch for a bit? There are some subtleties in going back to xapic when the platform/cpu's are in x2apic mode. I will check and get back to you on this after KS.

thanks,
suresh

author
#31 lore raw

Re: [PATCH -v3] x86: Disable x2apic if nox2apic is specified

Quoted 10 lines · Suresh Siddha
Quoted 9 lines · Yinghai Lu

For
1. x2apic preenabled system
2. first kernel have x2apic enabled, and try to kexec second kernel with "nox2apic"

Will put back cpu with apic id < 255 into xapic mode, instead of panic.

-v2: use x2apic_disabled instead of nox2apic, Suggested by Thomas
update x2apic_supported with x2apic_disabled, Suggested by Thomas

Quoted 7 lines
Quoted 3 lines

-v3: add checking for boot cpu apic id > 255. in that case will just panic
--- pointed out by Suresh.

Can we please hold off in merging this patch for a bit? There are some subtleties in going back to xapic when the platform/cpu's are in x2apic mode. I will check and get back to you on this after KS.

sure. take you time.

Yinghai