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

[PATCH] x86: rework hypercall argument count table instantiation & use


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 27 Jul 2022 18:00:09 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KiKQ2q0lgHbyBHN7HUm074QjCFaoPiIZWv42M+fpFog=; b=QoYBePyMYhPnwVzGZEUWusbfRO5RjDcKGDLXPMU/pT1VX64QfR7OcSU4fK/zExxHD3svMzBfFBz0E1sSidWttxSmcSCTqUFre0VB7CrYFhQJVuuoteJLbMAndAxhtZDbmi2HjrTnSzlpJzuVTGdKp/zLY4IclVYwlWp47taYv7LvEs9+7oyA6dWVOUrLV9iHyVYH/14lZ8PSQ9hNxIQ+3qxPMXTznFyRB+6qqyT9rD16S9dVyMmQfV4h7HzEvaMosiFLfhxfaNN2oedywpWJ8OD2wWRvAXE16dapJZHmXAKqM2qbdZUsGR3KPDoSX/V9viK6qNNDBsXOk/2mH3tY0w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d0fvM9kHDGc1X4J1iLxhgJNIL7jV9+I3F47+m6SWR0/TXr564JScnCjr+6nJXzkZ578gedbdF67kqD1RGHiL90u2DQEW5KMunvANIR6diDzqnlUWMa2ghHQMAt8Vn9DFOsVw4TcSHtiI0Ux8IzFGG4O6JlujMPYawHWePnobxlEDJ+kTeWfwxLFuBmTawEbHnE+RjH3JFeGbVD+FTGH/2Solq27nRI12rm4tvDw9mvShc6yWcMVSwOvR2dHle/KlkkG5h+xlAJ4nbtvDc5fj6ns4MI5VnCdb7z3eLvTRX36Sk3r9o1VcDkUjPPQLtbgIvAFwwT/BcIPFgBLctqZsLA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Wed, 27 Jul 2022 16:00:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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 macros (a native and a 32-bit one each, where likely more
redundancy could be eliminated, if we really wanted to). While doing the
conversion also stop open-coding array_access_nospec().

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
A tentative variant with yet less redundancy (only a single macro
needed) would be

#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)); \
})

with invocations then being e.g.

    clobber_regs(regs, eax, hvm, 64);

and with the clobber_regs() inline function renamed to clobber_regs64().

--- a/xen/arch/x86/hvm/hypercall.c
+++ b/xen/arch/x86/hvm/hypercall.c
@@ -111,11 +111,6 @@ long hvm_physdev_op(int cmd, XEN_GUEST_H
         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->r10, regs->r8);
 
         if ( !curr->hcall_preempted && regs->rax != -ENOSYS )
-            clobber_regs(regs, get_nargs(hypercall_args_64, eax));
+            clobber_regs(regs, eax, hvm64);
     }
     else
     {
@@ -190,7 +185,7 @@ int hvm_hypercall(struct cpu_user_regs *
         curr->hcall_compat = false;
 
         if ( !curr->hcall_preempted && regs->eax != -ENOSYS )
-            clobber_regs32(regs, get_nargs(hypercall_args_32, eax));
+            clobber_regs32(regs, eax, hvm32);
     }
 
     hvmemul_cache_restore(curr, token);
--- a/xen/arch/x86/include/asm/hypercall.h
+++ b/xen/arch/x86/include/asm/hypercall.h
@@ -43,16 +43,6 @@ 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)
 {
@@ -69,6 +59,11 @@ static inline void clobber_regs(struct c
 #endif
 }
 
+#define clobber_regs(r, n, t) ({ \
+    static const unsigned char t[] = hypercall_args_ ## t; \
+    clobber_regs(r, array_access_nospec(t, n)); \
+})
+
 static inline void clobber_regs32(struct cpu_user_regs *regs,
                                   unsigned int nargs)
 {
@@ -85,4 +80,9 @@ static inline void clobber_regs32(struct
 #endif
 }
 
+#define clobber_regs32(r, n, t) ({ \
+    static const unsigned char t[] = hypercall_args_ ## t; \
+    clobber_regs32(r, array_access_nospec(t, n)); \
+})
+
 #endif /* __ASM_X86_HYPERCALL_H__ */
--- a/xen/arch/x86/pv/hypercall.c
+++ b/xen/arch/x86/pv/hypercall.c
@@ -27,13 +27,6 @@
 #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
         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, pv64);
     }
 #ifdef CONFIG_PV32
     else
@@ -90,7 +83,7 @@ _pv_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_regs32(regs, eax, pv32);
     }
 #endif /* CONFIG_PV32 */
 



 


Rackspace

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