Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2101003pxb; Sun, 31 Oct 2021 07:47:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7IckBKxStNlDlAy9OLhXbHwvLqRziQMry4fLZQr1iZucgNzdTxzBXo8kp4DU5ZkT4+b8A X-Received: by 2002:a17:907:d14:: with SMTP id gn20mr30598040ejc.304.1635691622797; Sun, 31 Oct 2021 07:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635691622; cv=none; d=google.com; s=arc-20160816; b=Uf+umNmmkqRiaGKG3hKjhibkZSrLd3d6rLHoqj6anK9zAebo8k8GCRzjTU8ibVppVK 7zEMws3q5QBJIYW/WYZKvGUS6kHTJUVhi06BeQ8R2KwF+4CBA+CQz8xWy8DW4yG2+K9V 0YW4/bXiyuuUh5SZxYrlZfBHAezBuZU7rT/SkkHk2r0e5wsZzGXL3H2YJSG4H5uSwQ4U 9rCB9J/KOfT5+UCTOUSt6KkTKf+8TJeLgUXdJSfKpTvPMTBjqlkokONLN5/J9gYcNSlY iVZZP+VeBzPYzdNu9xustex8820EDNjhqYtkD+7mODnCFJQ/3/RgGmgYOZpWgdijzgmf k+fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VuCaajuKPFmTiIUEF7c2E0sdpfzEPoBt97lGeDDdtio=; b=eWK7za8zeRijHr2ayqAA7gZiVwDEjd+bcqTs9dxT1q/N+XSCgTJTez5fcH/RmStcTw 8G8Q7clEgZ6q5z1DoqsQ1xtiT2uXvtoj2ygwl0o4iThHCvXE86myyo0SZoNCgOr4mx4Q bT7NFsH75xnsTVAlfkt6zfZBPPfByObHjp4F/B68eqWe8u8Rohc1vAkV+LovzK/0kr5N gM1b0qid4qU49GQR8QboV4pi4WMaS8vhQOKcHAAJuKWcGDz6xT40/+a7xt1xgLLwtoKA lkRGl4/pj4tVbq38WnfLCC6/y0q1cayYMUAR8O+tF9k7AC773Sr/ppdJ/IawUYzYnWgo 9gkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IHXRiKyL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y38si9060876ede.245.2021.10.31.07.46.37; Sun, 31 Oct 2021 07:47:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IHXRiKyL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230054AbhJaOpT (ORCPT + 99 others); Sun, 31 Oct 2021 10:45:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230059AbhJaOpP (ORCPT ); Sun, 31 Oct 2021 10:45:15 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC4C7C061570 for ; Sun, 31 Oct 2021 07:42:43 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id q187so14878506pgq.2 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=4Hn84QoCiGui6qJl0WCAGIz+HXlrTYL0z2jKHjFAHYI+oUNWT4CbubcFZ4PgJD6KOU zrm6gevKECSnF4XR8QdZDCOoZ4UEaEFSgyIqENk3xgxSPNGQLGfX6+t6RTcTCAHIfyxQ /bfS3hdEMA+VfzPF24rkKX8n4SC8AF/4+rwnLkc9QrKhpBIDyRiJCFiFe/Ms+gW+NpxT zfojB4jTZm2zxerykQJ1lWWMiOYx/vTGPf2o4V4TgM3a/YulcxItUsPzHhGzeT+nERYg L4ahmVRAVboseQNSUl0Zpg72OFo1xwNWLEhajZwFnHz9kBdG5seqaP9tgQ+IjHV0BxBM 4y4g== X-Gm-Message-State: AOAM533mBJr1Tmmws2MC81JVxnEYt/CQrJoiCRi3AZALCRv+nvC7H5Im rWN2Sf44guDRUdQ0Ni2RXnZqhQ== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 */ -- 2.25.1