Skip to contentSkip to conversation

xen: drop hypercall function tables

PATCH In review Juergen Gross 6 participants 34 messages Mar 24, 2022 – Jul 11, 2022

lore
Share & tools
lore
#0 lore raw

v6 cover xen: drop hypercall function tables

In order to avoid indirect function calls on the hypercall path as much as possible this series is removing the hypercall function tables and is replacing the hypercall handler calls via the function array by automatically generated call macros.

Another by-product of generating the call macros is the automatic generating of the hypercall handler prototypes from the same data base which is used to generate the macros.

This has the additional advantage of using type safe calls of the handlers and to ensure related handler (e.g. PV and HVM ones) share the same prototypes.

A very brief performance test (parallel build of the Xen hypervisor in a 6 vcpu guest) showed a very slim improvement (less than 1%) of the performance with the patches applied. The test was performed using a PV and a PVH guest.

Changes in V2:
- new patches 6, 14, 15
- patch 7: support hypercall priorities for faster code
- comments addressed

Changes in V3:
- patches 1 and 4 removed as already applied
- comments addressed

Changes in V4:
- 5 patches removed al already applied
- new patches 1, 3 and 11
- avoid switching Arm hypercall handlers to return long (no change of handlers returning long already)

Changes in V5:
- patch 3 of V4 has been applied already
- comments addressed
- rebase

Changes in V6:
- patch 1 of V5 has been applied already
- fix of a rebase artifact

Juergen Gross (9):
xen: move do_vcpu_op() to arch specific code
xen: harmonize return types of hypercall handlers
xen: don't include asm/hypercall.h from C sources
xen: include compat/platform.h from hypercall.h
xen: generate hypercall interface related code
xen: use generated prototypes for hypercall handlers xen/x86: call hypercall handlers via generated macro xen/arm: call hypercall handlers via generated macro xen/x86: remove cf_check attribute from hypercall handlers

 .gitignore                               |   1 +
 xen/arch/arm/domain.c                    |  15 +-
 xen/arch/arm/hvm.c                       |   3 +-
 xen/arch/arm/include/asm/hypercall.h     |   7 +-
 xen/arch/arm/platform_hypercall.c        |   1 +
 xen/arch/arm/traps.c                     | 117 ++-------
 xen/arch/x86/compat.c                    |   6 +-
 xen/arch/x86/cpu/mcheck/mce.c            |   2 +-
 xen/arch/x86/cpu/vpmu.c                  |   3 +-
 xen/arch/x86/domain.c                    |  11 +-
 xen/arch/x86/domctl.c                    |   4 +-
 xen/arch/x86/hvm/dm.c                    |   2 +-
 xen/arch/x86/hvm/hvm.c                   |   2 +-
 xen/arch/x86/hvm/hypercall.c             | 177 ++-----------
 xen/arch/x86/hypercall.c                 |  59 -----
 xen/arch/x86/include/asm/hypercall.h     | 201 ++++-----------
 xen/arch/x86/include/asm/paging.h        |   3 -
 xen/arch/x86/mm.c                        |  13 +-
 xen/arch/x86/mm/paging.c                 |   3 +-
 xen/arch/x86/physdev.c                   |   2 +-
 xen/arch/x86/platform_hypercall.c        |   3 +-
 xen/arch/x86/pv/callback.c               |  26 +-
 xen/arch/x86/pv/descriptor-tables.c      |   8 +-
 xen/arch/x86/pv/emul-priv-op.c           |   2 +-
 xen/arch/x86/pv/hypercall.c              | 187 ++------------
 xen/arch/x86/pv/iret.c                   |   5 +-
 xen/arch/x86/pv/misc-hypercalls.c        |  22 +-
 xen/arch/x86/pv/shim.c                   |   4 +-
 xen/arch/x86/traps.c                     |   2 +-
 xen/arch/x86/x86_64/compat/mm.c          |   3 +-
 xen/arch/x86/x86_64/domain.c             |  16 +-
 xen/arch/x86/x86_64/mm.c                 |   2 -
 xen/arch/x86/x86_64/platform_hypercall.c |   1 -
 xen/common/argo.c                        |   8 +-
 xen/common/compat/domain.c               |  15 +-
 xen/common/compat/grant_table.c          |   3 +-
 xen/common/compat/kernel.c               |   2 +-
 xen/common/compat/memory.c               |   3 +-
 xen/common/dm.c                          |   2 +-
 xen/common/domain.c                      |  14 +-
 xen/common/domctl.c                      |   2 +-
 xen/common/event_channel.c               |   3 +-
 xen/common/grant_table.c                 |   4 +-
 xen/common/hypfs.c                       |   2 +-
 xen/common/kernel.c                      |   2 +-
 xen/common/kexec.c                       |   6 +-
 xen/common/memory.c                      |   2 +-
 xen/common/multicall.c                   |   4 +-
 xen/common/sched/compat.c                |   2 +-
 xen/common/sched/core.c                  |   4 +-
 xen/common/sysctl.c                      |   2 +-
 xen/common/xenoprof.c                    |   2 +-
 xen/drivers/char/console.c               |   2 +-
 xen/include/Makefile                     |  13 +
 xen/include/hypercall-defs.c             | 285 ++++++++++++++++++++
 xen/include/xen/hypercall.h              | 185 +------------
 xen/scripts/gen_hypercall.awk            | 314 +++++++++++++++++++++++
 xen/xsm/xsm_core.c                       |   4 +-
 58 files changed, 861 insertions(+), 937 deletions(-)
 create mode 100644 xen/include/hypercall-defs.c
 create mode 100644 xen/scripts/gen_hypercall.awk
Signature · 1 line
2.34.1
#1 lore raw

PATCH v6 1/9 xen: move do_vcpu_op() to arch specific code

The entry point used for the vcpu_op hypercall on Arm is different from the one on x86 today, as some of the common sub-ops are not supported on Arm. The Arm specific handler filters out the not supported sub-ops and then calls the common handler. This leads to the weird call hierarchy:

do_arm_vcpu_op()

    do_vcpu_op()
      arch_do_vcpu_op()

Clean this up by renaming do_vcpu_op() to common_vcpu_op() and arch_do_vcpu_op() in each architecture to do_vcpu_op(). This way one of above calls can be avoided without restricting any potential future use of common sub-ops for Arm.

---
V4:
- don't remove HYPERCALL_ARM()
V4.1:
- add missing cf_check (Andrew Cooper)
V5:
- use v instead of current (Julien Grall)

---
 xen/arch/arm/domain.c                | 15 ++++++++-------
 xen/arch/arm/include/asm/hypercall.h |  2 --
 xen/arch/arm/traps.c                 |  2 +-
 xen/arch/x86/domain.c                | 12 ++++++++----
 xen/arch/x86/include/asm/hypercall.h |  2 +-
 xen/arch/x86/x86_64/domain.c         | 18 +++++++++++++-----
 xen/common/compat/domain.c           | 15 ++++++---------
 xen/common/domain.c                  | 12 ++++--------
 xen/include/xen/hypercall.h          |  2 +-
 9 files changed, 42 insertions(+), 38 deletions(-)
xen/arch/arm/domain.c +8 -7
index 8110c1df86..2f8eaab7b5 100644
@@ -1079,23 +1079,24 @@ void arch_dump_domain_info(struct domain *d)
 }
 
 
-long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
+long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
+    struct domain *d = current->domain;
+    struct vcpu *v;
+
+    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
+        return -ENOENT;
+
     switch ( cmd )
     {
         case VCPUOP_register_vcpu_info:
         case VCPUOP_register_runstate_memory_area:
-            return do_vcpu_op(cmd, vcpuid, arg);
+            return common_vcpu_op(cmd, v, arg);
         default:
             return -EINVAL;
     }
 }
 
-long arch_do_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
-{
-    return -ENOSYS;
-}
-
 void arch_dump_vcpu_info(struct vcpu *v)
 {
     gic_dump_info(v);
xen/arch/arm/include/asm/hypercall.h +0 -2
index 39d2e7889d..fac4d60f17 100644
@@ -4,8 +4,6 @@
 #include <public/domctl.h> /* for arch_do_domctl */
 int do_arm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg);
-
 long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
                        XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
 
xen/arch/arm/traps.c +1 -1
index 43f30747cf..e906bb4a89 100644
@@ -1380,7 +1380,7 @@ static arm_hypercall_t arm_hypercall_table[] = {
 #endif
     HYPERCALL(multicall, 2),
     HYPERCALL(platform_op, 1),
-    HYPERCALL_ARM(vcpu_op, 3),
+    HYPERCALL(vcpu_op, 3),
     HYPERCALL(vm_assist, 2),
 #ifdef CONFIG_ARGO
     HYPERCALL(argo_op, 5),
xen/arch/x86/domain.c +8 -4
index a5048ed654..d566fc82b4 100644
@@ -1489,11 +1489,15 @@ int arch_vcpu_reset(struct vcpu *v)
     return 0;
 }
 
-long
-arch_do_vcpu_op(
-    int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
+long cf_check do_vcpu_op(int cmd, unsigned int vcpuid,
+                         XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     long rc = 0;
+    struct domain *d = current->domain;
+    struct vcpu *v;
+
+    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
+        return -ENOENT;
 
     switch ( cmd )
     {
@@ -1545,7 +1549,7 @@ arch_do_vcpu_op(
     }
 
     default:
-        rc = -ENOSYS;
+        rc = common_vcpu_op(cmd, v, arg);
         break;
     }
 
xen/arch/x86/include/asm/hypercall.h +1 -1
index 61bf897147..d6daa7e4cb 100644
@@ -145,7 +145,7 @@ compat_physdev_op(
     XEN_GUEST_HANDLE_PARAM(void) arg);
 
 extern int
-arch_compat_vcpu_op(
+compat_common_vcpu_op(
     int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg);
 
 extern int cf_check compat_mmuext_op(
xen/arch/x86/x86_64/domain.c +13 -5
index c46dccc25a..9c559aa3ea 100644
@@ -12,11 +12,15 @@
 CHECK_vcpu_get_physid;
 #undef xen_vcpu_get_physid
 
-int
-arch_compat_vcpu_op(
-    int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
+int cf_check
+compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
-    int rc = -ENOSYS;
+    int rc;
+    struct domain *d = current->domain;
+    struct vcpu *v;
+
+    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
+        return -ENOENT;
 
     switch ( cmd )
     {
@@ -55,7 +59,11 @@ arch_compat_vcpu_op(
     }
 
     case VCPUOP_get_physid:
-        rc = arch_do_vcpu_op(cmd, v, arg);
+        rc = do_vcpu_op(cmd, vcpuid, arg);
+        break;
+
+    default:
+        rc = compat_common_vcpu_op(cmd, v, arg);
         break;
     }
 
xen/common/compat/domain.c +6 -9
index afae27eeba..1119534679 100644
@@ -38,15 +38,12 @@ CHECK_vcpu_hvm_context;
 
 #endif
 
-int cf_check compat_vcpu_op(
-    int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
+int compat_common_vcpu_op(int cmd, struct vcpu *v,
+                          XEN_GUEST_HANDLE_PARAM(void) arg)
 {
-    struct domain *d = current->domain;
-    struct vcpu *v;
     int rc = 0;
-
-    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
-        return -ENOENT;
+    struct domain *d = current->domain;
+    unsigned int vcpuid = v->vcpu_id;
 
     switch ( cmd )
     {
@@ -103,7 +100,7 @@ int cf_check compat_vcpu_op(
     case VCPUOP_stop_singleshot_timer:
     case VCPUOP_register_vcpu_info:
     case VCPUOP_send_nmi:
-        rc = do_vcpu_op(cmd, vcpuid, arg);
+        rc = common_vcpu_op(cmd, v, arg);
         break;
 
     case VCPUOP_get_runstate_info:
@@ -134,7 +131,7 @@ int cf_check compat_vcpu_op(
     }
 
     default:
-        rc = arch_compat_vcpu_op(cmd, v, arg);
+        rc = -ENOSYS;
         break;
     }
 
xen/common/domain.c +4 -8
index 351029f8b2..70747c02e6 100644
@@ -1570,15 +1570,11 @@ int default_initialise_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
     return rc;
 }
 
-long cf_check do_vcpu_op(
-    int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
+long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
-    struct domain *d = current->domain;
-    struct vcpu *v;
     long rc = 0;
-
-    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
-        return -ENOENT;
+    struct domain *d = v->domain;
+    unsigned int vcpuid = v->vcpu_id;
 
     switch ( cmd )
     {
@@ -1750,7 +1746,7 @@ long cf_check do_vcpu_op(
     }
 
     default:
-        rc = arch_do_vcpu_op(cmd, v, arg);
+        rc = -ENOSYS;
         break;
     }
 
xen/include/xen/hypercall.h +1 -1
index a1b6575976..81aae7a662 100644
@@ -110,7 +110,7 @@ do_vcpu_op(
 
 struct vcpu;
 extern long
-arch_do_vcpu_op(int cmd,
+common_vcpu_op(int cmd,
     struct vcpu *v,
     XEN_GUEST_HANDLE_PARAM(void) arg);
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v6 1/9] xen: move do_vcpu_op() to arch specific code

Quoted 10 lines · Juergen Gross

The entry point used for the vcpu_op hypercall on Arm is different from the one on x86 today, as some of the common sub-ops are not supported on Arm. The Arm specific handler filters out the not supported sub-ops and then calls the common handler. This leads to the weird call hierarchy:

   do_arm_vcpu_op()
     do_vcpu_op()
       arch_do_vcpu_op()
Quoted 7 lines

Clean this up by renaming do_vcpu_op() to common_vcpu_op() and arch_do_vcpu_op() in each architecture to do_vcpu_op(). This way one of above calls can be avoided without restricting any potential future use of common sub-ops for Arm.

There is still an Ack missing for x86 side. Jan already said he isn't happy to give one, but won't Nack it. Roger, Andrew, any comments for this patch? It is blocking further cleanup patches to go in (patches 2 and 4 of this series).

Juergen

Quoted 250 lines

---
V4:
- don't remove HYPERCALL_ARM()
V4.1:
- add missing cf_check (Andrew Cooper)
V5:
- use v instead of current (Julien Grall)

---
  xen/arch/arm/domain.c                | 15 ++++++++-------
  xen/arch/arm/include/asm/hypercall.h |  2 --
  xen/arch/arm/traps.c                 |  2 +-
  xen/arch/x86/domain.c                | 12 ++++++++----
  xen/arch/x86/include/asm/hypercall.h |  2 +-
  xen/arch/x86/x86_64/domain.c         | 18 +++++++++++++-----
  xen/common/compat/domain.c           | 15 ++++++---------
  xen/common/domain.c                  | 12 ++++--------
  xen/include/xen/hypercall.h          |  2 +-
  9 files changed, 42 insertions(+), 38 deletions(-)
xen/arch/arm/domain.c +8 -7
index 8110c1df86..2f8eaab7b5 100644
@@ -1079,23 +1079,24 @@ void arch_dump_domain_info(struct domain *d)
  }
 
 
-long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
+long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
  {
+    struct domain *d = current->domain;
+    struct vcpu *v;
+
+    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
+        return -ENOENT;
+
      switch ( cmd )
      {
          case VCPUOP_register_vcpu_info:
          case VCPUOP_register_runstate_memory_area:
-            return do_vcpu_op(cmd, vcpuid, arg);
+            return common_vcpu_op(cmd, v, arg);
          default:
              return -EINVAL;
      }
  }
 
-long arch_do_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
-{
-    return -ENOSYS;
-}
-
  void arch_dump_vcpu_info(struct vcpu *v)
  {
      gic_dump_info(v);
xen/arch/arm/include/asm/hypercall.h +0 -2
index 39d2e7889d..fac4d60f17 100644
@@ -4,8 +4,6 @@
  #include <public/domctl.h> /* for arch_do_domctl */
  int do_arm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg);
-
  long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
                         XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
 
xen/arch/arm/traps.c +1 -1
index 43f30747cf..e906bb4a89 100644
@@ -1380,7 +1380,7 @@ static arm_hypercall_t arm_hypercall_table[] = {
  #endif
      HYPERCALL(multicall, 2),
      HYPERCALL(platform_op, 1),
-    HYPERCALL_ARM(vcpu_op, 3),
+    HYPERCALL(vcpu_op, 3),
      HYPERCALL(vm_assist, 2),
  #ifdef CONFIG_ARGO
      HYPERCALL(argo_op, 5),
xen/arch/x86/domain.c +8 -4
index a5048ed654..d566fc82b4 100644
@@ -1489,11 +1489,15 @@ int arch_vcpu_reset(struct vcpu *v)
      return 0;
  }
 
-long
-arch_do_vcpu_op(
-    int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
+long cf_check do_vcpu_op(int cmd, unsigned int vcpuid,
+                         XEN_GUEST_HANDLE_PARAM(void) arg)
  {
      long rc = 0;
+    struct domain *d = current->domain;
+    struct vcpu *v;
+
+    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
+        return -ENOENT;
 
      switch ( cmd )
      {
@@ -1545,7 +1549,7 @@ arch_do_vcpu_op(
      }
 
      default:
-        rc = -ENOSYS;
+        rc = common_vcpu_op(cmd, v, arg);
          break;
      }
 
xen/arch/x86/include/asm/hypercall.h +1 -1
index 61bf897147..d6daa7e4cb 100644
@@ -145,7 +145,7 @@ compat_physdev_op(
      XEN_GUEST_HANDLE_PARAM(void) arg);
 
  extern int
-arch_compat_vcpu_op(
+compat_common_vcpu_op(
      int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg);
 
  extern int cf_check compat_mmuext_op(
xen/arch/x86/x86_64/domain.c +13 -5
index c46dccc25a..9c559aa3ea 100644
@@ -12,11 +12,15 @@
  CHECK_vcpu_get_physid;
  #undef xen_vcpu_get_physid
 
-int
-arch_compat_vcpu_op(
-    int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
+int cf_check
+compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
  {
-    int rc = -ENOSYS;
+    int rc;
+    struct domain *d = current->domain;
+    struct vcpu *v;
+
+    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
+        return -ENOENT;
 
      switch ( cmd )
      {
@@ -55,7 +59,11 @@ arch_compat_vcpu_op(
      }
 
      case VCPUOP_get_physid:
-        rc = arch_do_vcpu_op(cmd, v, arg);
+        rc = do_vcpu_op(cmd, vcpuid, arg);
+        break;
+
+    default:
+        rc = compat_common_vcpu_op(cmd, v, arg);
          break;
      }
 
xen/common/compat/domain.c +6 -9
index afae27eeba..1119534679 100644
@@ -38,15 +38,12 @@ CHECK_vcpu_hvm_context;
 
  #endif
 
-int cf_check compat_vcpu_op(
-    int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
+int compat_common_vcpu_op(int cmd, struct vcpu *v,
+                          XEN_GUEST_HANDLE_PARAM(void) arg)
  {
-    struct domain *d = current->domain;
-    struct vcpu *v;
      int rc = 0;
-
-    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
-        return -ENOENT;
+    struct domain *d = current->domain;
+    unsigned int vcpuid = v->vcpu_id;
 
      switch ( cmd )
      {
@@ -103,7 +100,7 @@ int cf_check compat_vcpu_op(
      case VCPUOP_stop_singleshot_timer:
      case VCPUOP_register_vcpu_info:
      case VCPUOP_send_nmi:
-        rc = do_vcpu_op(cmd, vcpuid, arg);
+        rc = common_vcpu_op(cmd, v, arg);
          break;
 
      case VCPUOP_get_runstate_info:
@@ -134,7 +131,7 @@ int cf_check compat_vcpu_op(
      }
 
      default:
-        rc = arch_compat_vcpu_op(cmd, v, arg);
+        rc = -ENOSYS;
          break;
      }
 
xen/common/domain.c +4 -8
index 351029f8b2..70747c02e6 100644
@@ -1570,15 +1570,11 @@ int default_initialise_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
      return rc;
  }
 
-long cf_check do_vcpu_op(
-    int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
+long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
  {
-    struct domain *d = current->domain;
-    struct vcpu *v;
      long rc = 0;
-
-    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
-        return -ENOENT;
+    struct domain *d = v->domain;
+    unsigned int vcpuid = v->vcpu_id;
 
      switch ( cmd )
      {
@@ -1750,7 +1746,7 @@ long cf_check do_vcpu_op(
      }
 
      default:
-        rc = arch_do_vcpu_op(cmd, v, arg);
+        rc = -ENOSYS;
          break;
      }
 
xen/include/xen/hypercall.h +1 -1
index a1b6575976..81aae7a662 100644
@@ -110,7 +110,7 @@ do_vcpu_op(
 
  struct vcpu;
  extern long
-arch_do_vcpu_op(int cmd,
+common_vcpu_op(int cmd,
      struct vcpu *v,
      XEN_GUEST_HANDLE_PARAM(void) arg);
 
#3 lore raw

Re: [PATCH v6 1/9] xen: move do_vcpu_op() to arch specific code

In reply to Juergen Gross
Quoted 6 lines · Juergen Gross

The entry point used for the vcpu_op hypercall on Arm is different from the one on x86 today, as some of the common sub-ops are not supported on Arm. The Arm specific handler filters out the not supported sub-ops and then calls the common handler. This leads to the weird call hierarchy:

Quoted 8 lines

do_arm_vcpu_op()

    do_vcpu_op()
      arch_do_vcpu_op()

Clean this up by renaming do_vcpu_op() to common_vcpu_op() and arch_do_vcpu_op() in each architecture to do_vcpu_op(). This way one of above calls can be avoided without restricting any potential future use of common sub-ops for Arm.

Wouldn't it be more natural to have do_vcpu_op() contain the common code (AFAICT handlers for VCPUOP_register_{vcpu_info,runstate_memory_area}) and then everything else handled by the x86 arch_do_vcpu_op() handler?

I find the common prefix misleading, as not all the VCPUOP hypercalls are available to all the architectures.

Thanks, Roger.

#4 lore raw

Re: [PATCH v6 1/9] xen: move do_vcpu_op() to arch specific code

Quoted 16 lines · Roger Pau Monné
Quoted 6 lines · Juergen Gross

The entry point used for the vcpu_op hypercall on Arm is different from the one on x86 today, as some of the common sub-ops are not supported on Arm. The Arm specific handler filters out the not supported sub-ops and then calls the common handler. This leads to the weird call hierarchy:

Quoted 8 lines
   do_arm_vcpu_op()
     do_vcpu_op()
       arch_do_vcpu_op()

Clean this up by renaming do_vcpu_op() to common_vcpu_op() and arch_do_vcpu_op() in each architecture to do_vcpu_op(). This way one of above calls can be avoided without restricting any potential future use of common sub-ops for Arm.

Quoted 7 lines

Wouldn't it be more natural to have do_vcpu_op() contain the common code (AFAICT handlers for VCPUOP_register_{vcpu_info,runstate_memory_area}) and then everything else handled by the x86 arch_do_vcpu_op() handler?

I find the common prefix misleading, as not all the VCPUOP hypercalls are available to all the architectures.

This would end up in Arm suddenly supporting the sub-ops it doesn't (want to) support today. Otherwise it would make no sense that Arm has a dedicated entry for this hypercall.

The "common" just wants to express that the code is common. I'm open for a better suggestion, though. :-)

Juergen

#5 lore raw

Re: [PATCH v6 1/9] xen: move do_vcpu_op() to arch specific code

Quoted 22 lines · Juergen Gross
Quoted 21 lines · Roger Pau Monné
Quoted 6 lines · Juergen Gross

The entry point used for the vcpu_op hypercall on Arm is different from the one on x86 today, as some of the common sub-ops are not supported on Arm. The Arm specific handler filters out the not supported sub-ops and then calls the common handler. This leads to the weird call hierarchy:

Quoted 8 lines
   do_arm_vcpu_op()
     do_vcpu_op()
       arch_do_vcpu_op()

Clean this up by renaming do_vcpu_op() to common_vcpu_op() and arch_do_vcpu_op() in each architecture to do_vcpu_op(). This way one of above calls can be avoided without restricting any potential future use of common sub-ops for Arm.

Wouldn't it be more natural to have do_vcpu_op() contain the common code (AFAICT handlers for VCPUOP_register_{vcpu_info,runstate_memory_area}) and then everything else handled by the x86 arch_do_vcpu_op() handler?

Quoted 6 lines
Quoted 2 lines

I find the common prefix misleading, as not all the VCPUOP hypercalls are available to all the architectures.

This would end up in Arm suddenly supporting the sub-ops it doesn't (want to) support today. Otherwise it would make no sense that Arm has a dedicated entry for this hypercall.

My preference would be for a common do_vcpu_op() that just contains handlers for VCPUOP_register_{vcpu_info,runstate_memory_area} and then an empty arch_ handler for Arm, and everything else moved to the x86 arch_ handler. That obviously implies some code churn, but results in a cleaner implementation IMO.

Also has the nice benefit of removing unreachable code from the Arm build, which is also a MISRA-C rule.

Quoted 2 lines

The "common" just wants to express that the code is common. I'm open for a better suggestion, though. :-)

Right, it lives in common/ anyway, so there's not a much better name.

Thanks, Roger.

#6 lore raw

Re: [PATCH v6 1/9] xen: move do_vcpu_op() to arch specific code

Quoted 30 lines · Roger Pau Monné
Quoted 22 lines · Juergen Gross
Quoted 21 lines · Roger Pau Monné
Quoted 6 lines · Juergen Gross

The entry point used for the vcpu_op hypercall on Arm is different from the one on x86 today, as some of the common sub-ops are not supported on Arm. The Arm specific handler filters out the not supported sub-ops and then calls the common handler. This leads to the weird call hierarchy:

Quoted 8 lines
    do_arm_vcpu_op()
      do_vcpu_op()
        arch_do_vcpu_op()

Clean this up by renaming do_vcpu_op() to common_vcpu_op() and arch_do_vcpu_op() in each architecture to do_vcpu_op(). This way one of above calls can be avoided without restricting any potential future use of common sub-ops for Arm.

Wouldn't it be more natural to have do_vcpu_op() contain the common code (AFAICT handlers for VCPUOP_register_{vcpu_info,runstate_memory_area}) and then everything else handled by the x86 arch_do_vcpu_op() handler?

Quoted 6 lines
Quoted 2 lines

I find the common prefix misleading, as not all the VCPUOP hypercalls are available to all the architectures.

This would end up in Arm suddenly supporting the sub-ops it doesn't (want to) support today. Otherwise it would make no sense that Arm has a dedicated entry for this hypercall.

Quoted 5 lines

My preference would be for a common do_vcpu_op() that just contains handlers for VCPUOP_register_{vcpu_info,runstate_memory_area} and then an empty arch_ handler for Arm, and everything else moved to the x86 arch_ handler. That obviously implies some code churn, but results in a cleaner implementation IMO.

I'd be fine with that.

I did it in V2 of the (then secret) series, and Jan replied:

I'm afraid I don't agree with this movement. I could see things getting moved that are purely PV (on the assumption that no new PV ports will appear), but anything that's also usable by PVH / HVM ought to be usable in principle also by Arm or other PV-free ports.

Juergen

#7 lore raw

Re: [PATCH v6 1/9] xen: move do_vcpu_op() to arch specific code

Quoted 37 lines · Juergen Gross
Quoted 30 lines · Roger Pau Monné
Quoted 22 lines · Juergen Gross
Quoted 21 lines · Roger Pau Monné
Quoted 6 lines · Juergen Gross

The entry point used for the vcpu_op hypercall on Arm is different from the one on x86 today, as some of the common sub-ops are not supported on Arm. The Arm specific handler filters out the not supported sub-ops and then calls the common handler. This leads to the weird call hierarchy:

Quoted 8 lines
    do_arm_vcpu_op()
      do_vcpu_op()
        arch_do_vcpu_op()

Clean this up by renaming do_vcpu_op() to common_vcpu_op() and arch_do_vcpu_op() in each architecture to do_vcpu_op(). This way one of above calls can be avoided without restricting any potential future use of common sub-ops for Arm.

Wouldn't it be more natural to have do_vcpu_op() contain the common code (AFAICT handlers for VCPUOP_register_{vcpu_info,runstate_memory_area}) and then everything else handled by the x86 arch_do_vcpu_op() handler?

Quoted 6 lines
Quoted 2 lines

I find the common prefix misleading, as not all the VCPUOP hypercalls are available to all the architectures.

This would end up in Arm suddenly supporting the sub-ops it doesn't (want to) support today. Otherwise it would make no sense that Arm has a dedicated entry for this hypercall.

Quoted 5 lines

My preference would be for a common do_vcpu_op() that just contains handlers for VCPUOP_register_{vcpu_info,runstate_memory_area} and then an empty arch_ handler for Arm, and everything else moved to the x86 arch_ handler. That obviously implies some code churn, but results in a cleaner implementation IMO.

Quoted 8 lines

I'd be fine with that.

I did it in V2 of the (then secret) series, and Jan replied:

I'm afraid I don't agree with this movement. I could see things getting moved that are purely PV (on the assumption that no new PV ports will appear), but anything that's also usable by PVH / HVM ought to be usable in principle also by Arm or other PV-free ports.

I see. My opinion is that when other ports need those functions they should be pulled out of arch code into common code, until then it just adds confusion to have them in common code.

I will take a look at the current patch, as we need to make progress on this.

Thanks, Roger.

#8 lore raw

Re: [PATCH v6 1/9] xen: move do_vcpu_op() to arch specific code

Quoted 47 lines · Roger Pau Monné
Quoted 37 lines · Juergen Gross
Quoted 30 lines · Roger Pau Monné
Quoted 22 lines · Juergen Gross
Quoted 21 lines · Roger Pau Monné
Quoted 6 lines · Juergen Gross

The entry point used for the vcpu_op hypercall on Arm is different from the one on x86 today, as some of the common sub-ops are not supported on Arm. The Arm specific handler filters out the not supported sub-ops and then calls the common handler. This leads to the weird call hierarchy:

Quoted 8 lines
     do_arm_vcpu_op()
       do_vcpu_op()
         arch_do_vcpu_op()

Clean this up by renaming do_vcpu_op() to common_vcpu_op() and arch_do_vcpu_op() in each architecture to do_vcpu_op(). This way one of above calls can be avoided without restricting any potential future use of common sub-ops for Arm.

Wouldn't it be more natural to have do_vcpu_op() contain the common code (AFAICT handlers for VCPUOP_register_{vcpu_info,runstate_memory_area}) and then everything else handled by the x86 arch_do_vcpu_op() handler?

Quoted 6 lines
Quoted 2 lines

I find the common prefix misleading, as not all the VCPUOP hypercalls are available to all the architectures.

This would end up in Arm suddenly supporting the sub-ops it doesn't (want to) support today. Otherwise it would make no sense that Arm has a dedicated entry for this hypercall.

Quoted 5 lines

My preference would be for a common do_vcpu_op() that just contains handlers for VCPUOP_register_{vcpu_info,runstate_memory_area} and then an empty arch_ handler for Arm, and everything else moved to the x86 arch_ handler. That obviously implies some code churn, but results in a cleaner implementation IMO.

Quoted 8 lines

I'd be fine with that.

I did it in V2 of the (then secret) series, and Jan replied:

I'm afraid I don't agree with this movement. I could see things getting moved that are purely PV (on the assumption that no new PV ports will appear), but anything that's also usable by PVH / HVM ought to be usable in principle also by Arm or other PV-free ports.

Quoted 6 lines

I see. My opinion is that when other ports need those functions they should be pulled out of arch code into common code, until then it just adds confusion to have them in common code.

I will take a look at the current patch, as we need to make progress on this.

Thanks for that.

Juergen

Acked-by on v6 1/9
#9 lore raw

Re: [PATCH v6 1/9] xen: move do_vcpu_op() to arch specific code

In reply to Juergen Gross
Quoted 10 lines · Juergen Gross

The entry point used for the vcpu_op hypercall on Arm is different from the one on x86 today, as some of the common sub-ops are not supported on Arm. The Arm specific handler filters out the not supported sub-ops and then calls the common handler. This leads to the weird call hierarchy:

do_arm_vcpu_op()

    do_vcpu_op()
      arch_do_vcpu_op()
Quoted 7 lines

Clean this up by renaming do_vcpu_op() to common_vcpu_op() and arch_do_vcpu_op() in each architecture to do_vcpu_op(). This way one of above calls can be avoided without restricting any potential future use of common sub-ops for Arm.

From an x86 only PoV I prefer the previous arrangement (do_vcpu_op() -> arch_do_vcpu_op()), but this approach seems to be better for Arm, so that's a reasonable argument for changing it.

My preference would have been to move the handling of hypercalls not used by Arm into arch_do_vcpu_op() for x86, but that's also not widely liked.

Quoted 25 lines

---
V4:
- don't remove HYPERCALL_ARM()
V4.1:
- add missing cf_check (Andrew Cooper)
V5:
- use v instead of current (Julien Grall)

---
 xen/arch/arm/domain.c                | 15 ++++++++-------
 xen/arch/arm/include/asm/hypercall.h |  2 --
 xen/arch/arm/traps.c                 |  2 +-
 xen/arch/x86/domain.c                | 12 ++++++++----
 xen/arch/x86/include/asm/hypercall.h |  2 +-
 xen/arch/x86/x86_64/domain.c         | 18 +++++++++++++-----
 xen/common/compat/domain.c           | 15 ++++++---------
 xen/common/domain.c                  | 12 ++++--------
 xen/include/xen/hypercall.h          |  2 +-
 9 files changed, 42 insertions(+), 38 deletions(-)
xen/arch/arm/domain.c +0 -0
index 8110c1df86..2f8eaab7b5 100644
@@ -1079,23 +1079,24 @@ void arch_dump_domain_info(struct domain *d)
 }

xen/arch/arm/domain.c void arch_dump_domain_info(struct domain *d) · line 1088

Quoted 10 lines
xen/arch/arm/domain.c +6 -1
 
 
-long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
+long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
+    struct domain *d = current->domain;
+    struct vcpu *v;
+
+    if ( (v = domain_vcpu(d, vcpuid)) == NULL )
+        return -ENOENT;

My preference (here and in x86) code would be to do the initialization at definition, and then just check for v here, ie:

struct vcpu *v = domain_vcpu(d, vcpuid);

if ( !v )

    return -ENOENT;

But that's just my taste.

Thanks, Roger.

#10 lore raw

PATCH v6 2/9 xen: harmonize return types of hypercall handlers

In reply to Juergen Gross

Today most hypercall handlers have a return type of long, while the compat ones return an int. There are a few exceptions from that rule, however.

Get rid of the exceptions by letting compat handlers always return int and others always return long, with the exception of the Arm specific physdev_op handler.

For the compat hvm case use eax instead of rax for the stored result as it should have been from the beginning.

Additionally move some prototypes to include/asm-x86/hypercall.h as they are x86 specific. Move the compat_platform_op() prototype to the common header.

Rename paging_domctl_continuation() to do_paging_domctl_cont() and add a matching define for the associated hypercall.

Make do_callback_op() and compat_callback_op() more similar by adding the const attribute to compat_callback_op()'s 2nd parameter.

Change the type of the cmd parameter for [do|compat]_kexec_op() to unsigned int, as this is more appropriate for the compat case.

---
V2:
- rework platform_op compat handling (Jan Beulich)
V3:
- remove include of types.h (Jan Beulich)
V4:
- don't move do_physdev_op() (Julien Grall)
- carve out non style compliant parameter replacements (Julien Grall) V6:
- remove rebase artifact (Jan Beulich)

---
 xen/arch/x86/domctl.c                |  4 ++--
 xen/arch/x86/hvm/hypercall.c         |  8 ++-----
 xen/arch/x86/hypercall.c             |  2 +-
 xen/arch/x86/include/asm/hypercall.h | 31 ++++++++++++++--------------
 xen/arch/x86/include/asm/paging.h    |  3 ---
 xen/arch/x86/mm/paging.c             |  3 ++-
 xen/arch/x86/pv/callback.c           | 14 ++++++-------
 xen/arch/x86/pv/emul-priv-op.c       |  2 +-
 xen/arch/x86/pv/hypercall.c          |  5 +----
 xen/arch/x86/pv/iret.c               |  4 ++--
 xen/arch/x86/pv/misc-hypercalls.c    | 14 ++++++++-----
 xen/common/argo.c                    |  6 +++---
 xen/common/kexec.c                   |  6 +++---
 xen/include/xen/hypercall.h          | 20 ++++++++----------
 14 files changed, 58 insertions(+), 64 deletions(-)
xen/arch/x86/domctl.c +2 -2
index e49f9e91b9..ea7d60ffb6 100644
@@ -221,8 +221,8 @@ long arch_do_domctl(
     case XEN_DOMCTL_shadow_op:
         ret = paging_domctl(d, &domctl->u.shadow_op, u_domctl, 0);
         if ( ret == -ERESTART )
-            return hypercall_create_continuation(__HYPERVISOR_arch_1,
-                                                 "h", u_domctl);
+            return hypercall_create_continuation(
+                       __HYPERVISOR_paging_domctl_cont, "h", u_domctl);
         copyback = true;
         break;
 
xen/arch/x86/hvm/hypercall.c +2 -6
index 62b5349e7d..3a35543997 100644
@@ -124,8 +124,6 @@ static long cf_check hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) do_ ## x,  \
                                (hypercall_fn_t *) compat_ ## x }
 
-#define do_arch_1             paging_domctl_continuation
-
 static const struct {
     hypercall_fn_t *native, *compat;
 } hvm_hypercall_table[] = {
@@ -158,11 +156,9 @@ static const struct {
 #ifdef CONFIG_HYPFS
     HYPERCALL(hypfs_op),
 #endif
-    HYPERCALL(arch_1)
+    HYPERCALL(paging_domctl_cont)
 };
 
-#undef do_arch_1
-
 #undef HYPERCALL
 #undef HVM_CALL
 #undef COMPAT_CALL
@@ -300,7 +296,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)
 #endif
 
         curr->hcall_compat = true;
-        regs->rax = hvm_hypercall_table[eax].compat(ebx, ecx, edx, esi, edi);
+        regs->eax = hvm_hypercall_table[eax].compat(ebx, ecx, edx, esi, edi);
         curr->hcall_compat = false;
 
 #ifndef NDEBUG
xen/arch/x86/hypercall.c +1 -1
index 2370d31d3f..07e1a45ef5 100644
@@ -75,7 +75,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
     ARGS(dm_op, 3),
     ARGS(hypfs_op, 5),
     ARGS(mca, 1),
-    ARGS(arch_1, 1),
+    ARGS(paging_domctl_cont, 1),
 };
 
 #undef COMP
xen/arch/x86/include/asm/hypercall.h +16 -15
index d6daa7e4cb..49973820af 100644
@@ -11,6 +11,8 @@
 #include <public/arch-x86/xen-mca.h> /* for do_mca */
 #include <asm/paging.h>
 
+#define __HYPERVISOR_paging_domctl_cont __HYPERVISOR_arch_1
+
 typedef unsigned long hypercall_fn_t(
     unsigned long, unsigned long, unsigned long,
     unsigned long, unsigned long);
@@ -80,7 +82,7 @@ do_set_debugreg(
     int reg,
     unsigned long value);
 
-extern unsigned long cf_check
+extern long cf_check
 do_get_debugreg(
     int reg);
 
@@ -118,7 +120,7 @@ do_mmuext_op(
 extern long cf_check do_callback_op(
     int cmd, XEN_GUEST_HANDLE_PARAM(const_void) arg);
 
-extern unsigned long cf_check
+extern long cf_check
 do_iret(
     void);
 
@@ -133,17 +135,20 @@ do_set_segment_base(
     unsigned int which,
     unsigned long base);
 
+long cf_check do_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
+
+long cf_check do_xenpmu_op(unsigned int op,
+                           XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
+
+long cf_check do_paging_domctl_cont(
+    XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
+
 #ifdef CONFIG_COMPAT
 
 #include <compat/arch-x86/xen.h>
 #include <compat/physdev.h>
 #include <compat/platform.h>
 
-extern int cf_check
-compat_physdev_op(
-    int cmd,
-    XEN_GUEST_HANDLE_PARAM(void) arg);
-
 extern int
 compat_common_vcpu_op(
     int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg);
@@ -154,12 +159,8 @@ extern int cf_check compat_mmuext_op(
     XEN_GUEST_HANDLE_PARAM(uint) pdone,
     unsigned int foreigndom);
 
-DEFINE_XEN_GUEST_HANDLE(compat_platform_op_t);
-extern int cf_check compat_platform_op(
-    XEN_GUEST_HANDLE_PARAM(compat_platform_op_t) u_xenpf_op);
-
-extern long cf_check compat_callback_op(
-    int cmd, XEN_GUEST_HANDLE(void) arg);
+extern int cf_check compat_callback_op(
+    int cmd, XEN_GUEST_HANDLE(const_void) arg);
 
 extern int cf_check compat_update_va_mapping(
     unsigned int va, uint32_t lo, uint32_t hi, unsigned int flags);
@@ -177,12 +178,12 @@ extern int cf_check compat_set_gdt(
 extern int cf_check compat_update_descriptor(
     uint32_t pa_lo, uint32_t pa_hi, uint32_t desc_lo, uint32_t desc_hi);
 
-extern unsigned int cf_check compat_iret(void);
+extern int cf_check compat_iret(void);
 
 extern int cf_check compat_nmi_op(
     unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check compat_set_callbacks(
+extern int cf_check compat_set_callbacks(
     unsigned long event_selector, unsigned long event_address,
     unsigned long failsafe_selector, unsigned long failsafe_address);
 
xen/arch/x86/include/asm/paging.h +0 -3
index f0b4efc66e..54c440be65 100644
@@ -234,9 +234,6 @@ int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
                   XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl,
                   bool_t resuming);
 
-/* Helper hypercall for dealing with continuations. */
-long cf_check paging_domctl_continuation(XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
-
 /* Call when destroying a vcpu/domain */
 void paging_vcpu_teardown(struct vcpu *v);
 int paging_teardown(struct domain *d);
xen/arch/x86/mm/paging.c +2 -1
index 1f0b94ad21..a7e2707ecc 100644
@@ -21,6 +21,7 @@
 
 #include <xen/init.h>
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <asm/paging.h>
 #include <asm/shadow.h>
 #include <asm/p2m.h>
@@ -759,7 +760,7 @@ int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
         return shadow_domctl(d, sc, u_domctl);
 }
 
-long cf_check paging_domctl_continuation(
+long cf_check do_paging_domctl_cont(
     XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
     struct xen_domctl op;
xen/arch/x86/pv/callback.c +7 -7
index 55148c7f9e..1be9d3f731 100644
@@ -207,9 +207,9 @@ long cf_check do_set_callbacks(
 #include <compat/callback.h>
 #include <compat/nmi.h>
 
-static long compat_register_guest_callback(struct compat_callback_register *reg)
+static int compat_register_guest_callback(struct compat_callback_register *reg)
 {
-    long ret = 0;
+    int ret = 0;
     struct vcpu *curr = current;
 
     fixup_guest_code_selector(curr->domain, reg->address.cs);
@@ -256,10 +256,10 @@ static long compat_register_guest_callback(struct compat_callback_register *reg)
     return ret;
 }
 
-static long compat_unregister_guest_callback(
+static int compat_unregister_guest_callback(
     struct compat_callback_unregister *unreg)
 {
-    long ret;
+    int ret;
 
     switch ( unreg->type )
     {
@@ -283,9 +283,9 @@ static long compat_unregister_guest_callback(
     return ret;
 }
 
-long cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)
+int cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(const_void) arg)
 {
-    long ret;
+    int ret;
 
     switch ( cmd )
     {
@@ -321,7 +321,7 @@ long cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)
     return ret;
 }
 
-long cf_check compat_set_callbacks(
+int cf_check compat_set_callbacks(
     unsigned long event_selector, unsigned long event_address,
     unsigned long failsafe_selector, unsigned long failsafe_address)
 {
xen/arch/x86/pv/emul-priv-op.c +1 -1
index 22b10dec2a..5da00e24e4 100644
@@ -22,13 +22,13 @@
 #include <xen/domain_page.h>
 #include <xen/event.h>
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <xen/iocap.h>
 
 #include <asm/amd.h>
 #include <asm/debugreg.h>
 #include <asm/endbr.h>
 #include <asm/hpet.h>
-#include <asm/hypercall.h>
 #include <asm/mc146818rtc.h>
 #include <asm/pv/domain.h>
 #include <asm/pv/trace.h>
xen/arch/x86/pv/hypercall.c +1 -4
index e8fbee7bbb..fe8dfe9e8f 100644
@@ -47,8 +47,6 @@ typedef struct {
 #define COMPAT_CALL(x) HYPERCALL(x)
 #endif
 
-#define do_arch_1             paging_domctl_continuation
-
 static const pv_hypercall_table_t pv_hypercall_table[] = {
     COMPAT_CALL(set_trap_table),
     HYPERCALL(mmu_update),
@@ -109,11 +107,10 @@ static const pv_hypercall_table_t pv_hypercall_table[] = {
 #endif
     HYPERCALL(mca),
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
-    HYPERCALL(arch_1),
+    HYPERCALL(paging_domctl_cont),
 #endif
 };
 
-#undef do_arch_1
 #undef COMPAT_CALL
 #undef HYPERCALL
 
xen/arch/x86/pv/iret.c +2 -2
index dd2965d8f0..55eb6a63bd 100644
@@ -48,7 +48,7 @@ static void async_exception_cleanup(struct vcpu *curr)
         curr->arch.async_exception_state(trap).old_mask;
 }
 
-unsigned long cf_check do_iret(void)
+long cf_check do_iret(void)
 {
     struct cpu_user_regs *regs = guest_cpu_user_regs();
     struct iret_context iret_saved;
@@ -105,7 +105,7 @@ unsigned long cf_check do_iret(void)
 }
 
 #ifdef CONFIG_PV32
-unsigned int cf_check compat_iret(void)
+int cf_check compat_iret(void)
 {
     struct cpu_user_regs *regs = guest_cpu_user_regs();
     struct vcpu *v = current;
xen/arch/x86/pv/misc-hypercalls.c +9 -5
index 5649aaab44..635f5a644a 100644
@@ -28,12 +28,16 @@ long cf_check do_set_debugreg(int reg, unsigned long value)
     return set_debugreg(current, reg, value);
 }
 
-unsigned long cf_check do_get_debugreg(int reg)
+long cf_check do_get_debugreg(int reg)
 {
-    unsigned long val;
-    int res = x86emul_read_dr(reg, &val, NULL);
-
-    return res == X86EMUL_OKAY ? val : -ENODEV;
+    /* Avoid implementation defined behavior casting unsigned long to long. */
+    union {
+        unsigned long val;
+        long ret;
+    } u;
+    int res = x86emul_read_dr(reg, &u.val, NULL);
+
+    return res == X86EMUL_OKAY ? u.ret : -ENODEV;
 }
 
 long cf_check do_fpu_taskswitch(int set)
xen/common/argo.c +3 -3
index 297f6d11f0..26a01c2188 100644
@@ -2207,13 +2207,13 @@ do_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
 }
 
 #ifdef CONFIG_COMPAT
-long cf_check
+int cf_check
 compat_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
                XEN_GUEST_HANDLE_PARAM(void) arg2, unsigned long arg3,
                unsigned long arg4)
 {
     struct domain *currd = current->domain;
-    long rc;
+    int rc;
     xen_argo_send_addr_t send_addr;
     xen_argo_iov_t iovs[XEN_ARGO_MAXIOV];
     compat_argo_iov_t compat_iovs[XEN_ARGO_MAXIOV];
@@ -2267,7 +2267,7 @@ compat_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
 
     rc = sendv(currd, &send_addr.src, &send_addr.dst, iovs, niov, arg4);
  out:
-    argo_dprintk("<-compat_argo_op(%u)=%ld\n", cmd, rc);
+    argo_dprintk("<-compat_argo_op(%u)=%d\n", cmd, rc);
 
     return rc;
 }
xen/common/kexec.c +3 -3
index a2ffb6530c..41669964d2 100644
@@ -1213,7 +1213,7 @@ static int kexec_status(XEN_GUEST_HANDLE_PARAM(void) uarg)
     return !!test_bit(bit, &kexec_flags);
 }
 
-static int do_kexec_op_internal(unsigned long op,
+static int do_kexec_op_internal(unsigned int op,
                                 XEN_GUEST_HANDLE_PARAM(void) uarg,
                                 bool_t compat)
 {
@@ -1265,13 +1265,13 @@ static int do_kexec_op_internal(unsigned long op,
     return ret;
 }
 
-long cf_check do_kexec_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg)
+long cf_check do_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
 {
     return do_kexec_op_internal(op, uarg, 0);
 }
 
 #ifdef CONFIG_COMPAT
-int cf_check compat_kexec_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg)
+int cf_check compat_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
 {
     return do_kexec_op_internal(op, uarg, 1);
 }
xen/include/xen/hypercall.h +9 -11
index 81aae7a662..a032ba2b4a 100644
@@ -114,11 +114,6 @@ common_vcpu_op(int cmd,
     struct vcpu *v,
     XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check
-do_nmi_op(
-    unsigned int cmd,
-    XEN_GUEST_HANDLE_PARAM(void) arg);
-
 extern long cf_check
 do_hvm_op(
     unsigned long op,
@@ -126,7 +121,7 @@ do_hvm_op(
 
 extern long cf_check
 do_kexec_op(
-    unsigned long op,
+    unsigned int op,
     XEN_GUEST_HANDLE_PARAM(void) uarg);
 
 extern long cf_check
@@ -145,9 +140,6 @@ extern long cf_check do_argo_op(
 extern long cf_check
 do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check
-do_xenpmu_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
-
 extern long cf_check
 do_dm_op(
     domid_t domid,
@@ -205,15 +197,21 @@ extern int cf_check compat_xsm_op(
     XEN_GUEST_HANDLE_PARAM(void) op);
 
 extern int cf_check compat_kexec_op(
-    unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg);
+    unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg);
 
 DEFINE_XEN_GUEST_HANDLE(multicall_entry_compat_t);
 extern int cf_check compat_multicall(
     XEN_GUEST_HANDLE_PARAM(multicall_entry_compat_t) call_list,
     uint32_t nr_calls);
 
+int compat_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
+
+typedef struct compat_platform_op compat_platform_op_t;
+DEFINE_XEN_GUEST_HANDLE(compat_platform_op_t);
+int compat_platform_op(XEN_GUEST_HANDLE_PARAM(compat_platform_op_t) u_xenpf_op);
+
 #ifdef CONFIG_ARGO
-extern long cf_check compat_argo_op(
+extern int cf_check compat_argo_op(
     unsigned int cmd,
     XEN_GUEST_HANDLE_PARAM(void) arg1,
     XEN_GUEST_HANDLE_PARAM(void) arg2,
Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH v6 2/9] xen: harmonize return types of hypercall handlers

Quoted 18 lines · Juergen Gross

Today most hypercall handlers have a return type of long, while the compat ones return an int. There are a few exceptions from that rule, however.

Get rid of the exceptions by letting compat handlers always return int and others always return long, with the exception of the Arm specific physdev_op handler.

For the compat hvm case use eax instead of rax for the stored result as it should have been from the beginning.

Additionally move some prototypes to include/asm-x86/hypercall.h as they are x86 specific. Move the compat_platform_op() prototype to the common header.

Rename paging_domctl_continuation() to do_paging_domctl_cont() and add a matching define for the associated hypercall.

Quoted 8 lines

Make do_callback_op() and compat_callback_op() more similar by adding the const attribute to compat_callback_op()'s 2nd parameter.

Change the type of the cmd parameter for [do|compat]_kexec_op() to unsigned int, as this is more appropriate for the compat case.

Could I please have some feedback regarding the kexec and argo changes?

Juergen

Quoted 472 lines

---
V2:
- rework platform_op compat handling (Jan Beulich)
V3:
- remove include of types.h (Jan Beulich)
V4:
- don't move do_physdev_op() (Julien Grall)
- carve out non style compliant parameter replacements (Julien Grall) V6:
- remove rebase artifact (Jan Beulich)

---
  xen/arch/x86/domctl.c                |  4 ++--
  xen/arch/x86/hvm/hypercall.c         |  8 ++-----
  xen/arch/x86/hypercall.c             |  2 +-
  xen/arch/x86/include/asm/hypercall.h | 31 ++++++++++++++--------------
  xen/arch/x86/include/asm/paging.h    |  3 ---
  xen/arch/x86/mm/paging.c             |  3 ++-
  xen/arch/x86/pv/callback.c           | 14 ++++++-------
  xen/arch/x86/pv/emul-priv-op.c       |  2 +-
  xen/arch/x86/pv/hypercall.c          |  5 +----
  xen/arch/x86/pv/iret.c               |  4 ++--
  xen/arch/x86/pv/misc-hypercalls.c    | 14 ++++++++-----
  xen/common/argo.c                    |  6 +++---
  xen/common/kexec.c                   |  6 +++---
  xen/include/xen/hypercall.h          | 20 ++++++++----------
  14 files changed, 58 insertions(+), 64 deletions(-)
xen/arch/x86/domctl.c +2 -2
index e49f9e91b9..ea7d60ffb6 100644
@@ -221,8 +221,8 @@ long arch_do_domctl(
      case XEN_DOMCTL_shadow_op:
          ret = paging_domctl(d, &domctl->u.shadow_op, u_domctl, 0);
          if ( ret == -ERESTART )
-            return hypercall_create_continuation(__HYPERVISOR_arch_1,
-                                                 "h", u_domctl);
+            return hypercall_create_continuation(
+                       __HYPERVISOR_paging_domctl_cont, "h", u_domctl);
          copyback = true;
          break;
 
xen/arch/x86/hvm/hypercall.c +2 -6
index 62b5349e7d..3a35543997 100644
@@ -124,8 +124,6 @@ static long cf_check hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
      [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) do_ ## x,  \
                                 (hypercall_fn_t *) compat_ ## x }
 
-#define do_arch_1             paging_domctl_continuation
-
  static const struct {
      hypercall_fn_t *native, *compat;
  } hvm_hypercall_table[] = {
@@ -158,11 +156,9 @@ static const struct {
  #ifdef CONFIG_HYPFS
      HYPERCALL(hypfs_op),
  #endif
-    HYPERCALL(arch_1)
+    HYPERCALL(paging_domctl_cont)
  };
 
-#undef do_arch_1
-
  #undef HYPERCALL
  #undef HVM_CALL
  #undef COMPAT_CALL
@@ -300,7 +296,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)
  #endif
 
          curr->hcall_compat = true;
-        regs->rax = hvm_hypercall_table[eax].compat(ebx, ecx, edx, esi, edi);
+        regs->eax = hvm_hypercall_table[eax].compat(ebx, ecx, edx, esi, edi);
          curr->hcall_compat = false;
 
  #ifndef NDEBUG
xen/arch/x86/hypercall.c +1 -1
index 2370d31d3f..07e1a45ef5 100644
@@ -75,7 +75,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
      ARGS(dm_op, 3),
      ARGS(hypfs_op, 5),
      ARGS(mca, 1),
-    ARGS(arch_1, 1),
+    ARGS(paging_domctl_cont, 1),
  };
 
  #undef COMP
xen/arch/x86/include/asm/hypercall.h +16 -15
index d6daa7e4cb..49973820af 100644
@@ -11,6 +11,8 @@
  #include <public/arch-x86/xen-mca.h> /* for do_mca */
  #include <asm/paging.h>
 
+#define __HYPERVISOR_paging_domctl_cont __HYPERVISOR_arch_1
+
  typedef unsigned long hypercall_fn_t(
      unsigned long, unsigned long, unsigned long,
      unsigned long, unsigned long);
@@ -80,7 +82,7 @@ do_set_debugreg(
      int reg,
      unsigned long value);
 
-extern unsigned long cf_check
+extern long cf_check
  do_get_debugreg(
      int reg);
 
@@ -118,7 +120,7 @@ do_mmuext_op(
  extern long cf_check do_callback_op(
      int cmd, XEN_GUEST_HANDLE_PARAM(const_void) arg);
 
-extern unsigned long cf_check
+extern long cf_check
  do_iret(
      void);
 
@@ -133,17 +135,20 @@ do_set_segment_base(
      unsigned int which,
      unsigned long base);
 
+long cf_check do_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
+
+long cf_check do_xenpmu_op(unsigned int op,
+                           XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
+
+long cf_check do_paging_domctl_cont(
+    XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
+
  #ifdef CONFIG_COMPAT
 
  #include <compat/arch-x86/xen.h>
  #include <compat/physdev.h>
  #include <compat/platform.h>
 
-extern int cf_check
-compat_physdev_op(
-    int cmd,
-    XEN_GUEST_HANDLE_PARAM(void) arg);
-
  extern int
  compat_common_vcpu_op(
      int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg);
@@ -154,12 +159,8 @@ extern int cf_check compat_mmuext_op(
      XEN_GUEST_HANDLE_PARAM(uint) pdone,
      unsigned int foreigndom);
 
-DEFINE_XEN_GUEST_HANDLE(compat_platform_op_t);
-extern int cf_check compat_platform_op(
-    XEN_GUEST_HANDLE_PARAM(compat_platform_op_t) u_xenpf_op);
-
-extern long cf_check compat_callback_op(
-    int cmd, XEN_GUEST_HANDLE(void) arg);
+extern int cf_check compat_callback_op(
+    int cmd, XEN_GUEST_HANDLE(const_void) arg);
 
  extern int cf_check compat_update_va_mapping(
      unsigned int va, uint32_t lo, uint32_t hi, unsigned int flags);
@@ -177,12 +178,12 @@ extern int cf_check compat_set_gdt(
  extern int cf_check compat_update_descriptor(
      uint32_t pa_lo, uint32_t pa_hi, uint32_t desc_lo, uint32_t desc_hi);
 
-extern unsigned int cf_check compat_iret(void);
+extern int cf_check compat_iret(void);
 
  extern int cf_check compat_nmi_op(
      unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check compat_set_callbacks(
+extern int cf_check compat_set_callbacks(
      unsigned long event_selector, unsigned long event_address,
      unsigned long failsafe_selector, unsigned long failsafe_address);
 
xen/arch/x86/include/asm/paging.h +0 -3
index f0b4efc66e..54c440be65 100644
@@ -234,9 +234,6 @@ int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
                    XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl,
                    bool_t resuming);
 
-/* Helper hypercall for dealing with continuations. */
-long cf_check paging_domctl_continuation(XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
-
  /* Call when destroying a vcpu/domain */
  void paging_vcpu_teardown(struct vcpu *v);
  int paging_teardown(struct domain *d);
xen/arch/x86/mm/paging.c +2 -1
index 1f0b94ad21..a7e2707ecc 100644
@@ -21,6 +21,7 @@
 
  #include <xen/init.h>
  #include <xen/guest_access.h>
+#include <xen/hypercall.h>
  #include <asm/paging.h>
  #include <asm/shadow.h>
  #include <asm/p2m.h>
@@ -759,7 +760,7 @@ int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
          return shadow_domctl(d, sc, u_domctl);
  }
 
-long cf_check paging_domctl_continuation(
+long cf_check do_paging_domctl_cont(
      XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
  {
      struct xen_domctl op;
xen/arch/x86/pv/callback.c +7 -7
index 55148c7f9e..1be9d3f731 100644
@@ -207,9 +207,9 @@ long cf_check do_set_callbacks(
  #include <compat/callback.h>
  #include <compat/nmi.h>
 
-static long compat_register_guest_callback(struct compat_callback_register *reg)
+static int compat_register_guest_callback(struct compat_callback_register *reg)
  {
-    long ret = 0;
+    int ret = 0;
      struct vcpu *curr = current;
 
      fixup_guest_code_selector(curr->domain, reg->address.cs);
@@ -256,10 +256,10 @@ static long compat_register_guest_callback(struct compat_callback_register *reg)
      return ret;
  }
 
-static long compat_unregister_guest_callback(
+static int compat_unregister_guest_callback(
      struct compat_callback_unregister *unreg)
  {
-    long ret;
+    int ret;
 
      switch ( unreg->type )
      {
@@ -283,9 +283,9 @@ static long compat_unregister_guest_callback(
      return ret;
  }
 
-long cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)
+int cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(const_void) arg)
  {
-    long ret;
+    int ret;
 
      switch ( cmd )
      {
@@ -321,7 +321,7 @@ long cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)
      return ret;
  }
 
-long cf_check compat_set_callbacks(
+int cf_check compat_set_callbacks(
      unsigned long event_selector, unsigned long event_address,
      unsigned long failsafe_selector, unsigned long failsafe_address)
  {
xen/arch/x86/pv/emul-priv-op.c +1 -1
index 22b10dec2a..5da00e24e4 100644
@@ -22,13 +22,13 @@
  #include <xen/domain_page.h>
  #include <xen/event.h>
  #include <xen/guest_access.h>
+#include <xen/hypercall.h>
  #include <xen/iocap.h>
 
  #include <asm/amd.h>
  #include <asm/debugreg.h>
  #include <asm/endbr.h>
  #include <asm/hpet.h>
-#include <asm/hypercall.h>
  #include <asm/mc146818rtc.h>
  #include <asm/pv/domain.h>
  #include <asm/pv/trace.h>
xen/arch/x86/pv/hypercall.c +1 -4
index e8fbee7bbb..fe8dfe9e8f 100644
@@ -47,8 +47,6 @@ typedef struct {
  #define COMPAT_CALL(x) HYPERCALL(x)
  #endif
 
-#define do_arch_1             paging_domctl_continuation
-
  static const pv_hypercall_table_t pv_hypercall_table[] = {
      COMPAT_CALL(set_trap_table),
      HYPERCALL(mmu_update),
@@ -109,11 +107,10 @@ static const pv_hypercall_table_t pv_hypercall_table[] = {
  #endif
      HYPERCALL(mca),
  #ifndef CONFIG_PV_SHIM_EXCLUSIVE
-    HYPERCALL(arch_1),
+    HYPERCALL(paging_domctl_cont),
  #endif
  };
 
-#undef do_arch_1
  #undef COMPAT_CALL
  #undef HYPERCALL
 
xen/arch/x86/pv/iret.c +2 -2
index dd2965d8f0..55eb6a63bd 100644
@@ -48,7 +48,7 @@ static void async_exception_cleanup(struct vcpu *curr)
          curr->arch.async_exception_state(trap).old_mask;
  }
 
-unsigned long cf_check do_iret(void)
+long cf_check do_iret(void)
  {
      struct cpu_user_regs *regs = guest_cpu_user_regs();
      struct iret_context iret_saved;
@@ -105,7 +105,7 @@ unsigned long cf_check do_iret(void)
  }
 
  #ifdef CONFIG_PV32
-unsigned int cf_check compat_iret(void)
+int cf_check compat_iret(void)
  {
      struct cpu_user_regs *regs = guest_cpu_user_regs();
      struct vcpu *v = current;
xen/arch/x86/pv/misc-hypercalls.c +9 -5
index 5649aaab44..635f5a644a 100644
@@ -28,12 +28,16 @@ long cf_check do_set_debugreg(int reg, unsigned long value)
      return set_debugreg(current, reg, value);
  }
 
-unsigned long cf_check do_get_debugreg(int reg)
+long cf_check do_get_debugreg(int reg)
  {
-    unsigned long val;
-    int res = x86emul_read_dr(reg, &val, NULL);
-
-    return res == X86EMUL_OKAY ? val : -ENODEV;
+    /* Avoid implementation defined behavior casting unsigned long to long. */
+    union {
+        unsigned long val;
+        long ret;
+    } u;
+    int res = x86emul_read_dr(reg, &u.val, NULL);
+
+    return res == X86EMUL_OKAY ? u.ret : -ENODEV;
  }
 
  long cf_check do_fpu_taskswitch(int set)
xen/common/argo.c +3 -3
index 297f6d11f0..26a01c2188 100644
@@ -2207,13 +2207,13 @@ do_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
  }
 
  #ifdef CONFIG_COMPAT
-long cf_check
+int cf_check
  compat_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
                 XEN_GUEST_HANDLE_PARAM(void) arg2, unsigned long arg3,
                 unsigned long arg4)
  {
      struct domain *currd = current->domain;
-    long rc;
+    int rc;
      xen_argo_send_addr_t send_addr;
      xen_argo_iov_t iovs[XEN_ARGO_MAXIOV];
      compat_argo_iov_t compat_iovs[XEN_ARGO_MAXIOV];
@@ -2267,7 +2267,7 @@ compat_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
 
      rc = sendv(currd, &send_addr.src, &send_addr.dst, iovs, niov, arg4);
   out:
-    argo_dprintk("<-compat_argo_op(%u)=%ld\n", cmd, rc);
+    argo_dprintk("<-compat_argo_op(%u)=%d\n", cmd, rc);
 
      return rc;
  }
xen/common/kexec.c +3 -3
index a2ffb6530c..41669964d2 100644
@@ -1213,7 +1213,7 @@ static int kexec_status(XEN_GUEST_HANDLE_PARAM(void) uarg)
      return !!test_bit(bit, &kexec_flags);
  }
 
-static int do_kexec_op_internal(unsigned long op,
+static int do_kexec_op_internal(unsigned int op,
                                  XEN_GUEST_HANDLE_PARAM(void) uarg,
                                  bool_t compat)
  {
@@ -1265,13 +1265,13 @@ static int do_kexec_op_internal(unsigned long op,
      return ret;
  }
 
-long cf_check do_kexec_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg)
+long cf_check do_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
  {
      return do_kexec_op_internal(op, uarg, 0);
  }
 
  #ifdef CONFIG_COMPAT
-int cf_check compat_kexec_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg)
+int cf_check compat_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
  {
      return do_kexec_op_internal(op, uarg, 1);
  }
xen/include/xen/hypercall.h +9 -11
index 81aae7a662..a032ba2b4a 100644
@@ -114,11 +114,6 @@ common_vcpu_op(int cmd,
      struct vcpu *v,
      XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check
-do_nmi_op(
-    unsigned int cmd,
-    XEN_GUEST_HANDLE_PARAM(void) arg);
-
  extern long cf_check
  do_hvm_op(
      unsigned long op,
@@ -126,7 +121,7 @@ do_hvm_op(
 
  extern long cf_check
  do_kexec_op(
-    unsigned long op,
+    unsigned int op,
      XEN_GUEST_HANDLE_PARAM(void) uarg);
 
  extern long cf_check
@@ -145,9 +140,6 @@ extern long cf_check do_argo_op(
  extern long cf_check
  do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check
-do_xenpmu_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
-
  extern long cf_check
  do_dm_op(
      domid_t domid,
@@ -205,15 +197,21 @@ extern int cf_check compat_xsm_op(
      XEN_GUEST_HANDLE_PARAM(void) op);
 
  extern int cf_check compat_kexec_op(
-    unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg);
+    unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg);
 
  DEFINE_XEN_GUEST_HANDLE(multicall_entry_compat_t);
  extern int cf_check compat_multicall(
      XEN_GUEST_HANDLE_PARAM(multicall_entry_compat_t) call_list,
      uint32_t nr_calls);
 
+int compat_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
+
+typedef struct compat_platform_op compat_platform_op_t;
+DEFINE_XEN_GUEST_HANDLE(compat_platform_op_t);
+int compat_platform_op(XEN_GUEST_HANDLE_PARAM(compat_platform_op_t) u_xenpf_op);
+
  #ifdef CONFIG_ARGO
-extern long cf_check compat_argo_op(
+extern int cf_check compat_argo_op(
      unsigned int cmd,
      XEN_GUEST_HANDLE_PARAM(void) arg1,
      XEN_GUEST_HANDLE_PARAM(void) arg2,
#12 lore raw

Re: [PATCH v6 2/9] xen: harmonize return types of hypercall handlers

Quoted 23 lines · Juergen Gross
Quoted 21 lines · Juergen Gross

Today most hypercall handlers have a return type of long, while the compat ones return an int. There are a few exceptions from that rule, however.

Get rid of the exceptions by letting compat handlers always return int and others always return long, with the exception of the Arm specific physdev_op handler.

For the compat hvm case use eax instead of rax for the stored result as it should have been from the beginning.

Additionally move some prototypes to include/asm-x86/hypercall.h as they are x86 specific. Move the compat_platform_op() prototype to the common header.

Rename paging_domctl_continuation() to do_paging_domctl_cont() and add a matching define for the associated hypercall.

Make do_callback_op() and compat_callback_op() more similar by adding the const attribute to compat_callback_op()'s 2nd parameter.

Quoted 7 lines
Quoted 5 lines

Change the type of the cmd parameter for [do|compat]_kexec_op() to unsigned int, as this is more appropriate for the compat case.

Could I please have some feedback regarding the kexec and argo changes?

Thanks for the ping on this and apologies for the delay. The Argo-related changes in this patch look ok, and I have built and tested Argo functionality with this patch applied with PV 32 and 64 bit guests, using XTF -- with successful results for the patch -- but I am behind on exercising it on a system that can run HVM guests, sorry. Given the HVM-related change described in the description of the patch, I think that such a test is needed and I am working on getting a build and a system installed to get that done.

Christopher

Quoted 477 lines

Juergen

Quoted 472 lines

---
V2:
- rework platform_op compat handling (Jan Beulich)
V3:
- remove include of types.h (Jan Beulich)
V4:
- don't move do_physdev_op() (Julien Grall)
- carve out non style compliant parameter replacements (Julien Grall) V6:
- remove rebase artifact (Jan Beulich)

---
  xen/arch/x86/domctl.c                |  4 ++--
  xen/arch/x86/hvm/hypercall.c         |  8 ++-----
  xen/arch/x86/hypercall.c             |  2 +-
  xen/arch/x86/include/asm/hypercall.h | 31 ++++++++++++++--------------
  xen/arch/x86/include/asm/paging.h    |  3 ---
  xen/arch/x86/mm/paging.c             |  3 ++-
  xen/arch/x86/pv/callback.c           | 14 ++++++-------
  xen/arch/x86/pv/emul-priv-op.c       |  2 +-
  xen/arch/x86/pv/hypercall.c          |  5 +----
  xen/arch/x86/pv/iret.c               |  4 ++--
  xen/arch/x86/pv/misc-hypercalls.c    | 14 ++++++++-----
  xen/common/argo.c                    |  6 +++---
  xen/common/kexec.c                   |  6 +++---
  xen/include/xen/hypercall.h          | 20 ++++++++----------
  14 files changed, 58 insertions(+), 64 deletions(-)
xen/arch/x86/domctl.c +2 -2
index e49f9e91b9..ea7d60ffb6 100644
@@ -221,8 +221,8 @@ long arch_do_domctl(
      case XEN_DOMCTL_shadow_op:
          ret = paging_domctl(d, &domctl->u.shadow_op, u_domctl, 0);
          if ( ret == -ERESTART )
-            return hypercall_create_continuation(__HYPERVISOR_arch_1,
-                                                 "h", u_domctl);
+            return hypercall_create_continuation(
+                       __HYPERVISOR_paging_domctl_cont, "h", u_domctl);
          copyback = true;
          break;
 
xen/arch/x86/hvm/hypercall.c +2 -6
index 62b5349e7d..3a35543997 100644
@@ -124,8 +124,6 @@ static long cf_check hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
      [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) do_ ## x,  \
                                 (hypercall_fn_t *) compat_ ## x }
 
-#define do_arch_1             paging_domctl_continuation
-
  static const struct {
      hypercall_fn_t *native, *compat;
  } hvm_hypercall_table[] = {
@@ -158,11 +156,9 @@ static const struct {
  #ifdef CONFIG_HYPFS
      HYPERCALL(hypfs_op),
  #endif
-    HYPERCALL(arch_1)
+    HYPERCALL(paging_domctl_cont)
  };
 
-#undef do_arch_1
-
  #undef HYPERCALL
  #undef HVM_CALL
  #undef COMPAT_CALL
@@ -300,7 +296,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)
  #endif
 
          curr->hcall_compat = true;
-        regs->rax = hvm_hypercall_table[eax].compat(ebx, ecx, edx, esi, edi);
+        regs->eax = hvm_hypercall_table[eax].compat(ebx, ecx, edx, esi, edi);
          curr->hcall_compat = false;
 
  #ifndef NDEBUG
xen/arch/x86/hypercall.c +1 -1
index 2370d31d3f..07e1a45ef5 100644
@@ -75,7 +75,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
      ARGS(dm_op, 3),
      ARGS(hypfs_op, 5),
      ARGS(mca, 1),
-    ARGS(arch_1, 1),
+    ARGS(paging_domctl_cont, 1),
  };
 
  #undef COMP
xen/arch/x86/include/asm/hypercall.h +16 -15
index d6daa7e4cb..49973820af 100644
@@ -11,6 +11,8 @@
  #include <public/arch-x86/xen-mca.h> /* for do_mca */
  #include <asm/paging.h>
 
+#define __HYPERVISOR_paging_domctl_cont __HYPERVISOR_arch_1
+
  typedef unsigned long hypercall_fn_t(
      unsigned long, unsigned long, unsigned long,
      unsigned long, unsigned long);
@@ -80,7 +82,7 @@ do_set_debugreg(
      int reg,
      unsigned long value);
 
-extern unsigned long cf_check
+extern long cf_check
  do_get_debugreg(
      int reg);
 
@@ -118,7 +120,7 @@ do_mmuext_op(
  extern long cf_check do_callback_op(
      int cmd, XEN_GUEST_HANDLE_PARAM(const_void) arg);
 
-extern unsigned long cf_check
+extern long cf_check
  do_iret(
      void);
 
@@ -133,17 +135,20 @@ do_set_segment_base(
      unsigned int which,
      unsigned long base);
 
+long cf_check do_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
+
+long cf_check do_xenpmu_op(unsigned int op,
+                           XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
+
+long cf_check do_paging_domctl_cont(
+    XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
+
  #ifdef CONFIG_COMPAT
 
  #include <compat/arch-x86/xen.h>
  #include <compat/physdev.h>
  #include <compat/platform.h>
 
-extern int cf_check
-compat_physdev_op(
-    int cmd,
-    XEN_GUEST_HANDLE_PARAM(void) arg);
-
  extern int
  compat_common_vcpu_op(
      int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg);
@@ -154,12 +159,8 @@ extern int cf_check compat_mmuext_op(
      XEN_GUEST_HANDLE_PARAM(uint) pdone,
      unsigned int foreigndom);
 
-DEFINE_XEN_GUEST_HANDLE(compat_platform_op_t);
-extern int cf_check compat_platform_op(
-    XEN_GUEST_HANDLE_PARAM(compat_platform_op_t) u_xenpf_op);
-
-extern long cf_check compat_callback_op(
-    int cmd, XEN_GUEST_HANDLE(void) arg);
+extern int cf_check compat_callback_op(
+    int cmd, XEN_GUEST_HANDLE(const_void) arg);
 
  extern int cf_check compat_update_va_mapping(
      unsigned int va, uint32_t lo, uint32_t hi, unsigned int flags);
@@ -177,12 +178,12 @@ extern int cf_check compat_set_gdt(
  extern int cf_check compat_update_descriptor(
      uint32_t pa_lo, uint32_t pa_hi, uint32_t desc_lo, uint32_t desc_hi);
 
-extern unsigned int cf_check compat_iret(void);
+extern int cf_check compat_iret(void);
 
  extern int cf_check compat_nmi_op(
      unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check compat_set_callbacks(
+extern int cf_check compat_set_callbacks(
      unsigned long event_selector, unsigned long event_address,
      unsigned long failsafe_selector, unsigned long failsafe_address);
 
xen/arch/x86/include/asm/paging.h +0 -3
index f0b4efc66e..54c440be65 100644
@@ -234,9 +234,6 @@ int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
                    XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl,
                    bool_t resuming);
 
-/* Helper hypercall for dealing with continuations. */
-long cf_check paging_domctl_continuation(XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
-
  /* Call when destroying a vcpu/domain */
  void paging_vcpu_teardown(struct vcpu *v);
  int paging_teardown(struct domain *d);
xen/arch/x86/mm/paging.c +2 -1
index 1f0b94ad21..a7e2707ecc 100644
@@ -21,6 +21,7 @@
 
  #include <xen/init.h>
  #include <xen/guest_access.h>
+#include <xen/hypercall.h>
  #include <asm/paging.h>
  #include <asm/shadow.h>
  #include <asm/p2m.h>
@@ -759,7 +760,7 @@ int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
          return shadow_domctl(d, sc, u_domctl);
  }
 
-long cf_check paging_domctl_continuation(
+long cf_check do_paging_domctl_cont(
      XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
  {
      struct xen_domctl op;
xen/arch/x86/pv/callback.c +7 -7
index 55148c7f9e..1be9d3f731 100644
@@ -207,9 +207,9 @@ long cf_check do_set_callbacks(
  #include <compat/callback.h>
  #include <compat/nmi.h>
 
-static long compat_register_guest_callback(struct compat_callback_register *reg)
+static int compat_register_guest_callback(struct compat_callback_register *reg)
  {
-    long ret = 0;
+    int ret = 0;
      struct vcpu *curr = current;
 
      fixup_guest_code_selector(curr->domain, reg->address.cs);
@@ -256,10 +256,10 @@ static long compat_register_guest_callback(struct compat_callback_register *reg)
      return ret;
  }
 
-static long compat_unregister_guest_callback(
+static int compat_unregister_guest_callback(
      struct compat_callback_unregister *unreg)
  {
-    long ret;
+    int ret;
 
      switch ( unreg->type )
      {
@@ -283,9 +283,9 @@ static long compat_unregister_guest_callback(
      return ret;
  }
 
-long cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)
+int cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(const_void) arg)
  {
-    long ret;
+    int ret;
 
      switch ( cmd )
      {
@@ -321,7 +321,7 @@ long cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)
      return ret;
  }
 
-long cf_check compat_set_callbacks(
+int cf_check compat_set_callbacks(
      unsigned long event_selector, unsigned long event_address,
      unsigned long failsafe_selector, unsigned long failsafe_address)
  {
xen/arch/x86/pv/emul-priv-op.c +1 -1
index 22b10dec2a..5da00e24e4 100644
@@ -22,13 +22,13 @@
  #include <xen/domain_page.h>
  #include <xen/event.h>
  #include <xen/guest_access.h>
+#include <xen/hypercall.h>
  #include <xen/iocap.h>
 
  #include <asm/amd.h>
  #include <asm/debugreg.h>
  #include <asm/endbr.h>
  #include <asm/hpet.h>
-#include <asm/hypercall.h>
  #include <asm/mc146818rtc.h>
  #include <asm/pv/domain.h>
  #include <asm/pv/trace.h>
xen/arch/x86/pv/hypercall.c +1 -4
index e8fbee7bbb..fe8dfe9e8f 100644
@@ -47,8 +47,6 @@ typedef struct {
  #define COMPAT_CALL(x) HYPERCALL(x)
  #endif
 
-#define do_arch_1             paging_domctl_continuation
-
  static const pv_hypercall_table_t pv_hypercall_table[] = {
      COMPAT_CALL(set_trap_table),
      HYPERCALL(mmu_update),
@@ -109,11 +107,10 @@ static const pv_hypercall_table_t pv_hypercall_table[] = {
  #endif
      HYPERCALL(mca),
  #ifndef CONFIG_PV_SHIM_EXCLUSIVE
-    HYPERCALL(arch_1),
+    HYPERCALL(paging_domctl_cont),
  #endif
  };
 
-#undef do_arch_1
  #undef COMPAT_CALL
  #undef HYPERCALL
 
xen/arch/x86/pv/iret.c +2 -2
index dd2965d8f0..55eb6a63bd 100644
@@ -48,7 +48,7 @@ static void async_exception_cleanup(struct vcpu *curr)
          curr->arch.async_exception_state(trap).old_mask;
  }
 
-unsigned long cf_check do_iret(void)
+long cf_check do_iret(void)
  {
      struct cpu_user_regs *regs = guest_cpu_user_regs();
      struct iret_context iret_saved;
@@ -105,7 +105,7 @@ unsigned long cf_check do_iret(void)
  }
 
  #ifdef CONFIG_PV32
-unsigned int cf_check compat_iret(void)
+int cf_check compat_iret(void)
  {
      struct cpu_user_regs *regs = guest_cpu_user_regs();
      struct vcpu *v = current;
xen/arch/x86/pv/misc-hypercalls.c +9 -5
index 5649aaab44..635f5a644a 100644
@@ -28,12 +28,16 @@ long cf_check do_set_debugreg(int reg, unsigned long value)
      return set_debugreg(current, reg, value);
  }
 
-unsigned long cf_check do_get_debugreg(int reg)
+long cf_check do_get_debugreg(int reg)
  {
-    unsigned long val;
-    int res = x86emul_read_dr(reg, &val, NULL);
-
-    return res == X86EMUL_OKAY ? val : -ENODEV;
+    /* Avoid implementation defined behavior casting unsigned long to long. */
+    union {
+        unsigned long val;
+        long ret;
+    } u;
+    int res = x86emul_read_dr(reg, &u.val, NULL);
+
+    return res == X86EMUL_OKAY ? u.ret : -ENODEV;
  }
 
  long cf_check do_fpu_taskswitch(int set)
xen/common/argo.c +3 -3
index 297f6d11f0..26a01c2188 100644
@@ -2207,13 +2207,13 @@ do_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
  }
 
  #ifdef CONFIG_COMPAT
-long cf_check
+int cf_check
  compat_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
                 XEN_GUEST_HANDLE_PARAM(void) arg2, unsigned long arg3,
                 unsigned long arg4)
  {
      struct domain *currd = current->domain;
-    long rc;
+    int rc;
      xen_argo_send_addr_t send_addr;
      xen_argo_iov_t iovs[XEN_ARGO_MAXIOV];
      compat_argo_iov_t compat_iovs[XEN_ARGO_MAXIOV];
@@ -2267,7 +2267,7 @@ compat_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
 
      rc = sendv(currd, &send_addr.src, &send_addr.dst, iovs, niov, arg4);
   out:
-    argo_dprintk("<-compat_argo_op(%u)=%ld\n", cmd, rc);
+    argo_dprintk("<-compat_argo_op(%u)=%d\n", cmd, rc);
 
      return rc;
  }
xen/common/kexec.c +3 -3
index a2ffb6530c..41669964d2 100644
@@ -1213,7 +1213,7 @@ static int kexec_status(XEN_GUEST_HANDLE_PARAM(void) uarg)
      return !!test_bit(bit, &kexec_flags);
  }
 
-static int do_kexec_op_internal(unsigned long op,
+static int do_kexec_op_internal(unsigned int op,
                                  XEN_GUEST_HANDLE_PARAM(void) uarg,
                                  bool_t compat)
  {
@@ -1265,13 +1265,13 @@ static int do_kexec_op_internal(unsigned long op,
      return ret;
  }
 
-long cf_check do_kexec_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg)
+long cf_check do_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
  {
      return do_kexec_op_internal(op, uarg, 0);
  }
 
  #ifdef CONFIG_COMPAT
-int cf_check compat_kexec_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg)
+int cf_check compat_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
  {
      return do_kexec_op_internal(op, uarg, 1);
  }
xen/include/xen/hypercall.h +9 -11
index 81aae7a662..a032ba2b4a 100644
@@ -114,11 +114,6 @@ common_vcpu_op(int cmd,
      struct vcpu *v,
      XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check
-do_nmi_op(
-    unsigned int cmd,
-    XEN_GUEST_HANDLE_PARAM(void) arg);
-
  extern long cf_check
  do_hvm_op(
      unsigned long op,
@@ -126,7 +121,7 @@ do_hvm_op(
 
  extern long cf_check
  do_kexec_op(
-    unsigned long op,
+    unsigned int op,
      XEN_GUEST_HANDLE_PARAM(void) uarg);
 
  extern long cf_check
@@ -145,9 +140,6 @@ extern long cf_check do_argo_op(
  extern long cf_check
  do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check
-do_xenpmu_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
-
  extern long cf_check
  do_dm_op(
      domid_t domid,
@@ -205,15 +197,21 @@ extern int cf_check compat_xsm_op(
      XEN_GUEST_HANDLE_PARAM(void) op);
 
  extern int cf_check compat_kexec_op(
-    unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg);
+    unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg);
 
  DEFINE_XEN_GUEST_HANDLE(multicall_entry_compat_t);
  extern int cf_check compat_multicall(
      XEN_GUEST_HANDLE_PARAM(multicall_entry_compat_t) call_list,
      uint32_t nr_calls);
 
+int compat_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
+
+typedef struct compat_platform_op compat_platform_op_t;
+DEFINE_XEN_GUEST_HANDLE(compat_platform_op_t);
+int compat_platform_op(XEN_GUEST_HANDLE_PARAM(compat_platform_op_t) u_xenpf_op);
+
  #ifdef CONFIG_ARGO
-extern long cf_check compat_argo_op(
+extern int cf_check compat_argo_op(
      unsigned int cmd,
      XEN_GUEST_HANDLE_PARAM(void) arg1,
      XEN_GUEST_HANDLE_PARAM(void) arg2,
Reviewed-by
#13 lore raw

Re: [PATCH v6 2/9] xen: harmonize return types of hypercall handlers

Quoted 33 lines · Christopher Clark
Quoted 23 lines · Juergen Gross
Quoted 21 lines · Juergen Gross

Today most hypercall handlers have a return type of long, while the compat ones return an int. There are a few exceptions from that rule, however.

Get rid of the exceptions by letting compat handlers always return int and others always return long, with the exception of the Arm specific physdev_op handler.

For the compat hvm case use eax instead of rax for the stored result as it should have been from the beginning.

Additionally move some prototypes to include/asm-x86/hypercall.h as they are x86 specific. Move the compat_platform_op() prototype to the common header.

Rename paging_domctl_continuation() to do_paging_domctl_cont() and add a matching define for the associated hypercall.

Make do_callback_op() and compat_callback_op() more similar by adding the const attribute to compat_callback_op()'s 2nd parameter.

Quoted 7 lines
Quoted 5 lines

Change the type of the cmd parameter for [do|compat]_kexec_op() to unsigned int, as this is more appropriate for the compat case.

Could I please have some feedback regarding the kexec and argo changes?

Quoted 8 lines

Thanks for the ping on this and apologies for the delay. The Argo-related changes in this patch look ok, and I have built and tested Argo functionality with this patch applied with PV 32 and 64 bit guests, using XTF -- with successful results for the patch -- but I am behind on exercising it on a system that can run HVM guests, sorry. Given the HVM-related change described in the description of the patch, I think that such a test is needed and I am working on getting a build and a system installed to get that done.

As discussed on the Xen Community Call today, for the Argo changes:

and tested for 32 and 64-bit PV guests on x86.
thanks,

Christopher

Quoted 480 lines

Christopher

Quoted 477 lines

Juergen

Quoted 472 lines

---
V2:
- rework platform_op compat handling (Jan Beulich)
V3:
- remove include of types.h (Jan Beulich)
V4:
- don't move do_physdev_op() (Julien Grall)
- carve out non style compliant parameter replacements (Julien Grall) V6:
- remove rebase artifact (Jan Beulich)

---
  xen/arch/x86/domctl.c                |  4 ++--
  xen/arch/x86/hvm/hypercall.c         |  8 ++-----
  xen/arch/x86/hypercall.c             |  2 +-
  xen/arch/x86/include/asm/hypercall.h | 31 ++++++++++++++--------------
  xen/arch/x86/include/asm/paging.h    |  3 ---
  xen/arch/x86/mm/paging.c             |  3 ++-
  xen/arch/x86/pv/callback.c           | 14 ++++++-------
  xen/arch/x86/pv/emul-priv-op.c       |  2 +-
  xen/arch/x86/pv/hypercall.c          |  5 +----
  xen/arch/x86/pv/iret.c               |  4 ++--
  xen/arch/x86/pv/misc-hypercalls.c    | 14 ++++++++-----
  xen/common/argo.c                    |  6 +++---
  xen/common/kexec.c                   |  6 +++---
  xen/include/xen/hypercall.h          | 20 ++++++++----------
  14 files changed, 58 insertions(+), 64 deletions(-)
xen/arch/x86/domctl.c +2 -2
index e49f9e91b9..ea7d60ffb6 100644
@@ -221,8 +221,8 @@ long arch_do_domctl(
      case XEN_DOMCTL_shadow_op:
          ret = paging_domctl(d, &domctl->u.shadow_op, u_domctl, 0);
          if ( ret == -ERESTART )
-            return hypercall_create_continuation(__HYPERVISOR_arch_1,
-                                                 "h", u_domctl);
+            return hypercall_create_continuation(
+                       __HYPERVISOR_paging_domctl_cont, "h", u_domctl);
          copyback = true;
          break;
 
xen/arch/x86/hvm/hypercall.c +2 -6
index 62b5349e7d..3a35543997 100644
@@ -124,8 +124,6 @@ static long cf_check hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
      [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) do_ ## x,  \
                                 (hypercall_fn_t *) compat_ ## x }
 
-#define do_arch_1             paging_domctl_continuation
-
  static const struct {
      hypercall_fn_t *native, *compat;
  } hvm_hypercall_table[] = {
@@ -158,11 +156,9 @@ static const struct {
  #ifdef CONFIG_HYPFS
      HYPERCALL(hypfs_op),
  #endif
-    HYPERCALL(arch_1)
+    HYPERCALL(paging_domctl_cont)
  };
 
-#undef do_arch_1
-
  #undef HYPERCALL
  #undef HVM_CALL
  #undef COMPAT_CALL
@@ -300,7 +296,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)
  #endif
 
          curr->hcall_compat = true;
-        regs->rax = hvm_hypercall_table[eax].compat(ebx, ecx, edx, esi, edi);
+        regs->eax = hvm_hypercall_table[eax].compat(ebx, ecx, edx, esi, edi);
          curr->hcall_compat = false;
 
  #ifndef NDEBUG
xen/arch/x86/hypercall.c +1 -1
index 2370d31d3f..07e1a45ef5 100644
@@ -75,7 +75,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
      ARGS(dm_op, 3),
      ARGS(hypfs_op, 5),
      ARGS(mca, 1),
-    ARGS(arch_1, 1),
+    ARGS(paging_domctl_cont, 1),
  };
 
  #undef COMP
xen/arch/x86/include/asm/hypercall.h +16 -15
index d6daa7e4cb..49973820af 100644
@@ -11,6 +11,8 @@
  #include <public/arch-x86/xen-mca.h> /* for do_mca */
  #include <asm/paging.h>
 
+#define __HYPERVISOR_paging_domctl_cont __HYPERVISOR_arch_1
+
  typedef unsigned long hypercall_fn_t(
      unsigned long, unsigned long, unsigned long,
      unsigned long, unsigned long);
@@ -80,7 +82,7 @@ do_set_debugreg(
      int reg,
      unsigned long value);
 
-extern unsigned long cf_check
+extern long cf_check
  do_get_debugreg(
      int reg);
 
@@ -118,7 +120,7 @@ do_mmuext_op(
  extern long cf_check do_callback_op(
      int cmd, XEN_GUEST_HANDLE_PARAM(const_void) arg);
 
-extern unsigned long cf_check
+extern long cf_check
  do_iret(
      void);
 
@@ -133,17 +135,20 @@ do_set_segment_base(
      unsigned int which,
      unsigned long base);
 
+long cf_check do_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
+
+long cf_check do_xenpmu_op(unsigned int op,
+                           XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
+
+long cf_check do_paging_domctl_cont(
+    XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
+
  #ifdef CONFIG_COMPAT
 
  #include <compat/arch-x86/xen.h>
  #include <compat/physdev.h>
  #include <compat/platform.h>
 
-extern int cf_check
-compat_physdev_op(
-    int cmd,
-    XEN_GUEST_HANDLE_PARAM(void) arg);
-
  extern int
  compat_common_vcpu_op(
      int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg);
@@ -154,12 +159,8 @@ extern int cf_check compat_mmuext_op(
      XEN_GUEST_HANDLE_PARAM(uint) pdone,
      unsigned int foreigndom);
 
-DEFINE_XEN_GUEST_HANDLE(compat_platform_op_t);
-extern int cf_check compat_platform_op(
-    XEN_GUEST_HANDLE_PARAM(compat_platform_op_t) u_xenpf_op);
-
-extern long cf_check compat_callback_op(
-    int cmd, XEN_GUEST_HANDLE(void) arg);
+extern int cf_check compat_callback_op(
+    int cmd, XEN_GUEST_HANDLE(const_void) arg);
 
  extern int cf_check compat_update_va_mapping(
      unsigned int va, uint32_t lo, uint32_t hi, unsigned int flags);
@@ -177,12 +178,12 @@ extern int cf_check compat_set_gdt(
  extern int cf_check compat_update_descriptor(
      uint32_t pa_lo, uint32_t pa_hi, uint32_t desc_lo, uint32_t desc_hi);
 
-extern unsigned int cf_check compat_iret(void);
+extern int cf_check compat_iret(void);
 
  extern int cf_check compat_nmi_op(
      unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check compat_set_callbacks(
+extern int cf_check compat_set_callbacks(
      unsigned long event_selector, unsigned long event_address,
      unsigned long failsafe_selector, unsigned long failsafe_address);
 
xen/arch/x86/include/asm/paging.h +0 -3
index f0b4efc66e..54c440be65 100644
@@ -234,9 +234,6 @@ int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
                    XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl,
                    bool_t resuming);
 
-/* Helper hypercall for dealing with continuations. */
-long cf_check paging_domctl_continuation(XEN_GUEST_HANDLE_PARAM(xen_domctl_t));
-
  /* Call when destroying a vcpu/domain */
  void paging_vcpu_teardown(struct vcpu *v);
  int paging_teardown(struct domain *d);
xen/arch/x86/mm/paging.c +2 -1
index 1f0b94ad21..a7e2707ecc 100644
@@ -21,6 +21,7 @@
 
  #include <xen/init.h>
  #include <xen/guest_access.h>
+#include <xen/hypercall.h>
  #include <asm/paging.h>
  #include <asm/shadow.h>
  #include <asm/p2m.h>
@@ -759,7 +760,7 @@ int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
          return shadow_domctl(d, sc, u_domctl);
  }
 
-long cf_check paging_domctl_continuation(
+long cf_check do_paging_domctl_cont(
      XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
  {
      struct xen_domctl op;
xen/arch/x86/pv/callback.c +7 -7
index 55148c7f9e..1be9d3f731 100644
@@ -207,9 +207,9 @@ long cf_check do_set_callbacks(
  #include <compat/callback.h>
  #include <compat/nmi.h>
 
-static long compat_register_guest_callback(struct compat_callback_register *reg)
+static int compat_register_guest_callback(struct compat_callback_register *reg)
  {
-    long ret = 0;
+    int ret = 0;
      struct vcpu *curr = current;
 
      fixup_guest_code_selector(curr->domain, reg->address.cs);
@@ -256,10 +256,10 @@ static long compat_register_guest_callback(struct compat_callback_register *reg)
      return ret;
  }
 
-static long compat_unregister_guest_callback(
+static int compat_unregister_guest_callback(
      struct compat_callback_unregister *unreg)
  {
-    long ret;
+    int ret;
 
      switch ( unreg->type )
      {
@@ -283,9 +283,9 @@ static long compat_unregister_guest_callback(
      return ret;
  }
 
-long cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)
+int cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(const_void) arg)
  {
-    long ret;
+    int ret;
 
      switch ( cmd )
      {
@@ -321,7 +321,7 @@ long cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)
      return ret;
  }
 
-long cf_check compat_set_callbacks(
+int cf_check compat_set_callbacks(
      unsigned long event_selector, unsigned long event_address,
      unsigned long failsafe_selector, unsigned long failsafe_address)
  {
xen/arch/x86/pv/emul-priv-op.c +1 -1
index 22b10dec2a..5da00e24e4 100644
@@ -22,13 +22,13 @@
  #include <xen/domain_page.h>
  #include <xen/event.h>
  #include <xen/guest_access.h>
+#include <xen/hypercall.h>
  #include <xen/iocap.h>
 
  #include <asm/amd.h>
  #include <asm/debugreg.h>
  #include <asm/endbr.h>
  #include <asm/hpet.h>
-#include <asm/hypercall.h>
  #include <asm/mc146818rtc.h>
  #include <asm/pv/domain.h>
  #include <asm/pv/trace.h>
xen/arch/x86/pv/hypercall.c +1 -4
index e8fbee7bbb..fe8dfe9e8f 100644
@@ -47,8 +47,6 @@ typedef struct {
  #define COMPAT_CALL(x) HYPERCALL(x)
  #endif
 
-#define do_arch_1             paging_domctl_continuation
-
  static const pv_hypercall_table_t pv_hypercall_table[] = {
      COMPAT_CALL(set_trap_table),
      HYPERCALL(mmu_update),
@@ -109,11 +107,10 @@ static const pv_hypercall_table_t pv_hypercall_table[] = {
  #endif
      HYPERCALL(mca),
  #ifndef CONFIG_PV_SHIM_EXCLUSIVE
-    HYPERCALL(arch_1),
+    HYPERCALL(paging_domctl_cont),
  #endif
  };
 
-#undef do_arch_1
  #undef COMPAT_CALL
  #undef HYPERCALL
 
xen/arch/x86/pv/iret.c +2 -2
index dd2965d8f0..55eb6a63bd 100644
@@ -48,7 +48,7 @@ static void async_exception_cleanup(struct vcpu *curr)
          curr->arch.async_exception_state(trap).old_mask;
  }
 
-unsigned long cf_check do_iret(void)
+long cf_check do_iret(void)
  {
      struct cpu_user_regs *regs = guest_cpu_user_regs();
      struct iret_context iret_saved;
@@ -105,7 +105,7 @@ unsigned long cf_check do_iret(void)
  }
 
  #ifdef CONFIG_PV32
-unsigned int cf_check compat_iret(void)
+int cf_check compat_iret(void)
  {
      struct cpu_user_regs *regs = guest_cpu_user_regs();
      struct vcpu *v = current;
xen/arch/x86/pv/misc-hypercalls.c +9 -5
index 5649aaab44..635f5a644a 100644
@@ -28,12 +28,16 @@ long cf_check do_set_debugreg(int reg, unsigned long value)
      return set_debugreg(current, reg, value);
  }
 
-unsigned long cf_check do_get_debugreg(int reg)
+long cf_check do_get_debugreg(int reg)
  {
-    unsigned long val;
-    int res = x86emul_read_dr(reg, &val, NULL);
-
-    return res == X86EMUL_OKAY ? val : -ENODEV;
+    /* Avoid implementation defined behavior casting unsigned long to long. */
+    union {
+        unsigned long val;
+        long ret;
+    } u;
+    int res = x86emul_read_dr(reg, &u.val, NULL);
+
+    return res == X86EMUL_OKAY ? u.ret : -ENODEV;
  }
 
  long cf_check do_fpu_taskswitch(int set)
xen/common/argo.c +3 -3
index 297f6d11f0..26a01c2188 100644
@@ -2207,13 +2207,13 @@ do_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
  }
 
  #ifdef CONFIG_COMPAT
-long cf_check
+int cf_check
  compat_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
                 XEN_GUEST_HANDLE_PARAM(void) arg2, unsigned long arg3,
                 unsigned long arg4)
  {
      struct domain *currd = current->domain;
-    long rc;
+    int rc;
      xen_argo_send_addr_t send_addr;
      xen_argo_iov_t iovs[XEN_ARGO_MAXIOV];
      compat_argo_iov_t compat_iovs[XEN_ARGO_MAXIOV];
@@ -2267,7 +2267,7 @@ compat_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
 
      rc = sendv(currd, &send_addr.src, &send_addr.dst, iovs, niov, arg4);
   out:
-    argo_dprintk("<-compat_argo_op(%u)=%ld\n", cmd, rc);
+    argo_dprintk("<-compat_argo_op(%u)=%d\n", cmd, rc);
 
      return rc;
  }
xen/common/kexec.c +3 -3
index a2ffb6530c..41669964d2 100644
@@ -1213,7 +1213,7 @@ static int kexec_status(XEN_GUEST_HANDLE_PARAM(void) uarg)
      return !!test_bit(bit, &kexec_flags);
  }
 
-static int do_kexec_op_internal(unsigned long op,
+static int do_kexec_op_internal(unsigned int op,
                                  XEN_GUEST_HANDLE_PARAM(void) uarg,
                                  bool_t compat)
  {
@@ -1265,13 +1265,13 @@ static int do_kexec_op_internal(unsigned long op,
      return ret;
  }
 
-long cf_check do_kexec_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg)
+long cf_check do_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
  {
      return do_kexec_op_internal(op, uarg, 0);
  }
 
  #ifdef CONFIG_COMPAT
-int cf_check compat_kexec_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg)
+int cf_check compat_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
  {
      return do_kexec_op_internal(op, uarg, 1);
  }
xen/include/xen/hypercall.h +9 -11
index 81aae7a662..a032ba2b4a 100644
@@ -114,11 +114,6 @@ common_vcpu_op(int cmd,
      struct vcpu *v,
      XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check
-do_nmi_op(
-    unsigned int cmd,
-    XEN_GUEST_HANDLE_PARAM(void) arg);
-
  extern long cf_check
  do_hvm_op(
      unsigned long op,
@@ -126,7 +121,7 @@ do_hvm_op(
 
  extern long cf_check
  do_kexec_op(
-    unsigned long op,
+    unsigned int op,
      XEN_GUEST_HANDLE_PARAM(void) uarg);
 
  extern long cf_check
@@ -145,9 +140,6 @@ extern long cf_check do_argo_op(
  extern long cf_check
  do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-extern long cf_check
-do_xenpmu_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
-
  extern long cf_check
  do_dm_op(
      domid_t domid,
@@ -205,15 +197,21 @@ extern int cf_check compat_xsm_op(
      XEN_GUEST_HANDLE_PARAM(void) op);
 
  extern int cf_check compat_kexec_op(
-    unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg);
+    unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg);
 
  DEFINE_XEN_GUEST_HANDLE(multicall_entry_compat_t);
  extern int cf_check compat_multicall(
      XEN_GUEST_HANDLE_PARAM(multicall_entry_compat_t) call_list,
      uint32_t nr_calls);
 
+int compat_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
+
+typedef struct compat_platform_op compat_platform_op_t;
+DEFINE_XEN_GUEST_HANDLE(compat_platform_op_t);
+int compat_platform_op(XEN_GUEST_HANDLE_PARAM(compat_platform_op_t) u_xenpf_op);
+
  #ifdef CONFIG_ARGO
-extern long cf_check compat_argo_op(
+extern int cf_check compat_argo_op(
      unsigned int cmd,
      XEN_GUEST_HANDLE_PARAM(void) arg1,
      XEN_GUEST_HANDLE_PARAM(void) arg2,
#14 lore raw

PATCH v6 3/9 xen: don't include asm/hypercall.h from C sources

In reply to Juergen Gross

Instead of including asm/hypercall.h always use xen/hypercall.h. Additionally include xen/hypercall.h from all sources containing a hypercall handler.

This prepares for generating the handlers' prototypes at build time.

Add a guard in asm/hypercall.h to catch direct inclusion.

---
V2:
- remove platform_op hunk (Jan Beulich)
- remove including of xen/hypervisor.h from arch/x86/x86_64/mm.c (Jan Beulich)
- fix include order in common/compat/grant_table.c (Jan Beulich)

---
 xen/arch/arm/hvm.c                   | 3 +--
 xen/arch/arm/include/asm/hypercall.h | 4 ++++
 xen/arch/arm/platform_hypercall.c    | 1 +
 xen/arch/x86/cpu/vpmu.c              | 1 +
 xen/arch/x86/include/asm/hypercall.h | 4 ++++
 xen/arch/x86/mm.c                    | 1 -
 xen/arch/x86/platform_hypercall.c    | 1 +
 xen/arch/x86/pv/iret.c               | 1 +
 xen/arch/x86/traps.c                 | 2 +-
 xen/arch/x86/x86_64/compat/mm.c      | 1 +
 xen/arch/x86/x86_64/mm.c             | 2 --
 xen/common/compat/grant_table.c      | 1 +
 xen/common/event_channel.c           | 1 +
 xen/common/grant_table.c             | 1 +
 xen/common/multicall.c               | 1 +
 15 files changed, 19 insertions(+), 6 deletions(-)
xen/arch/arm/hvm.c +1 -2
index 8951b34086..fc1a52767d 100644
@@ -20,6 +20,7 @@
 #include <xen/lib.h>
 #include <xen/errno.h>
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <xen/sched.h>
 #include <xen/monitor.h>
 
@@ -29,8 +30,6 @@
 #include <public/hvm/params.h>
 #include <public/hvm/hvm_op.h>
 
-#include <asm/hypercall.h>
-
 static int hvm_allow_set_param(const struct domain *d, unsigned int param)
 {
     switch ( param )
xen/arch/arm/include/asm/hypercall.h +4 -0
index fac4d60f17..8182895358 100644
@@ -1,3 +1,7 @@
+#ifndef __XEN_HYPERCALL_H__
+#error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"
+#endif
+
 #ifndef __ASM_ARM_HYPERCALL_H__
 #define __ASM_ARM_HYPERCALL_H__
 
xen/arch/arm/platform_hypercall.c +1 -0
index 8efac7ee60..403cc84324 100644
@@ -9,6 +9,7 @@
 #include <xen/types.h>
 #include <xen/sched.h>
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <xen/spinlock.h>
 #include <public/platform.h>
 #include <xsm/xsm.h>
xen/arch/x86/cpu/vpmu.c +1 -0
index 4fedc7c570..51d171615f 100644
@@ -22,6 +22,7 @@
 #include <xen/param.h>
 #include <xen/event.h>
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <xen/sched.h>
 #include <asm/regs.h>
 #include <asm/types.h>
xen/arch/x86/include/asm/hypercall.h +4 -0
index 49973820af..81ca25f7b3 100644
@@ -2,6 +2,10 @@
  * asm-x86/hypercall.h
  */
 
+#ifndef __XEN_HYPERCALL_H__
+#error "asm/hypercall.h should not be included directly - include xen/hypercall.h instead"
+#endif
+
 #ifndef __ASM_X86_HYPERCALL_H__
 #define __ASM_X86_HYPERCALL_H__
 
xen/arch/x86/mm.c +0 -1
index 2befd0c191..6cc73187ac 100644
@@ -129,7 +129,6 @@
 #include <asm/ldt.h>
 #include <asm/x86_emulate.h>
 #include <asm/e820.h>
-#include <asm/hypercall.h>
 #include <asm/shared.h>
 #include <asm/mem_sharing.h>
 #include <public/memory.h>
xen/arch/x86/platform_hypercall.c +1 -0
index b91ccff589..eeb4f7a20e 100644
@@ -17,6 +17,7 @@
 #include <xen/console.h>
 #include <xen/iocap.h>
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <xen/acpi.h>
 #include <xen/efi.h>
 #include <xen/cpu.h>
xen/arch/x86/pv/iret.c +1 -0
index 55eb6a63bd..58de9f7922 100644
@@ -18,6 +18,7 @@
  */
 
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <xen/lib.h>
 #include <xen/sched.h>
 
xen/arch/x86/traps.c +1 -1
index 8659547970..4c38f6c015 100644
@@ -29,6 +29,7 @@
 #include <xen/lib.h>
 #include <xen/err.h>
 #include <xen/errno.h>
+#include <xen/hypercall.h>
 #include <xen/mm.h>
 #include <xen/param.h>
 #include <xen/console.h>
@@ -70,7 +71,6 @@
 #include <asm/x86_emulate.h>
 #include <asm/traps.h>
 #include <asm/hvm/vpt.h>
-#include <asm/hypercall.h>
 #include <asm/mce.h>
 #include <asm/apic.h>
 #include <asm/mc146818rtc.h>
xen/arch/x86/x86_64/compat/mm.c +1 -0
index b3da8fafbb..70b08a832a 100644
@@ -1,4 +1,5 @@
 #include <xen/event.h>
+#include <xen/hypercall.h>
 #include <xen/mem_access.h>
 #include <xen/multicall.h>
 #include <compat/memory.h>
xen/arch/x86/x86_64/mm.c +0 -2
index 4f225da81e..3510a5affe 100644
@@ -25,14 +25,12 @@ EMIT_FILE;
 #include <xen/numa.h>
 #include <xen/nodemask.h>
 #include <xen/guest_access.h>
-#include <xen/hypercall.h>
 #include <xen/mem_access.h>
 #include <asm/current.h>
 #include <asm/asm_defns.h>
 #include <asm/page.h>
 #include <asm/flushtlb.h>
 #include <asm/fixmap.h>
-#include <asm/hypercall.h>
 #include <asm/msr.h>
 #include <asm/pv/domain.h>
 #include <asm/setup.h>
xen/common/compat/grant_table.c +1 -0
index c6199e8918..d5787e3719 100644
@@ -3,6 +3,7 @@
  *
  */
 
+#include <xen/hypercall.h>
 #include <compat/grant_table.h>
 
 #define xen_grant_entry_v1 grant_entry_v1
xen/common/event_channel.c +1 -0
index ffb042a241..0a82eb3ac2 100644
@@ -24,6 +24,7 @@
 #include <xen/iocap.h>
 #include <xen/compat.h>
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <xen/keyhandler.h>
 #include <asm/current.h>
 
xen/common/grant_table.c +1 -0
index 1e0762b064..febbe12eab 100644
@@ -33,6 +33,7 @@
 #include <xen/trace.h>
 #include <xen/grant_table.h>
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <xen/domain_page.h>
 #include <xen/iommu.h>
 #include <xen/paging.h>
xen/common/multicall.c +1 -0
index e48f46dbe0..9db49092b4 100644
@@ -9,6 +9,7 @@
 #include <xen/event.h>
 #include <xen/multicall.h>
 #include <xen/guest_access.h>
+#include <xen/hypercall.h>
 #include <xen/perfc.h>
 #include <xen/trace.h>
 #include <asm/current.h>
Signature · 1 line
2.34.1
#15 lore raw

PATCH v6 4/9 xen: include compat/platform.h from hypercall.h

In reply to Juergen Gross

The definition of compat_platform_op_t is in compat/platform.h already, so include that file from hypercall.h instead of repeating the typedef.

This allows to remove the related include statement from arch/x86/x86_64/platform_hypercall.c.

---
V3:
- new patch

---
 xen/arch/x86/x86_64/platform_hypercall.c | 1 -
 xen/include/xen/hypercall.h              | 4 +++-
 2 files changed, 3 insertions(+), 2 deletions(-)
xen/arch/x86/x86_64/platform_hypercall.c +0 -1
index 966fd27b5f..5bf6b958d2 100644
@@ -5,7 +5,6 @@
 EMIT_FILE;
 
 #include <xen/lib.h>
-#include <compat/platform.h>
 #include <xen/hypercall.h>
 
 #define xen_platform_op     compat_platform_op
xen/include/xen/hypercall.h +3 -1
index a032ba2b4a..ca8ee22717 100644
@@ -15,6 +15,9 @@
 #include <public/version.h>
 #include <public/pmu.h>
 #include <public/hvm/dm_op.h>
+#ifdef CONFIG_COMPAT
+#include <compat/platform.h>
+#endif
 #include <asm/hypercall.h>
 #include <xsm/xsm.h>
 
@@ -206,7 +209,6 @@ extern int cf_check compat_multicall(
 
 int compat_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
 
-typedef struct compat_platform_op compat_platform_op_t;
 DEFINE_XEN_GUEST_HANDLE(compat_platform_op_t);
 int compat_platform_op(XEN_GUEST_HANDLE_PARAM(compat_platform_op_t) u_xenpf_op);
 
Signature · 1 line
2.34.1
#16 lore raw

PATCH v6 5/9 xen: generate hypercall interface related code

In reply to Juergen Gross

Instead of repeating similar data multiple times use a single source file and a generator script for producing prototypes and call sequences of the hypercalls.

As the script already knows the number of parameters used add generating a macro for populating an array with the number of parameters per hypercall.

The priorities for the specific hypercalls are based on two benchamrks performed in guests (PV and PVH):

- make -j 4 of the Xen hypervisor (resulting in cpu load with lots of processes created)
- scp of a large file to the guest (network load)

With a small additional debug patch applied the number of the different hypercalls in the guest and in dom0 (for looking at backend activity related hypercalls) were counted while the benchmark in domU was running:

PV-hypercall PV-guest build PV-guest scp dom0 build dom0 scp
mmu_update 186175729 2865 20936 33725
stack_switch 1273311 62381 108589 270764
multicall 2182803 50 302 524
update_va_mapping 571868 10 60 80
xen_version 73061 850 859 5432

grant_table_op               0              0         35557       139110
iret                  75673006         484132        268157       757958
vcpu_op                 453037          71199        138224       334988
set_segment_base       1650249          62387        108645       270823
mmuext_op             11225681            188          7239         3426
sched_op                280153         134645         70729       137943
event_channel_op        192327          66204         71409       214191

physdev_op 0 0 7721 4315
(the dom0 values are for the guest running the build or scp test, so dom0 acting as backend)

HVM-hypercall PVH-guest build PVH-guest scp
vcpu_op 277684 2324
event_channel_op 350233 57383
(the related dom0 counter values are in the same range as with the test running in the PV guest)

---
V2:
- split platform_op for doe and compat prefixes (Jan Beulich)
- add "addline:" directive
- add priorities to handlers (Jan Beulich)
V2.1:
- add missing "delete" statement in awk script
- optimize case of 2 hypercalls with same priority
V2.2:
- avoid asort() function (Michal Orzel)
V3:
- drop "addline:" support, as no longer needed
- enclose call sequence macros in "({ ... })" (Jan Beulich)
- small style adjustment (Jan Beulich)
- move generating to xen/include/Makefile (Anthony PERARD)
V4:
- generate cf_check attribute for prototype (will be removed in later patch)
- add Arm-specific variant of physdev_op()
V5:
- user $(srctree) (Anthony Perard)
- specify priority 1 for arm evtchn_op (Julien Grall)

---
 .gitignore                    |   1 +
 xen/include/Makefile          |  13 ++
 xen/include/hypercall-defs.c  | 285 ++++++++++++++++++++++++++++++
 xen/scripts/gen_hypercall.awk | 314 ++++++++++++++++++++++++++++++++++
 4 files changed, 613 insertions(+)
 create mode 100644 xen/include/hypercall-defs.c
 create mode 100644 xen/scripts/gen_hypercall.awk
.gitignore +1 -0
index d425be4bd9..c6e5b31b98 100644
@@ -324,6 +324,7 @@ xen/include/public/public
 xen/include/xen/*.new
 xen/include/xen/acm_policy.h
 xen/include/xen/compile.h
+xen/include/xen/hypercall-defs.h
 xen/include/xen/lib/x86/cpuid-autogen.h
 xen/test/livepatch/config.h
 xen/test/livepatch/expect_config.h
xen/include/Makefile +13 -0
index a3c2511f5f..dfc43f9fba 100644
@@ -77,6 +77,18 @@ $(obj)/compat/xlat.h: $(addprefix $(obj)/compat/.xlat/,$(xlat-y)) $(obj)/config/
 	cat $(filter %.h,$^) >[email protected]
 	mv -f [email protected] $@
 
+quiet_cmd_genhyp = GEN     $@
+define cmd_genhyp
+    awk -f $(srctree)/scripts/gen_hypercall.awk <$< >$@
+endef
+
+all: $(obj)/xen/hypercall-defs.h
+
+$(obj)/xen/hypercall-defs.h: $(obj)/hypercall-defs.i $(srctree)/scripts/gen_hypercall.awk FORCE
+	$(call if_changed,genhyp)
+
+targets += xen/hypercall-defs.h
+
 ifeq ($(XEN_TARGET_ARCH),$(XEN_COMPILE_ARCH))
 
 all: $(obj)/headers.chk $(obj)/headers99.chk $(obj)/headers++.chk
@@ -132,3 +144,4 @@ all: lib-x86-all
 endif
 
 clean-files := compat config generated headers*.chk xen/lib/x86/cpuid-autogen.h
+clean-files += xen/hypercall-defs.h hypercall-defs.i
xen/include/hypercall-defs.c new file +285 -0

285 lines not on this page · raw message

xen/scripts/gen_hypercall.awk new file +314 -0

314 lines not on this page · raw message

Signature · 1 line
2.34.1
#17 lore raw

Re: [PATCH v6 5/9] xen: generate hypercall interface related code

Quoted 22 lines · Juergen Gross
xen/include/Makefile +12 -0
@@ -77,6 +77,18 @@ $(obj)/compat/xlat.h: $(addprefix $(obj)/compat/.xlat/,$(xlat-y)) $(obj)/config/
 	cat $(filter %.h,$^) >[email protected]
 	mv -f [email protected] $@
 
+quiet_cmd_genhyp = GEN     $@
+define cmd_genhyp
+    awk -f $(srctree)/scripts/gen_hypercall.awk <$< >$@
+endef
+
+all: $(obj)/xen/hypercall-defs.h
+
+$(obj)/xen/hypercall-defs.h: $(obj)/hypercall-defs.i $(srctree)/scripts/gen_hypercall.awk FORCE
+	$(call if_changed,genhyp)
+
+targets += xen/hypercall-defs.h
+
 ifeq ($(XEN_TARGET_ARCH),$(XEN_COMPILE_ARCH))
 
 all: $(obj)/headers.chk $(obj)/headers99.chk $(obj)/headers++.chk

xen/include/Makefile all: lib-x86-all · line 147

Quoted 4 lines
xen/include/Makefile +1 -0
@@ -132,3 +144,4 @@ all: lib-x86-all
 endif
 
 clean-files := compat config generated headers*.chk xen/lib/x86/cpuid-autogen.h
+clean-files += xen/hypercall-defs.h hypercall-defs.i

I've committed this as-is (with just fuzz suitably resolved), despite being uncertain whether xen/hypercall-defs.h - being part of targets - actually needs enumerating here (anymore).

Jan

#18 lore raw

Re: [PATCH v6 5/9] xen: generate hypercall interface related code

Quoted 25 lines · Jan Beulich
Quoted 24 lines · Juergen Gross
xen/include/Makefile +12 -0
@@ -77,6 +77,18 @@ $(obj)/compat/xlat.h: $(addprefix $(obj)/compat/.xlat/,$(xlat-y)) $(obj)/config/
  	cat $(filter %.h,$^) >[email protected]
  	mv -f [email protected] $@
 
+quiet_cmd_genhyp = GEN     $@
+define cmd_genhyp
+    awk -f $(srctree)/scripts/gen_hypercall.awk <$< >$@
+endef
+
+all: $(obj)/xen/hypercall-defs.h
+
+$(obj)/xen/hypercall-defs.h: $(obj)/hypercall-defs.i $(srctree)/scripts/gen_hypercall.awk FORCE
+	$(call if_changed,genhyp)
+
+targets += xen/hypercall-defs.h
+
  ifeq ($(XEN_TARGET_ARCH),$(XEN_COMPILE_ARCH))
 
  all: $(obj)/headers.chk $(obj)/headers99.chk $(obj)/headers++.chk
@@ -132,3 +144,4 @@ all: lib-x86-all
  endif
 
Quoted 6 lines

xen/include/Makefile all: lib-x86-all · line 147

Quoted 2 lines
xen/include/Makefile +1 -0
  clean-files := compat config generated headers*.chk xen/lib/x86/cpuid-autogen.h
+clean-files += xen/hypercall-defs.h hypercall-defs.i

I've committed this as-is (with just fuzz suitably resolved), despite being uncertain whether xen/hypercall-defs.h - being part of targets - actually needs enumerating here (anymore).

Without it being enumerated "make clean" will still remove it. So it is obviously not needed.

Sending a patch ...

Juergen

#19 lore raw

PATCH v6 6/9 xen: use generated prototypes for hypercall handlers

In reply to Juergen Gross

Remove the hypercall handler's prototypes in the related header files and use the generated ones instead.

Some handlers having been static before need to be made globally visible.

---
 xen/arch/arm/include/asm/hypercall.h |   1 -
 xen/arch/x86/hvm/hypercall.c         |   7 +-
 xen/arch/x86/include/asm/hypercall.h | 141 ---------------------
 xen/include/xen/hypercall.h          | 177 +--------------------------
 4 files changed, 5 insertions(+), 321 deletions(-)
xen/arch/arm/include/asm/hypercall.h +0 -1
index 8182895358..ccd26c5184 100644
@@ -6,7 +6,6 @@
 #define __ASM_ARM_HYPERCALL_H__
 
 #include <public/domctl.h> /* for arch_do_domctl */
-int do_arm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);
 
 long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
                        XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
xen/arch/x86/hvm/hypercall.c +3 -4
index 3a35543997..a9c9ad721f 100644
@@ -31,8 +31,7 @@
 #include <public/hvm/hvm_op.h>
 #include <public/hvm/params.h>
 
-static long cf_check hvm_memory_op(
-    unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+long cf_check hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     long rc;
 
@@ -52,7 +51,7 @@ static long cf_check hvm_memory_op(
 }
 
 #ifdef CONFIG_GRANT_TABLE
-static long cf_check hvm_grant_table_op(
+long cf_check hvm_grant_table_op(
     unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop, unsigned int count)
 {
     switch ( cmd )
@@ -78,7 +77,7 @@ static long cf_check hvm_grant_table_op(
 }
 #endif
 
-static long cf_check hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+long cf_check hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     const struct vcpu *curr = current;
     const struct domain *currd = curr->domain;
xen/arch/x86/include/asm/hypercall.h +0 -141

153 lines not on this page · raw message

xen/include/xen/hypercall.h +2 -175

205 lines not on this page · raw message

Signature · 1 line
2.34.1
#20 lore raw

PATCH v6 7/9 xen/x86: call hypercall handlers via generated macro

In reply to Juergen Gross

Instead of using a function table use the generated macros for calling the appropriate hypercall handlers.

This is beneficial to performance and avoids speculation issues.

With calling the handlers using the correct number of parameters now it is possible to do the parameter register clobbering in the NDEBUG case after returning from the handler. With the additional generated data the hard coded hypercall_args_table[] can be replaced by tables using the generated number of parameters.

Note that this change modifies behavior of clobbering registers in a minor way: in case a hypercall is returning -ENOSYS (or the unsigned equivalent thereof) for any reason the parameter registers will no longer be clobbered. This should be of no real concern, as those cases ought to be extremely rare and reuse of the registers in those cases seems rather far fetched.

---
V2:
- make hypercall_args_*[] const (Jan Beulich)
- make clobber_regs*() independent from NDEBUG (Jan Beulich)
- drop "L" suffix for 32-bit register clobber value (Jan Beulich) V3:
- add array_access_nospec() (Jan Beulich)
- remove local variables in hvm_hypercall() (Andrew Cooper)

---
 xen/arch/x86/hvm/hypercall.c         | 166 +++---------------------
 xen/arch/x86/hypercall.c             |  59 ---------
 xen/arch/x86/include/asm/hypercall.h |  55 ++++++--
 xen/arch/x86/pv/hypercall.c          | 184 +++------------------------
 4 files changed, 76 insertions(+), 388 deletions(-)
xen/arch/x86/hvm/hypercall.c +17 -149
index a9c9ad721f..ae601185fc 100644
@@ -111,56 +111,10 @@ long cf_check hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return compat_physdev_op(cmd, arg);
 }
 
-#define HYPERCALL(x)                                         \
-    [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) do_ ## x,  \
-                               (hypercall_fn_t *) do_ ## x }
-
-#define HVM_CALL(x)                                          \
-    [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) hvm_ ## x, \
-                               (hypercall_fn_t *) hvm_ ## x }
-
-#define COMPAT_CALL(x)                                       \
-    [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) do_ ## x,  \
-                               (hypercall_fn_t *) compat_ ## x }
-
-static const struct {
-    hypercall_fn_t *native, *compat;
-} hvm_hypercall_table[] = {
-    HVM_CALL(memory_op),
-    COMPAT_CALL(multicall),
-#ifdef CONFIG_GRANT_TABLE
-    HVM_CALL(grant_table_op),
-#endif
-    HYPERCALL(vm_assist),
-    COMPAT_CALL(vcpu_op),
-    HVM_CALL(physdev_op),
-    COMPAT_CALL(xen_version),
-    HYPERCALL(console_io),
-    HYPERCALL(event_channel_op),
-    COMPAT_CALL(sched_op),
-    COMPAT_CALL(set_timer_op),
-    COMPAT_CALL(xsm_op),
-    HYPERCALL(hvm_op),
-    HYPERCALL(sysctl),
-    HYPERCALL(domctl),
-#ifdef CONFIG_ARGO
-    COMPAT_CALL(argo_op),
-#endif
-    COMPAT_CALL(platform_op),
-#ifdef CONFIG_PV
-    COMPAT_CALL(mmuext_op),
-#endif
-    HYPERCALL(xenpmu_op),
-    COMPAT_CALL(dm_op),
-#ifdef CONFIG_HYPFS
-    HYPERCALL(hypfs_op),
+#ifndef NDEBUG
+static const unsigned char hypercall_args_64[] = hypercall_args_hvm64;
+static const unsigned char hypercall_args_32[] = hypercall_args_hvm32;
 #endif
-    HYPERCALL(paging_domctl_cont)
-};
-
-#undef HYPERCALL
-#undef HVM_CALL
-#undef COMPAT_CALL
 
 int hvm_hypercall(struct cpu_user_regs *regs)
 {
@@ -206,23 +160,6 @@ int hvm_hypercall(struct cpu_user_regs *regs)
         return ret;
     }
 
-    BUILD_BUG_ON(ARRAY_SIZE(hvm_hypercall_table) >
-                 ARRAY_SIZE(hypercall_args_table));
-
-    if ( eax >= ARRAY_SIZE(hvm_hypercall_table) )
-    {
-        regs->rax = -ENOSYS;
-        return HVM_HCALL_completed;
-    }
-
-    eax = array_index_nospec(eax, ARRAY_SIZE(hvm_hypercall_table));
-
-    if ( !hvm_hypercall_table[eax].native )
-    {
-        regs->rax = -ENOSYS;
-        return HVM_HCALL_completed;
-    }
-
     /*
      * Caching is intended for instruction emulation only. Disable it
      * for any accesses by hypercall argument copy-in / copy-out.
@@ -233,85 +170,27 @@ int hvm_hypercall(struct cpu_user_regs *regs)
 
     if ( mode == 8 )
     {
-        unsigned long rdi = regs->rdi;
-        unsigned long rsi = regs->rsi;
-        unsigned long rdx = regs->rdx;
-        unsigned long r10 = regs->r10;
-        unsigned long r8 = regs->r8;
-
         HVM_DBG_LOG(DBG_LEVEL_HCALL, "hcall%lu(%lx, %lx, %lx, %lx, %lx)",
-                    eax, rdi, rsi, rdx, r10, r8);
-
-#ifndef NDEBUG
-        /* Deliberately corrupt parameter regs not used by this hypercall. */
-        switch ( hypercall_args_table[eax].native )
-        {
-        case 0: rdi = 0xdeadbeefdeadf00dUL; fallthrough;
-        case 1: rsi = 0xdeadbeefdeadf00dUL; fallthrough;
-        case 2: rdx = 0xdeadbeefdeadf00dUL; fallthrough;
-        case 3: r10 = 0xdeadbeefdeadf00dUL; fallthrough;
-        case 4: r8 = 0xdeadbeefdeadf00dUL;
-        }
-#endif
+                    eax, regs->rdi, regs->rsi, regs->rdx, regs->r10, regs->r8);
 
-        regs->rax = hvm_hypercall_table[eax].native(rdi, rsi, rdx, r10, r8);
+        call_handlers_hvm64(eax, regs->rax, regs->rdi, regs->rsi, regs->rdx,
+                            regs->r10, regs->r8);
 
-#ifndef NDEBUG
-        if ( !curr->hcall_preempted )
-        {
-            /* Deliberately corrupt parameter regs used by this hypercall. */
-            switch ( hypercall_args_table[eax].native )
-            {
-            case 5: regs->r8  = 0xdeadbeefdeadf00dUL; fallthrough;
-            case 4: regs->r10 = 0xdeadbeefdeadf00dUL; fallthrough;
-            case 3: regs->rdx = 0xdeadbeefdeadf00dUL; fallthrough;
-            case 2: regs->rsi = 0xdeadbeefdeadf00dUL; fallthrough;
-            case 1: regs->rdi = 0xdeadbeefdeadf00dUL;
-            }
-        }
-#endif
+        if ( !curr->hcall_preempted && regs->rax != -ENOSYS )
+            clobber_regs(regs, get_nargs(hypercall_args_64, eax));
     }
     else
     {
-        unsigned int ebx = regs->ebx;
-        unsigned int ecx = regs->ecx;
-        unsigned int edx = regs->edx;
-        unsigned int esi = regs->esi;
-        unsigned int edi = regs->edi;
-
         HVM_DBG_LOG(DBG_LEVEL_HCALL, "hcall%lu(%x, %x, %x, %x, %x)", eax,
-                    ebx, ecx, edx, esi, edi);
-
-#ifndef NDEBUG
-        /* Deliberately corrupt parameter regs not used by this hypercall. */
-        switch ( hypercall_args_table[eax].compat )
-        {
-        case 0: ebx = 0xdeadf00d; fallthrough;
-        case 1: ecx = 0xdeadf00d; fallthrough;
-        case 2: edx = 0xdeadf00d; fallthrough;
-        case 3: esi = 0xdeadf00d; fallthrough;
-        case 4: edi = 0xdeadf00d;
-        }
-#endif
+                    regs->ebx, regs->ecx, regs->edx, regs->esi, regs->edi);
 
         curr->hcall_compat = true;
-        regs->eax = hvm_hypercall_table[eax].compat(ebx, ecx, edx, esi, edi);
+        call_handlers_hvm32(eax, regs->eax, regs->ebx, regs->ecx, regs->edx,
+                            regs->esi, regs->edi);
         curr->hcall_compat = false;
 
-#ifndef NDEBUG
-        if ( !curr->hcall_preempted )
-        {
-            /* Deliberately corrupt parameter regs used by this hypercall. */
-            switch ( hypercall_args_table[eax].compat )
-            {
-            case 5: regs->rdi = 0xdeadf00d; fallthrough;
-            case 4: regs->rsi = 0xdeadf00d; fallthrough;
-            case 3: regs->rdx = 0xdeadf00d; fallthrough;
-            case 2: regs->rcx = 0xdeadf00d; fallthrough;
-            case 1: regs->rbx = 0xdeadf00d;
-            }
-        }
-#endif
+        if ( !curr->hcall_preempted && regs->eax != -ENOSYS )
+            clobber_regs32(regs, get_nargs(hypercall_args_32, eax));
     }
 
     hvmemul_cache_restore(curr, token);
@@ -332,31 +211,20 @@ int hvm_hypercall(struct cpu_user_regs *regs)
 enum mc_disposition hvm_do_multicall_call(struct mc_state *state)
 {
     struct vcpu *curr = current;
-    hypercall_fn_t *func = NULL;
 
     if ( hvm_guest_x86_mode(curr) == 8 )
     {
         struct multicall_entry *call = &state->call;
 
-        if ( call->op < ARRAY_SIZE(hvm_hypercall_table) )
-            func = array_access_nospec(hvm_hypercall_table, call->op).native;
-        if ( func )
-            call->result = func(call->args[0], call->args[1], call->args[2],
-                                call->args[3], call->args[4]);
-        else
-            call->result = -ENOSYS;
+        call_handlers_hvm64(call->op, call->result, call->args[0], call->args[1],
+                            call->args[2], call->args[3], call->args[4]);
     }
     else
     {
         struct compat_multicall_entry *call = &state->compat_call;
 
-        if ( call->op < ARRAY_SIZE(hvm_hypercall_table) )
-            func = array_access_nospec(hvm_hypercall_table, call->op).compat;
-        if ( func )
-            call->result = func(call->args[0], call->args[1], call->args[2],
-                                call->args[3], call->args[4]);
-        else
-            call->result = -ENOSYS;
+        call_handlers_hvm32(call->op, call->result, call->args[0], call->args[1],
+                            call->args[2], call->args[3], call->args[4]);
     }
 
     return !hvm_get_cpl(curr) ? mc_continue : mc_preempt;
xen/arch/x86/hypercall.c +0 -59

65 lines not on this page · raw message

xen/arch/x86/include/asm/hypercall.h +42 -13

65 lines not on this page · raw message

xen/arch/x86/pv/hypercall.c +17 -167

241 lines not on this page · raw message

Signature · 1 line
2.34.1
#21 lore raw

PATCH v6 8/9 xen/arm: call hypercall handlers via generated macro

In reply to Juergen Gross

Instead of using a function table use the generated macros for calling the appropriate hypercall handlers.

This makes the calls of the handlers type safe.

For deprecated hypercalls define stub functions.

---
V2:
- make hypercall_args[] const (Jan Beulich)
V5:
- move out-of-bounds check (Julien Grall)

---
 xen/arch/arm/traps.c | 117 +++++++++----------------------------------
 1 file changed, 24 insertions(+), 93 deletions(-)
xen/arch/arm/traps.c +24 -93
index e906bb4a89..e0fca3b4d8 100644
@@ -1331,67 +1331,20 @@ static register_t do_deprecated_hypercall(void)
     return -ENOSYS;
 }
 
-typedef register_t (*arm_hypercall_fn_t)(
-    register_t, register_t, register_t, register_t, register_t);
-
-typedef struct {
-    arm_hypercall_fn_t fn;
-    int nr_args;
-} arm_hypercall_t;
-
-#define HYPERCALL(_name, _nr_args)                                   \
-    [ __HYPERVISOR_ ## _name ] =  {                                  \
-        .fn = (arm_hypercall_fn_t) &do_ ## _name,                    \
-        .nr_args = _nr_args,                                         \
-    }
+long dep_sched_op_compat(int cmd, unsigned long arg)
+{
+    return do_deprecated_hypercall();
+}
 
-#define HYPERCALL_ARM(_name, _nr_args)                        \
-    [ __HYPERVISOR_ ## _name ] =  {                                  \
-        .fn = (arm_hypercall_fn_t) &do_arm_ ## _name,                \
-        .nr_args = _nr_args,                                         \
-    }
-/*
- * Only use this for hypercalls which were deprecated (i.e. replaced
- * by something else) before Xen on ARM was created, i.e. *not* for
- * hypercalls which are simply not yet used on ARM.
- */
-#define HYPERCALL_DEPRECATED(_name, _nr_args)                   \
-    [ __HYPERVISOR_##_name ] = {                                \
-        .fn = (arm_hypercall_fn_t) &do_deprecated_hypercall,    \
-        .nr_args = _nr_args,                                    \
-    }
+long dep_event_channel_op_compat(XEN_GUEST_HANDLE_PARAM(evtchn_op_t) uop)
+{
+    return do_deprecated_hypercall();
+}
 
-static arm_hypercall_t arm_hypercall_table[] = {
-    HYPERCALL(memory_op, 2),
-    HYPERCALL(domctl, 1),
-    HYPERCALL(sched_op, 2),
-    HYPERCALL_DEPRECATED(sched_op_compat, 2),
-    HYPERCALL(console_io, 3),
-    HYPERCALL(xen_version, 2),
-    HYPERCALL(xsm_op, 1),
-    HYPERCALL(event_channel_op, 2),
-    HYPERCALL_DEPRECATED(event_channel_op_compat, 1),
-    HYPERCALL_ARM(physdev_op, 2),
-    HYPERCALL_DEPRECATED(physdev_op_compat, 1),
-    HYPERCALL(sysctl, 2),
-    HYPERCALL(hvm_op, 2),
-#ifdef CONFIG_GRANT_TABLE
-    HYPERCALL(grant_table_op, 3),
-#endif
-    HYPERCALL(multicall, 2),
-    HYPERCALL(platform_op, 1),
-    HYPERCALL(vcpu_op, 3),
-    HYPERCALL(vm_assist, 2),
-#ifdef CONFIG_ARGO
-    HYPERCALL(argo_op, 5),
-#endif
-#ifdef CONFIG_HYPFS
-    HYPERCALL(hypfs_op, 5),
-#endif
-#ifdef CONFIG_IOREQ_SERVER
-    HYPERCALL(dm_op, 3),
-#endif
-};
+long dep_physdev_op_compat(XEN_GUEST_HANDLE_PARAM(physdev_op_t) uop)
+{
+    return do_deprecated_hypercall();
+}
 
 #ifndef NDEBUG
 static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code)
@@ -1430,7 +1383,6 @@ static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code)
 #define HYPERCALL_ARG3(r) (r)->x2
 #define HYPERCALL_ARG4(r) (r)->x3
 #define HYPERCALL_ARG5(r) (r)->x4
-#define HYPERCALL_ARGS(r) (r)->x0, (r)->x1, (r)->x2, (r)->x3, (r)->x4
 #else
 #define HYPERCALL_RESULT_REG(r) (r)->r0
 #define HYPERCALL_ARG1(r) (r)->r0
@@ -1438,52 +1390,40 @@ static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code)
 #define HYPERCALL_ARG3(r) (r)->r2
 #define HYPERCALL_ARG4(r) (r)->r3
 #define HYPERCALL_ARG5(r) (r)->r4
-#define HYPERCALL_ARGS(r) (r)->r0, (r)->r1, (r)->r2, (r)->r3, (r)->r4
 #endif
 
+static const unsigned char hypercall_args[] = hypercall_args_arm;
+
 static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,
                               const union hsr hsr)
 {
-    arm_hypercall_fn_t call = NULL;
     struct vcpu *curr = current;
 
-    BUILD_BUG_ON(NR_hypercalls < ARRAY_SIZE(arm_hypercall_table) );
-
     if ( hsr.iss != XEN_HYPERCALL_TAG )
     {
         gprintk(XENLOG_WARNING, "Invalid HVC imm 0x%x\n", hsr.iss);
         return inject_undef_exception(regs, hsr);
     }
 
-    if ( *nr >= ARRAY_SIZE(arm_hypercall_table) )
-    {
-        perfc_incr(invalid_hypercalls);
-        HYPERCALL_RESULT_REG(regs) = -ENOSYS;
-        return;
-    }
-
     curr->hcall_preempted = false;
 
     perfc_incra(hypercalls, *nr);
-    call = arm_hypercall_table[*nr].fn;
-    if ( call == NULL )
-    {
-        HYPERCALL_RESULT_REG(regs) = -ENOSYS;
-        return;
-    }
 
-    HYPERCALL_RESULT_REG(regs) = call(HYPERCALL_ARGS(regs));
+    call_handlers_arm(*nr, HYPERCALL_RESULT_REG(regs), HYPERCALL_ARG1(regs),
+                      HYPERCALL_ARG2(regs), HYPERCALL_ARG3(regs),
+                      HYPERCALL_ARG4(regs), HYPERCALL_ARG5(regs));
 
 #ifndef NDEBUG
-    if ( !curr->hcall_preempted )
+    if ( !curr->hcall_preempted && HYPERCALL_RESULT_REG(regs) != -ENOSYS )
     {
         /* Deliberately corrupt parameter regs used by this hypercall. */
-        switch ( arm_hypercall_table[*nr].nr_args ) {
+        switch ( hypercall_args[*nr] ) {
         case 5: HYPERCALL_ARG5(regs) = 0xDEADBEEF;
         case 4: HYPERCALL_ARG4(regs) = 0xDEADBEEF;
         case 3: HYPERCALL_ARG3(regs) = 0xDEADBEEF;
         case 2: HYPERCALL_ARG2(regs) = 0xDEADBEEF;
         case 1: /* Don't clobber x0/r0 -- it's the return value */
+        case 0: /* -ENOSYS case */
             break;
         default: BUG();
         }
@@ -1520,7 +1460,7 @@ static bool check_multicall_32bit_clean(struct multicall_entry *multi)
 {
     int i;
 
-    for ( i = 0; i < arm_hypercall_table[multi->op].nr_args; i++ )
+    for ( i = 0; i < hypercall_args[multi->op]; i++ )
     {
         if ( unlikely(multi->args[i] & 0xffffffff00000000ULL) )
         {
@@ -1537,16 +1477,8 @@ static bool check_multicall_32bit_clean(struct multicall_entry *multi)
 enum mc_disposition arch_do_multicall_call(struct mc_state *state)
 {
     struct multicall_entry *multi = &state->call;
-    arm_hypercall_fn_t call = NULL;
-
-    if ( multi->op >= ARRAY_SIZE(arm_hypercall_table) )
-    {
-        multi->result = -ENOSYS;
-        return mc_continue;
-    }
 
-    call = arm_hypercall_table[multi->op].fn;
-    if ( call == NULL )
+    if ( multi->op >= ARRAY_SIZE(hypercall_args) )
     {
         multi->result = -ENOSYS;
         return mc_continue;
@@ -1556,9 +1488,8 @@ enum mc_disposition arch_do_multicall_call(struct mc_state *state)
          !check_multicall_32bit_clean(multi) )
         return mc_continue;
 
-    multi->result = call(multi->args[0], multi->args[1],
-                         multi->args[2], multi->args[3],
-                         multi->args[4]);
+    call_handlers_arm(multi->op, multi->result, multi->args[0], multi->args[1],
+                      multi->args[2], multi->args[3], multi->args[4]);
 
     return likely(!regs_mode_is_user(guest_cpu_user_regs()))
            ? mc_continue : mc_preempt;
Signature · 1 line
2.34.1
#22 lore raw

PATCH v6 9/9 xen/x86: remove cf_check attribute from hypercall handlers

In reply to Juergen Gross

Now that the hypercall handlers are all being called directly instead through a function vector, the "cf_check" attribute can be removed.

---
V4:
- new patch

---
 xen/arch/x86/compat.c               |  6 +++---
 xen/arch/x86/cpu/mcheck/mce.c       |  2 +-
 xen/arch/x86/cpu/vpmu.c             |  2 +-
 xen/arch/x86/domain.c               |  3 +--
 xen/arch/x86/hvm/dm.c               |  2 +-
 xen/arch/x86/hvm/hvm.c              |  2 +-
 xen/arch/x86/hvm/hypercall.c        |  6 +++---
 xen/arch/x86/mm.c                   | 12 ++++++------
 xen/arch/x86/mm/paging.c            |  2 +-
 xen/arch/x86/physdev.c              |  2 +-
 xen/arch/x86/platform_hypercall.c   |  2 +-
 xen/arch/x86/pv/callback.c          | 16 ++++++++--------
 xen/arch/x86/pv/descriptor-tables.c |  8 ++++----
 xen/arch/x86/pv/iret.c              |  4 ++--
 xen/arch/x86/pv/misc-hypercalls.c   | 10 +++++-----
 xen/arch/x86/pv/shim.c              |  4 ++--
 xen/arch/x86/x86_64/compat/mm.c     |  2 +-
 xen/arch/x86/x86_64/domain.c        |  2 +-
 xen/common/argo.c                   |  4 ++--
 xen/common/compat/grant_table.c     |  2 +-
 xen/common/compat/kernel.c          |  2 +-
 xen/common/compat/memory.c          |  3 +--
 xen/common/dm.c                     |  2 +-
 xen/common/domain.c                 |  2 +-
 xen/common/domctl.c                 |  2 +-
 xen/common/event_channel.c          |  2 +-
 xen/common/grant_table.c            |  3 +--
 xen/common/hypfs.c                  |  2 +-
 xen/common/kernel.c                 |  2 +-
 xen/common/kexec.c                  |  4 ++--
 xen/common/memory.c                 |  2 +-
 xen/common/multicall.c              |  3 +--
 xen/common/sched/compat.c           |  2 +-
 xen/common/sched/core.c             |  4 ++--
 xen/common/sysctl.c                 |  2 +-
 xen/common/xenoprof.c               |  2 +-
 xen/drivers/char/console.c          |  2 +-
 xen/scripts/gen_hypercall.awk       |  2 +-
 xen/xsm/xsm_core.c                  |  4 ++--
 39 files changed, 68 insertions(+), 72 deletions(-)
xen/arch/x86/compat.c +3 -3
index 28281a262a..a031062830 100644
@@ -15,7 +15,7 @@ typedef long ret_t;
 #endif
 
 /* Legacy hypercall (as of 0x00030202). */
-ret_t cf_check do_physdev_op_compat(XEN_GUEST_HANDLE_PARAM(physdev_op_t) uop)
+ret_t do_physdev_op_compat(XEN_GUEST_HANDLE_PARAM(physdev_op_t) uop)
 {
     struct physdev_op op;
 
@@ -28,7 +28,7 @@ ret_t cf_check do_physdev_op_compat(XEN_GUEST_HANDLE_PARAM(physdev_op_t) uop)
 #ifndef COMPAT
 
 /* Legacy hypercall (as of 0x00030101). */
-long cf_check do_sched_op_compat(int cmd, unsigned long arg)
+long do_sched_op_compat(int cmd, unsigned long arg)
 {
     switch ( cmd )
     {
@@ -50,7 +50,7 @@ long cf_check do_sched_op_compat(int cmd, unsigned long arg)
 }
 
 /* Legacy hypercall (as of 0x00030202). */
-long cf_check do_event_channel_op_compat(
+long do_event_channel_op_compat(
     XEN_GUEST_HANDLE_PARAM(evtchn_op_t) uop)
 {
     struct evtchn_op op;
xen/arch/x86/cpu/mcheck/mce.c +1 -1
index 275c54be7c..f68e31b643 100644
@@ -1351,7 +1351,7 @@ CHECK_mcinfo_recovery;
 # endif /* CONFIG_COMPAT */
 
 /* Machine Check Architecture Hypercall */
-long cf_check do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
+long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
 {
     long ret = 0;
     struct xen_mc curop, *op = &curop;
xen/arch/x86/cpu/vpmu.c +1 -1
index 51d171615f..d2c03a1104 100644
@@ -672,7 +672,7 @@ void vpmu_dump(struct vcpu *v)
         alternative_vcall(vpmu_ops.arch_vpmu_dump, v);
 }
 
-long cf_check do_xenpmu_op(
+long do_xenpmu_op(
     unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg)
 {
     int ret;
xen/arch/x86/domain.c +1 -2
index d566fc82b4..ddf969f76e 100644
@@ -1489,8 +1489,7 @@ int arch_vcpu_reset(struct vcpu *v)
     return 0;
 }
 
-long cf_check do_vcpu_op(int cmd, unsigned int vcpuid,
-                         XEN_GUEST_HANDLE_PARAM(void) arg)
+long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     long rc = 0;
     struct domain *d = current->domain;
xen/arch/x86/hvm/dm.c +1 -1
index d80975efcf..f8e6089870 100644
@@ -654,7 +654,7 @@ CHECK_dm_op_relocate_memory;
 CHECK_dm_op_pin_memory_cacheattr;
 CHECK_dm_op_nr_vcpus;
 
-int cf_check compat_dm_op(
+int compat_dm_op(
     domid_t domid, unsigned int nr_bufs, XEN_GUEST_HANDLE_PARAM(void) bufs)
 {
     struct dmop_args args;
xen/arch/x86/hvm/hvm.c +1 -1
index 709a4191ef..9b3973dad8 100644
@@ -5022,7 +5022,7 @@ static int hvmop_get_mem_type(
     return rc;
 }
 
-long cf_check do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
+long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     long rc = 0;
 
xen/arch/x86/hvm/hypercall.c +3 -3
index ae601185fc..29d1ca7a13 100644
@@ -31,7 +31,7 @@
 #include <public/hvm/hvm_op.h>
 #include <public/hvm/params.h>
 
-long cf_check hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     long rc;
 
@@ -51,7 +51,7 @@ long cf_check hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 }
 
 #ifdef CONFIG_GRANT_TABLE
-long cf_check hvm_grant_table_op(
+long hvm_grant_table_op(
     unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop, unsigned int count)
 {
     switch ( cmd )
@@ -77,7 +77,7 @@ long cf_check hvm_grant_table_op(
 }
 #endif
 
-long cf_check hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     const struct vcpu *curr = current;
     const struct domain *currd = curr->domain;
xen/arch/x86/mm.c +6 -6
index 6cc73187ac..a958142d17 100644
@@ -3377,7 +3377,7 @@ static int vcpumask_to_pcpumask(
     }
 }
 
-long cf_check do_mmuext_op(
+long do_mmuext_op(
     XEN_GUEST_HANDLE_PARAM(mmuext_op_t) uops,
     unsigned int count,
     XEN_GUEST_HANDLE_PARAM(uint) pdone,
@@ -3916,7 +3916,7 @@ long cf_check do_mmuext_op(
     return rc;
 }
 
-long cf_check do_mmu_update(
+long do_mmu_update(
     XEN_GUEST_HANDLE_PARAM(mmu_update_t) ureqs,
     unsigned int count,
     XEN_GUEST_HANDLE_PARAM(uint) pdone,
@@ -4501,7 +4501,7 @@ static int __do_update_va_mapping(
     return rc;
 }
 
-long cf_check do_update_va_mapping(
+long do_update_va_mapping(
     unsigned long va, u64 val64, unsigned long flags)
 {
     int rc = __do_update_va_mapping(va, val64, flags, current->domain);
@@ -4513,7 +4513,7 @@ long cf_check do_update_va_mapping(
     return rc;
 }
 
-long cf_check do_update_va_mapping_otherdomain(
+long do_update_va_mapping_otherdomain(
     unsigned long va, u64 val64, unsigned long flags, domid_t domid)
 {
     struct domain *pg_owner;
@@ -4536,7 +4536,7 @@ long cf_check do_update_va_mapping_otherdomain(
 #endif /* CONFIG_PV */
 
 #ifdef CONFIG_PV32
-int cf_check compat_update_va_mapping(
+int compat_update_va_mapping(
     unsigned int va, uint32_t lo, uint32_t hi, unsigned int flags)
 {
     int rc = __do_update_va_mapping(va, ((uint64_t)hi << 32) | lo,
@@ -4549,7 +4549,7 @@ int cf_check compat_update_va_mapping(
     return rc;
 }
 
-int cf_check compat_update_va_mapping_otherdomain(
+int compat_update_va_mapping_otherdomain(
     unsigned int va, uint32_t lo, uint32_t hi, unsigned int flags,
     domid_t domid)
 {
xen/arch/x86/mm/paging.c +1 -1
index a7e2707ecc..cb1bfcbde5 100644
@@ -760,7 +760,7 @@ int paging_domctl(struct domain *d, struct xen_domctl_shadow_op *sc,
         return shadow_domctl(d, sc, u_domctl);
 }
 
-long cf_check do_paging_domctl_cont(
+long do_paging_domctl_cont(
     XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
     struct xen_domctl op;
xen/arch/x86/physdev.c +1 -1
index 2ddcf44f33..ea38be8b79 100644
@@ -174,7 +174,7 @@ int physdev_unmap_pirq(domid_t domid, int pirq)
 }
 #endif /* COMPAT */
 
-ret_t cf_check do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     int irq;
     ret_t ret;
xen/arch/x86/platform_hypercall.c +1 -1
index eeb4f7a20e..a7341dc3d7 100644
@@ -214,7 +214,7 @@ void cf_check resource_access(void *info)
 }
 #endif
 
-ret_t cf_check do_platform_op(
+ret_t do_platform_op(
     XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op)
 {
     ret_t ret;
xen/arch/x86/pv/callback.c +8 -8
index 1be9d3f731..067ee3b795 100644
@@ -140,7 +140,7 @@ static long unregister_guest_callback(struct callback_unregister *unreg)
     return ret;
 }
 
-long cf_check do_callback_op(int cmd, XEN_GUEST_HANDLE_PARAM(const_void) arg)
+long do_callback_op(int cmd, XEN_GUEST_HANDLE_PARAM(const_void) arg)
 {
     long ret;
 
@@ -178,7 +178,7 @@ long cf_check do_callback_op(int cmd, XEN_GUEST_HANDLE_PARAM(const_void) arg)
     return ret;
 }
 
-long cf_check do_set_callbacks(
+long do_set_callbacks(
     unsigned long event_address, unsigned long failsafe_address,
     unsigned long syscall_address)
 {
@@ -283,7 +283,7 @@ static int compat_unregister_guest_callback(
     return ret;
 }
 
-int cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(const_void) arg)
+int compat_callback_op(int cmd, XEN_GUEST_HANDLE(const_void) arg)
 {
     int ret;
 
@@ -321,7 +321,7 @@ int cf_check compat_callback_op(int cmd, XEN_GUEST_HANDLE(const_void) arg)
     return ret;
 }
 
-int cf_check compat_set_callbacks(
+int compat_set_callbacks(
     unsigned long event_selector, unsigned long event_address,
     unsigned long failsafe_selector, unsigned long failsafe_address)
 {
@@ -348,7 +348,7 @@ int cf_check compat_set_callbacks(
 
 #endif /* CONFIG_PV32 */
 
-long cf_check do_set_trap_table(XEN_GUEST_HANDLE_PARAM(const_trap_info_t) traps)
+long do_set_trap_table(XEN_GUEST_HANDLE_PARAM(const_trap_info_t) traps)
 {
     struct trap_info cur;
     struct vcpu *curr = current;
@@ -394,7 +394,7 @@ long cf_check do_set_trap_table(XEN_GUEST_HANDLE_PARAM(const_trap_info_t) traps)
 }
 
 #ifdef CONFIG_PV32
-int cf_check compat_set_trap_table(XEN_GUEST_HANDLE(trap_info_compat_t) traps)
+int compat_set_trap_table(XEN_GUEST_HANDLE(trap_info_compat_t) traps)
 {
     struct vcpu *curr = current;
     struct compat_trap_info cur;
@@ -437,7 +437,7 @@ int cf_check compat_set_trap_table(XEN_GUEST_HANDLE(trap_info_compat_t) traps)
 }
 #endif
 
-long cf_check do_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+long do_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     struct xennmi_callback cb;
     long rc = 0;
@@ -463,7 +463,7 @@ long cf_check do_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 }
 
 #ifdef CONFIG_PV32
-int cf_check compat_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+int compat_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     struct compat_nmi_callback cb;
     int rc = 0;
xen/arch/x86/pv/descriptor-tables.c +4 -4
index 653a61d0b5..b4135b450c 100644
@@ -124,7 +124,7 @@ int pv_set_gdt(struct vcpu *v, const unsigned long frames[],
     return -EINVAL;
 }
 
-long cf_check do_set_gdt(
+long do_set_gdt(
     XEN_GUEST_HANDLE_PARAM(xen_ulong_t) frame_list, unsigned int entries)
 {
     unsigned int nr_frames = DIV_ROUND_UP(entries, 512);
@@ -151,7 +151,7 @@ long cf_check do_set_gdt(
 
 #ifdef CONFIG_PV32
 
-int cf_check compat_set_gdt(
+int compat_set_gdt(
     XEN_GUEST_HANDLE_PARAM(uint) frame_list, unsigned int entries)
 {
     struct vcpu *curr = current;
@@ -187,7 +187,7 @@ int cf_check compat_set_gdt(
     return ret;
 }
 
-int cf_check compat_update_descriptor(
+int compat_update_descriptor(
     uint32_t pa_lo, uint32_t pa_hi, uint32_t desc_lo, uint32_t desc_hi)
 {
     seg_desc_t d;
@@ -299,7 +299,7 @@ int validate_segdesc_page(struct page_info *page)
     return i == 512 ? 0 : -EINVAL;
 }
 
-long cf_check do_update_descriptor(uint64_t gaddr, seg_desc_t d)
+long do_update_descriptor(uint64_t gaddr, seg_desc_t d)
 {
     struct domain *currd = current->domain;
     gfn_t gfn = gaddr_to_gfn(gaddr);
xen/arch/x86/pv/iret.c +2 -2
index 58de9f7922..316a23e77e 100644
@@ -49,7 +49,7 @@ static void async_exception_cleanup(struct vcpu *curr)
         curr->arch.async_exception_state(trap).old_mask;
 }
 
-long cf_check do_iret(void)
+long do_iret(void)
 {
     struct cpu_user_regs *regs = guest_cpu_user_regs();
     struct iret_context iret_saved;
@@ -106,7 +106,7 @@ long cf_check do_iret(void)
 }
 
 #ifdef CONFIG_PV32
-int cf_check compat_iret(void)
+int compat_iret(void)
 {
     struct cpu_user_regs *regs = guest_cpu_user_regs();
     struct vcpu *v = current;
xen/arch/x86/pv/misc-hypercalls.c +5 -5
index 635f5a644a..aaaf70eb63 100644
@@ -23,12 +23,12 @@
 
 #include <asm/debugreg.h>
 
-long cf_check do_set_debugreg(int reg, unsigned long value)
+long do_set_debugreg(int reg, unsigned long value)
 {
     return set_debugreg(current, reg, value);
 }
 
-long cf_check do_get_debugreg(int reg)
+long do_get_debugreg(int reg)
 {
     /* Avoid implementation defined behavior casting unsigned long to long. */
     union {
@@ -40,7 +40,7 @@ long cf_check do_get_debugreg(int reg)
     return res == X86EMUL_OKAY ? u.ret : -ENODEV;
 }
 
-long cf_check do_fpu_taskswitch(int set)
+long do_fpu_taskswitch(int set)
 {
     struct vcpu *v = current;
 
@@ -175,7 +175,7 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
     return 0;
 }
 
-long cf_check do_stack_switch(unsigned long ss, unsigned long esp)
+long do_stack_switch(unsigned long ss, unsigned long esp)
 {
     fixup_guest_stack_selector(current->domain, ss);
     current->arch.pv.kernel_ss = ss;
@@ -184,7 +184,7 @@ long cf_check do_stack_switch(unsigned long ss, unsigned long esp)
     return 0;
 }
 
-long cf_check do_set_segment_base(unsigned int which, unsigned long base)
+long do_set_segment_base(unsigned int which, unsigned long base)
 {
     struct vcpu *v = current;
     long ret = 0;
xen/arch/x86/pv/shim.c +2 -2
index 2ee290a392..2b74fea181 100644
@@ -824,7 +824,7 @@ long pv_shim_grant_table_op(unsigned int cmd,
 
 #ifndef CONFIG_GRANT_TABLE
 /* Thin wrapper(s) needed. */
-long cf_check do_grant_table_op(
+long do_grant_table_op(
     unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop, unsigned int count)
 {
     if ( !pv_shim )
@@ -834,7 +834,7 @@ long cf_check do_grant_table_op(
 }
 
 #ifdef CONFIG_PV32
-int cf_check compat_grant_table_op(
+int compat_grant_table_op(
     unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop, unsigned int count)
 {
     if ( !pv_shim )
xen/arch/x86/x86_64/compat/mm.c +1 -1
index 70b08a832a..d54efaad21 100644
@@ -177,7 +177,7 @@ int compat_arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 #ifdef CONFIG_PV
 DEFINE_XEN_GUEST_HANDLE(mmuext_op_compat_t);
 
-int cf_check compat_mmuext_op(
+int compat_mmuext_op(
     XEN_GUEST_HANDLE_PARAM(void) arg, unsigned int count,
     XEN_GUEST_HANDLE_PARAM(uint) pdone, unsigned int foreigndom)
 {
xen/arch/x86/x86_64/domain.c +1 -1
index 9c559aa3ea..62fe51ee74 100644
@@ -12,7 +12,7 @@
 CHECK_vcpu_get_physid;
 #undef xen_vcpu_get_physid
 
-int cf_check
+int
 compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     int rc;
xen/common/argo.c +2 -2
index 26a01c2188..748b8714d6 100644
@@ -2069,7 +2069,7 @@ sendv(struct domain *src_d, xen_argo_addr_t *src_addr,
     return ( ret < 0 ) ? ret : len;
 }
 
-long cf_check
+long
 do_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
            XEN_GUEST_HANDLE_PARAM(void) arg2, unsigned long raw_arg3,
            unsigned long raw_arg4)
@@ -2207,7 +2207,7 @@ do_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
 }
 
 #ifdef CONFIG_COMPAT
-int cf_check
+int
 compat_argo_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg1,
                XEN_GUEST_HANDLE_PARAM(void) arg2, unsigned long arg3,
                unsigned long arg4)
xen/common/compat/grant_table.c +1 -1
index d5787e3719..4705ee5f76 100644
@@ -56,7 +56,7 @@ CHECK_gnttab_swap_grant_ref;
 CHECK_gnttab_cache_flush;
 #undef xen_gnttab_cache_flush
 
-int cf_check compat_grant_table_op(
+int compat_grant_table_op(
     unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) cmp_uop, unsigned int count)
 {
     int rc = 0;
xen/common/compat/kernel.c +1 -1
index 8e8c413bf1..804b919bdc 100644
@@ -37,7 +37,7 @@ CHECK_TYPE(capabilities_info);
 
 CHECK_TYPE(domain_handle);
 
-#define DO(fn) int cf_check compat_##fn
+#define DO(fn) int compat_##fn
 #define COMPAT
 
 #include "../kernel.c"
xen/common/compat/memory.c +1 -2
index 077ded4a75..ce1de1b307 100644
@@ -53,8 +53,7 @@ static int cf_check get_reserved_device_memory(
 }
 #endif
 
-int cf_check compat_memory_op(
-    unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
+int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
 {
     struct vcpu *curr = current;
     struct domain *currd = curr->domain;
xen/common/dm.c +1 -1
index fcb3a1aa05..201b652deb 100644
@@ -19,7 +19,7 @@
 #include <xen/hypercall.h>
 #include <xen/nospec.h>
 
-long cf_check do_dm_op(
+long do_dm_op(
     domid_t domid, unsigned int nr_bufs,
     XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs)
 {
xen/common/domain.c +1 -1
index 70747c02e6..2f8efbb6d8 100644
@@ -1754,7 +1754,7 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
 }
 
 #ifdef arch_vm_assist_valid_mask
-long cf_check do_vm_assist(unsigned int cmd, unsigned int type)
+long do_vm_assist(unsigned int cmd, unsigned int type)
 {
     struct domain *currd = current->domain;
     const unsigned long valid = arch_vm_assist_valid_mask(currd);
xen/common/domctl.c +1 -1
index 9606fa4f1a..879a2adcbe 100644
@@ -274,7 +274,7 @@ static struct vnuma_info *vnuma_init(const struct xen_domctl_vnuma *uinfo,
     return ERR_PTR(ret);
 }
 
-long cf_check do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
+long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
     long ret = 0;
     bool_t copyback = 0;
xen/common/event_channel.c +1 -1
index 0a82eb3ac2..5e2420fa12 100644
@@ -1191,7 +1191,7 @@ static int evtchn_set_priority(const struct evtchn_set_priority *set_priority)
     return ret;
 }
 
-long cf_check do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     int rc;
 
xen/common/grant_table.c +1 -2
index febbe12eab..c71d3ad24b 100644
@@ -3559,8 +3559,7 @@ gnttab_cache_flush(XEN_GUEST_HANDLE_PARAM(gnttab_cache_flush_t) uop,
     return 0;
 }
 
-long cf_check
-do_grant_table_op(
+long do_grant_table_op(
     unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) uop, unsigned int count)
 {
     long rc;
xen/common/hypfs.c +1 -1
index 0d22396f5d..acd258edf2 100644
@@ -670,7 +670,7 @@ static int hypfs_write(struct hypfs_entry *entry,
     return entry->funcs->write(l, uaddr, ulen);
 }
 
-long cf_check do_hypfs_op(
+long do_hypfs_op(
     unsigned int cmd, XEN_GUEST_HANDLE_PARAM(const_char) arg1,
     unsigned long arg2, XEN_GUEST_HANDLE_PARAM(void) arg3, unsigned long arg4)
 {
xen/common/kernel.c +1 -1
index adff2d2c77..08bdae082a 100644
@@ -451,7 +451,7 @@ static int __init cf_check param_init(void)
 __initcall(param_init);
 #endif
 
-# define DO(fn) long cf_check do_##fn
+# define DO(fn) long do_##fn
 
 #endif
 
xen/common/kexec.c +2 -2
index 41669964d2..7095651605 100644
@@ -1265,13 +1265,13 @@ static int do_kexec_op_internal(unsigned int op,
     return ret;
 }
 
-long cf_check do_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
+long do_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
 {
     return do_kexec_op_internal(op, uarg, 0);
 }
 
 #ifdef CONFIG_COMPAT
-int cf_check compat_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
+int compat_kexec_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(void) uarg)
 {
     return do_kexec_op_internal(op, uarg, 1);
 }
xen/common/memory.c +1 -1
index 69b0cd1e50..963f4df1b6 100644
@@ -1367,7 +1367,7 @@ static int acquire_resource(
     return rc;
 }
 
-long cf_check do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     struct domain *d, *curr_d = current->domain;
     long rc;
xen/common/multicall.c +1 -2
index 9db49092b4..1f0cc4cb26 100644
@@ -33,8 +33,7 @@ static void trace_multicall_call(multicall_entry_t *call)
     __trace_multicall_call(call);
 }
 
-ret_t cf_check
-do_multicall(
+ret_t do_multicall(
     XEN_GUEST_HANDLE_PARAM(multicall_entry_t) call_list, uint32_t nr_calls)
 {
     struct vcpu *curr = current;
xen/common/sched/compat.c +1 -1
index 66ba0fe88f..040b4caca2 100644
@@ -39,7 +39,7 @@ static int compat_poll(struct compat_sched_poll *compat)
 
 #include "core.c"
 
-int cf_check compat_set_timer_op(u32 lo, s32 hi)
+int compat_set_timer_op(u32 lo, s32 hi)
 {
     return do_set_timer_op(((s64)hi << 32) | lo);
 }
xen/common/sched/core.c +2 -2
index 19ab678181..25885b5640 100644
@@ -1862,7 +1862,7 @@ typedef long ret_t;
 
 #endif /* !COMPAT */
 
-ret_t cf_check do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     ret_t ret = 0;
 
@@ -1999,7 +1999,7 @@ ret_t cf_check do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 #ifndef COMPAT
 
 /* Per-vcpu oneshot-timer hypercall. */
-long cf_check do_set_timer_op(s_time_t timeout)
+long do_set_timer_op(s_time_t timeout)
 {
     struct vcpu *v = current;
     s_time_t offset = timeout - NOW();
xen/common/sysctl.c +1 -1
index fc4a0b31d6..1ad3c29351 100644
@@ -29,7 +29,7 @@
 #include <xen/livepatch.h>
 #include <xen/coverage.h>
 
-long cf_check do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
+long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
 {
     long ret = 0;
     int copyback = -1;
xen/common/xenoprof.c +1 -1
index af617f1d0b..1926a92fe4 100644
@@ -721,7 +721,7 @@ static int xenoprof_op_get_buffer(XEN_GUEST_HANDLE_PARAM(void) arg)
                       || (op == XENOPROF_disable_virq)  \
                       || (op == XENOPROF_get_buffer))
  
-ret_t cf_check do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)
+ret_t do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     int ret = 0;
     
xen/drivers/char/console.c +1 -1
index d9d6556c22..c53fe30313 100644
@@ -675,7 +675,7 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,
     return 0;
 }
 
-long cf_check do_console_io(
+long do_console_io(
     unsigned int cmd, unsigned int count, XEN_GUEST_HANDLE_PARAM(char) buffer)
 {
     long rc;
xen/scripts/gen_hypercall.awk +1 -1
index 403758be21..34840c514f 100644
@@ -226,7 +226,7 @@ END {
     # Generate prototypes
     for (i = 1; i <= n; i++) {
         for (p = 1; p <= n_pre[i]; p++) {
-            printf("%s cf_check %s_%s(", rettype[pre[i, p]], pre[i, p], fn[i]);
+            printf("%s %s_%s(", rettype[pre[i, p]], pre[i, p], fn[i]);
             if (n_args[i] == 0)
                 printf("void");
             else
xen/xsm/xsm_core.c +2 -2
index 2286a502e3..eaa028109b 100644
@@ -219,13 +219,13 @@ bool __init has_xsm_magic(paddr_t start)
 
 #endif
 
-long cf_check do_xsm_op(XEN_GUEST_HANDLE_PARAM(void) op)
+long do_xsm_op(XEN_GUEST_HANDLE_PARAM(void) op)
 {
     return xsm_do_xsm_op(op);
 }
 
 #ifdef CONFIG_COMPAT
-int cf_check compat_xsm_op(XEN_GUEST_HANDLE_PARAM(void) op)
+int compat_xsm_op(XEN_GUEST_HANDLE_PARAM(void) op)
 {
     return xsm_do_compat_op(op);
 }
Signature · 1 line
2.34.1
Acked-by on v6 9/9
#23 lore raw

Re: [PATCH v6 9/9] xen/x86: remove cf_check attribute from hypercall handlers

Quoted 9 lines · Juergen Gross

Now that the hypercall handlers are all being called directly instead through a function vector, the "cf_check" attribute can be removed.

parts

Regards

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)
#24 lore raw
In reply to Juergen Gross
Quoted 9 lines · Juergen Gross

In order to avoid indirect function calls on the hypercall path as much as possible this series is removing the hypercall function tables and is replacing the hypercall handler calls via the function array by automatically generated call macros.

Another by-product of generating the call macros is the automatic generating of the hypercall handler prototypes from the same data base which is used to generate the macros.

Quoted 8 lines

This has the additional advantage of using type safe calls of the handlers and to ensure related handler (e.g. PV and HVM ones) share the same prototypes.

A very brief performance test (parallel build of the Xen hypervisor in a 6 vcpu guest) showed a very slim improvement (less than 1%) of the performance with the patches applied. The test was performed using a PV and a PVH guest.

A gentle ping regarding this series.

I think patch 1 still lacks an Ack from x86 side. Other than that patches 1, 2 and 4 should be fine to go in, as they are cleanups which are fine on their own IMHO.

Andrew, you wanted to get some performance numbers of the series using the Citrix test environment. Any news on the progress here?

Juergen

#25 lore raw
Quoted 19 lines · Juergen Gross
Quoted 9 lines · Juergen Gross

In order to avoid indirect function calls on the hypercall path as much as possible this series is removing the hypercall function tables and is replacing the hypercall handler calls via the function array by automatically generated call macros.

Another by-product of generating the call macros is the automatic generating of the hypercall handler prototypes from the same data base which is used to generate the macros.

Quoted 8 lines

This has the additional advantage of using type safe calls of the handlers and to ensure related handler (e.g. PV and HVM ones) share the same prototypes.

A very brief performance test (parallel build of the Xen hypervisor in a 6 vcpu guest) showed a very slim improvement (less than 1%) of the performance with the patches applied. The test was performed using a PV and a PVH guest.

Quoted 8 lines

A gentle ping regarding this series.

I think patch 1 still lacks an Ack from x86 side. Other than that patches 1, 2 and 4 should be fine to go in, as they are cleanups which are fine on their own IMHO.

Andrew, you wanted to get some performance numbers of the series using the Citrix test environment. Any news on the progress here?

And another ping.

Andrew, could you please give some feedback regarding performance testing progress?

Juergen

#26 lore raw
Quoted 26 lines · Juergen Gross
Quoted 25 lines · Juergen Gross
Quoted 9 lines · Juergen Gross

In order to avoid indirect function calls on the hypercall path as much as possible this series is removing the hypercall function tables and is replacing the hypercall handler calls via the function array by automatically generated call macros.

Another by-product of generating the call macros is the automatic generating of the hypercall handler prototypes from the same data base which is used to generate the macros.

Quoted 8 lines

This has the additional advantage of using type safe calls of the handlers and to ensure related handler (e.g. PV and HVM ones) share the same prototypes.

A very brief performance test (parallel build of the Xen hypervisor in a 6 vcpu guest) showed a very slim improvement (less than 1%) of the performance with the patches applied. The test was performed using a PV and a PVH guest.

A gentle ping regarding this series.

I think patch 1 still lacks an Ack from x86 side. Other than that patches 1, 2 and 4 should be fine to go in, as they are cleanups which are fine on their own IMHO.

Quoted 7 lines
Quoted 2 lines

Andrew, you wanted to get some performance numbers of the series using the Citrix test environment. Any news on the progress here?

And another ping.

Andrew, could you please give some feedback regarding performance testing progress?

This is becoming ridiculous. Andrew, I know you are busy, but not reacting at all to explicit questions is kind of annoying.

BTW, the question regarding patches 1, 2 and 4 to go in as being cleanups still stands.

Juergen

#27 lore raw
Quoted 2 lines · Juergen Gross

BTW, the question regarding patches 1, 2 and 4 to go in as being cleanups still stands.

I would long have committed these (without waiting for Andrew), but patch 1 continues to lack an x86 side ack (which, as indicated before, I'm not happy to provide, while I also don't mean to nak the change). From an earlier attempt I also seem to recall that patches 2 and 4 can't go in ahead of patch 1.

Jan

#28 lore raw
In reply to Juergen Gross
Quoted 30 lines · Juergen Gross
Quoted 29 lines · Juergen Gross
Quoted 27 lines · Juergen Gross
Quoted 9 lines · Juergen Gross

In order to avoid indirect function calls on the hypercall path as much as possible this series is removing the hypercall function tables and is replacing the hypercall handler calls via the function array by automatically generated call macros.

Another by-product of generating the call macros is the automatic generating of the hypercall handler prototypes from the same data base which is used to generate the macros.

Quoted 8 lines

This has the additional advantage of using type safe calls of the handlers and to ensure related handler (e.g. PV and HVM ones) share the same prototypes.

A very brief performance test (parallel build of the Xen hypervisor in a 6 vcpu guest) showed a very slim improvement (less than 1%) of the performance with the patches applied. The test was performed using a PV and a PVH guest.

A gentle ping regarding this series.

I think patch 1 still lacks an Ack from x86 side. Other than that patches 1, 2 and 4 should be fine to go in, as they are cleanups which are fine on their own IMHO.

Andrew, you wanted to get some performance numbers of the series using the Citrix test environment. Any news on the progress here?

Quoted 7 lines
Quoted 4 lines

And another ping.

Andrew, could you please give some feedback regarding performance testing progress?

This is becoming ridiculous. Andrew, I know you are busy, but not reacting at all to explicit questions is kind of annoying.

____ ___ _ _ ____

|  _ \_ _| \ | |/ ___|
| |_) | ||  \| | |  _
|  __/| || |\  | |_| |
|_|  |___|_| \_|\____|

Juergen

#29 lore raw
In reply to Juergen Gross
Quoted 30 lines · Juergen Gross
Quoted 29 lines · Juergen Gross
Quoted 27 lines · Juergen Gross
Quoted 9 lines · Juergen Gross

In order to avoid indirect function calls on the hypercall path as much as possible this series is removing the hypercall function tables and is replacing the hypercall handler calls via the function array by automatically generated call macros.

Another by-product of generating the call macros is the automatic generating of the hypercall handler prototypes from the same data base which is used to generate the macros.

Quoted 8 lines

This has the additional advantage of using type safe calls of the handlers and to ensure related handler (e.g. PV and HVM ones) share the same prototypes.

A very brief performance test (parallel build of the Xen hypervisor in a 6 vcpu guest) showed a very slim improvement (less than 1%) of the performance with the patches applied. The test was performed using a PV and a PVH guest.

A gentle ping regarding this series.

I think patch 1 still lacks an Ack from x86 side. Other than that patches 1, 2 and 4 should be fine to go in, as they are cleanups which are fine on their own IMHO.

Andrew, you wanted to get some performance numbers of the series using the Citrix test environment. Any news on the progress here?

Quoted 7 lines
Quoted 4 lines

And another ping.

Andrew, could you please give some feedback regarding performance testing progress?

This is becoming ridiculous. Andrew, I know you are busy, but not reacting at all to explicit questions is kind of annoying.

  ____ ___ _   _  ____
|  _ \_ _| \ | |/ ___|
| |_) | ||  \| | |  _
|  __/| || |\  | |_| |
|_|  |___|_| \_|\____|

Juergen

#30 lore raw
In reply to Juergen Gross

Hi,

It seems that this series has been stale for more than 3 months, with:

Patch #1 merged.
Patch #2 need feedback regarding the kexec and argo changes. Patch #3 #4 #5 #6 #7 #8 #9 reviewed/acked.

So sending this as a gentle reminder for kexec and argo maintainers. Thanks!

Kind regards,
Henry

Quoted 121 lines

-----Original Message-----
Subject: [PATCH v6 0/9] xen: drop hypercall function tables

In order to avoid indirect function calls on the hypercall path as much as possible this series is removing the hypercall function tables and is replacing the hypercall handler calls via the function array by automatically generated call macros.

Another by-product of generating the call macros is the automatic generating of the hypercall handler prototypes from the same data base which is used to generate the macros.

This has the additional advantage of using type safe calls of the handlers and to ensure related handler (e.g. PV and HVM ones) share the same prototypes.

A very brief performance test (parallel build of the Xen hypervisor in a 6 vcpu guest) showed a very slim improvement (less than 1%) of the performance with the patches applied. The test was performed using a PV and a PVH guest.

Changes in V2:
- new patches 6, 14, 15
- patch 7: support hypercall priorities for faster code
- comments addressed

Changes in V3:
- patches 1 and 4 removed as already applied
- comments addressed

Changes in V4:
- 5 patches removed al already applied
- new patches 1, 3 and 11
- avoid switching Arm hypercall handlers to return long (no change of handlers returning long already)

Changes in V5:
- patch 3 of V4 has been applied already
- comments addressed
- rebase

Changes in V6:
- patch 1 of V5 has been applied already
- fix of a rebase artifact

Juergen Gross (9):
xen: move do_vcpu_op() to arch specific code
xen: harmonize return types of hypercall handlers
xen: don't include asm/hypercall.h from C sources
xen: include compat/platform.h from hypercall.h
xen: generate hypercall interface related code
xen: use generated prototypes for hypercall handlers xen/x86: call hypercall handlers via generated macro xen/arm: call hypercall handlers via generated macro xen/x86: remove cf_check attribute from hypercall handlers

 .gitignore                               |   1 +
 xen/arch/arm/domain.c                    |  15 +-
 xen/arch/arm/hvm.c                       |   3 +-
 xen/arch/arm/include/asm/hypercall.h     |   7 +-
 xen/arch/arm/platform_hypercall.c        |   1 +
 xen/arch/arm/traps.c                     | 117 ++-------
 xen/arch/x86/compat.c                    |   6 +-
 xen/arch/x86/cpu/mcheck/mce.c            |   2 +-
 xen/arch/x86/cpu/vpmu.c                  |   3 +-
 xen/arch/x86/domain.c                    |  11 +-
 xen/arch/x86/domctl.c                    |   4 +-
 xen/arch/x86/hvm/dm.c                    |   2 +-
 xen/arch/x86/hvm/hvm.c                   |   2 +-
 xen/arch/x86/hvm/hypercall.c             | 177 ++-----------
 xen/arch/x86/hypercall.c                 |  59 -----
 xen/arch/x86/include/asm/hypercall.h     | 201 ++++-----------
 xen/arch/x86/include/asm/paging.h        |   3 -
 xen/arch/x86/mm.c                        |  13 +-
 xen/arch/x86/mm/paging.c                 |   3 +-
 xen/arch/x86/physdev.c                   |   2 +-
 xen/arch/x86/platform_hypercall.c        |   3 +-
 xen/arch/x86/pv/callback.c               |  26 +-
 xen/arch/x86/pv/descriptor-tables.c      |   8 +-
 xen/arch/x86/pv/emul-priv-op.c           |   2 +-
 xen/arch/x86/pv/hypercall.c              | 187 ++------------
 xen/arch/x86/pv/iret.c                   |   5 +-
 xen/arch/x86/pv/misc-hypercalls.c        |  22 +-
 xen/arch/x86/pv/shim.c                   |   4 +-
 xen/arch/x86/traps.c                     |   2 +-
 xen/arch/x86/x86_64/compat/mm.c          |   3 +-
 xen/arch/x86/x86_64/domain.c             |  16 +-
 xen/arch/x86/x86_64/mm.c                 |   2 -
 xen/arch/x86/x86_64/platform_hypercall.c |   1 -
 xen/common/argo.c                        |   8 +-
 xen/common/compat/domain.c               |  15 +-
 xen/common/compat/grant_table.c          |   3 +-
 xen/common/compat/kernel.c               |   2 +-
 xen/common/compat/memory.c               |   3 +-
 xen/common/dm.c                          |   2 +-
 xen/common/domain.c                      |  14 +-
 xen/common/domctl.c                      |   2 +-
 xen/common/event_channel.c               |   3 +-
 xen/common/grant_table.c                 |   4 +-
 xen/common/hypfs.c                       |   2 +-
 xen/common/kernel.c                      |   2 +-
 xen/common/kexec.c                       |   6 +-
 xen/common/memory.c                      |   2 +-
 xen/common/multicall.c                   |   4 +-
 xen/common/sched/compat.c                |   2 +-
 xen/common/sched/core.c                  |   4 +-
 xen/common/sysctl.c                      |   2 +-
 xen/common/xenoprof.c                    |   2 +-
 xen/drivers/char/console.c               |   2 +-
 xen/include/Makefile                     |  13 +
 xen/include/hypercall-defs.c             | 285 ++++++++++++++++++++
 xen/include/xen/hypercall.h              | 185 +------------
 xen/scripts/gen_hypercall.awk            | 314 +++++++++++++++++++++++
 xen/xsm/xsm_core.c                       |   4 +-
 58 files changed, 861 insertions(+), 937 deletions(-)
 create mode 100644 xen/include/hypercall-defs.c
 create mode 100644 xen/scripts/gen_hypercall.awk

--
2.34.1

#31 lore raw
Quoted 7 lines · Henry Wang

It seems that this series has been stale for more than 3 months, with:

Patch #1 merged.
Patch #2 need feedback regarding the kexec and argo changes. Patch #3 #4 #5 #6 #7 #8 #9 reviewed/acked.

So sending this as a gentle reminder for kexec and argo maintainers.

Patch 3 was also merged. Patch 2 and 4 indeed only wait for said acks. Patches 5 and onwards are pending a clarification by Andrew as to performance concerns he had voiced. Jürgen did send a number of pings, with no result at all.

Jan

#32 lore raw

Hi Jan,

Quoted 11 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Subject: Re: [PATCH v6 0/9] xen: drop hypercall function tables

Quoted 6 lines · Henry Wang

It seems that this series has been stale for more than 3 months, with:

Patch #1 merged.
Patch #2 need feedback regarding the kexec and argo changes. Patch #3 #4 #5 #6 #7 #8 #9 reviewed/acked.

Quoted 6 lines
Quoted 1 line

So sending this as a gentle reminder for kexec and argo maintainers.

Patch 3 was also merged. Patch 2 and 4 indeed only wait for said acks. Patches 5 and onwards are pending a clarification by Andrew as to performance concerns he had voiced. Jürgen did send a number of pings, with no result at all.

Thanks for the information, let me just put Andrew (for kexec and Patch from #5) and Christopher (for argo) in the TO: list to see if they can receive the ping.

Kind regards,
Henry

Quoted 2 lines

Jan

#33 lore raw

***PING***: [PATCH v6 0/9] xen: drop hypercall function tables

In reply to Juergen Gross

Andrew,

Quoted 10 lines · Juergen Gross

Juergen Gross (9):
xen: move do_vcpu_op() to arch specific code
xen: harmonize return types of hypercall handlers
xen: don't include asm/hypercall.h from C sources
xen: include compat/platform.h from hypercall.h
xen: generate hypercall interface related code
xen: use generated prototypes for hypercall handlers xen/x86: call hypercall handlers via generated macro xen/arm: call hypercall handlers via generated macro xen/x86: remove cf_check attribute from hypercall handlers

we've discussed the state of this on the Community Call today. Unfortunately you weren't there. It was common consensus that we've waited long enough here, so unless very good reasons (including a timeline) appear very quickly, the plan is to commit the series (with REST acks to stand in for the few small areas were acks are still missing) early next week. Should performance issues really turn out excessively bad, we can still consider reverting down the road; I don't expect we would want to go that route though, and rather make incremental adjustments as necessary.

Thanks for your understanding,
Jan