From nobody Thu May 2 04:27:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611264492; cv=none; d=zohomail.com; s=zohoarc; b=TlQYgy8DaCgUA2Tkv26wSGu2WfyG5NpsV3yZna2+FGqjLn8qBb17JMQTwjR9yzE9pqw8sX7ZfREBCvRsHjvJL858bcYOlGs0l4738TidyHhxcRFUJw4yNsTUPdDOAC9cdJChT+3h5ov/riNJDwq9Yq6RL5oLFxy0KSm7mSJtRn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611264492; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DYbYBoWLCbqjFFAoQAGKJrAtfH9jYUNpjymydISnpuM=; b=eqWuZiXoLzMYLP9u2KCHlGktp15YUBZTVqt2UDwuClkyAFKPQX6e2+MaWm7quVUg51AfZAWROsaBP8eKtFRFnB6bj4fZ3Cb41Rb1ui63NANGT1se8tWHAx59GJ76kgCJPffFJGzTdWg5tjxtiBQg76m+JmDyox9gP1ePvRSjMUg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611264492838111.17963388053317; Thu, 21 Jan 2021 13:28:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72428.130448 (Exim 4.92) (envelope-from ) id 1l2hUh-0005KI-GR; Thu, 21 Jan 2021 21:27:55 +0000 Received: by outflank-mailman (output) from mailman id 72428.130448; Thu, 21 Jan 2021 21:27:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUh-0005K7-C4; Thu, 21 Jan 2021 21:27:55 +0000 Received: by outflank-mailman (input) for mailman id 72428; Thu, 21 Jan 2021 21:27:54 +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 1l2hUg-0004xj-Da for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:27:54 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 984b4494-49c2-40d8-8eae-e5d0fa3ebcc4; Thu, 21 Jan 2021 21:27:40 +0000 (UTC) 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: 984b4494-49c2-40d8-8eae-e5d0fa3ebcc4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611264460; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DUfVqLjeYl5aZeWE9Zcryu0zAb2yVRHiyW3ZELnMKNk=; b=dKkCllxBpb+H+Ku29A+OknXip0bIWGIRCI3WOg0U4mHJB25MJmhsWdRV MbJIWcZk+NT8yaSc97AXZ+l2eglaMnlcZOOPKgxNZo5NhKPx9FmMg9+Ea xPwbeqVgW8D2d507b/KTbmu5VtpWx4AdEpCUyz9EMzXSX2HG/NGili00n E=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: y4ySfdYP34dqIynXJrVxHMLo1FMFKJypHttOqgSJkAZCR0/Nlf183JlInpPczur3oiOfygKG9F fEqVI3EBLqQ11Gl2CvMfN/id32xax8Zphx/AzutyQ2spBhHA5+KyFrslpyvpfh0fj1C5s5w7yA +3b3nCM7sLpkglZVVFX5STZlImpH+acbW+aCMoxvcP5MSGM2fC1k3apZCMhn+p5mJ7uXCov9fk GoR++NTeulvtJI8C6LfaDfnXV+rYQbmOKCRObhJXsRoQRYfFhjDD1ojdB3WePy1W3dyiqPH+IO OZE= X-SBRS: 5.1 X-MesageID: 35977343 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="35977343" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Ian Jackson , =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Tamas K Lengyel Subject: [PATCH v7 01/10] xen+tools: Introduce XEN_SYSCTL_PHYSCAP_vmtrace Date: Thu, 21 Jan 2021 21:27:09 +0000 Message-ID: <20210121212718.2441-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) We're about to introduce support for Intel Processor Trace, but similar functionality exists in other platforms. Aspects of vmtrace can reasonably can be common, so start with XEN_SYSCTL_PHYSCAP_vmtrace and plumb the signal from Xen all the way down i= nto `xl info`. Signed-off-by: Andrew Cooper Acked-by: Ian Jackson --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Ian Jackson CC: Wei Liu CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel v7: * New --- tools/golang/xenlight/helpers.gen.go | 2 ++ tools/golang/xenlight/types.gen.go | 1 + tools/include/libxl.h | 7 +++++++ tools/libs/light/libxl.c | 2 ++ tools/libs/light/libxl_types.idl | 1 + tools/xl/xl_info.c | 5 +++-- xen/common/domain.c | 2 ++ xen/common/sysctl.c | 2 ++ xen/include/public/sysctl.h | 1 + xen/include/xen/domain.h | 2 ++ 10 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index c8605994e7..62fb98ba30 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -3345,6 +3345,7 @@ x.CapHvmDirectio =3D bool(xc.cap_hvm_directio) 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) =20 return nil} =20 @@ -3375,6 +3376,7 @@ xc.cap_hvm_directio =3D C.bool(x.CapHvmDirectio) 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) =20 return nil } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index b4c5df0f2c..369da6dd1e 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -998,6 +998,7 @@ CapHvmDirectio bool CapHap bool CapShadow bool CapIommuHapPtShare bool +CapVmtrace bool } =20 type Connectorinfo struct { diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 3433c950f9..c4d920f1e5 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -464,6 +464,13 @@ #define LIBXL_HAVE_DEVICE_PCI_ASSIGNABLE_LIST_FREE 1 =20 /* + * LIBXL_HAVE_PHYSINFO_CAP_VMTRACE indicates that libxl_physinfo has a + * cap_vmtrace field, which indicates the availability of platform tracing + * functionality. + */ +#define LIBXL_HAVE_PHYSINFO_CAP_VMTRACE 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility diff --git a/tools/libs/light/libxl.c b/tools/libs/light/libxl.c index d2a87157a2..204eb0be2d 100644 --- a/tools/libs/light/libxl.c +++ b/tools/libs/light/libxl.c @@ -402,6 +402,8 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *= physinfo) !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_shadow); physinfo->cap_iommu_hap_pt_share =3D !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share= ); + physinfo->cap_vmtrace =3D + !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_vmtrace); =20 GC_FREE; return 0; diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 05324736b7..b43d5f1265 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -1050,6 +1050,7 @@ libxl_physinfo =3D Struct("physinfo", [ ("cap_hap", bool), ("cap_shadow", bool), ("cap_iommu_hap_pt_share", bool), + ("cap_vmtrace", bool), ], dir=3DDIR_OUT) =20 libxl_connectorinfo =3D Struct("connectorinfo", [ diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c index ca417df8e8..8383e4a6df 100644 --- a/tools/xl/xl_info.c +++ b/tools/xl/xl_info.c @@ -210,14 +210,15 @@ 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\n", + maybe_printf("virt_caps :%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" : "", info.cap_pv && info.cap_hvm_directio ? " pv_directio" : "", info.cap_hap ? " hap" : "", info.cap_shadow ? " shadow" : "", - info.cap_iommu_hap_pt_share ? " iommu_hap_pt_share" : "" + info.cap_iommu_hap_pt_share ? " iommu_hap_pt_share" : "", + info.cap_vmtrace ? " vmtrace" : "" ); =20 vinfo =3D libxl_get_version_info(ctx); diff --git a/xen/common/domain.c b/xen/common/domain.c index 2b461655c3..d1e94d88cf 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -82,6 +82,8 @@ struct vcpu *idle_vcpu[NR_CPUS] __read_mostly; =20 vcpu_info_t dummy_vcpu_info; =20 +bool __read_mostly vmtrace_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 ec916424e5..3558641cd9 100644 --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -277,6 +277,8 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_s= ysctl) if ( iommu_hap_pt_share ) pi->capabilities |=3D XEN_SYSCTL_PHYSCAP_iommu_hap_pt_shar= e; } + if ( vmtrace_available ) + pi->capabilities |=3D XEN_SYSCTL_PHYSCAP_vmtrace; =20 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 a073647117..d4453d2eab 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -100,6 +100,7 @@ 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) =20 /* Max XEN_SYSCTL_PHYSCAP_* constant. Used for ABI checking. */ #define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index cde0d9c7fe..1708c36964 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -131,4 +131,6 @@ void vnuma_destroy(struct vnuma_info *vnuma); static inline void vnuma_destroy(struct vnuma_info *vnuma) { ASSERT(!vnuma= ); } #endif =20 +extern bool vmtrace_available; + #endif /* __XEN_DOMAIN_H__ */ --=20 2.11.0 From nobody Thu May 2 04:27:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611264480; cv=none; d=zohomail.com; s=zohoarc; b=JGEqVHg6nVE7SX6PjUvoi/CQdub1RsL3xJcOYMneQ4Be2YnEWzRrl3TmNsosl+zWpkdJn7vmiPQ+GvTbd9ZmMlyK6IPPNATrc/eTFC/mDmN/Gint5KxPhyJasm/rSPXzgx1BiuGHVksDZPFRPMkwYgS3UFOpAFsDruLfwGLIYnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611264480; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7t4UBpgQbhboBMPiMwXPv8ete8y8qmYG+3S2JnoYRmU=; b=HcZvO2u8Ec6oroUJzXq2yeoGfA+EG6lMVKD8LX6/4Ds571ZkKgmgSMInA01MJ7lTEruOVPLaVXaLE5HiUnssv0rNt3XQtRH61SXPQD6lRULOFXgvp5XG7nPXyXJJPDt0jxYIczRH2WpStRaP3TvceH2s8S7V/8yWFScyYmmawcM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611264480635321.0922532077974; Thu, 21 Jan 2021 13:28:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72425.130408 (Exim 4.92) (envelope-from ) id 1l2hUY-00054p-CI; Thu, 21 Jan 2021 21:27:46 +0000 Received: by outflank-mailman (output) from mailman id 72425.130408; Thu, 21 Jan 2021 21:27:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUY-00054a-5r; Thu, 21 Jan 2021 21:27:46 +0000 Received: by outflank-mailman (input) for mailman id 72425; Thu, 21 Jan 2021 21:27:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUW-0004xo-Pn for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:27:44 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 34d0ff5b-f912-4506-b4bd-4183fb09ef45; Thu, 21 Jan 2021 21:27:39 +0000 (UTC) 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: 34d0ff5b-f912-4506-b4bd-4183fb09ef45 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611264459; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ULMuNKqMqja/nwuazQayF1mJYFYLgopMHXg6OvP+G2w=; b=hiT0WFxFfwotWHZ6qCB/0HqnaRZ4WQHfV7UZEJnm2HfGJk/enjrLAHsu jIFza//YwTz+iiwJ1blaxnxf5048SCafVa35uiQ2ZtArnRF5b5zkVT89d ssMNhbNUnUIPU//bITCThDaYAj63I1KlIXFios/cvS2emxFJLJDeCDC+C I=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: pUDmeMzBzRUQ5LTuG7vLz88SRopKYd+75Ncm4urmXpHutgRACRYa+VamcvP0TWw/Fo1GROtlJr PWVvoh999Y1SDb/1b5WMtSn0ovR3pofDNrSEyOurvccaZqjK2y07Lh9NxCIyzDpyAYYGo37R6k dpJ5XK62w2YR88xMxstJlfkSG1aRTxITQ1/JI1KR5Nz2/JXExMSbHaaYHZxxsVRG2RwRwem3yo 4L2ARqoLjqKd6PJONXwV7huOUiMpsqo5C8kO6Rtj9NYi14Enolf1VmD4V4RNDbfxgvMLNxc5zr z1Q= X-SBRS: 5.1 X-MesageID: 35977341 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="35977341" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Anthony PERARD , Tamas K Lengyel Subject: [PATCH v7 02/10] xen/domain: Add vmtrace_frames domain creation parameter Date: Thu, 21 Jan 2021 21:27:10 +0000 Message-ID: <20210121212718.2441-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Micha=C5=82 Leszczy=C5=84ski To use vmtrace, buffers of a suitable size need allocating, and different tasks will want different sizes. Add a domain creation parameter, and audit it appropriately in the {arch_,}sanitise_domain_config() functions. For now, the x86 specific auditing is tuned to Processor Trace running in Single Output mode, which requires a single contiguous range of memory. The size is given an arbitrary limit of 64M which is expected to be enough = for anticipated usecases, but not large enough to get into long-running-hyperca= ll problems. Signed-off-by: Micha=C5=82 Leszczy=C5=84ski Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Anthony PERARD CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel When support for later generations of IPT get added, we can in principle st= art to use ToTP which is a scatter list of smaller trace regions to use, if we need to massively up the buffer size available. v7: * Major chop&change within the series. * Use the name 'vmtrace' consistently. * Use the (new) common vcpu_teardown() functionality, rather than leaving a latent memory leak on ARM. --- xen/arch/x86/domain.c | 23 +++++++++++++++++++ xen/common/domain.c | 56 +++++++++++++++++++++++++++++++++++++++++= ++++ xen/include/public/domctl.h | 1 + xen/include/xen/sched.h | 7 ++++++ 4 files changed, 87 insertions(+) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index b9ba04633e..3f12d68e9e 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -660,6 +660,29 @@ int arch_sanitise_domain_config(struct xen_domctl_crea= tedomain *config) return -EINVAL; } =20 + if ( config->vmtrace_frames ) + { + unsigned int frames =3D config->vmtrace_frames; + + ASSERT(vmtrace_available); /* Checked by common code. */ + + /* + * For now, vmtrace is restricted to HVM guests, and using a + * power-of-2 buffer up to 64M in size. + */ + if ( !hvm ) + { + dprintk(XENLOG_INFO, "vmtrace not supported for PV\n"); + return -EINVAL; + } + + if ( frames > (MB(64) >> PAGE_SHIFT) || (frames & (frames - 1)) ) + { + dprintk(XENLOG_INFO, "Unsupported vmtrace frames: %u\n", frame= s); + return -EINVAL; + } + } + return 0; } =20 diff --git a/xen/common/domain.c b/xen/common/domain.c index d1e94d88cf..a844bc7b78 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -132,6 +132,48 @@ static void vcpu_info_reset(struct vcpu *v) v->vcpu_info_mfn =3D INVALID_MFN; } =20 +static void vmtrace_free_buffer(struct vcpu *v) +{ + const struct domain *d =3D v->domain; + struct page_info *pg =3D v->vmtrace.buf; + unsigned int i; + + if ( !pg ) + return; + + for ( i =3D 0; i < d->vmtrace_frames; i++ ) + { + put_page_alloc_ref(&pg[i]); + put_page_and_type(&pg[i]); + } + + v->vmtrace.buf =3D NULL; +} + +static int vmtrace_alloc_buffer(struct vcpu *v) +{ + struct domain *d =3D v->domain; + struct page_info *pg; + unsigned int i; + + if ( !d->vmtrace_frames ) + return 0; + + pg =3D alloc_domheap_pages(d, get_order_from_pages(d->vmtrace_frames), + MEMF_no_refcount); + if ( !pg ) + return -ENOMEM; + + v->vmtrace.buf =3D pg; + + for ( i =3D 0; i < d->vmtrace_frames; i++ ) + /* Domain can't know about this page yet - something fishy going o= n. */ + if ( !get_page_and_type(&pg[i], d, PGT_writable_page) ) + BUG(); + + return 0; +} + /* * Release resources held by a vcpu. There may or may not be live referen= ces * to the vcpu, and it may or may not be fully constructed. @@ -140,6 +182,8 @@ static void vcpu_info_reset(struct vcpu *v) */ static int vcpu_teardown(struct vcpu *v) { + vmtrace_free_buffer(v); + return 0; } =20 @@ -201,6 +245,9 @@ struct vcpu *vcpu_create(struct domain *d, unsigned int= vcpu_id) if ( sched_init_vcpu(v) !=3D 0 ) goto fail_wq; =20 + if ( vmtrace_alloc_buffer(v) !=3D 0 ) + goto fail_wq; + if ( arch_vcpu_create(v) !=3D 0 ) goto fail_sched; =20 @@ -449,6 +496,12 @@ static int sanitise_domain_config(struct xen_domctl_cr= eatedomain *config) } } =20 + if ( config->vmtrace_frames && !vmtrace_available ) + { + dprintk(XENLOG_INFO, "vmtrace requested but not available\n"); + return -EINVAL; + } + return arch_sanitise_domain_config(config); } =20 @@ -474,7 +527,10 @@ struct domain *domain_create(domid_t domid, ASSERT(is_system_domain(d) ? config =3D=3D NULL : config !=3D NULL); =20 if ( config ) + { d->options =3D config->flags; + d->vmtrace_frames =3D config->vmtrace_frames; + } =20 /* Sort out our idea of is_control_domain(). */ d->is_privileged =3D is_priv; diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 666aeb71bf..1585678d50 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -94,6 +94,7 @@ struct xen_domctl_createdomain { uint32_t max_evtchn_port; int32_t max_grant_frames; int32_t max_maptrack_frames; + uint32_t vmtrace_frames; =20 struct xen_arch_domainconfig arch; }; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index da19f4e9f6..03905f6246 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -257,6 +257,10 @@ struct vcpu /* vPCI per-vCPU area, used to store data for long running operations.= */ struct vpci_vcpu vpci; =20 + struct { + struct page_info *buf; + } vmtrace; + struct arch_vcpu arch; }; =20 @@ -470,6 +474,9 @@ struct domain unsigned pbuf_idx; spinlock_t pbuf_lock; =20 + /* Used by vmtrace features */ + uint32_t vmtrace_frames; + /* OProfile support. */ struct xenoprof *xenoprof; =20 --=20 2.11.0 From nobody Thu May 2 04:27:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611264483; cv=none; d=zohomail.com; s=zohoarc; b=d0WWU24fFDk+XXAqMuq6eNL4V6PIPv8xLUSt4vvNJHzksLWFenD5rc2Y4AbOGcoy7FkUSR3c2H9HT99BpVSrIEbtVO2PYC4wfO3X4sQqYCRNphYn3PbLdhyf/cayPFi9HIgf/BLf3dTcuizqqre2a7HQRsy9xZBjvmR2Ghy9AgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611264483; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rX+qpOzKAsRim3WpWNRoe5GS+Cg4IGOMEVnKUiCkLkA=; b=G7BGMXNwFUKeCq1KxWWvNR3kIWiWczFtgUavKfc2ZmzKv/Em4+hz3ujhaZkfJ5+nwDC1nU4jpyne3On7DdLjU7QtD1Rrm/M9CS0esUHrudip34Vs81pqVsbK/BkN1ffQMmbZ4qQcNgepmIVD4VHWkYNMd6IjQVP90zfsBkaK1FM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611264483299909.4194514377579; Thu, 21 Jan 2021 13:28:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72424.130400 (Exim 4.92) (envelope-from ) id 1l2hUX-00053C-Pe; Thu, 21 Jan 2021 21:27:45 +0000 Received: by outflank-mailman (output) from mailman id 72424.130400; Thu, 21 Jan 2021 21:27:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUX-000535-KU; Thu, 21 Jan 2021 21:27:45 +0000 Received: by outflank-mailman (input) for mailman id 72424; Thu, 21 Jan 2021 21:27:44 +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 1l2hUW-0004xj-DL for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:27:44 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d58a849e-48fc-4e36-afb6-4038de5a7806; Thu, 21 Jan 2021 21:27:37 +0000 (UTC) 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: d58a849e-48fc-4e36-afb6-4038de5a7806 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611264457; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qqMUUvIGHfWHo68RiFDlQlo29XS58mcICccVrvN4uCc=; b=S4lC9XrK9Xpk91ar8G9UPMLyUUB+HPAu2eGYKjGPXC2l4ZNh+FA4MF4V AGHQut8iCsHpcE1wMMVUMiOb11VZOmNy0qLOtQvwHnv2OQY+JVxXVaRta BZVmxcKmdqzPtCCtuT+k/Ali8sJGZEOrr/8ZvleEiF2I8Wk3KRTmRyDhM o=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: FahN9JCqGqamlM+Omlb8VQ65ePzW1gAXmKRskkiqzmUomKyC8VKfiNb5H7f1fzmUJi3XwVTtqy xgmy0iVVxyXGHOaBHd3pjVAXMCiODNOWJbCpZ567Us/hRJ3TzKFQfKUSC4Gm39UpxcWMWVDOCl 1nBZNDgkDZOiPJ0UlwxOm5a0t2og/pnT/VBvGmkH21JS8c4canrG/LyAVKywrEN7NPIqe4m+yY Kz3yrCcKfvDIOTp7lB/KuWhXXL1mNWwZrh6ex48/bXvkJFh5S6fsuX3JwJEuiawMvfRMkZIXgV tCc= X-SBRS: 5.1 X-MesageID: 35977339 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="35977339" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Andrew Cooper , Ian Jackson , Wei Liu , Anthony PERARD , "Tamas K Lengyel" Subject: [PATCH v7 03/10] tools/[lib]xl: Add vmtrace_buf_size parameter Date: Thu, 21 Jan 2021 21:27:11 +0000 Message-ID: <20210121212718.2441-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Micha=C5=82 Leszczy=C5=84ski Allow to specify the size of per-vCPU trace buffer upon domain creation. This is zero by default (meaning: not enabled). Signed-off-by: Micha=C5=82 Leszczy=C5=84ski Signed-off-by: Andrew Cooper Acked-by: Ian Jackson --- CC: Ian Jackson CC: Wei Liu CC: Anthony PERARD CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel v7: * Use the name 'vmtrace' consistently. --- docs/man/xl.cfg.5.pod.in | 9 +++++++++ tools/golang/xenlight/helpers.gen.go | 2 ++ tools/golang/xenlight/types.gen.go | 1 + tools/include/libxl.h | 7 +++++++ tools/libs/light/libxl_create.c | 2 ++ tools/libs/light/libxl_types.idl | 4 ++++ tools/xl/xl_parse.c | 4 ++++ 7 files changed, 29 insertions(+) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index c8e017f950..86963298a3 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -681,6 +681,15 @@ Windows). =20 If this option is not specified then it will default to B. =20 +=3Ditem B + +Specifies the size of vmtrace buffer that would be allocated for each +vCPU belonging to this domain. Disabled (i.e. B) by +default. + +B: Acceptable values are platform specific. For Intel Processor +Trace, this value must be a power of 2 between 4k and 16M. + =3Dback =20 =3Dhead2 Devices diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index 62fb98ba30..1e22a407bf 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1114,6 +1114,7 @@ return fmt.Errorf("invalid union key '%v'", x.Type)} x.ArchArm.GicVersion =3D GicVersion(xc.arch_arm.gic_version) x.ArchArm.Vuart =3D VuartType(xc.arch_arm.vuart) x.Altp2M =3D Altp2MMode(xc.altp2m) +x.VmtraceBufKb =3D int(xc.vmtrace_buf_kb) =20 return nil} =20 @@ -1589,6 +1590,7 @@ return fmt.Errorf("invalid union key '%v'", x.Type)} xc.arch_arm.gic_version =3D C.libxl_gic_version(x.ArchArm.GicVersion) xc.arch_arm.vuart =3D C.libxl_vuart_type(x.ArchArm.Vuart) xc.altp2m =3D C.libxl_altp2m_mode(x.Altp2M) +xc.vmtrace_buf_kb =3D C.int(x.VmtraceBufKb) =20 return nil } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index 369da6dd1e..130524dce9 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -513,6 +513,7 @@ GicVersion GicVersion Vuart VuartType } Altp2M Altp2MMode +VmtraceBufKb int } =20 type domainBuildInfoTypeUnion interface { diff --git a/tools/include/libxl.h b/tools/include/libxl.h index c4d920f1e5..7606a21219 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -471,6 +471,13 @@ #define LIBXL_HAVE_PHYSINFO_CAP_VMTRACE 1 =20 /* + * LIBXL_HAVE_VMTRACE_BUF_KB indicates that libxl_domain_create_info has a + * vmtrace_buf_kb parameter, which allows to enable pre-allocation of + * processor tracing buffers of given size. + */ +#define LIBXL_HAVE_VMTRACE_BUF_KB 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_creat= e.c index 86f4a8369d..d4a9380357 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -607,6 +607,8 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_conf= ig *d_config, .max_evtchn_port =3D b_info->event_channels, .max_grant_frames =3D b_info->max_grant_frames, .max_maptrack_frames =3D b_info->max_maptrack_frames, + .vmtrace_frames =3D DIV_ROUNDUP(b_info->vmtrace_buf_kb, + XC_PAGE_SIZE >> 10), }; =20 if (info->type !=3D LIBXL_DOMAIN_TYPE_PV) { diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index b43d5f1265..c092c31b5e 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -646,6 +646,10 @@ libxl_domain_build_info =3D Struct("domain_build_info"= ,[ # supported by x86 HVM and ARM support is planned. ("altp2m", libxl_altp2m_mode), =20 + # Size of preallocated vmtrace trace buffers (in KBYTES). + # Use zero value to disable this feature. + ("vmtrace_buf_kb", integer), + ], dir=3DDIR_IN, copy_deprecated_fn=3D"libxl__domain_build_info_copy_deprecated", ) diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 4ebf39620a..ca99af8d1b 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1863,6 +1863,10 @@ void parse_config_data(const char *config_source, } } =20 + if (!xlu_cfg_get_long(config, "vmtrace_buf_kb", &l, 1) && l) { + b_info->vmtrace_buf_kb =3D l; + } + if (!xlu_cfg_get_list(config, "ioports", &ioports, &num_ioports, 0)) { b_info->num_ioports =3D num_ioports; b_info->ioports =3D calloc(num_ioports, sizeof(*b_info->ioports)); --=20 2.11.0 From nobody Thu May 2 04:27:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611264485; cv=none; d=zohomail.com; s=zohoarc; b=gjGpWvUAYQAVn/ECRcFjLtocrPLGfaNHZ0yJgX1zSztTCkh5N/HIam2FDshyIc/c+B65JncGm1T23DD/FxPqTX0oDeetm7COOkqn9Rf+GMgeiVmT86i2qPzKRrOazD/7ZcvElRxQ/T0w+/JXkpdcFdlgN+Z0ibmutI5N7FEvXdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611264485; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gH4865WyS2hCcrLYVN7vEX2aCUCPiRk410z7xr7MffE=; b=mUKX/1aegbNR96tt2Ul4upzozZUZoXUvpb2bFUv93e0h/GrTwl/EuG9K6uibiNkal+RRZKMZupkcc7IGglAVKm2f1OBcUAE3mmncw/qGjbfVXfuK0Ta7KjV6g7LSaRMzQsnAa0p+v4W4RLjabi6+CIkpt/Jog9lKQFZ2xbI+920= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611264485111504.83262758818137; Thu, 21 Jan 2021 13:28:05 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72426.130424 (Exim 4.92) (envelope-from ) id 1l2hUc-0005B8-O8; Thu, 21 Jan 2021 21:27:50 +0000 Received: by outflank-mailman (output) from mailman id 72426.130424; Thu, 21 Jan 2021 21:27:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUc-0005Av-Ip; Thu, 21 Jan 2021 21:27:50 +0000 Received: by outflank-mailman (input) for mailman id 72426; Thu, 21 Jan 2021 21:27:49 +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 1l2hUb-0004xj-DS for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:27:49 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 16cfb996-d4fd-4070-967c-4b157110cdd2; Thu, 21 Jan 2021 21:27:39 +0000 (UTC) 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: 16cfb996-d4fd-4070-967c-4b157110cdd2 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611264459; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r2BwqWd7NQ1mzdR8kM1P36wwz2HedhnLfyw+QNKXGLk=; b=TT+KlL9d549HqmUOYL54KqyoreABqNFyTQ0xkEXO8Zhi381f23Dz8WH8 4XHTBqtDvypKFV9ZCILd5vsnRS/BdgFLwiogNhzFCBM2q+Rbdwjxbcj+q UqF31vb0LApI0fXXtxCrYsxlKMquN0wAOVsGvb6uaE5XVyUlPaIp6iJeP g=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: rgTHx5nwswuWivY0m9MruSK+ZqPzFzwki2x7fihnbWKj1XiBOOjkjfF/9PaRER3ClVBodvFDKw H2Yi8JNq5TGHeGeANl2hIzHIirx+cox+DoLIoC+OM4ofK6s7AlA6RHNiP0tFjXNG98DuI8YQQx nTcm4Ck0AJPV3MThKebFhsnz9aYcNTRMHYqcPXBIAg9HHN2rWbWFfNgP/9Ow54QFbeGFy/czpR e8BnR2XXlYOc8TDGRWpvYl9sebMArpiHAB36ggFYIVfDw0VO1rNP77Qt//XPeRaNKf9o6+u3VG Ey0= X-SBRS: 5.1 X-MesageID: 35815974 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="35815974" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Tamas K Lengyel Subject: [PATCH v7 04/10] xen/memory: Add a vmtrace_buf resource type Date: Thu, 21 Jan 2021 21:27:12 +0000 Message-ID: <20210121212718.2441-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Micha=C5=82 Leszczy=C5=84ski Allow to map processor trace buffer using acquire_resource(). Signed-off-by: Micha=C5=82 Leszczy=C5=84ski Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel v7: * Rebase over changes elsewhere in the series --- xen/common/memory.c | 27 +++++++++++++++++++++++++++ xen/include/public/memory.h | 1 + 2 files changed, 28 insertions(+) diff --git a/xen/common/memory.c b/xen/common/memory.c index c89923d909..ec6a55172a 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1068,11 +1068,35 @@ static unsigned int resource_max_frames(const struc= t domain *d, case XENMEM_resource_grant_table: return gnttab_resource_max_frames(d, id); =20 + case XENMEM_resource_vmtrace_buf: + return d->vmtrace_frames; + default: return arch_resource_max_frames(d, type, id); } } =20 +static int acquire_vmtrace_buf( + struct domain *d, unsigned int id, unsigned long frame, + unsigned int nr_frames, xen_pfn_t mfn_list[]) +{ + const struct vcpu *v =3D domain_vcpu(d, id); + unsigned int i; + mfn_t mfn; + + if ( !v || !v->vmtrace.buf || + nr_frames > d->vmtrace_frames || + (frame + nr_frames) > d->vmtrace_frames ) + return -EINVAL; + + mfn =3D page_to_mfn(v->vmtrace.buf); + + for ( i =3D 0; i < nr_frames; i++ ) + mfn_list[i] =3D mfn_x(mfn) + frame + i; + + return nr_frames; +} + /* * Returns -errno on error, or positive in the range [1, nr_frames] on * success. Returning less than nr_frames contitutes a request for a @@ -1087,6 +1111,9 @@ static int _acquire_resource( case XENMEM_resource_grant_table: return gnttab_acquire_resource(d, id, frame, nr_frames, mfn_list); =20 + case XENMEM_resource_vmtrace_buf: + return acquire_vmtrace_buf(d, id, frame, nr_frames, mfn_list); + default: return arch_acquire_resource(d, type, id, frame, nr_frames, mfn_li= st); } diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index c4c47a0b38..b0378bb14b 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -625,6 +625,7 @@ struct xen_mem_acquire_resource { =20 #define XENMEM_resource_ioreq_server 0 #define XENMEM_resource_grant_table 1 +#define XENMEM_resource_vmtrace_buf 2 =20 /* * IN - a type-specific resource identifier, which must be zero --=20 2.11.0 From nobody Thu May 2 04:27:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611264478; cv=none; d=zohomail.com; s=zohoarc; b=W1/vdVGg/of4cDhn4XHFkGQmC5jAgKAu7nuQEDTJt2ZsNdOy6DtE5feH02q6wISvsh49C5pUmAO7mlPse+hjLaH+5q0XWeTPbnMOGXgR7E4HtUasy48OwmaW5VnwLgzRzENRPU+i9LR1wpHm5Eucf9+3/FG8hdRL6An/GFN2yBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611264478; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3lqoAV93cYr2LRyipAIjwJKoYvpLHGhT6IK2kr3R9Nw=; b=eqCE2gI5VPmY8kcQgBdAHcXwAUvYFU4p0zjInOxOBjPiuqx1e8STuKufrLkswDS+uQ9VX9aLSpBccfqlY+6x6y7+CKXNeQw1qs0nlFAAj4dM1X9SAqkFj64bFqEL0YSE9LBNaaiUBHU4JBUNoSlQ/3czXgMJizrmTstPymSBIQY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611264478445716.9471604686713; Thu, 21 Jan 2021 13:27:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72421.130376 (Exim 4.92) (envelope-from ) id 1l2hUT-0004y1-5P; Thu, 21 Jan 2021 21:27:41 +0000 Received: by outflank-mailman (output) from mailman id 72421.130376; Thu, 21 Jan 2021 21:27:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUT-0004xu-2D; Thu, 21 Jan 2021 21:27:41 +0000 Received: by outflank-mailman (input) for mailman id 72421; Thu, 21 Jan 2021 21:27:39 +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 1l2hUR-0004xj-IN for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:27:39 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0aeb351d-c53c-4014-95d2-625cc86d0797; Thu, 21 Jan 2021 21:27:37 +0000 (UTC) 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: 0aeb351d-c53c-4014-95d2-625cc86d0797 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611264457; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Wc3FEvOvDDgeHoKwLAGPw5KnMsVxUDgNrcW7jjtvYnA=; b=f2iH52La3CAkdlG4f14y1ml+AXdQwD5WZtkZhrB9h0OkEPGvrdittjEP Hk2ZRc80ddxKWHJRcLExVQj95Lnn2Ga/nv+BxN9/a4B4ImwijoQSvTcyW CpRPs+I5taM8VlS6sfWlJMy3eoNDJVL3N7mYCBq88xVzLXrD4mt3RHgeB Y=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: gQCoibysz3Y2cMDVmBNNrwewFxcfjaxB7dDpMPt+Jas6aw4Dt4V1G4ddmDxeN15mX4bah9p143 QA7lh1vvwD/28Kd3G2DlaPomGSWXfOhFfpKm68GjvFYkwvIzJDnGR0NrG9D0kZnhC5avUuzD3X AMgwCEp2ZFPT4sqC5keONMaWNsFtz64IkIqgmnQ3XljKQkSVDTqloGzyUzXsdbwc5IA5e84WMd D4rx/lbgVpsZaQK1HFle5ELas97NSAk8jztSxxxT4ngsEimgpOnKdtVtBFzdVqnE7K1U9SlNTa G8I= X-SBRS: 5.1 X-MesageID: 35815967 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="35815967" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , Tamas K Lengyel Subject: [PATCH v7 05/10] x86/vmx: Add Intel Processor Trace support Date: Thu, 21 Jan 2021 21:27:13 +0000 Message-ID: <20210121212718.2441-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Micha=C5=82 Leszczy=C5=84ski Add CPUID/MSR enumeration details for Processor Trace. For now, we will on= ly support its use inside VMX operation. Fill in the vmtrace_available boolean to activate the newly introduced common infrastructure for allocating trace buffers. For now, Processor Trace is going to be operated in Single Output mode behi= nd the guests back. Add the MSRs to struct vcpu_msrs, and set up the buffer limit in vmx_init_pt() as it is fixed for the lifetime of the domain. Context switch the most of the MSRs in and out of vCPU context switch, but = the main control register needs to reside in the MSR load/save lists. Explicit= ly pull the msrs pointer out into a local variable, because the optimiser cann= ot keep it live across the memory clobbers in the MSR accesses. Signed-off-by: Micha=C5=82 Leszczy=C5=84ski Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Jun Nakajima CC: Kevin Tian CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel v7: * Major chop&change within the series. * Move MSRs to vcpu_msrs, which is where they'll definitely want to live w= hen we offer PT to VMs for their own use. --- tools/libs/light/libxl_cpuid.c | 1 + tools/misc/xen-cpuid.c | 2 +- xen/arch/x86/hvm/vmx/vmcs.c | 15 ++++++++++++- xen/arch/x86/hvm/vmx/vmx.c | 34 +++++++++++++++++++++++++= +++- xen/include/asm-x86/cpufeature.h | 1 + xen/include/asm-x86/hvm/vmx/vmcs.h | 4 ++++ xen/include/asm-x86/msr.h | 32 +++++++++++++++++++++++++= ++ xen/include/public/arch-x86/cpufeatureset.h | 1 + 8 files changed, 87 insertions(+), 3 deletions(-) diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index 259612834e..289c59c742 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -188,6 +188,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *c= puid, const char* str) {"avx512-ifma", 0x00000007, 0, CPUID_REG_EBX, 21, 1}, {"clflushopt", 0x00000007, 0, CPUID_REG_EBX, 23, 1}, {"clwb", 0x00000007, 0, CPUID_REG_EBX, 24, 1}, + {"proc-trace", 0x00000007, 0, CPUID_REG_EBX, 25, 1}, {"avx512pf", 0x00000007, 0, CPUID_REG_EBX, 26, 1}, {"avx512er", 0x00000007, 0, CPUID_REG_EBX, 27, 1}, {"avx512cd", 0x00000007, 0, CPUID_REG_EBX, 28, 1}, diff --git a/tools/misc/xen-cpuid.c b/tools/misc/xen-cpuid.c index c81aa93055..2d04162d8d 100644 --- a/tools/misc/xen-cpuid.c +++ b/tools/misc/xen-cpuid.c @@ -106,7 +106,7 @@ static const char *const str_7b0[32] =3D [18] =3D "rdseed", [19] =3D "adx", [20] =3D "smap", [21] =3D "avx512-ifma", [22] =3D "pcommit", [23] =3D "clflushopt", - [24] =3D "clwb", [25] =3D "pt", + [24] =3D "clwb", [25] =3D "proc-trace", [26] =3D "avx512pf", [27] =3D "avx512er", [28] =3D "avx512cd", [29] =3D "sha", [30] =3D "avx512bw", [31] =3D "avx512vl", diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 164535f8f0..5576caad8e 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -291,6 +291,20 @@ static int vmx_init_vmcs_config(void) _vmx_cpu_based_exec_control &=3D ~(CPU_BASED_CR8_LOAD_EXITING | CPU_BASED_CR8_STORE_EXITING); =20 + rdmsrl(MSR_IA32_VMX_MISC, _vmx_misc_cap); + + /* Check whether IPT is supported in VMX operation. */ + if ( !smp_processor_id() ) + vmtrace_available =3D cpu_has_proc_trace && + (_vmx_misc_cap & VMX_MISC_PROC_TRACE); + else if ( vmtrace_available && + !(_vmx_misc_cap & VMX_MISC_PROC_TRACE) ) + { + printk("VMX: IPT capabilities differ between CPU%u and CPU0\n", + smp_processor_id()); + return -EINVAL; + } + if ( _vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTRO= LS ) { min =3D 0; @@ -305,7 +319,6 @@ static int vmx_init_vmcs_config(void) SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS | SECONDARY_EXEC_XSAVES | SECONDARY_EXEC_TSC_SCALING); - rdmsrl(MSR_IA32_VMX_MISC, _vmx_misc_cap); if ( _vmx_misc_cap & VMX_MISC_VMWRITE_ALL ) opt |=3D SECONDARY_EXEC_ENABLE_VMCS_SHADOWING; if ( opt_vpid_enabled ) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 4120234c15..93121fbf27 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -428,6 +428,20 @@ static void vmx_domain_relinquish_resources(struct dom= ain *d) vmx_free_vlapic_mapping(d); } =20 +static void vmx_init_pt(struct vcpu *v) +{ + unsigned int frames =3D v->domain->vmtrace_frames; + + if ( !frames ) + return; + + /* Checked by domain creation logic. */ + ASSERT(v->vmtrace.buf); + ASSERT(frames <=3D (GB(4) >> PAGE_SHIFT) && (frames & (frames - 1)) = =3D=3D 0); + + v->arch.msrs->rtit.output_limit =3D (frames << PAGE_SHIFT) - 1; +} + static int vmx_vcpu_initialise(struct vcpu *v) { int rc; @@ -470,6 +484,7 @@ static int vmx_vcpu_initialise(struct vcpu *v) } =20 vmx_install_vlapic_mapping(v); + vmx_init_pt(v); =20 return 0; } @@ -508,22 +523,39 @@ static void vmx_restore_host_msrs(void) =20 static void vmx_save_guest_msrs(struct vcpu *v) { + struct vcpu_msrs *msrs =3D v->arch.msrs; + /* * We cannot cache SHADOW_GS_BASE while the VCPU runs, as it can * be updated at any time via SWAPGS, which we cannot trap. */ v->arch.hvm.vmx.shadow_gs =3D read_gs_shadow(); + + if ( v->arch.hvm.vmx.ipt_active ) + { + rdmsrl(MSR_RTIT_OUTPUT_MASK, msrs->rtit.output_mask); + rdmsrl(MSR_RTIT_STATUS, msrs->rtit.status); + } } =20 static void vmx_restore_guest_msrs(struct vcpu *v) { + const struct vcpu_msrs *msrs =3D v->arch.msrs; + write_gs_shadow(v->arch.hvm.vmx.shadow_gs); wrmsrl(MSR_STAR, v->arch.hvm.vmx.star); wrmsrl(MSR_LSTAR, v->arch.hvm.vmx.lstar); wrmsrl(MSR_SYSCALL_MASK, v->arch.hvm.vmx.sfmask); =20 if ( cpu_has_msr_tsc_aux ) - wrmsr_tsc_aux(v->arch.msrs->tsc_aux); + wrmsr_tsc_aux(msrs->tsc_aux); + + if ( v->arch.hvm.vmx.ipt_active ) + { + wrmsrl(MSR_RTIT_OUTPUT_BASE, page_to_maddr(v->vmtrace.buf)); + wrmsrl(MSR_RTIT_OUTPUT_MASK, msrs->rtit.output_mask); + wrmsrl(MSR_RTIT_STATUS, msrs->rtit.status); + } } =20 void vmx_update_cpu_exec_control(struct vcpu *v) diff --git a/xen/include/asm-x86/cpufeature.h b/xen/include/asm-x86/cpufeat= ure.h index ad3d84bdde..8ad658be1b 100644 --- a/xen/include/asm-x86/cpufeature.h +++ b/xen/include/asm-x86/cpufeature.h @@ -104,6 +104,7 @@ #define cpu_has_clwb boot_cpu_has(X86_FEATURE_CLWB) #define cpu_has_avx512er boot_cpu_has(X86_FEATURE_AVX512ER) #define cpu_has_avx512cd boot_cpu_has(X86_FEATURE_AVX512CD) +#define cpu_has_proc_trace boot_cpu_has(X86_FEATURE_PROC_TRACE) #define cpu_has_sha boot_cpu_has(X86_FEATURE_SHA) #define cpu_has_avx512bw boot_cpu_has(X86_FEATURE_AVX512BW) #define cpu_has_avx512vl boot_cpu_has(X86_FEATURE_AVX512VL) diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/v= mx/vmcs.h index 906810592f..8073af323b 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -156,6 +156,9 @@ struct vmx_vcpu { /* Do we need to tolerate a spurious EPT_MISCONFIG VM exit? */ bool_t ept_spurious_misconfig; =20 + /* Processor Trace configured and enabled for the vcpu. */ + bool ipt_active; + /* Is the guest in real mode? */ uint8_t vmx_realmode; /* Are we emulating rather than VMENTERing? */ @@ -283,6 +286,7 @@ extern u32 vmx_secondary_exec_control; #define VMX_VPID_INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 0x80000000000ULL extern u64 vmx_ept_vpid_cap; =20 +#define VMX_MISC_PROC_TRACE 0x00004000 #define VMX_MISC_CR3_TARGET 0x01ff0000 #define VMX_MISC_VMWRITE_ALL 0x20000000 =20 diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h index 16f95e7344..1d3eca9063 100644 --- a/xen/include/asm-x86/msr.h +++ b/xen/include/asm-x86/msr.h @@ -306,6 +306,38 @@ struct vcpu_msrs }; } misc_features_enables; =20 + /* + * 0x00000560 ... 57x - MSR_RTIT_* + * + * "Real Time Instruction Trace", now called Processor Trace. + * + * These MSRs are not exposed to guests. They are controlled by Xen + * behind the scenes, when vmtrace is enabled for the domain. + * + * MSR_RTIT_OUTPUT_BASE not stored here. It is fixed per vcpu, and + * derived from v->vmtrace.buf. + */ + struct { + /* + * Placed in the MSR load/save lists. Only modified by hypercall = in + * the common case. + */ + uint64_t ctl; + + /* + * Updated by hardware in non-root mode. Synchronised here on vcpu + * context switch. + */ + uint64_t status; + union { + uint64_t output_mask; + struct { + uint32_t output_limit; + uint32_t output_offset; + }; + }; + } rtit; + /* 0x00000da0 - MSR_IA32_XSS */ struct { uint64_t raw; diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/publ= ic/arch-x86/cpufeatureset.h index 6f7efaad6d..a501479820 100644 --- a/xen/include/public/arch-x86/cpufeatureset.h +++ b/xen/include/public/arch-x86/cpufeatureset.h @@ -217,6 +217,7 @@ XEN_CPUFEATURE(SMAP, 5*32+20) /*S Supervisor = Mode Access Prevention */ XEN_CPUFEATURE(AVX512_IFMA, 5*32+21) /*A AVX-512 Integer Fused Multiply= Add */ XEN_CPUFEATURE(CLFLUSHOPT, 5*32+23) /*A CLFLUSHOPT instruction */ XEN_CPUFEATURE(CLWB, 5*32+24) /*A CLWB instruction */ +XEN_CPUFEATURE(PROC_TRACE, 5*32+25) /* Processor Trace */ XEN_CPUFEATURE(AVX512PF, 5*32+26) /*A AVX-512 Prefetch Instructions = */ XEN_CPUFEATURE(AVX512ER, 5*32+27) /*A AVX-512 Exponent & Reciprocal = Instrs */ XEN_CPUFEATURE(AVX512CD, 5*32+28) /*A AVX-512 Conflict Detection Ins= trs */ --=20 2.11.0 From nobody Thu May 2 04:27:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611264502; cv=none; d=zohomail.com; s=zohoarc; b=K+Pwm3a53vCnmbZ8vvybX46mCCjBSgE4I+UbSxlTbfch//xlaBQYa10XtbOmFluajPCStsHCPCCgL6KqYOwSX2Cl022vBiqjKRABf9y16C3IkNjp3D0sSWOhv9g4xzC/BfVZODfSsO6a0RwJlirvwVKhzcJke1cI18a7K+EC/yQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611264502; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7h1b7AtHx8Sb1BaBe9fyC9+EyRu7dekFw8gwCKrd2bA=; b=Rs797EfLLiX2DwebbXTn1fs9sseAV+Q+buU9YBRjglNIjxDgQ4+wa8QYZ/QMbD1wYUsZpgmR4y8N5Bzneo5Du+f6FKTpeLQtRGHmKG8ZCS0eFmGZCunCJ9D9WPps7G4mXKhAzDbg0YZ/49Ms1C+uCu6kGcmUFG7cy+I+tzIVJGw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611264502649583.5650597667972; Thu, 21 Jan 2021 13:28:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72433.130471 (Exim 4.92) (envelope-from ) id 1l2hUq-0005aq-WC; Thu, 21 Jan 2021 21:28:05 +0000 Received: by outflank-mailman (output) from mailman id 72433.130471; Thu, 21 Jan 2021 21:28:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUq-0005aa-SC; Thu, 21 Jan 2021 21:28:04 +0000 Received: by outflank-mailman (input) for mailman id 72433; Thu, 21 Jan 2021 21:28:03 +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 1l2hUp-0005Yt-B2 for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:28:03 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 069a7fe1-dc92-44cf-9c62-0116619a9485; Thu, 21 Jan 2021 21:28:02 +0000 (UTC) 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: 069a7fe1-dc92-44cf-9c62-0116619a9485 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611264482; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ao91LD5RU1JMlY1QXvmQo9WVVoz5as90GePXi5Nwnxw=; b=d5Nigeb2Tz0CzZihuzPt5WvPOpxZfv5uZWcDwAZVxp7Gwnz0l5RnU92T QMhzEifK1WnLivOUw13qZNOm/9mdTwtk7k5vSzW7dudPWn+oN6D8UgdIS VROxApv9dor7TLrfqRBfAreOhjRNkIHov7vywn0ayugCWFe5SG1c3Xc3B M=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: 5nDw2G6uFJpOg7SlV4SYjm/To8+T/hhhKhvuegTu8ja7NYZfLrN3dQcnTbRAp1Xo5OvSEfc/Hv ub0ZHxxrSjH/Ar/AvYHY8NzbL6s+NzR2f2ckgiC4e1fMygN0UMWJvI4Fu3dv4gZKMd4uLjGTrW oOmqOF9jFVn0ksIRypIZ0AAoyfKOYpKDLRU9YK1PvLwBupi2cKUkGjNYRj45+lbU1mNW3uJQJg 1dnSFxQqd7BXvOOnwMvOPYczZHXXT0HZXnbIgwlH4XpCKOMhAR8QnM0eguI377/I2IpptVkG98 w/g= X-SBRS: 5.1 X-MesageID: 35651443 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="35651443" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , Tamas K Lengyel Subject: [PATCH v7 06/10] xen/domctl: Add XEN_DOMCTL_vmtrace_op Date: Thu, 21 Jan 2021 21:27:14 +0000 Message-ID: <20210121212718.2441-7-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Micha=C5=82 Leszczy=C5=84ski Implement an interface to configure and control tracing operations. Reuse = the existing SETDEBUGGING flask vector rather than inventing a new one. Userspace using this interface is going to need platform specific knowledge anyway to interpret the contents of the trace buffer. While some operations (e.g. enable/disable) can reasonably be generic, others cannot. Provide an explicitly-platform specific pair of get/set operations to reduce API churn= as new options get added/enabled. For the VMX specific Processor Trace implementation, tolerate reading and modifying a safe subset of bits in CTL, STATUS and OUTPUT_MASK. This permi= ts userspace to control the content which gets logged, but prevents modificati= on of details such as the position/size of the output buffer. Signed-off-by: Micha=C5=82 Leszczy=C5=84ski Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Jun Nakajima CC: Kevin Tian CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel v7: * Major chop&change within the series. --- xen/arch/x86/domctl.c | 55 +++++++++++++++ xen/arch/x86/hvm/vmx/vmx.c | 151 ++++++++++++++++++++++++++++++++++++++= ++++ xen/include/asm-x86/hvm/hvm.h | 63 ++++++++++++++++++ xen/include/public/domctl.h | 35 ++++++++++ xen/xsm/flask/hooks.c | 1 + 5 files changed, 305 insertions(+) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index b28cfe9817..aa6dfe8eed 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -155,6 +155,55 @@ void arch_get_domain_info(const struct domain *d, info->arch_config.emulation_flags =3D d->arch.emulation_flags; } =20 +static int do_vmtrace_op(struct domain *d, struct xen_domctl_vmtrace_op *o= p, + XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) +{ + struct vcpu *v; + int rc; + + if ( !d->vmtrace_frames || d =3D=3D current->domain /* No vcpu_pause()= */ ) + return -EINVAL; + + ASSERT(is_hvm_domain(d)); /* Restricted by domain creation logic. */ + + v =3D domain_vcpu(d, op->vcpu); + if ( !v ) + return -ENOENT; + + vcpu_pause(v); + switch ( op->cmd ) + { + case XEN_DOMCTL_vmtrace_enable: + case XEN_DOMCTL_vmtrace_disable: + case XEN_DOMCTL_vmtrace_reset_and_enable: + rc =3D hvm_vmtrace_control( + v, op->cmd !=3D XEN_DOMCTL_vmtrace_disable, + op->cmd =3D=3D XEN_DOMCTL_vmtrace_reset_and_enable); + break; + + case XEN_DOMCTL_vmtrace_output_position: + rc =3D hvm_vmtrace_output_position(v, &op->value); + if ( rc >=3D 0 ) + rc =3D 0; + break; + + case XEN_DOMCTL_vmtrace_get_option: + rc =3D hvm_vmtrace_get_option(v, op->key, &op->value); + break; + + case XEN_DOMCTL_vmtrace_set_option: + rc =3D hvm_vmtrace_set_option(v, op->key, op->value); + break; + + default: + rc =3D -EOPNOTSUPP; + break; + } + vcpu_unpause(v); + + return rc; +} + #define MAX_IOPORTS 0x10000 =20 long arch_do_domctl( @@ -1320,6 +1369,12 @@ long arch_do_domctl( domain_unpause(d); break; =20 + case XEN_DOMCTL_vmtrace_op: + ret =3D do_vmtrace_op(d, &domctl->u.vmtrace_op, u_domctl); + if ( !ret ) + copyback =3D true; + break; + default: ret =3D iommu_do_domctl(domctl, d, u_domctl); break; diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 93121fbf27..d4e7b50b8a 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2261,6 +2261,153 @@ static bool vmx_get_pending_event(struct vcpu *v, s= truct x86_event *info) return true; } =20 +static int vmtrace_get_option(struct vcpu *v, uint64_t key, uint64_t *outp= ut) +{ + const struct vcpu_msrs *msrs =3D v->arch.msrs; + + /* + * We only let vmtrace agents see and modify a subset of bits in + * MSR_RTIT_CTL. These all pertain to date emitted into the trace + * buffer(s). Must not include controls pertaining to the + * structure/position of the trace buffer(s). + */ +#define RTIT_CTL_MASK \ + (RTIT_CTL_TRACE_EN | RTIT_CTL_OS | RTIT_CTL_USR | RTIT_CTL_TSC_EN | \ + RTIT_CTL_DIS_RETC | RTIT_CTL_BRANCH_EN) + + /* + * Status bits restricted to the first-gen subset (i.e. no further CPU= ID + * requirements.) + */ +#define RTIT_STATUS_MASK \ + (RTIT_STATUS_FILTER_EN | RTIT_STATUS_CONTEXT_EN | RTIT_STATUS_TRIGGER_= EN | \ + RTIT_STATUS_ERROR | RTIT_STATUS_STOPPED) + + switch ( key ) + { + case MSR_RTIT_OUTPUT_MASK: + *output =3D msrs->rtit.output_mask; + break; + + case MSR_RTIT_CTL: + *output =3D msrs->rtit.ctl & RTIT_CTL_MASK; + break; + + case MSR_RTIT_STATUS: + *output =3D msrs->rtit.status & RTIT_STATUS_MASK; + break; + + default: + *output =3D 0; + return -EINVAL; + } + return 0; +} + +static int vmtrace_set_option(struct vcpu *v, uint64_t key, uint64_t value) +{ + struct vcpu_msrs *msrs =3D v->arch.msrs; + bool new_en, old_en =3D msrs->rtit.ctl & RTIT_CTL_TRACE_EN; + + switch ( key ) + { + case MSR_RTIT_OUTPUT_MASK: + /* + * MSR_RTIT_OUTPUT_MASK, when using Single Output mode, has a limit + * field in the lower 32 bits, and an offset in the upper 32 bits. + * + * Limit is fixed by the vmtrace buffer size and must not be + * controlled by userspace, while offset must be within the limit. + * + * Drop writes to the limit field to simply userspace wanting to r= eset + * the offset by writing 0. + */ + if ( (value >> 32) > msrs->rtit.output_limit ) + return -EINVAL; + msrs->rtit.output_offset =3D value >> 32; + break; + + case MSR_RTIT_CTL: + if ( value & ~RTIT_CTL_MASK ) + return -EINVAL; + + msrs->rtit.ctl &=3D ~RTIT_CTL_MASK; + msrs->rtit.ctl |=3D (value & RTIT_CTL_MASK); + break; + + case MSR_RTIT_STATUS: + if ( value & ~RTIT_STATUS_MASK ) + return -EINVAL; + + msrs->rtit.status &=3D ~RTIT_STATUS_MASK; + msrs->rtit.status |=3D (value & RTIT_STATUS_MASK); + break; + + default: + return -EINVAL; + } + + new_en =3D msrs->rtit.ctl & RTIT_CTL_TRACE_EN; + + /* ctl.trace_en changed =3D> update MSR load/save lists appropriately.= */ + if ( !old_en && new_en ) + { + if ( vmx_add_guest_msr(v, MSR_RTIT_CTL, msrs->rtit.ctl) || + vmx_add_host_load_msr(v, MSR_RTIT_CTL, 0) ) + { + /* + * The only failure cases here are failing the + * singleton-per-domain memory allocation, or exceeding the sp= ace + * in the allocation. We could unwind in principle, but there= is + * nothing userspace can usefully do to continue using this VM. + */ + domain_crash(v->domain); + return -ENXIO; + } + } + else if ( old_en && !new_en ) + { + vmx_del_msr(v, MSR_RTIT_CTL, VMX_MSR_GUEST); + vmx_del_msr(v, MSR_RTIT_CTL, VMX_MSR_HOST); + } + + return 0; +} + +static int vmtrace_control(struct vcpu *v, bool enable, bool reset) +{ + struct vcpu_msrs *msrs =3D v->arch.msrs; + uint64_t new_ctl; + int rc; + + if ( v->arch.hvm.vmx.ipt_active =3D=3D enable ) + return -EINVAL; + + if ( reset ) + { + msrs->rtit.status =3D 0; + msrs->rtit.output_offset =3D 0; + } + + new_ctl =3D msrs->rtit.ctl & ~RTIT_CTL_TRACE_EN; + if ( enable ) + new_ctl |=3D RTIT_CTL_TRACE_EN; + + rc =3D vmtrace_set_option(v, MSR_RTIT_CTL, new_ctl); + if ( rc ) + return rc; + + v->arch.hvm.vmx.ipt_active =3D enable; + + return 0; +} + +static int vmtrace_output_position(struct vcpu *v, uint64_t *pos) +{ + *pos =3D v->arch.msrs->rtit.output_offset; + return v->arch.hvm.vmx.ipt_active; +} + static struct hvm_function_table __initdata vmx_function_table =3D { .name =3D "VMX", .cpu_up_prepare =3D vmx_cpu_up_prepare, @@ -2316,6 +2463,10 @@ static struct hvm_function_table __initdata vmx_func= tion_table =3D { .altp2m_vcpu_update_vmfunc_ve =3D vmx_vcpu_update_vmfunc_ve, .altp2m_vcpu_emulate_ve =3D vmx_vcpu_emulate_ve, .altp2m_vcpu_emulate_vmfunc =3D vmx_vcpu_emulate_vmfunc, + .vmtrace_control =3D vmtrace_control, + .vmtrace_output_position =3D vmtrace_output_position, + .vmtrace_set_option =3D vmtrace_set_option, + .vmtrace_get_option =3D vmtrace_get_option, .tsc_scaling =3D { .max_ratio =3D VMX_TSC_MULTIPLIER_MAX, }, diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index 334bd573b9..960ec03917 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -214,6 +214,12 @@ struct hvm_function_table { bool_t (*altp2m_vcpu_emulate_ve)(struct vcpu *v); int (*altp2m_vcpu_emulate_vmfunc)(const struct cpu_user_regs *regs); =20 + /* vmtrace */ + int (*vmtrace_control)(struct vcpu *v, bool enable, bool reset); + int (*vmtrace_output_position)(struct vcpu *v, uint64_t *pos); + int (*vmtrace_set_option)(struct vcpu *v, uint64_t key, uint64_t value= ); + int (*vmtrace_get_option)(struct vcpu *v, uint64_t key, uint64_t *valu= e); + /* * Parameters and callbacks for hardware-assisted TSC scaling, * which are valid only when the hardware feature is available. @@ -655,6 +661,41 @@ static inline bool altp2m_vcpu_emulate_ve(struct vcpu = *v) return false; } =20 +static inline int hvm_vmtrace_control(struct vcpu *v, bool enable, bool re= set) +{ + if ( hvm_funcs.vmtrace_control ) + return hvm_funcs.vmtrace_control(v, enable, reset); + + return -EOPNOTSUPP; +} + +/* Returns -errno, or a boolean of whether tracing is currently active. */ +static inline int hvm_vmtrace_output_position(struct vcpu *v, uint64_t *po= s) +{ + if ( hvm_funcs.vmtrace_output_position ) + return hvm_funcs.vmtrace_output_position(v, pos); + + return -EOPNOTSUPP; +} + +static inline int hvm_vmtrace_set_option( + struct vcpu *v, uint64_t key, uint64_t value) +{ + if ( hvm_funcs.vmtrace_set_option ) + return hvm_funcs.vmtrace_set_option(v, key, value); + + return -EOPNOTSUPP; +} + +static inline int hvm_vmtrace_get_option( + struct vcpu *v, uint64_t key, uint64_t *value) +{ + if ( hvm_funcs.vmtrace_get_option ) + return hvm_funcs.vmtrace_get_option(v, key, value); + + return -EOPNOTSUPP; +} + /* * This must be defined as a macro instead of an inline function, * because it uses 'struct vcpu' and 'struct domain' which have @@ -751,6 +792,28 @@ static inline bool hvm_has_set_descriptor_access_exiti= ng(void) return false; } =20 +static inline int hvm_vmtrace_control(struct vcpu *v, bool enable, bool re= set) +{ + return -EOPNOTSUPP; +} + +static inline int hvm_vmtrace_output_position(struct vcpu *v, uint64_t *po= s) +{ + return -EOPNOTSUPP; +} + +static inline int hvm_vmtrace_set_option( + struct vcpu *v, uint64_t key, uint64_t value) +{ + return -EOPNOTSUPP; +} + +static inline int hvm_vmtrace_get_option( + struct vcpu *v, uint64_t key, uint64_t *value) +{ + return -EOPNOTSUPP; +} + #define is_viridian_domain(d) ((void)(d), false) #define is_viridian_vcpu(v) ((void)(v), false) #define has_viridian_time_ref_count(d) ((void)(d), false) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 1585678d50..218593e548 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1133,6 +1133,39 @@ struct xen_domctl_vuart_op { */ }; =20 +/* XEN_DOMCTL_vmtrace_op: Perform VM tracing operations. */ +struct xen_domctl_vmtrace_op { + uint32_t cmd; /* IN */ + uint32_t vcpu; /* IN */ + uint64_aligned_t key; /* IN - @cmd specific data. */ + uint64_aligned_t value; /* IN/OUT - @cmd specific data. */ + + /* + * General enable/disable of tracing. + * + * XEN_DOMCTL_vmtrace_reset_and_enable is provided as optimisation for + * common usecases, which want to reset status and position information + * when turning tracing back on. + */ +#define XEN_DOMCTL_vmtrace_enable 1 +#define XEN_DOMCTL_vmtrace_disable 2 +#define XEN_DOMCTL_vmtrace_reset_and_enable 3 + + /* Obtain the current output position within the buffer. Fills @value= . */ +#define XEN_DOMCTL_vmtrace_output_position 4 + + /* + * Get/Set platform specific configuration. + * + * For Intel Processor Trace, @key/@value are interpreted as MSR + * reads/writes to MSR_RTIT_*, filtered to a safe subset. + */ +#define XEN_DOMCTL_vmtrace_get_option 5 +#define XEN_DOMCTL_vmtrace_set_option 6 +}; +typedef struct xen_domctl_vmtrace_op xen_domctl_vmtrace_op_t; +DEFINE_XEN_GUEST_HANDLE(xen_domctl_vmtrace_op_t); + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -1217,6 +1250,7 @@ struct xen_domctl { #define XEN_DOMCTL_vuart_op 81 #define XEN_DOMCTL_get_cpu_policy 82 #define XEN_DOMCTL_set_cpu_policy 83 +#define XEN_DOMCTL_vmtrace_op 84 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1277,6 +1311,7 @@ struct xen_domctl { struct xen_domctl_monitor_op monitor_op; struct xen_domctl_psr_alloc psr_alloc; struct xen_domctl_vuart_op vuart_op; + struct xen_domctl_vmtrace_op vmtrace_op; uint8_t pad[128]; } u; }; diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 19b0d9e3eb..3eba495ab3 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -703,6 +703,7 @@ static int flask_domctl(struct domain *d, int cmd) return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__VM_EVENT); =20 case XEN_DOMCTL_debug_op: + case XEN_DOMCTL_vmtrace_op: case XEN_DOMCTL_gdbsx_guestmemio: case XEN_DOMCTL_gdbsx_pausevcpu: case XEN_DOMCTL_gdbsx_unpausevcpu: --=20 2.11.0 From nobody Thu May 2 04:27:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611264485; cv=none; d=zohomail.com; s=zohoarc; b=CEZkMUdXNQk9ElkbMxkBGPOtqeGpG1y1vSe7zn/9LgiSGKdap4eojIo1FIAFD/HQcqRFdJKqHf6AC2ItlimJyXSPwHdFrwTEZqcFpvK1vpcA0xYZnsXNRu8QLeC2UdSOKnS/UVrFuMVG2WjCt7WxeKh12CeZbaqAaUCobq/GfN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611264485; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=590oI3ygSc4wbvCd6v+UbdTAv68ZcP37508QTvucQjc=; b=TE4jfy1x8jSWkWuqokETkh+wNC/MiGf5qGV4MO1pBzsrkvKhAN3beXyfnfGU7PKmXahLRa7WEDPwOkbrNkjwsxJIzUd45SLVQjuC00wWN6IRyAh2wT15mCy5Avy7oRcG7XZ+S0qZ8D9zLzXwwvY6NstF3dV7vBvXpIvndWuiwF0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611264485272773.5111437677788; Thu, 21 Jan 2021 13:28:05 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72427.130430 (Exim 4.92) (envelope-from ) id 1l2hUd-0005CV-9f; Thu, 21 Jan 2021 21:27:51 +0000 Received: by outflank-mailman (output) from mailman id 72427.130430; Thu, 21 Jan 2021 21:27:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUc-0005By-VZ; Thu, 21 Jan 2021 21:27:50 +0000 Received: by outflank-mailman (input) for mailman id 72427; Thu, 21 Jan 2021 21:27:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUb-0004xo-QD for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:27:49 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 375bebc6-b808-405d-9366-9079a2fcb42e; Thu, 21 Jan 2021 21:27:39 +0000 (UTC) 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: 375bebc6-b808-405d-9366-9079a2fcb42e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611264458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BoP/rfsovnNtQ8ibuYb5LfKyC6U90NDoKfh3PcApORE=; b=C/NB7nW1QOtiRnZHxlxkCU6PabzItyY562WXYRUvc7/CgEv8W3V+CcwR cmWQJkYUIe1JnYAoVyqLflQ1sw6Kfi3XKIoeQHReO09ZJciOUVv+ZFIFK jOhvdFdgGulL/eyY6u01Xs5wYGquRgWgfogivdHW/Ab7zCFy4xIo5mJxp w=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: hEJkToRs80NOlG7G50aqfGmIoekXoev5dlNXRccxGlRsPOfz/mYw2svrxzHQU/vHfbRdZvNVYY stDBZrWwf4raZ/aUKLZb650XFRwB75NslribDjzupdv3zMm+allu3ZqF/ZD68wNc1LE0y3lFEv d4MNeoxLVxu5fFBa+r8IIjM4+P92z1fewLrYstgUo+lZ9NMhjXTiRcYXjBiw8F6tqEfGZrKN1u yV8FG6M3B9rhlH/bFeCgAu3t7UPd21SUTq7gd35g/KUKapAjREg+SfUssw+ujVdRNwWJsd8XXK wRE= X-SBRS: 5.1 X-MesageID: 35815969 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="35815969" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Andrew Cooper , Ian Jackson , Wei Liu , Tamas K Lengyel Subject: [PATCH v7 07/10] tools/libxc: Add xc_vmtrace_* functions Date: Thu, 21 Jan 2021 21:27:15 +0000 Message-ID: <20210121212718.2441-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Micha=C5=82 Leszczy=C5=84ski Add functions in libxc that use the new XEN_DOMCTL_vmtrace interface. Signed-off-by: Micha=C5=82 Leszczy=C5=84ski Signed-off-by: Andrew Cooper Acked-by: Ian Jackson --- CC: Ian Jackson CC: Wei Liu CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel v7: * Use the name 'vmtrace' consistently. --- tools/include/xenctrl.h | 73 ++++++++++++++++++++++++ tools/libs/ctrl/Makefile | 1 + tools/libs/ctrl/xc_vmtrace.c | 128 +++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 202 insertions(+) create mode 100644 tools/libs/ctrl/xc_vmtrace.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 3796425e1e..0efcdae8b4 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1583,6 +1583,79 @@ int xc_tbuf_set_cpu_mask(xc_interface *xch, xc_cpuma= p_t mask); =20 int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask); =20 +/** + * Enable vmtrace for given vCPU. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_enable(xc_interface *xch, uint32_t domid, uint32_t vcpu); + +/** + * Enable vmtrace for given vCPU. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_disable(xc_interface *xch, uint32_t domid, uint32_t vcpu); + +/** + * Enable vmtrace for a given vCPU, along with resetting status/offset + * details. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_reset_and_enable(xc_interface *xch, uint32_t domid, + uint32_t vcpu); + +/** + * Get current output position inside the trace buffer. + * + * Repeated calls will return different values if tracing is enabled. It = is + * platform specific what happens when the buffer fills completely. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @parm pos current output position in bytes + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_output_position(xc_interface *xch, uint32_t domid, + uint32_t vcpu, uint64_t *pos); + +/** + * Get platform specific vmtrace options. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @parm key platform-specific input + * @parm value platform-specific output + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_get_option(xc_interface *xch, uint32_t domid, + uint32_t vcpu, uint64_t key, uint64_t *value); + +/** + * Set platform specific vntvmtrace options. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @parm key platform-specific input + * @parm value platform-specific input + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_set_option(xc_interface *xch, uint32_t domid, + uint32_t vcpu, uint64_t key, uint64_t value); + int xc_domctl(xc_interface *xch, struct xen_domctl *domctl); int xc_sysctl(xc_interface *xch, struct xen_sysctl *sysctl); =20 diff --git a/tools/libs/ctrl/Makefile b/tools/libs/ctrl/Makefile index 4185dc3f22..449c89f440 100644 --- a/tools/libs/ctrl/Makefile +++ b/tools/libs/ctrl/Makefile @@ -22,6 +22,7 @@ SRCS-y +=3D xc_pm.c SRCS-y +=3D xc_cpu_hotplug.c SRCS-y +=3D xc_resume.c SRCS-y +=3D xc_vm_event.c +SRCS-y +=3D xc_vmtrace.c SRCS-y +=3D xc_monitor.c SRCS-y +=3D xc_mem_paging.c SRCS-y +=3D xc_mem_access.c diff --git a/tools/libs/ctrl/xc_vmtrace.c b/tools/libs/ctrl/xc_vmtrace.c new file mode 100644 index 0000000000..602502367f --- /dev/null +++ b/tools/libs/ctrl/xc_vmtrace.c @@ -0,0 +1,128 @@ +/*************************************************************************= ***** + * xc_vmtrace.c + * + * API for manipulating hardware tracing features + * + * Copyright (c) 2020, Michal Leszczynski + * + * Copyright 2020 CERT Polska. All rights reserved. + * Use is subject to license terms. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_private.h" + +int xc_vmtrace_enable( + xc_interface *xch, uint32_t domid, uint32_t vcpu) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_enable, + .vcpu =3D vcpu, + }, + }; + + return do_domctl(xch, &domctl); +} + +int xc_vmtrace_disable( + xc_interface *xch, uint32_t domid, uint32_t vcpu) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_disable, + .vcpu =3D vcpu, + }, + }; + + return do_domctl(xch, &domctl); +} + +int xc_vmtrace_reset_and_enable( + xc_interface *xch, uint32_t domid, uint32_t vcpu) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_reset_and_enable, + .vcpu =3D vcpu, + }, + }; + + return do_domctl(xch, &domctl); +} + +int xc_vmtrace_output_position( + xc_interface *xch, uint32_t domid, uint32_t vcpu, uint64_t *pos) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_output_position, + .vcpu =3D vcpu, + }, + }; + int rc =3D do_domctl(xch, &domctl); + + if ( !rc ) + *pos =3D domctl.u.vmtrace_op.value; + + return rc; +} + +int xc_vmtrace_get_option( + xc_interface *xch, uint32_t domid, uint32_t vcpu, + uint64_t key, uint64_t *value) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_get_option, + .vcpu =3D vcpu, + .key =3D key, + }, + }; + int rc =3D do_domctl(xch, &domctl); + + if ( !rc ) + *value =3D domctl.u.vmtrace_op.value; + + return rc; +} + +int xc_vmtrace_set_option( + xc_interface *xch, uint32_t domid, uint32_t vcpu, + uint64_t key, uint64_t value) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_set_option, + .vcpu =3D vcpu, + .key =3D key, + .value =3D value, + }, + }; + + return do_domctl(xch, &domctl); +} --=20 2.11.0 From nobody Thu May 2 04:27:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611264478; cv=none; d=zohomail.com; s=zohoarc; b=aB+Qf8BwL83YZmehi2mByls7pojTurgGBV+5hijepHQe/enl8J0g/IaUNH/DTeFTKzIOviqEkhWIWQWgV/BFKvjDUDD0hEp6+t+RCjglTFxxQYl2QRE5imqh81QjR5Jvb+LmKfA4oFEOyrMYHcZg3gyPqE7eo9HyoKD0IgC7RwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611264478; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QvTvLSFURojjUs+VYuWmjWsIHx0t1uX97KoqQg96Crs=; b=m+2HmQ1P5DUCMcG5r2NAXdDBp0xCJehVlhScscUX2Wk4lvklrFNjEYXf5PVdtLn914zIEl+ZoaUbsu+Jz5/+wVIUMmNKOa66d1C7Gh/9BOS34m8VCpiqGtZBwAWYnjjh0BHLaGgiWTcRP/PBrI5znEbEuNOtYPFW/+o+lLPBT4M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611264478674995.5923463486081; Thu, 21 Jan 2021 13:27:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72422.130381 (Exim 4.92) (envelope-from ) id 1l2hUT-0004yp-Ez; Thu, 21 Jan 2021 21:27:41 +0000 Received: by outflank-mailman (output) from mailman id 72422.130381; Thu, 21 Jan 2021 21:27:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUT-0004yI-AI; Thu, 21 Jan 2021 21:27:41 +0000 Received: by outflank-mailman (input) for mailman id 72422; Thu, 21 Jan 2021 21:27:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUR-0004xo-R4 for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:27:39 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 68ffbe82-822a-4ed2-b229-2a8cd48775d7; Thu, 21 Jan 2021 21:27:37 +0000 (UTC) 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: 68ffbe82-822a-4ed2-b229-2a8cd48775d7 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611264458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9ygrxiTWMU6ddR5H5cC6oPFyoapiyUYkxKa2094fnWg=; b=JHW4RIdkR0rYCGVSmR6djyDRTenNFHhjjXUXB2pWaagkFpYKRodT8Tiv 70edUAV9LOWPn6FjjjLyHy0ycdkJyZSca2tOZVU0AoVM8vkccfEZH6wwd nR/C/XdqScDP3dVBlaNSi0CW2xhJGTFErBMfziNUz6gIQuCuIluUVaa1C Y=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: 1zCq+VimT1/IZWu8Fuo2jqnyI7SzvSEKWY2v+4vSlECRUL9Avzfg+wf2W+IkI4gx+mLIml4569 mtr2GgxyVpwZmXnuEN9pHUhPKe3YUDhC7i+mwX/sZg1EgaSqLmXNIs//EqoXdfANnlZ5c3kj7J EO6o4aiYhBSMdMShHluv/P5EkmcFT1G9E9C53VhaQYXICQJ0P5v6J0MFyqZkG+kKyljl4R3iGB wrpDziwzVe0NtmltI69mxgoXS6XNbVPk3ZFTt7UgAIF2UuRbavkLSQXK8sR4TtomlmkWKG5Rb2 8Ds= X-SBRS: 5.1 X-MesageID: 35651441 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="35651441" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Andrew Cooper , Ian Jackson , Wei Liu , Tamas K Lengyel Subject: [PATCH v7 08/10] tools/misc: Add xen-vmtrace tool Date: Thu, 21 Jan 2021 21:27:16 +0000 Message-ID: <20210121212718.2441-9-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Micha=C5=82 Leszczy=C5=84ski Add an demonstration tool that uses xc_vmtrace_* calls in order to manage external IPT monitoring for DomU. Signed-off-by: Micha=C5=82 Leszczy=C5=84ski Signed-off-by: Andrew Cooper --- CC: Ian Jackson CC: Wei Liu CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel --- tools/misc/.gitignore | 1 + tools/misc/Makefile | 4 ++ tools/misc/xen-vmtrace.c | 154 +++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 159 insertions(+) create mode 100644 tools/misc/xen-vmtrace.c diff --git a/tools/misc/.gitignore b/tools/misc/.gitignore index b2c3b21f57..ce6f937d0c 100644 --- a/tools/misc/.gitignore +++ b/tools/misc/.gitignore @@ -1,3 +1,4 @@ xen-access xen-memshare xen-ucode +xen-vmtrace diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 912c5d4f0e..c5017e6c70 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -25,6 +25,7 @@ INSTALL_SBIN-$(CONFIG_X86) +=3D xen-lowmemd INSTALL_SBIN-$(CONFIG_X86) +=3D xen-memshare INSTALL_SBIN-$(CONFIG_X86) +=3D xen-mfndump INSTALL_SBIN-$(CONFIG_X86) +=3D xen-ucode +INSTALL_SBIN-$(CONFIG_X86) +=3D xen-vmtrace INSTALL_SBIN +=3D xencov INSTALL_SBIN +=3D xenhypfs INSTALL_SBIN +=3D xenlockprof @@ -90,6 +91,9 @@ xen-hvmcrash: xen-hvmcrash.o xen-memshare: xen-memshare.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) =20 +xen-vmtrace: xen-vmtrace.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenforeignmemo= ry) $(APPEND_LDFLAGS) + xenperf: xenperf.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) =20 diff --git a/tools/misc/xen-vmtrace.c b/tools/misc/xen-vmtrace.c new file mode 100644 index 0000000000..47fea871cf --- /dev/null +++ b/tools/misc/xen-vmtrace.c @@ -0,0 +1,154 @@ +/*************************************************************************= ***** + * tools/vmtrace.c + * + * Demonstrative tool for collecting Intel Processor Trace data from Xen. + * Could be used to externally monitor a given vCPU in given DomU. + * + * Copyright (C) 2020 by CERT Polska - NASK PIB + * + * Authors: Micha=C5=82 Leszczy=C5=84ski, michal.leszczynski@cert.pl + * Date: June, 2020 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#define MSR_RTIT_CTL 0x00000570 +#define RTIT_CTL_OS (1 << 2) +#define RTIT_CTL_USR (1 << 3) +#define RTIT_CTL_BRANCH_EN (1 << 13) + +static volatile int interrupted =3D 0; + +static xc_interface *xch; +static xenforeignmemory_handle *fh; + +void int_handler(int signum) +{ + interrupted =3D 1; +} + +int main(int argc, char **argv) +{ + uint32_t domid, vcpu; + int rc, exit =3D 1; + size_t size; + char *buf =3D NULL; + xenforeignmemory_resource_handle *fres =3D NULL; + uint64_t last_offset =3D 0; + + if ( signal(SIGINT, int_handler) =3D=3D SIG_ERR ) + err(1, "Failed to register signal handler\n"); + + if ( argc !=3D 3 ) + { + fprintf(stderr, "Usage: %s \n", argv[0]); + fprintf(stderr, "It's recommended to redirect thisprogram's output= to file\n"); + fprintf(stderr, "or to pipe it's output to xxd or other program.\n= "); + return 1; + } + + domid =3D atoi(argv[1]); + vcpu =3D atoi(argv[2]); + + xch =3D xc_interface_open(NULL, NULL, 0); + fh =3D xenforeignmemory_open(NULL, 0); + + if ( !xch ) + err(1, "xc_interface_open()"); + if ( !fh ) + err(1, "xenforeignmemory_open()"); + + rc =3D xenforeignmemory_resource_size( + fh, domid, XENMEM_resource_vmtrace_buf, vcpu, &size); + if ( rc ) + err(1, "xenforeignmemory_resource_size()"); + + fres =3D xenforeignmemory_map_resource( + fh, domid, XENMEM_resource_vmtrace_buf, vcpu, + 0, size >> XC_PAGE_SHIFT, (void **)&buf, PROT_READ, 0); + if ( !fres ) + err(1, "xenforeignmemory_map_resource()"); + + if ( xc_vmtrace_set_option( + xch, domid, vcpu, MSR_RTIT_CTL, + RTIT_CTL_BRANCH_EN | RTIT_CTL_USR | RTIT_CTL_OS) ) + { + perror("xc_vmtrace_set_option()"); + goto out; + } + + if ( xc_vmtrace_enable(xch, domid, vcpu) ) + { + perror("xc_vmtrace_enable()"); + goto out; + } + + while ( !interrupted ) + { + xc_dominfo_t dominfo; + uint64_t offset; + + if ( xc_vmtrace_output_position(xch, domid, vcpu, &offset) ) + { + perror("xc_vmtrace_output_position()"); + goto out; + } + + if ( offset > last_offset ) + fwrite(buf + last_offset, offset - last_offset, 1, stdout); + else if ( offset < last_offset ) + { + /* buffer wrapped */ + fwrite(buf + last_offset, size - last_offset, 1, stdout); + fwrite(buf, offset, 1, stdout); + } + + last_offset =3D offset; + usleep(1000 * 100); + + if ( xc_domain_getinfo(xch, domid, 1, &dominfo) !=3D 1 || + dominfo.domid !=3D domid || dominfo.shutdown ) + break; + } + + exit =3D 0; + + out: + if ( xc_vmtrace_disable(xch, domid, vcpu) ) + perror("xc_vmtrace_disable()"); + + if ( fres && xenforeignmemory_unmap_resource(fh, fres) ) + perror("xenforeignmemory_unmap_resource()"); + + return exit; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.11.0 From nobody Thu May 2 04:27:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611264490; cv=none; d=zohomail.com; s=zohoarc; b=A+1uU7RfIQneC6Gha37/zJxToPZYZc65DFIBy/6bBChKiKSyjQfGFpmnMpMtDy7Bt/EzDxe8zL+EOI2Fqu7MCFP/sysbG1UOtEiX600yfTKzLaOGP2Lx0OJ4513c3ijMcPdk4w6yQ1yZTg3NCEY2/sZe4L3Dr5eEZUzDdDAQM1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611264490; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iYJu6mi2ufz3SNlM0N08BsGbm3iYwzKvouTph5KrMgk=; b=MRlyfuM+PR1bMc+wC0Bo3lUD2Zu1OI7B5aGBeHHVNA0W4f3bpYCS0bz/8CZJg73Jz9LUr44vRtDGq0Hver7JsL9hHsIq8+rf+zF93G9AWXC+Qh6ymG4cTxKsGSCbKCCx7ZXcVOwTe0AmUKjKU0BMv1TtxK/3m77sBzzOu5aXtHc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611264490617524.669185514839; Thu, 21 Jan 2021 13:28:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72429.130457 (Exim 4.92) (envelope-from ) id 1l2hUi-0005My-Hb; Thu, 21 Jan 2021 21:27:56 +0000 Received: by outflank-mailman (output) from mailman id 72429.130457; Thu, 21 Jan 2021 21:27:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUi-0005MO-8u; Thu, 21 Jan 2021 21:27:56 +0000 Received: by outflank-mailman (input) for mailman id 72429; Thu, 21 Jan 2021 21:27:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUg-0004xo-Re for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:27:54 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cc95afc1-16c5-4671-ba77-cb1a5634bf41; Thu, 21 Jan 2021 21:27:40 +0000 (UTC) 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: cc95afc1-16c5-4671-ba77-cb1a5634bf41 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611264461; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7e+PT6CI2IW9VvmlQDpZMLGMDO6+ZV3J/eiWjcFr53M=; b=W7X4L0wRwHAzvX4XTOmnJwQg+oiApoT7yuYtw2fGxIq+dB5IiADTy9Tv 8Gfm3Rb+fGHe3YU0zv+OaSfI66cjTecOgVbrSofCn0klTp6KvqxK6ztCG VJ/oJOIDj/S/aFGjizMS1tSMbJiMZ87boO3fKTJGW6MyPlz00kHc1FnJj c=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: cQf0RDzhXE13BySs4YmNC/SPFB+uq+uBqGFBBIznYnTSz1PFgyATflfOepIImkyEfQ3cr1owSL HS6M54ULfMDywoJ/mCncxx4fBRPGN6Igd7QMK5b1tMe6tavuQoaLqe4rz2fKoar+cQyw6sQtNt VQcV7B25X2VmwXz7kJniMDmcl1vM6VDtwX2hCSemWt4fObPiWxrEFb7Rfsy5phJy2WdpA/e/rl bLQ1zW1jeGS9Fqk+NOM0ExDXjAehnabzBOnJkImyGBm2BtX5+6RPgfdUwtk2u1513ztDR6r9YN 1KY= X-SBRS: 5.1 X-MesageID: 35977348 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="35977348" From: Andrew Cooper To: Xen-devel CC: Tamas K Lengyel , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Tamas K Lengyel Subject: [PATCH v7 09/10] xen/vmtrace: support for VM forks Date: Thu, 21 Jan 2021 21:27:17 +0000 Message-ID: <20210121212718.2441-10-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Tamas K Lengyel Implement vmtrace_reset_pt function. Properly set IPT state for VM forks. Signed-off-by: Tamas K Lengyel Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Jun Nakajima CC: Kevin Tian CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel v7: * New --- xen/arch/x86/hvm/vmx/vmx.c | 11 +++++++++++ xen/arch/x86/mm/mem_sharing.c | 3 +++ xen/include/asm-x86/hvm/hvm.h | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index d4e7b50b8a..40ae398cf5 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2408,6 +2408,16 @@ static int vmtrace_output_position(struct vcpu *v, u= int64_t *pos) return v->arch.hvm.vmx.ipt_active; } =20 +static int vmtrace_reset(struct vcpu *v) +{ + if ( !v->arch.hvm.vmx.ipt_active ) + return -EINVAL; + + v->arch.msrs->rtit.output_offset =3D 0; + v->arch.msrs->rtit.status =3D 0; + return 0; +} + static struct hvm_function_table __initdata vmx_function_table =3D { .name =3D "VMX", .cpu_up_prepare =3D vmx_cpu_up_prepare, @@ -2467,6 +2477,7 @@ static struct hvm_function_table __initdata vmx_funct= ion_table =3D { .vmtrace_output_position =3D vmtrace_output_position, .vmtrace_set_option =3D vmtrace_set_option, .vmtrace_get_option =3D vmtrace_get_option, + .vmtrace_reset =3D vmtrace_reset, .tsc_scaling =3D { .max_ratio =3D VMX_TSC_MULTIPLIER_MAX, }, diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index adaeab4612..fd07eb8d4d 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -1632,6 +1632,8 @@ static int copy_vcpu_settings(struct domain *cd, cons= t struct domain *d) copy_domain_page(new_vcpu_info_mfn, vcpu_info_mfn); } =20 + hvm_vmtrace_reset(cd_vcpu); + /* * TODO: to support VMs with PV interfaces copy additional * settings here, such as PV timers. @@ -1782,6 +1784,7 @@ static int fork(struct domain *cd, struct domain *d) cd->max_pages =3D d->max_pages; *cd->arch.cpuid =3D *d->arch.cpuid; *cd->arch.msr =3D *d->arch.msr; + cd->vmtrace_frames =3D d->vmtrace_frames; cd->parent =3D d; } =20 diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index 960ec03917..150746de66 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -219,6 +219,7 @@ struct hvm_function_table { int (*vmtrace_output_position)(struct vcpu *v, uint64_t *pos); int (*vmtrace_set_option)(struct vcpu *v, uint64_t key, uint64_t value= ); int (*vmtrace_get_option)(struct vcpu *v, uint64_t key, uint64_t *valu= e); + int (*vmtrace_reset)(struct vcpu *v); =20 /* * Parameters and callbacks for hardware-assisted TSC scaling, @@ -696,6 +697,14 @@ static inline int hvm_vmtrace_get_option( return -EOPNOTSUPP; } =20 +static inline int hvm_vmtrace_reset(struct vcpu *v) +{ + if ( hvm_funcs.vmtrace_reset ) + return hvm_funcs.vmtrace_reset(v); + + return -EOPNOTSUPP; +} + /* * This must be defined as a macro instead of an inline function, * because it uses 'struct vcpu' and 'struct domain' which have --=20 2.11.0 From nobody Thu May 2 04:27:05 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611265992; cv=none; d=zohomail.com; s=zohoarc; b=Y4OMaym4Kusm5p3zcBp2bxyaDur4PLBAfPjFhdecuxpAyKrx2AH/CpyvvNQSrEtg3Kldkbims3qc8645KhpsIOGZAAuoorcCI57mHxhGzhyI8uhc/fR6SmCv6+kTBZZCrCOnja0RTahM0BEXj311lAg12XmPN+U9rkSXi8cRgwA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611265992; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VYNwtMJB2OKgPYmg2SPVWwwfCjNngrBGRYuRUGwtPQE=; b=CYXrwiPhAFlk8J6WtlYPY1hdalGaVSAPSeuoDCN3o0hOM77OgT0vqy8cdwHLeGc1GX567D0U58juxGJymTspRuhDO4Sa0RBt4VWynAIJbyDHuPdLsvO2tue4Mmc8Z2+ZWKTiaowVVKlRZMG2bdnlx2FJdS4diAiwsgKIOOREmOc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611265992418895.3451200127802; Thu, 21 Jan 2021 13:53:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72475.130511 (Exim 4.92) (envelope-from ) id 1l2hsa-0000i6-Rv; Thu, 21 Jan 2021 21:52:36 +0000 Received: by outflank-mailman (output) from mailman id 72475.130511; Thu, 21 Jan 2021 21:52:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hsa-0000hz-Ou; Thu, 21 Jan 2021 21:52:36 +0000 Received: by outflank-mailman (input) for mailman id 72475; Thu, 21 Jan 2021 21:52:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hsZ-0000hu-9L for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:52:35 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 90c8481c-d379-4e99-bb30-9231fc32ec76; Thu, 21 Jan 2021 21:52:34 +0000 (UTC) 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: 90c8481c-d379-4e99-bb30-9231fc32ec76 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611265954; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zH10SOrS7TRCmlRhWyG1y7Y9O10ncjn3XWV3SJVhL6Y=; b=gga2V/WHyJ063ht6vuo3T+EliWp00GLnNHYHpphtKa2O2DYoMCCJI/3m xQ11VnurqXaZzHooEIEbQUP4AN3UprucBMyi/1adNbxyncjQ/YR3l2fP6 oj4WZNF065Txt/Kkiz9XJkpzKXUaG2JytecZPmTh7WXebRNJ3+65rY6ug M=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: Z5eoCsesdA5J0UFxtp/KuY8s6qAAYZrfcrxD/3PJKeCdae9f9Q5cx4sOQDRyplc9S/5Rx5tyNk FcXLVipkwbPT7CMTgSM7YnTEz8EzkaY1cZoO5MsHF7PFOnlQ8HlCdWS83L6sgAmAZTwLFAWkZE zqt7oOHH5k07/khV9Yjt/n4Ag9jVytHirgZbsK9cfKgKMQ6TS9SJOWkM1fBJ58NGM30SP+P24n PvRG7euZrF08Z5XvVF4hSMRkKYc/fV/XK+l6G3s6dH5tkYvW5/8uAZ2f7CvRGWG4Y2wOOQ+/bf Vqo= X-SBRS: 5.1 X-MesageID: 36915711 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="36915711" From: Andrew Cooper To: Xen-devel CC: Tamas K Lengyel , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Tamas K Lengyel Subject: [PATCH v7 10/10] x86/vm_event: Carry Processor Trace buffer offset in vm_event Date: Thu, 21 Jan 2021 21:27:18 +0000 Message-ID: <20210121212718.2441-11-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Tamas K Lengyel Add pt_offset field to x86 regs in vm_event. Initialized to ~0 if PT is not in use. Signed-off-by: Tamas K Lengyel Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Jun Nakajima CC: Kevin Tian CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel v7: * New --- xen/arch/x86/vm_event.c | 3 +++ xen/include/public/vm_event.h | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c index 848d69c1b0..09dfc0924e 100644 --- a/xen/arch/x86/vm_event.c +++ b/xen/arch/x86/vm_event.c @@ -251,6 +251,9 @@ void vm_event_fill_regs(vm_event_request_t *req) =20 req->data.regs.x86.shadow_gs =3D ctxt.shadow_gs; req->data.regs.x86.dr6 =3D ctxt.dr6; + + if ( hvm_vmtrace_output_position(curr, &req->data.regs.x86.pt_offset) = !=3D 1 ) + req->data.regs.x86.pt_offset =3D ~0; #endif } =20 diff --git a/xen/include/public/vm_event.h b/xen/include/public/vm_event.h index 141ea024a3..57f34bf902 100644 --- a/xen/include/public/vm_event.h +++ b/xen/include/public/vm_event.h @@ -223,6 +223,12 @@ struct vm_event_regs_x86 { */ uint64_t npt_base; =20 + /* + * Current offset in the Processor Trace buffer. For Intel Processor T= race + * this is MSR_RTIT_OUTPUT_MASK. Set to ~0 if no Processor Trace is ac= tive. + */ + uint64_t pt_offset; + uint32_t cs_base; uint32_t ss_base; uint32_t ds_base; --=20 2.11.0