[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v7 43/50] x86/ucode: move the stop_machine payload off the stack



Per-CPU stack mappings, to come as part of Address Space Isolation,
give some contexts page-tables which map only the stack of the CPU
they run on.  A CPU in such a context cannot reach another CPU's
stack, so payloads handed to other CPUs - here via stop_machine_run()
- must live somewhere globally reachable.

ucode_update_hcall_cont() passes the address of a stack-local struct
patch_with_flags to stop_machine_run(), which stashes the raw pointer
in the (static) stopmachine_data and has every online CPU dereference
it from do_microcode_update().

Make it a function-scope static, mirroring the adjacent nmi_patch.
Both fields are written on every invocation before stop_machine_run()
is called.  Serialisation is already guaranteed: the continuation is
always queued via continue_hypercall_on_cpu(0, ...), so invocations
run one at a time in CPU0 tasklet context.

Groundwork for per-CPU stack mappings, which take away a CPU's access
to other CPUs' stacks: besides get_cpu_current(), cross-CPU rendezvous
and call-function payloads are what reads another CPU's stack at run
time.

Assisted-by: Claude Code:claude-opus-4-8, Claude Code:claude-opus-5-5
Signed-off-by: George Dunlap <gwd@xxxxxxxxxxxxxx>
---
Changes in v7:
- New in this version.
---
 xen/arch/x86/cpu/microcode/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/cpu/microcode/core.c 
b/xen/arch/x86/cpu/microcode/core.c
index 9b8d1e09cb..6f27d0b885 100644
--- a/xen/arch/x86/cpu/microcode/core.c
+++ b/xen/arch/x86/cpu/microcode/core.c
@@ -492,7 +492,12 @@ static long cf_check __maybe_unused 
ucode_update_hcall_cont(void *data)
     int ret, result;
     struct ucode_buf *buffer = data;
     unsigned int cpu, updated;
-    struct patch_with_flags patch_with_flags;
+    /*
+     * Dereferenced by every CPU from the stop_machine context below, so not
+     * on the stack, which other CPUs need not be able to reach.  Invocations
+     * are serialised: each runs as a CPU0 tasklet.
+     */
+    static struct patch_with_flags patch_with_flags;
     bool ucode_force = buffer->flags & XENPF_UCODE_FORCE;
 
     /* cpu_online_map must not change during update */
-- 
2.56.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.