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=1796382781; b=xsJ7uejUbrq5iCy9MqQTrk+kg2lDFA2HcGa0p+irFi4UEPH2oj+GL0OEl0GjKDfjAn+K G8f9GbMrRh9uzyqyIU38R+886naPCYqJgt4Rqmua/li1r7Z+fTcRnmLTSnBDsRxc6R/F6 aMrQ19Mq0KDC+AjzIKk24SVRjKbjmiooYrBMaOpHTA+iPfQZnKYTlU53Pm3APBXHiF1tT DJkCDTOK2KQvjgyfIEnQNiYDVfpgGE9cgij8EOXa+iy5CzHaBkZXRSCVedoYRRGka16W/ noRWM75iMKHT3pTmZvj/mM3RGPs3eoqQEZResM+LaqYb3sHqTBDp2v79ee1IgXaLt2A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382781; 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=vFnH5k9gAAKndd/fY/WXuOaIqXGWXH5l7d8DKPRLnkc=; b=Mo5O5r4fCC9KVFroVxJq4DcGd/k1hNlwwzPzpNW415ST5s06S9bMSzZ9N6tABauUfSPT kmrjb4QQFKqmMHi6hC7TThGYclAj4jUEFT51uZRKukpeQAnHvMHr7mPyeJEhlx/dKcWSw 6GV8LWN0HOibM3cNTGXilRhHmaIKsIVyMiV6RFYQsOWBP+66yUS3yGrzZ2cNtznZuZzVM voVDtitMJRgHd+opDhAMjIwp/acPw5a8WduHnVxTxiQLhmaLZ6YmfJt7bwIhevgcDiZlm fSRZIwZyMNKAALpRijkthj3bevMmB2Kke0t88B7rKWJkOIDXgN8y/I+9j/xBoPeQQ3w== 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=ae87ehOM; 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 B26C5606A322; Fri, 4 Dec 2026 11:13: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=ae87ehOM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 117DB1F00A06; Fri, 4 Dec 2026 11:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382781; bh=vFnH5k9gAAKndd/fY/WXuOaIqXGWXH5l7d8DKPRLnkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ae87ehOMf3bb3OsBGJ3h3zYM4q6odvSx/J7Ww1LrbrDepiRGbiRJtMwwH30Tj8XYk 3ep3/F7sIiBH5L+ugOCoSBfYk9gM9/miikJSG7wMjqCsw+wSpFdvhu8jxUA49na8ZY KZ0Fpx8VGbq/P/8BDSMW+3ICIfCxAXbS9kkRJN1A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bernard Pidoux , Sasha Levin Subject: [PATCH 6.18 599/703] netrom: leave the busy state when the application reads Date: Fri, 4 Dec 2026 19:08:18 +0900 Message-ID: <20261204100643.681669248@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 86c0fca779051..0882c91bd9468 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 0be44b88f8948..db263358350fa 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