Skip to contentSkip to conversation

x86: pvh: allow to disable 32-bit (COMPAT) interface support

PATCH In review Grygorii Strashko 5 participants 14 messages Nov 19, 2025 – Dec 19, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover x86: pvh: allow to disable 32-bit (COMPAT) interface support

From: Grygorii Strashko <[email protected]>

Hi

This series introduces possibility to disable 32-bit (COMPAT) interface support in the following case:
- Only PVH domains are used
- Guests (OS) are started by using direct Direct Kernel Boot
- Guests (OS) are 64-bit and Guest early boot code, which is running not in 64-bit mode, does not access Xen interfaces (hypercalls, shared_info, ..)

If above criterias are met the COMPAT HVM interface become unreachable and can be disabled. Coverage reports analyze and adding guard (debug) exceptions in hvm_hypercall/hvm_do_multicall_call and hvm_latch_shinfo_size() confirm that COMPAT HVM interface is unused for safety use-case.

Changes in v2 described in each patch:
- patch "x86: constify has_32bit_shinfo() if !CONFIG_COMPAT" squashed in patch 2.

v1:
https://patchwork.kernel.org/project/xen-devel/cover/[email protected]/

Grygorii Strashko (4):
x86: hvm: dm: factor out compat code under ifdefs
x86: hvm: compat: introduce is_hcall_compat() helper
x86: hvm: factor out COMPAT code under ifdefs
x86: pvh: allow to disable 32-bit interface support

 xen/arch/x86/hvm/Kconfig          | 19 ++++++++++++++++++-
 xen/arch/x86/hvm/dm.c             |  2 ++
 xen/arch/x86/hvm/hvm.c            | 24 ++++++++++++++++++++----
 xen/arch/x86/hvm/hypercall.c      | 22 +++++++++++++++++-----
 xen/arch/x86/hypercall.c          |  6 +-----
 xen/arch/x86/include/asm/domain.h |  9 +++++++--
 xen/common/kernel.c               |  2 +-
 xen/include/hypercall-defs.c      |  9 +++++++--
 xen/include/xen/sched.h           |  9 +++++++++
 9 files changed, 82 insertions(+), 20 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/4 x86: hvm: dm: factor out compat code under ifdefs

From: Grygorii Strashko <[email protected]>

Factor out COMPAT HVM DM code under ifdefs in preparation for making HVM COMPAT code optional.

---
changes in v2:
- no changes

 xen/arch/x86/hvm/dm.c | 2 ++
 1 file changed, 2 insertions(+)
xen/arch/x86/hvm/dm.c +2 -0
index 3b53471af0d9..f6dd1634428a 100644
@@ -623,6 +623,7 @@ int dm_op(const struct dmop_args *op_args)
     return rc;
 }
 
+#ifdef CONFIG_COMPAT
 #include <compat/hvm/dm_op.h>
 
 CHECK_dm_op_create_ioreq_server;
@@ -680,6 +681,7 @@ int compat_dm_op(
 
     return rc;
 }
+#endif /* CONFIG_COMPAT */
 
 /*
  * Local variables:
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/4 x86: hvm: compat: introduce is_hcall_compat() helper

In reply to Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Introduce is_hcall_compat() helper and use it instead of direct access to struct vcpu->hcall_compat field in preparation for making HVM COMPAT code optional. The vcpu->hcall_compat field is under CONFIG_COMPAT ifdefs already.

---
changes in v2:
- change to bool is_hcall_compat(void)

 xen/arch/x86/hvm/hvm.c       | 8 ++++----
 xen/arch/x86/hvm/hypercall.c | 9 ++++-----
 xen/arch/x86/hypercall.c     | 6 +-----
 xen/common/kernel.c          | 2 +-
 xen/include/xen/sched.h      | 9 +++++++++
 5 files changed, 19 insertions(+), 15 deletions(-)
xen/arch/x86/hvm/hvm.c +4 -4
index 0ff242d4a0d6..0fd3f95b6e0e 100644
@@ -3500,7 +3500,7 @@ unsigned int copy_to_user_hvm(void *to, const void *from, unsigned int len)
 {
     int rc;
 
-    if ( current->hcall_compat && is_compat_arg_xlat_range(to, len) )
+    if ( is_hcall_compat() && is_compat_arg_xlat_range(to, len) )
     {
         memcpy(to, from, len);
         return 0;
@@ -3514,7 +3514,7 @@ unsigned int clear_user_hvm(void *to, unsigned int len)
 {
     int rc;
 
-    if ( current->hcall_compat && is_compat_arg_xlat_range(to, len) )
+    if ( is_hcall_compat() && is_compat_arg_xlat_range(to, len) )
     {
         memset(to, 0x00, len);
         return 0;
@@ -3529,7 +3529,7 @@ unsigned int copy_from_user_hvm(void *to, const void *from, unsigned int len)
 {
     int rc;
 
-    if ( current->hcall_compat && is_compat_arg_xlat_range(from, len) )
+    if ( is_hcall_compat() && is_compat_arg_xlat_range(from, len) )
     {
         memcpy(to, from, len);
         return 0;
@@ -5214,7 +5214,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
         break;
 
     case HVMOP_altp2m:
-        rc = current->hcall_compat ? compat_altp2m_op(arg) : do_altp2m_op(arg);
+        rc = is_hcall_compat() ? compat_altp2m_op(arg) : do_altp2m_op(arg);
         break;
 
     default:
xen/arch/x86/hvm/hypercall.c +4 -5
index b254b3e2f7d6..52cae1d15312 100644
@@ -29,7 +29,7 @@ long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return -ENOSYS;
     }
 
-    if ( !current->hcall_compat )
+    if ( !is_hcall_compat() )
         rc = do_memory_op(cmd, arg);
     else
         rc = compat_memory_op(cmd, arg);
@@ -57,7 +57,7 @@ long hvm_grant_table_op(
         return -ENOSYS;
     }
 
-    if ( !current->hcall_compat )
+    if ( !is_hcall_compat() )
         return do_grant_table_op(cmd, uop, count);
     else
         return compat_grant_table_op(cmd, uop, count);
@@ -66,8 +66,7 @@ long hvm_grant_table_op(
 
 long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
-    const struct vcpu *curr = current;
-    const struct domain *currd = curr->domain;
+    const struct domain *currd = current->domain;
 
     switch ( cmd )
     {
@@ -96,7 +95,7 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return -ENOSYS;
     }
 
-    if ( !curr->hcall_compat )
+    if ( !is_hcall_compat() )
         return do_physdev_op(cmd, arg);
     else
         return compat_physdev_op(cmd, arg);
xen/arch/x86/hypercall.c +1 -5
index dc0a90ca0915..5d1ac906fd37 100644
@@ -53,11 +53,7 @@ unsigned long hypercall_create_continuation(
 
         regs->rax = op;
 
-#ifdef CONFIG_COMPAT
-        if ( !curr->hcall_compat )
-#else
-        if ( true )
-#endif
+        if ( !is_hcall_compat() )
         {
             for ( i = 0; *p != '\0'; i++ )
             {
xen/common/kernel.c +1 -1
index e6979352e100..3ff06e315f57 100644
@@ -615,7 +615,7 @@ long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         const struct vcpu *curr = current;
 
 #ifdef CONFIG_COMPAT
-        if ( curr->hcall_compat )
+        if ( is_hcall_compat() )
         {
             compat_platform_parameters_t params = {
                 .virt_start = is_pv_vcpu(curr)
xen/include/xen/sched.h +9 -0
index 02bdc256ce37..ed6fdeeda9f9 100644
@@ -311,6 +311,15 @@ struct vcpu
 #endif
 };
 
+static inline bool is_hcall_compat(void)
+{
+#ifdef CONFIG_COMPAT
+    return current->hcall_compat;
+#else
+    return false;
+#endif /* CONFIG_COMPAT */
+}
+
 struct sched_unit {
     struct domain         *domain;
     struct vcpu           *vcpu_list;
Signature · 1 line
2.34.1
Reviewed-by on v2 2/4
#3 lore raw

Re: [XEN][PATCH v2 2/4] x86: hvm: compat: introduce is_hcall_compat() helper

Quoted 16 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Introduce is_hcall_compat() helper and use it instead of direct access to struct vcpu->hcall_compat field in preparation for making HVM COMPAT code optional. The vcpu->hcall_compat field is under CONFIG_COMPAT ifdefs already.

xen/include/xen/sched.h +0 -0
index 02bdc256ce37..ed6fdeeda9f9 100644
@@ -311,6 +311,15 @@ struct vcpu
  #endif
  };

xen/include/xen/sched.h struct vcpu · line 322

Quoted 10 lines
xen/include/xen/sched.h +9 -0
 
+static inline bool is_hcall_compat(void)
+{
+#ifdef CONFIG_COMPAT
+    return current->hcall_compat;
+#else
+    return false;
+#endif /* CONFIG_COMPAT */
+}
+

is_hcall_compat() matches the hcall_compat field, so I am okay with this.

However, is_compat_hcall() might be a slightly better name for the helper. For me at least, I think of these as "compat hypercalls", so that ordering reads a little more naturally for me. It's not a big deal, but I figured I'd mention it in case others have an opinion.

Thanks,
Jason

#4 lore raw

PATCH v2 3/4 x86: hvm: factor out COMPAT code under ifdefs

In reply to Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Factor out COMPAT HVM code under ifdefs in preparation for making HVM COMPAT code optional.

- hypercall-defs.c updated to always provide compat declaration for:
physdev_op, grant_table_op, grant_table_op. This reduces number of COMPAT ifdefs in HVM code and lets compiler DCE do the job.

- Only 64-bit shinfo is supported with COMPAT=n, so struct arch_domain->has_32bit_shinfo field is moved under COMPAT ifdef and has_32bit_shinfo() is updated to account for COMPAT=n.

---
changes in v2:
- update hypercall-defs.c to always provide compat declaration for:
physdev_op, grant_table_op, grant_table_op
- move struct arch_domain->has_32bit_shinfo is moved under COMPAT ifdef
- return hvm_hypercall()
- use ASSERT_UNREACHABLE() in hvm_do_multicall_call()
- constify has_32bit_shinfo() for COMPAT=n

 xen/arch/x86/hvm/hvm.c            | 16 ++++++++++++++++
 xen/arch/x86/hvm/hypercall.c      | 13 +++++++++++++
 xen/arch/x86/include/asm/domain.h |  9 +++++++--
 xen/include/hypercall-defs.c      |  9 +++++++--
 4 files changed, 43 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/hvm.c +16 -0
index 0fd3f95b6e0e..19524cb7a914 100644
@@ -69,7 +69,9 @@
 #include <public/version.h>
 #include <public/vm_event.h>
 
+#ifdef CONFIG_COMPAT
 #include <compat/hvm/hvm_op.h>
+#endif
 
 bool __read_mostly hvm_enabled;
 
@@ -1255,6 +1257,7 @@ static int cf_check hvm_save_cpu_xsave_states(
     return 0;
 }
 
+#ifdef CONFIG_COMPAT
 /*
  * Structure layout conformity checks, documenting correctness of the cast in
  * the invocation of validate_xstate() below.
@@ -1267,6 +1270,7 @@ CHECK_FIELD_(struct, xsave_hdr, xcomp_bv);
 CHECK_FIELD_(struct, xsave_hdr, reserved);
 #undef compat_xsave_hdr
 #undef xen_xsave_hdr
+#endif /* CONFIG_COMPAT */
 
 static int cf_check hvm_load_cpu_xsave_states(
     struct domain *d, hvm_domain_context_t *h)
@@ -3991,8 +3995,14 @@ static void hvm_latch_shinfo_size(struct domain *d)
      */
     if ( current->domain == d )
     {
+#ifdef CONFIG_COMPAT
+        /*
+         * Only 64-bit shinfo is supported when COMPAT 32-bit hypercalls
+         * interface is disabled
+         */
         d->arch.has_32bit_shinfo =
             hvm_guest_x86_mode(current) != X86_MODE_64BIT;
+#endif
 
         /*
          * Make sure that the timebase in the shared info structure is correct.
@@ -4965,6 +4975,7 @@ static int do_altp2m_op(
 #endif /* CONFIG_ALTP2M */
 }
 
+#ifdef CONFIG_COMPAT
 DEFINE_XEN_GUEST_HANDLE(compat_hvm_altp2m_op_t);
 
 /*
@@ -4992,10 +5003,12 @@ DEFINE_XEN_GUEST_HANDLE(compat_hvm_altp2m_op_t);
 
 CHECK_hvm_altp2m_op;
 CHECK_hvm_altp2m_set_mem_access_multi;
+#endif /* CONFIG_COMPAT */
 
 static int compat_altp2m_op(
     XEN_GUEST_HANDLE_PARAM(void) arg)
 {
+#ifdef CONFIG_COMPAT
     int rc = 0;
     struct compat_hvm_altp2m_op a;
     union
@@ -5063,6 +5076,9 @@ static int compat_altp2m_op(
     }
 
     return rc;
+#else
+    return -EOPNOTSUPP;
+#endif /* CONFIG_COMPAT */
 }
 
 static int hvmop_get_mem_type(
xen/arch/x86/hvm/hypercall.c +13 -0
index 52cae1d15312..1ee0193b69af 100644
@@ -170,6 +170,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)
         HVM_DBG_LOG(DBG_LEVEL_HCALL, "hcall%lu(%x, %x, %x, %x, %x)", eax,
                     regs->ebx, regs->ecx, regs->edx, regs->esi, regs->edi);
 
+#ifdef CONFIG_COMPAT
         curr->hcall_compat = true;
         call_handlers_hvm32(eax, regs->eax, regs->ebx, regs->ecx, regs->edx,
                             regs->esi, regs->edi);
@@ -177,6 +178,9 @@ int hvm_hypercall(struct cpu_user_regs *regs)
 
         if ( !curr->hcall_preempted && regs->eax != -ENOSYS )
             clobber_regs(regs, eax, hvm, 32);
+#else
+        regs->eax = -ENOSYS;
+#endif
     }
 
     hvmemul_cache_restore(curr, token);
@@ -207,10 +211,19 @@ enum mc_disposition hvm_do_multicall_call(struct mc_state *state)
     }
     else
     {
+#ifdef CONFIG_COMPAT
         struct compat_multicall_entry *call = &state->compat_call;
 
         call_handlers_hvm32(call->op, call->result, call->args[0], call->args[1],
                             call->args[2], call->args[3], call->args[4]);
+#else
+        /*
+         * code should never reach here in case !CONFIG_COMPAT as any
+         * 32-bit hypercall should bail out earlier from hvm_hypercall()
+         * with -EOPNOTSUPP
+         */
+        ASSERT_UNREACHABLE();
+#endif
     }
 
     return !hvm_get_cpl(curr) ? mc_continue : mc_preempt;
xen/arch/x86/include/asm/domain.h +7 -2
index 5df8c7825333..0005f4450931 100644
@@ -12,8 +12,11 @@
 #include <public/vcpu.h>
 #include <public/hvm/hvm_info_table.h>
 
-#define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)
-
+#ifdef CONFIG_COMPAT
+#define has_32bit_shinfo(d) ((d)->arch.has_32bit_shinfo)
+#else
+#define has_32bit_shinfo(d) ((void)(d), false)
+#endif
 /*
  * Set to true if either the global vector-type callback or per-vCPU
  * LAPIC vectors are used. Assume all vCPUs will use
@@ -365,8 +368,10 @@ struct arch_domain
     /* NB. protected by d->event_lock and by irq_desc[irq].lock */
     struct radix_tree_root irq_pirq;
 
+#ifdef CONFIG_COMPAT
     /* Is shared-info page in 32-bit format? */
     bool has_32bit_shinfo;
+#endif
 
     /* Is PHYSDEVOP_eoi to automatically unmask the event channel? */
     bool auto_unmask;
xen/include/hypercall-defs.c +7 -2
index cef08eeec1b8..08c01153ac56 100644
@@ -80,6 +80,8 @@ rettype: compat int
 #define PREFIX_compat
 #endif
 
+#define PREFIX_compat_always compat
+
 #ifdef CONFIG_ARM
 #define PREFIX_dep dep
 #define PREFIX_do_arm do_arm
@@ -104,10 +106,10 @@ defhandle: trap_info_compat_t
 defhandle: physdev_op_compat_t
 #endif
 
-prefix: do PREFIX_hvm PREFIX_compat PREFIX_do_arm
+prefix: do PREFIX_hvm PREFIX_compat_always PREFIX_do_arm
 physdev_op(int cmd, void *arg)
 
-prefix: do PREFIX_hvm PREFIX_compat
+prefix: do PREFIX_hvm PREFIX_compat_always
 #if defined(CONFIG_GRANT_TABLE) || defined(CONFIG_PV_SHIM)
 grant_table_op(unsigned int cmd, void *uop, unsigned int count)
 #endif
@@ -156,6 +158,9 @@ platform_op(compat_platform_op_t *u_xenpf_op)
 #ifdef CONFIG_KEXEC
 kexec_op(unsigned int op, void *uarg)
 #endif
+#else /* CONFIG_COMPAT */
+prefix: PREFIX_compat_always
+memory_op(unsigned int cmd, void *arg)
 #endif /* CONFIG_COMPAT */
 
 #if defined(CONFIG_PV) || defined(CONFIG_ARM)
Signature · 1 line
2.34.1
Reviewed-by on v2 3/4
#5 lore raw

Re: [XEN][PATCH v2 3/4] x86: hvm: factor out COMPAT code under ifdefs

Quoted 20 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Factor out COMPAT HVM code under ifdefs in preparation for making HVM COMPAT code optional.

- hypercall-defs.c updated to always provide compat declaration for:
physdev_op, grant_table_op, grant_table_op. This reduces number of COMPAT ifdefs in HVM code and lets compiler DCE do the job.

- Only 64-bit shinfo is supported with COMPAT=n, so struct arch_domain->has_32bit_shinfo field is moved under COMPAT ifdef and has_32bit_shinfo() is updated to account for COMPAT=n.

xen/arch/x86/include/asm/domain.h +0 -0
index 5df8c7825333..0005f4450931 100644

xen/arch/x86/include/asm/domain.h line 18

Quoted 9 lines
xen/arch/x86/include/asm/domain.h +4 -2
@@ -12,8 +12,11 @@
  #include <public/vcpu.h>
  #include <public/hvm/hvm_info_table.h>
 
-#define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)
-
+#ifdef CONFIG_COMPAT
+#define has_32bit_shinfo(d) ((d)->arch.has_32bit_shinfo)
+#else
+#define has_32bit_shinfo(d) ((void)(d), false)

(void)(d) is to avoid an any potential unreferenced 'd' messages?

Just using false builds for me, but your way is a little more robust.

xen/arch/x86/include/asm/domain.h line 22

Quoted 4 lines
xen/arch/x86/include/asm/domain.h +1 -0
+#endif
  /*
   * Set to true if either the global vector-type callback or per-vCPU
   * LAPIC vectors are used. Assume all vCPUs will use

Regards,
Jason

#6 lore raw

Re: [XEN][PATCH v2 3/4] x86: hvm: factor out COMPAT code under ifdefs

Quoted 16 lines · Jason Andryuk
Quoted 14 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Factor out COMPAT HVM code under ifdefs in preparation for making HVM COMPAT code optional.

- hypercall-defs.c updated to always provide compat declaration for:
physdev_op, grant_table_op, grant_table_op. This reduces number of COMPAT ifdefs in HVM code and lets compiler DCE do the job.

- Only 64-bit shinfo is supported with COMPAT=n, so struct arch_domain->has_32bit_shinfo field is moved under COMPAT ifdef and has_32bit_shinfo() is updated to account for COMPAT=n.

Quoted 15 lines

xen/arch/x86/include/asm/domain.h line 17

Quoted 13 lines
xen/arch/x86/include/asm/domain.h +4 -2
index 5df8c7825333..0005f4450931 100644
@@ -12,8 +12,11 @@
   #include <public/vcpu.h>
   #include <public/hvm/hvm_info_table.h>
-#define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)
-
+#ifdef CONFIG_COMPAT
+#define has_32bit_shinfo(d) ((d)->arch.has_32bit_shinfo)
+#else
+#define has_32bit_shinfo(d) ((void)(d), false)

(void)(d) is to avoid an any potential unreferenced 'd' messages?

It's a generic request to have macro arguments evaluated consistently.

Quoted 11 lines

Just using false builds for me, but your way is a little more robust.

xen/arch/x86/include/asm/domain.h line 22

Quoted 4 lines
xen/arch/x86/include/asm/domain.h +1 -0
+#endif
   /*
    * Set to true if either the global vector-type callback or per-vCPU
    * LAPIC vectors are used. Assume all vCPUs will use

Regards,
Jason

Signature · 2 lines
Best regards,
-grygorii
#7 lore raw

Re: [XEN][PATCH v2 3/4] x86: hvm: factor out COMPAT code under ifdefs

In reply to Grygorii Strashko

Hi Jürgen,

Would it be possible for you to take a look at hypercall-defs.c changes?

Quoted 212 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Factor out COMPAT HVM code under ifdefs in preparation for making HVM COMPAT code optional.

- hypercall-defs.c updated to always provide compat declaration for:
physdev_op, grant_table_op, grant_table_op. This reduces number of COMPAT ifdefs in HVM code and lets compiler DCE do the job.

- Only 64-bit shinfo is supported with COMPAT=n, so struct arch_domain->has_32bit_shinfo field is moved under COMPAT ifdef and has_32bit_shinfo() is updated to account for COMPAT=n.

---
changes in v2:
- update hypercall-defs.c to always provide compat declaration for:
physdev_op, grant_table_op, grant_table_op
- move struct arch_domain->has_32bit_shinfo is moved under COMPAT ifdef
- return hvm_hypercall()
- use ASSERT_UNREACHABLE() in hvm_do_multicall_call()
- constify has_32bit_shinfo() for COMPAT=n

  xen/arch/x86/hvm/hvm.c            | 16 ++++++++++++++++
  xen/arch/x86/hvm/hypercall.c      | 13 +++++++++++++
  xen/arch/x86/include/asm/domain.h |  9 +++++++--
  xen/include/hypercall-defs.c      |  9 +++++++--
  4 files changed, 43 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/hvm.c +16 -0
index 0fd3f95b6e0e..19524cb7a914 100644
@@ -69,7 +69,9 @@
  #include <public/version.h>
  #include <public/vm_event.h>
 
+#ifdef CONFIG_COMPAT
  #include <compat/hvm/hvm_op.h>
+#endif
 
  bool __read_mostly hvm_enabled;
 
@@ -1255,6 +1257,7 @@ static int cf_check hvm_save_cpu_xsave_states(
      return 0;
  }
 
+#ifdef CONFIG_COMPAT
  /*
   * Structure layout conformity checks, documenting correctness of the cast in
   * the invocation of validate_xstate() below.
@@ -1267,6 +1270,7 @@ CHECK_FIELD_(struct, xsave_hdr, xcomp_bv);
  CHECK_FIELD_(struct, xsave_hdr, reserved);
  #undef compat_xsave_hdr
  #undef xen_xsave_hdr
+#endif /* CONFIG_COMPAT */
 
  static int cf_check hvm_load_cpu_xsave_states(
      struct domain *d, hvm_domain_context_t *h)
@@ -3991,8 +3995,14 @@ static void hvm_latch_shinfo_size(struct domain *d)
       */
      if ( current->domain == d )
      {
+#ifdef CONFIG_COMPAT
+        /*
+         * Only 64-bit shinfo is supported when COMPAT 32-bit hypercalls
+         * interface is disabled
+         */
          d->arch.has_32bit_shinfo =
              hvm_guest_x86_mode(current) != X86_MODE_64BIT;
+#endif
 
          /*
           * Make sure that the timebase in the shared info structure is correct.
@@ -4965,6 +4975,7 @@ static int do_altp2m_op(
  #endif /* CONFIG_ALTP2M */
  }
 
+#ifdef CONFIG_COMPAT
  DEFINE_XEN_GUEST_HANDLE(compat_hvm_altp2m_op_t);
 
  /*
@@ -4992,10 +5003,12 @@ DEFINE_XEN_GUEST_HANDLE(compat_hvm_altp2m_op_t);
 
  CHECK_hvm_altp2m_op;
  CHECK_hvm_altp2m_set_mem_access_multi;
+#endif /* CONFIG_COMPAT */
 
  static int compat_altp2m_op(
      XEN_GUEST_HANDLE_PARAM(void) arg)
  {
+#ifdef CONFIG_COMPAT
      int rc = 0;
      struct compat_hvm_altp2m_op a;
      union
@@ -5063,6 +5076,9 @@ static int compat_altp2m_op(
      }
 
      return rc;
+#else
+    return -EOPNOTSUPP;
+#endif /* CONFIG_COMPAT */
  }
 
  static int hvmop_get_mem_type(
xen/arch/x86/hvm/hypercall.c +13 -0
index 52cae1d15312..1ee0193b69af 100644
@@ -170,6 +170,7 @@ int hvm_hypercall(struct cpu_user_regs *regs)
          HVM_DBG_LOG(DBG_LEVEL_HCALL, "hcall%lu(%x, %x, %x, %x, %x)", eax,
                      regs->ebx, regs->ecx, regs->edx, regs->esi, regs->edi);
 
+#ifdef CONFIG_COMPAT
          curr->hcall_compat = true;
          call_handlers_hvm32(eax, regs->eax, regs->ebx, regs->ecx, regs->edx,
                              regs->esi, regs->edi);
@@ -177,6 +178,9 @@ int hvm_hypercall(struct cpu_user_regs *regs)
 
          if ( !curr->hcall_preempted && regs->eax != -ENOSYS )
              clobber_regs(regs, eax, hvm, 32);
+#else
+        regs->eax = -ENOSYS;
+#endif
      }
 
      hvmemul_cache_restore(curr, token);
@@ -207,10 +211,19 @@ enum mc_disposition hvm_do_multicall_call(struct mc_state *state)
      }
      else
      {
+#ifdef CONFIG_COMPAT
          struct compat_multicall_entry *call = &state->compat_call;
 
          call_handlers_hvm32(call->op, call->result, call->args[0], call->args[1],
                              call->args[2], call->args[3], call->args[4]);
+#else
+        /*
+         * code should never reach here in case !CONFIG_COMPAT as any
+         * 32-bit hypercall should bail out earlier from hvm_hypercall()
+         * with -EOPNOTSUPP
+         */
+        ASSERT_UNREACHABLE();
+#endif
      }
 
      return !hvm_get_cpl(curr) ? mc_continue : mc_preempt;
xen/arch/x86/include/asm/domain.h +7 -2
index 5df8c7825333..0005f4450931 100644
@@ -12,8 +12,11 @@
  #include <public/vcpu.h>
  #include <public/hvm/hvm_info_table.h>
 
-#define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)
-
+#ifdef CONFIG_COMPAT
+#define has_32bit_shinfo(d) ((d)->arch.has_32bit_shinfo)
+#else
+#define has_32bit_shinfo(d) ((void)(d), false)
+#endif
  /*
   * Set to true if either the global vector-type callback or per-vCPU
   * LAPIC vectors are used. Assume all vCPUs will use
@@ -365,8 +368,10 @@ struct arch_domain
      /* NB. protected by d->event_lock and by irq_desc[irq].lock */
      struct radix_tree_root irq_pirq;
 
+#ifdef CONFIG_COMPAT
      /* Is shared-info page in 32-bit format? */
      bool has_32bit_shinfo;
+#endif
 
      /* Is PHYSDEVOP_eoi to automatically unmask the event channel? */
      bool auto_unmask;
xen/include/hypercall-defs.c +7 -2
index cef08eeec1b8..08c01153ac56 100644
@@ -80,6 +80,8 @@ rettype: compat int
  #define PREFIX_compat
  #endif
 
+#define PREFIX_compat_always compat
+
  #ifdef CONFIG_ARM
  #define PREFIX_dep dep
  #define PREFIX_do_arm do_arm
@@ -104,10 +106,10 @@ defhandle: trap_info_compat_t
  defhandle: physdev_op_compat_t
  #endif
 
-prefix: do PREFIX_hvm PREFIX_compat PREFIX_do_arm
+prefix: do PREFIX_hvm PREFIX_compat_always PREFIX_do_arm
  physdev_op(int cmd, void *arg)
 
-prefix: do PREFIX_hvm PREFIX_compat
+prefix: do PREFIX_hvm PREFIX_compat_always
  #if defined(CONFIG_GRANT_TABLE) || defined(CONFIG_PV_SHIM)
  grant_table_op(unsigned int cmd, void *uop, unsigned int count)
  #endif
@@ -156,6 +158,9 @@ platform_op(compat_platform_op_t *u_xenpf_op)
  #ifdef CONFIG_KEXEC
  kexec_op(unsigned int op, void *uarg)
  #endif
+#else /* CONFIG_COMPAT */
+prefix: PREFIX_compat_always
+memory_op(unsigned int cmd, void *arg)
  #endif /* CONFIG_COMPAT */
 
  #if defined(CONFIG_PV) || defined(CONFIG_ARM)
Signature · 2 lines
Best regards,
-grygorii
Reviewed-by
#8 lore raw

Re: [XEN][PATCH v2 3/4] x86: hvm: factor out COMPAT code under ifdefs

Quoted 19 lines · Grygorii Strashko

Hi Jürgen,

Would it be possible for you to take a look at hypercall-defs.c changes?

Quoted 14 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Factor out COMPAT HVM code under ifdefs in preparation for making HVM COMPAT code optional.

- hypercall-defs.c updated to always provide compat declaration for:
physdev_op, grant_table_op, grant_table_op. This reduces number of COMPAT ifdefs in HVM code and lets compiler DCE do the job.

- Only 64-bit shinfo is supported with COMPAT=n, so struct arch_domain->has_32bit_shinfo field is moved under COMPAT ifdef and has_32bit_shinfo() is updated to account for COMPAT=n.

Juergen

#9 lore raw

PATCH v2 4/4 x86: pvh: allow to disable 32-bit interface support

In reply to Grygorii Strashko

From: Grygorii Strashko <[email protected]>

For x86 Xen safety certification only PVH Gusts are selected to be allowed which are started by using direct Direct Kernel Boot only. There is also an assumption that x86 Guest's (OS) early boot code (which is running not in 64-bit mode) does not access Xen interfaces (hypercalls, shared_info, ..).

In this case the Xen HVM 32-bit COMPAT interface become unused and leaves gaps in terms of coverage.

Hence now all prerequisite changes are in place, introduce a CONFIG_HVM_COMPAT option through which HVM(PVH) 32-bit interface support on 64-bit Xen can be disabled.

By default, CONFIG_HVM_COMPAT is ("y") enabled and accessible only in EXPERT mode.

---
changes in v2:
- fix format and move above HVM_FEP

 xen/arch/x86/hvm/Kconfig | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/Kconfig +18 -1
index c323d767e77c..88090f5b3965 100644
@@ -2,7 +2,6 @@ menuconfig HVM
 	bool "HVM support"
 	depends on !PV_SHIM_EXCLUSIVE
 	default !PV_SHIM
-	select COMPAT
 	select IOREQ_SERVER
 	select MEM_ACCESS_ALWAYS_ON
 	help
@@ -35,6 +34,24 @@ config INTEL_VMX
 	  If your system includes a processor with Intel VT-x support, say Y.
 	  If in doubt, say Y.
 
+config HVM_COMPAT
+	bool "HVM 32-bit hypercalls interface support" if EXPERT
+	select COMPAT
+	default y
+	help
+	  The HVM 32-bit interface must be enabled for HVM domains to be able to
+	  make hypercalls in 32bit mode. Non-PVH domains unconditionally need this
+	  option so that hvmloader may issue hypercalls in 32bit mode.
+
+	  The HVM 32-bit interface can be disabled if:
+	  - Only PVH domains are used
+	  - Guests (OS) are started by using direct Direct Kernel Boot
+	  - Guests (OS) are 64-bit and Guest early boot code, which is running not
+	    in 64-bit mode, does not access Xen interfaces
+	    (hypercalls, shared_info, ..)
+
+	  If unsure, say Y.
+
 config HVM_FEP
 	bool "HVM Forced Emulation Prefix support (UNSUPPORTED)" if UNSUPPORTED
 	default DEBUG
Signature · 1 line
2.34.1
#10 lore raw

Re: [XEN][PATCH v2 4/4] x86: pvh: allow to disable 32-bit interface support

Quoted 3 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

For x86 Xen safety certification only PVH Gusts are selected to be allowed

s/Gusts/Guests/

Quoted 1 line

which are started by using direct Direct Kernel Boot only. There is also an

s/direct Direct/direct/

Quoted 34 lines

assumption that x86 Guest's (OS) early boot code (which is running not in 64-bit mode) does not access Xen interfaces (hypercalls, shared_info, ..).

In this case the Xen HVM 32-bit COMPAT interface become unused and leaves gaps in terms of coverage.

Hence now all prerequisite changes are in place, introduce a CONFIG_HVM_COMPAT option through which HVM(PVH) 32-bit interface support on 64-bit Xen can be disabled.

By default, CONFIG_HVM_COMPAT is ("y") enabled and accessible only in EXPERT mode.

---
changes in v2:
- fix format and move above HVM_FEP

  xen/arch/x86/hvm/Kconfig | 19 ++++++++++++++++++-
  1 file changed, 18 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/Kconfig +0 -1
index c323d767e77c..88090f5b3965 100644
@@ -2,7 +2,6 @@ menuconfig HVM
  	bool "HVM support"
  	depends on !PV_SHIM_EXCLUSIVE
  	default !PV_SHIM
-	select COMPAT
  	select IOREQ_SERVER
  	select MEM_ACCESS_ALWAYS_ON
  	help

xen/arch/x86/hvm/Kconfig config INTEL_VMX · line 38

Quoted 5 lines
xen/arch/x86/hvm/Kconfig +2 -0
@@ -35,6 +34,24 @@ config INTEL_VMX
  	  If your system includes a processor with Intel VT-x support, say Y.
  	  If in doubt, say Y.
 
+config HVM_COMPAT
+	bool "HVM 32-bit hypercalls interface support" if EXPERT

Maybe "HVM 32-bit compat hypercall support" to get "compat" in the user-visible text?

Quoted 6 lines
xen/arch/x86/hvm/Kconfig +6 -0
+	select COMPAT
+	default y
+	help
+	  The HVM 32-bit interface must be enabled for HVM domains to be able to
+	  make hypercalls in 32bit mode. Non-PVH domains unconditionally need this
+	  option so that hvmloader may issue hypercalls in 32bit mode.

xen/arch/x86/hvm/Kconfig config INTEL_VMX · line 54

Quoted 10 lines
xen/arch/x86/hvm/Kconfig +10 -0
+
+	  The HVM 32-bit interface can be disabled if:
+	  - Only PVH domains are used
+	  - Guests (OS) are started by using direct Direct Kernel Boot
+	  - Guests (OS) are 64-bit and Guest early boot code, which is running not
+	    in 64-bit mode, does not access Xen interfaces
+	    (hypercalls, shared_info, ..)
+
+	  If unsure, say Y.
+

Maybe something like:
"""
Support HVM hypercalls from 32-bit code. Hypercalls from 64-bit code are always supported.

Disabling 32-bit compat hypercalls reduces the hypervisor binary size. HVM guests require the 32-bit hvmloader, so they cannot run with this disabled. i.e. Xen will only run 64-bit PVH guests with this disabled.

If unsure, say Y.
"""

While what you wrote is correct, I tried to rephrase to highlight the the implications.

Regards,
Jason

Quoted 3 lines
xen/arch/x86/hvm/Kconfig +0 -0
  config HVM_FEP
  	bool "HVM Forced Emulation Prefix support (UNSUPPORTED)" if UNSUPPORTED
  	default DEBUG
#11 lore raw
In reply to Grygorii Strashko

Hi All,

I'm planning to send v3 - so would be appreciated for any other comments.

Quoted 39 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Hi

This series introduces possibility to disable 32-bit (COMPAT) interface support in the following case:
- Only PVH domains are used
- Guests (OS) are started by using direct Direct Kernel Boot
- Guests (OS) are 64-bit and Guest early boot code, which is running not in 64-bit mode, does not access Xen interfaces (hypercalls, shared_info, ..)

If above criterias are met the COMPAT HVM interface become unreachable and can be disabled. Coverage reports analyze and adding guard (debug) exceptions in hvm_hypercall/hvm_do_multicall_call and hvm_latch_shinfo_size() confirm that COMPAT HVM interface is unused for safety use-case.

Changes in v2 described in each patch:
- patch "x86: constify has_32bit_shinfo() if !CONFIG_COMPAT" squashed in patch 2.

v1:
https://patchwork.kernel.org/project/xen-devel/cover/[email protected]/

Grygorii Strashko (4):
x86: hvm: dm: factor out compat code under ifdefs
x86: hvm: compat: introduce is_hcall_compat() helper
x86: hvm: factor out COMPAT code under ifdefs
x86: pvh: allow to disable 32-bit interface support

  xen/arch/x86/hvm/Kconfig          | 19 ++++++++++++++++++-
  xen/arch/x86/hvm/dm.c             |  2 ++
  xen/arch/x86/hvm/hvm.c            | 24 ++++++++++++++++++++----
  xen/arch/x86/hvm/hypercall.c      | 22 +++++++++++++++++-----
  xen/arch/x86/hypercall.c          |  6 +-----
  xen/arch/x86/include/asm/domain.h |  9 +++++++--
  xen/common/kernel.c               |  2 +-
  xen/include/hypercall-defs.c      |  9 +++++++--
  xen/include/xen/sched.h           |  9 +++++++++
  9 files changed, 82 insertions(+), 20 deletions(-)
Signature · 2 lines
Best regards,
-grygorii
#12 lore raw
Quoted 1 line · Grygorii Strashko

I'm planning to send v3 - so would be appreciated for any other comments.

Andrew,

could you please write down the outline of what you described verbally the other day, to scope the extent to which we may want to take changes here?

Thanks, Jan

Quoted 41 lines · Grygorii Strashko
Quoted 39 lines

From: Grygorii Strashko <[email protected]>

Hi

This series introduces possibility to disable 32-bit (COMPAT) interface support in the following case:
- Only PVH domains are used
- Guests (OS) are started by using direct Direct Kernel Boot
- Guests (OS) are 64-bit and Guest early boot code, which is running not in 64-bit mode, does not access Xen interfaces (hypercalls, shared_info, ..)

If above criterias are met the COMPAT HVM interface become unreachable and can be disabled. Coverage reports analyze and adding guard (debug) exceptions in hvm_hypercall/hvm_do_multicall_call and hvm_latch_shinfo_size() confirm that COMPAT HVM interface is unused for safety use-case.

Changes in v2 described in each patch:
- patch "x86: constify has_32bit_shinfo() if !CONFIG_COMPAT" squashed in patch 2.

v1:
https://patchwork.kernel.org/project/xen-devel/cover/[email protected]/

Grygorii Strashko (4):
x86: hvm: dm: factor out compat code under ifdefs
x86: hvm: compat: introduce is_hcall_compat() helper
x86: hvm: factor out COMPAT code under ifdefs
x86: pvh: allow to disable 32-bit interface support

  xen/arch/x86/hvm/Kconfig          | 19 ++++++++++++++++++-
  xen/arch/x86/hvm/dm.c             |  2 ++
  xen/arch/x86/hvm/hvm.c            | 24 ++++++++++++++++++++----
  xen/arch/x86/hvm/hypercall.c      | 22 +++++++++++++++++-----
  xen/arch/x86/hypercall.c          |  6 +-----
  xen/arch/x86/include/asm/domain.h |  9 +++++++--
  xen/common/kernel.c               |  2 +-
  xen/include/hypercall-defs.c      |  9 +++++++--
  xen/include/xen/sched.h           |  9 +++++++++
  9 files changed, 82 insertions(+), 20 deletions(-)
#13 lore raw
Quoted 7 lines · Jan Beulich
Quoted 1 line · Grygorii Strashko

I'm planning to send v3 - so would be appreciated for any other comments.

Andrew,

could you please write down the outline of what you described verbally the other day, to scope the extent to which we may want to take changes here?

I am not Andrew, but I just wanted to take the opportunity to write down my recollection, letting Andrew chime in as needed of course.

We would make it possible to remove the compat code itself and compat hypercall entries. This would be acceptable right away.

When it comes to 32-bit code intermixed with 64-bit code, we would have to look at it on a case by case basis.

Quoted 42 lines
Quoted 41 lines · Grygorii Strashko
Quoted 39 lines

From: Grygorii Strashko <[email protected]>

Hi

This series introduces possibility to disable 32-bit (COMPAT) interface support in the following case:
- Only PVH domains are used
- Guests (OS) are started by using direct Direct Kernel Boot
- Guests (OS) are 64-bit and Guest early boot code, which is running not in 64-bit mode, does not access Xen interfaces (hypercalls, shared_info, ..)

If above criterias are met the COMPAT HVM interface become unreachable and can be disabled. Coverage reports analyze and adding guard (debug) exceptions in hvm_hypercall/hvm_do_multicall_call and hvm_latch_shinfo_size() confirm that COMPAT HVM interface is unused for safety use-case.

Changes in v2 described in each patch:
- patch "x86: constify has_32bit_shinfo() if !CONFIG_COMPAT" squashed in patch 2.

v1:
https://patchwork.kernel.org/project/xen-devel/cover/[email protected]/

Grygorii Strashko (4):
x86: hvm: dm: factor out compat code under ifdefs
x86: hvm: compat: introduce is_hcall_compat() helper
x86: hvm: factor out COMPAT code under ifdefs
x86: pvh: allow to disable 32-bit interface support

  xen/arch/x86/hvm/Kconfig          | 19 ++++++++++++++++++-
  xen/arch/x86/hvm/dm.c             |  2 ++
  xen/arch/x86/hvm/hvm.c            | 24 ++++++++++++++++++++----
  xen/arch/x86/hvm/hypercall.c      | 22 +++++++++++++++++-----
  xen/arch/x86/hypercall.c          |  6 +-----
  xen/arch/x86/include/asm/domain.h |  9 +++++++--
  xen/common/kernel.c               |  2 +-
  xen/include/hypercall-defs.c      |  9 +++++++--
  xen/include/xen/sched.h           |  9 +++++++++
  9 files changed, 82 insertions(+), 20 deletions(-)