Expose PMU to the guests
v5 cover Expose PMU to the guests
This patch series is a rework of an already pushed patch exposing PMU to the guests. Since the second version the vpmu parameter is common and prework in the form of reporting availability of vPMU on the hardware is added.
The third version of the patch series removes the redundant check from x86 code and modifies the way to define the flags XEN_DOMCTL_CDF and XEN_SYSCTL_PHYSCAP, meaning not to define bit position and mask separately.
In the fourth version, the additional check is added so that we fail if vpmu is set in the config file but XEN_SYSCTL_PHYSCAP_vpmu is not available.
In the fifth version, SUPPORT.md is updated with the information about vPMU feature and checks for platform PMU support are improved.
The current status is that the PMU registers are not virtualized and the physical registers are directly accessible when "vpmu" parameter is enabled in the guest config file. There is no interrupt support and Xen will not save/restore the register values on context switches. This is to be done in the future.
Michal Orzel (3):
xen+tools: Introduce XEN_SYSCTL_PHYSCAP_vpmu
xen/arm: Check for PMU platform support
xen: Expose the PMU to the guests
SUPPORT.md | 9 +++++ docs/man/xl.cfg.5.pod.in | 17 ++++++++++ tools/golang/xenlight/helpers.gen.go | 8 +++++ tools/golang/xenlight/types.gen.go | 2 ++ tools/include/libxl.h | 12 +++++++ tools/libs/light/libxl.c | 1 + tools/libs/light/libxl_create.c | 10 ++++++ tools/libs/light/libxl_types.idl | 3 ++ tools/ocaml/libs/xc/xenctrl.ml | 2 ++ tools/ocaml/libs/xc/xenctrl.mli | 2 ++ tools/xl/xl_info.c | 5 +-- tools/xl/xl_parse.c | 2 ++ xen/arch/arm/domain.c | 13 +++++-- xen/arch/arm/setup.c | 3 ++ xen/common/domain.c | 12 ++++++- xen/common/sysctl.c | 3 ++ xen/include/asm-arm/cpufeature.h | 51 ++++++++++++++++++++++++++-- xen/include/asm-arm/domain.h | 1 + xen/include/public/domctl.h | 4 ++- xen/include/public/sysctl.h | 6 ++-- xen/include/xen/domain.h | 2 ++ 21 files changed, 157 insertions(+), 11 deletions(-)
Signature · 1 line
2.29.0
PATCH v5 1/3 xen+tools: Introduce XEN_SYSCTL_PHYSCAP_vpmu
Introduce flag XEN_SYSCTL_PHYSCAP_vpmu which indicates whether the platform supports vPMU functionality. Modify Xen and tools accordingly.
Take the opportunity and fix XEN_SYSCTL_PHYSCAP_vmtrace definition in sysctl.h which wrongly use (1 << 6) instead of (1u << 6).
---
Changes since v4:
-none
Changes since v3:
-add spaces between brackets and keyword Changes since v2:
-do not define bit position and mask separately Changes since v1:
-new in v2
--- tools/golang/xenlight/helpers.gen.go | 2 ++ tools/golang/xenlight/types.gen.go | 1 + tools/include/libxl.h | 6 ++++++ tools/libs/light/libxl.c | 1 + tools/libs/light/libxl_types.idl | 1 + tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + tools/xl/xl_info.c | 5 +++-- xen/common/domain.c | 2 ++ xen/common/sysctl.c | 3 +++ xen/include/public/sysctl.h | 6 ++++-- xen/include/xen/domain.h | 2 ++ 12 files changed, 27 insertions(+), 4 deletions(-)
tools/golang/xenlight/helpers.gen.go +2 -0
@@ -3360,6 +3360,7 @@ x.CapHap = bool(xc.cap_hap) x.CapShadow = bool(xc.cap_shadow) x.CapIommuHapPtShare = bool(xc.cap_iommu_hap_pt_share) x.CapVmtrace = bool(xc.cap_vmtrace) +x.CapVpmu = bool(xc.cap_vpmu) return nil}
@@ -3391,6 +3392,7 @@ xc.cap_hap = C.bool(x.CapHap) xc.cap_shadow = C.bool(x.CapShadow) xc.cap_iommu_hap_pt_share = C.bool(x.CapIommuHapPtShare) xc.cap_vmtrace = C.bool(x.CapVmtrace) +xc.cap_vpmu = C.bool(x.CapVpmu) return nil }
tools/golang/xenlight/types.gen.go +1 -0
@@ -1008,6 +1008,7 @@ CapHap bool CapShadow bool CapIommuHapPtShare bool CapVmtrace bool +CapVpmu bool } type Connectorinfo struct {
tools/include/libxl.h +6 -0
@@ -502,6 +502,12 @@*/ #define LIBXL_HAVE_X86_MSR_RELAXED 1 +/* +* LIBXL_HAVE_PHYSINFO_CAP_VPMU indicates that libxl_physinfo has a cap_vpmu +* field, which indicates the availability of vPMU functionality. +*/ +#define LIBXL_HAVE_PHYSINFO_CAP_VPMU 1 +/* * libxl ABI compatibility *
tools/libs/light/libxl.c +1 -0
@@ -404,6 +404,7 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo) !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share); physinfo->cap_vmtrace = !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_vmtrace); + physinfo->cap_vpmu = !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_vpmu);GC_FREE ;return 0 ;
tools/libs/light/libxl_types.idl +1 -0
@@ -1061,6 +1061,7 @@ libxl_physinfo = Struct("physinfo", [ ("cap_shadow", bool), ("cap_iommu_hap_pt_share", bool), ("cap_vmtrace", bool), + ("cap_vpmu", bool), ], dir=DIR_OUT) libxl_connectorinfo = Struct("connectorinfo", [
tools/ocaml/libs/xc/xenctrl.ml +1 -0
@@ -122,6 +122,7 @@ type physinfo_cap_flag = | CAP_Shadow | CAP_IOMMU_HAP_PT_SHARE | CAP_Vmtrace + | CAP_Vpmu type physinfo = {
tools/ocaml/libs/xc/xenctrl.mli +1 -0
@@ -107,6 +107,7 @@ type physinfo_cap_flag = | CAP_Shadow | CAP_IOMMU_HAP_PT_SHARE | CAP_Vmtrace + | CAP_Vpmu type physinfo = { threads_per_core : int;
tools/xl/xl_info.c +3 -2
@@ -210,7 +210,7 @@ static void output_physinfo(void) info.hw_cap[4 ], info.hw_cap[5 ], info.hw_cap[6 ], info.hw_cap[7 ] ); - maybe_printf("virt_caps :%s%s%s%s%s%s%s%s\n", + maybe_printf("virt_caps :%s%s%s%s%s%s%s%s%s\n", info.cap_pv ? " pv" : "", info.cap_hvm ? " hvm" : "", info.cap_hvm && info.cap_hvm_directio ? " hvm_directio" : "",
@@ -218,7 +218,8 @@ static void output_physinfo(void) info.cap_hap ?" hap" :"" , info.cap_shadow ?" shadow" :"" , info.cap_iommu_hap_pt_share ?" iommu_hap_pt_share" :"" , - info.cap_vmtrace ?" vmtrace" :"" + info.cap_vmtrace ?" vmtrace" :"" , + info.cap_vpmu ?" vpmu" :"" ); vinfo =libxl_get_version_info (ctx);
xen/common/domain.c +2 -0
@@ -84,6 +84,8 @@ vcpu_info_t dummy_vcpu_info;bool __read_mostly vmtrace_available; +bool __read_mostly vpmu_is_available; +static void __domain_finalise_shutdown (struct domain *d) {struct vcpu *v;
xen/common/sysctl.c +3 -0
@@ -280,6 +280,9 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)if ( vmtrace_available ) pi->capabilities |= XEN_SYSCTL_PHYSCAP_vmtrace; +if ( vpmu_is_available ) + pi->capabilities |= XEN_SYSCTL_PHYSCAP_vpmu; +if (copy_to_guest (u_sysctl, op,1 ) ) ret = -EFAULT ; }
xen/include/public/sysctl.h +4 -2
@@ -100,10 +100,12 @@ struct xen_sysctl_tbuf_op {#define _XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share 5#define XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share \ (1u << _XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share) -#define XEN_SYSCTL_PHYSCAP_vmtrace (1 << 6) +#define XEN_SYSCTL_PHYSCAP_vmtrace (1u << 6) +/* The platform supports vPMU. */ +#define XEN_SYSCTL_PHYSCAP_vpmu (1u << 7)/* Max XEN_SYSCTL_PHYSCAP_* constant. Used for ABI checking. */ -#define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_vmtrace +#define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_vpmustruct xen_sysctl_physinfo {uint32_t threads_per_core;
xen/include/xen/domain.h +2 -0
@@ -133,4 +133,6 @@ static inline void vnuma_destroy(struct vnuma_info *vnuma) { ASSERT(!vnuma); }extern bool vmtrace_available; +extern bool vpmu_is_available; +#endif /* __XEN_DOMAIN_H__ */
Signature · 1 line
2.29.0
PATCH v5 2/3 xen/arm: Check for PMU platform support
In reply to Michal OrzelID_AA64DFR0_EL1/ID_DFR0_EL1 registers provide information about PMU support. Replace structure dbg64/dbg32 with a union and fill in all the register fields according to document:
ARM Architecture Registers(DDI 0595, 2021-06).
Add macros boot_dbg_feature64/boot_dbg_feature32 to check for a debug feature. Add macro cpu_has_pmu to check for PMU support.
Any value higher than 0 and less than 15 means that PMU is supported (we do not care about its version for now).
---
Changes since v4:
-improve checks for PMU
Changes since v3:
-none
Changes since v2:
-none
Changes since v1:
-new in v2
--- xen/include/asm-arm/cpufeature.h | 51 ++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-)
xen/include/asm-arm/cpufeature.h +49 -2
@@ -4,6 +4,7 @@#ifdef CONFIG_ARM_64 #define cpu_feature64 (c, feat) ((c)->pfr64.feat)#define boot_cpu_feature64 (feat) (system_cpuinfo.pfr64.feat) +#define boot_dbg_feature64 (feat) (system_cpuinfo.dbg64.feat)#define cpu_feature64_has_el0_32 (c) (cpu_feature64(c, el0) == 2)
@@ -22,6 +23,7 @@#define cpu_feature32 (c, feat) ((c)->pfr32.feat)#define boot_cpu_feature32 (feat) (system_cpuinfo.pfr32.feat) +#define boot_dbg_feature32 (feat) (system_cpuinfo.dbg32.feat)#define cpu_has_arm (boot_cpu_feature32(arm) == 1)#define cpu_has_thumb (boot_cpu_feature32(thumb) >= 1)
@@ -32,8 +34,12 @@#ifdef CONFIG_ARM_32 #define cpu_has_gentimer (boot_cpu_feature32(gentimer) == 1) +#define cpu_has_pmu ((boot_dbg_feature32(perfmon) >= 1) && \ + (boot_dbg_feature32(perfmon) < 15))#else #define cpu_has_gentimer (1) +#define cpu_has_pmu ((boot_dbg_feature64(pmu_ver) >= 1) && \ + (boot_dbg_feature64(pmu_ver) < 15))#endif #define cpu_has_security (boot_cpu_feature32(security) > 0)
@@ -181,8 +187,28 @@ struct cpuinfo_arm { }; } pfr64; -struct { +union {register_t bits[2 ]; +struct { +/* DFR0 */ +unsigned long debug_ver:4 ; +unsigned long trace_ver:4 ; +unsigned long pmu_ver:4 ; +unsigned long brps:4 ; +unsigned long __res0:4 ; +unsigned long wrps:4 ; +unsigned long __res1:4 ; +unsigned long ctx_cmps:4 ; +unsigned long pms_ver:4 ; +unsigned long double_lock:4 ; +unsigned long trace_filt:4 ; +unsigned long __res2:4 ; +unsigned long mtpmu:4 ; +unsigned long __res3:12 ; + +/* DFR1 */ +unsigned long __res4:64 ; + }; } dbg64;struct {
@@ -321,8 +347,29 @@ struct cpuinfo_arm { }; } pfr32; -struct { +union {register_t bits[2 ]; +struct { +/* DFR0 */ +unsigned long copdbg:4 ; +unsigned long copsdbg:4 ; +unsigned long mmapdbg:4 ; +unsigned long coptrc:4 ; +unsigned long mmaptrc:4 ; +unsigned long mprofdbg:4 ; +unsigned long perfmon:4 ; +unsigned long tracefilt:4 ; +#ifdef CONFIG_ARM_64 +unsigned long __res0:32 ; +#endif + +/* DFR1 */ +unsigned long mtpmu:4 ; +unsigned long __res1:28 ; +#ifdef CONFIG_ARM_64 +unsigned long __res2:32 ; +#endif + }; } dbg32;struct {
Signature · 1 line
2.29.0
Re: [PATCH v5 2/3] xen/arm: Check for PMU platform support
Hi Michal,
Quoted 50 lines · Michal Orzel
ID_AA64DFR0_EL1/ID_DFR0_EL1 registers provide information about PMU support. Replace structure dbg64/dbg32 with a union and fill in all the register fields according to document:
ARM ArchitectureRegisters(DDI 0595, 2021-06).Add macros boot_dbg_feature64/boot_dbg_feature32 to check for a debug feature. Add macro
cpu_has_pmuto check for PMU support.
Any value higher than 0 and less than 15 means that PMU is supported (we do not care about its version for now).Signed-off-by Michal Orzel <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>---
Changes since v4:
-improve checks for PMU
Changes since v3:
-none
Changes since v2:
-none
Changes since v1:(quoted diff) +0
-2-new in v2 --- xen/include/asm-arm/cpufeature.h | 51 ++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-)xen/include/asm-arm/cpufeature.h +2
-0@@ -4,6 +4,7 @@#ifdef CONFIG_ARM_64 #define cpu_feature64 (c, feat) ((c)->pfr64.feat)#define boot_cpu_feature64 (feat) (system_cpuinfo.pfr64.feat) +#define boot_dbg_feature64 (feat) (system_cpuinfo.dbg64.feat)#define cpu_feature64_has_el0_32 (c) (cpu_feature64(c, el0) == 2)@@ -22,6 +23,7 @@#define cpu_feature32 (c, feat) ((c)->pfr32.feat)#define boot_cpu_feature32 (feat) (system_cpuinfo.pfr32.feat) +#define boot_dbg_feature32 (feat) (system_cpuinfo.dbg32.feat)#define cpu_has_arm (boot_cpu_feature32(arm) == 1)#define cpu_has_thumb (boot_cpu_feature32(thumb) >= 1)
xen/include/asm-arm/cpufeature.h line 38
Quoted 5 lines
xen/include/asm-arm/cpufeature.h +2
-0@@ -32,8 +34,12 @@#ifdef CONFIG_ARM_32 #define cpu_has_gentimer (boot_cpu_feature32(gentimer) == 1) +#define cpu_has_pmu ((boot_dbg_feature32(perfmon) >= 1) && \ + (boot_dbg_feature32(perfmon) < 15))
So I am happy with this check for arm32. But I would still like to have a comment explaining the fact that on Armv7 perfmon == 0 may mean PMUv1 is may be used. Something like:
"On Armv7, the value 0 is used to indicate that PMUv2 is not supported. IOW this doesn't tell us whether the PMU is not supported (a processor may implement PMUv1).
For convenience, we treat 0 as not supported which this match the meaning on Armv8".
The rest of the code looks fine to me.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v5 2/3] xen/arm: Check for PMU platform support
Quoted 59 lines · Julien Grall
Hi Michal,
Quoted 47 lines · Michal Orzel
ID_AA64DFR0_EL1/ID_DFR0_EL1 registers provide information about PMU support. Replace structure dbg64/dbg32 with a union and fill in all the register fields according to document:
ARM ArchitectureRegisters(DDI 0595, 2021-06).Add macros boot_dbg_feature64/boot_dbg_feature32 to check for a debug feature. Add macro
cpu_has_pmuto check for PMU support.
Any value higher than 0 and less than 15 means that PMU is supported (we do not care about its version for now).Signed-off-by Michal Orzel <[email protected]>Reviewed-by Stefano Stabellini <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>---
Changes since v4:
-improve checks for PMU
Changes since v3:
-none
Changes since v2:
-none
Changes since v1:(quoted diff) +0
-2-new in v2 --- xen/include/asm-arm/cpufeature.h | 51 ++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-)xen/include/asm-arm/cpufeature.h +1
-0@@ -4,6 +4,7 @@#ifdef CONFIG_ARM_64 #define cpu_feature64 (c, feat) ((c)->pfr64.feat)#define boot_cpu_feature64 (feat) (system_cpuinfo.pfr64.feat) +#define boot_dbg_feature64 (feat) (system_cpuinfo.dbg64.feat)#define cpu_feature64_has_el0_32 (c) (cpu_feature64(c, el0) == 2) @@ -22,6 +23,7 @@#define cpu_feature32 (c, feat) ((c)->pfr32.feat)#define boot_cpu_feature32(feat) (system_cpuinfo.pfr32.feat)xen/include/asm-arm/cpufeature.h +1
-0+#define boot_dbg_feature32 (feat) (system_cpuinfo.dbg32.feat)#define cpu_has_arm (boot_cpu_feature32(arm) == 1)#define cpu_has_thumb (boot_cpu_feature32(thumb) >= 1)xen/include/asm-arm/cpufeature.h line 37
Quoted 4 lines
xen/include/asm-arm/cpufeature.h +2
-0@@ -32,8 +34,12 @@#ifdef CONFIG_ARM_32 #define cpu_has_gentimer (boot_cpu_feature32(gentimer) == 1) +#define cpu_has_pmu ((boot_dbg_feature32(perfmon) >= 1) && \ + (boot_dbg_feature32(perfmon) < 15))So I am happy with this check for arm32. But I would still like to have a comment explaining the fact that on Armv7 perfmon == 0 may mean PMUv1 is may be used. Something like:
Quoted 8 lines
"On Armv7, the value 0 is used to indicate that PMUv2 is not supported. IOW this doesn't tell us whether the PMU is not supported (a processor may implement PMUv1).
For convenience, we treat 0 as not supported which this match the meaning on Armv8".
The rest of the code looks fine to me.
I made the change on commit
PATCH v5 3/3 xen: Expose the PMU to the guests
In reply to Michal OrzelAdd parameter vpmu to xl domain configuration syntax to enable the access to PMU registers by disabling the PMU traps(currently only for ARM).
The current status is that the PMU registers are not virtualized and the physical registers are directly accessible when this parameter is enabled. There is no interrupt support and Xen will not save/restore the register values on context switches.
According to Arm Arm, section D7.1:
"The Performance Monitors Extension is common to AArch64 operation and AArch32 operation." That means we have an ensurance that if PMU is present in one exception state, it must also be present in the other.
Please note that this feature is experimental.
---
Changes since v4:
-update SUPPORT.md
-move vpmu_is_available assignment after the secondary CPUs have been brought up
-introduce masks for flags that need to be set and for flags that are optional
Changes since v3:
-fail if vpmu is set but not supported
Changes since v2:
-remove redundant check from x86 code
-do not define bit position and mask separately Changes since v1:
-modify vpmu parameter to be common rather than arch specific
--- SUPPORT.md | 9 +++++++++ docs/man/xl.cfg.5.pod.in | 17 +++++++++++++++++ tools/golang/xenlight/helpers.gen.go | 6 ++++++ tools/golang/xenlight/types.gen.go | 1 + tools/include/libxl.h | 6 ++++++ tools/libs/light/libxl_create.c | 10 ++++++++++ tools/libs/light/libxl_types.idl | 2 ++ tools/ocaml/libs/xc/xenctrl.ml | 1 + tools/ocaml/libs/xc/xenctrl.mli | 1 + tools/xl/xl_parse.c | 2 ++ xen/arch/arm/domain.c | 13 ++++++++++--- xen/arch/arm/setup.c | 3 +++ xen/common/domain.c | 10 +++++++++- xen/include/asm-arm/domain.h | 1 + xen/include/public/domctl.h | 4 +++- 15 files changed, 81 insertions(+), 5 deletions(-)
SUPPORT.md +9 -0
@@ -256,6 +256,15 @@ from dom0. Status, x86: Tech Preview +### vPMU support + +Support for accessing PMU registers from the guests. +There is no interrupt support and Xen will not save/restore +the register values on context switches. +Disabled by default (enable with guest parameter). + + Status, ARM: Experimental + ## Memory Management ### Dynamic memory control
docs/man/xl.cfg.5.pod.in +17 -0
@@ -690,6 +690,23 @@ default. B<NOTE>: Acceptable values are platform specific. For Intel Processor Trace, this value must be a power of 2 between 4k and 16M. +=item B<vpmu=BOOLEAN> + +Currently ARM only. + +Specifies whether to enable the access to PMU registers by disabling +the PMU traps. + +The PMU registers are not virtualized and the physical registers are directly +accessible when this parameter is enabled. There is no interrupt support and +Xen will not save/restore the register values on context switches. + +vPMU, by design and purpose, exposes system level performance +information to the guest. Only to be used by sufficiently privileged +domains. This feature is currently in experimental state. + +If this option is not specified then it will default to B<false>. + =back =head2 Devices
tools/golang/xenlight/helpers.gen.go +6 -0
@@ -1119,6 +1119,9 @@ return fmt.Errorf("converting field ArchX86.MsrRelaxed: %v", err) } x.Altp2M = Altp2MMode(xc.altp2m) x.VmtraceBufKb = int(xc.vmtrace_buf_kb) +if err := x.Vpmu.fromC(&xc.vpmu);err != nil { +return fmt.Errorf("converting field Vpmu: %v", err) +} return nil}
@@ -1600,6 +1603,9 @@ return fmt.Errorf("converting field ArchX86.MsrRelaxed: %v", err) } xc.altp2m = C.libxl_altp2m_mode(x.Altp2M) xc.vmtrace_buf_kb = C.int(x.VmtraceBufKb) +if err := x.Vpmu.toC(&xc.vpmu); err != nil { +return fmt.Errorf("converting field Vpmu: %v", err) +} return nil }
tools/golang/xenlight/types.gen.go +1 -0
@@ -521,6 +521,7 @@ MsrRelaxed Defbool } Altp2M Altp2MMode VmtraceBufKb int +Vpmu Defbool } type DomainBuildInfoTypeUnion interface {
tools/include/libxl.h +6 -0
@@ -508,6 +508,12 @@*/ #define LIBXL_HAVE_PHYSINFO_CAP_VPMU 1 +/* +* LIBXL_HAVE_VPMU indicates that libxl_domain_build_info has a vpmu parameter, +* which allows to enable the access to PMU registers. +*/ +#define LIBXL_HAVE_VPMU 1 +/* * libxl ABI compatibility *
tools/libs/light/libxl_create.c +10 -0
@@ -91,6 +91,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, }libxl_defbool_setdefault (&b_info->device_model_stubdomain, false); +libxl_defbool_setdefault (&b_info->vpmu, false);if (libxl_defbool_val (b_info->device_model_stubdomain) && !b_info->device_model_ssidref)
@@ -622,6 +623,9 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, create.flags |= XEN_DOMCTL_CDF_nested_virt; } +if (libxl_defbool_val (b_info->vpmu) ) + create.flags |= XEN_DOMCTL_CDF_vpmu; +assert (info->passthrough !=LIBXL_PASSTHROUGH_DEFAULT );LOG (DETAIL ,"passthrough: %s" ,libxl_passthrough_to_string (info->passthrough));
@@ -1199,6 +1203,12 @@ int libxl__domain_config_setdefault(libxl__gc *gc, goto error_out; } +if (libxl_defbool_val (d_config->b_info.vpmu) && !physinfo.cap_vpmu) { + ret =ERROR_INVAL ; +LOGD (ERROR , domid,"vpmu not supported on this platform\n" ); + goto error_out; + } + ret =0 ; error_out:return ret;
tools/libs/light/libxl_types.idl +2 -0
@@ -655,6 +655,8 @@ libxl_domain_build_info = Struct("domain_build_info",[ # Use zero value to disable this feature. ("vmtrace_buf_kb", integer), + ("vpmu", libxl_defbool), + ], dir=DIR_IN, copy_deprecated_fn="libxl__domain_build_info_copy_deprecated", )
tools/ocaml/libs/xc/xenctrl.ml +1 -0
@@ -70,6 +70,7 @@ type domain_create_flag = | CDF_IOMMU | CDF_NESTED_VIRT | CDF_VPCI + | CDF_VPMU type domain_create_iommu_opts = | IOMMU_NO_SHAREPT
tools/ocaml/libs/xc/xenctrl.mli +1 -0
@@ -63,6 +63,7 @@ type domain_create_flag = | CDF_IOMMU | CDF_NESTED_VIRT | CDF_VPCI + | CDF_VPMU type domain_create_iommu_opts = | IOMMU_NO_SHAREPT
tools/xl/xl_parse.c +2 -0
@@ -2750,6 +2750,8 @@ skip_usbdev:"If it fixes an issue you are having please report to " "[email protected].\n"); +xlu_cfg_get_defbool (config,"vpmu" , &b_info->vpmu,0 ); +xlu_cfg_destroy (config); }
xen/arch/arm/domain.c +10 -3
@@ -276,6 +276,8 @@ static void ctxt_switch_to(struct vcpu *n)* timer. The interrupt needs to be injected into the guest. */ WRITE_SYSREG (n->arch.cntkctl,CNTKCTL_EL1 );virt_timer_restore (n); + +WRITE_SYSREG (n->arch.mdcr_el2,MDCR_EL2 ); }/* Update per-VCPU guest runstate shared memory area (if registered). */
@@ -586,6 +588,10 @@ int arch_vcpu_create(struct vcpu *v) v->arch.hcr_el2 =get_default_hcr_flags (); + v->arch.mdcr_el2 =HDCR_TDRA |HDCR_TDOSA |HDCR_TDA ; +if ( !(v->domain->options & XEN_DOMCTL_CDF_vpmu) ) + v->arch.mdcr_el2 |=HDCR_TPM |HDCR_TPMCR ; +if ( (rc =vcpu_vgic_init (v)) !=0 ) goto fail;
@@ -621,10 +627,11 @@ void vcpu_switch_to_aarch64_mode(struct vcpu *v)int arch_sanitise_domain_config (struct xen_domctl_createdomain *config) {unsigned int max_vcpus; +unsigned int flags_required = (XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap); +unsigned int flags_optional = (XEN_DOMCTL_CDF_iommu | XEN_DOMCTL_CDF_vpci | + XEN_DOMCTL_CDF_vpmu); -/* HVM and HAP must be set. IOMMU and VPCI may or may not be */ -if ( (config->flags & ~XEN_DOMCTL_CDF_iommu & ~XEN_DOMCTL_CDF_vpci) != - (XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap) ) +if ( (config->flags & ~flags_optional) != flags_required ) {dprintk (XENLOG_INFO ,"Unsupported configuration %#x\n" , config->flags);
xen/arch/arm/setup.c +3 -0
@@ -999,6 +999,9 @@ void __init start_xen(unsigned long boot_phys_offset,printk ("Brought up %ld CPUs\n" , (long )num_online_cpus ());/* TODO: smp_cpus_done(); */ +/* This should be done in a vpmu driver but we do not have one yet. */ + vpmu_is_available = cpu_has_pmu; +/* * The IOMMU subsystem must be initialized before P2M as we need * to gather requirements regarding the maximum IPA bits supported by
xen/common/domain.c +9 -1
@@ -480,12 +480,14 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config)bool hvm = config->flags & XEN_DOMCTL_CDF_hvm;bool hap = config->flags & XEN_DOMCTL_CDF_hap;bool iommu = config->flags & XEN_DOMCTL_CDF_iommu; +bool vpmu = config->flags & XEN_DOMCTL_CDF_vpmu;if ( config->flags & ~(XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap | XEN_DOMCTL_CDF_s3_integrity | XEN_DOMCTL_CDF_oos_off | XEN_DOMCTL_CDF_xs_domain | XEN_DOMCTL_CDF_iommu | - XEN_DOMCTL_CDF_nested_virt | XEN_DOMCTL_CDF_vpci) ) + XEN_DOMCTL_CDF_nested_virt | XEN_DOMCTL_CDF_vpci | + XEN_DOMCTL_CDF_vpmu) ) {dprintk (XENLOG_INFO ,"Unknown CDF flags %#x\n" , config->flags);return -EINVAL ;
@@ -534,6 +536,12 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config)return -EINVAL ; } +if ( vpmu && !vpmu_is_available ) + { +dprintk (XENLOG_INFO ,"vpmu requested but cannot be enabled this way\n" ); +return -EINVAL ; + } +return arch_sanitise_domain_config (config); }
xen/include/asm-arm/domain.h +1 -0
@@ -166,6 +166,7 @@ struct arch_vcpu/* HYP configuration */ register_t hcr_el2; +register_t mdcr_el2;uint32_t teecr, teehbr;/* ThumbEE, 32-bit guests only */ #ifdef CONFIG_ARM_32
xen/include/public/domctl.h +3 -1
@@ -71,9 +71,11 @@ struct xen_domctl_createdomain {#define _XEN_DOMCTL_CDF_nested_virt 6#define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt)#define XEN_DOMCTL_CDF_vpci (1U << 7) +/* Should we expose the vPMU to the guest? */ +#define XEN_DOMCTL_CDF_vpmu (1U << 8)/* Max XEN_DOMCTL_CDF_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_vpci +#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_vpmuuint32_t flags;
Signature · 1 line
2.29.0
Re: [PATCH v5 3/3] xen: Expose the PMU to the guests
tools/libs/light/libxl_create.c int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, · line 626
Quoted 9 lines · Michal Orzel
tools/libs/light/libxl_create.c +1
-0@@ -622,6 +623,9 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, create.flags |= XEN_DOMCTL_CDF_nested_virt; } +if (libxl_defbool_val (b_info->vpmu) )
We don't usually have space between the parentheses and the condition in libxl.
tools/libs/light/libxl_create.c int libxl__domain_config_setdefault(libxl__gc *gc, · line 1208
Quoted 12 lines
tools/libs/light/libxl_create.c +5
-0+ create.flags |= XEN_DOMCTL_CDF_vpmu; +assert (info->passthrough !=LIBXL_PASSTHROUGH_DEFAULT );LOG (DETAIL ,"passthrough: %s" ,libxl_passthrough_to_string (info->passthrough));@@ -1199,6 +1203,12 @@ int libxl__domain_config_setdefault(libxl__gc *gc, goto error_out; } +if (libxl_defbool_val (d_config->b_info.vpmu) && !physinfo.cap_vpmu) { + ret =ERROR_INVAL ; +LOGD (ERROR , domid,"vpmu not supported on this platform\n" );
You don't need a '\n' here. Also, you could write "vPMU" instead of "vpmu" in the error message.
Otherwise, changes for libxl and xl looks good:
Thanks,
Signature · 1 line
Anthony PERARD
Re: [PATCH v5 3/3] xen: Expose the PMU to the guests
In reply to Michal OrzelHi Michal,
SUPPORT.md from dom0. · line 259
Quoted 9 lines · Michal Orzel
SUPPORT.md +1
-0@@ -256,6 +256,15 @@ from dom0. Status, x86: Tech Preview +### vPMU support
There is already a section vPMU that is meant to be generic. At the moment it mentions the status support for x86 but not Arm. So can you fold the status for Arm there?
SUPPORT.md from dom0. · line 267
Quoted 8 lines
SUPPORT.md +8
-0+ +Support for accessing PMU registers from the guests. +There is no interrupt support and Xen will not save/restore +the register values on context switches. +Disabled by default (enable with guest parameter). + + Status, ARM: Experimental +
The rest of the patch looks good to me.
Cheers,
Signature · 1 line
Julien Grall
On 12 Oct 2021, at 09:13, Michal Orzel <[email protected]<mailto:[email protected]>> wrote:
This patch series is a rework of an already pushed patch exposing PMU to the guests. Since the second version the vpmu parameter is common and prework in the form of reporting availability of vPMU on the hardware is added.
The third version of the patch series removes the redundant check from x86 code and modifies the way to define the flags XEN_DOMCTL_CDF and XEN_SYSCTL_PHYSCAP, meaning not to define bit position and mask separately.
In the fourth version, the additional check is added so that we fail if vpmu is set in the config file but XEN_SYSCTL_PHYSCAP_vpmu is not available.
In the fifth version, SUPPORT.md is updated with the information about vPMU feature and checks for platform PMU support are improved.
The current status is that the PMU registers are not virtualized and the physical registers are directly accessible when "vpmu" parameter is enabled in the guest config file. There is no interrupt support and Xen will not save/restore the register values on context switches. This is to be done in the future.
Michal Orzel (3):
xen+tools: Introduce XEN_SYSCTL_PHYSCAP_vpmu
xen/arm: Check for PMU platform support
xen: Expose the PMU to the guests
SUPPORT.md | 9 +++++ docs/man/xl.cfg.5.pod.in | 17 ++++++++++ tools/golang/xenlight/helpers.gen.go | 8 +++++ tools/golang/xenlight/types.gen.go | 2 ++ tools/include/libxl.h | 12 +++++++ tools/libs/light/libxl.c | 1 + tools/libs/light/libxl_create.c | 10 ++++++ tools/libs/light/libxl_types.idl | 3 ++ tools/ocaml/libs/xc/xenctrl.ml | 2 ++ tools/ocaml/libs/xc/xenctrl.mli | 2 ++ tools/xl/xl_info.c | 5 +-- tools/xl/xl_parse.c | 2 ++ xen/arch/arm/domain.c | 13 +++++-- xen/arch/arm/setup.c | 3 ++ xen/common/domain.c | 12 ++++++- xen/common/sysctl.c | 3 ++ xen/include/asm-arm/cpufeature.h | 51 ++++++++++++++++++++++++++-- xen/include/asm-arm/domain.h | 1 + xen/include/public/domctl.h | 4 ++- xen/include/public/sysctl.h | 6 ++-- xen/include/xen/domain.h | 2 ++ 21 files changed, 157 insertions(+), 11 deletions(-)
—
2.29.0