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

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


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Jürgen Groß <jgross@xxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Date: Thu, 4 Dec 2025 20:47:42 +0200
  • 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=SCIMsY63nvESKdY6wv1L3mIbm910UVVFoS4YF/TvM9g=; b=Khe7AunL6Fh7MwgkTopUtg8J9WwwdURC9dVvoHrKvvdVX+VU9ekBTSSCYamRNTYvib79bh0gTHF55OggdchTMfwHeS2hB5CXi6HD9xkFlCJLPQeH68pOxZNI1I+yT2qBapSEZtJHwzE6hpBAf3tcBF4un13Yeje0zijeOJAXLiFbxqD1Ga24tnRbXeRothjGTJyhpSybWy3Ns0p4rAWXMJwRfg2xHsrtXaQLEICJvBu0ba7H75uihcpT9bFM9t1wKseVq+eDAyLVsQyEZgVbLJGQf+/tOzBYCxD25hCj+JiD6MFWIM9xfNZ5aUoemAUjmE9Sa+YR8sxNPORfznND3g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lKPLNGMgsxNDzQZt084Q0XxY1RdRtQrozD2RaAsYn8bvY20U6BGYl1SnPaQmnd/XHc/viDceQza7nhzf4fO53byxJd7Bqk+Fze7Taw3O566+dxznY6ub7PmwRUTl74kJ9vMxf+38YyZWaJ/0IDBq1uG5BZFcHNce18d0u4p4ICDr3t5iOv+ml31NeOrLzINX6QQIfPin8w9lqtyj9oiAAPrRcQ1OPqB1I0JfZjXBzJPYYg5V6YmLAhqhF8qQ5zqbOcjoECS8uhxobk5Fr+wOgoc7aB0WVSFQ08LR2Db68guYHWdx+ftH1pM3hFwShlQbd3rN3Tn+4SCJ+vKzvi6KAw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: 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: Thu, 04 Dec 2025 18:47:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Jürgen,

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

On 19.11.25 21:30, Grygorii Strashko wrote:
From: Grygorii Strashko <grygorii_strashko@xxxxxxxx>

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.

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

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 0fd3f95b6e0e..19524cb7a914 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,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(
diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c
index 52cae1d15312..1ee0193b69af 100644
--- a/xen/arch/x86/hvm/hypercall.c
+++ b/xen/arch/x86/hvm/hypercall.c
@@ -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;
diff --git a/xen/arch/x86/include/asm/domain.h 
b/xen/arch/x86/include/asm/domain.h
index 5df8c7825333..0005f4450931 100644
--- a/xen/arch/x86/include/asm/domain.h
+++ b/xen/arch/x86/include/asm/domain.h
@@ -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;
diff --git a/xen/include/hypercall-defs.c b/xen/include/hypercall-defs.c
index cef08eeec1b8..08c01153ac56 100644
--- a/xen/include/hypercall-defs.c
+++ b/xen/include/hypercall-defs.c
@@ -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)

--
Best regards,
-grygorii




 


Rackspace

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