Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp41436rdb; Fri, 5 Jan 2024 01:56:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWbD2tp9/eZzCXy6gBSO1vJ3fessdcgDtoWLuOoCi2zp8uoFQ9v4YoqyvHj83vJgjARsYu X-Received: by 2002:a05:6a00:18a7:b0:6d9:af1f:a77 with SMTP id x39-20020a056a0018a700b006d9af1f0a77mr2102572pfh.63.1704448609475; Fri, 05 Jan 2024 01:56:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704448609; cv=none; d=google.com; s=arc-20160816; b=LHlmruLSLW/vCGF5ZVXNpmosSfldtQBQaHzta4jCiEk3dw7EqbP67iHSk1+zZkBvoc FQLH14V1kh+MICrx/z+/B7H1iOc+fiwpSqHE6gCxSo7ZfbxZyaP60oG9tOC6DypZ+cyb dihDCL43nz63rIWPMPOVjujABHxxwQXRguyYlEkr2NatfjYHFxfMyS7NR6QS7JVWmzsd Aaui+4PnAIEQmvTo+UmUs5g5/HLXnYJ9tWHDI5/IDFPBjbHMFMR8QMr+iQ1PiFwYo2e7 H+vCh9Ii8gBoJiv2r/YkRYOvqVSgkO5pf1Kbca2K47op+H4BBnxj9pHJnCw18FucW696 HOhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=iG74jRge0B0PUljRdo9tEKHijSftXQoTUSdssQ0IvdA=; fh=WP/YWSe5MGfQlHT2+oGNZlkYglHqkwSrIYUZyGCWtSk=; b=HCBtMEuWPHV4eDyd8LTIoPbXBJXOCKg8nS86fD3sgGE1oRMMq+wWUwsXVVFeuwlnTh 5Ke2YmjT5kdhFYbHR/0Q0cPp+lNBN1AMig8/4tnHfxTIQTXlHaRXwBYXYdYr368BgibN 7ZYzshNB1YIFiaGJvC4r+jkQglcEFYZgDy3VCF+YtMZDonX9dO1O9Ci2LBAVr8rTg611 GEtWyKus/0SjKZ2Rk6G8V0AucC3ggqPspdWd0AmbUSU+PhCnjv26rlAnyA5yeAc3H9U4 k4icWoxzBvutaiyw+soC7Jj2phjQPgUZLscaf0SJqFbLsk9llobsSc4od5GRy7rCNMHA m4ng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17697-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17697-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e17-20020a656bd1000000b005cdfd55d112si1059813pgw.655.2024.01.05.01.56.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 01:56:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17697-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17697-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17697-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C1A7CB21788 for ; Fri, 5 Jan 2024 09:55:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34E2D24B2A; Fri, 5 Jan 2024 09:55:47 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0FF8824A05 for ; Fri, 5 Jan 2024 09:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 735BDFEC; Fri, 5 Jan 2024 01:56:30 -0800 (PST) Received: from [10.57.44.155] (unknown [10.57.44.155]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 63C583F5A1; Fri, 5 Jan 2024 01:55:40 -0800 (PST) Message-ID: <50c5076f-fd7f-4b16-b2e2-f67e40394642@arm.com> Date: Fri, 5 Jan 2024 09:55:38 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 7/7] coresight: Pass guest TRFCR value to KVM Content-Language: en-GB To: James Clark , 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 , James Morse , Zenghui Yu , Catalin Marinas , Will Deacon , Mike Leach , Leo Yan , Alexander Shishkin , Anshuman Khandual , Rob Herring , Miguel Luis , Jintack Lim , Ard Biesheuvel , Mark Rutland , Arnd Bergmann , Quentin Perret , Vincent Donnefort , Fuad Tabba , Akihiko Odaki , Kristina Martsenko , Joey Gouly , Jing Zhang , linux-kernel@vger.kernel.org References: <20240104162714.1062610-1-james.clark@arm.com> <20240104162714.1062610-8-james.clark@arm.com> From: Suzuki K Poulose In-Reply-To: <20240104162714.1062610-8-james.clark@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 Reviewed-by: Suzuki K Poulose > --- > .../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 > #include > #include > +#include > #include > #include > #include > @@ -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;