Skip to contentSkip to conversation

x86/cpu: identify uninitialized CPU data using BAD_APICID

PATCH In review Roger Pau Monne 4 participants 5 messages Apr 30 – May 4

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/cpu: identify uninitialized CPU data using BAD_APICID

Uninitialized cpu_data[] entries have the apicid field set to BAD_APICID, not boot_cpu_data.apicid. Fix the check in cpu_smpboot_free() to use the correct condition.

Fixes 7126b7f806d5 ("x86/CPU: re-work populating of cpu_data[]")
---
 xen/arch/x86/smpboot.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/smpboot.c +1 -2
index 491cbbba33ae..ff05955bae40 100644
@@ -961,8 +961,7 @@ static void cpu_smpboot_free(unsigned int cpu, bool remove)
      * In that case the socket number cannot be relied upon, but the respective
      * socket_cpumask[] slot also wouldn't have been set.
      */
-    if ( c[cpu].apicid != boot_cpu_data.apicid &&
-         cpumask_empty(socket_cpumask[socket]) )
+    if ( c[cpu].apicid != BAD_APICID && cpumask_empty(socket_cpumask[socket]) )
     {
         xfree(socket_cpumask[socket]);
         socket_cpumask[socket] = NULL;
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw

Le 30/04/2026 à 13:47, Roger Pau Monne a écrit :

Quoted 15 lines

Uninitialized cpu_data[] entries have the apicid field set to BAD_APICID, not boot_cpu_data.apicid. Fix the check in cpu_smpboot_free() to use the correct condition.

Fixes 7126b7f806d5 ("x86/CPU: re-work populating of cpu_data[]")
---
  xen/arch/x86/smpboot.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/smpboot.c +0 -0
index 491cbbba33ae..ff05955bae40 100644

xen/arch/x86/smpboot.c static void cpu_smpboot_free(unsigned int cpu, bool remove) · line 967

Quoted 9 lines
xen/arch/x86/smpboot.c +1 -2
@@ -961,8 +961,7 @@ static void cpu_smpboot_free(unsigned int cpu, bool remove)
       * In that case the socket number cannot be relied upon, but the respective
       * socket_cpumask[] slot also wouldn't have been set.
       */
-    if ( c[cpu].apicid != boot_cpu_data.apicid &&
-         cpumask_empty(socket_cpumask[socket]) )
+    if ( c[cpu].apicid != BAD_APICID && cpumask_empty(socket_cpumask[socket]) )
      {
          xfree(socket_cpumask[socket]);
          socket_cpumask[socket] = NULL;

--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

Reviewed-by on v1 1/1
#2 lore raw
In reply to Roger Pau Monne
Quoted 15 lines · Roger Pau Monne

Uninitialized cpu_data[] entries have the apicid field set to BAD_APICID, not boot_cpu_data.apicid. Fix the check in cpu_smpboot_free() to use the correct condition.

Fixes 7126b7f806d5 ("x86/CPU: re-work populating of cpu_data[]")
---
 xen/arch/x86/smpboot.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/smpboot.c +0 -0
index 491cbbba33ae..ff05955bae40 100644

xen/arch/x86/smpboot.c static void cpu_smpboot_free(unsigned int cpu, bool remove) · line 967

Quoted 9 lines
xen/arch/x86/smpboot.c +1 -2
@@ -961,8 +961,7 @@ static void cpu_smpboot_free(unsigned int cpu, bool remove)
      * In that case the socket number cannot be relied upon, but the respective
      * socket_cpumask[] slot also wouldn't have been set.
      */
-    if ( c[cpu].apicid != boot_cpu_data.apicid &&
-         cpumask_empty(socket_cpumask[socket]) )
+    if ( c[cpu].apicid != BAD_APICID && cpumask_empty(socket_cpumask[socket]) )
     {
         xfree(socket_cpumask[socket]);
         socket_cpumask[socket] = NULL;

Yet more fallout from that change...

This is the singular use of apicid.  We should consider removing it, but that's a change for later.

#3 lore raw
In reply to Roger Pau Monne
Quoted 5 lines · Roger Pau Monne

Uninitialized cpu_data[] entries have the apicid field set to BAD_APICID, not boot_cpu_data.apicid. Fix the check in cpu_smpboot_free() to use the correct condition.

Fixes 7126b7f806d5 ("x86/CPU: re-work populating of cpu_data[]")

I think this isn't correct, and the issue here is me having overlooked a dependency between that commit and the one introducing the line which you change: 8c15d3d18725 ("x86/SMP: guard socket_cpumask[] access in cpu_smpboot_free()"). Both changes were committed close together, but they were entirely separate submissions (well over a year apart). Hence as an individual patch that latter commit was correct, but on top of 7126b7f806d5 it would have needed adjustment. Since 7126b7f806d5 wasn't backported (while 8c15d3d18725 was), the fix here also shouldn't be backported to anything earlier than 4.21 (which indeed the Fixes: tag better expresses).

Jan

Quoted 12 lines
xen/arch/x86/smpboot.c +1 -2
@@ -961,8 +961,7 @@ static void cpu_smpboot_free(unsigned int cpu, bool remove)
      * In that case the socket number cannot be relied upon, but the respective
      * socket_cpumask[] slot also wouldn't have been set.
      */
-    if ( c[cpu].apicid != boot_cpu_data.apicid &&
-         cpumask_empty(socket_cpumask[socket]) )
+    if ( c[cpu].apicid != BAD_APICID && cpumask_empty(socket_cpumask[socket]) )
     {
         xfree(socket_cpumask[socket]);
         socket_cpumask[socket] = NULL;
#4 lore raw
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monne

Uninitialized cpu_data[] entries have the apicid field set to BAD_APICID, not boot_cpu_data.apicid. Fix the check in cpu_smpboot_free() to use the correct condition.

Fixes 7126b7f806d5 ("x86/CPU: re-work populating of cpu_data[]")
Quoted 10 lines

I think this isn't correct, and the issue here is me having overlooked a dependency between that commit and the one introducing the line which you change: 8c15d3d18725 ("x86/SMP: guard socket_cpumask[] access in cpu_smpboot_free()"). Both changes were committed close together, but they were entirely separate submissions (well over a year apart). Hence as an individual patch that latter commit was correct, but on top of 7126b7f806d5 it would have needed adjustment. Since 7126b7f806d5 wasn't backported (while 8c15d3d18725 was), the fix here also shouldn't be backported to anything earlier than 4.21 (which indeed the Fixes: tag better expresses).

I see, right, in the git history 8c15d3d18725 is indeed later than 7126b7f806d5, and hence 7126b7f806d5 was correct when introduced. The bug in cpu_smpboot_free() was there, but 7126b7f806d5 made it no worse. It was 8c15d3d18725 that would indeed need to be adjusted to pick up the new initialization value.

Thanks, Roger.