From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: James Clark <james.clark@arm.com>,
coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
kvmarm@lists.linux.dev, broonie@kernel.org, maz@kernel.org,
acme@kernel.org
Cc: Oliver Upton <oliver.upton@linux.dev>,
James Morse <james.morse@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Mike Leach <mike.leach@linaro.org>,
Leo Yan <leo.yan@linaro.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Rob Herring <robh@kernel.org>,
Miguel Luis <miguel.luis@oracle.com>,
Jintack Lim <jintack.lim@linaro.org>,
Ard Biesheuvel <ardb@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Arnd Bergmann <arnd@arndb.de>,
Quentin Perret <qperret@google.com>,
Vincent Donnefort <vdonnefort@google.com>,
Fuad Tabba <tabba@google.com>,
Akihiko Odaki <akihiko.odaki@daynix.com>,
Kristina Martsenko <kristina.martsenko@arm.com>,
Joey Gouly <joey.gouly@arm.com>,
Jing Zhang <jingzhangos@google.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 7/7] coresight: Pass guest TRFCR value to KVM
Date: Fri, 5 Jan 2024 09:55:38 +0000 [thread overview]
Message-ID: <50c5076f-fd7f-4b16-b2e2-f67e40394642@arm.com> (raw)
In-Reply-To: <20240104162714.1062610-8-james.clark@arm.com>
On 04/01/2024 16:27, James Clark wrote:
> Currently the userspace and kernel filters for guests are never set, so
> no trace will be generated for them. Add support for tracing guests by
> passing the desired TRFCR value to KVM so it can be applied to the
> guest.
>
> By writing either E1TRE or E0TRE, filtering on either guest kernel or
> guest userspace is also supported. And if both E1TRE and E0TRE are
> cleared when exclude_guest is set, that option is supported too. This
> change also brings exclude_host support which is difficult to add as a
> separate commit without excess churn and resulting in no trace at all.
>
> Testing
> =======
>
> The addresses were counted with the following:
>
> $ perf report -D | grep -Eo 'EL2|EL1|EL0' | sort | uniq -c
>
> Guest kernel only:
>
> $ perf record -e cs_etm//Gk -a -- true
> 535 EL1
> 1 EL2
>
> Guest user only (only 5 addresses because the guest runs slowly in the
> model):
>
> $ perf record -e cs_etm//Gu -a -- true
> 5 EL0
>
> Host kernel only:
>
> $ perf record -e cs_etm//Hk -a -- true
> 3501 EL2
>
> Host userspace only:
>
> $ perf record -e cs_etm//Hu -a -- true
> 408 EL0
> 1 EL2
>
> Signed-off-by: James Clark <james.clark@arm.com>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
> .../coresight/coresight-etm4x-core.c | 42 ++++++++++++++++---
> drivers/hwtracing/coresight/coresight-etm4x.h | 2 +-
> drivers/hwtracing/coresight/coresight-priv.h | 3 ++
> 3 files changed, 40 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> index 34aee59dd147..885d70fd6f40 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> @@ -6,6 +6,7 @@
> #include <linux/acpi.h>
> #include <linux/bitops.h>
> #include <linux/kernel.h>
> +#include <linux/kvm_host.h>
> #include <linux/moduleparam.h>
> #include <linux/init.h>
> #include <linux/types.h>
> @@ -271,9 +272,22 @@ static void etm4x_prohibit_trace(struct etmv4_drvdata *drvdata)
> /* If the CPU doesn't support FEAT_TRF, nothing to do */
> if (!drvdata->trfcr)
> return;
> + kvm_etm_set_guest_trfcr(0);
> cpu_prohibit_trace();
> }
>
> +static u64 etm4x_get_kern_user_filter(struct etmv4_drvdata *drvdata)
> +{
> + u64 trfcr = drvdata->trfcr;
> +
> + if (drvdata->config.mode & ETM_MODE_EXCL_KERN)
> + trfcr &= ~TRFCR_ELx_ExTRE;
> + if (drvdata->config.mode & ETM_MODE_EXCL_USER)
> + trfcr &= ~TRFCR_ELx_E0TRE;
> +
> + return trfcr;
> +}
> +
> /*
> * etm4x_allow_trace - Allow CPU tracing in the respective ELs,
> * as configured by the drvdata->config.mode for the current
> @@ -286,18 +300,28 @@ static void etm4x_prohibit_trace(struct etmv4_drvdata *drvdata)
> */
> static void etm4x_allow_trace(struct etmv4_drvdata *drvdata)
> {
> - u64 trfcr = drvdata->trfcr;
> + u64 trfcr;
>
> /* If the CPU doesn't support FEAT_TRF, nothing to do */
> - if (!trfcr)
> + if (!drvdata->trfcr)
> return;
>
> - if (drvdata->config.mode & ETM_MODE_EXCL_KERN)
> - trfcr &= ~TRFCR_ELx_ExTRE;
> - if (drvdata->config.mode & ETM_MODE_EXCL_USER)
> - trfcr &= ~TRFCR_ELx_E0TRE;
> + if (drvdata->config.mode & ETM_MODE_EXCL_HOST)
> + trfcr = drvdata->trfcr & ~(TRFCR_ELx_ExTRE | TRFCR_ELx_E0TRE);
> + else
> + trfcr = etm4x_get_kern_user_filter(drvdata);
>
> write_trfcr(trfcr);
> +
> + /* Set filters for guests and pass to KVM */
> + if (drvdata->config.mode & ETM_MODE_EXCL_GUEST)
> + trfcr = drvdata->trfcr & ~(TRFCR_ELx_ExTRE | TRFCR_ELx_E0TRE);
> + else
> + trfcr = etm4x_get_kern_user_filter(drvdata);
> +
> + /* TRFCR_EL1 doesn't have CX so mask it out. */
> + trfcr &= ~TRFCR_EL2_CX;
> + kvm_etm_set_guest_trfcr(trfcr);
> }
>
> #ifdef CONFIG_ETM4X_IMPDEF_FEATURE
> @@ -655,6 +679,12 @@ static int etm4_parse_event_config(struct coresight_device *csdev,
> if (attr->exclude_user)
> config->mode = ETM_MODE_EXCL_USER;
>
> + if (attr->exclude_host)
> + config->mode |= ETM_MODE_EXCL_HOST;
> +
> + if (attr->exclude_guest)
> + config->mode |= ETM_MODE_EXCL_GUEST;
> +
> /* Always start from the default config */
> etm4_set_default_config(config);
>
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.h b/drivers/hwtracing/coresight/coresight-etm4x.h
> index 20e2e4cb7614..3f170599822f 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x.h
> +++ b/drivers/hwtracing/coresight/coresight-etm4x.h
> @@ -841,7 +841,7 @@ enum etm_impdef_type {
> * @s_ex_level: Secure ELs where tracing is supported.
> */
> struct etmv4_config {
> - u32 mode;
> + u64 mode;
> u32 pe_sel;
> u32 cfg;
> u32 eventctrl0;
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index 767076e07970..727dd27ba800 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -39,6 +39,9 @@
>
> #define ETM_MODE_EXCL_KERN BIT(30)
> #define ETM_MODE_EXCL_USER BIT(31)
> +#define ETM_MODE_EXCL_HOST BIT(32)
> +#define ETM_MODE_EXCL_GUEST BIT(33)
> +
> struct cs_pair_attribute {
> struct device_attribute attr;
> u32 lo_off;
prev parent reply other threads:[~2024-01-05 9:55 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-04 16:27 [PATCH v4 0/7] kvm/coresight: Support exclude guest and exclude host James Clark
2024-01-04 16:27 ` [PATCH v4 1/7] arm64: KVM: Fix renamed function in comment James Clark
2024-01-04 16:58 ` Suzuki K Poulose
2024-01-04 16:27 ` [PATCH v4 2/7] arm64: KVM: Use shared area to pass PMU event state to hypervisor James Clark
2024-01-05 9:40 ` Suzuki K Poulose
2024-02-01 16:14 ` James Clark
2024-02-02 22:00 ` Oliver Upton
2024-02-05 12:16 ` James Clark
2024-02-05 13:04 ` Oliver Upton
2024-02-05 13:15 ` Marc Zyngier
2024-02-05 13:21 ` Oliver Upton
2024-02-05 14:16 ` Marc Zyngier
2024-02-05 14:17 ` James Clark
2024-02-05 14:52 ` Marc Zyngier
2024-02-05 15:37 ` James Clark
2024-02-05 15:50 ` Marc Zyngier
2024-02-05 16:38 ` Oliver Upton
2024-01-04 16:27 ` [PATCH v4 3/7] arm64/sysreg/tools: Move TRFCR definitions to sysreg James Clark
2024-01-05 9:18 ` Suzuki K Poulose
2024-01-05 9:59 ` James Clark
2024-01-04 16:27 ` [PATCH v4 4/7] arm64: KVM: Add iflag for FEAT_TRF James Clark
2024-01-04 16:27 ` [PATCH v4 5/7] arm64: KVM: Add interface to set guest value for TRFCR register James Clark
2024-01-05 9:20 ` Suzuki K Poulose
2024-01-04 16:27 ` [PATCH v4 6/7] arm64: KVM: Write TRFCR value on guest switch with nVHE James Clark
2024-01-05 9:50 ` Suzuki K Poulose
2024-01-05 10:05 ` James Clark
2024-01-04 16:27 ` [PATCH v4 7/7] coresight: Pass guest TRFCR value to KVM James Clark
2024-01-05 9:55 ` Suzuki K Poulose [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50c5076f-fd7f-4b16-b2e2-f67e40394642@arm.com \
--to=suzuki.poulose@arm.com \
--cc=acme@kernel.org \
--cc=akihiko.odaki@daynix.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=anshuman.khandual@arm.com \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=coresight@lists.linaro.org \
--cc=james.clark@arm.com \
--cc=james.morse@arm.com \
--cc=jingzhangos@google.com \
--cc=jintack.lim@linaro.org \
--cc=joey.gouly@arm.com \
--cc=kristina.martsenko@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=leo.yan@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=miguel.luis@oracle.com \
--cc=mike.leach@linaro.org \
--cc=oliver.upton@linux.dev \
--cc=qperret@google.com \
--cc=robh@kernel.org \
--cc=tabba@google.com \
--cc=vdonnefort@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®