From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 1260E459AFA for ; Tue, 28 Jul 2026 15:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785250872; cv=none; b=gBkEyS188z856KlqqNQEZyiY49L1SAiaikiUSAdliCTppRj3vQWFLarIAQfVmV+/wOD9RDVvSUT8tWQccM0fhaTel8WKE2AikH6Uy494y7F2nV2eaBWgyXYo69S677JOuTJlCoW25raHfjTE6wQ2oJgLk5kPY+IIkprdnKp7LPM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785250872; c=relaxed/simple; bh=i/Y0PasYAK3zjfkVfDVgWpxiDnzngYTzwGF0ClmMBfg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AGdoqFAxhYSRjG5XTH1Zx/6p+DDX7pp9xvzcDORbXAHvs9rAskKZqUqmqCJ5BH4+++NT81ffVzxq4PrA0rB7sbL0syGpwY+9y0YZtZFpb/tFCfew2Kv7+U3l04DEMcssf2h/5jWQkdj7ckwYiwywlniw0TSRlSGUrkCJ/m8+o2w= 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=wMUtNhJC; arc=none smtp.client-ip=209.85.221.50 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="wMUtNhJC" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-47640541585so2586784f8f.1 for ; Tue, 28 Jul 2026 08:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1785250869; x=1785855669; 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=+vpaJNvpoUmEak1pga/I7fEICTsiogr6kwDxnUKRL9k=; b=wMUtNhJCFu9pilWRl7BAITEOxLv90Ql5JHKcP8BmnV1iJM+jkvdT3G6McvRr8EQjFA WFdqnu34F1Bu9z7y05a14NRAehXpP+j8JRbMMCYzYQRmiNjw1qMt2BTyfPuz2HDgixeN UPERwvoFzQ8/2f4ZNTxFk9NT697a/HSvhARxQsoK/o3SMzsMQmenO+JES6NtiDjInFnR gEbYS6Nz02PiyzsVgu4HCIkVTVRmPvx9PGsSRzhjwv2cd4NO5OfK45CmkOT+JG7PEQAO xKdugKsmO/4btjuAMXZrc18QpaoqO8oHFae5Ng1mQU+I8b3e5WFKzOg0k2w0NpS7EhMi Riuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785250869; x=1785855669; 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=+vpaJNvpoUmEak1pga/I7fEICTsiogr6kwDxnUKRL9k=; b=WV4K+KBgxsCp2RJTIezFGaKwxyETPV+de5yTCe4Jcat1NIjJnN8jPH5IWSg6ql8P8H QWlulVNv6CtF+WVPrz6/PI/dnXGhk55aNOVI1+it7UU5+Fuqi5Aoz5KLJR0M9kc6qfHx szHwk4FsOmEOkL6mVMlMmwDDqArwP9bDekAkphAAjI+3y3fmRPr/9HDaFr1OWgL2YKWf YRIHjCYsy1ELKAXgJ0Uffm0aoBxA01V+u2u8Tc0WqbwrPXEPgGspiShS82M4e37+Oy/C aSj4f+BLXKWLEVgoLnfuTR8oRP6FBFWtASui6Th8ojlsQbie8fN4cTyT5yglzTnC/bca yZ+Q== X-Forwarded-Encrypted: i=1; AHgh+Rr0eQ9H78M8fx22E4N2hwL0OXfRCXnmjMg5NQGp2ufrOznZ6MvOvDZnO2Eowt8+7iXJYSJ0rHNGm9yHOPo=@vger.kernel.org X-Gm-Message-State: AOJu0YyZPkHjMLEhu6rm/ss/7ZJIWdVhbZIz04JBc8L/O1vtFUa25SIX olXjp4HiLq97zjIpO+C6hLNW6fu0qF5lvUQRdwkM5GNx7nIK6bmkWODgHtGwsq0ekew= X-Gm-Gg: AR+sD12Y9kmDePLFjjjR8ZGx0Fl/5JuaZoOFmxgOyvbTUCxUNZGV/roTflAIumUtc3F 9uwx18fA4mwobHb6J1t4Y46SXRwXgJAYU/2Uki5AmNoiGTEiag5j2hJWR9nBdbqy1KLKpTF/pQS XfTEBh7jX12Otr6nph7MaL5pyRjPFLWw+Gyj3KxVM086awiwXR2YFlFw7ypZpjOxxaghT5CzKBP jd/ElS/WWpRjnTBz5D2ExwMNbouoWBPIZ/GsnmwjSiqbRBxsmTh2iL5ommekngJ/5rBO9Nj/iyT NK03+S4HmcEjzzb5Yjgu6MwG9TaK2WamGCrK8d2UJ8g0tlGZiIrIiJdZgIoQaySFzsORn4rKppJ 0kaLgddC5NBGWMk3QcSxu5fmOYZ2r7tZYkm1PgxWdZZu1ucXKO8WpcZR4QBUxEHuMREfXL0fc8P xJsdtIZy0= X-Received: by 2002:a05:6000:2910:b0:47f:85a1:32fe with SMTP id ffacd0b85a97d-47fb1f14b12mr3311643f8f.38.1785250869142; Tue, 28 Jul 2026 08:01:09 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 08:01:08 -0700 (PDT) From: James Clark Date: Tue, 28 Jul 2026 16:00:19 +0100 Subject: [PATCH v3 7/8] coresight: etb10: 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-7-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, ETB10 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: 75d7dbd38824 ("coresight: etb10: Add support for CPU-wide trace scenarios") Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-etb10.c | 30 +++++++-------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 6a4a1edf46ba..ee0f20c30153 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -71,8 +71,7 @@ * @miscdev: specifics to handle "/dev/xyz.etb" entry. * @spinlock: only one at a time pls. * @reading: synchronise user space access to etb 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. * @buf: area of memory where ETB buffer content gets sent. * @buffer_depth: size of @buf. * @trigger_cntr: amount of words to store after a trigger. @@ -84,7 +83,7 @@ struct etb_drvdata { struct miscdevice miscdev; raw_spinlock_t spinlock; atomic_t reading; - pid_t pid; + struct etm_session_id perf_session; u8 *buf; u32 buffer_depth; u32 trigger_cntr; @@ -168,11 +167,10 @@ static int etb_enable_sysfs(struct coresight_device *csdev) static int etb_enable_perf(struct coresight_device *csdev, struct coresight_path *path) { int ret = 0; - pid_t pid; unsigned long flags; struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct perf_output_handle *handle = path->handle; - struct cs_buffers *buf = etm_perf_sink_config(handle); + struct etm_event_data *event_data = perf_get_aux(handle); raw_spin_lock_irqsave(&drvdata->spinlock, flags); @@ -182,19 +180,13 @@ static int etb_enable_perf(struct coresight_device *csdev, struct coresight_path goto out; } - /* Get a handle on the pid of the process to monitor */ - pid = buf->pid; - - if (drvdata->pid != -1 && drvdata->pid != pid) { + if (!etm_perf_sink_can_share(csdev, &drvdata->perf_session, handle)) { ret = -EBUSY; goto out; } - /* - * No HW configuration is needed if the sink is already in - * use for this session. - */ - if (drvdata->pid == pid) { + /* No HW configuration is needed if the sink is already in use. */ + if (csdev->refcnt) { csdev->refcnt++; goto out; } @@ -210,8 +202,7 @@ static int etb_enable_perf(struct coresight_device *csdev, struct coresight_path ret = etb_enable_hw(drvdata); if (!ret) { - /* Associate with monitored process. */ - drvdata->pid = pid; + drvdata->perf_session = event_data->session_id; coresight_set_mode(drvdata->csdev, CS_MODE_PERF); csdev->refcnt++; } @@ -361,8 +352,7 @@ static int etb_disable(struct coresight_device *csdev) /* Complain if we (somehow) got out of sync */ WARN_ON_ONCE(coresight_get_mode(csdev) == CS_MODE_DISABLED); etb_disable_hw(drvdata); - /* Dissociate from monitored process. */ - drvdata->pid = -1; + drvdata->perf_session = (struct etm_session_id) {}; coresight_set_mode(csdev, CS_MODE_DISABLED); raw_spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -384,7 +374,6 @@ static void *etb_alloc_buffer(struct coresight_device *csdev, if (!buf) return NULL; - buf->pid = task_pid_nr(event->owner); buf->snapshot = overwrite; buf->nr_pages = nr_pages; buf->data_pages = pages; @@ -755,9 +744,6 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id) if (!drvdata->buf) return -ENOMEM; - /* This device is not associated with a session */ - drvdata->pid = -1; - pdata = coresight_get_platform_data(dev); if (IS_ERR(pdata)) return PTR_ERR(pdata); -- 2.34.1