From patchwork Sun Oct 31 14:42:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12595163 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 41FA0C433EF for ; Sun, 31 Oct 2021 14:44:14 +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 036DD60EB1 for ; Sun, 31 Oct 2021 14:44:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 036DD60EB1 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=oFqUFYi5MHkmGfdxvads0pbJDIcpxuoOQFvbZMqj/R0=; b=xNIglfFsfAHQE4 b3TjyY6NXSnuyHFKWfQQjp7I+RX5b+B5n/G56IRKcNlsl4pQL63y82TlGfVnet8Es90iyTZK1GC6c jzfkkfC94adhFgeHc7d0/DrSjCacZ4urVx1NF9+fBDpAMEtzwsFaJseA49pWfN92o4f/lRewYQcwU wCKGJF4acZs0L8v5oTKaqN3Sf3XZ4b/B1klRaqsDO2TspN9Nq/gbyln9t2OtZ0jSeczrh/qKDiegE z481NZxZes+na7ovsg7RK4XZxJJeJbG/Tyt8zQUeRQCrowJqTWImdE7wtlYdBMGeizZGeDNvsh+I4 NC0yScgjNmUUyvzCPkrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhC2t-00ECUF-SB; Sun, 31 Oct 2021 14:42:52 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhC2g-00ECSJ-Ei for linux-arm-kernel@lists.infradead.org; Sun, 31 Oct 2021 14:42:40 +0000 Received: by mail-pg1-x52d.google.com with SMTP id b4so7767117pgh.10 for ; Sun, 31 Oct 2021 07:42:38 -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=uwHc5y/wIScBvEn6bCWIFA7yggj/JltDtCr4bDo6Y0g=; b=kj7gPQXHAooXNx1kSa8Aa7p+r94I7QxhXdyu33lPC/Ro8QQl2PAjMBw6EJFwSc9ZDJ UROzJT9KG0j5IY6GZcyWSXaN5LVytPfmgdlnsStHdnz8bbqTy/IsSHvidD2dc8b+2xE/ FvFLdXF8oXCx+AadCWeMM1dx9Atzch4CDKiaYFjW9PZ8pYv22SeRsyT6FFxfliCuQpqV SYDEC0q7KfwCezat2WunuF3CBnUaz6Pgk/apx6yEZ1vfv/c9Qr4q4tP2AMCdlMqIze4i w6AMvLZmAqyJeti7Z6ni9BW/3uvhq1JazTmgg/xT796xY6r7aFK0nDb+rVKrx8whAIBB QMnQ== 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=uwHc5y/wIScBvEn6bCWIFA7yggj/JltDtCr4bDo6Y0g=; b=JqhXwbRwkKCl4RuNgeqnjHftsWd6s8p3P+ZeWULyGzx3UsX+VbAyooPjY1JfZm3tcU 59nk3QSesEQiYySpGfvZS2Oveo5pbSIuKToBaCHSWVePZ7z4aabFjJ7obh+AMYvjbowK PWzF4X0FQiGKnlEdbhkbgxQbZqQZGBiBInTmaxSQw+evIe+86+w6799tlgvhhYx4m20r qY1okw0R/GIDvuWx2Go3LCC0SrbTDQIBTS3bBbYmAM/RSND8x4lVTLkSJBbDfngsWdPT 8BhV3I+IUS08gryyizKCtmtTBMp+YQRzEsjDKvEVc7PUwzatZMrDf8yHuRsZF3I2YEFq dkyQ== X-Gm-Message-State: AOAM530FAIlYqPKQqGDc2FW93QXmfT4wJvWnMASUlYqASVg6s13eL72G MqLUGX3e2A3oiYR+1BgqUPe5NA== X-Google-Smtp-Source: ABdhPJwNPl2Jf3gP+mXfhnUBrTAL3ug8leeRXwOWQD5KRvFzBPQaQOP2zw7n1DP9rckK8qKD3qFG6A== X-Received: by 2002:a63:7506:: with SMTP id q6mr17315883pgc.349.1635691357679; Sun, 31 Oct 2021 07:42:37 -0700 (PDT) Received: from localhost ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id e14sm9323996pga.76.2021.10.31.07.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 07:42:37 -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 1/4] coresight: etm4x: Add lock for reading virtual context ID comparator Date: Sun, 31 Oct 2021 22:42:11 +0800 Message-Id: <20211031144214.237879-2-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_074238_675778_D89AA7B2 X-CRM114-Status: GOOD ( 11.39 ) 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 read the virtual context ID comparator value via sysfs node, the driver firstly reads out the index, then reads the comparator value based on index. This patch adds the spinlock to protect the atomicity for up two steps. Signed-off-by: Leo Yan Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c index a0640fa5c55b..e4c8c44d04ef 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -2111,7 +2111,9 @@ static ssize_t vmid_val_show(struct device *dev, struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etmv4_config *config = &drvdata->config; + spin_lock(&drvdata->spinlock); val = (unsigned long)config->vmid_val[config->vmid_idx]; + spin_unlock(&drvdata->spinlock); return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } From patchwork Sun Oct 31 14:42:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12595165 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 CDCC9C433F5 for ; Sun, 31 Oct 2021 14:44:14 +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 9BAB860F46 for ; Sun, 31 Oct 2021 14:44:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9BAB860F46 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=hWOyRr/mRTqaJ3KpxuDlmRGFgDvhLMlgJaIxh74j2Ac=; b=Ku9o0zudvLlkWw ccu1EgL+VDBBdKDFrtHqx/3CXp78EhjOXIHdJuyW0tGRY23Lm3RAJFcKj7nYULYC6MIKfNIYGfHZk N5AFHrUCq3FbHVQYEehL8zDMnTnNvL1lJ5jISbmZrTXKh7FO4R58eF6UaZAUuHjlWmYI5UPBumy+A MWBrqOTy7RWAiZeB9K0NPFJIbhCfCd6ukTPPdnVFznPe/m0xm+kj+5cKBFF8TSMarg89A/tgutziB PhrYFF0BI7nfa/XDsXbCaT0pGQ7mHonwSjQ47a2trTd7+sxrMnAoIBdKclogCtDdYC7RjGilJg04X TVpLjAm91t/cLNxSkSNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhC33-00ECVA-Tq; Sun, 31 Oct 2021 14:43:02 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhC2j-00ECSz-C9 for linux-arm-kernel@lists.infradead.org; Sun, 31 Oct 2021 14:42:42 +0000 Received: by mail-pj1-x102d.google.com with SMTP id o6-20020a17090a0a0600b001a64b9a11aeso3423817pjo.3 for ; Sun, 31 Oct 2021 07:42:41 -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=beclhWZk3zZOlcCh3M65MSbbbJkA4NCrMmRNtUJzgjw=; b=cPa3TvRtndC9F08ijkVxCIcA9hfQyiCNSmc+5tGVOEvSPq6DeO5449Oc6KSo4drY3W 2ji9igIaQ3yYPLSLsh7zyZks9JvsZ6+vDEh7pwYpF+syP6JFrUnAmTaFqA299xrBfCqQ 6ifE52tv6uUQQqoAisDng1ckQ4ZoAzKR+HgvTM5LDdWSrI9vgUjnEplU9ABQALT33R/E zDWrTgveSPBVFnT9buDbEjAJcmoKIzekEfdrjVvMsRpTZYGnuH+etosUGIPf3NcJJRnH zs5x1OAmDwtEaCpDx0zuokdgg97AWZzm9qGfaCfT70HwTP7XuTr/7+tJMKYlJprusiGa Dqkw== 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=beclhWZk3zZOlcCh3M65MSbbbJkA4NCrMmRNtUJzgjw=; b=fqRCMubbdITPyfk1p9MCzuozn7wBUXI1tI+Klog42UJ+pHbBG39xxTQA2qVhJJchqR +6u274S/MI4H4aJC+eo8AyDAivFeLrWPx45VT42yxeUy2LR894O+DjLa+zgBPRbyPFum V1wuhpRZW2iCRmKUGGxoqAqJXKsc8HNB3zaVN/08Va2DLXUfg2SfZtzG1Mqe0WjlLEe4 VYM/RdWF0i6PlwrgVwDHZn7Js2KDWLsVJbT9wCuT7j1iwUgJsA+wQc8KjI2m202pbODX i+qDTwB2kmQI6K6V1nmZv0Bu9zk/d6Nge+KJWl0lIZTxzeeENkfBBOD3az5bglYztg00 glZQ== X-Gm-Message-State: AOAM530xV7tdfRExiAErObzxNJzJLwtvtSvQEST6i7tdMtnKtVPCodpX 0r8QB8DSB9MVrH/Mp4yMvIYXZQ== X-Google-Smtp-Source: ABdhPJxxP8iviH2KsSwwMEIFD9QUMKimBYb9VpD3xn3ySaU04zl0IWmXoiK1P75a8LNwY/iJAgCpVg== X-Received: by 2002:a17:902:a70e:b0:141:a01d:9d6c with SMTP id w14-20020a170902a70e00b00141a01d9d6cmr17132607plq.84.1635691360562; Sun, 31 Oct 2021 07:42:40 -0700 (PDT) Received: from localhost ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id o13sm14332316pfu.90.2021.10.31.07.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 07:42:40 -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 2/4] coresight: etm4x: Don't use virtual contextID for non-root PID namespace Date: Sun, 31 Oct 2021 22:42:12 +0800 Message-Id: <20211031144214.237879-3-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_074241_442678_813C1B19 X-CRM114-Status: GOOD ( 15.78 ) 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 As commented in the function ctxid_pid_store(), it can cause the PID values mismatching between context ID tracing and PID allocated in a non-root namespace, and it can leak kernel information. For this reason, when a process runs in non-root PID namespace, the driver doesn't allow contextID tracing and returns failure when access contextID related sysfs nodes. VMID works for virtual contextID when the kernel runs in EL2 mode with VHE; on the other hand, the driver doesn't prevent users from accessing it when programs run in the non-root namespace. Thus this can lead to same issues with contextID described above. This patch imposes the checking on VMID related sysfs knobs, it returns failure if current process runs in non-root PID namespace. Signed-off-by: Leo Yan --- .../coresight/coresight-etm4x-sysfs.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c index e4c8c44d04ef..e218281703b0 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -2111,6 +2111,13 @@ static ssize_t vmid_val_show(struct device *dev, struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etmv4_config *config = &drvdata->config; + /* + * Don't use virtual contextID tracing if coming from a PID namespace. + * See comment in ctxid_pid_store(). + */ + if (task_active_pid_ns(current) != &init_pid_ns) + return -EINVAL; + spin_lock(&drvdata->spinlock); val = (unsigned long)config->vmid_val[config->vmid_idx]; spin_unlock(&drvdata->spinlock); @@ -2125,6 +2132,13 @@ static ssize_t vmid_val_store(struct device *dev, struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etmv4_config *config = &drvdata->config; + /* + * Don't use virtual contextID tracing if coming from a PID namespace. + * See comment in ctxid_pid_store(). + */ + if (task_active_pid_ns(current) != &init_pid_ns) + return -EINVAL; + /* * only implemented when vmid tracing is enabled, i.e. at least one * vmid comparator is implemented and at least 8 bit vmid size @@ -2148,6 +2162,13 @@ static ssize_t vmid_masks_show(struct device *dev, struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent); struct etmv4_config *config = &drvdata->config; + /* + * Don't use virtual contextID tracing if coming from a PID namespace. + * See comment in ctxid_pid_store(). + */ + if (task_active_pid_ns(current) != &init_pid_ns) + return -EINVAL; + spin_lock(&drvdata->spinlock); val1 = config->vmid_mask0; val2 = config->vmid_mask1; @@ -2165,6 +2186,13 @@ static ssize_t vmid_masks_store(struct device *dev, struct etmv4_config *config = &drvdata->config; int nr_inputs; + /* + * Don't use virtual contextID tracing if coming from a PID namespace. + * See comment in ctxid_pid_store(). + */ + if (task_active_pid_ns(current) != &init_pid_ns) + return -EINVAL; + /* * only implemented when vmid tracing is enabled, i.e. at least one * vmid comparator is implemented and at least 8 bit vmid size 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 */ From patchwork Sun Oct 31 14:42:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12595171 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 0DA8DC433F5 for ; Sun, 31 Oct 2021 14:44:37 +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 CA50B60E9B for ; Sun, 31 Oct 2021 14:44:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CA50B60E9B 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=h5cE9Jd2+7fAHG3SkLflZfULsSFRvC8VmPLdQDTF9sw=; b=giqVLJq0qw6QkE zcw4YGiVrhUfOBIrc+GhaEL8m9txLP4d1tYRzfB0J6U+D/NHt6QzLUohrrX+InFHa2jqML/PnRGSV tVtVhdCUleblYaU0Wun3l6Fz+hgVySp5n6/Vb7i2ifmAIuDpMdRy0l2yGlA2ENY3jCyG/Zil9+YRe KZ8CTSQ1UJqlpAgOQp70FGQRbw2/rbBcCRX7WilfCSeioklwg6epwbJuCiUmq5CjmkbTI1kW0iU9p n5KiMsmwSyXOF4bqGzJxw+rjBZSxD30C7UpBKUJon5suLVndw/XJs1cPoloPVZ3nd8kjk0Ye20MdX nypfNbvoqOznvXJuQ4Fg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhC3Q-00ECbB-Lc; Sun, 31 Oct 2021 14:43:24 +0000 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhC2p-00ECTp-18 for linux-arm-kernel@lists.infradead.org; Sun, 31 Oct 2021 14:42:48 +0000 Received: by mail-pg1-x52c.google.com with SMTP id a9so4324268pgg.7 for ; Sun, 31 Oct 2021 07:42:46 -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=dPTMEqL3NYtc2Q3PnJ9nazYoyjO4/ce4FmSNrOKpptk=; b=fvlc7+A6nqrzxoPKKUIvAefVAfll9mNtvEKZ6O3SGUNMcKV63hHgX0xMJlTH8cJK6+ mvffOvszw/VC3IR49oLmoCEA1r2zARnOcQaJiofKWb8x5qkcu5Bb/vBizCjq8cFIxZ/g wO3+mPkOOJPtrS5HfLSP/26nEaBL+d94OvX+L5ixHb/QDgFfd9CKWi5lmMkyMdkvKttj Rb+k04JYYqbhmooL9EmZYDdBXyFXeNam1MkaZGjYLMDCnKu6pb1pDUXP8eeSplYaT8fY ZBIUIpHqWg1yqOgEMG4z0fZhFxx9FcGmVGpinXaUNE9PPRN6fmJBbW3NiW7Fz9+4zu8w sv4A== 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=dPTMEqL3NYtc2Q3PnJ9nazYoyjO4/ce4FmSNrOKpptk=; b=na8psFIul9psz1hWKS/y95F12EBI8PhNtJcvrx+5BwLiORHkOTEP2gsEhQ9c23Rs1B tElbR4XFkhoeCofbG5PYnc3cGxnx+CVR4XLS4wwKEN5gBbLBhaSiz6JVPTBAYajMkYL4 zxASTTONVDH/Q4DP/LzNm8v3SJcZuiAwpWH0k+BSDfmCDstpNtzAk02yna2byBNAmryS zssrYREXcGsfsdQbxtgMobOuXtr++60LRLUQ4W0W3IgcPTIzcZz2LbU15TzyEgEi9AqU yQt8vNeF4jV7bvDoNBeTLwUQzxFfNZ3QljItxTYpdQ1JefpNosR6QJjOd77c/SUdg2h0 DTrg== X-Gm-Message-State: AOAM533Ta8UE6Nmgsuy1H2iPl3TnStd9GAoEQuylwUyY7I7WuYqfpAQn BVkuUWNF7KsMCGFppo3zgaEheQ== X-Google-Smtp-Source: ABdhPJwXduf3AOks9pU8yn43VO7xAPmYmLRcctvjxyNmzFodti8wWEVQIEw7JUcym45Ic3DlaybJBQ== X-Received: by 2002:a05:6a00:1309:b0:44d:4d1e:c930 with SMTP id j9-20020a056a00130900b0044d4d1ec930mr22820405pfu.65.1635691366224; Sun, 31 Oct 2021 07:42:46 -0700 (PDT) Received: from localhost ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id w13sm4088839pgm.3.2021.10.31.07.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 07:42:45 -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 4/4] coresight: etm3x: Don't trace contextID for non-root namespace in perf mode Date: Sun, 31 Oct 2021 22:42:14 +0800 Message-Id: <20211031144214.237879-5-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_074247_118933_F3A8F9D3 X-CRM114-Status: GOOD ( 12.59 ) 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 ETMv3 driver doesn't handle the case when programs run in non-root PID namespace, so it allows the contextID tracing by directly using perf config. This patch changes to only enable contextID tracing for root PID namespace. Note, the hardware supports VMID tracing from ETMv3.5, but the driver never enables VMID trace, so this patch doesn't handle VMID trace (bit 30 in ETMCR register) particularly. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-etm3x-core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-etm3x-core.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c index cf64ce73a741..0621ab0c71d9 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_active_pid_ns(current) != &init_pid_ns) + 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