]> xenbits.xensource.com Git - xen.git/commitdiff
xen/tasklet: Fix return value truncation on arm64
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 11 Apr 2019 12:54:36 +0000 (13:54 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 27 Dec 2019 17:18:57 +0000 (17:18 +0000)
The use of return_reg() assumes ARM's 32bit ABI.  Therefore, a failure such as
-EINVAL will appear as a large positive number near 4 billion to a 64bit ARM
guest which happens to use continue_hypercall_on_cpu().

Introduce a new arch_hypercall_tasklet_result() hook which is implemented by
both architectures, and drop the return_reg() macros.  This logic will be
extended in a later change to make continuations out of the tasklet work.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Julien Grall <julien@xen.org>
xen/arch/arm/traps.c
xen/arch/x86/hypercall.c
xen/common/domain.c
xen/include/asm-arm/regs.h
xen/include/asm-x86/regs.h
xen/include/xen/domain.h

index d028ec9224e4446b31eda688dfbe3df23d17753b..a20474f87c3a3e61997a936e2687fbb8d38662eb 100644 (file)
@@ -1485,6 +1485,13 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,
         regs->pc -= 4;  /* re-execute 'hvc #XEN_HYPERCALL_TAG' */
 }
 
+void arch_hypercall_tasklet_result(struct vcpu *v, long res)
+{
+    struct cpu_user_regs *regs = &v->arch.cpu_info->guest_cpu_user_regs;
+
+    HYPERCALL_RESULT_REG(regs) = res;
+}
+
 static bool check_multicall_32bit_clean(struct multicall_entry *multi)
 {
     int i;
index 1d42702c6a686825f0a6189da907d878b2bf2c7f..7f299d45c6b5c28bdffe4280c3343be1831574dd 100644 (file)
@@ -166,6 +166,13 @@ unsigned long hypercall_create_continuation(
 
 #undef NEXT_ARG
 
+void arch_hypercall_tasklet_result(struct vcpu *v, long res)
+{
+    struct cpu_user_regs *regs = &v->arch.user_regs;
+
+    regs->rax = res;
+}
+
 int hypercall_xlat_continuation(unsigned int *id, unsigned int nr,
                                 unsigned int mask, ...)
 {
index 611116c7fcafb70f87e850b098d06e494dded7f5..ccf689fcbebae6d7a0774e73491b7ebdcb6deb96 100644 (file)
@@ -1665,13 +1665,18 @@ static void continue_hypercall_tasklet_handler(unsigned long _info)
 {
     struct migrate_info *info = (struct migrate_info *)_info;
     struct vcpu *v = info->vcpu;
+    long res = -EINVAL;
 
     /* Wait for vcpu to sleep so that we can access its register state. */
     vcpu_sleep_sync(v);
 
     this_cpu(continue_info) = info;
-    return_reg(v) = (info->cpu == smp_processor_id())
-        ? info->func(info->data) : -EINVAL;
+
+    if ( likely(info->cpu == smp_processor_id()) )
+        res = info->func(info->data);
+
+    arch_hypercall_tasklet_result(v, res);
+
     this_cpu(continue_info) = NULL;
 
     if ( info->nest-- == 0 )
index 0e3e56b452d4231ff77edcdb8009a6dfbd252dcf..ec091a28a2f658484608e747c7f8ab6f3c938f66 100644 (file)
@@ -57,8 +57,6 @@ static inline bool guest_mode(const struct cpu_user_regs *r)
     return (diff == 0);
 }
 
-#define return_reg(v) ((v)->arch.cpu_info->guest_cpu_user_regs.r0)
-
 register_t get_user_reg(struct cpu_user_regs *regs, int reg);
 void set_user_reg(struct cpu_user_regs *regs, int reg, register_t val);
 
index 725a664e0aa38eb9d14e1e3982e791119fa9669b..dc00b854e30b5c094273122cdd141ce9810e793f 100644 (file)
@@ -15,6 +15,4 @@
     (diff == 0);                                                              \
 })
 
-#define return_reg(v) ((v)->arch.user_regs.rax)
-
 #endif /* __X86_REGS_H__ */
index 769302057b4a93b3565855a14548a8e9d08ea6a0..1cb205d977f7cf6fb97eac728c3f0a5b8684b537 100644 (file)
@@ -103,6 +103,12 @@ void domctl_lock_release(void);
 int continue_hypercall_on_cpu(
     unsigned int cpu, long (*func)(void *data), void *data);
 
+/*
+ * Companion to continue_hypercall_on_cpu(), to feed func()'s result back into
+ * vcpu regsiter state.
+ */
+void arch_hypercall_tasklet_result(struct vcpu *v, long res);
+
 extern unsigned int xen_processor_pmbits;
 
 extern bool_t opt_dom0_vcpus_pin;