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

[PATCH v7 49/50] x86: pass remaining stack-allocated callfunc payloads by value



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 pointers into a caller's stack cannot be dereferenced by
call-function callees.

Convert the remaining call sites that point another CPU at a local
variable via on_selected_cpus(), with on_selected_cpus_obj_inout()
where the callee writes results back (resource_access(),
l3_cache_get()) and on_selected_cpus_obj() where it only reads
(do_write_psr_msrs(), __machine_restart()):

 * XENPF_resource_op: struct resource_access on the do_platform_op()
   stack; the callee writes ra.nr_done back, and ra.entries points at
   a (heap) array the callee also writes - both keep working, the
   former via the copy-back, the latter because the array stays
   globally reachable.
 * psr do_write_psr_msrs(): struct cos_write_info, which the callee
   only reads; the embedded val pointer references a heap array.
 * machine_restart(): the hop to the boot CPU passes delay_millisecs
   with @wait == 0 and then halts this CPU forever.  This is the one
   asynchronous case: the halted caller's frame stays alive for the
   callee (correct today), but with per-CPU mapped stacks it would no
   longer be reachable.  Passing by value removes the cross-CPU
   reference altogether.
 * XEN_SYSCTL_psr_cmt_op: struct l3_cache_info, filled by the callee.

No functional change.

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/platform_hypercall.c | 2 +-
 xen/arch/x86/psr.c                | 2 +-
 xen/arch/x86/shutdown.c           | 4 ++--
 xen/arch/x86/sysctl.c             | 3 ++-
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/xen/arch/x86/platform_hypercall.c 
b/xen/arch/x86/platform_hypercall.c
index 0f3c791fc2..5516a232e4 100644
--- a/xen/arch/x86/platform_hypercall.c
+++ b/xen/arch/x86/platform_hypercall.c
@@ -876,7 +876,7 @@ ret_t do_platform_op(
         if ( cpu == smp_processor_id() )
             resource_access(&ra);
         else
-            on_selected_cpus(cpumask_of(cpu), resource_access, &ra, 1);
+            on_selected_cpus_obj_inout(cpumask_of(cpu), resource_access, &ra);
 
         /* Copy all if succeeded or up to the failed entry. */
         if ( __copy_to_guest(guest_entries, ra.entries,
diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c
index cce7020868..29b8fad96e 100644
--- a/xen/arch/x86/psr.c
+++ b/xen/arch/x86/psr.c
@@ -1337,7 +1337,7 @@ static int write_psr_msrs(unsigned int socket, unsigned 
int cos,
 
         if ( cpu >= nr_cpu_ids )
             return -ENOTSOCK;
-        on_selected_cpus(cpumask_of(cpu), do_write_psr_msrs, &data, 1);
+        on_selected_cpus_obj(cpumask_of(cpu), do_write_psr_msrs, &data, 1);
     }
 
     return 0;
diff --git a/xen/arch/x86/shutdown.c b/xen/arch/x86/shutdown.c
index 902076cf67..820eaa7e30 100644
--- a/xen/arch/x86/shutdown.c
+++ b/xen/arch/x86/shutdown.c
@@ -550,8 +550,8 @@ void machine_restart(unsigned int delay_millisecs)
         if ( get_apic_id() != boot_cpu_physical_apicid )
         {
             /* Send IPI to the boot CPU (logical cpu 0). */
-            on_selected_cpus(cpumask_of(0), __machine_restart,
-                             &delay_millisecs, 0);
+            on_selected_cpus_obj(cpumask_of(0), __machine_restart,
+                                 &delay_millisecs, 0);
             for ( ; ; )
                 halt();
         }
diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c
index 6bd4e191a7..b1a15dce97 100644
--- a/xen/arch/x86/sysctl.c
+++ b/xen/arch/x86/sysctl.c
@@ -195,7 +195,8 @@ long arch_do_sysctl(
             if ( cpu == smp_processor_id() )
                 l3_cache_get(&info);
             else
-                on_selected_cpus(cpumask_of(cpu), l3_cache_get, &info, 1);
+                on_selected_cpus_obj_inout(cpumask_of(cpu), l3_cache_get,
+                                           &info);
 
             ret = info.ret;
             sysctl->u.psr_cmt_op.u.data = (ret ? 0 : info.size);
-- 
2.56.0




 


Rackspace

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