From patchwork Mon Dec 13 12:13:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12695890 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8FCEBC433EF for ; Mon, 13 Dec 2021 12:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mUz8V9jWUXSk5JAzysQq9OuGu01h0/KPZbFxmmcZPws=; b=3khzAjAz947olE s83f4BmHDp504LI6Jt87/dUYUAZJutEaQv6QBaOeGC32a4dMg9aUDidrjr6cTTpB/2heI6p2hQHIP r78NaibCpdiDLIX8fE2dSRkw7t2mGeLMEU6oSK+AjuBE00+39HQaNikaePCYCl0ENt+V8EmO53/4t fhTnKowo+2nGNQkuhhru7ZU38bwjEowM4vwPhdGDbM/KM+4EyIT8zLBPvQxef/a6P2whSHaY+UrVI E7JBFJ6kapjjmrTeyv6s8Imm+yhGivATU8LZNJRBEerKtaiNQ/6aZYUuvlLz4gk7qDFBr99ZSn3Ra a8DtMs/6eWvNRbx5Byyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwkDq-009R00-NH; Mon, 13 Dec 2021 12:14:27 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwkDN-009QsJ-H4 for linux-arm-kernel@lists.infradead.org; Mon, 13 Dec 2021 12:13:59 +0000 Received: by mail-ed1-x52c.google.com with SMTP id w1so51185051edc.6 for ; Mon, 13 Dec 2021 04:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TSGFEEK57vZgNj+GJPFHPovuhunjSnX1LTdz3s3nsLA=; b=ShuKM7QtQJfbrrEovXJ4uS7mOzRqEUFSdQ7aM7lCo9LkxPZQjIqDKwIOo63kafeBvr kQJ+oQFG5qNVMyIRLMlNyZemMrQLCii6MG1ibBiv0x0SYygmdX8N0wtLNT5vdBrtgtpy 9oorT95681UBLuDX36Qt/2ANtKnW2EdXzvszsioSG4OxP4IDPWdMDEKTGzgHcNBeaiVB 9uQyopAHfJE+K8ZO9iLOSUWVZU8KnpYUfVUqwLNJGzfo6TtosWDMuWLXsJV93JW0qm+X A+rqqF9WSaaMuXyQYmO4M7Q2KIr2tcPUrwqV6jmCRinZtAHaOihmNFs+Rm3VyLT4/J9/ qnZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TSGFEEK57vZgNj+GJPFHPovuhunjSnX1LTdz3s3nsLA=; b=ZIZjd2+0KjifUmO2qpRe6e2L2Pdaj+8LirIIEvF5ou+woqFQooRI+CXTjiwwqiy+xX SgteGP+W/aoehJ+WiXhJMNDm9YJBp/3yy4e+N5k40TXYzWVCD8Gy+Wza5pqFINK0f0I/ p7uu+f7UQ5FEI0tiKSA360oF8PnXjnplpHrR3LcbZ3J0zzLrtYOZozqr6qbfwWUC2jrz q/stRLMwSmiyQrpCkv/QZwNPCV9XoHejYqe2MLsbRKuuV9bOMGSAVcCwj7ULAk9d5f+H p+tTtS9ugGi6vuczWfBtULoNDIrEszRJpk7WcWbiIFN2l/4QkhAyHj0xeBymZjrI+9wZ vkng== X-Gm-Message-State: AOAM533KxIEo7BALDZfEJw+MuMwex9U2e2qnEd0kFUHJeAA7xHMH2SFa vvIx7hCcHtYASqABmNE0vyLwfQ== X-Google-Smtp-Source: ABdhPJy6QhigKx/sG6cyezTv+KNVxOCZGCewaO1EOL4bzSW8lGQxoFkpqUmBkvpQwCmQisQsh4GUKQ== X-Received: by 2002:a17:906:c109:: with SMTP id do9mr43177666ejc.48.1639397635903; Mon, 13 Dec 2021 04:13:55 -0800 (PST) Received: from localhost ([104.245.96.202]) by smtp.gmail.com with ESMTPSA id bd12sm6247430edb.11.2021.12.13.04.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 04:13:55 -0800 (PST) From: Leo Yan To: Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v2 3/4] coresight: etm4x: Don't trace PID for non-root PID namespace Date: Mon, 13 Dec 2021 20:13:22 +0800 Message-Id: <20211213121323.1887180-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211213121323.1887180-1-leo.yan@linaro.org> References: <20211213121323.1887180-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211213_041357_595377_65FFC7CF X-CRM114-Status: GOOD ( 14.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When runs in perf mode, the driver always enables the PID tracing. This can lead confusion when the profiling session runs in non-root PID namespace, whereas it records the PIDs from the root PID namespace. To avoid confusion for PID tracing, when runs in perf mode, this patch changes to only enable PID tracing for root PID namespace. As result, after apply this patch, the perf tool reports PID as '-1' for all samples: # unshare --fork --pid perf record -e cs_etm// -m 64K,64K -a \ -o perf_test.data -- uname # perf report -i perf_test.data --itrace=Zi1000i --stdio # Total Lost Samples: 0 # # Samples: 94 of event 'instructions' # Event count (approx.): 94000 # # Overhead Command Shared Object Symbol # ........ ....... ................. .............................. # 68.09% :-1 [kernel.kallsyms] [k] __sched_text_end 3.19% :-1 [kernel.kallsyms] [k] hrtimer_interrupt 2.13% :-1 [kernel.kallsyms] [k] __bitmap_and 2.13% :-1 [kernel.kallsyms] [k] trace_vbprintk 1.06% :-1 [kernel.kallsyms] [k] __fget_files 1.06% :-1 [kernel.kallsyms] [k] __schedule 1.06% :-1 [kernel.kallsyms] [k] __softirqentry_text_start 1.06% :-1 [kernel.kallsyms] [k] __update_load_avg_cfs_rq 1.06% :-1 [kernel.kallsyms] [k] __update_load_avg_se 1.06% :-1 [kernel.kallsyms] [k] arch_counter_get_cntpct 1.06% :-1 [kernel.kallsyms] [k] check_and_switch_context 1.06% :-1 [kernel.kallsyms] [k] format_decode 1.06% :-1 [kernel.kallsyms] [k] handle_percpu_devid_irq 1.06% :-1 [kernel.kallsyms] [k] irq_enter_rcu 1.06% :-1 [kernel.kallsyms] [k] irqtime_account_irq 1.06% :-1 [kernel.kallsyms] [k] ktime_get 1.06% :-1 [kernel.kallsyms] [k] ktime_get_coarse_real_ts64 1.06% :-1 [kernel.kallsyms] [k] memmove 1.06% :-1 [kernel.kallsyms] [k] perf_ioctl 1.06% :-1 [kernel.kallsyms] [k] perf_output_begin 1.06% :-1 [kernel.kallsyms] [k] perf_output_copy 1.06% :-1 [kernel.kallsyms] [k] profile_tick 1.06% :-1 [kernel.kallsyms] [k] sched_clock 1.06% :-1 [kernel.kallsyms] [k] timerqueue_add 1.06% :-1 [kernel.kallsyms] [k] trace_save_cmdline 1.06% :-1 [kernel.kallsyms] [k] update_load_avg 1.06% :-1 [kernel.kallsyms] [k] vbin_printf Signed-off-by: Leo Yan Reported-by: kernel test robot --- drivers/hwtracing/coresight/coresight-etm4x-core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index 86a313857b58..f3eda536267c 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -656,7 +656,9 @@ static int etm4_parse_event_config(struct coresight_device *csdev, config->cfg |= BIT(11); } - if (attr->config & BIT(ETM_OPT_CTXTID)) + /* Only trace contextID when runs in root PID namespace */ + if ((attr->config & BIT(ETM_OPT_CTXTID)) && + task_is_in_init_pid_ns(current)) /* bit[6], Context ID tracing bit */ config->cfg |= BIT(ETM4_CFG_BIT_CTXTID); @@ -670,7 +672,11 @@ static int etm4_parse_event_config(struct coresight_device *csdev, ret = -EINVAL; goto out; } - config->cfg |= BIT(ETM4_CFG_BIT_VMID) | BIT(ETM4_CFG_BIT_VMID_OPT); + + /* Only trace virtual contextID when runs in root PID namespace */ + if (task_is_in_init_pid_ns(current)) + config->cfg |= BIT(ETM4_CFG_BIT_VMID) | + BIT(ETM4_CFG_BIT_VMID_OPT); } /* return stack - enable if selected and supported */