xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/arm: XEN_DOMCTL_get_address_size hypercall support
@ 2025-10-01 20:01 Milan Djokic
  2025-10-02 10:10 ` Andrew Cooper
  2025-10-03 10:05 ` Alejandro Vallejo
  0 siblings, 2 replies; 11+ messages in thread
From: Milan Djokic @ 2025-10-01 20:01 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Milan Djokic, Stefano Stabellini, Julien Grall, Bertrand Marquis,
	Michal Orzel, Volodymyr Babchuk

Signed-off-by: Milan Djokic <milan_djokic@epam.com>

---
XEN_DOMCTL_get_address_size hypercall is not implemented for arm (only for x86)
It would be useful to have this hypercall supported for arm64, in order to get
current guest addressing mode and also to verify that XEN_DOMCTL_set_address_size
performs switch to target addressing mode (instead of relying on its returned error code only).
---
 xen/arch/arm/arm64/domctl.c       | 46 +++++++++++++++++++++++++++++--
 xen/arch/arm/domain.c             |  5 ++++
 xen/arch/arm/include/asm/domain.h |  1 +
 3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/arm64/domctl.c b/xen/arch/arm/arm64/domctl.c
index 8720d126c9..f227309e06 100644
--- a/xen/arch/arm/arm64/domctl.c
+++ b/xen/arch/arm/arm64/domctl.c
@@ -12,6 +12,7 @@
 #include <public/domctl.h>
 #include <asm/arm64/sve.h>
 #include <asm/cpufeature.h>
+#include <xen/guest_access.h>
 
 static long switch_mode(struct domain *d, enum domain_type type)
 {
@@ -33,6 +34,37 @@ static long switch_mode(struct domain *d, enum domain_type type)
     return 0;
 }
 
+static long get_address_size(struct domain *d, uint32_t *address_size)
+{
+    long rc = 0;
+    struct vcpu *v;
+    /* Check invalid arguments */
+    if ( d == NULL || address_size == NULL) {
+        rc = -EINVAL;
+    }
+    /* Domain structure type field and actual vcpu mode must be aligned */
+    if(rc == 0) {
+        for_each_vcpu(d, v) {
+            if(vcpu_get_mode(v) != d->arch.type) {
+                rc = -EFAULT;
+            }
+        }
+    }
+
+    if(rc == 0) {
+        if(d->arch.type == DOMAIN_32BIT) {
+            *address_size = 32U;
+        }
+        else if(d->arch.type == DOMAIN_64BIT) {
+            *address_size = 64U;
+        }
+        else {
+            rc = -EFAULT;
+        }
+    }
+    return rc;
+}
+
 static long set_address_size(struct domain *d, uint32_t address_size)
 {
     switch ( address_size )
@@ -54,14 +86,22 @@ static long set_address_size(struct domain *d, uint32_t address_size)
 long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
                        XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
 {
+    long rc = 0;
     switch ( domctl->cmd )
     {
     case XEN_DOMCTL_set_address_size:
-        return set_address_size(d, domctl->u.address_size.size);
-
+        rc = set_address_size(d, domctl->u.address_size.size);
+        break;
+    case XEN_DOMCTL_get_address_size:
+        rc = get_address_size(d, &domctl->u.address_size.size);
+        if(__copy_to_guest(u_domctl, domctl, 1)) {
+            rc = -EFAULT;
+        }
+        break;
     default:
-        return -ENOSYS;
+        rc = -ENOSYS;
     }
+    return rc;
 }
 
 /*
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index 1a8585d02b..9096dc7411 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -608,6 +608,11 @@ void vcpu_switch_to_aarch64_mode(struct vcpu *v)
     v->arch.hcr_el2 |= HCR_RW;
 }
 
+unsigned int vcpu_get_mode(struct vcpu *v)
+{
+    return v->arch.hcr_el2 & HCR_RW ? DOMAIN_64BIT : DOMAIN_32BIT;
+}
+
 int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
 {
     unsigned int max_vcpus;
diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h
index af3e168374..e64402a67d 100644
--- a/xen/arch/arm/include/asm/domain.h
+++ b/xen/arch/arm/include/asm/domain.h
@@ -252,6 +252,7 @@ struct arch_vcpu
 
 void vcpu_show_registers(struct vcpu *v);
 void vcpu_switch_to_aarch64_mode(struct vcpu *v);
+unsigned int vcpu_get_mode(struct vcpu *v);
 
 /*
  * Due to the restriction of GICv3, the number of vCPUs in AFF0 is
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-10-06 11:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-01 20:01 [PATCH] xen/arm: XEN_DOMCTL_get_address_size hypercall support Milan Djokic
2025-10-02 10:10 ` Andrew Cooper
2025-10-02 11:10   ` Milan Djokic
2025-10-02 12:43     ` Julien Grall
2025-10-03  9:26       ` Milan Djokic
2025-10-02 18:27   ` Demi Marie Obenour
2025-10-03 10:00     ` Alejandro Vallejo
2025-10-03 10:14     ` Julien Grall
2025-10-03 16:03       ` Demi Marie Obenour
2025-10-06 11:28         ` Julien Grall
2025-10-03 10:05 ` Alejandro Vallejo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).