From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796516576; b=XSRPlidhppR/nSsVclpv+BQYszU9jUzvWLYVz8xr7OQ9Nt7qiHLo44BufU15hgXJkhUa Gfp9Hv1n2PG8ourbA9NXMb7HODkFtiBPHFTdXju5/l9BFSezMhk3DtxpKsfBXwccHxFPE OCphm9MSJRcHXNt/Xk2iqlCIHA2geOF63sJpLxeP6l91hkXKEeKO0Rs6fnX6Z70FKb4qN +8MaWmtNrIeXXveodSGckWRLIMiBx87/bOqx8cZ/7D86ZXC+x48YEtGtYquMN8Bpunkom 9V/k+u/PyJGiLxMqWgvpbWCJPC4Uh1AsCCw5sD5u81q+2S7W5gOwUPSc8/b2adGRZ/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796516576; 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=aiQo0y2e4deyCNF1g8Ls7zxAf/tLLiH38Xn+ER2Zb44=; b=lWeFn9ekFJ1EILQe/a1/bTIRF0gFvMj3fUL+Oaw6f/THxC+M1fssK6BQ7gdVp751HsKX cAwlMfm2kIYvXJ/aIQPjeSdJ+V5EipffNVcs7zvVG5lVlpbtpdmMQyDKrPAs0EdM6Savf jQsO1A/R5+GOVufCM5hLu1bsuwVfJPzRnrMso+IOO64OJ580vpFr9VFKQrvwI+nnaTknD 155kGfZsCstHorQHAIRKAD7C/q0gxOT1hcgx7xI7L6NDFCVwHz3o864C9ABl0xdgKtqtP 34ImPC4J8dyheyz/uE528QYjlvF3NIj71P4If23pXW+ymz1b0/McIPDt8Acsiy6WVtA== 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=tVhTr5lK; arc=none smtp.remote-ip=209.85.208.177 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 4C46A606A322 for ; Sun, 6 Dec 2026 00:22:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4C46A606A322 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=tVhTr5lK Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-3aff7fb5faeso18746931fa.0 for ; Sat, 05 Dec 2026 16:22:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796516574; x=1797121374; 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=aiQo0y2e4deyCNF1g8Ls7zxAf/tLLiH38Xn+ER2Zb44=; b=tVhTr5lKrBn/TLxpaeXvlx6rvnvxCfzM/u9JTdXDEmwiS0jvYcb7jMQC6G4mCEwgkj nNoX3qcGl64iRaBSyN6cHjLS9Ur0x3tkx0Gu/4SEe41/81ncKIFr23Bcj9Y0y50fli72 5OT6g8RWIXtYu7fWYFUt0H6lYMFwUH30mLgiCM1klR+zo7yjUzZEACMa6HZ+ibITQAW4 LLSsGIKyMCpWLyLtjziA4cMl4v+RvqNnm/vXLish92TB7QyMQBPfhwfQT2k/fJsODAM9 devrDFoK7SXcyuV+qrKg4qZD9kmFI4C383kphS76ST24aYPey2onDTbuxU7/+HHrecMC hMng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796516574; x=1797121374; 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=aiQo0y2e4deyCNF1g8Ls7zxAf/tLLiH38Xn+ER2Zb44=; b=VS+fDQBZUi7Itqwb9dMa5jYyfug4JJMesk3g5yPgDDiZ71YwtDbh7S0dinCHwGz+Yj TK5DDzAvy7MeDz+fHwkpFdjAB2LfZrJ9ItnocolABJXCKDOu9fWK2KbkweZRxmpY9Hh8 UeKU5xNRaDK7UHsPW4wCgUkn55lHnOt8Ik9pEilHNRRkYVrOjTM64AxYYe+WplKBZTEV oxpLkt3ikCd+oZYmR0z7av0iUIeQ/z/S4gyjaSGC5OxXZL0WnN91fTlnRrfwalrBgN7Y 1zHWtwfcTecyDizQ9eKqBklYWiDnMud+0oJu5omuoQRc8ppuoe/Z3QKEIFI109aXlUve lWFQ== X-Forwarded-Encrypted: i=1; AL+hErFSAEbNlc9aIwKP43dyzWKTP6unWkey/gw5WUAMBJaQNtMoBsdl4E3NlMYZ7EFfVoNAVCUsMmA=@vger.kernel.org X-Gm-Message-State: AB4q+uGmfLqHbf/nm3RRMX7YFHQUUIEiM8LaMxantv0cQ8hfAR2dmAz4 I5QBklLkh8HqL543OIIvYU+lLAjrIsBoWpZGGP8g9ROp1ODj0zbnbO4k X-Gm-Gg: AZFdTZfTJ7iK856LHLnPzRHvT9jkXhNF0duuBoR3hn76LJv2wIUfRJhza/S8WbNowUs JDD1sdW1c+rgIbF0Hew/TciPiDWCP0a6P66Jghq9RC6+IBCOR3CESG+ACuGkXuVsG6EVYwa4ysz khRf5iOeXlHbmEGMjdjKMoSp+xTvl88plB7FMKNpfq89AqRLVWSa1Win2sZqMqlsbb8SuXuFeI5 z3LUXU33pVHdV7LYept0xWnWaqwrjqH/HwL4M+EOsXraw3uO3wrp98Yq58CFicEUBDhaLWYn5yr Zb0RLx8stLHU3oinLins1Su9DwB9BCRWIKQZzAi7+GzFqFBPJ+YE+0N5NnkrhaNwNGGok2Pg/rH ZUkH3Gs6KqMImyMf+cN/tFyG3MrkSRPAuVUcKBSVWKNHoY3gKN+VnSdx2roqklxV4WkNKtTwdTe rBuKCUfUhKdzYlvh3nlJu0R4WUNBbMp1s/6fVb4BWW7XeQHOdtlZHAXuY8bB02d/Ehthhms5C2e 7elWR1mwch/1fQ5y5Amwg5cCqflVAHNmdJMI6Ct53YgPZTb+v5H3cDOzvHCL6Vzuar742gtlrcn TZBsLyqCdBpvkaDlMl2k81wZkNZEfkmQhi2ptBx9VEBQF2bKIlzuJowgSBbp8Fv+4dA1il0Dpvs wIhnKUcCy8PrbZ6JBUvLS6btNwcxjyBxZ5RXUJ2nZZhmGXQGue3SpA2QsGrkDbyrDKSd05UNMvP kZrfb8oOqst46J5AspkLcsakJOx/VamtwCwda+BFc3jPdsUv/VxgTb X-Received: by 2002:a05:6512:2382:b0:5bf:a6e9:4cf with SMTP id 2adb3069b0e04-5c3861acddamr1225253e87.41.1796516574076; Sat, 05 Dec 2026 16:22:54 -0800 (PST) Received: from kompukter-Systems ([193.25.177.41]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3b004d14a61sm20884091fa.8.2026.12.05.16.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 16:22:53 -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 v3] net: qrtr: smd: hold packets that arrive before probe has finished Date: Sun, 6 Dec 2026 02:22:48 +0200 Message-ID: <20261206002248.1636316-1-gabin278@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: netdev@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 driver data is set only when no held packet is left, so a packet that arrives in the meantime is held behind the others, and all of them 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. Probe passes the held packets on one at a time, with interrupts enabled. If one can't be passed on for lack of memory, probe sleeps for a moment and tries again, as SMD would have done, and drops it with a warning only after 10 tries. A packet that qrtr refuses is not tried again, but it is counted as dropped too. Fixes: 5052de8deff5 ("soc: qcom: smd: Transition client drivers from smd to rpmsg") Signed-off-by: Andrey Derkach --- Changes in v3 (both found by the netdev review bot in v2): - pass held packets on with interrupts enabled; retry -ENOMEM, 10 tries - count every failure as dropped; print the last error in the warning 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 v2: https://lore.kernel.org/r/20261204210624.535124-1-gabin278@gmail.com/ 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 18 boots bad (normal boots, a 50 ms delay in probe, udevd held off its CPU during probe, a failed first probe, the ADSP on); v2: 0 of 17; v1: 0 of 29. Test builds for the new paths: a faked -ENOMEM on the first try was tried again and the packet went through; with -ENOMEM on every try the warning came after 10 tries (0.16 s) and the HELLO was lost; a faked -EINVAL was not tried again and was counted as dropped. 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, v2 and v3 each). 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 | 173 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 164 insertions(+), 9 deletions(-) diff --git a/net/qrtr/smd.c b/net/qrtr/smd.c index 8b30b8275..6645dc0dc 100644 --- a/net/qrtr/smd.c +++ b/net/qrtr/smd.c @@ -4,6 +4,7 @@ * Copyright (c) 2013, The Linux Foundation. All rights reserved. */ +#include #include #include #include @@ -16,15 +17,45 @@ 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, and + * sets the driver data only when none is left; 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 + +/* qrtr_endpoint_post() allocates with GFP_ATOMIC. When that failed before + * packets were held, SMD kept the packet in its FIFO and tried it again + * later. So probe tries a held packet again too, after a short sleep that + * gives reclaim a chance: at most nine sleeps per packet (0.1 to 0.2 s, + * depending on HZ), and only while atomic allocations keep failing. + */ +#define QRTR_SMD_POST_TRIES 10 +#define QRTR_SMD_POST_RETRY_MS 10 + +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 +67,122 @@ 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; +} + +/* Take the next held packet. If none is left, set the driver data under the + * same lock, so that from now on the callback posts directly. Until then, + * packets that arrive are held behind the ones being posted. + */ +static struct sk_buff *qcom_smd_qrtr_next_held(struct rpmsg_device *rpdev, + struct qrtr_smd_dev *qdev) +{ + struct sk_buff_head *held; + struct sk_buff *skb = NULL; + 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) + skb = __skb_dequeue(held); + if (!skb) + dev_set_drvdata(&rpdev->dev, qdev); + + spin_unlock_irqrestore(&qrtr_smd_held_lock, flags); + + return skb; +} + +/* Post the packets held during probe, one at a time, with interrupts + * enabled, then publish @qdev (see qcom_smd_qrtr_next_held()). Runs in + * probe, so it may sleep between tries. A packet that qrtr refuses, or that + * still can't be allocated after the last try, is dropped. + */ +static void qcom_smd_qrtr_post_held(struct rpmsg_device *rpdev, + struct qrtr_smd_dev *qdev, + unsigned int *posted, unsigned int *dropped, + int *last_err) +{ + struct sk_buff *skb; + int tries, rc; + + while ((skb = qcom_smd_qrtr_next_held(rpdev, qdev))) { + for (tries = 1; ; tries++) { + rc = qrtr_endpoint_post(&qdev->ep, skb->data, skb->len); + if (rc != -ENOMEM || tries == QRTR_SMD_POST_TRIES) + break; + msleep(QRTR_SMD_POST_RETRY_MS); + } + + if (rc) { + *last_err = rc; + kfree_skb(skb); + (*dropped)++; + } else { + consume_skb(skb); + (*posted)++; + } + } +} + +/* 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,7 +205,9 @@ 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 last_err = 0; int rc; qdev = devm_kzalloc_obj(&rpdev->dev, *qdev); @@ -73,9 +222,15 @@ 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, &last_err); + if (dropped) + dev_warn(&rpdev->dev, + "dropped %u of %u packets held during probe, last error %d\n", + dropped, posted + dropped, last_err); - 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