From: Bryam Vargas <hexl…@proton.me>
When the HiperSockets device keeps a frame for later, qeth reports it as
TX_NOTIFY_PENDING and af_iucv counts it in iucv->pendings: sendmsg()
sends nothing while that count is above zero. Only TX_NOTIFY_DELAYED_OK
takes the count down. When the device ends such a frame with an error,
the count stays up. On a connected socket, that changes nothing, since
the error disconnects it. When the frame is a SYN, the socket stays
IUCV_BOUND and a later connect() can still connect it. For as long as it
is connected, sendmsg() returns -EAGAIN, at once or after the send
timeout, or blocks if there is no timeout, and poll() does not report
EPOLLOUT.
Take the count down for the two delayed error notifications as well.
A pending frame that qeth gives up on when it drains its queues is
reported as TX_NOTIFY_GENERALERROR, like a frame that was never
pending, and is still not counted down.
Fixes: 3881ac441f64 ("af_iucv: add HiperSockets transport")
Fixes: 800c5eb7b5eb ("af_iucv: change net_device handling for HS transport")
Cc: stab…@vger.kernel.org # 6.18.x
Signed-off-by: Bryam Vargas <hexl…@proton.me>
---
v5: new. The bug was found while reviewing 10/10, which makes it
reachable again; net has it too. The patch applies to net without the
rest of the series.
Emulated setup. The adapter is told to report the SYN as pending and to
end it later with an error, so that qeth gives TX_NOTIFY_PENDING and
then the delayed notification. The first connect() times out. The peer
is listening the whole time. After the second connect() the socket
sends one byte, with a send timeout of 1 s:
- pending, then unreachable (completion code 16). net: the second
connect() returns 0 and send() returns -EAGAIN; the count is still 1.
net with this patch alone: the byte arrives. With 1/10 to 8/10, and
with 1/10 to 9/10, the second connect() sends no SYN and returns
-EAGAIN. With the series the byte arrives. With the series but
without this patch, send() returns -EAGAIN again
- pending, then another error (completion code 1). net: send() returns
-EAGAIN. net with this patch alone: the byte arrives. With only the
TX_NOTIFY_DELAYED_UNREACHABLE label of this patch: -EAGAIN again.
With the series the second connect() sends no SYN: 10/10 forgets a
SYN only when it is reported unreachable
I can't tell whether a real device reports a SYN as pending and then
fails it. If it does not, the patch changes nothing that can be seen:
on a connected socket the error disconnects it, and the count is not
read again.
Not fixed: when qeth drains its pending buffers it reports them with
TX_NOTIFY_GENERALERROR, the same as a frame that was never pending, so
af_iucv cannot take the count down there. Tested with a device recovery
(1 written to its recover attribute) while the SYN is pending: on net,
with or without this patch, the second connect() returns 0 and send()
returns -EAGAIN.
---
net/iucv/af_iucv.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index 8336f7056d49..1f1f6f698648 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -2725,6 +2725,11 @@ static void afiucv_hs_callback_txnotify(struct sock *sk, enum iucv_tx_notify n)
if (atomic_dec_return(&iucv->pendings) <= 0)
iucv_sock_wake_msglim(sk);
break;
+ case TX_NOTIFY_DELAYED_UNREACHABLE:
+ case TX_NOTIFY_DELAYED_GENERALERROR:
+ /* counted when the device reported the frame as pending */
+ atomic_dec(&iucv->pendings);
+ fallthrough;
default:
atomic_dec(&iucv->skbs_in_xmit);
if (sk->sk_state == IUCV_CONNECTED) {
--
2.56.1