Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: gabin278@gmail.com
Cc: mani@kernel.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
	horms@kernel.org, andersson@kernel.org, netdev@vger.kernel.org,
	linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH net] net: qrtr: smd: hold packets that arrive before probe has finished
Date: Fri, 04 Dec 2026 17:46:28 +0000	[thread overview]
Message-ID: <179640638895.3146.13536976927342826919@kernel.org> (raw)
In-Reply-To: <20261203170532.3598521-1-gabin278@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] On SMD, a packet held during probe can now be lost, and
  nothing logs it.
- [Medium] While drvdata is NULL, the remote can fill the held queue
  without limit.

--

net: qrtr: smd: hold packets that arrive before probe has finished

This patch changes qrtr-smd so that packets arriving before probe has set
the driver data are held in a devres-backed sk_buff_head. Once the QRTR
endpoint is registered, the held packets are posted and drvdata is
published under a global spinlock. The goal is to stop losing the remote's
HELLO on GLINK, which ignores the callback's return value.

> diff --git a/net/qrtr/smd.c b/net/qrtr/smd.c
> index 8b30b8275a2d9..e9e984db1e961 100644
> --- a/net/qrtr/smd.c
> +++ b/net/qrtr/smd.c

[ ... ]

> @@ -36,6 +49,91 @@ static int qcom_smd_qrtr_callback(struct rpmsg_device *rpdev,
>  	return rc;
>  }
>  
> +static int qcom_smd_qrtr_hold(struct rpmsg_device *rpdev, void *data, int len)
> +{

[ ... ]

> +	skb = alloc_skb(len, GFP_ATOMIC);
> +	if (!skb) {
> +		rc = -ENOMEM;
> +		goto out;
> +	}
> +	skb_put_data(skb, data, len);
> +	__skb_queue_tail(held, skb);

[Severity: Medium]
Is there a limit on how much the remote can queue here while drvdata is
NULL?

Each packet gets a GFP_ATOMIC copy, which is added to the held queue
without any check on qlen or total bytes, and the function then returns 0.
qcom_smd_channel_recv_single() only skips qcom_smd_channel_advance() when
the callback returns a negative value. So SMD keeps reading from the FIFO.
What used to be back-pressure in shared memory turns into kernel
allocations.

The window includes qrtr_endpoint_register(), which does GFP_KERNEL
allocations and takes qrtr_node_lock. Under memory pressure the window can
get longer.

The window also seems to open again on unbind. rpmsg_dev_remove() calls
rpdrv->remove() before rpmsg_destroy_ept(), and qcom_smd_qrtr_remove()
does:

	dev_set_drvdata(&rpdev->dev, NULL);

Packets that arrive between those two calls are copied, only to be freed
by devres_release_all().

Later, qcom_smd_qrtr_post_held() drains the whole queue through
qrtr_endpoint_post(). That is one more GFP_ATOMIC allocation per packet,
plus sock_queue_rcv_skb() and the wakeups. All of it runs inside
spin_lock_irqsave() on the global qrtr_smd_held_lock, which every qrtr-smd
device shares.

Does the time with IRQs off on the probing CPU then grow with the number
of packets the remote queued?

Would it help to cap the held queue, returning -EAGAIN on SMD when the cap
is reached? The queue could also be spliced out under the lock, so that
the posting happens with IRQs enabled.

> +
> +out:
> +	spin_unlock_irqrestore(&qrtr_smd_held_lock, flags);
> +
> +	return rc;
> +}
> +
> +/* Post the packets held during probe, then publish @qdev so the callback
> + * posts directly. Both happen under the lock, so held packets are posted
> + * before any packet that arrives later.
> + */
> +static unsigned int qcom_smd_qrtr_post_held(struct rpmsg_device *rpdev,
> +					    struct qrtr_smd_dev *qdev)
> +{
> +	struct sk_buff_head *held;
> +	unsigned int count = 0;
> +	struct sk_buff *skb;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&qrtr_smd_held_lock, flags);
> +
> +	held = devres_find(&rpdev->dev, qcom_smd_qrtr_held_release, NULL, NULL);
> +	if (held) {
> +		while ((skb = __skb_dequeue(held))) {
> +			qcom_smd_qrtr_post(qdev, skb->data, skb->len);
> +			consume_skb(skb);
> +			count++;
> +		}
> +	}

[Severity: Medium]
Can a held packet be lost here with nothing logged? The return value of
qcom_smd_qrtr_post() is ignored, and the skb is consumed and counted
whatever happens.

qrtr_endpoint_post() can return -ENOMEM:

	skb = __netdev_alloc_skb(NULL, len, GFP_ATOMIC | __GFP_NOWARN);
	if (!skb)
		return -ENOMEM;

Before this patch, a packet that arrived on SMD while drvdata was NULL got
-EAGAIN. qcom_smd_channel_recv_single() then left it in the RX FIFO to be
delivered again:

	ret = ept->cb(ept->rpdev, ptr, len, ept->priv, RPMSG_ADDR_ANY);
	if (ret < 0)
		return ret;

	/* Only forward the tail if the client consumed the data */
	qcom_smd_channel_advance(channel, len);

Now qcom_smd_qrtr_hold() copies the packet and returns 0. SMD advances the
tail, and the devres queue holds the only copy. If the GFP_ATOMIC
allocation fails during this drain, the packet is gone for good. That
packet is often the remote's HELLO. The "held packets: %u" debug line
still counts it as passed on.

The commit message doesn't mention that SMD moves from keeping the packet
in the FIFO for a retry to copying and holding it. Is that change
intended?

Could rc be checked here, so the code at least warns or keeps the packet?
Another option would be to keep returning -EAGAIN on SMD.

> +
> +	dev_set_drvdata(&rpdev->dev, qdev);
> +
> +	spin_unlock_irqrestore(&qrtr_smd_held_lock, flags);
> +
> +	return count;
> +}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203170532.3598521-1-gabin278%40gmail.com

  reply	other threads:[~2026-12-04 17:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 17:05 [PATCH net] net: qrtr: smd: hold packets that arrive before probe has finished Andrey Derkach
2026-12-04 17:46 ` netdev-bot+sashiko [this message]
2026-12-04 21:06   ` Andrey Derkach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179640638895.3146.13536976927342826919@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andersson@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gabin278@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox