From patchwork Mon Dec 13 12:13:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12695888 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 C663BC433EF for ; Mon, 13 Dec 2021 12:15:32 +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=6PqkztiJDxBqM18Gp+MfcuH5bJHKb7OZRKHfYdhPh9s=; b=s2kryCGpJZEDLM 1FxyvqC0rdAYj7HqoDEcQmux3O0MTMQ8hHV+FkXvlr6z/uA8U7zvQKhB5j6igIPhl4xyIbb7liIez jvDMEipgRmwKofh3Yb+9iHKJfUxVyozc9PB1RSwKlMyNa18xflSH6AM1h2PsEO2MuHiC0e2WL6a3u z5wO1axpqcaxO1yIBDTFuxxPdfdYK8sww3vwaMU7dY6ZVF4QxMHS99CyArD8/2XvTdEn0MlHivuSs zMtRNbFZsSYjoYlzxHSD9+f3u/MMBW29jny9ZS5nVnML1pUySo5D/qciWjyb8D3MO4ALK8T9TY/IT N3YE/UseXFilv5oFy5mw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwkDV-009Qv2-4T; Mon, 13 Dec 2021 12:14:05 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwkDI-009Qq1-3f for linux-arm-kernel@lists.infradead.org; Mon, 13 Dec 2021 12:13:53 +0000 Received: by mail-ed1-x535.google.com with SMTP id w1so51184331edc.6 for ; Mon, 13 Dec 2021 04:13:51 -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=JBlM0fJPQdFbfZELyfGYDQMeIzp3LQS6pQHkYWuX8+E=; b=dd7hlYP2Clq1AqRb//9vi2Gv0QEIpIvvfOc9+YtILUbE2SbzZJEQh9ItbAZFdJGYta QICI6sLf7SLo3L4q++xMdDcSwnQzgK2YiKmKuuC89NHt6+KWmQaotLkWJydNCot8tZrb 8yao4HIb8kRXQcll9l2Z9ah2lVvUAeUsLFt3pQCNL4scCAusbSM1MxuF3KAT+lKwIytR r1oWPyT9DyVR71GioIAtooIYhNCccMtLWfm4hqFVoMocfEw3BfKt1MOP74+VMWjGpluB 7b77azzx47p+L2DphzEiHlSrjBoztZNWS1BSz4g1vPtfY8vghI1nj0PbGSmEb+NZEPhj 9XOg== 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=JBlM0fJPQdFbfZELyfGYDQMeIzp3LQS6pQHkYWuX8+E=; b=rvpJl1bOnuaU1XEmaVJTZDmHH3p5PcJgfZzig/aEQ4FwfJjSQBMfV2dWobZtLMOBbZ 88gnTjcBpFJDJ/0Jax8GNoXHhllH0HFe9WgqAkMoAM0DHt0orv8O5jdAySgqvfOH2oLI fICggT4dqUcPXWUKXG+Kw6revtoBZHZnFqHHBG8HtvhjODPyRfF2nu6om4gYJ4NSSTx8 XaEdYwiOk0sozPGy2cwRyo28qCeEeEsCH364qxv2q5GPV831qgv2ONYpsvJsCkTOncCa SojfpI0126QhWVxsgJZwb+xhbP4L3WMHBqHezvy06iiJvG2uv9i0FkXpTlaHUB8wuGKz eozg== X-Gm-Message-State: AOAM530qEJUMTA0HAAswxrFNfaYdlchCknCwZ43Qw5B/+0qJPpZJcm+9 /QtSHUTn+emw7fpH8NkSYsiuYg== X-Google-Smtp-Source: ABdhPJwz5oYW29GAi3U4zyh+V9Z7lEcvYsoaWvpdN0+4MDNP19p4ZNmFHRg0zw6gTZu2cB7ZId4N4w== X-Received: by 2002:a17:906:9b8f:: with SMTP id dd15mr42691115ejc.480.1639397630513; Mon, 13 Dec 2021 04:13:50 -0800 (PST) Received: from localhost ([104.245.96.202]) by smtp.gmail.com with ESMTPSA id nd36sm5895826ejc.17.2021.12.13.04.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 04:13:50 -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 1/4] coresight: etm4x: Add lock for reading virtual context ID comparator Date: Mon, 13 Dec 2021 20:13:20 +0800 Message-Id: <20211213121323.1887180-2-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_041352_174324_0EAC1411 X-CRM114-Status: GOOD ( 10.52 ) 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 Updates to the values and the index are protected via the spinlock. Ensure we use the same lock to read the value safely. 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 10ef2a29006e..2f3b4eef8261 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 Mon Dec 13 12:13:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12695889 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 65C25C433EF for ; Mon, 13 Dec 2021 12:15:47 +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=xB5yIoA7dpUY4ReOcRXZ0rq7HhN5Wpn+WtSEAeSwW/w=; b=UoKjv7BLG9D6fT gNMvOIcyeUicsOY8OB/7jIb2iR7oolGu38+0cK06DrmckrT/kVPzH6NesrNILDGt80Iy7O8ae92Q9 0j31CTA2N8fCJ2QmG/m7uEIcjUbeEO2JmRgZOm2k611wD+PjHUa6Wp9GNHe0a6S9XBIE+730T34A4 dI8XKeOsMFvYWjY1kMPpjOGc82NQkoKYjBcgBeX08yWqc0+T7nV46gsBFavZoywMHO7yRXMKM95S4 Nlqgp/FX9O9rqbPQdn2yXa8POYVOupg8jOkTqCzmg5cddFMbJKJi0eEWnT7gWAX08TI4djssKyROK SPZT54mX3b/H3gGxmRgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwkDg-009Qxg-4V; Mon, 13 Dec 2021 12:14:16 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwkDK-009Qr3-LB for linux-arm-kernel@lists.infradead.org; Mon, 13 Dec 2021 12:13:57 +0000 Received: by mail-ed1-x52e.google.com with SMTP id y13so50935137edd.13 for ; Mon, 13 Dec 2021 04:13:54 -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=4/q5CQ3/q+2EJBhXdOxiiNn1t4GGrRS1OQ5Mkhf3Sec=; b=FQOiwxWIa/V50ZOvIdGrxTMDpMzUJYTDnJDsBkBrsHoCMvjGB3JGMyk2jz0ZhXKQQV P10aOa+Fd3f0lB2j4MAI924aBw3zStw8fq1rOvxuIHgQ+3LHMroZZe0QL/eAzbPtP6cM Py5peunGY3HKzWu8JFSe9Jf64cg24VZLyM39StxAr+lvo7RL8tR9TDD+cFO67mJ81IOC TuZLaIbncZ40e+u4rpBAO8dYHzJfNUraSjcpxrbs3KGkbNENZshyn1ulLZTf5dPLhMDh SUSbVCpTixyLr3V1bL3fVjDXi8L5ElPpfB4pd5+EsUOMRjmCrqbe1/1S4q+d51LfUejw 3oTA== 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=4/q5CQ3/q+2EJBhXdOxiiNn1t4GGrRS1OQ5Mkhf3Sec=; b=vrBa3y2L1iqLJ4qQ2iuqDq+7yfFlPbCF4//xvDK3iqejosXGRDq8IItocI17hkty0I CjG9xMo0+Oxiv6izDu6R7OjeYssi9jsAofdx5cxg0xDhFtISJMB4jiTHDMQD7KCLzjrv apzzq4L1VfKKfvnUsup4Uwufs+1LC1Q/RF68jk5f+KzoIo3HUR+HCMcaTNsui1K4juii yJcsnuD0g18zG3thuYPcu5tE0XgixQbIlQltuba6StIhsn/1JCTrhISaTB/EOhFfORlD CLHuqSMgA4E9mqnRTZNISZmfR8XNAmQsdH2Fo6C693Bg8x2lZJYwuHKyZE49xZ1NenrO He3A== X-Gm-Message-State: AOAM533nFZOHM/qEN/skdxAM9dGRfTXNkKAUKHK73jhDwjPL8drczNbf cNNSAJV/5e7ZcO5snBp2SsQqLg== X-Google-Smtp-Source: ABdhPJwpHCWcd1fqcvPvzOIn657fLFck/7Gj6sLy9umteOuFTthGsPkU/q9M/IcZwJZKz36vOlBQgQ== X-Received: by 2002:aa7:d794:: with SMTP id s20mr62400515edq.305.1639397633225; Mon, 13 Dec 2021 04:13:53 -0800 (PST) Received: from localhost ([104.245.96.202]) by smtp.gmail.com with ESMTPSA id r3sm5803128ejr.79.2021.12.13.04.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 04:13:52 -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 2/4] coresight: etm4x: Don't use virtual contextID for non-root PID namespace Date: Mon, 13 Dec 2021 20:13:21 +0800 Message-Id: <20211213121323.1887180-3-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_041354_731548_BE295F33 X-CRM114-Status: GOOD ( 15.37 ) 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. For this reason, when a process runs in non-root PID namespace, the driver doesn't allow PID 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 and returns failure if current process runs in non-root PID namespace. Signed-off-by: Leo Yan Reported-by: kernel test robot --- .../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 2f3b4eef8261..a00c0d1bbd85 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_is_in_init_pid_ns(current)) + 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_is_in_init_pid_ns(current)) + 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_is_in_init_pid_ns(current)) + 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_is_in_init_pid_ns(current)) + 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 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 */ From patchwork Mon Dec 13 12:13:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12695891 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 E2465C433EF for ; Mon, 13 Dec 2021 12:16:13 +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=3ZUSFNdxelrweEVtBTV3SrFaqmGpC6zjToSW9idBLFI=; b=FLOsSo6IM5NzYv UzHhLpgAvvcJS/eK/q8vNrjcWplrsNhFd1Xp5Hv+tVEE5aOkHi2d1NowZqmnoMrlChtqeuG0GyTg6 aLc05F8kgBbyaVn+Ak0x1hZarqrAvHw9PW2ks0LZ4IqOT9wprqTieG3TwxPHcAV47QbC7mXj05hSq wOy1b0knvOAkYWTmAvPlssDMi6MI0f4xg6I8kz4OBTcCAdYI4LtlZ5E7MiEuByry/F3/AvO3pR6IA 1UpSGxWIY3pPyAHq5QLelZWN/QwVq6UgKJeXMG05X2xNBR68Wc4BEXhz3lhwTsCCTomkoYhR2Iar9 qJF7eb+RJYmgBq4a5WBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwkE4-009R4K-9q; Mon, 13 Dec 2021 12:14:40 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwkDQ-009Qtc-Ix for linux-arm-kernel@lists.infradead.org; Mon, 13 Dec 2021 12:14:02 +0000 Received: by mail-ed1-x529.google.com with SMTP id r11so50761855edd.9 for ; Mon, 13 Dec 2021 04:14:00 -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=CP130Joo5LnzHA5fd0JPgyy8qzQq4QiMmlbo4WSc/bc=; b=PSS1H3WXFIMfkQxsIWTWwPkYK0wcqIk2+76oPkMNGMZ0qSS0iW+g1XjW6KXrKR+L62 VZEOcDtuRohjJWGX17jBc1X1QFF5D6QVXy/07L0sCzejVVBUVGun7Rdp3RacKI13kR+G lnFNiTYewYD7lmVCYatZZ2L7DrabtOQEcTGNOeVyK1b3JHPBeBBD5Qqsb3I3H0eVDNfW nHM6svD7D9x/YbKj3k4Yi9DfY+ceccgIxldW8uXVMXTfC3lKetcPIu8unIGmQo70yGvX it9eh/YrirQGva1/nfhawMjYtC5hJ2btu4n/JGYDt9CK30DoC8JabmNh9qmyfMpoXleB g3FA== 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=CP130Joo5LnzHA5fd0JPgyy8qzQq4QiMmlbo4WSc/bc=; b=bt3p8DNODvaWkC6RYR+4TooR6osamu0KDaOyvcf7wbF/xvHj00y0H3bzcV2QnCjFVq T+1t+YxxbhPvAuUXWffDAqfs0wStzwUcbowo4TG+hUCRzZi6K/R1zImb75ub7/q+cN4U EZ6+9LSi78gv8XfRIf5zho+4Xo2Ip29TRTMLwKCyrWo6o3zmM9uG229rSavbjjsXdWOm IUFiATm9C1ObH8O74WAG0EldWRt09eazU9hie4hq+CzVwGgw7uFBexfU1xT7RLKota2g aZJohcFsFrhDk2USRQ1hTp+d41zLhU4mqTIiIQvPqa6OQjDM17ZzqfRj6O+VL3Sr1ehH mD9Q== X-Gm-Message-State: AOAM5310qRmr77UUl0kogxRrVj5Dck+Eprp3iTo2CV3om71f+seZf8E2 unamKWFRmB8nHHlApU5cJi6hT+AZlNrWVfK22mI= X-Google-Smtp-Source: ABdhPJzEjrG8YHO4P2YfYwddzrc1l59/YSf3cTyU7Z/e8XhYhxdxpkf6MgfH65sMs/AbT7XDZH+LtA== X-Received: by 2002:a17:907:3c6:: with SMTP id su6mr46285599ejb.255.1639397638590; Mon, 13 Dec 2021 04:13:58 -0800 (PST) Received: from localhost ([104.245.96.202]) by smtp.gmail.com with ESMTPSA id d19sm6273171edt.34.2021.12.13.04.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 04:13:58 -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 4/4] coresight: etm3x: Don't trace PID for non-root PID namespace Date: Mon, 13 Dec 2021 20:13:23 +0800 Message-Id: <20211213121323.1887180-5-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_041400_648665_B645CE94 X-CRM114-Status: GOOD ( 12.19 ) 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 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 Reported-by: kernel test robot --- 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..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