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

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


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Date: Tue, 11 Nov 2025 17:54:17 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hS6MnFghC+Qj7tFhTma9PYKjRin7yKtaSHIg329odxk=; b=CpX1xtXE/cBfnmVVwcsu5Bf6PWC0BvHHz0tFleQ4ziWcwnSAFvIYOzAcpuZIV35EGbfwlVU18dXGeR3iYqARIpAx0HET2g9Tg4fcyU6/hHFTTKKf6OXhAcdb/LRf6dSPbQY0nQwbFz63jEW3Zn03B/i8FAtLfC1MNFoCaTvNfSW7r26IJvrPqha9lgO+kesQDrR/KUgy6/JqLKmSJZyYItryCG0/wFK2Kh6Ylvq4RV7t1sK1Acn3ErhgVyZb/Sf3ervw/RueYHzIxyAELQhumDFMvOvO9qus3FUD51TyZWzhNwU10jNDF9gomMwoFtYG5ErZMwQmRasH2+udjML5JQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LGtbIXYXG46U8/BoBTsjcxQALLYUXHtoWWvCrY1012tU3SAKS9yYFDYR/m5A1X4+UAmQ9LHAAspePYZLj8VZIVjniT124pD7w5qmSdLyyKel7QQrZTWzId6m7NGvXv+PDljUrUE+YZMqJ7zQmghGb2YgcwiwK0WX6BKW3vThXP4C5YX6PHA4N58QY4zJTmFfmHUdHC10aLdjBJqzHODbzTBMCnhmqAopStyjwuYkFRCdZ+qP9y8i58DWbR4QrBVruKwk9ic6PPaXmrvQzNznN4b3K5P8PjgZbIg0m8q/Phu49/pxV2Y9ITSIueSI3jxoU2WYEWiY/5S+ERP2cpCqzw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Grygorii Strashko <grygorii_strashko@xxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
  • Delivery-date: Tue, 11 Nov 2025 17:54:25 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcUzQziKdu2C0rLUOkIzlzxAvY8g==
  • Thread-topic: [XEN][PATCH 3/5] x86: hvm: factor out compat code under ifdefs

From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>

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

Signed-off-by: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
---
 xen/arch/x86/hvm/hvm.c       | 13 ++++++++++++-
 xen/arch/x86/hvm/hypercall.c | 37 +++++++++++++++++++++++++++---------
 2 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 2e47a71714fd..56c0059401d0 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -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)
diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c
index 549e25445e67..f8b2c90b7c41 100644
--- a/xen/arch/x86/hvm/hypercall.c
+++ b/xen/arch/x86/hvm/hypercall.c
@@ -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;
-- 
2.34.1



 


Rackspace

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