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

[PATCH] xen: Don't cast away const-ness in vcpu_show_registers()



The final hunk is `(struct vcpu *)v` in disguise, expressed using a runtime
pointer chase through memory and a technicality of the C type system to work
around the fact that get_hvm_registers() strictly requires a mutable pointer.

For anyone interested, this is one reason why C cannot optimise any reads
across sequence points, even for a function purporting to take a const object.

Anyway, have the function correctly state that it needs a mutable vcpu.  All
callers have a mutable vCPU to hand, and it removes the runtime pointer chase
in x86.

Make one style adjustment in ARM while adjusting the parameter type.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Anthony PERARD <anthony.perard@xxxxxxxxxx>
CC: Michal Orzel <michal.orzel@xxxxxxx>
CC: Jan Beulich <jbeulich@xxxxxxxx>
CC: Julien Grall <julien@xxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
CC: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
CC: Bertrand Marquis <bertrand.marquis@xxxxxxx>

RISC-V and PPC don't have this helper yet, not even in stub form.

I expect there will be one objection to this patch.  Since the last time we
fought over this, speculative vulnerabilities have demonstrated how dangerous
pointer chases are, and this is a violation of Misra Rule 11.8, even if it's
not reasonable for Eclair to be able to spot and reject it.
---
 xen/arch/arm/include/asm/domain.h | 2 +-
 xen/arch/arm/traps.c              | 3 ++-
 xen/arch/x86/include/asm/domain.h | 2 +-
 xen/arch/x86/x86_64/traps.c       | 4 ++--
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/xen/arch/arm/include/asm/domain.h 
b/xen/arch/arm/include/asm/domain.h
index f1d72c6e48df..50b6a4b00982 100644
--- a/xen/arch/arm/include/asm/domain.h
+++ b/xen/arch/arm/include/asm/domain.h
@@ -243,7 +243,7 @@ struct arch_vcpu
 
 }  __cacheline_aligned;
 
-void vcpu_show_registers(const struct vcpu *v);
+void vcpu_show_registers(struct vcpu *v);
 void vcpu_switch_to_aarch64_mode(struct vcpu *v);
 
 /*
diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
index 737f4d65e324..665b17813acb 100644
--- a/xen/arch/arm/traps.c
+++ b/xen/arch/arm/traps.c
@@ -969,9 +969,10 @@ void show_registers(const struct cpu_user_regs *regs)
     _show_registers(regs, &ctxt, guest_mode(regs), current);
 }
 
-void vcpu_show_registers(const struct vcpu *v)
+void vcpu_show_registers(struct vcpu *v)
 {
     struct reg_ctxt ctxt;
+
     ctxt.sctlr_el1 = v->arch.sctlr;
     ctxt.tcr_el1 = v->arch.ttbcr;
     ctxt.ttbr0_el1 = v->arch.ttbr0;
diff --git a/xen/arch/x86/include/asm/domain.h 
b/xen/arch/x86/include/asm/domain.h
index b79d6badd71c..5fc1d1e5d01a 100644
--- a/xen/arch/x86/include/asm/domain.h
+++ b/xen/arch/x86/include/asm/domain.h
@@ -688,7 +688,7 @@ bool update_secondary_system_time(struct vcpu *v,
 void force_update_secondary_system_time(struct vcpu *v,
                                         struct vcpu_time_info *map);
 
-void vcpu_show_registers(const struct vcpu *v);
+void vcpu_show_registers(struct vcpu *v);
 
 static inline struct vcpu_guest_context *alloc_vcpu_guest_context(void)
 {
diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c
index 02fdb3637d09..22d4db240b95 100644
--- a/xen/arch/x86/x86_64/traps.c
+++ b/xen/arch/x86/x86_64/traps.c
@@ -170,7 +170,7 @@ void show_registers(const struct cpu_user_regs *regs)
     }
 }
 
-void vcpu_show_registers(const struct vcpu *v)
+void vcpu_show_registers(struct vcpu *v)
 {
     const struct cpu_user_regs *regs = &v->arch.user_regs;
     struct cpu_user_regs aux_regs;
@@ -180,7 +180,7 @@ void vcpu_show_registers(const struct vcpu *v)
     if ( is_hvm_vcpu(v) )
     {
         aux_regs = *regs;
-        get_hvm_registers(v->domain->vcpu[v->vcpu_id], &aux_regs, crs);
+        get_hvm_registers(v, &aux_regs, crs);
         regs = &aux_regs;
         context = CTXT_hvm_guest;
     }
-- 
2.39.5




 


Rackspace

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