From: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
To: Mathieu Poirier <mathieu.poirier@linaro.org>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Mike Leach <mike.leach@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
Leo Yan <leo.yan@linaro.org>
Cc: coresight@lists.linaro.org, Stephen Boyd <swboyd@chromium.org>,
Denis Nikitin <denik@chromium.org>,
Mattias Nissler <mnissler@chromium.org>,
Al Grant <al.grant@arm.com>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
Subject: [PATCH 3/4] coresight: etm4x: Add support to exclude kernel mode tracing
Date: Sat, 30 Jan 2021 00:35:12 +0530 [thread overview]
Message-ID: <5d063d6035ff079b10e34cee110a26b856957ebe.1611909025.git.saiprakash.ranjan@codeaurora.org> (raw)
In-Reply-To: <cover.1611909025.git.saiprakash.ranjan@codeaurora.org>
On production systems with ETMs enabled, it is preferred to exclude
kernel mode(NS EL1) tracing for security concerns and support only
userspace(NS EL0) tracing. Perf subsystem interface for ETMs use
the newly introduced kernel config CONFIG_EXCLUDE_KERNEL_HW_ITRACE
to exclude kernel mode tracing, but there is an additional interface
via sysfs for ETMs which also needs to be handled to exclude kernel
mode tracing. So we use this same generic kernel config to handle
the sysfs mode of tracing. This config is disabled by default and
would not affect the current configuration which has both kernel and
userspace tracing enabled by default.
Tested-by: Denis Nikitin <denik@chromium.org>
Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
---
drivers/hwtracing/coresight/coresight-etm4x-core.c | 14 +++++++++++++-
.../hwtracing/coresight/coresight-etm4x-sysfs.c | 3 ++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
index b20b6ff17cf6..f94143057bb8 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -1052,12 +1052,16 @@ static void etm4_set_default(struct etmv4_config *config)
return;
/*
- * Make default initialisation trace everything
+ * Make default initialisation trace everything when
+ * CONFIG_EXCLUDE_KERNEL_HW_ITRACE is disabled.
*
* This is done by a minimum default config sufficient to enable
* full instruction trace - with a default filter for trace all
* achieved by having no filtering.
*/
+ if (IS_ENABLED(CONFIG_EXCLUDE_KERNEL_HW_ITRACE))
+ config->mode |= ETM_MODE_EXCL_KERN;
+
etm4_set_default_config(config);
etm4_set_default_filter(config);
}
@@ -1195,6 +1199,7 @@ static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
void etm4_config_trace_mode(struct etmv4_config *config)
{
u32 mode;
+ struct etmv4_drvdata *drvdata = container_of(config, struct etmv4_drvdata, config);
mode = config->mode;
mode &= (ETM_MODE_EXCL_KERN | ETM_MODE_EXCL_USER);
@@ -1202,6 +1207,13 @@ void etm4_config_trace_mode(struct etmv4_config *config)
/* excluding kernel AND user space doesn't make sense */
WARN_ON_ONCE(mode == (ETM_MODE_EXCL_KERN | ETM_MODE_EXCL_USER));
+ if (!(mode & ETM_MODE_EXCL_KERN) && IS_ENABLED(CONFIG_EXCLUDE_KERNEL_HW_ITRACE)) {
+ dev_err(&drvdata->csdev->dev,
+ "Kernel mode tracing is not allowed, check your kernel config\n");
+ config->mode |= ETM_MODE_EXCL_KERN;
+ return;
+ }
+
/* nothing to do if neither flags are set */
if (!(mode & ETM_MODE_EXCL_KERN) && !(mode & ETM_MODE_EXCL_USER))
return;
diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
index 989ce7b8ade7..f1d19d69d151 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
@@ -426,7 +426,8 @@ static ssize_t mode_store(struct device *dev,
else
config->vinst_ctrl &= ~BIT(11);
- if (config->mode & (ETM_MODE_EXCL_KERN | ETM_MODE_EXCL_USER))
+ if ((config->mode & (ETM_MODE_EXCL_KERN | ETM_MODE_EXCL_USER)) ||
+ IS_ENABLED(CONFIG_EXCLUDE_KERNEL_HW_ITRACE))
etm4_config_trace_mode(config);
spin_unlock(&drvdata->spinlock);
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
next prev parent reply other threads:[~2021-01-29 19:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-29 19:05 [PATCH 0/4] Add support to exclude kernel mode hardware assisted instruction tracing Sai Prakash Ranjan
2021-01-29 19:05 ` [PATCH 1/4] perf/core: Add support to exclude kernel mode " Sai Prakash Ranjan
2021-01-29 19:30 ` Peter Zijlstra
2021-02-01 7:41 ` Sai Prakash Ranjan
2021-02-01 13:41 ` Peter Zijlstra
2021-02-02 6:11 ` Sai Prakash Ranjan
2021-02-10 7:38 ` Sai Prakash Ranjan
2021-01-29 19:05 ` [PATCH 2/4] perf evsel: Print warning for excluding " Sai Prakash Ranjan
2021-01-29 19:05 ` Sai Prakash Ranjan [this message]
2021-02-22 20:14 ` [PATCH 3/4] coresight: etm4x: Add support to exclude kernel mode tracing Doug Anderson
2021-02-24 14:51 ` Sai Prakash Ranjan
2021-01-29 19:05 ` [PATCH 4/4] coresight: etm3x: " Sai Prakash Ranjan
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=5d063d6035ff079b10e34cee110a26b856957ebe.1611909025.git.saiprakash.ranjan@codeaurora.org \
--to=saiprakash.ranjan@codeaurora.org \
--cc=acme@kernel.org \
--cc=al.grant@arm.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=coresight@lists.linaro.org \
--cc=denik@chromium.org \
--cc=jolsa@redhat.com \
--cc=leo.yan@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.poirier@linaro.org \
--cc=mike.leach@linaro.org \
--cc=mingo@redhat.com \
--cc=mnissler@chromium.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=suzuki.poulose@arm.com \
--cc=swboyd@chromium.org \
/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®