* [PATCH v2 0/2] rpmsg: glink: smem: robustness and debuggability fixes
@ 2026-06-17 11:07 Chunkai Deng
2026-06-17 11:07 ` [PATCH v2 1/2] rpmsg: glink: smem: Use device name as IRQ name Chunkai Deng
2026-06-17 11:07 ` [PATCH v2 2/2] rpmsg: glink: smem: Add WARN_ON_ONCE for FIFO index invariants Chunkai Deng
0 siblings, 2 replies; 4+ messages in thread
From: Chunkai Deng @ 2026-06-17 11:07 UTC (permalink / raw)
To: Bjorn Andersson, Mathieu Poirier
Cc: linux-arm-msm, linux-remoteproc, linux-kernel, chris.lew,
tony.truong, Chunkai Deng, Dmitry Baryshkov, stable
This series makes two small improvements to the SMEM GLINK transport:
1. Add WARN_ON_ONCE checks in the FIFO read/write helpers to catch
and report broken index invariants early, rather than proceeding
with an out-of-bounds offset into the FIFO.
2. Pass dev_name(&smem->dev) as the IRQ name instead of the static
string "glink-smem". On platforms with multiple remoteprocs each
SMEM GLINK instance registers its own IRQ, and the unique device
name makes each entry in /proc/interrupts identifiable without
adding a new struct field.
Signed-off-by: Chunkai Deng <chunkai.deng@oss.qualcomm.com>
---
Changes in v2:
- Drop the modulo patch ("rpmsg: glink: smem: Use modulo for FIFO
tail wrap-around in rx_advance"); per review, it papers over an
unreachable scenario without restoring a valid protocol state.
Proper RX-side validation of chunk_size against rx_pipe->length
will be sent as a separate patch.
- "rpmsg: glink: smem: Add WARN_ON_ONCE for FIFO index invariants":
- Drop the trailing comma after "skipped" in the commit message
body (per review).
- Add Fixes: caf989c350e8 ("rpmsg: glink: Introduce glink smem
based transport") and Cc: stable@vger.kernel.org (per review).
- Carry Dmitry's Reviewed-by on "rpmsg: glink: smem: Use device
name as IRQ name" (no code changes since v1).
- Link to v1: https://patch.msgid.link/20260603-rpmsg-improvements-v1-0-dcfc22ed69f7@oss.qualcomm.com
---
Chunkai Deng (2):
rpmsg: glink: smem: Use device name as IRQ name
rpmsg: glink: smem: Add WARN_ON_ONCE for FIFO index invariants
drivers/rpmsg/qcom_glink_smem.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
---
base-commit: f7af91adc230aa99e23330ecf85bc9badd9780ad
change-id: 20260601-rpmsg-improvements-643a6e133f66
Best regards,
--
Chunkai Deng <chunkai.deng@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 1/2] rpmsg: glink: smem: Use device name as IRQ name 2026-06-17 11:07 [PATCH v2 0/2] rpmsg: glink: smem: robustness and debuggability fixes Chunkai Deng @ 2026-06-17 11:07 ` Chunkai Deng 2026-06-17 11:07 ` [PATCH v2 2/2] rpmsg: glink: smem: Add WARN_ON_ONCE for FIFO index invariants Chunkai Deng 1 sibling, 0 replies; 4+ messages in thread From: Chunkai Deng @ 2026-06-17 11:07 UTC (permalink / raw) To: Bjorn Andersson, Mathieu Poirier Cc: linux-arm-msm, linux-remoteproc, linux-kernel, chris.lew, tony.truong, Chunkai Deng, Dmitry Baryshkov A SoC typically has multiple remoteprocs (ADSP, MPSS, CDSP, etc.), each registering its own SMEM GLINK instance. With the static name "glink-smem" all instances appear identically in /proc/interrupts, making it impossible to associate an IRQ with a specific remote processor. Pass dev_name(&smem->dev) to devm_request_irq() instead. The device name is already set to "<parent>:<edge-node>" which uniquely identifies each instance without requiring an additional field in the driver struct. Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Signed-off-by: Chunkai Deng <chunkai.deng@oss.qualcomm.com> --- drivers/rpmsg/qcom_glink_smem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/rpmsg/qcom_glink_smem.c b/drivers/rpmsg/qcom_glink_smem.c index 62adc4db2317..edab912557ac 100644 --- a/drivers/rpmsg/qcom_glink_smem.c +++ b/drivers/rpmsg/qcom_glink_smem.c @@ -307,7 +307,7 @@ struct qcom_glink_smem *qcom_glink_smem_register(struct device *parent, smem->irq = of_irq_get(smem->dev.of_node, 0); ret = devm_request_irq(&smem->dev, smem->irq, qcom_glink_smem_intr, IRQF_NO_SUSPEND | IRQF_NO_AUTOEN, - "glink-smem", smem); + dev_name(&smem->dev), smem); if (ret) { dev_err(&smem->dev, "failed to request IRQ\n"); goto err_put_dev; -- 2.34.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] rpmsg: glink: smem: Add WARN_ON_ONCE for FIFO index invariants 2026-06-17 11:07 [PATCH v2 0/2] rpmsg: glink: smem: robustness and debuggability fixes Chunkai Deng 2026-06-17 11:07 ` [PATCH v2 1/2] rpmsg: glink: smem: Use device name as IRQ name Chunkai Deng @ 2026-06-17 11:07 ` Chunkai Deng 2026-07-14 3:11 ` Bjorn Andersson 1 sibling, 1 reply; 4+ messages in thread From: Chunkai Deng @ 2026-06-17 11:07 UTC (permalink / raw) To: Bjorn Andersson, Mathieu Poirier Cc: linux-arm-msm, linux-remoteproc, linux-kernel, chris.lew, tony.truong, Chunkai Deng, stable The FIFO read/write helpers assume the head and tail indices stay within [0, pipe->native.length) and use them directly as offsets into the mapped FIFO region. If that invariant is ever broken, the subsequent memcpy or memcpy_fromio would access memory outside the FIFO. Add WARN_ON_ONCE checks in these helpers so a broken invariant is caught and reported once, and the out-of-bounds access is skipped instead of proceeding silently. Fixes: caf989c350e8 ("rpmsg: glink: Introduce glink smem based transport") Cc: stable@vger.kernel.org Signed-off-by: Chunkai Deng <chunkai.deng@oss.qualcomm.com> --- drivers/rpmsg/qcom_glink_smem.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/rpmsg/qcom_glink_smem.c b/drivers/rpmsg/qcom_glink_smem.c index edab912557ac..42ad315d7910 100644 --- a/drivers/rpmsg/qcom_glink_smem.c +++ b/drivers/rpmsg/qcom_glink_smem.c @@ -86,9 +86,14 @@ static size_t glink_smem_rx_avail(struct qcom_glink_pipe *np) tail = le32_to_cpu(*pipe->tail); if (head < tail) - return pipe->native.length - tail + head; + len = pipe->native.length - tail + head; else - return head - tail; + len = head - tail; + + if (WARN_ON_ONCE(len > pipe->native.length)) + len = 0; + + return len; } static void glink_smem_rx_peek(struct qcom_glink_pipe *np, @@ -103,6 +108,9 @@ static void glink_smem_rx_peek(struct qcom_glink_pipe *np, if (tail >= pipe->native.length) tail -= pipe->native.length; + if (WARN_ON_ONCE(tail >= pipe->native.length)) + return; + len = min_t(size_t, count, pipe->native.length - tail); if (len) memcpy_fromio(data, pipe->fifo + tail, len); @@ -141,6 +149,9 @@ static size_t glink_smem_tx_avail(struct qcom_glink_pipe *np) else avail = tail - head; + if (WARN_ON_ONCE(avail > pipe->native.length)) + avail = 0; + if (avail < (FIFO_FULL_RESERVE + TX_BLOCKED_CMD_RESERVE)) avail = 0; else @@ -155,6 +166,9 @@ static unsigned int glink_smem_tx_write_one(struct glink_smem_pipe *pipe, { size_t len; + if (WARN_ON_ONCE(head >= pipe->native.length)) + return head; + len = min_t(size_t, count, pipe->native.length - head); if (len) memcpy(pipe->fifo + head, data, len); -- 2.34.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] rpmsg: glink: smem: Add WARN_ON_ONCE for FIFO index invariants 2026-06-17 11:07 ` [PATCH v2 2/2] rpmsg: glink: smem: Add WARN_ON_ONCE for FIFO index invariants Chunkai Deng @ 2026-07-14 3:11 ` Bjorn Andersson 0 siblings, 0 replies; 4+ messages in thread From: Bjorn Andersson @ 2026-07-14 3:11 UTC (permalink / raw) To: Chunkai Deng Cc: Mathieu Poirier, linux-arm-msm, linux-remoteproc, linux-kernel, chris.lew, tony.truong, stable On Wed, Jun 17, 2026 at 07:07:14PM +0800, Chunkai Deng wrote: > The FIFO read/write helpers assume the head and tail indices stay within > [0, pipe->native.length) and use them directly as offsets into the > mapped FIFO region. If that invariant is ever broken, the subsequent > memcpy or memcpy_fromio would access memory outside the FIFO. > > Add WARN_ON_ONCE checks in these helpers so a broken invariant is > caught and reported once, and the out-of-bounds access is skipped > instead of proceeding silently. > > Fixes: caf989c350e8 ("rpmsg: glink: Introduce glink smem based transport") > Cc: stable@vger.kernel.org > Signed-off-by: Chunkai Deng <chunkai.deng@oss.qualcomm.com> > --- > drivers/rpmsg/qcom_glink_smem.c | 18 ++++++++++++++++-- > 1 file changed, 16 insertions(+), 2 deletions(-) > > diff --git a/drivers/rpmsg/qcom_glink_smem.c b/drivers/rpmsg/qcom_glink_smem.c > index edab912557ac..42ad315d7910 100644 > --- a/drivers/rpmsg/qcom_glink_smem.c > +++ b/drivers/rpmsg/qcom_glink_smem.c > @@ -86,9 +86,14 @@ static size_t glink_smem_rx_avail(struct qcom_glink_pipe *np) > tail = le32_to_cpu(*pipe->tail); > > if (head < tail) > - return pipe->native.length - tail + head; > + len = pipe->native.length - tail + head; > else > - return head - tail; > + len = head - tail; > + > + if (WARN_ON_ONCE(len > pipe->native.length)) > + len = 0; > + > + return len; Looks good. > } > > static void glink_smem_rx_peek(struct qcom_glink_pipe *np, > @@ -103,6 +108,9 @@ static void glink_smem_rx_peek(struct qcom_glink_pipe *np, > if (tail >= pipe->native.length) > tail -= pipe->native.length; > > + if (WARN_ON_ONCE(tail >= pipe->native.length)) > + return; > + Wouldn't it be preferable to check the original "tail", before the addition and subtraction? Perhaps also validate that `offset + count < pipe->native.length`? > len = min_t(size_t, count, pipe->native.length - tail); > if (len) > memcpy_fromio(data, pipe->fifo + tail, len); > @@ -141,6 +149,9 @@ static size_t glink_smem_tx_avail(struct qcom_glink_pipe *np) > else > avail = tail - head; > > + if (WARN_ON_ONCE(avail > pipe->native.length)) > + avail = 0; `head - tail < length` does not guarantee that head and tail are valid offsets within the fifo, so I think you should check both of them instead of the difference. > + > if (avail < (FIFO_FULL_RESERVE + TX_BLOCKED_CMD_RESERVE)) > avail = 0; > else > @@ -155,6 +166,9 @@ static unsigned int glink_smem_tx_write_one(struct glink_smem_pipe *pipe, > { > size_t len; > > + if (WARN_ON_ONCE(head >= pipe->native.length)) > + return head; This makes glink_smem_tx_write_one() do nothing, twice. But then we return to glink_smem_tx_write() which will adjust and update pipe->head; possible subtract head into the valid range. I think it would be better to move this check up to glink_smem_tx_write(). And also check that `hlen + dlen < pipe->native.length`? Regards, Bjorn > + > len = min_t(size_t, count, pipe->native.length - head); > if (len) > memcpy(pipe->fifo + head, data, len); > > -- > 2.34.1 > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-14 3:11 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-06-17 11:07 [PATCH v2 0/2] rpmsg: glink: smem: robustness and debuggability fixes Chunkai Deng 2026-06-17 11:07 ` [PATCH v2 1/2] rpmsg: glink: smem: Use device name as IRQ name Chunkai Deng 2026-06-17 11:07 ` [PATCH v2 2/2] rpmsg: glink: smem: Add WARN_ON_ONCE for FIFO index invariants Chunkai Deng 2026-07-14 3:11 ` Bjorn Andersson
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.