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

[PATCH v7 42/50] x86/time: move the calibration rendezvous data 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 an IPI handler cannot dereference a pointer into the
initiating CPU's stack.  Payloads handed to other CPUs via
on_selected_cpus() must live somewhere globally reachable.

time_calibration() passes a pointer to a stack-allocated struct
calibration_rendezvous to all online CPUs.  The payload is a shared
rendezvous object: the handlers synchronise with each other through
r->semaphore, the CPU0 handler publishes master_stime for the others
to read, and the TSC variant additionally cmpxchg-loops on
r->max_tsc_stamp.  All of that requires every participating CPU to be
able to reach the object.

Make the rendezvous data a function-scope static, fully re-initialised
on entry.  Serialisation is already guaranteed: invocations come from
calibration_timer, which is bound to CPU0, and at boot directly from
verify_tsc_reliability(), also on CPU0, and the call uses @wait == 1
precisely so that all CPUs are done with @r before the caller returns
(the existing comment says as much), hence also before the next
invocation can re-initialise it.

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/time.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index 0e5d06a9a8..68719a43d3 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -2390,7 +2390,14 @@ static void (*time_calibration_rendezvous_fn)(void *) =
 
 static void cf_check time_calibration(void *unused)
 {
-    struct calibration_rendezvous r = {
+    /*
+     * Shared by the calibration handlers on every CPU, so not on the stack,
+     * which other CPUs need not be able to reach.  Invocations are serialised
+     * (calibration_timer and verify_tsc_reliability(), both on CPU0).
+     */
+    static struct calibration_rendezvous r;
+
+    r = (struct calibration_rendezvous){
         .semaphore = ATOMIC_INIT(0)
     };
 
@@ -2403,7 +2410,7 @@ static void cf_check time_calibration(void *unused)
 
     cpumask_copy(&r.cpu_calibration_map, &cpu_online_map);
 
-    /* @wait=1 because we must wait for all cpus before freeing @r. */
+    /* @wait=1 because we must wait for all cpus before reusing @r. */
     on_selected_cpus(&r.cpu_calibration_map,
                      time_calibration_rendezvous_fn,
                      &r, 1);
-- 
2.56.0




 


Rackspace

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