[PATCH] x86/cpu: Rewrite initialize_cpu_data() for clarity

Andrew Cooper posted 1 patch 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20260813145349.1656699-1-andrew.cooper3@citrix.com
xen/arch/x86/smpboot.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
[PATCH] x86/cpu: Rewrite initialize_cpu_data() for clarity
Posted by Andrew Cooper 2 weeks ago
Without passing opinion on the behaviour of this function, it is deceptive to
read (I've twice now mistaken it for resetting boot_cpu_data), and
inefficient.

Instead of having a 256 byte object on the stack and a double copy, copy
boot_cpu_data directly, then reset parts of cpu_data[cpu] in place.  Leave
some comments behind explaining what's happening.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <jbeulich@suse.com>
CC: Roger Pau Monné <roger@xenproject.org>
CC: Teddy Astie <teddy.astie@vates.tech>

Pulled out of separate series.
---
 xen/arch/x86/smpboot.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
index 84e9e4beed60..cede2b886f33 100644
--- a/xen/arch/x86/smpboot.c
+++ b/xen/arch/x86/smpboot.c
@@ -94,12 +94,14 @@ void *stack_base[NR_CPUS];
 
 void initialize_cpu_data(unsigned int cpu)
 {
-    struct cpuinfo_x86 c = boot_cpu_data;
+    struct cpuinfo_x86 *c = &cpu_data[cpu];
 
-    /* Must not partially clear the BSP's collected data. */
+    /* First, inherit from boot_cpu_data */
+    *c = boot_cpu_data;
+
+    /* Second, reset most of it, except if we're the BSP at early boot. */
     if ( cpu || system_state > SYS_STATE_smp_boot )
-        reset_cpuinfo(&c, true);
-    cpu_data[cpu] = c;
+        reset_cpuinfo(c, true);
 }
 
 static bool smp_store_cpu_info(unsigned int id)
-- 
2.39.5


Re: [PATCH] x86/cpu: Rewrite initialize_cpu_data() for clarity
Posted by Jan Beulich 2 weeks ago
On 13.08.2026 16:53, Andrew Cooper wrote:
> Without passing opinion on the behaviour of this function, it is deceptive to
> read (I've twice now mistaken it for resetting boot_cpu_data), and
> inefficient.
> 
> Instead of having a 256 byte object on the stack and a double copy, copy
> boot_cpu_data directly, then reset parts of cpu_data[cpu] in place.  Leave
> some comments behind explaining what's happening.
> 
> No functional change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

While I think it was good enough before, I also don't mind the change:
Acked-by: Jan Beulich <jbeulich@suse.com>

Jan