Skip to contentSkip to conversation

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

PATCH Superseded Grygorii Strashko 6 participants 26 messages Nov 11, 2025 – Nov 19, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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 cases:
- 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.

Grygorii Strashko (5):
x86: hvm: dm: factor out compat code under ifdefs
x86: hvm: compat: introduce vcpu_is_hcall_compat() helper
x86: hvm: factor out compat code under ifdefs
x86: pvh: allow to disable 32-bit interface support
x86: constify has_32bit_shinfo() if !CONFIG_COMPAT

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

PATCH 1/5 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:
- do not move code, use ifdefs

---
 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
#3 lore raw

PATCH 2/5 x86: hvm: compat: introduce vcpu_is_hcall_compat() helper

In reply to Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Introduce vcpu_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.

---
 xen/arch/x86/hvm/hvm.c       | 9 +++++----
 xen/arch/x86/hvm/hypercall.c | 6 +++---
 xen/arch/x86/hypercall.c     | 6 +-----
 xen/common/kernel.c          | 2 +-
 xen/include/xen/sched.h      | 9 +++++++++
 5 files changed, 19 insertions(+), 13 deletions(-)
xen/arch/x86/hvm/hvm.c +5 -4
index 0c60faa39d7b..2e47a71714fd 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 ( vcpu_is_hcall_compat(current) && 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 ( vcpu_is_hcall_compat(current) && 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 ( vcpu_is_hcall_compat(current) && is_compat_arg_xlat_range(from, len) )
     {
         memcpy(to, from, len);
         return 0;
@@ -5214,7 +5214,8 @@ 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 = vcpu_is_hcall_compat(current) ? compat_altp2m_op(arg)
+                                           : do_altp2m_op(arg);
         break;
 
     default:
xen/arch/x86/hvm/hypercall.c +3 -3
index b254b3e2f7d6..549e25445e67 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 ( !vcpu_is_hcall_compat(current) )
         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 ( !vcpu_is_hcall_compat(current) )
         return do_grant_table_op(cmd, uop, count);
     else
         return compat_grant_table_op(cmd, uop, count);
@@ -96,7 +96,7 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return -ENOSYS;
     }
 
-    if ( !curr->hcall_compat )
+    if ( !vcpu_is_hcall_compat(curr) )
         return do_physdev_op(cmd, arg);
     else
         return compat_physdev_op(cmd, arg);
xen/arch/x86/hypercall.c +1 -5
index dc0a90ca0915..3a1a363d8648 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 ( !vcpu_is_hcall_compat(curr) )
         {
             for ( i = 0; *p != '\0'; i++ )
             {
xen/common/kernel.c +1 -1
index e6979352e100..99be0fbb9d90 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 ( vcpu_is_hcall_compat(curr) )
         {
             compat_platform_parameters_t params = {
                 .virt_start = is_pv_vcpu(curr)
xen/include/xen/sched.h +9 -0
index 02bdc256ce37..e3ce427f0bd9 100644
@@ -311,6 +311,15 @@ struct vcpu
 #endif
 };
 
+static inline bool vcpu_is_hcall_compat(const struct vcpu *v)
+{
+#ifdef CONFIG_COMPAT
+    return v->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 v1 2/5
#4 lore raw

Re: [XEN][PATCH 2/5] x86: hvm: compat: introduce vcpu_is_hcall_compat() helper

Quoted 7 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Introduce vcpu_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.

Thanks,
Jason

#5 lore raw

Re: [XEN][PATCH 2/5] x86: hvm: compat: introduce vcpu_is_hcall_compat() helper

In reply to Grygorii Strashko

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

Quoted 7 lines · Grygorii Strashko
xen/include/xen/sched.h +1 -0
@@ -311,6 +311,15 @@ struct vcpu
 #endif
 };
 
+static inline bool vcpu_is_hcall_compat(const struct vcpu *v)

Does the vcpu_ prefix really buy us much here? The per-vCPU aspect is already conveyed by the function parameter, I'd say.

Actually - is a parameter in fact needed? It's always current afaics. (Then, if the parameter was to stay for some reason, it would want naming "curr".)

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

Quoted 3 lines
xen/include/xen/sched.h +3 -0
+{
+#ifdef CONFIG_COMPAT
+    return v->hcall_compat;

As long as you don't remove the struct field, ...

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

Quoted 3 lines
xen/include/xen/sched.h +3 -0
+#else
+    return false;
+#endif /* CONFIG_COMPAT */

... why not

    return IS_ENABLED(CONFIG_COMPAT) && v->hcall_compat;

?

Jan

#6 lore raw

Re: [XEN][PATCH 2/5] x86: hvm: compat: introduce vcpu_is_hcall_compat() helper

Quoted 11 lines · Jan Beulich

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

Quoted 7 lines · Grygorii Strashko
xen/include/xen/sched.h +1 -0
@@ -311,6 +311,15 @@ struct vcpu
  #endif
  };
 
+static inline bool vcpu_is_hcall_compat(const struct vcpu *v)

Does the vcpu_ prefix really buy us much here? The per-vCPU aspect is already conveyed by the function parameter, I'd say.

Such annotation makes it clear that operation is performed on struct vcpu object, which improves readability and code analyze (might help also if somebody will ever try split sched.h).

For example:

is_hcall_compat(curr) in the code doesn't say too much - need parse code (or have modern editor which can parse and highlight parameter type for us,
still need some mouse manipulations:))

vcpu_is_hcall_compat(curr) - is kinda absolutely clear from the first look.

Quoted 3 lines

Actually - is a parameter in fact needed? It's always current afaics. (Then, if the parameter was to stay for some reason, it would want naming "curr".)

"curr" it be

Quoted 6 lines

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

Quoted 4 lines
xen/include/xen/sched.h +3 -0
+{
+#ifdef CONFIG_COMPAT
+    return v->hcall_compat;

As long as you don't remove the struct field, ...

It is already under

#ifdef CONFIG_COMPAT
    /* A hypercall is using the compat ABI? */
    bool             hcall_compat;
    /* Physical runstate area registered via compat ABI? */
    bool             runstate_guest_area_compat;

#endif

which is the main reason for vcpu_is_hcall_compat() introduction.

Quoted 8 lines

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

Quoted 4 lines
xen/include/xen/sched.h +3 -0
+#else
+    return false;
+#endif /* CONFIG_COMPAT */

... why not

     return IS_ENABLED(CONFIG_COMPAT) && v->hcall_compat;
Signature · 2 lines
Best regards,
-grygorii
#7 lore raw

Re: [XEN][PATCH 2/5] x86: hvm: compat: introduce vcpu_is_hcall_compat() helper

Quoted 17 lines · Grygorii Strashko
Quoted 11 lines · Jan Beulich

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

Quoted 7 lines · Grygorii Strashko
xen/include/xen/sched.h +1 -0
@@ -311,6 +311,15 @@ struct vcpu
  #endif
  };
 
+static inline bool vcpu_is_hcall_compat(const struct vcpu *v)

Does the vcpu_ prefix really buy us much here? The per-vCPU aspect is already conveyed by the function parameter, I'd say.

Such annotation makes it clear that operation is performed on struct vcpu object, which improves readability and code analyze (might help also if somebody will ever try split sched.h).

Quoted 5 lines

For example:

is_hcall_compat(curr) in the code doesn't say too much - need parse code (or have modern editor which can parse and highlight parameter type for us,
still need some mouse manipulations:))

That's one of the reasons we aim at using consistently named variables. "curr" should be pretty clear to everyone as being "current" latched into a local variable. Plus of course for every function invocation call site context is relevant anyway, when it comes to arguments passed to the function.

Quoted 7 lines

vcpu_is_hcall_compat(curr) - is kinda absolutely clear from the first look.

Quoted 3 lines

Actually - is a parameter in fact needed? It's always current afaics. (Then, if the parameter was to stay for some reason, it would want naming "curr".)

"curr" it be

My preference would still be is_hcall_compat(void).

Jan

#8 lore raw

PATCH 3/5 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.

---
 xen/arch/x86/hvm/hvm.c       | 13 ++++++++++++-
 xen/arch/x86/hvm/hypercall.c | 37 +++++++++++++++++++++++++++---------
 2 files changed, 40 insertions(+), 10 deletions(-)
xen/arch/x86/hvm/hvm.c +12 -1
index 2e47a71714fd..56c0059401d0 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,7 +3995,7 @@ static void hvm_latch_shinfo_size(struct domain *d)
      */
     if ( current->domain == d )
     {
-        d->arch.has_32bit_shinfo =
+        d->arch.has_32bit_shinfo = IS_ENABLED(CONFIG_COMPAT) &&
             hvm_guest_x86_mode(current) != X86_MODE_64BIT;
 
         /*
@@ -4965,6 +4969,7 @@ static int do_altp2m_op(
 #endif /* CONFIG_ALTP2M */
 }
 
+#ifdef CONFIG_COMPAT
 DEFINE_XEN_GUEST_HANDLE(compat_hvm_altp2m_op_t);
 
 /*
@@ -5064,6 +5069,12 @@ static int compat_altp2m_op(
 
     return rc;
 }
+#else
+static int compat_altp2m_op(XEN_GUEST_HANDLE_PARAM(void) arg)
+{
+    return -EOPNOTSUPP;
+}
+#endif /* CONFIG_COMPAT */
 
 static int hvmop_get_mem_type(
     XEN_GUEST_HANDLE_PARAM(xen_hvm_get_mem_type_t) arg)
xen/arch/x86/hvm/hypercall.c +28 -9
index 549e25445e67..f8b2c90b7c41 100644
@@ -29,10 +29,12 @@ long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return -ENOSYS;
     }
 
-    if ( !vcpu_is_hcall_compat(current) )
-        rc = do_memory_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
+    if ( vcpu_is_hcall_compat(current) )
         rc = compat_memory_op(cmd, arg);
+    else
+#endif
+        rc = do_memory_op(cmd, arg);
 
     return rc;
 }
@@ -57,10 +59,12 @@ long hvm_grant_table_op(
         return -ENOSYS;
     }
 
-    if ( !vcpu_is_hcall_compat(current) )
-        return do_grant_table_op(cmd, uop, count);
-    else
+#ifdef CONFIG_COMPAT
+    if ( vcpu_is_hcall_compat(current) )
         return compat_grant_table_op(cmd, uop, count);
+    else
+#endif
+        return do_grant_table_op(cmd, uop, count);
 }
 #endif
 
@@ -96,10 +100,12 @@ long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return -ENOSYS;
     }
 
-    if ( !vcpu_is_hcall_compat(curr) )
-        return do_physdev_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
+    if ( vcpu_is_hcall_compat(curr) )
         return compat_physdev_op(cmd, arg);
+    else
+#endif
+        return do_physdev_op(cmd, arg);
 }
 
 int hvm_hypercall(struct cpu_user_regs *regs)
@@ -171,6 +177,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);
@@ -178,6 +185,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 = -EOPNOTSUPP;
+#endif
     }
 
     hvmemul_cache_restore(curr, token);
@@ -208,10 +218,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
+         */
+        unreachable();
+#endif
     }
 
     return !hvm_get_cpl(curr) ? mc_continue : mc_preempt;
Signature · 1 line
2.34.1
#9 lore raw

Re: [XEN][PATCH 3/5] x86: hvm: factor out compat code under ifdefs

xen/arch/x86/hvm/hvm.c static void hvm_latch_shinfo_size(struct domain *d) · line 3999

Quoted 7 lines · Grygorii Strashko
xen/arch/x86/hvm/hvm.c +1 -1
@@ -3991,7 +3995,7 @@ static void hvm_latch_shinfo_size(struct domain *d)
      */
     if ( current->domain == d )
     {
-        d->arch.has_32bit_shinfo =
+        d->arch.has_32bit_shinfo = IS_ENABLED(CONFIG_COMPAT) &&
             hvm_guest_x86_mode(current) != X86_MODE_64BIT;

I think this could need commenting on if we really want to put it in this shape. But why would we retain the has_32bit_shinfo field in the first place when COMPAT=n?

Quoted 9 lines
xen/arch/x86/hvm/hvm.c +1 -0
@@ -4965,6 +4969,7 @@ static int do_altp2m_op(
 #endif /* CONFIG_ALTP2M */
 }
 
+#ifdef CONFIG_COMPAT
 DEFINE_XEN_GUEST_HANDLE(compat_hvm_altp2m_op_t);
 
 /*

xen/arch/x86/hvm/hvm.c static int compat_altp2m_op( · line 5077

Quoted 9 lines
xen/arch/x86/hvm/hvm.c +6 -0
@@ -5064,6 +5069,12 @@ static int compat_altp2m_op(
 
     return rc;
 }
+#else
+static int compat_altp2m_op(XEN_GUEST_HANDLE_PARAM(void) arg)
+{
+    return -EOPNOTSUPP;
+}
+#endif /* CONFIG_COMPAT */

I'm not in favor of repeating the function "header". Imo such #ifdef-s better go inside respective functions' bodies.

Quoted 5 lines
xen/arch/x86/hvm/hypercall.c +0 -0
@@ -29,10 +29,12 @@ long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return -ENOSYS;
     }

xen/arch/x86/hvm/hypercall.c long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 37

Quoted 10 lines
xen/arch/x86/hvm/hypercall.c +5 -3
 
-    if ( !vcpu_is_hcall_compat(current) )
-        rc = do_memory_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
+    if ( vcpu_is_hcall_compat(current) )
         rc = compat_memory_op(cmd, arg);
+    else
+#endif
+        rc = do_memory_op(cmd, arg);

Why would this be needed when vcpu_is_hcall_compat() already honors CONFIG_COMPAT? (Same question then applies elsewhere, of course.)

Quoted 9 lines
xen/arch/x86/hvm/hypercall.c +1 -0
@@ -171,6 +177,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);

xen/arch/x86/hvm/hypercall.c int hvm_hypercall(struct cpu_user_regs *regs) · line 190

Quoted 6 lines
xen/arch/x86/hvm/hypercall.c +3 -0
@@ -178,6 +185,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 = -EOPNOTSUPP;
+#endif

I'm generally against most attempts to use ENOSYS, but here it should be used:
The top-level hypercalls are (effectively) unimplemented in this mode.

Quoted 6 lines
xen/arch/x86/hvm/hypercall.c +1 -0
@@ -208,10 +218,19 @@ enum mc_disposition hvm_do_multicall_call(struct mc_state *state)
     }
     else
     {
+#ifdef CONFIG_COMPAT
         struct compat_multicall_entry *call = &state->compat_call;

xen/arch/x86/hvm/hypercall.c enum mc_disposition hvm_do_multicall_call(struct mc_state *state) · line 232

Quoted 10 lines
xen/arch/x86/hvm/hypercall.c +7 -0
 
         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
+         */
+        unreachable();

I.e. you rather mean ASSERT_UNREACHABLE()?

Jan

#10 lore raw

Re: [XEN][PATCH 3/5] x86: hvm: factor out compat code under ifdefs

Quoted 10 lines · Jan Beulich

xen/arch/x86/hvm/hvm.c static void hvm_latch_shinfo_size(struct domain *d) · line 3999

Quoted 7 lines · Grygorii Strashko
xen/arch/x86/hvm/hvm.c +1 -1
@@ -3991,7 +3995,7 @@ static void hvm_latch_shinfo_size(struct domain *d)
       */
      if ( current->domain == d )
      {
-        d->arch.has_32bit_shinfo =
+        d->arch.has_32bit_shinfo = IS_ENABLED(CONFIG_COMPAT) &&
              hvm_guest_x86_mode(current) != X86_MODE_64BIT;

I think this could need commenting on if we really want to put it in this shape.

ok.

Quoted 2 lines

But why would we retain the has_32bit_shinfo field in the first place when COMPAT=n?

Here I'm not sure. May be other can comment.

Quoted 11 lines
Quoted 11 lines
xen/arch/x86/hvm/hvm.c +1 -0
@@ -4965,6 +4969,7 @@ static int do_altp2m_op(
  #endif /* CONFIG_ALTP2M */
  }
 
+#ifdef CONFIG_COMPAT
  DEFINE_XEN_GUEST_HANDLE(compat_hvm_altp2m_op_t);
 
  /*
@@ -5064,6 +5069,12 @@ static int compat_altp2m_op(
 
Quoted 11 lines

xen/arch/x86/hvm/hvm.c static int compat_altp2m_op( · line 5077

Quoted 8 lines
xen/arch/x86/hvm/hvm.c +6 -0
      return rc;
  }
+#else
+static int compat_altp2m_op(XEN_GUEST_HANDLE_PARAM(void) arg)
+{
+    return -EOPNOTSUPP;
+}
+#endif /* CONFIG_COMPAT */

I'm not in favor of repeating the function "header". Imo such #ifdef-s better go inside respective functions' bodies.

ok.

Quoted 7 lines
Quoted 7 lines
xen/arch/x86/hvm/hypercall.c +0 -0
@@ -29,10 +29,12 @@ long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
          return -ENOSYS;
      }
 
Quoted 12 lines

xen/arch/x86/hvm/hypercall.c long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 37

Quoted 9 lines
xen/arch/x86/hvm/hypercall.c +5 -3
-    if ( !vcpu_is_hcall_compat(current) )
-        rc = do_memory_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
+    if ( vcpu_is_hcall_compat(current) )
          rc = compat_memory_op(cmd, arg);
+    else
+#endif
+        rc = do_memory_op(cmd, arg);

Why would this be needed when vcpu_is_hcall_compat() already honors CONFIG_COMPAT? (Same question then applies elsewhere, of course.)

This I do not like by myself, but I was not able to find other options :(

hypercall-defs.h is autogenerated and it's the only one place where functions declarations like do_x_op() are appeared or disappeared.
So build is failing without ifdefs as compiler can't find compat_memory_op() declaration.

Quoted 11 lines
Quoted 11 lines
xen/arch/x86/hvm/hypercall.c +1 -0
@@ -171,6 +177,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);
@@ -178,6 +185,9 @@ int hvm_hypercall(struct cpu_user_regs *regs)
 
Quoted 8 lines

xen/arch/x86/hvm/hypercall.c int hvm_hypercall(struct cpu_user_regs *regs) · line 190

Quoted 5 lines
xen/arch/x86/hvm/hypercall.c +3 -0
          if ( !curr->hcall_preempted && regs->eax != -ENOSYS )
              clobber_regs(regs, eax, hvm, 32);
+#else
+        regs->eax = -EOPNOTSUPP;
+#endif

I'm generally against most attempts to use ENOSYS, but here it should be used:
The top-level hypercalls are (effectively) unimplemented in this mode.

ok.

Quoted 8 lines
Quoted 8 lines
xen/arch/x86/hvm/hypercall.c +1 -0
@@ -208,10 +218,19 @@ enum mc_disposition hvm_do_multicall_call(struct mc_state *state)
      }
      else
      {
+#ifdef CONFIG_COMPAT
          struct compat_multicall_entry *call = &state->compat_call;
 
Quoted 11 lines

xen/arch/x86/hvm/hypercall.c enum mc_disposition hvm_do_multicall_call(struct mc_state *state) · line 232

Quoted 9 lines
xen/arch/x86/hvm/hypercall.c +7 -0
          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
+         */
+        unreachable();

I.e. you rather mean ASSERT_UNREACHABLE()?

ok.

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

Re: [XEN][PATCH 3/5] x86: hvm: factor out compat code under ifdefs

Quoted 21 lines · Grygorii Strashko
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Grygorii Strashko
xen/arch/x86/hvm/hypercall.c +0 -0
@@ -29,10 +29,12 @@ long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
          return -ENOSYS;
      }
 
Quoted 12 lines

xen/arch/x86/hvm/hypercall.c long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 37

Quoted 9 lines
xen/arch/x86/hvm/hypercall.c +5 -3
-    if ( !vcpu_is_hcall_compat(current) )
-        rc = do_memory_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
+    if ( vcpu_is_hcall_compat(current) )
          rc = compat_memory_op(cmd, arg);
+    else
+#endif
+        rc = do_memory_op(cmd, arg);

Why would this be needed when vcpu_is_hcall_compat() already honors CONFIG_COMPAT? (Same question then applies elsewhere, of course.)

Quoted 6 lines

This I do not like by myself, but I was not able to find other options :(

hypercall-defs.h is autogenerated and it's the only one place where functions declarations like do_x_op() are appeared or disappeared.
So build is failing without ifdefs as compiler can't find compat_memory_op() declaration.

Oh, I see; I hadn't thought of that aspect. I wonder if we wouldn't better take care of that in the machinery there. Cc-ing Jürgen, who did introduce this originally. Maybe he has concrete arguments against us doing so.

Jan

#12 lore raw

Re: [XEN][PATCH 3/5] x86: hvm: factor out compat code under ifdefs

Quoted 24 lines · Jan Beulich
Quoted 23 lines · Grygorii Strashko
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Grygorii Strashko
xen/arch/x86/hvm/hypercall.c +0 -0
@@ -29,10 +29,12 @@ long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
           return -ENOSYS;
       }
 
Quoted 12 lines

xen/arch/x86/hvm/hypercall.c long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 37

Quoted 9 lines
xen/arch/x86/hvm/hypercall.c +5 -3
-    if ( !vcpu_is_hcall_compat(current) )
-        rc = do_memory_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
+    if ( vcpu_is_hcall_compat(current) )
           rc = compat_memory_op(cmd, arg);
+    else
+#endif
+        rc = do_memory_op(cmd, arg);

Why would this be needed when vcpu_is_hcall_compat() already honors CONFIG_COMPAT? (Same question then applies elsewhere, of course.)

This I do not like by myself, but I was not able to find other options :(

Quoted 8 lines
Quoted 4 lines

hypercall-defs.h is autogenerated and it's the only one place where functions declarations like do_x_op() are appeared or disappeared.
So build is failing without ifdefs as compiler can't find compat_memory_op() declaration.

Oh, I see; I hadn't thought of that aspect. I wonder if we wouldn't better take care of that in the machinery there. Cc-ing Jürgen, who did introduce this originally. Maybe he has concrete arguments against us doing so.

No arguments against it.

You probably will need a new Prefix defined (e.g. compat_always) and set it via

#define PREFIX_compat_always compat

unconditionally. Then it should be possible to have

Prefix: compat_always
memory_op(...)

outside of #ifdefs and drop the memory_op() in the #ifdef CONFIG_COMPAT section.

This should result in the compat_memory_op() prototype to be always available. Having no related function should be no problem due to DCO in case CONFIG_COMPAT isn't defined.

Juergen

#13 lore raw

Re: [XEN][PATCH 3/5] x86: hvm: factor out compat code under ifdefs

Quoted 38 lines · Jürgen Groß
Quoted 24 lines · Jan Beulich
Quoted 23 lines · Grygorii Strashko
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Grygorii Strashko
xen/arch/x86/hvm/hypercall.c +1 -3
@@ -29,10 +29,12 @@ long hvm_memory_op(unsigned long cmd, 
 XEN_GUEST_HANDLE_PARAM(void) arg)
            return -ENOSYS;
        }
-    if ( !vcpu_is_hcall_compat(current) )
-        rc = do_memory_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
Quoted 8 lines

xen/arch/x86/hvm/hypercall.c long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 37

Quoted 5 lines
xen/arch/x86/hvm/hypercall.c +4 -0
+    if ( vcpu_is_hcall_compat(current) )
            rc = compat_memory_op(cmd, arg);
+    else
+#endif
+        rc = do_memory_op(cmd, arg);

Why would this be needed when vcpu_is_hcall_compat() already honors CONFIG_COMPAT? (Same question then applies elsewhere, of course.)

This I do not like by myself, but I was not able to find other options :(

Quoted 8 lines
Quoted 4 lines

hypercall-defs.h is autogenerated and it's the only one place where functions declarations like do_x_op() are appeared or disappeared.
So build is failing without ifdefs as compiler can't find compat_memory_op() declaration.

Oh, I see; I hadn't thought of that aspect. I wonder if we wouldn't better take care of that in the machinery there. Cc-ing Jürgen, who did introduce this originally. Maybe he has concrete arguments against us doing so.

No arguments against it.

You probably will need a new Prefix defined (e.g. compat_always) and set it via

Quoted 8 lines

#define PREFIX_compat_always compat

unconditionally. Then it should be possible to have

Prefix: compat_always
memory_op(...)

outside of #ifdefs and drop the memory_op() in the #ifdef CONFIG_COMPAT section.

Oh, this might be wrong, as this will break the PV32 memory_op() hypercall.

You need to keep the current memory_op() in the #ifdef CONFIG_COMPAT section and move the compat_always stuff into an #else part of the CONFIG_COMPAT.

Quoted 4 lines

This should result in the compat_memory_op() prototype to be always available. Having no related function should be no problem due to DCO in case CONFIG_COMPAT isn't defined.

Juergen

#14 lore raw

Re: [XEN][PATCH 3/5] x86: hvm: factor out compat code under ifdefs

Hi Jürgen,

Quoted 45 lines · Juergen Gross
Quoted 44 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Grygorii Strashko
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Grygorii Strashko
xen/arch/x86/hvm/hypercall.c +1 -3
@@ -29,10 +29,12 @@ long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
            return -ENOSYS;
        }
-    if ( !vcpu_is_hcall_compat(current) )
-        rc = do_memory_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
Quoted 8 lines

xen/arch/x86/hvm/hypercall.c long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 36

Quoted 5 lines
xen/arch/x86/hvm/hypercall.c +4 -0
+    if ( vcpu_is_hcall_compat(current) )
            rc = compat_memory_op(cmd, arg);
+    else
+#endif
+        rc = do_memory_op(cmd, arg);

Why would this be needed when vcpu_is_hcall_compat() already honors CONFIG_COMPAT? (Same question then applies elsewhere, of course.)

This I do not like by myself, but I was not able to find other options :(

Quoted 8 lines
Quoted 4 lines

hypercall-defs.h is autogenerated and it's the only one place where functions declarations like do_x_op() are appeared or disappeared.
So build is failing without ifdefs as compiler can't find compat_memory_op() declaration.

Oh, I see; I hadn't thought of that aspect. I wonder if we wouldn't better take care of that in the machinery there. Cc-ing Jürgen, who did introduce this originally. Maybe he has concrete arguments against us doing so.

No arguments against it.

You probably will need a new Prefix defined (e.g. compat_always) and set it via

#define PREFIX_compat_always compat

unconditionally. Then it should be possible to have

Prefix: compat_always
memory_op(...)

Quoted 11 lines
Quoted 1 line

outside of #ifdefs and drop the memory_op() in the #ifdef CONFIG_COMPAT section.

Oh, this might be wrong, as this will break the PV32 memory_op() hypercall.

You need to keep the current memory_op() in the #ifdef CONFIG_COMPAT section and move the compat_always stuff into an #else part of the CONFIG_COMPAT.

Quoted 4 lines

This should result in the compat_memory_op() prototype to be always available. Having no related function should be no problem due to DCO in case CONFIG_COMPAT isn't defined.

Smth like this, right?

xen/include/hypercall-defs.c +5 -0
index 338d7afe3048..e85943320bd2 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
@@ -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
+prefix: PREFIX_compat_always
+memory_op(unsigned int cmd, void *arg)
 #endif /* CONFIG_COMPAT */
 
 
Signature · 2 lines
Best regards,
-grygorii
#15 lore raw

Re: [XEN][PATCH 3/5] x86: hvm: factor out compat code under ifdefs

Quoted 77 lines · Grygorii Strashko

Hi Jürgen,

Quoted 46 lines · Juergen Gross
Quoted 45 lines · Jürgen Groß
Quoted 24 lines · Jan Beulich
Quoted 23 lines · Grygorii Strashko
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Grygorii Strashko
xen/arch/x86/hvm/hypercall.c +1 -3
@@ -29,10 +29,12 @@ long hvm_memory_op(unsigned long cmd, 
 XEN_GUEST_HANDLE_PARAM(void) arg)
            return -ENOSYS;
        }
-    if ( !vcpu_is_hcall_compat(current) )
-        rc = do_memory_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
Quoted 8 lines

xen/arch/x86/hvm/hypercall.c long hvm_memory_op(unsigned long cmd, · line 37

Quoted 5 lines
xen/arch/x86/hvm/hypercall.c +4 -0
+    if ( vcpu_is_hcall_compat(current) )
            rc = compat_memory_op(cmd, arg);
+    else
+#endif
+        rc = do_memory_op(cmd, arg);

Why would this be needed when vcpu_is_hcall_compat() already honors CONFIG_COMPAT? (Same question then applies elsewhere, of course.)

This I do not like by myself, but I was not able to find other options :(

Quoted 8 lines
Quoted 4 lines

hypercall-defs.h is autogenerated and it's the only one place where functions declarations like do_x_op() are appeared or disappeared.
So build is failing without ifdefs as compiler can't find compat_memory_op() declaration.

Oh, I see; I hadn't thought of that aspect. I wonder if we wouldn't better take care of that in the machinery there. Cc-ing Jürgen, who did introduce this originally. Maybe he has concrete arguments against us doing so.

No arguments against it.

You probably will need a new Prefix defined (e.g. compat_always) and set it via

#define PREFIX_compat_always compat

unconditionally. Then it should be possible to have

Prefix: compat_always
memory_op(...)

Quoted 11 lines
Quoted 1 line

outside of #ifdefs and drop the memory_op() in the #ifdef CONFIG_COMPAT section.

Oh, this might be wrong, as this will break the PV32 memory_op() hypercall.

You need to keep the current memory_op() in the #ifdef CONFIG_COMPAT section and move the compat_always stuff into an #else part of the CONFIG_COMPAT.

Quoted 4 lines

This should result in the compat_memory_op() prototype to be always available. Having no related function should be no problem due to DCO in case CONFIG_COMPAT isn't defined.

Smth like this, right?

xen/include/hypercall-defs.c +2 -0
index 338d7afe3048..e85943320bd2 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

xen/include/hypercall-defs.c platform_op(compat_platform_op_t *u_xenpf_op) · line 162

Quoted 5 lines
xen/include/hypercall-defs.c +2 -0
@@ -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
+prefix: PREFIX_compat_always

This should be:

+prefix: compat_always

xen/include/hypercall-defs.c platform_op(compat_platform_op_t *u_xenpf_op) · line 164

Quoted 2 lines
xen/include/hypercall-defs.c +1 -0
+memory_op(unsigned int cmd, void *arg)
  #endif /* CONFIG_COMPAT */

Juergen

#16 lore raw

Re: [XEN][PATCH 3/5] x86: hvm: factor out compat code under ifdefs

Hi Jürgen,

Quoted 85 lines · Jürgen Groß
Quoted 76 lines · Grygorii Strashko

Hi Jürgen,

Quoted 45 lines · Juergen Gross
Quoted 44 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Grygorii Strashko
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Grygorii Strashko
xen/arch/x86/hvm/hypercall.c +1 -3
@@ -29,10 +29,12 @@ long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
            return -ENOSYS;
        }
-    if ( !vcpu_is_hcall_compat(current) )
-        rc = do_memory_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
Quoted 8 lines

xen/arch/x86/hvm/hypercall.c long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 36

Quoted 5 lines
xen/arch/x86/hvm/hypercall.c +4 -0
+    if ( vcpu_is_hcall_compat(current) )
            rc = compat_memory_op(cmd, arg);
+    else
+#endif
+        rc = do_memory_op(cmd, arg);

Why would this be needed when vcpu_is_hcall_compat() already honors CONFIG_COMPAT? (Same question then applies elsewhere, of course.)

This I do not like by myself, but I was not able to find other options :(

Quoted 8 lines
Quoted 4 lines

hypercall-defs.h is autogenerated and it's the only one place where functions declarations like do_x_op() are appeared or disappeared.
So build is failing without ifdefs as compiler can't find compat_memory_op() declaration.

Oh, I see; I hadn't thought of that aspect. I wonder if we wouldn't better take care of that in the machinery there. Cc-ing Jürgen, who did introduce this originally. Maybe he has concrete arguments against us doing so.

No arguments against it.

You probably will need a new Prefix defined (e.g. compat_always) and set it via

#define PREFIX_compat_always compat

unconditionally. Then it should be possible to have

Prefix: compat_always
memory_op(...)

Quoted 11 lines
Quoted 1 line

outside of #ifdefs and drop the memory_op() in the #ifdef CONFIG_COMPAT section.

Oh, this might be wrong, as this will break the PV32 memory_op() hypercall.

You need to keep the current memory_op() in the #ifdef CONFIG_COMPAT section and move the compat_always stuff into an #else part of the CONFIG_COMPAT.

Quoted 4 lines

This should result in the compat_memory_op() prototype to be always available. Having no related function should be no problem due to DCO in case CONFIG_COMPAT isn't defined.

Smth like this, right?

xen/include/hypercall-defs.c +2 -0
index 338d7afe3048..e85943320bd2 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

xen/include/hypercall-defs.c platform_op(compat_platform_op_t *u_xenpf_op) · line 162

Quoted 5 lines
xen/include/hypercall-defs.c +2 -0
@@ -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
+prefix: PREFIX_compat_always

This should be:

Quoted 1 line

+prefix: compat_always

Unfortunately, ^ is not working it generates
long compat_always_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);

My version works "prefix: PREFIX_compat_always"

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

Re: [XEN][PATCH 3/5] x86: hvm: factor out compat code under ifdefs

Quoted 89 lines · Grygorii Strashko

Hi Jürgen,

Quoted 86 lines · Jürgen Groß
Quoted 77 lines · Grygorii Strashko

Hi Jürgen,

Quoted 46 lines · Juergen Gross
Quoted 45 lines · Jürgen Groß
Quoted 24 lines · Jan Beulich
Quoted 23 lines · Grygorii Strashko
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Grygorii Strashko
xen/arch/x86/hvm/hypercall.c +1 -3
@@ -29,10 +29,12 @@ long hvm_memory_op(unsigned long cmd, 
 XEN_GUEST_HANDLE_PARAM(void) arg)
            return -ENOSYS;
        }
-    if ( !vcpu_is_hcall_compat(current) )
-        rc = do_memory_op(cmd, arg);
-    else
+#ifdef CONFIG_COMPAT
Quoted 8 lines

xen/arch/x86/hvm/hypercall.c long hvm_memory_op(unsigned long cmd, · line 37

Quoted 5 lines
xen/arch/x86/hvm/hypercall.c +4 -0
+    if ( vcpu_is_hcall_compat(current) )
            rc = compat_memory_op(cmd, arg);
+    else
+#endif
+        rc = do_memory_op(cmd, arg);

Why would this be needed when vcpu_is_hcall_compat() already honors CONFIG_COMPAT? (Same question then applies elsewhere, of course.)

This I do not like by myself, but I was not able to find other options :(

Quoted 8 lines
Quoted 4 lines

hypercall-defs.h is autogenerated and it's the only one place where functions declarations like do_x_op() are appeared or disappeared.
So build is failing without ifdefs as compiler can't find compat_memory_op() declaration.

Oh, I see; I hadn't thought of that aspect. I wonder if we wouldn't better take care of that in the machinery there. Cc-ing Jürgen, who did introduce this originally. Maybe he has concrete arguments against us doing so.

No arguments against it.

You probably will need a new Prefix defined (e.g. compat_always) and set it via

#define PREFIX_compat_always compat

unconditionally. Then it should be possible to have

Prefix: compat_always
memory_op(...)

Quoted 11 lines
Quoted 1 line

outside of #ifdefs and drop the memory_op() in the #ifdef CONFIG_COMPAT section.

Oh, this might be wrong, as this will break the PV32 memory_op() hypercall.

You need to keep the current memory_op() in the #ifdef CONFIG_COMPAT section and move the compat_always stuff into an #else part of the CONFIG_COMPAT.

Quoted 4 lines

This should result in the compat_memory_op() prototype to be always available. Having no related function should be no problem due to DCO in case CONFIG_COMPAT isn't defined.

Smth like this, right?

xen/include/hypercall-defs.c +2 -0
index 338d7afe3048..e85943320bd2 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

xen/include/hypercall-defs.c platform_op(compat_platform_op_t *u_xenpf_op) · line 162

Quoted 5 lines
xen/include/hypercall-defs.c +2 -0
@@ -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
+prefix: PREFIX_compat_always

This should be:

Quoted 7 lines
Quoted 1 line

+prefix: compat_always

Unfortunately, ^ is not working it generates
long compat_always_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg);

My version works "prefix: PREFIX_compat_always"

Oh, I stand corrected then.

Juergen

#18 lore raw

PATCH 4/5 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.

---
 xen/arch/x86/hvm/Kconfig | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/Kconfig +18 -1
index f10a2b374448..33152f2a6bbe 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
@@ -70,4 +69,22 @@ config MEM_PAGING
 config MEM_SHARING
 	bool "Xen memory sharing support (UNSUPPORTED)" if UNSUPPORTED
 
+config HVM_COMPAT
+    bool "HVM 32-bit interface support on 64-bit Xen" 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.
+
 endif
Signature · 1 line
2.34.1
#19 lore raw

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

Quoted 11 lines · Grygorii Strashko
xen/arch/x86/hvm/Kconfig +0 -1
@@ -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 MEM_PAGING · line 73

Quoted 5 lines
xen/arch/x86/hvm/Kconfig +2 -0
@@ -70,4 +69,22 @@ config MEM_PAGING
 config MEM_SHARING
 	bool "Xen memory sharing support (UNSUPPORTED)" if UNSUPPORTED
 
+config HVM_COMPAT
+    bool "HVM 32-bit interface support on 64-bit Xen" if EXPERT

x86 Xen is always 64-bit, so I don't view it necessary to say so explicitly.

Imo the whole construct will want to move up, perhaps ahead of HVM_FEP.

Jan

#20 lore raw

PATCH 5/5 x86: constify has_32bit_shinfo() if !CONFIG_COMPAT

In reply to Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Constify has_32bit_shinfo() if !CONFIG_COMPAT.

---
 xen/arch/x86/include/asm/domain.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/domain.h +2 -1
index 5df8c7825333..6883b7226aa7 100644
@@ -12,7 +12,8 @@
 #include <public/vcpu.h>
 #include <public/hvm/hvm_info_table.h>
 
-#define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)
+#define has_32bit_shinfo(d)                                                    \
+        (IS_ENABLED(CONFIG_COMPAT) && (d)->arch.has_32bit_shinfo)
 
 /*
  * Set to true if either the global vector-type callback or per-vCPU
Signature · 1 line
2.34.1
#21 lore raw

Re: [XEN][PATCH 5/5] x86: constify has_32bit_shinfo() if !CONFIG_COMPAT

Quoted 3 lines · Grygorii Strashko

From: Grygorii Strashko <[email protected]>

Constify has_32bit_shinfo() if !CONFIG_COMPAT.

As already indicated in reply to another patch, drop the field altogether when COMPAT=n, having the macro simply resolve to false in that case?

Jan

#22 lore raw
In reply to Grygorii Strashko
Quoted 2 lines · Grygorii Strashko

This series introduces possibility to disable 32-bit (COMPAT) interface support in the following cases:

The use of plural here ...

Quoted 5 lines

- 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, ..)

... makes this an OR list, which I don't think would be correct. PVH domains, for example, can well be 32-bit ones, can't they? Otoh the latter two points look as if they really enumerate alternatives. Can you clarify please what is meant?

Jan

Quoted 21 lines

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.

Grygorii Strashko (5):
x86: hvm: dm: factor out compat code under ifdefs
x86: hvm: compat: introduce vcpu_is_hcall_compat() helper
x86: hvm: factor out compat code under ifdefs
x86: pvh: allow to disable 32-bit interface support
x86: constify has_32bit_shinfo() if !CONFIG_COMPAT

 xen/arch/x86/hvm/Kconfig          | 19 +++++++++++++++-
 xen/arch/x86/hvm/dm.c             |  2 ++
 xen/arch/x86/hvm/hvm.c            | 22 +++++++++++++-----
 xen/arch/x86/hvm/hypercall.c      | 37 +++++++++++++++++++++++--------
 xen/arch/x86/hypercall.c          |  6 +----
 xen/arch/x86/include/asm/domain.h |  3 ++-
 xen/common/kernel.c               |  2 +-
 xen/include/xen/sched.h           |  9 ++++++++
 8 files changed, 78 insertions(+), 22 deletions(-)
#23 lore raw
Quoted 5 lines · Jan Beulich
Quoted 2 lines · Grygorii Strashko

This series introduces possibility to disable 32-bit (COMPAT) interface support in the following cases:

The use of plural here ...

should be "case"

Quoted 8 lines
Quoted 6 lines

- 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, ..)

... makes this an OR list, which I don't think would be correct.

It is AND for all items.
I think I worded it better in Patch 4

PVH domains,

Quoted 28 lines

for example, can well be 32-bit ones, can't they? Otoh the latter two points look as if they really enumerate alternatives. Can you clarify please what is meant?

Jan

Quoted 21 lines

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.

Grygorii Strashko (5):
x86: hvm: dm: factor out compat code under ifdefs
x86: hvm: compat: introduce vcpu_is_hcall_compat() helper
x86: hvm: factor out compat code under ifdefs
x86: pvh: allow to disable 32-bit interface support
x86: constify has_32bit_shinfo() if !CONFIG_COMPAT

  xen/arch/x86/hvm/Kconfig          | 19 +++++++++++++++-
  xen/arch/x86/hvm/dm.c             |  2 ++
  xen/arch/x86/hvm/hvm.c            | 22 +++++++++++++-----
  xen/arch/x86/hvm/hypercall.c      | 37 +++++++++++++++++++++++--------
  xen/arch/x86/hypercall.c          |  6 +----
  xen/arch/x86/include/asm/domain.h |  3 ++-
  xen/common/kernel.c               |  2 +-
  xen/include/xen/sched.h           |  9 ++++++++
  8 files changed, 78 insertions(+), 22 deletions(-)
Signature · 2 lines
Best regards,
-grygorii
#24 lore raw
In reply to Grygorii Strashko

Le 11/11/2025 à 18:55, Grygorii Strashko a écrit :

Quoted 7 lines

From: Grygorii Strashko <[email protected]>

Hi

This series introduces possibility to disable 32-bit (COMPAT) interface support in the following cases:
- Only PVH domains are used

I assume this one is mostly due to hvmloader being today running in protected mode 32-bits rather than a limitation "HVM" itself. I don't think of anything else preventing HVM (with 64-bits guests or 32-bits ones without Xen support) from working with COMPAT disabled.

Quoted 16 lines

- 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.

Grygorii Strashko (5):
x86: hvm: dm: factor out compat code under ifdefs
x86: hvm: compat: introduce vcpu_is_hcall_compat() helper
x86: hvm: factor out compat code under ifdefs
x86: pvh: allow to disable 32-bit interface support
x86: constify has_32bit_shinfo() if !CONFIG_COMPAT

Quoted 10 lines
  xen/arch/x86/hvm/Kconfig          | 19 +++++++++++++++-
  xen/arch/x86/hvm/dm.c             |  2 ++
  xen/arch/x86/hvm/hvm.c            | 22 +++++++++++++-----
  xen/arch/x86/hvm/hypercall.c      | 37 +++++++++++++++++++++++--------
  xen/arch/x86/hypercall.c          |  6 +----
  xen/arch/x86/include/asm/domain.h |  3 ++-
  xen/common/kernel.c               |  2 +-
  xen/include/xen/sched.h           |  9 ++++++++
  8 files changed, 78 insertions(+), 22 deletions(-)

Teddy

--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#25 lore raw
Quoted 5 lines · Teddy Astie

Le 11/11/2025 à 18:55, Grygorii Strashko a écrit :

Quoted 4 lines

From: Grygorii Strashko <[email protected]>

Hi

Quoted 8 lines
Quoted 3 lines

This series introduces possibility to disable 32-bit (COMPAT) interface support in the following cases:
- Only PVH domains are used

I assume this one is mostly due to hvmloader being today running in protected mode 32-bits rather than a limitation "HVM" itself. I don't think of anything else preventing HVM (with 64-bits guests or 32-bits ones without Xen support) from working with COMPAT disabled.

It is indeed because hvmloader makes hypercalls. Otherwise HVM would work too.

Cheers,
Alejandro