From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28A9045A2B0 for ; Tue, 28 Jul 2026 15:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785250873; cv=none; b=g5PpCFBwcovLeFGe6uuoatgeUVEyUZjmYrmtyL5NWS/PdUFhL+vNhsS/U7+Wy86AAswrkzq3HJMEImbCzSIGSOcEt4Mhtsh64+GdErVcpN06vAdFUSbA2oqYnqexnlLi7M38XXgEJCbTFtgm1LW8AyoD7uVhiqa55TPDFnY2Bqg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785250873; c=relaxed/simple; bh=+f7e9UOWcMVSC9Q6jXSXvI/rdH74qrlZalYQYT5ZmfQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oA8iYhRczIzY5RQH4Zr0/DfQ8fiYmrIiB+hnAc9IXJLj/5TUccYD0i7vacdm6aDvLUIPlqU/78NFGcie5JNM8fcRcMDfriNaMcRSp/AgxeWYy68b0VcOEw9i4TUESch7n2mAkJtcCS0u2Fsz/2p+OgQu1x1iCis12FcDhVuakmc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=G2XDPR5L; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="G2XDPR5L" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-47f9ab7ee38so2151109f8f.2 for ; Tue, 28 Jul 2026 08:01:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1785250870; x=1785855670; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6irnWQqchvDZHnaA1/Tl45cb8j/7gKVA44kzoAlrHu4=; b=G2XDPR5LqVeMJS7H8Ns7aUfgBdq1HeDDoQ4TzXZ5/N6cEcvSmwdcmDKbD7RIKqYTdp vzS3tPqWi/c2rAJtK/yt5yGZdp5kpUjnVIX4fk38NcBA3li3lGD3ep406OGovb4WRze7 A3siiasLY9OHaj23KMgoTUJZCFBeg0ZkPw3q0ynWNmFBpoF875B1eKxPbsTQkf1+iLpw ZFTDqP3LHOFFfEWU7GSviISwyruWDGzOq2yNYmvwZq2dBgxeT/S45FMwgLNuWr7ZuJRp jk3/qL7yK6MQo7sr+msnFmb8cAuRMFBnqetuyOHgx0hSM4fyYIs3Jq7wEk0w6rH4cGx0 HxEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785250870; x=1785855670; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6irnWQqchvDZHnaA1/Tl45cb8j/7gKVA44kzoAlrHu4=; b=a8qJhwrYP3O4Srxt+GkT897xNC9FwQ8DPQQ8MbQHrKEQHaaFyYyuuRYseT+zSSXHZL sDutqbpCvIyEDgr/6NM2lAreCPu9g1KAuHqF+taf542AO9Pxm0FfGACB8EaLmGXQ7+KD Pf0XTyFMPdtLYOQothZTZnuskX72x32ezzksLGxZ6vy51+zzVjWanxggGOGSzGgRSaK3 TcR2sLi98xHIGtYzFXLZw+pgXnYaLlrZReJnUYAlJOJj5JdoALD+Xbl91bLwQtq6kOi/ b/KpsUjCpbCKLh7stl732eivC9dTAg1xRyMFaXIzhUU9+o/T4l4PTKp3oM0EE8ftjqRU P4yg== X-Forwarded-Encrypted: i=1; AHgh+RoYB/1aOvSHHUnBWmYwTT1rcjUcdfa8ZVBWI/my469skxdNIKQU/X/KY1RQvnN1tFDBakm1NUhpTO4mPsk=@vger.kernel.org X-Gm-Message-State: AOJu0Yycd5iLU85Vnog80K5/6D6SBR/PLGZ7FSBaTwxxAfrVxFFItz7F S33eq7qNLx7jFfUJaq8sx6wxgBsIKdV68gN5yOjdsdD/NL6iZk3VcP/YYvit/fCrCJs= X-Gm-Gg: AR+sD116pI5NOHHyvAVUEgkzApn/RJTpTNlcTFICkmYV/A/65CcK3lfwMjqL4xGsl+o XwaC/tXis9fz3sbM3Cl4NIhMTA+jcpsnxi3r/1rl6Bpqmh3zSlrwfcT6PJo7mVaE8jWlx+f0WLE BmhB0Mv5BzfxryAq85djCAU5QWhxCC1GYHTa0+GsbCJyog07kxcqfo+qui+Fa8ROCH6TVHZwqpR WFG3WIOWQocjBSL49FhigWyZZ3/Nb9MEC0CCsUTPWfy9ifUM5Ad1t5vrGOihvYSIqaCN+EcQxGu 0d/eJ6hq6MZCEP1Wq/hpRLyIdhxgE8AB4ZxVoLeeYszJoTK2M0SXkA6RP+5FNzJe7y6QLb7EIS9 5PFAiqbl1bumJaTAPnOsym/2AfJ+fNgdhJb6a0sHQD9qBZCPi7xBmkE36EJNA1MEF+32oKMzrYZ KDf0K9/EaPU2GxkLyjoA== X-Received: by 2002:a05:600c:46cc:b0:495:737a:7afe with SMTP id 5b1f17b1804b1-496c643b54bmr32514925e9.15.1785250870374; Tue, 28 Jul 2026 08:01:10 -0700 (PDT) Received: from [192.168.1.3] ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85c52fa9sm61036324f8f.20.2026.07.28.08.01.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 08:01:09 -0700 (PDT) From: James Clark Date: Tue, 28 Jul 2026 16:00:20 +0100 Subject: [PATCH v3 8/8] coresight: ultrasoc-smb: Prevent per-thread events from sharing a sink Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260728-james-cs-multiple-per-threads-v3-8-6aee7579f1dc@linaro.org> References: <20260728-james-cs-multiple-per-threads-v3-0-6aee7579f1dc@linaro.org> In-Reply-To: <20260728-james-cs-multiple-per-threads-v3-0-6aee7579f1dc@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , Suyash Mahar , Yeoreum Yun Cc: Greg Kroah-Hartman , Qi Liu , Junhao He , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, James Clark , Jonathan Cameron X-Mailer: b4 0.14.0 Like the previous commit to ETR, SMB sinks shouldn't share per-thread events. Fix it by returning -EBUSY if a second per-thread event tries to use the same sink. Fixes: 06f5c2926aaa ("drivers/coresight: Add UltraSoc System Memory Buffer driver") Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-priv.h | 2 -- drivers/hwtracing/coresight/ultrasoc-smb.c | 22 ++++++---------------- drivers/hwtracing/coresight/ultrasoc-smb.h | 6 +++--- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index dddac946659f..492f050eb698 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -94,7 +94,6 @@ enum etm_addr_type { * struct cs_buffer - keep track of a recording session' specifics * @cur: index of the current buffer * @nr_pages: max number of pages granted to us - * @pid: PID this cs_buffer belongs to * @offset: offset within the current buffer * @data_size: how much we collected in this run * @snapshot: is this run in snapshot mode @@ -103,7 +102,6 @@ enum etm_addr_type { struct cs_buffers { unsigned int cur; unsigned int nr_pages; - pid_t pid; unsigned long offset; local_t data_size; bool snapshot; diff --git a/drivers/hwtracing/coresight/ultrasoc-smb.c b/drivers/hwtracing/coresight/ultrasoc-smb.c index f66ec53070d7..ba4a7a8f6f96 100644 --- a/drivers/hwtracing/coresight/ultrasoc-smb.c +++ b/drivers/hwtracing/coresight/ultrasoc-smb.c @@ -216,22 +216,15 @@ static int smb_enable_perf(struct coresight_device *csdev, { struct smb_drv_data *drvdata = dev_get_drvdata(csdev->dev.parent); struct perf_output_handle *handle = path->handle; - struct cs_buffers *buf = etm_perf_sink_config(handle); - pid_t pid; + struct etm_event_data *event_data = perf_get_aux(handle); - if (!buf) - return -EINVAL; - - /* Get a handle on the pid of the target process */ - pid = buf->pid; - - /* Device is already in used by other session */ - if (drvdata->pid != -1 && drvdata->pid != pid) + /* Do not proceed if this device is associated with another session */ + if (!etm_perf_sink_can_share(csdev, &drvdata->perf_session, handle)) return -EBUSY; - if (drvdata->pid == -1) { + if (!csdev->refcnt) { smb_enable_hw(drvdata); - drvdata->pid = pid; + drvdata->perf_session = event_data->session_id; coresight_set_mode(csdev, CS_MODE_PERF); } @@ -293,8 +286,7 @@ static int smb_disable(struct coresight_device *csdev) smb_disable_hw(drvdata); - /* Dissociate from the target process. */ - drvdata->pid = -1; + drvdata->perf_session = (struct etm_session_id) {}; coresight_set_mode(csdev, CS_MODE_DISABLED); dev_dbg(&csdev->dev, "Ultrasoc SMB disabled\n"); @@ -317,7 +309,6 @@ static void *smb_alloc_buffer(struct coresight_device *csdev, buf->snapshot = overwrite; buf->nr_pages = nr_pages; buf->data_pages = pages; - buf->pid = task_pid_nr(event->owner); return buf; } @@ -565,7 +556,6 @@ static int smb_probe(struct platform_device *pdev) smb_reset_buffer(drvdata); platform_set_drvdata(pdev, drvdata); raw_spin_lock_init(&drvdata->spinlock); - drvdata->pid = -1; ret = smb_register_sink(pdev, drvdata); if (ret) { diff --git a/drivers/hwtracing/coresight/ultrasoc-smb.h b/drivers/hwtracing/coresight/ultrasoc-smb.h index 323f0ccb6878..491c2716b835 100644 --- a/drivers/hwtracing/coresight/ultrasoc-smb.h +++ b/drivers/hwtracing/coresight/ultrasoc-smb.h @@ -10,6 +10,7 @@ #include #include #include +#include "coresight-etm-perf.h" /* Offset of SMB global registers */ #define SMB_GLB_CFG_REG 0x00 @@ -108,8 +109,7 @@ struct smb_data_buffer { * @miscdev: Specifics to handle "/dev/xyz.smb" entry. * @spinlock: Control data access to one at a time. * @reading: Synchronise user space access to SMB buffer. - * @pid: Process ID of the process being monitored by the - * session that is using this component. + * @perf_session: Session identity of the Perf event currently using this sink. */ struct smb_drv_data { void __iomem *base; @@ -118,7 +118,7 @@ struct smb_drv_data { struct miscdevice miscdev; raw_spinlock_t spinlock; bool reading; - pid_t pid; + struct etm_session_id perf_session; }; #endif -- 2.34.1