From: Grygorii Strashko <grygorii_strashko@epam.com>
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@epam.com>
---
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
On 2025-11-19 14:30, Grygorii Strashko wrote:
> From: Grygorii Strashko <grygorii_strashko@epam.com>
>
> 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@epam.com>
> 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 */
> +}
> +
is_hcall_compat() matches the hcall_compat field, so I am okay with this.
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
However, is_compat_hcall() might be a slightly better name for the
helper. For me at least, I think of these as "compat hypercalls", so
that ordering reads a little more naturally for me. It's not a big
deal, but I figured I'd mention it in case others have an opinion.
Thanks,
Jason
© 2016 - 2025 Red Hat, Inc.