From nobody Thu Apr 25 04:51:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 163394288195010.612435316892288; Mon, 11 Oct 2021 02:01:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.205525.360853 (Exim 4.92) (envelope-from ) id 1mZrBD-0002uw-P1; Mon, 11 Oct 2021 09:01:07 +0000 Received: by outflank-mailman (output) from mailman id 205525.360853; Mon, 11 Oct 2021 09:01:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZrBD-0002un-LY; Mon, 11 Oct 2021 09:01:07 +0000 Received: by outflank-mailman (input) for mailman id 205525; Mon, 11 Oct 2021 09:01:06 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZrBC-0002uG-Kk for xen-devel@lists.xenproject.org; Mon, 11 Oct 2021 09:01:06 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id c3e86d3e-2a71-11ec-80d2-12813bfff9fa; Mon, 11 Oct 2021 09:01:04 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 801CE1FB; Mon, 11 Oct 2021 02:01:04 -0700 (PDT) Received: from e123311-lin.arm.com (unknown [10.57.19.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E4D293F66F; Mon, 11 Oct 2021 02:01:01 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c3e86d3e-2a71-11ec-80d2-12813bfff9fa From: Michal Orzel To: xen-devel@lists.xenproject.org Cc: George Dunlap , Nick Rosbrook , Ian Jackson , Wei Liu , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Anthony PERARD , Juergen Gross , Christian Lindig , David Scott , bertrand.marquis@arm.com Subject: [PATCH v4 1/3] xen+tools: Introduce XEN_SYSCTL_PHYSCAP_vpmu Date: Mon, 11 Oct 2021 11:00:45 +0200 Message-Id: <20211011090047.8878-2-michal.orzel@arm.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20211011090047.8878-1-michal.orzel@arm.com> References: <20211011090047.8878-1-michal.orzel@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1633942883154100002 Content-Type: text/plain; charset="utf-8" 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). Signed-off-by: Michal Orzel Reviewed-by: Bertrand Marquis Acked-by: Nick Rosbrook Reviewed-by: Stefano Stabellini Acked-by: Ian Jackson --- 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(-) diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index bfc1e7f312..c8669837d8 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -3360,6 +3360,7 @@ x.CapHap =3D bool(xc.cap_hap) x.CapShadow =3D bool(xc.cap_shadow) x.CapIommuHapPtShare =3D bool(xc.cap_iommu_hap_pt_share) x.CapVmtrace =3D bool(xc.cap_vmtrace) +x.CapVpmu =3D bool(xc.cap_vpmu) =20 return nil} =20 @@ -3391,6 +3392,7 @@ xc.cap_hap =3D C.bool(x.CapHap) xc.cap_shadow =3D C.bool(x.CapShadow) xc.cap_iommu_hap_pt_share =3D C.bool(x.CapIommuHapPtShare) xc.cap_vmtrace =3D C.bool(x.CapVmtrace) +xc.cap_vpmu =3D C.bool(x.CapVpmu) =20 return nil } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index 09a3bb67e2..45f2cba3d2 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -1008,6 +1008,7 @@ CapHap bool CapShadow bool CapIommuHapPtShare bool CapVmtrace bool +CapVpmu bool } =20 type Connectorinfo struct { diff --git a/tools/include/libxl.h b/tools/include/libxl.h index b9ba16d698..ec5e3badae 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -502,6 +502,12 @@ */ #define LIBXL_HAVE_X86_MSR_RELAXED 1 =20 +/* + * LIBXL_HAVE_PHYSINFO_CAP_VPMU indicates that libxl_physinfo has a cap_vp= mu + * field, which indicates the availability of vPMU functionality. + */ +#define LIBXL_HAVE_PHYSINFO_CAP_VPMU 1 + /* * libxl ABI compatibility * diff --git a/tools/libs/light/libxl.c b/tools/libs/light/libxl.c index 204eb0be2d..a032723fde 100644 --- a/tools/libs/light/libxl.c +++ b/tools/libs/light/libxl.c @@ -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 =3D !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_vmtrace); + physinfo->cap_vpmu =3D !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP= _vpmu); =20 GC_FREE; return 0; diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 3f9fff653a..993e83acca 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -1061,6 +1061,7 @@ libxl_physinfo =3D Struct("physinfo", [ ("cap_shadow", bool), ("cap_iommu_hap_pt_share", bool), ("cap_vmtrace", bool), + ("cap_vpmu", bool), ], dir=3DDIR_OUT) =20 libxl_connectorinfo =3D Struct("connectorinfo", [ diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml index 7ed1c00e47..7a4030a192 100644 --- a/tools/ocaml/libs/xc/xenctrl.ml +++ b/tools/ocaml/libs/xc/xenctrl.ml @@ -122,6 +122,7 @@ type physinfo_cap_flag =3D | CAP_Shadow | CAP_IOMMU_HAP_PT_SHARE | CAP_Vmtrace + | CAP_Vpmu =20 type physinfo =3D { diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.= mli index 391d4abdf8..6900513e7f 100644 --- a/tools/ocaml/libs/xc/xenctrl.mli +++ b/tools/ocaml/libs/xc/xenctrl.mli @@ -107,6 +107,7 @@ type physinfo_cap_flag =3D | CAP_Shadow | CAP_IOMMU_HAP_PT_SHARE | CAP_Vmtrace + | CAP_Vpmu =20 type physinfo =3D { threads_per_core : int; diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c index 8383e4a6df..2c86b317b7 100644 --- a/tools/xl/xl_info.c +++ b/tools/xl/xl_info.c @@ -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] ); =20 - 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" : "" ); =20 vinfo =3D libxl_get_version_info(ctx); diff --git a/xen/common/domain.c b/xen/common/domain.c index 40d67ec342..262b6c0c3c 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -84,6 +84,8 @@ vcpu_info_t dummy_vcpu_info; =20 bool __read_mostly vmtrace_available; =20 +bool __read_mostly vpmu_is_available; + static void __domain_finalise_shutdown(struct domain *d) { struct vcpu *v; diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c index 3558641cd9..6e7189bb3c 100644 --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -280,6 +280,9 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_s= ysctl) if ( vmtrace_available ) pi->capabilities |=3D XEN_SYSCTL_PHYSCAP_vmtrace; =20 + if ( vpmu_is_available ) + pi->capabilities |=3D XEN_SYSCTL_PHYSCAP_vpmu; + if ( copy_to_guest(u_sysctl, op, 1) ) ret =3D -EFAULT; } diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 039ccf885c..fead0e5b53 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -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) =20 /* 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_vpmu =20 struct xen_sysctl_physinfo { uint32_t threads_per_core; diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 1708c36964..160c8dbdab 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -133,4 +133,6 @@ static inline void vnuma_destroy(struct vnuma_info *vnu= ma) { ASSERT(!vnuma); } =20 extern bool vmtrace_available; =20 +extern bool vpmu_is_available; + #endif /* __XEN_DOMAIN_H__ */ --=20 2.29.0 From nobody Thu Apr 25 04:51:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 163394288310113.078406130614553; Mon, 11 Oct 2021 02:01:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.205526.360863 (Exim 4.92) (envelope-from ) id 1mZrBG-0003D4-0k; Mon, 11 Oct 2021 09:01:10 +0000 Received: by outflank-mailman (output) from mailman id 205526.360863; Mon, 11 Oct 2021 09:01:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZrBF-0003Ct-Tu; Mon, 11 Oct 2021 09:01:09 +0000 Received: by outflank-mailman (input) for mailman id 205526; Mon, 11 Oct 2021 09:01:08 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZrBE-0002dD-CB for xen-devel@lists.xenproject.org; Mon, 11 Oct 2021 09:01:08 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 673ef07a-bd79-459f-a938-92a355f24d98; Mon, 11 Oct 2021 09:01:06 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DAEBB11FB; Mon, 11 Oct 2021 02:01:05 -0700 (PDT) Received: from e123311-lin.arm.com (unknown [10.57.19.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C94203F66F; Mon, 11 Oct 2021 02:01:04 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 673ef07a-bd79-459f-a938-92a355f24d98 From: Michal Orzel To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Volodymyr Babchuk , bertrand.marquis@arm.com Subject: [PATCH v4 2/3] xen/arm: Check for PMU platform support Date: Mon, 11 Oct 2021 11:00:46 +0200 Message-Id: <20211011090047.8878-3-michal.orzel@arm.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20211011090047.8878-1-michal.orzel@arm.com> References: <20211011090047.8878-1-michal.orzel@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1633942884809100005 Content-Type: text/plain; charset="utf-8" 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 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. Signed-off-by: Michal Orzel Reviewed-by: Stefano Stabellini Reviewed-by: Bertrand Marquis --- Changes since v3: -none Changes since v2: -none Changes since v1: -new in v2 --- xen/include/asm-arm/cpufeature.h | 49 ++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeat= ure.h index 5ca09b0bff..4fce23844d 100644 --- a/xen/include/asm-arm/cpufeature.h +++ b/xen/include/asm-arm/cpufeature.h @@ -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) =20 #define cpu_feature64_has_el0_32(c) (cpu_feature64(c, el0) =3D=3D 2) =20 @@ -22,6 +23,7 @@ =20 #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) =20 #define cpu_has_arm (boot_cpu_feature32(arm) =3D=3D 1) #define cpu_has_thumb (boot_cpu_feature32(thumb) >=3D 1) @@ -32,8 +34,10 @@ =20 #ifdef CONFIG_ARM_32 #define cpu_has_gentimer (boot_cpu_feature32(gentimer) =3D=3D 1) +#define cpu_has_pmu (boot_dbg_feature32(perfmon) >=3D 1) #else #define cpu_has_gentimer (1) +#define cpu_has_pmu (boot_dbg_feature64(pmu_ver) >=3D 1) #endif #define cpu_has_security (boot_cpu_feature32(security) > 0) =20 @@ -181,8 +185,28 @@ struct cpuinfo_arm { }; } pfr64; =20 - 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; =20 struct { @@ -321,8 +345,29 @@ struct cpuinfo_arm { }; } pfr32; =20 - 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; =20 struct { --=20 2.29.0 From nobody Thu Apr 25 04:51:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1633942885756803.5492613481482; Mon, 11 Oct 2021 02:01:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.205527.360875 (Exim 4.92) (envelope-from ) id 1mZrBI-0003WL-BD; Mon, 11 Oct 2021 09:01:12 +0000 Received: by outflank-mailman (output) from mailman id 205527.360875; Mon, 11 Oct 2021 09:01:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZrBI-0003WA-6y; Mon, 11 Oct 2021 09:01:12 +0000 Received: by outflank-mailman (input) for mailman id 205527; Mon, 11 Oct 2021 09:01:11 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZrBH-0002uG-JT for xen-devel@lists.xenproject.org; Mon, 11 Oct 2021 09:01:11 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id c681921e-2a71-11ec-80d2-12813bfff9fa; Mon, 11 Oct 2021 09:01:09 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E595F1FB; Mon, 11 Oct 2021 02:01:08 -0700 (PDT) Received: from e123311-lin.arm.com (unknown [10.57.19.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 346643F66F; Mon, 11 Oct 2021 02:01:06 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c681921e-2a71-11ec-80d2-12813bfff9fa From: Michal Orzel To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Wei Liu , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Nick Rosbrook , Anthony PERARD , Juergen Gross , Christian Lindig , David Scott , Volodymyr Babchuk , bertrand.marquis@arm.com Subject: [PATCH v4 3/3] xen: Expose the PMU to the guests Date: Mon, 11 Oct 2021 11:00:47 +0200 Message-Id: <20211011090047.8878-4-michal.orzel@arm.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20211011090047.8878-1-michal.orzel@arm.com> References: <20211011090047.8878-1-michal.orzel@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1633942887811100001 Content-Type: text/plain; charset="utf-8" Add 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. Please note that this feature is experimental. Signed-off-by: Michal Orzel Signed-off-by: Julien Grall Reviewed-by: Bertrand Marquis --- Changes since v3: -fail if vpmu is set but not supported -rebase on top of latest staging 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 --- 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 | 12 +++++++++--- xen/arch/arm/setup.c | 1 + xen/common/domain.c | 10 +++++++++- xen/include/asm-arm/domain.h | 1 + xen/include/public/domctl.h | 4 +++- 14 files changed, 69 insertions(+), 5 deletions(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 4b1e3028d2..55c4881205 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -690,6 +690,23 @@ default. B: Acceptable values are platform specific. For Intel Processor Trace, this value must be a power of 2 between 4k and 16M. =20 +=3Ditem B + +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 direc= tly +accessible when this parameter is enabled. There is no interrupt support a= nd +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. + =3Dback =20 =3Dhead2 Devices diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index c8669837d8..2449580bad 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1119,6 +1119,9 @@ return fmt.Errorf("converting field ArchX86.MsrRelaxe= d: %v", err) } x.Altp2M =3D Altp2MMode(xc.altp2m) x.VmtraceBufKb =3D int(xc.vmtrace_buf_kb) +if err :=3D x.Vpmu.fromC(&xc.vpmu);err !=3D nil { +return fmt.Errorf("converting field Vpmu: %v", err) +} =20 return nil} =20 @@ -1600,6 +1603,9 @@ return fmt.Errorf("converting field ArchX86.MsrRelaxe= d: %v", err) } xc.altp2m =3D C.libxl_altp2m_mode(x.Altp2M) xc.vmtrace_buf_kb =3D C.int(x.VmtraceBufKb) +if err :=3D x.Vpmu.toC(&xc.vpmu); err !=3D nil { +return fmt.Errorf("converting field Vpmu: %v", err) +} =20 return nil } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index 45f2cba3d2..b2e8bd1a85 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -521,6 +521,7 @@ MsrRelaxed Defbool } Altp2M Altp2MMode VmtraceBufKb int +Vpmu Defbool } =20 type DomainBuildInfoTypeUnion interface { diff --git a/tools/include/libxl.h b/tools/include/libxl.h index ec5e3badae..ee73eb06f1 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -508,6 +508,12 @@ */ #define LIBXL_HAVE_PHYSINFO_CAP_VPMU 1 =20 +/* + * LIBXL_HAVE_VPMU indicates that libxl_domain_build_info has a vpmu param= eter, + * which allows to enable the access to PMU registers. + */ +#define LIBXL_HAVE_VPMU 1 + /* * libxl ABI compatibility * diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_creat= e.c index e356b2106d..2a0234ec16 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -91,6 +91,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, } =20 libxl_defbool_setdefault(&b_info->device_model_stubdomain, false); + libxl_defbool_setdefault(&b_info->vpmu, false); =20 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_conf= ig *d_config, create.flags |=3D XEN_DOMCTL_CDF_nested_virt; } =20 + if ( libxl_defbool_val(b_info->vpmu) ) + create.flags |=3D XEN_DOMCTL_CDF_vpmu; + assert(info->passthrough !=3D 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; } =20 + if (libxl_defbool_val(d_config->b_info.vpmu) && !physinfo.cap_vpmu) { + ret =3D ERROR_INVAL; + LOGD(ERROR, domid, "vpmu not supported on this platform\n"); + goto error_out; + } + ret =3D 0; error_out: return ret; diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 993e83acca..b96fb5c47e 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -655,6 +655,8 @@ libxl_domain_build_info =3D Struct("domain_build_info",[ # Use zero value to disable this feature. ("vmtrace_buf_kb", integer), =20 + ("vpmu", libxl_defbool), + ], dir=3DDIR_IN, copy_deprecated_fn=3D"libxl__domain_build_info_copy_deprecated", ) diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml index 7a4030a192..86758babb3 100644 --- a/tools/ocaml/libs/xc/xenctrl.ml +++ b/tools/ocaml/libs/xc/xenctrl.ml @@ -70,6 +70,7 @@ type domain_create_flag =3D | CDF_IOMMU | CDF_NESTED_VIRT | CDF_VPCI + | CDF_VPMU =20 type domain_create_iommu_opts =3D | IOMMU_NO_SHAREPT diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.= mli index 6900513e7f..0fdb0cc169 100644 --- a/tools/ocaml/libs/xc/xenctrl.mli +++ b/tools/ocaml/libs/xc/xenctrl.mli @@ -63,6 +63,7 @@ type domain_create_flag =3D | CDF_IOMMU | CDF_NESTED_VIRT | CDF_VPCI + | CDF_VPMU =20 type domain_create_iommu_opts =3D | IOMMU_NO_SHAREPT diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 17dddb4cd5..c503b9be00 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -2750,6 +2750,8 @@ skip_usbdev: "If it fixes an issue you are having please report to " "xen-devel@lists.xenproject.org.\n"); =20 + xlu_cfg_get_defbool(config, "vpmu", &b_info->vpmu, 0); + xlu_cfg_destroy(config); } =20 diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index aae4472479..2f988c790e 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -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); } =20 /* Update per-VCPU guest runstate shared memory area (if registered). */ @@ -586,6 +588,10 @@ int arch_vcpu_create(struct vcpu *v) =20 v->arch.hcr_el2 =3D get_default_hcr_flags(); =20 + v->arch.mdcr_el2 =3D HDCR_TDRA | HDCR_TDOSA | HDCR_TDA; + if ( !(v->domain->options & XEN_DOMCTL_CDF_vpmu) ) + v->arch.mdcr_el2 |=3D HDCR_TPM | HDCR_TPMCR; + if ( (rc =3D vcpu_vgic_init(v)) !=3D 0 ) goto fail; =20 @@ -622,9 +628,9 @@ int arch_sanitise_domain_config(struct xen_domctl_creat= edomain *config) { unsigned int max_vcpus; =20 - /* 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) != =3D - (XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap) ) + /* HVM and HAP must be set. IOMMU, VPCI and VPMU may or may not be */ + if ( (config->flags & ~(XEN_DOMCTL_CDF_iommu | XEN_DOMCTL_CDF_vpci | + XEN_DOMCTL_CDF_vpmu)) !=3D (XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_= hap) ) { dprintk(XENLOG_INFO, "Unsupported configuration %#x\n", config->flags); diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 49dc90d198..85386a765a 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -108,6 +108,7 @@ static void __init processor_id(void) =20 identify_cpu(c); current_cpu_data =3D *c; + vpmu_is_available =3D cpu_has_pmu; =20 if ( c->midr.implementer < ARRAY_SIZE(processor_implementers) && processor_implementers[c->midr.implementer] ) diff --git a/xen/common/domain.c b/xen/common/domain.c index 262b6c0c3c..8543fb54fd 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -480,12 +480,14 @@ static int sanitise_domain_config(struct xen_domctl_c= reatedomain *config) bool hvm =3D config->flags & XEN_DOMCTL_CDF_hvm; bool hap =3D config->flags & XEN_DOMCTL_CDF_hap; bool iommu =3D config->flags & XEN_DOMCTL_CDF_iommu; + bool vpmu =3D config->flags & XEN_DOMCTL_CDF_vpmu; =20 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_cr= eatedomain *config) return -EINVAL; } =20 + if ( vpmu && !vpmu_is_available ) + { + dprintk(XENLOG_INFO, "vpmu requested but cannot be enabled this wa= y\n"); + return -EINVAL; + } + return arch_sanitise_domain_config(config); } =20 diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index c9277b5c6d..14e575288f 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -166,6 +166,7 @@ struct arch_vcpu =20 /* HYP configuration */ register_t hcr_el2; + register_t mdcr_el2; =20 uint32_t teecr, teehbr; /* ThumbEE, 32-bit guests only */ #ifdef CONFIG_ARM_32 diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 4cb3f662c2..a53cbd16f4 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -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) =20 /* 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_vpmu =20 uint32_t flags; =20 --=20 2.29.0