From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796024019; b=PNOCb5MTD+1BFB+hgajTzUkoMz8Y4jnsWx+MZZOtdI2Sacdo4iaahNwp46857PgHcHTe 98A2VYnkYctnOATjZ3zDKb5eX0As8C40dGPuqRAcUW9MHiGgN+qmavzuIk6zzNAHWXxof 8t/Hrq87sPTy+/8BQGx+clH9Q9wO7EN/uZoNK113kvPKHpT5Exc6oH8KV9liILuO+fY6I h2bqubG0HKdetC0JTSnYJaJyDSDSwmV9MGTdDSvbG9sO6bSQyHmPlV/39Z31QeCNx3V7e 09bV23jMtzVILzqNoTVYpSO284vv5+xP4vZBQzEnOMu9wpd4RDpmMza4WMZ/cOdF9jQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796024019; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=VTqN4RJZYOr24cxuKdkJLbxLWv7QgpWfsz5oqIdBaUg=; b=VnS5GBu6iJ7Q7NcLy3MLFrQMCOEJtkwIVBM5oQLNuV2vBQRi3M66LBi5pAL0IrlZe4rF DcMuufDuMYfROkljfaCDnywavO3nQRi6kRqBp2U4sn97cDOMphd60IRchpZ29jVDk+p3g 9WYwY09SA9O5JqLMcHxO0FPT5W4irz8cb3QgtSqSSlTZrIQ6Dl3VQx1eINNEZSCgyT+Ap HiXI6qqQSA+O3VQTpcRtypS/OKgL/SmuM0JyxFR/VZoE36/LR6lttHF5r4vNrT6oR5tw2 HSXdxRFvYxcIbh8f4qKf/dV7i3MVzeL8Jh1rMjiIbVSIZVk0HQNyao61uYyt54wjRMw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=VW8mGhjb; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5AB1606A31C for ; Mon, 30 Nov 2026 07:33:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=VW8mGhjb Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA6911F00898; Mon, 30 Nov 2026 07:33:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796024019; bh=VTqN4RJZYOr24cxuKdkJLbxLWv7QgpWfsz5oqIdBaUg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=VW8mGhjbl/Q5uqhuGfG6rLFZbr/+jCPxgNK7QSNpJ9hMBdH5rAXcIuPegBIvtvd0B BxJJKsQEz0a3EwfZo/VBdBXgbP3XnFi6Dg0SImP9sgOEvNMmtpk/G3PskcO5M/7pyI sIxIwNiO0Y2csFmkvIjXQwVc5eaxTCjyUkR/oO3RYvlSG2jlyutNlbZ0cYgFb8aewP b7Y/SHbG43GFfbTpMegfYUyh+5hfAX3rl4Te7LxfnXZmb+OtKsuwHTf8/JqSJcpM0o Nq4leMqQopt5amxf1QTqw1I2DRmgtZFurguebshxrjPSPvCTAKXrf1u+joOc1RiTh3 Sp/KWwkeEvF2w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 8/8] coresight: tmc: add QECP owned TMC driver Reply-To: sashiko-reviews@lists.linux.dev To: "Jie Gan" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261130-introduce-qcom-qecp-feature-v2-8-dff9ae87327b@oss.qualcomm.com> References: <20261130-introduce-qcom-qecp-feature-v2-0-dff9ae87327b@oss.qualcomm.com> <20261130-introduce-qcom-qecp-feature-v2-8-dff9ae87327b@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 07:33:38 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] coresight: tmc-qdcp: refcnt leak and ETR resume in tmc_qdcp_etr_disable_sink() - [Medium] coresight: tmc-qdcp: missing RWP >=3D RRP check in tmc_qdcp_etr_hw_state_valid() -- commit 568910aefc42f8c1badeac3b8f837013fcf6546b Author: Jie Gan coresight: tmc: add QECP owned TMC driver This commit adds a driver for CoreSight TMC ETR devices managed by the Qualcomm Embedded Co-Processor (QECP) firmware over the Qualcomm Debug Control Protocol (QDCP), and exports common TMC ETR helpers for it. > diff --git a/drivers/hwtracing/coresight/coresight-tmc-qdcp.c b/drivers/h= wtracing/coresight/coresight-tmc-qdcp.c > new file mode 100644 > index 0000000000000..0c73d2834be28 > --- /dev/null > +++ b/drivers/hwtracing/coresight/coresight-tmc-qdcp.c [ ... ] > +/* > + * The pointers come from the firmware, make sure they are inside a flat > + * buffer before using them as offsets. The scatter-gather sync already > + * rejects pointers outside of its table. > + */ > +static bool tmc_qdcp_etr_hw_state_valid(struct etr_buf *etr_buf, > + const struct tmc_etr_hw_state *state) > +{ > + u64 start =3D etr_buf->hwaddr, end =3D etr_buf->hwaddr + etr_buf->size; > + > + if (etr_buf->mode !=3D ETR_MODE_FLAT) > + return true; > + > + return state->rrp >=3D start && state->rrp < end && > + state->rwp >=3D start && state->rwp < end; > +} [Severity: Medium] Can tmc_qdcp_etr_hw_state_valid() accept state->rwp < state->rrp when TMC_STS_FULL is not set in state->sts? If the firmware returns start <=3D state->rwp < state->rrp < end without TMC_STS_FULL, tmc_etr_sync_flat_buf() computes a negative etr_buf->len, passes the wrap check because etr_buf->offset + etr_buf->len equals rwp - etr_buf->hwaddr, and calls dma_sync_single_for_cpu() with a huge size_t: drivers/hwtracing/coresight/coresight-tmc-etr.c:tmc_etr_sync_flat_buf() { ... etr_buf->offset =3D rrp - etr_buf->hwaddr; if (etr_buf->full) etr_buf->len =3D etr_buf->size; else etr_buf->len =3D rwp - rrp; if (etr_buf->offset + etr_buf->len > etr_buf->size) dma_sync_single_for_cpu(real_dev, flat_buf->daddr, etr_buf->size, DMA_FROM_DEVICE); else dma_sync_single_for_cpu(real_dev, flat_buf->daddr + etr_buf->offset, etr_buf->len, DMA_FROM_DEVICE); } [ ... ] > +static int tmc_qdcp_etr_disable_sink(struct coresight_device *csdev) > +{ > + struct tmc_drvdata *drvdata =3D dev_get_drvdata(csdev->dev.parent); > + struct tmc_qdcp_drvdata *qdata =3D to_tmc_qdcp(drvdata); > + int ret; > + > + mutex_lock(&qdata->lock); > + if (drvdata->reading) { > + mutex_unlock(&qdata->lock); > + return -EBUSY; > + } > + > + csdev->refcnt--; > + if (csdev->refcnt) { > + mutex_unlock(&qdata->lock); > + return -EBUSY; > + } > + > + /* > + * The path is torn down whatever is returned here. If the stop is not > + * confirmed, the buffer stays pinned and the stop is retried on the > + * next enable, read or removal. > + */ > + ret =3D tmc_qdcp_etr_disable_hw(qdata); > + drvdata->pid =3D -1; > + coresight_set_mode(csdev, CS_MODE_DISABLED); > + mutex_unlock(&qdata->lock); > + > + if (!ret) > + dev_dbg(&csdev->dev, "TMC-ETR disabled\n"); > + return ret; > +} [Severity: High] Does returning -EBUSY when drvdata->reading is true leak csdev->refcnt and leave csdev->mode set to CS_MODE_SYSFS? When a trace source is disabled while the miscdevice is open for reading, coresight_disable_sysfs() ignores the return value from sink_ops->disable() and tears down the path. Because tmc_qdcp_etr_disable_sink() returns before decrementing csdev->refcnt or setting csdev->mode to CS_MODE_DISABLED, clos= ing the miscdevice in tmc_qdcp_etr_read_unprepare() sees CS_MODE_SYSFS and re-enables the ETR in firmware with drvdata->sysfs_buf instead of freeing t= he buffer. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130-introduce-= qcom-qecp-feature-v2-0-dff9ae87327b@oss.qualcomm.com?part=3D8