Skip to contentSkip to conversation

x86/acpi/boot: Do not register processors that cannot be onlined for x2apic

PATCH Applied Kishon Vijay Abraham I 7 participants 12 messages Jan 5, 2023 – Apr 2, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/acpi/boot: Do not register processors that cannot be onlined for x2apic

Section 5.2.12.12 Processor Local x2APIC Structure in the ACPI v6.5 spec mandates that both "enabled" and "online capable" Local APIC Flags should be used to determine if the processor is usable or not.

However, Linux doesn't use the "online capable" flag for x2APIC to determine if the processor is usable. As a result, cpu_possible_mask has incorrect value and results in more memory getting allocated for per_cpu variables than it is going to be used.

Make sure Linux parses both "enabled" and "online capable" flags for x2APIC to correctly determine if the processor is usable.

Fixes aa06e20f1be6 ("x86/ACPI: Don't add CPUs that are not online capable")

---
Changes from v1:
1) Changed the ACPI spec version to 6.5 in the commit log
2) Changed the Fixes tag to point to commit aa06e20f1be6
3) Added "Reported-by: Leo Duran <[email protected]>"

 arch/x86/kernel/acpi/boot.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
arch/x86/kernel/acpi/boot.c +16 -3
index 907cc98b1938..518bda50068c 100644
@@ -188,6 +188,17 @@ static int acpi_register_lapic(int id, u32 acpiid, u8 enabled)
 	return cpu;
 }
 
+static bool __init acpi_is_processor_usable(u32 lapic_flags)
+{
+	if (lapic_flags & ACPI_MADT_ENABLED)
+		return true;
+
+	if (acpi_support_online_capable && (lapic_flags & ACPI_MADT_ONLINE_CAPABLE))
+		return true;
+
+	return false;
+}
+
 static int __init
 acpi_parse_x2apic(union acpi_subtable_headers *header, const unsigned long end)
 {
@@ -212,6 +223,10 @@ acpi_parse_x2apic(union acpi_subtable_headers *header, const unsigned long end)
 	if (apic_id == 0xffffffff)
 		return 0;
 
+	/* don't register processors that cannot be onlined */
+	if (!acpi_is_processor_usable(processor->lapic_flags))
+		return 0;
+
 	/*
 	 * We need to register disabled CPU as well to permit
 	 * counting disabled CPUs. This allows us to size
@@ -250,9 +265,7 @@ acpi_parse_lapic(union acpi_subtable_headers * header, const unsigned long end)
 		return 0;
 
 	/* don't register processors that can not be onlined */
-	if (acpi_support_online_capable &&
-	    !(processor->lapic_flags & ACPI_MADT_ENABLED) &&
-	    !(processor->lapic_flags & ACPI_MADT_ONLINE_CAPABLE))
+	if (!acpi_is_processor_usable(processor->lapic_flags))
 		return 0;
 
 	/*
Signature · 1 line
2.34.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Kishon Vijay Abraham I

Section 5.2.12.12 Processor Local x2APIC Structure in the ACPI v6.5 spec mandates that both "enabled" and "online capable" Local APIC Flags should be used to determine if the processor is usable or not.

However, Linux doesn't use the "online capable" flag for x2APIC to determine if the processor is usable. As a result, cpu_possible_mask has incorrect value and results in more memory getting allocated for per_cpu variables than it is going to be used.

Quoted 7 lines

Make sure Linux parses both "enabled" and "online capable" flags for x2APIC to correctly determine if the processor is usable.

Fixes aa06e20f1be6 ("x86/ACPI: Don't add CPUs that are not online capable")
Quoted 55 lines

---
Changes from v1:
1) Changed the ACPI spec version to 6.5 in the commit log
2) Changed the Fixes tag to point to commit aa06e20f1be6
3) Added "Reported-by: Leo Duran <[email protected]>"

 arch/x86/kernel/acpi/boot.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
arch/x86/kernel/acpi/boot.c +16 -4
index 907cc98b1938..518bda50068c 100644
@@ -188,6 +188,17 @@ static int acpi_register_lapic(int id, u32 acpiid, u8 enabled)
        return cpu;
 }
 
+static bool __init acpi_is_processor_usable(u32 lapic_flags)
+{
+       if (lapic_flags & ACPI_MADT_ENABLED)
+               return true;
+
+       if (acpi_support_online_capable && (lapic_flags & ACPI_MADT_ONLINE_CAPABLE))
+               return true;
+
+       return false;
+}
+
 static int __init
 acpi_parse_x2apic(union acpi_subtable_headers *header, const unsigned long end)
 {
@@ -212,6 +223,10 @@ acpi_parse_x2apic(union acpi_subtable_headers *header, const unsigned long end)
        if (apic_id == 0xffffffff)
                return 0;
 
+       /* don't register processors that cannot be onlined */
+       if (!acpi_is_processor_usable(processor->lapic_flags))
+               return 0;
+
        /*
         * We need to register disabled CPU as well to permit
         * counting disabled CPUs. This allows us to size
@@ -250,9 +265,7 @@ acpi_parse_lapic(union acpi_subtable_headers * header, const unsigned long end)
                return 0;
 
        /* don't register processors that can not be onlined */
-       if (acpi_support_online_capable &&
-           !(processor->lapic_flags & ACPI_MADT_ENABLED) &&
-           !(processor->lapic_flags & ACPI_MADT_ONLINE_CAPABLE))
+       if (!acpi_is_processor_usable(processor->lapic_flags))
                return 0;
 
        /*
--

2.34.1

maintainer
#2 lore raw
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Kishon Vijay Abraham I

Section 5.2.12.12 Processor Local x2APIC Structure in the ACPI v6.5 spec mandates that both "enabled" and "online capable" Local APIC Flags should be used to determine if the processor is usable or not.

However, Linux doesn't use the "online capable" flag for x2APIC to determine if the processor is usable. As a result, cpu_possible_mask has incorrect value and results in more memory getting allocated for per_cpu variables than it is going to be used.

Make sure Linux parses both "enabled" and "online capable" flags for x2APIC to correctly determine if the processor is usable.

Quoted 6 lines
Quoted 4 lines
Fixes aa06e20f1be6 ("x86/ACPI: Don't add CPUs that are not online capable")

Are you saying, I should take it through tip?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#3 lore raw
Quoted 16 lines · Borislav Petkov
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Kishon Vijay Abraham I

Section 5.2.12.12 Processor Local x2APIC Structure in the ACPI v6.5 spec mandates that both "enabled" and "online capable" Local APIC Flags should be used to determine if the processor is usable or not.

However, Linux doesn't use the "online capable" flag for x2APIC to determine if the processor is usable. As a result, cpu_possible_mask has incorrect value and results in more memory getting allocated for per_cpu variables than it is going to be used.

Make sure Linux parses both "enabled" and "online capable" flags for x2APIC to correctly determine if the processor is usable.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Fixes aa06e20f1be6 ("x86/ACPI: Don't add CPUs that are not online capable")

Are you saying, I should take it through tip?

Works for me either way.

Just please let me know if I need to take care of it. :-)

maintainer
#4 lore raw
Quoted 1 line · Rafael J. Wysocki

Just please let me know if I need to take care of it. :-)

You don't. :-)

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Reviewed-by
#5 lore raw
In reply to Rafael J. Wysocki
Quoted 18 lines · Rafael J. Wysocki
Quoted 16 lines · Kishon Vijay Abraham I

Section 5.2.12.12 Processor Local x2APIC Structure in the ACPI v6.5 spec mandates that both "enabled" and "online capable" Local APIC Flags
should be used to determine if the processor is usable or not.

However, Linux doesn't use the "online capable" flag for x2APIC to determine if the processor is usable. As a result, cpu_possible_mask has
incorrect value and results in more memory getting allocated for per_cpu
variables than it is going to be used.

Make sure Linux parses both "enabled" and "online capable" flags for
x2APIC to correctly determine if the processor is usable.

Quoted 8 lines
Quoted 5 lines
Fixes aa06e20f1be6 ("x86/ACPI: Don't add CPUs that are not online

capable")

thanks,
rui

Quoted 61 lines
Quoted 61 lines

---
Changes from v1:
1) Changed the ACPI spec version to 6.5 in the commit log
2) Changed the Fixes tag to point to commit aa06e20f1be6
3) Added "Reported-by: Leo Duran <[email protected]>"

 arch/x86/kernel/acpi/boot.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
arch/x86/kernel/acpi/boot.c +11 -0
index 907cc98b1938..518bda50068c 100644
@@ -188,6 +188,17 @@ static int acpi_register_lapic(int id, u32
 acpiid, u8 enabled)
        return cpu;
 }
 
+static bool __init acpi_is_processor_usable(u32 lapic_flags)
+{
+       if (lapic_flags & ACPI_MADT_ENABLED)
+               return true;
+
+       if (acpi_support_online_capable && (lapic_flags &
 ACPI_MADT_ONLINE_CAPABLE))
+               return true;
+
+       return false;
+}
+
 static int __init

acpi_parse_x2apic(union acpi_subtable_headers *header, const
unsigned long end)
{

arch/x86/kernel/acpi/boot.c +4 -0
@@ -212,6 +223,10 @@ acpi_parse_x2apic(union acpi_subtable_headers
 *header, const unsigned long end)
        if (apic_id == 0xffffffff)
                return 0;
 
+       /* don't register processors that cannot be onlined */
+       if (!acpi_is_processor_usable(processor->lapic_flags))
+               return 0;
+
        /*
         * We need to register disabled CPU as well to permit

* counting disabled CPUs. This allows us to size

arch/x86/kernel/acpi/boot.c +1 -3
@@ -250,9 +265,7 @@ acpi_parse_lapic(union acpi_subtable_headers *
 header, const unsigned long end)
                return 0;
 
        /* don't register processors that can not be onlined */
-       if (acpi_support_online_capable &&
-           !(processor->lapic_flags & ACPI_MADT_ENABLED) &&
-           !(processor->lapic_flags & ACPI_MADT_ONLINE_CAPABLE))
+       if (!acpi_is_processor_usable(processor->lapic_flags))
                return 0;
 
        /*

--
2.34.1

#6 lore raw

[tip: x86/boot] x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC

In reply to Kishon Vijay Abraham I
The following commit has been merged into the x86/boot branch of tip:

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     e2869bd7af608c343988429ceb1c2fe99644a01f
Gitweb:        https://git.kernel.org/tip/e2869bd7af608c343988429ceb1c2fe99644a01f
Author:        Kishon Vijay Abraham I <[email protected]>
AuthorDate:    Thu, 05 Jan 2023 04:10:59 
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Tue, 10 Jan 2023 19:21:07 +01:00

x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC

Section 5.2.12.12 Processor Local x2APIC Structure in the ACPI v6.5 spec mandates that both "enabled" and "online capable" Local APIC Flags should be used to determine if the processor is usable or not.

However, Linux doesn't use the "online capable" flag for x2APIC to determine if the processor is usable. As a result, cpu_possible_mask has incorrect value and results in more memory getting allocated for per_cpu variables than it is going to be used.

Make sure Linux parses both "enabled" and "online capable" flags for x2APIC to correctly determine if the processor is usable.

---
 arch/x86/kernel/acpi/boot.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
arch/x86/kernel/acpi/boot.c +16 -3
index 907cc98..518bda5 100644
@@ -188,6 +188,17 @@ static int acpi_register_lapic(int id, u32 acpiid, u8 enabled)
 	return cpu;
 }
 
+static bool __init acpi_is_processor_usable(u32 lapic_flags)
+{
+	if (lapic_flags & ACPI_MADT_ENABLED)
+		return true;
+
+	if (acpi_support_online_capable && (lapic_flags & ACPI_MADT_ONLINE_CAPABLE))
+		return true;
+
+	return false;
+}
+
 static int __init
 acpi_parse_x2apic(union acpi_subtable_headers *header, const unsigned long end)
 {
@@ -212,6 +223,10 @@ acpi_parse_x2apic(union acpi_subtable_headers *header, const unsigned long end)
 	if (apic_id == 0xffffffff)
 		return 0;
 
+	/* don't register processors that cannot be onlined */
+	if (!acpi_is_processor_usable(processor->lapic_flags))
+		return 0;
+
 	/*
 	 * We need to register disabled CPU as well to permit
 	 * counting disabled CPUs. This allows us to size
@@ -250,9 +265,7 @@ acpi_parse_lapic(union acpi_subtable_headers * header, const unsigned long end)
 		return 0;
 
 	/* don't register processors that can not be onlined */
-	if (acpi_support_online_capable &&
-	    !(processor->lapic_flags & ACPI_MADT_ENABLED) &&
-	    !(processor->lapic_flags & ACPI_MADT_ONLINE_CAPABLE))
+	if (!acpi_is_processor_usable(processor->lapic_flags))
 		return 0;
 
 	/*
#7 lore raw
In reply to Kishon Vijay Abraham I

Le 05/01/2023 à 05:10, Kishon Vijay Abraham I a écrit :

Quoted 9 lines

Section 5.2.12.12 Processor Local x2APIC Structure in the ACPI v6.5 spec mandates that both "enabled" and "online capable" Local APIC Flags should be used to determine if the processor is usable or not.

However, Linux doesn't use the "online capable" flag for x2APIC to determine if the processor is usable. As a result, cpu_possible_mask has incorrect value and results in more memory getting allocated for per_cpu variables than it is going to be used.

Quoted 7 lines

Make sure Linux parses both "enabled" and "online capable" flags for x2APIC to correctly determine if the processor is usable.

Fixes aa06e20f1be6 ("x86/ACPI: Don't add CPUs that are not online capable")

Hello everyone,

My system worked fine with kernel 6.1.15, but stopped booting after upgrading to 6.1.20 and resulted in a kernel panic:

---

[ 0.117782] Kernel panic — not syncing: timer doesn’t work through Interrupt-remapped IO-APIC
[ 0.117848] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.1.0-7-and64 #1 Debian 6.1.20-1
[ 0.117913] Hardware name: Gigabyte Technology Co., Ltd. ABS50M-Gaming 3/AB350M-Gaming 3-CF, BIOS F50d 07/02/2020
[ 0.117982] Call Trace:
[ 0.118634] <TASK>
[ 0.118685] dump_stack_lvl+0x44/0x5c
[ 0.118143] panic+0x118/0x2ed
[ 0.118198] panic_if_irq_remap.cold+0x5/0x5
[ 0.118256] setup_I0_APIC+0x3db/0x64b
[ 0.118313] ? _raw_spin_unlock_irqrestore+0x23/0x40
[ 0.118372] ? clear_IO_APIC_pin+0x169/0x240
[ 0.118429] apic_intr_node_init+0x101/0x106
[ 0.118485] x86_late_time_init+0x20/0x34
[ 0.118542] start_kerne1+0x667/0x727
[ 0.118598] secondary_startup_64_no_verify+0xe5/0xeb
[ 0.118658] </TASK>
[ 0.118711] ---[ end Kernel panic - not syncing: timer doesn’t work through Interrupt-remapped IO-APIC J---

---
I tried an update of the BIOS up to F51h without any effect.

I sent a bug report to Debian Bug Tracking System. In reply Bjørn Mork identified ce7d894bed1a539a8d6cff42f6f78f9db0c9c26b from the linux-6.1.y branch as the likely culprit.

After building a 6.1.20 kernel with just that commit reverted, my system boots normally again.

I reported that all tohttps://bugs.debian.org/1033732 and were asked to report the issue 'upstream' (which is what that mail is).

Hope it will help!

Best regards.

-- Guy Durrieu

maintainer
#10 lore raw
Quoted 1 line · Guy Durrieu

Yes it does.

Thanks for testing.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#11 lore raw

Re: Bug#1033732: [PATCH v2] x86/acpi/boot: Do not register processors that cannot be onlined for x2apic

In reply to Guy Durrieu

Hi

Quoted 49 lines · Guy Durrieu

Le 05/01/2023 à 05:10, Kishon Vijay Abraham I a écrit :

Quoted 9 lines

Section 5.2.12.12 Processor Local x2APIC Structure in the ACPI v6.5 spec mandates that both "enabled" and "online capable" Local APIC Flags should be used to determine if the processor is usable or not.

However, Linux doesn't use the "online capable" flag for x2APIC to determine if the processor is usable. As a result, cpu_possible_mask has incorrect value and results in more memory getting allocated for per_cpu variables than it is going to be used.

Quoted 7 lines

Make sure Linux parses both "enabled" and "online capable" flags for x2APIC to correctly determine if the processor is usable.

Fixes aa06e20f1be6 ("x86/ACPI: Don't add CPUs that are not online capable")

Hello everyone,

My system worked fine with kernel 6.1.15, but stopped booting after upgrading to 6.1.20 and resulted in a kernel panic:

---

[ 0.117782] Kernel panic — not syncing: timer doesn’t work through Interrupt-remapped IO-APIC
[ 0.117848] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.1.0-7-and64 #1 Debian 6.1.20-1
[ 0.117913] Hardware name: Gigabyte Technology Co., Ltd. ABS50M-Gaming 3/AB350M-Gaming 3-CF, BIOS F50d 07/02/2020
[ 0.117982] Call Trace:
[ 0.118634] <TASK>
[ 0.118685] dump_stack_lvl+0x44/0x5c
[ 0.118143] panic+0x118/0x2ed
[ 0.118198] panic_if_irq_remap.cold+0x5/0x5
[ 0.118256] setup_I0_APIC+0x3db/0x64b
[ 0.118313] ? _raw_spin_unlock_irqrestore+0x23/0x40
[ 0.118372] ? clear_IO_APIC_pin+0x169/0x240
[ 0.118429] apic_intr_node_init+0x101/0x106
[ 0.118485] x86_late_time_init+0x20/0x34
[ 0.118542] start_kerne1+0x667/0x727
[ 0.118598] secondary_startup_64_no_verify+0xe5/0xeb
[ 0.118658] </TASK>
[ 0.118711] ---[ end Kernel panic - not syncing: timer doesn’t work through Interrupt-remapped IO-APIC J---

---
I tried an update of the BIOS up to F51h without any effect.

I sent a bug report to Debian Bug Tracking System. In reply Bjørn Mork identified ce7d894bed1a539a8d6cff42f6f78f9db0c9c26b from the linux-6.1.y branch as the likely culprit.

Quoted 7 lines

After building a 6.1.20 kernel with just that commit reverted, my system boots normally again.

I reported that all tohttps://bugs.debian.org/1033732 and were asked to report the issue 'upstream' (which is what that mail is).

Hope it will help!

Best regards.

Trying to make as well the regression tracker bot aware of the issue (but dropping all CCs to not spam them with duplicate information):

#regzbot ^introduced e2869bd7af60
#regzbot title: Regression from "x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC" #regzbot link https://lore.kernel.org/lkml/[email protected]/
#regzbot link https://bugs.debian.org/1033732
#regzbot fixed-by: fed8d8773b8e

Regards,
Salvatore