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

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


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Date: Wed, 19 Nov 2025 19:30:09 +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=yxVNyvT9747pN+a6JgkjBZM2A2r4H6G+Y1GFsarwU5k=; b=Qts7YRhjBXkKz8T5mPdGFsXRxLhudQhwrug0O+ra7pTx8K6kr2RDQ382zwRrweVSu2/LhHqhjvSfDfKej+afuVtwu2SoZNaE8Ilr47oQYpd18YZkHPDY5Yzq+Dk0tRqtH25hXCg4ET6FAod7l34q9JIoaCoB9UW/rXbEguVo5ODBwEVkl5MwqjDFOdUJKrb+TrBLeSyTNMwY7bV/qceO0wiCuvB3YBMrWGHVXNMgp1cAw5VP/IFsHrxmpxV6CbVRXHNlOib4d7Uv9nWnLfBb2Qs76/oF05tTMDO40h56KRW6BJhp7A764A2qjVH0Hv2oFAS6JWrYa20Oao86xbPT7g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qJN4pVjaecb08Qv8WxboLvOBhm15mGG+doAz9iSpr6ifcocJUfPLRc2O7vLJ4IC4ZynU6tq6RSPrKaf6wPnUxDJOFYnI8OKE49z5sxygDEyo51rdfhfV/KxViJReLX3F48CfRwF19/JI3QG8zTpSXawo8V5n+OzX/hTdxILL3Sa8bxIXYiwalbq+b2jvffR+9jzPQhkuLvP8vVCWPIz585WBDVfyi9qZKwfWpkAuDasbqFX4tBoGr3/HZYf6KB674PPEZ4FAWqqfTo+ClexoCtpVAdw0yNHI63SfDozkgY4ZovznnfhNCbU/qNVsS5x0b0QZXZFzaTFZSM/Ewdw5/g==
  • 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>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>
  • Delivery-date: Wed, 19 Nov 2025 19:30:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcWYrqDL5Jc1Je5EipZt1jZOW+Bw==
  • Thread-topic: [XEN][PATCH v2 2/4] x86: hvm: compat: introduce is_hcall_compat() helper

From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>

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.

Signed-off-by: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
---
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(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 0ff242d4a0d6..0fd3f95b6e0e 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -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:
diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c
index b254b3e2f7d6..52cae1d15312 100644
--- a/xen/arch/x86/hvm/hypercall.c
+++ b/xen/arch/x86/hvm/hypercall.c
@@ -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);
diff --git a/xen/arch/x86/hypercall.c b/xen/arch/x86/hypercall.c
index dc0a90ca0915..5d1ac906fd37 100644
--- a/xen/arch/x86/hypercall.c
+++ b/xen/arch/x86/hypercall.c
@@ -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++ )
             {
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index e6979352e100..3ff06e315f57 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -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)
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 02bdc256ce37..ed6fdeeda9f9 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -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;
-- 
2.34.1



 


Rackspace

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