Skip to contentSkip to conversation

xen/arm: report proper GIC version via XEN_DOMCTL_getdomaininfo

PATCH Superseded Julian Vetter 3 participants 11 messages Jul 10 – Jul 13 2 messages not in the archive

Subsystems (2)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/6 xen/arm: report proper GIC version via XEN_DOMCTL_getdomaininfo

When creating a domain on ARM, and passing XEN_DOMCTL_CONFIG_GIC_NATIVE for the gic_version field in the struct xen_arch_domainconfig, arch_sanitise_domain_config() resolves this to the approrpiate GIC_V2 or GIC_V3 version the domain actually has, based on the host's gic_hw_version(). That value is stored in the domain as d->arch.vgic.version, but can't be queried through any other domctl later. Toolstacks that create and build a domain in the same call already have this info from the createdomain reply and never need to ask again.

Toolstacks that create a domain and build it later from a separate process do need to ask again. But, the ARM implementation only fills in info->flags and info->gpaddr_bits. info->arch_config is left zeroed, so XEN_DOMCTL_getdomaininfo always reports gic_version as XEN_DOMCTL_CONFIG_GIC_NATIVE (0) regardless of what was actually configured earlier.

---
Changes in v2:
- Nothing

---
 xen/arch/arm/domctl.c | 2 ++
 1 file changed, 2 insertions(+)
xen/arch/arm/domctl.c +2 -0
index 6c9a3f9920..b76af56fad 100644
@@ -24,6 +24,8 @@ void arch_get_domain_info(const struct domain *d,
     info->flags |= XEN_DOMINF_hap;
 
     info->gpaddr_bits = p2m_ipa_bits;
+
+    info->arch_config.gic_version = d->arch.vgic.version;
 }
 
 static int handle_vuart_init(struct domain *d, 
Signature · 10 lines
2.53.0



--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
Reviewed-by on v2 1/6
#2 lore raw
Quoted 10 lines · Julian Vetter

When creating a domain on ARM, and passing XEN_DOMCTL_CONFIG_GIC_NATIVE for the gic_version field in the struct xen_arch_domainconfig, arch_sanitise_domain_config() resolves this to the approrpiate GIC_V2 or GIC_V3 version the domain actually has, based on the host's gic_hw_version(). That value is stored in the domain as d->arch.vgic.version, but can't be queried through any other domctl later. Toolstacks that create and build a domain in the same call already have this info from the createdomain reply and never need to ask again.

Quoted 8 lines

Toolstacks that create a domain and build it later from a separate process do need to ask again. But, the ARM implementation only fills in info->flags and info->gpaddr_bits. info->arch_config is left zeroed, so XEN_DOMCTL_getdomaininfo always reports gic_version as XEN_DOMCTL_CONFIG_GIC_NATIVE (0) regardless of what was actually configured earlier.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

PATCH v2 2/6 ARM/sysctl: Expose the supported guest GIC modes in physinfo

From: Andrew Cooper <[email protected]>

---
Changes in v2:
- New patch

---
 xen/arch/arm/sysctl.c       | 26 ++++++++++++++++++++++++++
 xen/include/public/sysctl.h |  2 ++
 2 files changed, 28 insertions(+)
xen/arch/arm/sysctl.c +26 -0
index 32cab4feff..3b0edf4cec 100644
@@ -12,7 +12,10 @@
 #include <xen/dt-overlay.h>
 #include <xen/errno.h>
 #include <xen/hypercall.h>
+
 #include <asm/arm64/sve.h>
+#include <asm/gic.h>
+
 #include <public/sysctl.h>
 
 void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
@@ -21,6 +24,29 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
 
     pi->arch_capabilities |= MASK_INSR(sve_encode_vl(get_sys_vl_len()),
                                        XEN_SYSCTL_PHYSCAP_ARM_SVE_MASK);
+
+    /*
+     * The GIC version(s) we're happy creating guests with.  Right now for
+     * simplicity it is tied to the active hardware version, but this will
+     * cease to be the case if/when the compatbility modes are enabled.
+     */
+    switch ( gic_hw_version() )
+    {
+    case GIC_V2:
+        pi->arch_capabilities |= XEN_SYSCTL_PHYSCAP_ARM_GIC_V2;
+        break;
+
+    case GIC_V3:
+        pi->arch_capabilities |= XEN_SYSCTL_PHYSCAP_ARM_GIC_V3;
+        break;
+
+    case GIC_INVALID:
+        /*
+         * Running a control domain without having the GIC sorted yet?
+         * Something's broken, but there's nothing we can do about it here.
+         */
+        break;
+    }
 }
 
 long arch_do_sysctl(struct xen_sysctl *sysctl,
xen/include/public/sysctl.h +2 -0
index c7cd9b4eb0..d20ebf3644 100644
@@ -106,6 +106,8 @@ struct xen_sysctl_tbuf_op {
 
 #if defined(__arm__) || defined(__aarch64__)
 #define XEN_SYSCTL_PHYSCAP_ARM_SVE_MASK  (0x1FU)
+#define XEN_SYSCTL_PHYSCAP_ARM_GIC_V2    (1U << 5)
+#define XEN_SYSCTL_PHYSCAP_ARM_GIC_V3    (1U << 6)
 #endif
 
 struct xen_sysctl_physinfo {
Signature · 10 lines
2.53.0



--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#5 lore raw

PATCH v2 3/6 xen/arm: choose GIC version explicitly instead of GIC_NATIVE

In reply to a message not in the archive

From: Andrew Cooper <[email protected]>

XEN_DOMCTL_CONFIG_GIC_NATIVE lets the toolstack ask Xen to silently resolve the domain's GIC version to whatever the host hardware has. Xen then writes the resolved value back into the same in/out xen_arch_domainconfig the toolstack used as input, which is the kind of API abuse we're trying to get rid of. The struct passed to createdomain should only be an input parameter.

Move the "pick the best available GIC version" decision to the toolstack, using the XEN_SYSCTL_PHYSCAP_ARM_GIC_V2/V3 capability bits already exposed via XEN_SYSCTL_physinfo:

* libxl__arch_domain_build_info_setdefault() resolves LIBXL_GIC_VERSION_DEFAULT to v3 if available, else v2, else fails, before the config is built.
* The Python xc.domain_create() binding does the same via a call to xc_physinfo().
* libxl__arch_domain_prepare_config() therefore only ever sees a concrete v2/v3 request and just validates it.

On the Xen side, arch_sanitise_domain_config() and the two in-Xen domain builders (create_dom0() and arch_parse_dom0less_node(), which always want a vGIC that exactly matches the hardware) no longer resolve GIC_NATIVE either. A new gic_domctl_version() helper returns the XEN_DOMCTL_CONFIG_GIC_* value matching the host's gic_hw_version(), used by all three. arch_sanitise_domain_config() now only validates that the requested version is compatible with the hardware, rather than changing config->arch.gic_version in place.

---
Changes in v2:
- New patch

---
 .../include/xen-tools/arm-arch-capabilities.h | 21 ++++++++++++++++
 tools/libs/light/libxl_arm.c                  | 15 ++++++++---
 tools/python/xen/lowlevel/xc/xc.c             | 18 ++++++++++++-
 xen/arch/arm/dom0less-build.c                 |  3 ++-
 xen/arch/arm/domain.c                         | 25 +++++++------------
 xen/arch/arm/domain_build.c                   |  3 ++-
 xen/arch/arm/gic.c                            | 16 ++++++++++++
 xen/arch/arm/include/asm/gic.h                |  6 +++++
 8 files changed, 85 insertions(+), 22 deletions(-)
tools/include/xen-tools/arm-arch-capabilities.h +21 -0
index 4aa4c6c34a..21e3c73bd1 100644
@@ -6,6 +6,7 @@
 #ifndef ARM_ARCH_CAPABILITIES_H
 #define ARM_ARCH_CAPABILITIES_H
 
+#include <stdbool.h>
 #include <stdint.h>
 #include <xen/sysctl.h>
 
@@ -25,4 +26,24 @@ unsigned int arch_capabilities_arm_sve(unsigned int arch_capabilities)
 #endif
 }
 
+static inline
+bool arch_capabilities_arm_gic_v2(unsigned int arch_capabilities)
+{
+#if defined(__arm__) || defined(__aarch64__)
+    return MASK_EXTR(arch_capabilities, XEN_SYSCTL_PHYSCAP_ARM_GIC_V2);
+#else
+    return false;
+#endif
+}
+
+static inline
+bool arch_capabilities_arm_gic_v3(unsigned int arch_capabilities)
+{
+#if defined(__arm__) || defined(__aarch64__)
+    return MASK_EXTR(arch_capabilities, XEN_SYSCTL_PHYSCAP_ARM_GIC_V3);
+#else
+    return false;
+#endif
+}
+
 #endif /* ARM_ARCH_CAPABILITIES_H */
tools/libs/light/libxl_arm.c +12 -3
index 7e9f8a1bc3..f26ed261dc 100644
@@ -196,9 +196,6 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
     LOG(DEBUG, " - Allocate %u SPIs", config->arch.nr_spis);
 
     switch (d_config->b_info.arch_arm.gic_version) {
-    case LIBXL_GIC_VERSION_DEFAULT:
-        config->arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
-        break;
     case LIBXL_GIC_VERSION_V2:
         config->arch.gic_version = XEN_DOMCTL_CONFIG_GIC_V2;
         break;
@@ -1800,6 +1797,18 @@ int libxl__arch_domain_build_info_setdefault(libxl__gc *gc,
     /* Trapping of unmapped accesses enabled by default.  */
     libxl_defbool_setdefault(&b_info->trap_unmapped_accesses, true);
 
+    /* Pick the best GIC version available if none was requested. */
+    if (b_info->arch_arm.gic_version == LIBXL_GIC_VERSION_DEFAULT) {
+        if (arch_capabilities_arm_gic_v3(physinfo->arch_capabilities))
+            b_info->arch_arm.gic_version = LIBXL_GIC_VERSION_V3;
+        else if (arch_capabilities_arm_gic_v2(physinfo->arch_capabilities))
+            b_info->arch_arm.gic_version = LIBXL_GIC_VERSION_V2;
+        else {
+            LOG(ERROR, "No supported GIC version found on this host");
+            return ERROR_FAIL;
+        }
+    }
+
     /* Sanitise SVE parameter */
     if (b_info->arch_arm.sve_vl) {
         unsigned int max_sve_vl =
tools/python/xen/lowlevel/xc/xc.c +17 -1
index 7a4bf54597..0127b4b1b7 100644
@@ -163,7 +163,23 @@ static PyObject *pyxc_domain_create(XcObject *self,
                                       ~(XEN_X86_EMU_VPCI |
                                         XEN_X86_EMU_USE_PIRQ);
 #elif defined (__arm__) || defined(__aarch64__)
-    config.arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
+    {
+        xc_physinfo_t pinfo;
+
+        if ( xc_physinfo(self->xc_handle, &pinfo) != 0 )
+            return pyxc_error_to_exception(self->xc_handle);
+
+        if ( arch_capabilities_arm_gic_v3(pinfo.arch_capabilities) )
+            config.arch.gic_version = XEN_DOMCTL_CONFIG_GIC_V3;
+        else if ( arch_capabilities_arm_gic_v2(pinfo.arch_capabilities) )
+            config.arch.gic_version = XEN_DOMCTL_CONFIG_GIC_V2;
+        else
+        {
+            errno = EINVAL;
+            PyErr_SetFromErrno(xc_error_obj);
+            return NULL;
+        }
+    }
 #else
 #error Architecture not supported
 #endif
xen/arch/arm/dom0less-build.c +2 -1
index 3f48f74226..5b01843db4 100644
@@ -23,6 +23,7 @@
 #include <asm/arm64/sve.h>
 #include <asm/domain_build.h>
 #include <asm/firmware/sci.h>
+#include <asm/gic.h>
 #include <asm/grant_table.h>
 #include <asm/setup.h>
 
@@ -368,7 +369,7 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,
     unsigned int flags = bd->create_flags;
     uint32_t val;
 
-    d_cfg->arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
+    d_cfg->arch.gic_version = gic_domctl_version();
     d_cfg->flags |= XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap;
 
     if ( domu_dt_sci_parse(node, d_cfg) )
xen/arch/arm/domain.c +9 -16
index baa3a5d708..b396d5e615 100644
@@ -609,23 +609,16 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         return -EINVAL;
     }
 
-    /* Fill in the native GIC version, passed back to the toolstack. */
-    if ( config->arch.gic_version == XEN_DOMCTL_CONFIG_GIC_NATIVE )
+    /*
+     * The toolstack must pick a specific GIC version. Xen doesn't choose on
+     * its behalf. It only checks the requested version matches what the
+     * hardware actually has. There's currently no support to run a guest on a
+     * GIC version other than the host's.
+     */
+    if ( config->arch.gic_version != gic_domctl_version() )
     {
-        switch ( gic_hw_version() )
-        {
-        case GIC_V2:
-            config->arch.gic_version = XEN_DOMCTL_CONFIG_GIC_V2;
-            break;
-
-        case GIC_V3:
-            config->arch.gic_version = XEN_DOMCTL_CONFIG_GIC_V3;
-            break;
-
-        default:
-            ASSERT_UNREACHABLE();
-            return -EINVAL;
-        }
+        dprintk(XENLOG_INFO, "Unsupported GIC version\n");
+        return -EINVAL;
     }
 
     /* max_vcpus depends on the GIC version, and Xen's compiled limit. */
xen/arch/arm/domain_build.c +2 -1
index 550617f152..2e00fc3e52 100644
@@ -26,6 +26,7 @@
 #include <xen/warning.h>
 #include <xen/static-shmem.h>
 #include <asm/device.h>
+#include <asm/gic.h>
 #include <asm/setup.h>
 #include <asm/tee/tee.h>
 #include <asm/pci.h>
@@ -1960,7 +1961,7 @@ void __init create_dom0(void)
     int rc;
 
     /* The vGIC for DOM0 is exactly emulating the hardware GIC */
-    dom0_cfg.arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
+    dom0_cfg.arch.gic_version = gic_domctl_version();
     dom0_cfg.arch.nr_spis = vgic_def_nr_spis();
     dom0_cfg.arch.tee_type = tee_get_type();
     dom0_cfg.max_vcpus = dom0_max_vcpus();
xen/arch/arm/gic.c +16 -0
index ee75258fc3..fc55a65159 100644
@@ -56,6 +56,22 @@ enum gic_version gic_hw_version(void)
    return gic_hw_ops->info->hw_version;
 }
 
+uint8_t gic_domctl_version(void)
+{
+    switch ( gic_hw_version() )
+    {
+    case GIC_V2:
+        return XEN_DOMCTL_CONFIG_GIC_V2;
+
+    case GIC_V3:
+        return XEN_DOMCTL_CONFIG_GIC_V3;
+
+    default:
+        ASSERT_UNREACHABLE();
+        return 0;
+    }
+}
+
 unsigned int gic_number_lines(void)
 {
     return gic_hw_ops->info->nr_lines;
xen/arch/arm/include/asm/gic.h +6 -0
index ff22dea40d..de6eabfadd 100644
@@ -262,6 +262,12 @@ DECLARE_PER_CPU(uint64_t, lr_mask);
 
 extern enum gic_version gic_hw_version(void);
 
+/*
+ * The XEN_DOMCTL_CONFIG_GIC_* value matching the GIC version actually
+ * present on this host.
+ */
+extern uint8_t gic_domctl_version(void);
+
 /* Program the IRQ type into the GIC */
 void gic_set_irq_type(struct irq_desc *desc, unsigned int type);
 
Signature · 10 lines
2.53.0



--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#6 lore raw

Re: [PATCH v2 3/6] xen/arm: choose GIC version explicitly instead of GIC_NATIVE

Quoted 30 lines · Julian Vetter

From: Andrew Cooper <[email protected]>

XEN_DOMCTL_CONFIG_GIC_NATIVE lets the toolstack ask Xen to silently resolve the domain's GIC version to whatever the host hardware has. Xen then writes the resolved value back into the same in/out xen_arch_domainconfig the toolstack used as input, which is the kind of API abuse we're trying to get rid of. The struct passed to createdomain should only be an input parameter.

Move the "pick the best available GIC version" decision to the toolstack, using the XEN_SYSCTL_PHYSCAP_ARM_GIC_V2/V3 capability bits already exposed via XEN_SYSCTL_physinfo:

* libxl__arch_domain_build_info_setdefault() resolves LIBXL_GIC_VERSION_DEFAULT to v3 if available, else v2, else fails, before the config is built.
* The Python xc.domain_create() binding does the same via a call to xc_physinfo().
* libxl__arch_domain_prepare_config() therefore only ever sees a concrete v2/v3 request and just validates it.

On the Xen side, arch_sanitise_domain_config() and the two in-Xen domain builders (create_dom0() and arch_parse_dom0less_node(), which always want a vGIC that exactly matches the hardware) no longer resolve GIC_NATIVE either. A new gic_domctl_version() helper returns the XEN_DOMCTL_CONFIG_GIC_* value matching the host's gic_hw_version(), used by all three. arch_sanitise_domain_config() now only validates that the requested version is compatible with the hardware, rather than changing config->arch.gic_version in place.

Quoted 1 line

Ah - my test branch didn't have a SoB line, but you need one from me if you want to keep me as author.

However, my version didn't even compile, and you've done almost all the work in this patch, so just take full ownership and solve the problem that way.

Quoted 13 lines

---
Changes in v2:
- New patch

---
 .../include/xen-tools/arm-arch-capabilities.h | 21 ++++++++++++++++
 tools/libs/light/libxl_arm.c                  | 15 ++++++++---
 tools/python/xen/lowlevel/xc/xc.c             | 18 ++++++++++++-
 xen/arch/arm/dom0less-build.c                 |  3 ++-
 xen/arch/arm/domain.c                         | 25 +++++++------------
 xen/arch/arm/domain_build.c                   |  3 ++-
 xen/arch/arm/gic.c                            | 16 ++++++++++++
 xen/arch/arm/include/asm/gic.h                |  6 +++++
 8 files changed, 85 insertions(+), 22 deletions(-)

Also, I think you want to split this patch in two, and merge half into the subsequent patch.

In this patch, deal only with the tools side of things guaranteeing not to produce XEN_DOMCTL_CONFIG_GIC_NATIVE.

Then in the subsequent patch, delete XEN_DOMCTL_CONFIG_GIC_NATIVE and disallow it from being consumed by Xen.  That way, you've got one clean tools patch and one clean Xen patch.

Quoted 26 lines
tools/include/xen-tools/arm-arch-capabilities.h +10 -0
index 4aa4c6c34a..21e3c73bd1 100644
@@ -6,6 +6,7 @@
 #ifndef ARM_ARCH_CAPABILITIES_H
 #define ARM_ARCH_CAPABILITIES_H
 
+#include <stdbool.h>
 #include <stdint.h>
 #include <xen/sysctl.h>
 
@@ -25,4 +26,24 @@ unsigned int arch_capabilities_arm_sve(unsigned int arch_capabilities)
 #endif
 }
 
+static inline
+bool arch_capabilities_arm_gic_v2(unsigned int arch_capabilities)
+{
+#if defined(__arm__) || defined(__aarch64__)
+    return MASK_EXTR(arch_capabilities, XEN_SYSCTL_PHYSCAP_ARM_GIC_V2);
+#else
+    return false;
+#endif
+}

tools/include/xen-tools/arm-arch-capabilities.h unsigned int arch_capabilities_arm_sve(unsigned int arch_capabilities) · line 47

Quoted 10 lines
tools/include/xen-tools/arm-arch-capabilities.h +10 -0
+
+static inline
+bool arch_capabilities_arm_gic_v3(unsigned int arch_capabilities)
+{
+#if defined(__arm__) || defined(__aarch64__)
+    return MASK_EXTR(arch_capabilities, XEN_SYSCTL_PHYSCAP_ARM_GIC_V3);
+#else
+    return false;
+#endif
+}

This is truly awful, but seems to be the prevailing pattern.

~Andrew

#7 lore raw

PATCH v2 4/6 xen/arm: remove XEN_DOMCTL_CONFIG_GIC_NATIVE from the ABI

In reply to a message not in the archive

From: Andrew Cooper <[email protected]>

Now that nothing resolves or relies on GIC_NATIVE (the previous patch moved that decision entirely into the toolstack and Xen's own dom0/ dom0less builders), drop it from the public ABI. Every caller must now request a concrete GIC_V2 or GIC_V3.

This is an incompatible change for any toolstack still passing 0 (formerly GIC_NATIVE) expecting Xen to auto-select a version, so bump XEN_DOMCTL_INTERFACE_VERSION.

---
Changes in v2:
- New patch

---
 xen/include/public/arch-arm.h | 1 -
 xen/include/public/domctl.h   | 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)
xen/include/public/arch-arm.h +0 -1
index 7d6f87e8b2..6987f5bdf4 100644
@@ -319,7 +319,6 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
  * struct xen_arch_domainconfig's ABI is covered by
  * XEN_DOMCTL_INTERFACE_VERSION.
  */
-#define XEN_DOMCTL_CONFIG_GIC_NATIVE    0
 #define XEN_DOMCTL_CONFIG_GIC_V2        1
 #define XEN_DOMCTL_CONFIG_GIC_V3        2
 
xen/include/public/domctl.h +2 -2
index 510300bb67..4ca8a2d7ca 100644
@@ -30,9 +30,9 @@
  * fields) don't require a change of the version.
  * Stable ops are NOT covered by XEN_DOMCTL_INTERFACE_VERSION!
  *
- * Last version bump: Xen 4.22
+ * Last version bump: Xen 4.23
  */
-#define XEN_DOMCTL_INTERFACE_VERSION 0x00000018
+#define XEN_DOMCTL_INTERFACE_VERSION 0x00000019
 
 /*
  * NB. xen_domctl.domain is an IN/OUT parameter for this operation.
Signature · 10 lines
2.53.0



--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#8 lore raw

Re: [PATCH v2 4/6] xen/arm: remove XEN_DOMCTL_CONFIG_GIC_NATIVE from the ABI

Quoted 7 lines · Julian Vetter

From: Andrew Cooper <[email protected]>

Now that nothing resolves or relies on GIC_NATIVE (the previous patch moved that decision entirely into the toolstack and Xen's own dom0/ dom0less builders), drop it from the public ABI. Every caller must now request a concrete GIC_V2 or GIC_V3.

Quoted 5 lines

This is an incompatible change for any toolstack still passing 0 (formerly GIC_NATIVE) expecting Xen to auto-select a version, so bump XEN_DOMCTL_INTERFACE_VERSION.

As before, take ownership of this patch.

Along with half of the previous patch, you must put an entry into CHANGELOG.md saying that XEN_DOMCTL_CONFIG_GIC_NATIVE has been deleted and toolstacks must choose GIC_V2 or V3 explicitly.

~Andrew

#9 lore raw

PATCH v2 5/6 xen/arm: report clock_frequency via sysctl physinfo, not createdomain

In reply to a message not in the archive

The xen_arch_domainconfig.clock_frequency value is populated in domain_vtimer_init() during XEN_DOMCTL_createdomain from the global timer_dt_clock_frequency, which comes from the host's DT timer node and has nothing to do with the domain being created. Like now removed GIC_NATIVE resolution, this is a host-wide system property being smuggled out through a domain-creation IN struct.

Expose it instead as a new arch_clock_frequency field in XEN_SYSCTL_physinfo, populated via arch_do_physinfo(), and mirroring how the GIC capability bits were already moved there. The XEN_DOMCTL_INTERFACE_VERSION doesn't need to be bumped, because only a previously zero'ed / ignored field is now used.

The xen_arch_domainconfig parameter passed to domain_vtimer_init() is no longer needed, so drop that parameter entirely. libxl now fetches the frequency via libxl_get_physinfo() in libxl__arch_domain_save_config() instead of reading it back out of the createdomain reply. The OCaml xen_arch_domainconfig mirror drops the field too.

---
Changes in v2:
- New patch

---
 tools/libs/light/libxl.c          |  1 +
 tools/libs/light/libxl_arm.c      | 13 ++++++++++++-
 tools/libs/light/libxl_types.idl  |  1 +
 tools/ocaml/libs/xc/xenctrl.ml    |  1 -
 tools/ocaml/libs/xc/xenctrl.mli   |  1 -
 xen/arch/arm/domain.c             |  2 +-
 xen/arch/arm/include/asm/vtimer.h |  3 +--
 xen/arch/arm/sysctl.c             |  3 +++
 xen/arch/arm/vtimer.c             |  4 +---
 xen/include/public/arch-arm.h     | 16 +---------------
 xen/include/public/sysctl.h       | 13 ++++++++++++-
 11 files changed, 33 insertions(+), 25 deletions(-)
tools/libs/light/libxl.c +1 -0
index a1fe16274d..2023385aa3 100644
@@ -410,6 +410,7 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
     physinfo->cap_gnttab_v2 =
         !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_gnttab_v2);
     physinfo->arch_capabilities = xcphysinfo.arch_capabilities;
+    physinfo->arch_clock_frequency = xcphysinfo.arch_clock_frequency;
 
     GC_FREE;
     return 0;
tools/libs/light/libxl_arm.c +12 -1
index f26ed261dc..4da7b26151 100644
@@ -252,6 +252,9 @@ int libxl__arch_domain_save_config(libxl__gc *gc,
                                    libxl__domain_build_state *state,
                                    const struct xen_domctl_createdomain *config)
 {
+    libxl_physinfo info;
+    int rc;
+
     switch (config->arch.gic_version) {
     case XEN_DOMCTL_CONFIG_GIC_V2:
         d_config->b_info.arch_arm.gic_version = LIBXL_GIC_VERSION_V2;
@@ -264,7 +267,15 @@ int libxl__arch_domain_save_config(libxl__gc *gc,
         return ERROR_FAIL;
     }
 
-    state->clock_frequency = config->arch.clock_frequency;
+    libxl_physinfo_init(&info);
+    rc = libxl_get_physinfo(CTX, &info);
+    if (rc) {
+        LOG(ERROR, "failed to get physinfo");
+        libxl_physinfo_dispose(&info);
+        return ERROR_FAIL;
+    }
+    state->clock_frequency = info.arch_clock_frequency;
+    libxl_physinfo_dispose(&info);
 
     return 0;
 }
tools/libs/light/libxl_types.idl +1 -0
index a7893460f0..3cda5f8e2b 100644
@@ -1201,6 +1201,7 @@ libxl_physinfo = Struct("physinfo", [
     ("cap_gnttab_v1", bool),
     ("cap_gnttab_v2", bool),
     ("arch_capabilities", uint32),
+    ("arch_clock_frequency", uint32), # ARM only
     ], dir=DIR_OUT)
 
 libxl_connectorinfo = Struct("connectorinfo", [
tools/ocaml/libs/xc/xenctrl.ml +0 -1
index 147afa62c2..582897af6d 100644
@@ -32,7 +32,6 @@ type xen_arm_arch_domainconfig =
   {
     gic_version: int;
     nr_spis: int;
-    clock_frequency: int32;
   }
 
 type x86_arch_emulation_flags =
tools/ocaml/libs/xc/xenctrl.mli +0 -1
index 9fccb2c2c2..9414b87164 100644
@@ -26,7 +26,6 @@ type vcpuinfo = {
 type xen_arm_arch_domainconfig = {
   gic_version: int;
   nr_spis: int;
-  clock_frequency: int32;
 }
 
 type x86_arch_emulation_flags =
xen/arch/arm/domain.c +1 -1
index b396d5e615..d6d80ac55d 100644
@@ -711,7 +711,7 @@ int arch_domain_create(struct domain *d,
     if ( (rc = domain_vgic_init(d, config->arch.nr_spis)) != 0 )
         goto fail;
 
-    if ( (rc = domain_vtimer_init(d, &config->arch)) != 0 )
+    if ( (rc = domain_vtimer_init(d)) != 0 )
         goto fail;
 
     if ( (rc = tee_domain_init(d, config->arch.tee_type)) != 0 )
xen/arch/arm/include/asm/vtimer.h +1 -2
index 9d4fb4c6e8..6bbfcf4e69 100644
@@ -20,8 +20,7 @@
 #ifndef __ARCH_ARM_VTIMER_H__
 #define __ARCH_ARM_VTIMER_H__
 
-extern int domain_vtimer_init(struct domain *d,
-                              struct xen_arch_domainconfig *config);
+extern int domain_vtimer_init(struct domain *d);
 extern int vcpu_vtimer_init(struct vcpu *v);
 extern bool vtimer_emulate(struct cpu_user_regs *regs, union hsr hsr);
 extern void virt_timer_save(struct vcpu *v);
xen/arch/arm/sysctl.c +3 -0
index 3b0edf4cec..9cddabe006 100644
@@ -15,6 +15,7 @@
 
 #include <asm/arm64/sve.h>
 #include <asm/gic.h>
+#include <asm/time.h>
 
 #include <public/sysctl.h>
 
@@ -25,6 +26,8 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
     pi->arch_capabilities |= MASK_INSR(sve_encode_vl(get_sys_vl_len()),
                                        XEN_SYSCTL_PHYSCAP_ARM_SVE_MASK);
 
+    pi->arch_clock_frequency = timer_dt_clock_frequency;
+
     /*
      * The GIC version(s) we're happy creating guests with.  Right now for
      * simplicity it is tied to the active hardware version, but this will
xen/arch/arm/vtimer.c +1 -3
index 2e85ff2b6e..18f5676158 100644
@@ -52,7 +52,7 @@ static void virt_timer_expired(void *data)
     perfc_incr(vtimer_virt_inject);
 }
 
-int domain_vtimer_init(struct domain *d, struct xen_arch_domainconfig *config)
+int domain_vtimer_init(struct domain *d)
 {
     d->arch.virt_timer_base.offset = get_cycles();
     d->arch.virt_timer_base.nanoseconds =
@@ -60,8 +60,6 @@ int domain_vtimer_init(struct domain *d, struct xen_arch_domainconfig *config)
     d->time_offset.seconds = d->arch.virt_timer_base.nanoseconds;
     do_div(d->time_offset.seconds, 1000000000);
 
-    config->clock_frequency = timer_dt_clock_frequency;
-
     /*
      * Per the ACPI specification, providing a secure EL1 timer
      * interrupt is optional and will be ignored by non-secure OS.
xen/include/public/arch-arm.h +1 -15
index 6987f5bdf4..b88c61c8ff 100644
@@ -334,7 +334,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
 #define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_VMSA    2
 
 struct xen_arch_domainconfig {
-    /* IN/OUT */
+    /* IN */
     uint8_t gic_version;
     /* IN - Contains SVE vector length divided by 128 */
     uint8_t sve_vl;
@@ -342,20 +342,6 @@ struct xen_arch_domainconfig {
     uint16_t tee_type;
     /* IN */
     uint32_t nr_spis;
-    /*
-     * OUT
-     * Based on the property clock-frequency in the DT timer node.
-     * The property may be present when the bootloader/firmware doesn't
-     * set correctly CNTFRQ which hold the timer frequency.
-     *
-     * As it's not possible to trap this register, we have to replicate
-     * the value in the guest DT.
-     *
-     * = 0 => property not present
-     * > 0 => Value of the property
-     *
-     */
-    uint32_t clock_frequency;
     /* IN */
     uint8_t arm_sci_type;
     /* IN */
xen/include/public/sysctl.h +12 -1
index d20ebf3644..bc3e1541ae 100644
@@ -120,7 +120,18 @@ struct xen_sysctl_physinfo {
     uint32_t cpu_khz;
     uint32_t capabilities;/* XEN_SYSCTL_PHYSCAP_??? */
     uint32_t arch_capabilities;/* XEN_SYSCTL_PHYSCAP_{X86,ARM,...}_??? */
-    uint32_t pad;
+    /*
+     * ARM only. Based on the property clock-frequency in the DT timer node.
+     * The property may be present when the bootloader/firmware doesn't
+     * correctly set CNTFRQ to hold the timer frequency.
+     *
+     * As it's not possible to trap this register, we have to replicate the
+     * value in the guest DT.
+     *
+     * = 0 => property not present, or non-ARM
+     * > 0 => Value of the property
+     */
+    uint32_t arch_clock_frequency;
     uint64_aligned_t total_pages;
     uint64_aligned_t free_pages;
     uint64_aligned_t scrub_pages;
Signature · 10 lines
2.53.0



--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#10 lore raw

Re: [PATCH v2 5/6] xen/arm: report clock_frequency via sysctl physinfo, not createdomain

xen/include/public/sysctl.h struct xen_sysctl_physinfo { · line 124

Quoted 9 lines · Julian Vetter
xen/include/public/sysctl.h +2 -1
@@ -120,7 +120,18 @@ struct xen_sysctl_physinfo {
     uint32_t cpu_khz;
     uint32_t capabilities;/* XEN_SYSCTL_PHYSCAP_??? */
     uint32_t arch_capabilities;/* XEN_SYSCTL_PHYSCAP_{X86,ARM,...}_??? */
-    uint32_t pad;
+    /*
+     * ARM only. Based on the property clock-frequency in the DT timer node.

What is the behavior then when using ACPI instead of DT?

xen/include/public/sysctl.h struct xen_sysctl_physinfo { · line 133

Quoted 9 lines
xen/include/public/sysctl.h +9 -0
+     * The property may be present when the bootloader/firmware doesn't
+     * correctly set CNTFRQ to hold the timer frequency.
+     *
+     * As it's not possible to trap this register, we have to replicate the
+     * value in the guest DT.
+     *
+     * = 0 => property not present, or non-ARM
+     * > 0 => Value of the property
+     */

All fine, but ...

xen/include/public/sysctl.h struct xen_sysctl_physinfo { · line 134

Quoted 1 line
xen/include/public/sysctl.h +1 -0
+    uint32_t arch_clock_frequency;

... not even the name says what the granularity is. Certainly not Hz, or a 32-bit value could easily be too narrow.

Jan

#11 lore raw

PATCH v2 6/6 xen: make config argument const

In reply to a message not in the archive

arch_sanitise_domain_config() validates the configuration requested by the toolstack, and should not fill anything in. The config struct passed to createdomain is supposed to be pure input. ARM used to abuse this (GIC_NATIVE resolution, now removed) to smuggle output back to the toolstack. Making the parameter const stops that type of abuse from happening on any architecture.

The x86 implementation turned out to have its own instance of the same issue. It set XEN_DOMCTL_CDF_oos_off into config->flags for non-HVM guests. Since The sanitisation runs before the function domain_create() copies config->flags into d->options, this relied on mutating the toolstack's config to take effect. Move the default onto d->options directly in arch_domain_create() (which runs after d->options is populated), where all the remaining domain options are resolved. This has the same effect and no mutation of the input config is required.

ARM, PPC and RISC-V need no equivalent change, Their implementations were already read-only.

---
Changes in v2:
- New patch

---
 xen/arch/arm/domain.c                   |  2 +-
 xen/arch/arm/firmware/sci.c             |  2 +-
 xen/arch/arm/firmware/scmi-smc.c        |  2 +-
 xen/arch/arm/include/asm/firmware/sci.h |  6 +++---
 xen/arch/ppc/stubs.c                    |  2 +-
 xen/arch/riscv/domain.c                 |  2 +-
 xen/arch/x86/domain.c                   | 16 ++++++++--------
 xen/include/xen/sched.h                 |  6 ++++--
 8 files changed, 20 insertions(+), 18 deletions(-)
xen/arch/arm/domain.c +1 -1
index d6d80ac55d..f605446cc5 100644
@@ -557,7 +557,7 @@ static bool v8r_el1_msa_domain_sanitise_config(
     }
 }
 
-int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
+int arch_sanitise_domain_config(const struct xen_domctl_createdomain *config)
 {
     unsigned int max_vcpus;
     unsigned int flags_required = (XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap);
xen/arch/arm/firmware/sci.c +1 -1
index aa93cda7f0..f73ed06092 100644
@@ -45,7 +45,7 @@ int sci_domain_init(struct domain *d, struct xen_domctl_createdomain *config)
     return cur_mediator->domain_init(d, config);
 }
 
-int sci_domain_sanitise_config(struct xen_domctl_createdomain *config)
+int sci_domain_sanitise_config(const struct xen_domctl_createdomain *config)
 {
     if ( !cur_mediator )
         return 0;
xen/arch/arm/firmware/scmi-smc.c +1 -1
index 0835ddeeec..a973679eaf 100644
@@ -82,7 +82,7 @@ static bool scmi_handle_smc(struct cpu_user_regs *regs)
 }
 
 static int
-scmi_smc_domain_sanitise_config(struct xen_domctl_createdomain *config)
+scmi_smc_domain_sanitise_config(const struct xen_domctl_createdomain *config)
 {
     if ( config->arch.arm_sci_type != XEN_DOMCTL_CONFIG_ARM_SCI_NONE &&
          config->arch.arm_sci_type != XEN_DOMCTL_CONFIG_ARM_SCI_SCMI_SMC )
xen/arch/arm/include/asm/firmware/sci.h +3 -3
index 485ce211c9..1d566be8e2 100644
@@ -32,7 +32,7 @@ struct sci_mediator_ops {
      * it to sanitize domain SCI configuration parameters.
      * Optional.
      */
-    int (*domain_sanitise_config)(struct xen_domctl_createdomain *config);
+    int (*domain_sanitise_config)(const struct xen_domctl_createdomain *config);
 
     /*
      * Called during domain destruction, releases all resources, that
@@ -101,7 +101,7 @@ int sci_domain_init(struct domain *d, struct xen_domctl_createdomain *config);
  * Sanitise domain configuration parameters.
  *
  */
-int sci_domain_sanitise_config(struct xen_domctl_createdomain *config);
+int sci_domain_sanitise_config(const struct xen_domctl_createdomain *config);
 
 /*
  * Destroy SCI domain instance.
@@ -162,7 +162,7 @@ static inline int sci_domain_init(struct domain *d,
 }
 
 static inline int
-sci_domain_sanitise_config(struct xen_domctl_createdomain *config)
+sci_domain_sanitise_config(const struct xen_domctl_createdomain *config)
 {
     if ( config->arch.arm_sci_type != XEN_DOMCTL_CONFIG_ARM_SCI_NONE )
         return -EINVAL;
xen/arch/ppc/stubs.c +1 -1
index a333f06119..82a289af85 100644
@@ -162,7 +162,7 @@ void arch_vcpu_destroy(struct vcpu *v)
     BUG_ON("unimplemented");
 }
 
-int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
+int arch_sanitise_domain_config(const struct xen_domctl_createdomain *config)
 {
     BUG_ON("unimplemented");
 }
xen/arch/riscv/domain.c +1 -1
index 2819ff4e7c..e096a53cb5 100644
@@ -289,7 +289,7 @@ void sync_vcpu_execstate(struct vcpu *v)
     /* Nothing to do -- no lazy switching */
 }
 
-int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
+int arch_sanitise_domain_config(const struct xen_domctl_createdomain *config)
 {
     return 0;
 }
xen/arch/x86/domain.c +8 -8
index 4252339978..35f591ab5d 100644
@@ -590,7 +590,7 @@ void arch_vcpu_destroy(struct vcpu *v)
         ASSERT_UNREACHABLE();
 }
 
-int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
+int arch_sanitise_domain_config(const struct xen_domctl_createdomain *config)
 {
     bool hvm = config->flags & XEN_DOMCTL_CDF_hvm;
     bool hap = config->flags & XEN_DOMCTL_CDF_hap;
@@ -633,13 +633,6 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         return -EINVAL;
     }
 
-    if ( !hvm )
-        /*
-         * It is only meaningful for XEN_DOMCTL_CDF_oos_off to be clear
-         * for HVM guests.
-         */
-        config->flags |= XEN_DOMCTL_CDF_oos_off;
-
     if ( nested_virt && !hvm_nested_virt_supported() )
     {
         dprintk(XENLOG_INFO, "Nested virt requested but not available\n");
@@ -833,6 +826,13 @@ int arch_domain_create(struct domain *d,
 
     spin_lock_init(&d->arch.e820_lock);
 
+    /*
+     * It is only meaningful for XEN_DOMCTL_CDF_oos_off to be clear for HVM
+     * guests.
+     */
+    if ( !is_hvm_domain(d) )
+        d->options |= XEN_DOMCTL_CDF_oos_off;
+
     if ( d->domain_id && cpu_has_amd_erratum(&boot_cpu_data, AMD_ERRATUM_121) )
     {
         if ( !opt_allow_unsafe )
xen/include/xen/sched.h +4 -2
index 011292e9f7..66ed7454ba 100644
@@ -756,9 +756,11 @@ static inline void domain_update_node_affinity(struct domain *d)
 
 /*
  * To be implemented by each architecture, sanity checking the configuration
- * and filling in any appropriate defaults.
+ * requested by the toolstack. config is not modified: createdomain is
+ * input-only, and the toolstack is expected to have already resolved any
+ * defaults.
  */
-int arch_sanitise_domain_config(struct xen_domctl_createdomain *config);
+int arch_sanitise_domain_config(const struct xen_domctl_createdomain *config);
 
 /*
  * Create a domain: the configuration is only necessary for real domain
Signature · 10 lines
2.53.0



--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
Reviewed-by on v2 6/6
#12 lore raw

Re: [PATCH v2 6/6] xen: make config argument const

Quoted 16 lines · Julian Vetter

arch_sanitise_domain_config() validates the configuration requested by the toolstack, and should not fill anything in. The config struct passed to createdomain is supposed to be pure input. ARM used to abuse this (GIC_NATIVE resolution, now removed) to smuggle output back to the toolstack. Making the parameter const stops that type of abuse from happening on any architecture.

The x86 implementation turned out to have its own instance of the same issue. It set XEN_DOMCTL_CDF_oos_off into config->flags for non-HVM guests. Since The sanitisation runs before the function domain_create() copies config->flags into d->options, this relied on mutating the toolstack's config to take effect. Move the default onto d->options directly in arch_domain_create() (which runs after d->options is populated), where all the remaining domain options are resolved. This has the same effect and no mutation of the input config is required.

Quoted 4 lines

ARM, PPC and RISC-V need no equivalent change, Their implementations were already read-only.