From patchwork Sun Oct 31 14:42:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12595169 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 3B777C433EF for ; Sun, 31 Oct 2021 14:44:27 +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 05F7860E9B for ; Sun, 31 Oct 2021 14:44:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 05F7860E9B 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: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=nBjwgO1wRAN508fp687dN92ajoSHsVgtk0nMyB4YsiU=; b=K8ghUCqYMZQLA9 aH8g1OwDEyqvhVFPrjvXIK9wAwh+WvnGki4hR3fu7WDCnEFa/mIDv6sAAjv6IEA5HtBbOiX1vU08F d0bR2gZBC237ES1/Lv8wGX3onkEEcACtz24vYuAnMXJmOzira8gHkUETMEXmejAeoBa4u7gXXS0xp InD0e53GewlmmIIaIFJawdf75dRFkeHeM7L6IBXCy+6EJqoyY5KiDEi6CFzYtZkJ84b6SwdZm4l2o l6AMaxMmVKfUHfeQkpmUXSg/fGbU1Fri98WkXEL/VOvlT7cCVn7ZkltNYz8TWnxxXXzJ7zCJbG4UP +wOYvqD8nbqHqILCAP4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhC3F-00ECYK-8d; Sun, 31 Oct 2021 14:43:13 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhC2m-00ECTR-BC for linux-arm-kernel@lists.infradead.org; Sun, 31 Oct 2021 14:42:45 +0000 Received: by mail-pf1-x436.google.com with SMTP id m14so13960908pfc.9 for ; Sun, 31 Oct 2021 07:42:43 -0700 (PDT) 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=VuCaajuKPFmTiIUEF7c2E0sdpfzEPoBt97lGeDDdtio=; b=IHXRiKyL1xCYSqfH34x9ox8qwe+3Pmxtc1hOLOThYNEnfO9quSYULaXhRsUeczp77J JmytcFtp8j21vZP7efbz3tbI/Kcv5RQ96v3hgP4ts/MQbOS+2hUgOmqD4+Vvzs38wzBZ xMaveS0YsceHzLlWTd5y8+k3Q/sS8V3iwXVjcudK5xsRU+l5GzDss8lIDJJtWfhKKWQ+ KxtZAw7XPWJXFUlkrHbOFewfOUssO/wZWqtKbtIcJEU3I4b2OTGShRiwuZT8oXMM8E0S TLgTz/U+h0GOki5FreB0D3dxtY70zPuQIzi2c++WSd+XUNYtF2WA97QLkVbKG15KuysC ABNQ== 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=VuCaajuKPFmTiIUEF7c2E0sdpfzEPoBt97lGeDDdtio=; b=fCkrzyeiD4Q3GMgLm4g5qk6KrDBwjW9aYrAuwqSC+ytJ38Nq1UKAtQUpP2ZpagNGE/ VVZXH2DyhVh9aOXsO5dTCPVYp4/6ZGhVShvj8I04Dshmx10tVbBN2uCBQrIZvKlPrr8G 2MlSOLerr/rAEVZ7rMUSvhqu+tc3R8SvOCNkUactRGkOg7l5dnZsuDGPe87N+kAk4w9P dNpGDm1QhKqlykaPXqBppLse4WmhyQA4XUO4fWruvbGwGaDInLPReMQXb7RgyThzfyNe HCaCq8o2nqfvBwG3b4VIhIXNnLolKTpI7jCT2UKhDUBgmRna2KpOGV0gHP4OvSlpQbom vY5A== X-Gm-Message-State: AOAM533b2xTgNv85zmDxoynsVEeHMmUnjeeegz28uI6XnG1w5XWOxOH/ 8o3RYVwx9NiKY++bLSZLr7pvpw== X-Google-Smtp-Source: ABdhPJzIsBGgktY1Uw2RqUWoMU33KsH/0a59nrOxFpzoAxXE7fbKTYrX7NXJlim1x/psRc1X6tTChA== X-Received: by 2002:a65:44c4:: with SMTP id g4mr17804689pgs.254.1635691363442; Sun, 31 Oct 2021 07:42:43 -0700 (PDT) Received: from localhost ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id w12sm16094817pjq.2.2021.10.31.07.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 07:42:43 -0700 (PDT) From: Leo Yan To: Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , James Clark , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 3/4] coresight: etm4x: Don't trace contextID for non-root namespace in perf mode Date: Sun, 31 Oct 2021 22:42:13 +0800 Message-Id: <20211031144214.237879-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211031144214.237879-1-leo.yan@linaro.org> References: <20211031144214.237879-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-20211031_074244_410102_DD2B72B3 X-CRM114-Status: GOOD ( 14.42 ) 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 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. 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); @@ -629,7 +631,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_active_pid_ns(current) == &init_pid_ns) + config->cfg |= BIT(ETM4_CFG_BIT_VMID) | + BIT(ETM4_CFG_BIT_VMID_OPT); } /* return stack - enable if selected and supported */