diff mbox series

[v2,4/4] coresight: etm3x: Don't trace PID for non-root PID namespace

Message ID 20211213121323.1887180-5-leo.yan@linaro.org (mailing list archive)
State New, archived
Headers show
Series coresight: etm: Correct PID tracing for non-root namespace | expand

Commit Message

Leo Yan Dec. 13, 2021, 12:13 p.m. UTC
ETMv3 driver enables PID tracing by directly using perf config from
userspace, this means the tracer will capture PID packets from root
namespace but the profiling session runs in non-root PID namespace.
Finally, the recorded packets can mislead perf reporting with the
mismatched PID values.

This patch changes to only enable PID tracing for root PID namespace.
Note, the hardware supports VMID tracing from ETMv3.5, but the driver
never enables VMID trace, this patch doesn't handle VMID trace (bit 30
in ETMCR register) particularly.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 drivers/hwtracing/coresight/coresight-etm3x-core.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

kernel test robot Dec. 13, 2021, 7:16 p.m. UTC | #1
Hi Leo,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.16-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Leo-Yan/coresight-etm-Correct-PID-tracing-for-non-root-namespace/20211213-201632
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2585cf9dfaaddf00b069673f27bb3f8530e2039c
config: arm-buildonly-randconfig-r003-20211213 (https://download.01.org/0day-ci/archive/20211214/202112140344.viPmOWp6-lkp@intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project b6a2ddb6c8ac29412b1361810972e15221fa021c)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/0day-ci/linux/commit/81d5f47788c40d34c8159d64d4505eb485254e8f
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Leo-Yan/coresight-etm-Correct-PID-tracing-for-non-root-namespace/20211213-201632
        git checkout 81d5f47788c40d34c8159d64d4505eb485254e8f
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/hwtracing/coresight/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/hwtracing/coresight/coresight-etm3x-core.c:344:7: error: implicit declaration of function 'task_is_in_init_pid_ns' [-Werror,-Wimplicit-function-declaration]
           if (!task_is_in_init_pid_ns(current))
                ^
   1 error generated.


vim +/task_is_in_init_pid_ns +344 drivers/hwtracing/coresight/coresight-etm3x-core.c

   301	
   302	#define ETM3X_SUPPORTED_OPTIONS (ETMCR_CYC_ACC | \
   303					 ETMCR_TIMESTAMP_EN | \
   304					 ETMCR_RETURN_STACK)
   305	
   306	static int etm_parse_event_config(struct etm_drvdata *drvdata,
   307					  struct perf_event *event)
   308	{
   309		struct etm_config *config = &drvdata->config;
   310		struct perf_event_attr *attr = &event->attr;
   311	
   312		if (!attr)
   313			return -EINVAL;
   314	
   315		/* Clear configuration from previous run */
   316		memset(config, 0, sizeof(struct etm_config));
   317	
   318		if (attr->exclude_kernel)
   319			config->mode = ETM_MODE_EXCL_KERN;
   320	
   321		if (attr->exclude_user)
   322			config->mode = ETM_MODE_EXCL_USER;
   323	
   324		/* Always start from the default config */
   325		etm_set_default(config);
   326	
   327		/*
   328		 * By default the tracers are configured to trace the whole address
   329		 * range.  Narrow the field only if requested by user space.
   330		 */
   331		if (config->mode)
   332			etm_config_trace_mode(config);
   333	
   334		/*
   335		 * At this time only cycle accurate, return stack  and timestamp
   336		 * options are available.
   337		 */
   338		if (attr->config & ~ETM3X_SUPPORTED_OPTIONS)
   339			return -EINVAL;
   340	
   341		config->ctrl = attr->config;
   342	
   343		/* Don't trace contextID when runs in non-root PID namespace */
 > 344		if (!task_is_in_init_pid_ns(current))
   345			config->ctrl &= ~ETMCR_CTXID_SIZE;
   346	
   347		/*
   348		 * Possible to have cores with PTM (supports ret stack) and ETM
   349		 * (never has ret stack) on the same SoC. So if we have a request
   350		 * for return stack that can't be honoured on this core then
   351		 * clear the bit - trace will still continue normally
   352		 */
   353		if ((config->ctrl & ETMCR_RETURN_STACK) &&
   354		    !(drvdata->etmccer & ETMCCER_RETSTACK))
   355			config->ctrl &= ~ETMCR_RETURN_STACK;
   356	
   357		return 0;
   358	}
   359	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Leo Yan Dec. 14, 2021, 4:46 a.m. UTC | #2
Hi,

On Tue, Dec 14, 2021 at 03:16:42AM +0800, kernel test robot wrote:
> Hi Leo,
> 
> I love your patch! Yet something to improve:
> 
> [auto build test ERROR on linus/master]
> [also build test ERROR on v5.16-rc5]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/0day-ci/linux/commits/Leo-Yan/coresight-etm-Correct-PID-tracing-for-non-root-namespace/20211213-201632
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2585cf9dfaaddf00b069673f27bb3f8530e2039c
> config: arm-buildonly-randconfig-r003-20211213 (https://download.01.org/0day-ci/archive/20211214/202112140344.viPmOWp6-lkp@intel.com/config)
> compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project b6a2ddb6c8ac29412b1361810972e15221fa021c)
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # install arm cross compiling tool for clang build
>         # apt-get install binutils-arm-linux-gnueabi
>         # https://github.com/0day-ci/linux/commit/81d5f47788c40d34c8159d64d4505eb485254e8f
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Leo-Yan/coresight-etm-Correct-PID-tracing-for-non-root-namespace/20211213-201632
>         git checkout 81d5f47788c40d34c8159d64d4505eb485254e8f
>         # save the config file to linux build tree
>         mkdir build_dir
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/hwtracing/coresight/
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
> >> drivers/hwtracing/coresight/coresight-etm3x-core.c:344:7: error: implicit declaration of function 'task_is_in_init_pid_ns' [-Werror,-Wimplicit-function-declaration]
>            if (!task_is_in_init_pid_ns(current))
>                 ^
>    1 error generated.
> 
> 
> vim +/task_is_in_init_pid_ns +344 drivers/hwtracing/coresight/coresight-etm3x-core.c
> 
>    301	
>    302	#define ETM3X_SUPPORTED_OPTIONS (ETMCR_CYC_ACC | \
>    303					 ETMCR_TIMESTAMP_EN | \
>    304					 ETMCR_RETURN_STACK)
>    305	
>    306	static int etm_parse_event_config(struct etm_drvdata *drvdata,
>    307					  struct perf_event *event)
>    308	{
>    309		struct etm_config *config = &drvdata->config;
>    310		struct perf_event_attr *attr = &event->attr;
>    311	
>    312		if (!attr)
>    313			return -EINVAL;
>    314	
>    315		/* Clear configuration from previous run */
>    316		memset(config, 0, sizeof(struct etm_config));
>    317	
>    318		if (attr->exclude_kernel)
>    319			config->mode = ETM_MODE_EXCL_KERN;
>    320	
>    321		if (attr->exclude_user)
>    322			config->mode = ETM_MODE_EXCL_USER;
>    323	
>    324		/* Always start from the default config */
>    325		etm_set_default(config);
>    326	
>    327		/*
>    328		 * By default the tracers are configured to trace the whole address
>    329		 * range.  Narrow the field only if requested by user space.
>    330		 */
>    331		if (config->mode)
>    332			etm_config_trace_mode(config);
>    333	
>    334		/*
>    335		 * At this time only cycle accurate, return stack  and timestamp
>    336		 * options are available.
>    337		 */
>    338		if (attr->config & ~ETM3X_SUPPORTED_OPTIONS)
>    339			return -EINVAL;
>    340	
>    341		config->ctrl = attr->config;
>    342	
>    343		/* Don't trace contextID when runs in non-root PID namespace */
>  > 344		if (!task_is_in_init_pid_ns(current))

This patchset is based on another patchset [1], as described on the
cover letter patch.  This is why here reports for building failure.

To avoid the false positive reporting, if any better practice I can
follow up to resolve the dependency between two patchsets, please let
me know and I will do in next time.

Thanks,
Leo

[1] https://lore.kernel.org/lkml/20211208083320.472503-1-leo.yan@linaro.org/

>    345			config->ctrl &= ~ETMCR_CTXID_SIZE;
>    346	
>    347		/*
>    348		 * Possible to have cores with PTM (supports ret stack) and ETM
>    349		 * (never has ret stack) on the same SoC. So if we have a request
>    350		 * for return stack that can't be honoured on this core then
>    351		 * clear the bit - trace will still continue normally
>    352		 */
>    353		if ((config->ctrl & ETMCR_RETURN_STACK) &&
>    354		    !(drvdata->etmccer & ETMCCER_RETSTACK))
>    355			config->ctrl &= ~ETMCR_RETURN_STACK;
>    356	
>    357		return 0;
>    358	}
>    359	
> 
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Chen, Rong A Dec. 16, 2021, 8:54 a.m. UTC | #3
On 12/14/21 12:46, Leo Yan wrote:
> Hi,
>
> On Tue, Dec 14, 2021 at 03:16:42AM +0800, kernel test robot wrote:
>> Hi Leo,
>>
>> I love your patch! Yet something to improve:
>>
>> [auto build test ERROR on linus/master]
>> [also build test ERROR on v5.16-rc5]
>> [If your patch is applied to the wrong git tree, kindly drop us a note.
>> And when submitting patch, we suggest to use '--base' as documented in
>> https://git-scm.com/docs/git-format-patch]
>>
>> url:    https://github.com/0day-ci/linux/commits/Leo-Yan/coresight-etm-Correct-PID-tracing-for-non-root-namespace/20211213-201632
>> base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2585cf9dfaaddf00b069673f27bb3f8530e2039c
>> config: arm-buildonly-randconfig-r003-20211213 (https://download.01.org/0day-ci/archive/20211214/202112140344.viPmOWp6-lkp@intel.com/config)
>> compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project b6a2ddb6c8ac29412b1361810972e15221fa021c)
>> reproduce (this is a W=1 build):
>>          wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>>          chmod +x ~/bin/make.cross
>>          # install arm cross compiling tool for clang build
>>          # apt-get install binutils-arm-linux-gnueabi
>>          # https://github.com/0day-ci/linux/commit/81d5f47788c40d34c8159d64d4505eb485254e8f
>>          git remote add linux-review https://github.com/0day-ci/linux
>>          git fetch --no-tags linux-review Leo-Yan/coresight-etm-Correct-PID-tracing-for-non-root-namespace/20211213-201632
>>          git checkout 81d5f47788c40d34c8159d64d4505eb485254e8f
>>          # save the config file to linux build tree
>>          mkdir build_dir
>>          COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/hwtracing/coresight/
>>
>> If you fix the issue, kindly add following tag as appropriate
>> Reported-by: kernel test robot <lkp@intel.com>
>>
>> All errors (new ones prefixed by >>):
>>
>>>> drivers/hwtracing/coresight/coresight-etm3x-core.c:344:7: error: implicit declaration of function 'task_is_in_init_pid_ns' [-Werror,-Wimplicit-function-declaration]
>>             if (!task_is_in_init_pid_ns(current))
>>                  ^
>>     1 error generated.
>>
>>
>> vim +/task_is_in_init_pid_ns +344 drivers/hwtracing/coresight/coresight-etm3x-core.c
>>
>>     301	
>>     302	#define ETM3X_SUPPORTED_OPTIONS (ETMCR_CYC_ACC | \
>>     303					 ETMCR_TIMESTAMP_EN | \
>>     304					 ETMCR_RETURN_STACK)
>>     305	
>>     306	static int etm_parse_event_config(struct etm_drvdata *drvdata,
>>     307					  struct perf_event *event)
>>     308	{
>>     309		struct etm_config *config = &drvdata->config;
>>     310		struct perf_event_attr *attr = &event->attr;
>>     311	
>>     312		if (!attr)
>>     313			return -EINVAL;
>>     314	
>>     315		/* Clear configuration from previous run */
>>     316		memset(config, 0, sizeof(struct etm_config));
>>     317	
>>     318		if (attr->exclude_kernel)
>>     319			config->mode = ETM_MODE_EXCL_KERN;
>>     320	
>>     321		if (attr->exclude_user)
>>     322			config->mode = ETM_MODE_EXCL_USER;
>>     323	
>>     324		/* Always start from the default config */
>>     325		etm_set_default(config);
>>     326	
>>     327		/*
>>     328		 * By default the tracers are configured to trace the whole address
>>     329		 * range.  Narrow the field only if requested by user space.
>>     330		 */
>>     331		if (config->mode)
>>     332			etm_config_trace_mode(config);
>>     333	
>>     334		/*
>>     335		 * At this time only cycle accurate, return stack  and timestamp
>>     336		 * options are available.
>>     337		 */
>>     338		if (attr->config & ~ETM3X_SUPPORTED_OPTIONS)
>>     339			return -EINVAL;
>>     340	
>>     341		config->ctrl = attr->config;
>>     342	
>>     343		/* Don't trace contextID when runs in non-root PID namespace */
>>   > 344		if (!task_is_in_init_pid_ns(current))
> This patchset is based on another patchset [1], as described on the
> cover letter patch.  This is why here reports for building failure.
>
> To avoid the false positive reporting, if any better practice I can
> follow up to resolve the dependency between two patchsets, please let
> me know and I will do in next time.

Hi Leo,

Sorry for the inconvenience, the bot doesn't support to parse the link 
in cover letter yet,
we suggest to use '--base' as documented 
inhttps://git-scm.com/docs/git-format-patch

Best Regards,
Rong CHen

>
> Thanks,
> Leo
>
> [1] https://lore.kernel.org/lkml/20211208083320.472503-1-leo.yan@linaro.org/
>
>>     345			config->ctrl &= ~ETMCR_CTXID_SIZE;
>>     346	
>>     347		/*
>>     348		 * Possible to have cores with PTM (supports ret stack) and ETM
>>     349		 * (never has ret stack) on the same SoC. So if we have a request
>>     350		 * for return stack that can't be honoured on this core then
>>     351		 * clear the bit - trace will still continue normally
>>     352		 */
>>     353		if ((config->ctrl & ETMCR_RETURN_STACK) &&
>>     354		    !(drvdata->etmccer & ETMCCER_RETSTACK))
>>     355			config->ctrl &= ~ETMCR_RETURN_STACK;
>>     356	
>>     357		return 0;
>>     358	}
>>     359	
>>
>> ---
>> 0-DAY CI Kernel Test Service, Intel Corporation
>> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/coresight-etm3x-core.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c
index cf64ce73a741..7d413ba8b823 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x-core.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
@@ -340,6 +340,10 @@  static int etm_parse_event_config(struct etm_drvdata *drvdata,
 
 	config->ctrl = attr->config;
 
+	/* Don't trace contextID when runs in non-root PID namespace */
+	if (!task_is_in_init_pid_ns(current))
+		config->ctrl &= ~ETMCR_CTXID_SIZE;
+
 	/*
 	 * Possible to have cores with PTM (supports ret stack) and ETM
 	 * (never has ret stack) on the same SoC. So if we have a request