]> xenbits.xensource.com Git - people/tklengyel/xen.git/commitdiff
x86: rework hypercall argument count table instantiation & use
authorJan Beulich <jbeulich@suse.com>
Thu, 18 Aug 2022 07:30:41 +0000 (09:30 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 18 Aug 2022 07:30:41 +0000 (09:30 +0200)
The initial observation were duplicate symbols that our checking warns
about. Instead of merely renaming one or both pair(s) of symbols,
reduce #ifdef-ary at the same time by moving the instantiation of the
arrays into a macro. While doing the conversion also stop open-coding
array_access_nospec().

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
xen/arch/x86/hvm/hypercall.c
xen/arch/x86/include/asm/hypercall.h
xen/arch/x86/pv/hypercall.c

index 29d1ca7a13069c7e164b945c85b91f76ed2b48a5..405d0a95afd8ef77d298f3d4dd261ba3cd3f7920 100644 (file)
@@ -111,11 +111,6 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return compat_physdev_op(cmd, arg);
 }
 
-#ifndef NDEBUG
-static const unsigned char hypercall_args_64[] = hypercall_args_hvm64;
-static const unsigned char hypercall_args_32[] = hypercall_args_hvm32;
-#endif
-
 int hvm_hypercall(struct cpu_user_regs *regs)
 {
     struct vcpu *curr = current;
@@ -177,7 +172,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)
                             regs->r10, regs->r8);
 
         if ( !curr->hcall_preempted && regs->rax != -ENOSYS )
-            clobber_regs(regs, get_nargs(hypercall_args_64, eax));
+            clobber_regs(regs, eax, hvm, 64);
     }
     else
     {
@@ -190,7 +185,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)
         curr->hcall_compat = false;
 
         if ( !curr->hcall_preempted && regs->eax != -ENOSYS )
-            clobber_regs32(regs, get_nargs(hypercall_args_32, eax));
+            clobber_regs(regs, eax, hvm, 32);
     }
 
     hvmemul_cache_restore(curr, token);
index ab8bd12e60a33edfb8874d43a44ad3b45305aeef..ec2edc771e9ddc5357cfd93dfe21728c85e6efa4 100644 (file)
@@ -43,18 +43,8 @@ compat_common_vcpu_op(
 
 #endif /* CONFIG_COMPAT */
 
-#ifndef NDEBUG
-static inline unsigned int _get_nargs(const unsigned char *tbl, unsigned int c)
-{
-    return tbl[c];
-}
-#define get_nargs(t, c) _get_nargs(t, array_index_nospec(c, ARRAY_SIZE(t)))
-#else
-#define get_nargs(tbl, c) 0
-#endif
-
-static inline void clobber_regs(struct cpu_user_regs *regs,
-                                unsigned int nargs)
+static inline void clobber_regs64(struct cpu_user_regs *regs,
+                                  unsigned int nargs)
 {
 #ifndef NDEBUG
     /* Deliberately corrupt used parameter regs. */
@@ -85,4 +75,9 @@ static inline void clobber_regs32(struct cpu_user_regs *regs,
 #endif
 }
 
+#define clobber_regs(r, n, t, b) ({ \
+    static const unsigned char t ## b[] = hypercall_args_ ## t ## b; \
+    clobber_regs ## b(r, array_access_nospec(t ## b, n)); \
+})
+
 #endif /* __ASM_X86_HYPERCALL_H__ */
index bf64bb41bb0e185eb4a21c0debda2fbdda5590ea..2eedfbfae86417a48a682b3cc201ec0d8bfc478e 100644 (file)
 #include <asm/multicall.h>
 #include <irq_vectors.h>
 
-#ifndef NDEBUG
-static const unsigned char hypercall_args_64[] = hypercall_args_pv64;
-#ifdef CONFIG_PV32
-static const unsigned char hypercall_args_32[] = hypercall_args_pv32;
-#endif
-#endif
-
 /* Forced inline to cause 'compat' to be evaluated at compile time. */
 static void always_inline
 _pv_hypercall(struct cpu_user_regs *regs, bool compat)
@@ -65,7 +58,7 @@ _pv_hypercall(struct cpu_user_regs *regs, bool compat)
         call_handlers_pv64(eax, regs->rax, rdi, rsi, rdx, r10, r8);
 
         if ( !curr->hcall_preempted && regs->rax != -ENOSYS )
-            clobber_regs(regs, get_nargs(hypercall_args_64, eax));
+            clobber_regs(regs, eax, pv, 64);
     }
 #ifdef CONFIG_PV32
     else
@@ -90,7 +83,7 @@ _pv_hypercall(struct cpu_user_regs *regs, bool compat)
         curr->hcall_compat = false;
 
         if ( !curr->hcall_preempted && regs->eax != -ENOSYS )
-            clobber_regs32(regs, get_nargs(hypercall_args_32, eax));
+            clobber_regs(regs, eax, pv, 32);
     }
 #endif /* CONFIG_PV32 */