Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp52536rdb; Thu, 16 Nov 2023 11:37:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUksc/AlrEJLlB2vZJHKiDl8DggBhqFDutE+oaD9nTSozX3mGZB+7mJLhN6+xUrD6B6zJm X-Received: by 2002:a05:6830:1bf8:b0:6be:e447:dbd with SMTP id k24-20020a0568301bf800b006bee4470dbdmr9603342otb.22.1700163469544; Thu, 16 Nov 2023 11:37:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700163469; cv=none; d=google.com; s=arc-20160816; b=ap9ENP94JgnGWiuzo8JNNpwgbnW5LC7ORYA395yWFNIY4dEYOqU9ALWI2tSlUXMNOm NhiIzBD/pTu4LlpHSBDy20Y53Gi9dCijzpYx6aaUB/lrtZIBC8wk9WRVJnU2gd1JNlpQ ZOh6jvyrl2jgFNd+76Lrym1oH5yyVFAmqyEg4lqeBk8OMHoHn4QEfC+WUxcS3yF4A+O+ Zm9fNNZfR8A0GjMEEH7Qgfh0tDag741vV+nbgdPexG2oc4FvYXDBxqh2UbKVweDT4szW wplA51MC4x565NPy5e99DIfvXy7jLuGc0wPhB+Xdea9Ok95CyfwLm8IwdpGV+MPx/fpe whzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=+VrTqQ8oUE/ufc0vm/4T3fj9VCH8YlaXcP+g5svMz5g=; fh=wMSdQ+XO39y8hqo/yTgyAxyrNs/i9YNXrjlTAhM6rNw=; b=avxHw1EKRNdFKo+86nYB5OuzJoUicY/1jBI8JZhtYL55D5hL/8Z9wEulAW21802P9Y HaonXp4lyHLjglU7p/TAlvc44is68HM6E3y/KE0wKUD+2X7D/K2ot39AMxu6WGdvjhb6 p1MsqELkE8tlP83UxIY6Tqj7pRffVYjB2n1LNTOjsvzb6mK6WyC1jhTxjHge0prsNleZ YhD09r8lG5BN7tpcD7F1jspwaWnJ6wby0SunyF0iX5TEeeXrn3UqwwnzBdco+Hnm2jk+ legnHD3UcwqIoxVuCW7Miv3OoYxwpKDv4/RATlREf8871C6AL8xwZy2mg1nY2dzx8+1O NK3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id y5-20020a633205000000b005bdbda280c2si127164pgy.364.2023.11.16.11.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 11:37:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 7C88E825F1CF; Thu, 16 Nov 2023 11:37:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345524AbjKPThf (ORCPT + 99 others); Thu, 16 Nov 2023 14:37:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232932AbjKPThe (ORCPT ); Thu, 16 Nov 2023 14:37:34 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E94BDD68 for ; Thu, 16 Nov 2023 11:37:29 -0800 (PST) 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 CAA221595; Thu, 16 Nov 2023 11:38:15 -0800 (PST) Received: from [10.57.84.40] (unknown [10.57.84.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C60303F6C4; Thu, 16 Nov 2023 11:37:26 -0800 (PST) Message-ID: Date: Thu, 16 Nov 2023 19:37:25 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 6/6] 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, maz@kernel.org Cc: broonie@kernel.org, Oliver Upton , James Morse , Zenghui Yu , Catalin Marinas , Will Deacon , Mike Leach , Leo Yan , Alexander Shishkin , Anshuman Khandual , Rob Herring , Jintack Lim , Fuad Tabba , Kristina Martsenko , Akihiko Odaki , Joey Gouly , linux-kernel@vger.kernel.org References: <20231019165510.1966367-1-james.clark@arm.com> <20231019165510.1966367-7-james.clark@arm.com> From: Suzuki K Poulose In-Reply-To: <20231019165510.1966367-7-james.clark@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 16 Nov 2023 11:37:46 -0800 (PST) On 19/10/2023 17:55, 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 > --- > .../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 77b0271ce6eb..292f9da6aeaf 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; Here we are using the Guest "Virtual time" for the trace, which could be different from that of the "host" (if the trace covers both). Thus correlating the trace could be difficult if someone wants to do that. We could switch to using Physical time, for the guest trace always, matching the host time for correlating the events. (Assuming we are not a Guest Hypervisor). Rest looks fine to me. > + 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) > + nit: Some day, we should move to using the "event->attrs" directly, than translating them to these values. Suzuki