From: Grygorii Strashko <grygorii_strashko@epam.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Grygorii Strashko" <grygorii_strashko@epam.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Julien Grall" <julien@xen.org>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Alejandro Vallejo" <alejandro.garciavallejo@amd.com>,
"Jason Andryuk" <jason.andryuk@amd.com>,
"Jürgen Groß" <jgross@suse.com>
Subject: [XEN][PATCH v2 3/4] x86: hvm: factor out COMPAT code under ifdefs
Date: Wed, 19 Nov 2025 19:30:09 +0000 [thread overview]
Message-ID: <20251119192916.1009549-4-grygorii_strashko@epam.com> (raw)
In-Reply-To: <20251119192916.1009549-1-grygorii_strashko@epam.com>
From: Grygorii Strashko <grygorii_strashko@epam.com>
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@epam.com>
---
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)
--
2.34.1
next prev parent reply other threads:[~2025-11-19 19:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 19:30 [XEN][PATCH v2 0/4] x86: pvh: allow to disable 32-bit (COMPAT) interface support Grygorii Strashko
2025-11-19 19:30 ` [XEN][PATCH v2 1/4] x86: hvm: dm: factor out compat code under ifdefs Grygorii Strashko
2025-11-19 19:30 ` Grygorii Strashko [this message]
2025-12-02 19:26 ` [XEN][PATCH v2 3/4] x86: hvm: factor out COMPAT " Jason Andryuk
2025-12-04 18:39 ` Grygorii Strashko
2025-12-04 18:47 ` Grygorii Strashko
2025-12-18 16:47 ` Jürgen Groß
2025-11-19 19:30 ` [XEN][PATCH v2 2/4] x86: hvm: compat: introduce is_hcall_compat() helper Grygorii Strashko
2025-12-02 18:41 ` Jason Andryuk
2025-11-19 19:30 ` [XEN][PATCH v2 4/4] x86: pvh: allow to disable 32-bit interface support Grygorii Strashko
2025-12-02 19:56 ` Jason Andryuk
2025-12-18 16:20 ` [XEN][PATCH v2 0/4] x86: pvh: allow to disable 32-bit (COMPAT) " Grygorii Strashko
2025-12-18 16:33 ` Jan Beulich
2025-12-19 0:33 ` Stefano Stabellini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251119192916.1009549-4-grygorii_strashko@epam.com \
--to=grygorii_strashko@epam.com \
--cc=alejandro.garciavallejo@amd.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=jason.andryuk@amd.com \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.