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=1796384221; b=zlXZReOJ6XoOvcbp/O2KX2fygqQlgQD3xY/KYzmFbcDDS0um+PPUy4EtD905E4W3YAoS OdhF7Ovr9qbecGr+jP2cQJM3ZlAuQB9N61V5WoLluKNPphEc2dH6b5e9MwMXHhEbxGFOE pgT2aYkHYe+Kd6ymR3Cs2/yUC/jmQxyw45nvXGG5SiNLta+abmgJeUHA10aDUWRHAYxOM jQIYfkIciYMKvS+D/UdBQsDI9E035C9Zc6kg4oJDyXzYODf+kdZlczwk1bSGuSINFlixQ Js6IPaMapKI//yxDeZhZgEkBejMIza86mM24C/HF4mLlaCQrPmhqdjuNpaIqleoWH7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384221; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=++pr4dSvnUTkq+8TqfPLGp+2zKTldK6SZwLW8dVLxec=; b=Ln3c0d9SZ+pn4MntFiRkA9747nsxFcP9rLzxny5mO92MXEONuzeaXpokvIxzJZB9TT8y DqEaDRSGrmHZvP5L3xumnu2w6m+VJK5dcfeM7ixpsm8l/pYk9h2P/2GX1l+1D4ztWBdiq BkIrEEjv1+Py8aMVSBR3pDAzouWl8+F4k0XaojTdv7UYzx799IZxjVRc8KrBu7fCesPP9 Dh6+fFIqz4Y9S+Rs2RJYZltRZv0EpuRL9nVRAm3up7gQZCY+Yv7ySLs1Pa8i1flQpiYLW 8OPr66Aajm+iKI4UDuEN7MBPsyGKd5x6hCsNPvyA4m40SiiYxcOYsYmaPeNM21LQ/PA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=YWLXSidb; 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 D0487606A322; Fri, 4 Dec 2026 11:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=YWLXSidb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 493B61F000C2; Fri, 4 Dec 2026 11:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384221; bh=++pr4dSvnUTkq+8TqfPLGp+2zKTldK6SZwLW8dVLxec=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YWLXSidbKYOzPONp09+Y1XGAFRRXjocD4HkcrE9B/pYQnxK8Eyp2lYbIoxrJf/Az0 VpNaYMsM2I54iw/izew7wygZUGzidqnKsbMfsdPzAjAARf3BTK1b3qVHUjHQh5hdjf MM+XpuViW/aZi+Rh5TLDVmoQiUviPy/tfUvM1k80= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bernard Pidoux , Sasha Levin Subject: [PATCH 6.12 507/555] netrom: leave the busy state when the application reads Date: Fri, 4 Dec 2026 19:09:10 +0900 Message-ID: <20261204100628.193950014@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bernard Pidoux When the receive buffer of a socket is full we set NR_COND_OWN_RX_BUSY, send the choke flag, and keep the in-window frames that arrive on the resequencing queue. Two things then wait longer than needed: - The busy state is only left by the heartbeat, up to five seconds after the application has read its data, so the flow stops and starts in steps with a slow reader. - The heartbeat sends an INFO ACK but does not hand over the frames held meanwhile: they stay on the queue, are not acknowledged, and only reach the socket when another frame comes in. If the peer has nothing more to send, that is when its T1 expires and it sends them again (120 s by default). Move the resequencing loop into nr_reseq_deliver(), and add nr_check_rx_busy(), which leaves the busy state once the buffer is half empty, hands over the held frames, and answers at once with nr_enquiry_response(), so that the INFO ACK carries the new N(R) (and the choke or NAK flag when needed). Call it from the heartbeat as before, and from nr_recvmsg() after a message is consumed. Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS: A speaks NET/ROM itself and sends four INFO frames of 200 bytes to a socket on B with a minimal receive buffer; B reads only after 20 s and A sends nothing more. before: B reads a, b, c at 20.0 s; INFO ACK N(R)=3 without choke at 20.5 s (heartbeat); d never reaches the application after: B reads a, b, c, d at 20.0 s; INFO ACK N(R)=4 without choke at 20.15 s No KASAN, lockdep or WARN report. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Bernard Pidoux Assisted-by: Claude:claude-opus-5-5 (cherry picked from commit 719b06480659208bceae8e66ca34f4a4d5260689) Signed-off-by: Sasha Levin --- include/net/netrom.h | 1 + net/netrom/af_netrom.c | 7 ++++ net/netrom/nr_in.c | 87 ++++++++++++++++++++++++++++-------------- net/netrom/nr_timer.c | 9 +---- 4 files changed, 68 insertions(+), 36 deletions(-) diff --git a/include/net/netrom.h b/include/net/netrom.h index 3f6fd2f894344..72850f5f561e4 100644 --- a/include/net/netrom.h +++ b/include/net/netrom.h @@ -195,6 +195,7 @@ void nr_setup(struct net_device *); /* nr_in.c */ int nr_process_rx_frame(struct sock *, struct sk_buff *); +void nr_check_rx_busy(struct sock *sk); /* nr_loopback.c */ void nr_loopback_init(void); diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c index 99d9fe19d27f1..154367e6aad15 100644 --- a/net/netrom/af_netrom.c +++ b/net/netrom/af_netrom.c @@ -1248,6 +1248,13 @@ static int nr_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, skb_free_datagram(sk, skb); + /* Room was made: leave the busy state now if we can */ + local_bh_disable(); + bh_lock_sock(sk); + nr_check_rx_busy(sk); + bh_unlock_sock(sk); + local_bh_enable(); + release_sock(sk); return copied; } diff --git a/net/netrom/nr_in.c b/net/netrom/nr_in.c index f4f5b5fba15b3..9d2d1d853a586 100644 --- a/net/netrom/nr_in.c +++ b/net/netrom/nr_in.c @@ -192,6 +192,63 @@ static bool nr_reseq_has_ns(struct nr_sock *nrom, unsigned short ns) return false; } +/* + * Hand the frames held on the resequencing queue to the socket, in + * order, for as long as the socket takes them. + */ +static void nr_reseq_deliver(struct sock *sk) +{ + struct nr_sock *nrom = nr_sk(sk); + struct sk_buff_head temp_queue; + struct sk_buff *skbn; + unsigned short save_vr, ns; + int more; + + skb_queue_head_init(&temp_queue); + do { + save_vr = nrom->vr; + while ((skbn = skb_dequeue(&nrom->reseq_queue)) != NULL) { + ns = skbn->data[17]; + if (ns == nrom->vr) { + /* The flags of this frame, not of the one just received */ + more = skbn->data[19] & NR_MORE_FLAG; + if (nr_queue_rx_frame(sk, skbn, more) == 0) { + nrom->vr = (nrom->vr + 1) % NR_MODULUS; + } else { + nrom->condition |= NR_COND_OWN_RX_BUSY; + skb_queue_tail(&temp_queue, skbn); + } + } else if (nr_in_rx_window(sk, ns)) { + skb_queue_tail(&temp_queue, skbn); + } else { + kfree_skb(skbn); + } + } + while ((skbn = skb_dequeue(&temp_queue)) != NULL) + skb_queue_tail(&nrom->reseq_queue, skbn); + } while (save_vr != nrom->vr); +} + +/* + * Leave the busy state as soon as the application has made room in the + * receive buffer: hand over the frames held meanwhile and tell the peer + * at once, instead of waiting for the next heartbeat or the next frame. + * Called with the socket spinlock held. + */ +void nr_check_rx_busy(struct sock *sk) +{ + struct nr_sock *nrom = nr_sk(sk); + + if (nrom->state != NR_STATE_3 || + !(nrom->condition & NR_COND_OWN_RX_BUSY) || + atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf / 2) + return; + + nrom->condition &= ~NR_COND_OWN_RX_BUSY; + nr_reseq_deliver(sk); + nr_enquiry_response(sk); +} + /* * State machine for state 3, Connected State. * The handling of the timer(s) is in file nr_timer.c @@ -200,11 +257,8 @@ static bool nr_reseq_has_ns(struct nr_sock *nrom, unsigned short ns) static int nr_state3_machine(struct sock *sk, struct sk_buff *skb, int frametype) { struct nr_sock *nrom = nr_sk(sk); - struct sk_buff_head temp_queue; - struct sk_buff *skbn; - unsigned short save_vr; unsigned short nr, ns; - int queued = 0, more; + int queued = 0; nr = skb->data[18]; @@ -290,30 +344,7 @@ static int nr_state3_machine(struct sock *sk, struct sk_buff *skb, int frametype skb_queue_head(&nrom->reseq_queue, skb); if (nrom->condition & NR_COND_OWN_RX_BUSY) break; - skb_queue_head_init(&temp_queue); - do { - save_vr = nrom->vr; - while ((skbn = skb_dequeue(&nrom->reseq_queue)) != NULL) { - ns = skbn->data[17]; - if (ns == nrom->vr) { - /* The flags of this frame, not of the one just received */ - more = skbn->data[19] & NR_MORE_FLAG; - if (nr_queue_rx_frame(sk, skbn, more) == 0) { - nrom->vr = (nrom->vr + 1) % NR_MODULUS; - } else { - nrom->condition |= NR_COND_OWN_RX_BUSY; - skb_queue_tail(&temp_queue, skbn); - } - } else if (nr_in_rx_window(sk, ns)) { - skb_queue_tail(&temp_queue, skbn); - } else { - kfree_skb(skbn); - } - } - while ((skbn = skb_dequeue(&temp_queue)) != NULL) { - skb_queue_tail(&nrom->reseq_queue, skbn); - } - } while (save_vr != nrom->vr); + nr_reseq_deliver(sk); /* * Window is full, ack it immediately. */ diff --git a/net/netrom/nr_timer.c b/net/netrom/nr_timer.c index efa5cf6d7bf55..f49a421e8e5db 100644 --- a/net/netrom/nr_timer.c +++ b/net/netrom/nr_timer.c @@ -133,14 +133,7 @@ static void nr_heartbeat_expiry(struct timer_list *t) /* * Check for the state of the receive buffer. */ - if (atomic_read(&sk->sk_rmem_alloc) < (sk->sk_rcvbuf / 2) && - (nr->condition & NR_COND_OWN_RX_BUSY)) { - nr->condition &= ~NR_COND_OWN_RX_BUSY; - nr->condition &= ~NR_COND_ACK_PENDING; - nr->vl = nr->vr; - nr_write_internal(sk, NR_INFOACK); - break; - } + nr_check_rx_busy(sk); break; } -- 2.53.0