Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796418392; b=wMJ0ycw1v5EYP+TSsfGJANwqqtuOvRnZvRkNDKQ1PGwqClgZH7NPU8jZK91/O+b6kgKV DWmoHEw8Sr8THk9Qnsx18nZx2K6IjVXX2t7k9dmuRtfFXqvRHNGlu6iCrLXFYc6+o4Lx7 HyxmxuXyfEgrYcXuThpQkhpMeDrPt3lBWxNUGaJZ+E5Ys1tZ3u9tRKHWSY6W776nsG+dV gj2+Ym2mnqdrxP14zZgHgRHNsxJU2gEs3vFzAiZDGrd9isz1K1Rq8QTfnNkO+E2PxOtNG 3jxZtVY0EUfznbcPFjDkKim6aDw22EzuV2siXlTptxTtHKfWA/M/f6EWkhZ2D0uFI7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796418392; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=4TAFt3sNDxlqSoNgjDrAdgpYgTmYdGtnumBRJkNqilo=; b=BRboBo8gNzi6uYEdxQ1IebRX3efwmoogQ5TwFSR268hoHb3EICUaSjB7CATrCnrgBwpK t4NBQ97rQVW8ScjqQqxozZDjz7KC2oG+OY9fRaMMwCOWqn6a1zjgCRTkwiO11Hq0eilYm JpKDPzQwFQXq7N08WcXbRi661iEgWeh8xILMIU7iyz9V4whqe8crN0EXUvaAJipARWOIl A7dwGY3HuGjdnflt/o7o71XAA7GjdfI6LbygtG5ZTxITxh0Ddey23E+/hwmODPe5oLfu5 70EToCX5EQoKtQagjRW24tKs9KE61eLXebKKuQ+JCO2lZWNA8V9eXjqXaS8Lb7fvR5g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dvbPBUGD; arc=none smtp.remote-ip=209.85.167.48 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6E70606A32C for ; Fri, 4 Dec 2026 21:06:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E6E70606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dvbPBUGD Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5bccecba199so1318786e87.1 for ; Fri, 04 Dec 2026 13:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796418390; x=1797023190; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=4TAFt3sNDxlqSoNgjDrAdgpYgTmYdGtnumBRJkNqilo=; b=dvbPBUGD1lHbut8uZ2/63tnabjcxN47IZjLdltLYic+beQN090J303yMeORahFbL31 GC03npY2G2zSXJPByd4lDGBum5ZThXYd/7T3ndGGxLF39/Y8cXdP//yooaC+BfBixMGi FcojWW8iR5abtpM/wRWYK7qQNBgpqWwqMMH187RLdQJ46h9kxiB+y7olY8mEnjGzzsfJ z5Y00iMElhvMMM7XusPeUiD9qxozqGE4T3dMwZqU5ZFB67EAuSHMMRXySoE1XIq6Q2P9 xCr5ZcZp/Wn32Oblfp7rVWfO/djAv9tlipKz3Xz3aH0LeicmPS6l4QI8bVDS1ItIjJML /lLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796418390; x=1797023190; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=4TAFt3sNDxlqSoNgjDrAdgpYgTmYdGtnumBRJkNqilo=; b=OeXsqfOoCjdUuUf6dDnegHVwLUw7uBBuy9UUKgq0rnAyEgc92Kj4AHkiO1IIF5x4+w 4Nr+vyu8tNUrl4WkAbcDjc9+CoGHr6VkRyp8TMvBxE0xQvDnKGmErZNju3zQ0XkIjcca Y5V6XXE1c9CFb2zq9x6MoOs81YJWSIGJRYHg2m05fSrb61r7JGRX1tuE9Mq306I92QLR eh83lcRdec6h01NpKkJL9A9rnJi7TCw/JOpKtHOmS1VOfYig8oBWDDq3qfnmgpW1FmA0 mLsjbdEBGo9UDJB5H+bEtHI9+qlgFCbvag4oRt8p/23MyznnX5nC4S25bv0autFiGdlx 1sFw== X-Forwarded-Encrypted: i=1; AL+hErE4c3NdilGk+feQgBFLPObY2b5Pr6D/7eE6cR9fh5TeuzZNzk820oNT0dwUFNiuz5M822oRqHh9dTDODLBF@vger.kernel.org X-Gm-Message-State: APuU4Z9UD89umj8muvzBtxs/KUaRyzXVqBsMf8iVWbufsUkvBhYDMnLT h4Aeu9g73NejpA4ys7fLxJFjFNDsOUyFNDaMKMZ33WSbr827ZnLJLLRH X-Gm-Gg: AZFdTZcovp7oyw/5rzuji8s59CEvE7Q0hHthIvSUazMor+KImGR5e2HkUVlVHUiBiqG JLvQrGqiigECOnxC7CvB+9OEYpdEnj1uzAFLH5uQzuOfa7nRTVQH5DLQJ3cnNHAd0+zIS1UziVC IFMH9wgKf7pFhv2cEJstEtCA+BDDl7JWoafqWUywlw4Z4Fp/UpD6KmJjoP3cTjwNoi1P4oUHMUh dTenYaLKRxYOtNeylqniLdJTdVo2QGqikXvmejwOL8KJC5uzpo7YtEaUxSnPFBUmVnYvycuXuQ5 dIUUlJTn8Zud90MBjfPH0c8GAdQ+IH6ukKcr0FtkEdEdtlpkHEOTNhWuYWUEhPqxzrAP/kHV8Jh 43yZAqEJFCGjktiNZCfPViel8hh6qPHevKQegOgHFH/uS+gfaGaznf7K6lhbzfiIiC0bw8ul4pA FqH99OzEyV3juFHk9NKe1YXDu040ULCtWzcwEDS4H5W0PfZfUCd7fcmDwZ6jowyd0LmTaW+BEvC UtLoG4DQzobeqGPayHUo2bbXtqM/2MfNfDHvbTsWVc2AAPbjAXhBEftMFEd7GqWju4gUeTTX+PV to5xpp7K+xmGYlPtSlcX6V4GXK1o3zwcNm9MeatS3cbmiq+D/S7dFwfVX9uMLdmgTT4BcaiIMkE e2mRHAFDtulPoW0kn9WZTLrTd9DrTrqst+kOKFZZEDfMpz/sQ1NpzyS+9LiEGPwigqVpmquWG4o tOkfHhHSRytU4sPvMWq3szO2RljgSDJTs= X-Received: by 2002:a05:6512:3509:b0:5c1:522e:3d44 with SMTP id 2adb3069b0e04-5c3861b9a00mr818467e87.23.1796418389697; Fri, 04 Dec 2026 13:06:29 -0800 (PST) Received: from kompukter-Systems ([193.25.177.41]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c384a77737sm914384e87.46.2026.12.04.13.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 13:06:29 -0800 (PST) From: Andrey Derkach To: Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn Cc: Simon Horman , Bjorn Andersson , netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH net v2] net: qrtr: smd: hold packets that arrive before probe has finished Date: Fri, 4 Dec 2026 23:06:24 +0200 Message-ID: <20261204210624.535124-1-gabin278@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The rpmsg core opens the channel before it calls qcom_smd_qrtr_probe(), and probe sets the driver data only after qrtr_endpoint_register(). A packet that arrives in between finds no driver data, and the callback returns -EAGAIN. SMD delivers such a packet again later, but GLINK ignores the return value, so the packet is lost. GLINK can also drop such a packet even earlier; that is fixed in a separate GLINK patch. The first packet the modem sends is its QRTR HELLO. If it is lost, our name service never tells the modem about TFTP or the service locator. The modem then never loads its WLAN firmware and crashes 40 seconds later ("fatal error without message"). On two sdm636 phones (Lenovo S5 Pro, Xiaomi Redmi Note 5 Pro), where udev loads qrtr-smd when the modem opens the channel, the HELLO is lost on some boots, here or in GLINK. With a 50 ms delay added to probe it is lost here on every boot. When qrtr-smd is built in or already loaded, probe runs in the GLINK worker, which answers the modem's request for a receive buffer only after probe, so nothing can arrive early. Keep the packets that arrive during probe in a device resource and pass them on once the endpoint is registered. The held packets are passed on and the driver data is set under one lock, so they go out before any packet that arrives later. If probe fails or the driver is unbound, the driver core frees whatever is still held. On SMD such a packet is now held too, instead of being left in the FIFO for SMD to deliver again. At most 32 packets are held: the remote sends only a few before it gets our HELLO, and no test held more than 3. Once 32 are held, the callback returns -EAGAIN as before, so SMD leaves the packet in its FIFO and reads it again after probe, and GLINK drops it. If a held packet can't be passed on (qrtr_endpoint_post() can fail to allocate memory), it is dropped with a warning. Fixes: 5052de8deff5 ("soc: qcom: smd: Transition client drivers from smd to rpmsg") Signed-off-by: Andrey Derkach --- Changes in v2 (both found by the netdev review bot in v1): - cap the held queue at 32 packets; when full, return -EAGAIN as before - check the result of passing on a held packet; warn if one is dropped v1: https://lore.kernel.org/r/20261203170532.3598521-1-gabin278@gmail.com/ GLINK can lose the same packet one step earlier, before the endpoint callback is set. That is fixed in "rpmsg: glink: set up the endpoint before sending the open-ack": https://lore.kernel.org/r/20261203170512.3597156-1-gabin278@gmail.com/ The two patches don't depend on each other. Tests, with qrtr-smd loaded by udev when the modem opens IPCRTR: - Redmi Note 5 Pro (sdm636), with the GLINK patch. This patch on the net tree's net/qrtr, built for a 7.3-based kernel (devm_kzalloc_obj() changed back to devm_kzalloc() for that): 0 of 17 boots bad (normal boots, a 50 ms delay in probe, udevd held off its CPU during probe, a failed first probe, the ADSP on); v1: 0 of 29. Test builds for the new paths: with the cap at 0 nothing was held and the HELLO was lost; with the first held packet failing to post, the warning was printed and the HELLO was lost. Without the patch, 6 of 6 boots where the HELLO arrived before probe had finished were bad. v1 on the 7.3 tree: 0 of 23 bad. - Lenovo S5 Pro (sdm636), 7.3, an earlier version of this patch, no GLINK patch: 5 of 18 normal boots bad before, 0 of 3 with it; with the delay 2 of 2 bad before, 0 of 2 with it. Not tested: a full mainline kernel; only the net tree's net/qrtr on a 7.3-based kernel. Who is affected: the modem crash needs the modem to open the first IPCRTR channel. With the ADSP booting by itself, the ADSP opened IPCRTR 1.5 s before the modem on all 13 boots. qrtr-smd was then loaded for the ADSP's channel, the modem's channel was probed later in the GLINK worker, and the modem was fine on all of them, also with the delay (2 of 2 bad without the ADSP). The ADSP sends its HELLO about 42 ms after it opens IPCRTR; on normal boots probe had finished by then. With the delay, the ADSP's HELLO was lost on 3 of 3 boots: it sent no second one, our name service never told it about our services, and its DIAG service never showed up. Nothing else visibly broke in 5 minutes (audio and sensor drivers were not loaded). With this patch the ADSP's HELLO was held and passed on (2 of 2 with v1, 2 of 2 with v2). On the plain sdm660 7.3 kernel (neither patch) with the ADSP on, the modem was fine on 10 of 10 boots; without the ADSP and with the delay, 2 of 2 were bad. qcom_smd_qrtr_remove() has a separate ordering problem (it unregisters the endpoint before it clears the driver data); I'll send that fix on its own. net/qrtr/smd.c | 138 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 129 insertions(+), 9 deletions(-) diff --git a/net/qrtr/smd.c b/net/qrtr/smd.c index 8b30b8275..f7b1fa340 100644 --- a/net/qrtr/smd.c +++ b/net/qrtr/smd.c @@ -16,15 +16,35 @@ struct qrtr_smd_dev { struct device *dev; }; -/* from smd to qrtr */ -static int qcom_smd_qrtr_callback(struct rpmsg_device *rpdev, - void *data, int len, void *priv, u32 addr) +/* The rpmsg core opens the channel before it calls our probe, so the remote + * may send packets before the QRTR endpoint is registered. SMD retries a + * packet whose callback fails, but GLINK drops it, and losing the remote's + * HELLO this way leaves the link without any service announcements. Packets + * that arrive while the driver data is not set are therefore held in a + * device resource. Probe posts them once the endpoint is registered; if + * probe fails or the driver is unbound, the driver core frees them. + * + * One lock for all devices is enough: the callback takes it only while the + * driver data is not set, and before probe there is no per-device place to + * keep a lock. + */ +static DEFINE_SPINLOCK(qrtr_smd_held_lock); + +/* Before it gets our HELLO the remote sends only a few packets: its HELLO + * and some NEW_SERVER messages. Once this many packets are held, the + * callback returns -EAGAIN, as it did before packets were held: SMD keeps + * the packet in its FIFO and stops reading, GLINK drops it. + */ +#define QRTR_SMD_MAX_HELD 32 + +static void qcom_smd_qrtr_held_release(struct device *dev, void *res) { - struct qrtr_smd_dev *qdev = dev_get_drvdata(&rpdev->dev); - int rc; + __skb_queue_purge(res); +} - if (!qdev) - return -EAGAIN; +static int qcom_smd_qrtr_post(struct qrtr_smd_dev *qdev, void *data, int len) +{ + int rc; rc = qrtr_endpoint_post(&qdev->ep, data, len); if (rc == -EINVAL) { @@ -36,6 +56,100 @@ 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) +{ + struct qrtr_smd_dev *qdev; + struct sk_buff_head *held; + struct sk_buff *skb; + unsigned long flags; + int rc = 0; + + spin_lock_irqsave(&qrtr_smd_held_lock, flags); + + /* probe may have finished in the meantime */ + qdev = dev_get_drvdata(&rpdev->dev); + if (qdev) { + rc = qcom_smd_qrtr_post(qdev, data, len); + goto out; + } + + held = devres_find(&rpdev->dev, qcom_smd_qrtr_held_release, NULL, NULL); + if (!held) { + held = devres_alloc(qcom_smd_qrtr_held_release, sizeof(*held), + GFP_ATOMIC); + if (!held) { + rc = -ENOMEM; + goto out; + } + __skb_queue_head_init(held); + devres_add(&rpdev->dev, held); + } + + if (skb_queue_len(held) >= QRTR_SMD_MAX_HELD) { + rc = -EAGAIN; + goto out; + } + + skb = alloc_skb(len, GFP_ATOMIC); + if (!skb) { + rc = -ENOMEM; + goto out; + } + skb_put_data(skb, data, len); + __skb_queue_tail(held, skb); + +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 void qcom_smd_qrtr_post_held(struct rpmsg_device *rpdev, + struct qrtr_smd_dev *qdev, + unsigned int *posted, unsigned int *dropped) +{ + struct sk_buff_head *held; + struct sk_buff *skb; + unsigned long flags; + int rc; + + 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))) { + rc = qcom_smd_qrtr_post(qdev, skb->data, skb->len); + if (rc) { + kfree_skb(skb); + (*dropped)++; + } else { + consume_skb(skb); + (*posted)++; + } + } + } + + dev_set_drvdata(&rpdev->dev, qdev); + + spin_unlock_irqrestore(&qrtr_smd_held_lock, flags); +} + +/* from smd to qrtr */ +static int qcom_smd_qrtr_callback(struct rpmsg_device *rpdev, + void *data, int len, void *priv, u32 addr) +{ + struct qrtr_smd_dev *qdev = dev_get_drvdata(&rpdev->dev); + + if (!qdev) + return qcom_smd_qrtr_hold(rpdev, data, len); + + return qcom_smd_qrtr_post(qdev, data, len); +} + /* from qrtr to smd */ static int qcom_smd_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb) { @@ -58,6 +172,7 @@ static int qcom_smd_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb) static int qcom_smd_qrtr_probe(struct rpmsg_device *rpdev) { + unsigned int posted = 0, dropped = 0; struct qrtr_smd_dev *qdev; int rc; @@ -73,9 +188,14 @@ static int qcom_smd_qrtr_probe(struct rpmsg_device *rpdev) if (rc) return rc; - dev_set_drvdata(&rpdev->dev, qdev); + qcom_smd_qrtr_post_held(rpdev, qdev, &posted, &dropped); + if (dropped) + dev_warn(&rpdev->dev, "dropped %u of %u packets held during probe\n", + dropped, posted + dropped); - dev_dbg(&rpdev->dev, "Qualcomm SMD QRTR driver probed\n"); + dev_dbg(&rpdev->dev, + "Qualcomm SMD QRTR driver probed, held packets: %u posted, %u dropped\n", + posted, dropped); return 0; } base-commit: 90ae4042bd9f35a9098d14b1a12a43df9b326e2b -- 2.53.0