Message ID | 0b165b2608eed1a61240539f4b812bd80b6ad1bd.1614624041.git.saiprakash.ranjan@codeaurora.org |
---|---|
State | New |
Headers | show |
Series | None | expand |
Hi, On Mon, Mar 1, 2021 at 11:05 AM Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org> wrote: > > 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 uses the newly > introduced kernel config CONFIG_EXCLUDE_KERNEL_PMU_TRACE 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. > > Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org> > --- > drivers/hwtracing/coresight/coresight-etm3x-core.c | 3 +++ > drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 6 ++++++ > 2 files changed, 9 insertions(+) Reviewed-by: Douglas Anderson <dianders@chromium.org> > diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c > index e8c7649f123e..f522fc2e01b3 100644 > --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c > +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c > @@ -116,6 +116,12 @@ static ssize_t mode_store(struct device *dev, > if (ret) > return ret; > > + if (IS_ENABLED(CONFIG_EXCLUDE_KERNEL_PMU_TRACE) && (!(val & ETM_MODE_EXCL_KERN))) { > + dev_warn(dev, > + "Kernel mode tracing is not allowed, check your kernel config\n"); Same nit as in patch #3 that the above string should be indented by 1 more space.
On 2021-03-02 04:13, Doug Anderson wrote: > Hi, > > On Mon, Mar 1, 2021 at 11:05 AM Sai Prakash Ranjan > <saiprakash.ranjan@codeaurora.org> wrote: >> >> 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 uses the newly >> introduced kernel config CONFIG_EXCLUDE_KERNEL_PMU_TRACE 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. >> >> Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org> >> --- >> drivers/hwtracing/coresight/coresight-etm3x-core.c | 3 +++ >> drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 6 ++++++ >> 2 files changed, 9 insertions(+) > > Reviewed-by: Douglas Anderson <dianders@chromium.org> > Thanks. > >> diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c >> b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c >> index e8c7649f123e..f522fc2e01b3 100644 >> --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c >> +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c >> @@ -116,6 +116,12 @@ static ssize_t mode_store(struct device *dev, >> if (ret) >> return ret; >> >> + if (IS_ENABLED(CONFIG_EXCLUDE_KERNEL_PMU_TRACE) && (!(val & >> ETM_MODE_EXCL_KERN))) { >> + dev_warn(dev, >> + "Kernel mode tracing is not allowed, check >> your kernel config\n"); > > Same nit as in patch #3 that the above string should be indented by 1 > more space. > Will fix this up as well in v3. Thanks, Sai
diff --git a/drivers/hwtracing/coresight/coresight-etm3x-core.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c index cf64ce73a741..d94f6b01ca09 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c @@ -195,6 +195,9 @@ void etm_set_default(struct etm_config *config) if (WARN_ON_ONCE(!config)) return; + if (IS_ENABLED(CONFIG_EXCLUDE_KERNEL_PMU_TRACE)) + config->mode |= ETM_MODE_EXCL_KERN; + /* * Taken verbatim from the TRM: * diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c index e8c7649f123e..f522fc2e01b3 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c @@ -116,6 +116,12 @@ static ssize_t mode_store(struct device *dev, if (ret) return ret; + if (IS_ENABLED(CONFIG_EXCLUDE_KERNEL_PMU_TRACE) && (!(val & ETM_MODE_EXCL_KERN))) { + dev_warn(dev, + "Kernel mode tracing is not allowed, check your kernel config\n"); + return -EACCES; + } + spin_lock(&drvdata->spinlock); config->mode = val & ETM_MODE_ALL;
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 uses the newly introduced kernel config CONFIG_EXCLUDE_KERNEL_PMU_TRACE 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. Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org> --- drivers/hwtracing/coresight/coresight-etm3x-core.c | 3 +++ drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 6 ++++++ 2 files changed, 9 insertions(+)