From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC08CC433F5 for ; Wed, 17 Nov 2021 13:55:26 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 931B561875 for ; Wed, 17 Nov 2021 13:55:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 931B561875 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9Y7gT7DwQq8JNz0MFgUu514OlEi9KCNkf1wst9Qq6HA=; b=Q7/dOvyAzcFoXq 7m7nKQQbILOEkXtnaTCcdiUFQ1WLJDyBc++zdu2b2T2hLl7AhQkqOaCnNmXUVMUA4PGQOfGIjeyJG oIhak/DYhKcI/Jrw/AaOYxMD1KGZWW5rbwxs+0JlQO/SUzId/zNVM72SKneU2R0RQalWYObfPFaRd Ns83hZOihkbnGV+8jYMNIeXWwqK5Opyl15uRhKE2UK5gIQhepBw54qyp1u5ho21Uz3bncwVfSjhM9 wmCZe6MSURmQI2FT7JqL3w/Yjtkwa1NItDYoGZdaom1/4uAzMNgx5yDamhUM9U4kt27ibaLEamlKy HLy8m1co/zcAA98cqh4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnLNy-004yXQ-2I; Wed, 17 Nov 2021 13:54:02 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnLNp-004yP3-Ju for linux-arm-kernel@lists.infradead.org; Wed, 17 Nov 2021 13:53:57 +0000 Received: by mail-pj1-x1032.google.com with SMTP id p18-20020a17090ad31200b001a78bb52876so5303606pju.3 for ; Wed, 17 Nov 2021 05:53:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=zC2INOq4i9mC2uFkAt9YGh74OyV1gw0rpUisyLgMs34=; b=Qwt9a+AM5PE7w3U3o4cmUHlnV8pNjIChykgzmlj1W7PznZlBFNdMK9Jir+PXEP2zGo AD6p/c4zYmZUXsZtORbDOXpcVoYMP4nJEU37GjDAhouiNkFQhckx+/4ZkWOASZT9IWCr yw1Ibn19kdzE6S77nACF7LvtvNbTR7iz+IqilNJ+hzY4twv0cFrlJqqIhClwdmkYtZKL 9vQ1tcPjrbDEv/nI+2encB/MuTjFcr37zzq90zTUpRKFPWaMOrNq0rHyXnmTBSkiFANA rLZnDBlbkJxa9TJXEARQF8+CPaw4Mcn1i18FrEdeBfTNfXCq4DzKG+9FQxPJjhgH1y39 23yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=zC2INOq4i9mC2uFkAt9YGh74OyV1gw0rpUisyLgMs34=; b=g1Pua//eNYCc2FhUAXZbUducBwb3x0EztoqSrihBGkblFRQ2dS+FKiDw0UVfhFwHXu M1Wz2U43mlhHRsqTB/LsWZOUXGxZ01w+RpngLykmk5iye6U+wJSnYXTyPgykr6+1RHQ6 8+JrxnsxjF9rG7Eqy81YHVm6LtvQTLCGocJl9/3QccHM8nAjSP/7tw1JpGLFEth9BVVi UiYBNvMmsuZTuMBapqDR/SmsfEZHAJslErISYDhsg0wuvaBw14/6pnVj/12sKE0Y/G5O 1DhutmFSNmBb0Ftpgn+80MrPBeOn+yB22vFeh/DhjNn1RIVRIAKR3hmky42bhEL3ooI6 ynpA== X-Gm-Message-State: AOAM533XdyhFQnqB5vGL7RIw//FB5i9Xq56CiZp27DV6jLqEYncIbpT6 ICjP3u7UoVy4lwV92NOhFW+dIw== X-Google-Smtp-Source: ABdhPJzhnh2R57kvUTiK2IrlWXaZNIeFr9wFhjrifJwHuJcYigaFdm2oW9QeGOlmT4jB1qeVKE3jwA== X-Received: by 2002:a17:902:7b82:b0:143:a6d6:34ab with SMTP id w2-20020a1709027b8200b00143a6d634abmr51709366pll.30.1637157231909; Wed, 17 Nov 2021 05:53:51 -0800 (PST) Received: from leoy-ThinkPad-X240s ([66.23.193.242]) by smtp.gmail.com with ESMTPSA id s7sm25155266pfu.139.2021.11.17.05.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 05:53:51 -0800 (PST) Date: Wed, 17 Nov 2021 21:53:43 +0800 From: Leo Yan To: Suzuki K Poulose Cc: Mathieu Poirier , Mike Leach , Alexander Shishkin , James Clark , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 3/4] coresight: etm4x: Don't trace contextID for non-root namespace in perf mode Message-ID: <20211117135343.GB4771@leoy-ThinkPad-X240s> References: <20211031144214.237879-1-leo.yan@linaro.org> <20211031144214.237879-4-leo.yan@linaro.org> <07dbd4ac-5847-96cf-eb3c-d24561bb052c@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <07dbd4ac-5847-96cf-eb3c-d24561bb052c@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211117_055353_742026_80B185B8 X-CRM114-Status: GOOD ( 29.70 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Suzuki, On Tue, Nov 16, 2021 at 09:46:20AM +0000, Suzuki Kuruppassery Poulose wrote: > Hi Leo, > > On 31/10/2021 14:42, Leo Yan wrote: > > When runs in perf mode, the driver always enables the contextID tracing. > > This can lead to confusion if the program runs in non-root PID namespace > > and potentially leak kernel information. > > > > When programs running in perf mode, this patch changes to only enable > > contextID tracing for root PID namespace. > > > > The only concern with the patch here is we silently ignore the CTXTID > flag and the perf assumes the CTXTID is traced, when traced from a non-root > namespace. Does the decoder handle this case gracefully ? We are > fine if that is the case. Good point. As far as I know, if CoreSight trace data doesn't contain context packets, tidq->tid is initialized as '0' and tidq->pid is '-1'. In this case, the decoder will fail to find thread context and the user space samples will not output anymore, see [1], cs_etm__mem_access() returns 0 when the thread pointer is NULL and the user space samples will be skipped. On the other hand, I observed an unexpected behaviour is the decoder also fails to output any kernel samples. From my understanding, the kernel samples should always be output, I will check furthermore for this (I can think one possibility is perf tool fails to find a 'correct' vmlinux when parsing symbols). [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/cs-etm.c#n720 > Either way, we don't want to enforce the policy in the perf tool, if we > can transparently handle the missing CTXTID and allow the trace session > and decode complete. That said, your approach is the safe bet here. Do you agree below assumption for tracing in non-root PID namespace? For non-root namespace we doesn't tracing PID, CoreSight trace data doesn't contain context packet, so the perf decoder cannot find the corresponding thread context and perf tool will not generate any samples for user mode. But the decoder should generate kernel samples. If you agree with this, in theory I think we should not change anything in perf tool (but let me confirm the decoder kernel samples can output properly). > > Signed-off-by: Leo Yan > > --- > > 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 e24252eaf8e4..6e614bfb38c6 100644 > > --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c > > +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c > > @@ -615,7 +615,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_active_pid_ns(current) == &init_pid_ns)) > > /* bit[6], Context ID tracing bit */ > > config->cfg |= BIT(ETM4_CFG_BIT_CTXTID); > > As mentioned in the previous comment, please add a helper here, than open > coding the check. Agreed, will add new helper for checking root namespace. Thanks for reviewing. Leo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel