From patchwork Fri Feb 4 15:24:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12735221 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 54CE9C433F5 for ; Fri, 4 Feb 2022 15:25:55 +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=hNuIWAxpsJK11z pYN2BGYrac3pHNy8xKGvvRyI/prz2lnsieIljw79LZJLT1GnLkvjFhoGRUrpjI4G0SJ7RBD2s1tV6 Tx4ZnTHoXQSsAVNgtj7ppsMFMJQjkX8ZsR3lrVwlpVw6bLHBr9FuMkLK0ap1e8JV3g+lkSl8aMPup dw1+XOoktF4JZ337tyU4rgoPX+P8NCCee0FMGvhlSgyUXT7NoFNo+M+5ZAhzZwurK70Au2cQec7jU 7eF9clA7M/4Q48v9WE3EV7xdSrO2/43Smw025cisBoc8xtmXIIN7u8NjA/4GWChmN6KMt2tU8pBEJ GWgZS0EnPmFAKYGtXwfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG0Ry-004ipV-U4; Fri, 04 Feb 2022 15:24:39 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG0Rn-004il8-Fp for linux-arm-kernel@lists.infradead.org; Fri, 04 Feb 2022 15:24:28 +0000 Received: by mail-pl1-x62a.google.com with SMTP id h14so5434787plf.1 for ; Fri, 04 Feb 2022 07:24:26 -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=X9dUcNLOw092RvHVzkfzPS1gNBOrhNzF4xP71iXtrHvkaRqW2nTuThJXpAcz9y5B21 KoV9pnCaOh6YgT4o7+Hk2oENdB/GVyt6M6ugQWjUaLweghTWLCEv+i9+sBROt0qDm3wi poTuVRo4c0uG35TNM6PRmkT7dbUapI1Gn4N57UgrgD9yVv32iU/SljKcpp7QSoSnNtfu pXgtq+gWqvrWtfloS0/DLtPmN3qC3EbgWwh3jgLie39wUsb6Yc2Ion/ziNS6P5ANwE/c IBAr5gY4ZnFwRzxzbgKniEs+mPRr+T6M26MnrCGOJ2swBPjo6j1gSK4nvi1w56MKIdu/ Z92Q== 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=kQeHPfHva3tAM7t8DsIH8lq5Q9RgoICasqPmFxuLigEZGhoCd5jH6Ij8IbXW4yzMzv aiQRs1DRDd+DbZxtLoRh+E/n20n9/IY1t4x3DX5gRKvJJfgy/l+brSmKjI5iR0IcCwrF bZqM6p0dRMk8fZLL4IdppgAS5zVDzuBX3brdzBhLisYB1yl4+ZB8QhTYeBqBTkEsMOEi vVAzA1Am/F8GVUj5AvHyAD/k3cxE3rveB61BDs69xTiCsUCihXnHqUHKAdtrawOmWhIC ldaNboOF36UGHPGSbYRtk27mkmBzsrKklezOeHdY5xKZsy/8Xq6nEiZm6zDvd+8VqWQE pY/g== X-Gm-Message-State: AOAM533ceRsr9Q2TS50Ci7rQylrtF77oStUd2RNJQO7Q7cuTG5clwGlt 7A6fTU/zmEvyr/ZNkgHA0OXA4g== X-Google-Smtp-Source: ABdhPJyIBnN4dkIRd9M9D8tgwp/n04tEKjszNC29r+PG9jVXxmyMTXPE0hth4JQKWyim1uTygPiS8w== X-Received: by 2002:a17:902:7893:: with SMTP id q19mr3768988pll.9.1643988266284; Fri, 04 Feb 2022 07:24:26 -0800 (PST) Received: from localhost.localdomain ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id me4sm14237079pjb.26.2022.02.04.07.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 07:24:25 -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 RESEND 1/4] coresight: etm4x: Add lock for reading virtual context ID comparator Date: Fri, 4 Feb 2022 23:24:00 +0800 Message-Id: <20220204152403.71775-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204152403.71775-1-leo.yan@linaro.org> References: <20220204152403.71775-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-20220204_072427_557172_C0535968 X-CRM114-Status: GOOD ( 10.82 ) 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 Fri Feb 4 15:24:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12735222 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 A4C84C433EF for ; Fri, 4 Feb 2022 15:26:03 +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=rFqaeLST3UZIaJ 4yFUfh5lr5z8GicGWTK2RWqR1AuTI5NoCDO/3MIFtQRIs9CqfVYlJd5R5VE9yN3aDV5LEE8H9pFQ+ Qc5s2/HAJOFk14t37CQUs6NugS/tazCe7YLOjWYutc3bc0B5lUPCd9UVHae4RIqF4Yh5qO6fgYuvk x77CMLJAiIZXX1syV+J2LFPn9h123Jp36MciYk4XPld4Iw1yv8tW98J9yqS4P5cw132nwhMACl+Fc 6mfqdrrZuzFrwdR05d8kJafeFSqqFr64X7xqszDgjJrsa8RKjk0LqXDTD4PxtAL4uwDD9ICsk0vJp 4nl9BveEAwox0fzwCPcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG0SA-004iuM-Ei; Fri, 04 Feb 2022 15:24:50 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG0Rq-004imn-Ra for linux-arm-kernel@lists.infradead.org; Fri, 04 Feb 2022 15:24:32 +0000 Received: by mail-pj1-x102f.google.com with SMTP id m7so5917860pjk.0 for ; Fri, 04 Feb 2022 07:24:30 -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=C5DCpREMlr88/fQU73s5wGn0GGcqkJJL31Xyv/kKL/IgA4KcFNddOz+ZuVlvL7O5VQ V+CqjAPPP6J5XvAoD9yi63Bq/ObHpUVSJm/2jMiFFSF0INWY/ePh4sHgUzpeLlEGbw71 bKoRSRle8ruV4QdF0bAdTRTYow4z4Yw+8cWF1MkobFg3jbs1Wb2DeUzWxx3KWX+aH48b a+Chi9XM8igLqLv6gRa8gW3bjLkB0ePtQG5CRESTLFoiQ+hxCD67L17pbzcnqsMi1KHK ghDYmPZYgqZABx6Yi6Qa4DUf6/9GpniToBuuInQnhAJsn/4J1L8FaRaQZinevEbHC5J3 684g== 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=bsIW1j8T40n+XK/Y/aBX1GHaLlPWQwNAdBiinXwV//ANQrPJN6yWstUXHGci5w9rtv 7oQKZKqoOH2+jRLXbp6CwC1dxtBJPkOHvBDtao9Rz3LlvtkAAw4lyMPgIUpvmU5AM+kI ymJDJrRykX8MGwAkfBSs8onwi8UaG4T0MFKYilhA2cddGSpP/DJ1In+o7EdiAzS20iDk qa4xNq2trSyXUXZmbJeLWLunWMabXzw6ghl70PE22z9kZP8U20fWOPYfXK6q5V3TNXe4 kAyxAkVFqzM+e5fjvJdF8tu0V0CGV08uJEsJrG17DG6aoAD8cbcL1vr80jn3LVTtpQJU H63g== X-Gm-Message-State: AOAM533YYtuGhfhoTQvDByTu4iVpU03+FNxH8yIoT1RhV9uFH5iJkeFW hRWYRs4l1zbBQbWGUhoHHmHLGA== X-Google-Smtp-Source: ABdhPJw6LeGmJXDi9zLXZTklPRv2RbP51RpKUOJu3zoaiPjk/3n6c0kFXnwZysSKkOOnpiLJ0OSkzA== X-Received: by 2002:a17:90b:3b52:: with SMTP id ot18mr3730813pjb.34.1643988269617; Fri, 04 Feb 2022 07:24:29 -0800 (PST) Received: from localhost.localdomain ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id me4sm14237079pjb.26.2022.02.04.07.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 07:24:29 -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 RESEND 2/4] coresight: etm4x: Don't use virtual contextID for non-root PID namespace Date: Fri, 4 Feb 2022 23:24:01 +0800 Message-Id: <20220204152403.71775-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204152403.71775-1-leo.yan@linaro.org> References: <20220204152403.71775-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-20220204_072430_918948_6B39B786 X-CRM114-Status: GOOD ( 15.76 ) 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 --- .../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 Fri Feb 4 15:24:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12735224 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 4B2AFC433F5 for ; Fri, 4 Feb 2022 15:26:12 +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=LprqshpF6BkoTD1sBAMdiaBebN1Fi1FNT/7a9bm0Bbc=; b=cZCWktKX/Ja5fL tQg1aJtt8QejX7ZUet8KBGvNcUs/VZo8A9IwzFvdbli3RhxP7z3yC2T8luytuja0E/PsG1dW9Ojy5 jX3VpU4lzYmmhr9+dQAEzjJMmDMoBA2pt90/mOERGfixeIM24qwQL/U5BQhK7MFOPBdXLpEzIZfqG C6TIMymbVaZFqXqfKKMhXxwOnuH64VmOUGY7leNv3SP01TZh5wUahAEswQ4icKLTT9Jov45P7pTdG fHa3Z8AbseTKnNFaHoMPHSfaVlofzpxzYo3SHSs/s8IYbbUptsNAyPHaOCuu9nZgDcfIKXDJ/Oo54 tHcNRZmOZeOx7ltVVC7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG0SK-004ixX-IN; Fri, 04 Feb 2022 15:25:00 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG0Rt-004io0-SP for linux-arm-kernel@lists.infradead.org; Fri, 04 Feb 2022 15:24:35 +0000 Received: by mail-pj1-x102f.google.com with SMTP id q63so5890220pja.1 for ; Fri, 04 Feb 2022 07:24:33 -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=5hy+SU5DZKBp2FMkZFvZyRIrItONG8TmUC/aEVKilLA=; b=YVYVsFjbL0x1PoSKxlQAP6K1Q8tWbw8Kg/Pjxg2FOF7pQwqBlm4aamWc85meRcLFXn huSX7CmPT/037OkXHzkS/nZETc3ByhPzAKCmzUjkSPETbmWO8o6872bcmIHdH+b0JaaI wAprJiNghAyI8D7NztOzffdkxld1O/ruTxGaiveeXnEWBQApWyucb85lRhXKfu6rFYk0 PI/EXMInmwt6Y+y0/c1O34jqK9zW6+TH/rxZs2kWiKmj+z4pVj2QjMKCt2qDU6u0P947 OY2QmNPun9R49SR4OQ70OU9A4sNH5oiV/QJRf0uNbHp93lgmnyJIvyBJkKiMZQ5Y+/Fn Yg7A== 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=5hy+SU5DZKBp2FMkZFvZyRIrItONG8TmUC/aEVKilLA=; b=KPxGGOiLk+BlH0hHFq5nbzpgNoK083pF0wc7YxBOGrL/2dk25ElG9F02whi/K37aHc vcoieD3VF6Ida2Jwf9VaQrI+MwAPV5k+gwR+bmPWBCVQMxIHE8G52b8gJjqvtjck7OFV C2t7UnLthRdNmC0EUlxF/c8G5r5oftzeDuoHujgfBpyVK3y5OX6PbG9yRmHOIRnHjmTC nBkRcp1YqZ1tF5iTkd1nkJK87K3fRMr0iMRPtCFwDjbKx7Tt5RUxKCsELgfcfpNgtRf+ ky/0wuppBQNtnbcwSfeONi43FjBG/jJWKQQ+l3tMdNNZD6TO+CEVcEv4AyfyOUa528ym MapA== X-Gm-Message-State: AOAM532WpmpgaIYcOS3RFrGCM/9Qmbtf7PssNMvCM1RDlGKYksf5woiR CkGFaUshkKyUIwxoBba1yiV8ug== X-Google-Smtp-Source: ABdhPJxlCc5xJ4BQqndpWvQJnjLgf7o0hy2on0zKx3ZCMYmek4gRlokGD7MNBbxdNJYhr24PFAJ6YQ== X-Received: by 2002:a17:90a:b018:: with SMTP id x24mr3617371pjq.91.1643988273277; Fri, 04 Feb 2022 07:24:33 -0800 (PST) Received: from localhost.localdomain ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id me4sm14237079pjb.26.2022.02.04.07.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 07:24:32 -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 RESEND 3/4] coresight: etm4x: Don't trace PID for non-root PID namespace Date: Fri, 4 Feb 2022 23:24:02 +0800 Message-Id: <20220204152403.71775-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204152403.71775-1-leo.yan@linaro.org> References: <20220204152403.71775-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-20220204_072433_943746_A717A3B7 X-CRM114-Status: GOOD ( 15.02 ) 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 --- 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 bf18128cf5de..e7fc83a1e188 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 Fri Feb 4 15:24:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12735225 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 375F8C433F5 for ; Fri, 4 Feb 2022 15:26:20 +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=LTgaZW0xeIKEMC t9yXZGq92oR1piIpCjsJ3hgwXStk5smgy1CjGv+nRx0yij5NP13OuZko9xejcMrUjrc5B/bMvvSmo XGdm9TywHnq8RqMkuuLehGF11AyWwz+rJD+LKJqWS571hs/QFTY6qBsjv73jVSysuytjYBRbteQIU cTiU0MBvcaWNtnf0Fk+j6Ow21xyBE6+yHOtQhVYkqbj1oWWVGyGVH3PnrNm/OX0oLcvKyfAgTcTO/ I40r0HJ7KUQu/RjENwWF1pzFu81J1ak1bIkLCugnnhVPMlGT7XkBAOrny336h4llLepOk223QQE4n 7oGH4xLU1d5LADZ00/jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG0SV-004j1a-FO; Fri, 04 Feb 2022 15:25:11 +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 1nG0Rx-004ioz-Hc for linux-arm-kernel@lists.infradead.org; Fri, 04 Feb 2022 15:24:38 +0000 Received: by mail-pj1-x102d.google.com with SMTP id s2-20020a17090ad48200b001b501977b23so13410515pju.2 for ; Fri, 04 Feb 2022 07:24:36 -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=L/e7pgEILiyjVuGqBatpNWgdA2j6VCihnfihFatdCHPNmoY4xviCPf/nQm5bMBlzQP amlIOx/kyvPnSQj3m3GWhXKXIOA+a/ixQAcJmr78Hq0YtpO6MTDE9lX1FHMNfagK3HZS XjSYynqpHruY90Hlo5PWLIx6f3OaLgcF+xp/gx70H19rIuwS8nNLlUni73WYe46gynsG GURGyJRD/1DK7xxK8+9xaFuK/UxXPHwEdbr7m0QPU4ZzfG6x2YUMobaPHbjmceMXl+o4 su3bKwuXugi2Zt041Hk8OVTR0IWnW6yhOqS7WJa0hv89TPcSkQUhXdwGspZn8M5cugwX kjXA== 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=6UDqroYarednxiUixLt0fiQInWcfRUW9P3LHf+ahK8AJ5MxfB0smAqlbsl+3sKknlB 8q/q3/8ogpQMHJFE7NkuP5PC8v+kHPjT2DfDL84gHFvHe/jIor4u4ukLzIYfenHfDvYu rjdyjRBP+fIdX5DBw3gqN0lDL6rVOhGgIiu1BKu0qvPiqPnAmIeWV0Ul4sLNFu+pbOHi wBB6xYqKuzXh0tUABrSrBG/3J/pGbxZiM1CMsotPvNi2bW7GyYoY7LDR7O9+RlD0klxy UAby6azPFIktLMpaX/DZkno9KUQONplK7/pDulX/s5WKBr+t0nk4QLM6HV3pkKXcvj/Z SOoA== X-Gm-Message-State: AOAM532+xT61t5PX8fb9ISCE8L8yQUywBIGuKioDo4Zv7lZepG+lsAmE kKAYBkee2bQ2w59z7do8difBjA== X-Google-Smtp-Source: ABdhPJxbU+TPetYDwGr0juHAkGQdM/jc+JJ+Gtz12pEMdxQWIytSegOUq1HgGsra7H1qWC6d1uqoag== X-Received: by 2002:a17:902:ec81:: with SMTP id x1mr3384394plg.109.1643988276332; Fri, 04 Feb 2022 07:24:36 -0800 (PST) Received: from localhost.localdomain ([134.195.101.46]) by smtp.gmail.com with ESMTPSA id me4sm14237079pjb.26.2022.02.04.07.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 07:24:35 -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 RESEND 4/4] coresight: etm3x: Don't trace PID for non-root PID namespace Date: Fri, 4 Feb 2022 23:24:03 +0800 Message-Id: <20220204152403.71775-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204152403.71775-1-leo.yan@linaro.org> References: <20220204152403.71775-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-20220204_072437_616704_28A8AF7E X-CRM114-Status: GOOD ( 12.66 ) 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 --- 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