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=1796384226; b=pUTWVcJIFR0Zn4sB8WiJrXIDzqR2TBsQjDIOYXPO7CxKBmuWBp4D6zOtVKk9Rn8XariM FBW4IwldgVNO/8AkPu/k030DMSOeYmPIFtz6weJC++1yhnW5mWDkbfUeMS2R+qkh2s+9f lFHk5PUuV3laFaMTlB8QKAdmqoJkYeq4OVorrgrZe2zC+umjUKT66loWwa/g1MpwIEwrY NG1fsTeYeBYO4/ONWw8EgYXyFEErsD14RCdJw8YM9rJ320zzWtHuKwX+j2JjSqUCd2pNX 3udnzSJFH2MOVD2DtFr0CziftCYqiU3zB77pc4KwUqK4WlgCV1mtoAYtcz6bKj+g7eQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384226; 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=lNOW2Ex3Akr/ng765ajU6s3yqD9vt7uZhAJlOF1cSsI=; b=pqguVVyBFPUN862+NSg6FsF44J5ru+wqR9pJ0WbJKq4uGtzflZzwjAjOKmiTJVuvT/m7 hALe3kdsNJEJVXvfVqxMN5eySlerBrk6YZLc/GLKLlq+EF3cn6BkzLYxr1TTR4z2xCy97 +OpOe5FArmF/keUaJZpMFOMMVolcG9wckqAITl9DXfKi37Gh7sh5ghbzIJr/6BjUENf4V 6glDo201pTlQVDHZqSJ/aOGReh+UU2LlnfnSzXKWYjDEWa5wo18AnJwFGkPuNsaXvvh9y IeZCXZ2y0B0hTOML3zeq6KVZxkZ2uy1ZChTPFm6JqM7C3HwXrJSB7Q/Rk1y3RPlr4Fw== 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=y8rB7rzB; 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 6E389606A322; Fri, 4 Dec 2026 11:37:06 +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=y8rB7rzB Received: by smtp.kernel.org (Postfix) with ESMTPSA id D93D31F000C2; Fri, 4 Dec 2026 11:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384226; bh=lNOW2Ex3Akr/ng765ajU6s3yqD9vt7uZhAJlOF1cSsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=y8rB7rzB+TbVRZ0TwV1ogRSZJlT0pDDwArdILkMgZebDwc/eHElZMRFcFE6Q1HOoe Fur7OwnD6aRZWNHi8YMPTXnRffCaHEDCz4S5g2xIlQxzxMZGQXex+zW1GEKg4HxLPf LFBtoGYQqbUsnyAT1Z/rahXel7wjxnCZs+prZEPs= 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 509/555] ax25: leave the busy state when the application reads Date: Fri, 4 Dec 2026 19:09:12 +0900 Message-ID: <20261204100628.245933092@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 connected socket is full, the frame is not taken, AX25_COND_OWN_RX_BUSY is set and the peer gets RNR. Only the heartbeat clears it again, up to five seconds after the application has read its data. Until then every I frame is answered with RNR and the peer waits, so with a slow reader the flow stops and starts in steps of up to five seconds. Add ax25_check_rx_busy(), which leaves the busy state once the buffer is half empty and sends RR at once, as the heartbeat does. A DAMA slave only clears the condition and answers the master's next poll, as ax25_ds_heartbeat_expiry() does. Call it from the standard heartbeat instead of its own copy of the code, and from ax25_recvmsg() after a frame of a SOCK_SEQPACKET socket is consumed. Tested on two QEMU guests (6.12.94, KASAN, lockdep) linked by KISS: A writes twelve messages of 200 bytes on a connected socket, B has a minimal receive buffer and starts reading after 20 s. before: B reads messages 1-3 at 20.0 s, messages 4-12 at 23.5 s after: B reads messages 1-12 between 20.0 s and 20.1 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 321859eeb03bd6d5e2a7c298b974ec6e93370435) Signed-off-by: Sasha Levin --- include/net/ax25.h | 1 + net/ax25/af_ax25.c | 9 +++++++++ net/ax25/ax25_std_timer.c | 11 +---------- net/ax25/ax25_subr.c | 27 +++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/include/net/ax25.h b/include/net/ax25.h index e3c10a9395944..59d2dd2b77431 100644 --- a/include/net/ax25.h +++ b/include/net/ax25.h @@ -452,6 +452,7 @@ void ax25_requeue_frames(ax25_cb *); int ax25_validate_nr(ax25_cb *, unsigned short); int ax25_decode(ax25_cb *, struct sk_buff *, int *, int *, int *); void ax25_send_control(ax25_cb *, int, int, int); +void ax25_check_rx_busy(ax25_cb *ax25); void ax25_return_dm(struct net_device *, ax25_address *, ax25_address *, ax25_digi *); void ax25_calculate_t1(ax25_cb *); diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index d464f8ea4e558..6088baf162b15 100644 --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -1874,6 +1874,15 @@ static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, skb_free_datagram(sk, skb); err = copied; + /* Room was made: leave the busy state now if we can */ + if (sk->sk_type == SOCK_SEQPACKET) { + local_bh_disable(); + bh_lock_sock(sk); + ax25_check_rx_busy(sk_to_ax25(sk)); + bh_unlock_sock(sk); + local_bh_enable(); + } + out: release_sock(sk); diff --git a/net/ax25/ax25_std_timer.c b/net/ax25/ax25_std_timer.c index 05ff1032748f6..be5720b469d8d 100644 --- a/net/ax25/ax25_std_timer.c +++ b/net/ax25/ax25_std_timer.c @@ -58,16 +58,7 @@ void ax25_std_heartbeat_expiry(ax25_cb *ax25) /* * Check the state of the receive buffer. */ - if (sk != NULL) { - if (atomic_read(&sk->sk_rmem_alloc) < - (sk->sk_rcvbuf >> 1) && - (ax25->condition & AX25_COND_OWN_RX_BUSY)) { - ax25->condition &= ~AX25_COND_OWN_RX_BUSY; - ax25->condition &= ~AX25_COND_ACK_PENDING; - ax25_send_control(ax25, AX25_RR, AX25_POLLOFF, AX25_RESPONSE); - break; - } - } + ax25_check_rx_busy(ax25); } if (sk) diff --git a/net/ax25/ax25_subr.c b/net/ax25/ax25_subr.c index fbfeb09784119..d9ad696f524a3 100644 --- a/net/ax25/ax25_subr.c +++ b/net/ax25/ax25_subr.c @@ -212,6 +212,33 @@ void ax25_send_control(ax25_cb *ax25, int frametype, int poll_bit, int type) * * Note: src here is the sender, thus it's the target of the DM */ +/* + * Leave the busy state as soon as the application has made room in + * the receive buffer, instead of waiting for the next heartbeat. + * A DAMA slave does not send on its own: the master's next poll is + * answered with RR. Called with the socket spinlock held. + */ +void ax25_check_rx_busy(ax25_cb *ax25) +{ + struct sock *sk = ax25->sk; + + if (!sk || !ax25->ax25_dev || + !(ax25->condition & AX25_COND_OWN_RX_BUSY) || + (ax25->state != AX25_STATE_3 && ax25->state != AX25_STATE_4) || + atomic_read(&sk->sk_rmem_alloc) >= (sk->sk_rcvbuf >> 1)) + return; + + ax25->condition &= ~AX25_COND_OWN_RX_BUSY; + ax25->condition &= ~AX25_COND_ACK_PENDING; + +#ifdef CONFIG_AX25_DAMA_SLAVE + if (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL] == AX25_PROTO_DAMA_SLAVE && + ax25->ax25_dev->dama.slave) + return; +#endif + ax25_send_control(ax25, AX25_RR, AX25_POLLOFF, AX25_RESPONSE); +} + void ax25_return_dm(struct net_device *dev, ax25_address *src, ax25_address *dest, ax25_digi *digi) { struct sk_buff *skb; -- 2.53.0