Netdev List
 help / color / mirror / Atom feed
* [PATCH RFC net v5 00/10] net/iucv: serialize the HiperSockets receive path with the socket lock
@ 2026-12-04  3:02 Bryam Vargas via B4 Relay
  2026-12-04  3:02 ` [PATCH RFC net v5 01/10] net/iucv: record that a HiperSockets socket sent its SYN Bryam Vargas via B4 Relay
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: Bryam Vargas via B4 Relay @ 2026-12-04  3:02 UTC (permalink / raw)
  To: Paolo Abeni, David S. Miller, Hidayath Khan, Willem de Bruijn,
	Alexandra Winter, Jakub Kicinski, Eric Dumazet
  Cc: netdev, linux-kernel, Nagamani PV, linux-s390, Simon Horman,
	Thorsten Winkler

v5 of stage 1 of the socket-locking rework [1]. It is v4 [6] with the
review comments from Alexandra [8] and Hidayath [10] applied and the
findings of the AI review of v4 [7] fixed. Ten patches now:

   1/10  new: a HiperSockets socket records that its SYN left; after
         that SO_MSGLIMIT fails, connect() sends no other SYN, and a
         SYN|ACK or SYN|FIN that answers no SYN is dropped
   2/10  iucv_send_ctrl() leaves sk_shutdown alone
   3/10  sendmsg() fails with -EPIPE when sending is shut down while
         it waits for the window
   4/10  recvmsg() under lock_sock()
   5/10  the frame dispatch and three state changes moved into
         functions of their own, no functional change
   6/10  the HiperSockets rx path under the socket lock: a control
         frame waits for the task that owns the socket
   7/10  closes the race between shutdown(SHUT_RD) and a frame in
         flight
   8/10  EOF, not -ENOTCONN, for a reader parked when the peer closes
   9/10  new: a frame that is reported as pending and then fails no
         longer leaves a socket that cannot send
  10/10  new: the socket forgets a SYN that the device reports
         unreachable, so connect() can send one again

1/10 to 3/10, 8/10 and 9/10 are fixes in their own right. 1/10 to 3/10
and 9/10 each apply to net without the rest; 3/10 is complete only on
top of 2/10. 8/10 is written on top of 6/10: its hunks are in functions
that 4/10 and 5/10 add. 10/10 gives back a retry that 1/10 takes away:
it needs 1/10 and, for a SYN the device first reports as pending, 9/10.
5/10 moves code and is there for 6/10.

1/10 is Alexandra's design [8] in place of v4 1/8. One choice in it is
mine: a later connect() to the same peer waits for the reply to the
first SYN, while she proposed refusing it. The numbers for both are
below the --- of 1/10. In [9] she prefers the wait. What 1/10 costs is
there too: a socket whose SYN got no reply cannot connect again. 10/10
gives the retry back when the device reports the SYN unreachable. It is
last and on its own so that 1/10 stays small. If you want it at all, I
can put it right behind 1/10 or fold it in: which do you prefer?

Hidayath ran v4 on z/VM [10]: one guest, two HiperSockets devices, four
CPUs. No lost sk_shutdown bit in 97678 cycles, no backwards read, EOF
for every parked reader, no message lost with SO_MSGLIMIT lowered in
IUCV_BOUND, no KASAN, lockdep or atomic-sleep report, and no KCSAN
report on any pair of accesses that the series touches. The one KCSAN
pair left is on hs_dev; 1/2 of the two fixes posted for net on 28 Oct
[3] covers it. Alexandra reproduced both cases of v4 1/8 on real
HiperSockets and saw neither in 100 runs with the patch [8].

RFC because 1/10, 9/10 and 10/10 are new and have not run on hardware.
2/10 to 8/10 are what Hidayath ran, except for the changes in 6/10
listed below and for what 4/10 to 6/10 pick up from the new 1/10. 9/10
and 10/10 also rest on what I can't check: which completion code a real
device gives for a SYN to a user ID that is not on the LAN, and whether
it ever reports a SYN as pending first. In my setup the emulated adapter
does what the test tells it to. Alexandra, Hidayath: could one of you
run the two cases Alexandra reproduced [8] again, now with 1/10, and,
with 10/10, one connect() to a user ID that does not exist? If a real
device reports nothing there, 10/10 does nothing and can be dropped
without touching the rest.

My setup is QEMU TCG with an emulated HiperSockets adapter and CP, so
rates and real SMP come only from the hardware. Where my setup and the
hardware disagree, the hardware is the reference.

Changes in v5:

- 1/10: new, replaces v4 1/8 [8]. The field that kept the window given
  to the peer is gone; the socket records only that the SYN left
- 9/10: new. The bug was found while reviewing 10/10; net has it as
  well
- 10/10: new
- 6/10: netdev_put() runs under if (dev) in afiucv_hs_backlog_rcv(),
  and sk_max_ack_backlog is read with READ_ONCE() in
  afiucv_hs_backlog_add() and written with WRITE_ONCE() in
  iucv_sock_listen(), both as Hidayath asked [10]
- 6/10: a SYN|ACK or SYN|FIN for a socket that sent no SYN is a stray (a
  frame that no state of the socket can use), with or without an owner;
  this follows from 1/10
- 6/10, from the AI review of v4 [7]: connect() applies a reply recorded
  for its SYN each time its wait tests the state, not once before the
  wait. In v4 a wait that ended on a timeout or a signal missed a reply
  that came in while the task held the socket for the last time:
  connect() returned -EAGAIN or -EINTR, yet the socket was connected, or
  refused, by the time the call returned
- 6/10, same review: sendmsg() applies a recorded FIN each time its
  wait for the window tests the state. v4 sent its data to a peer
  whose FIN was already in
- 6/10, same review: data, SHT and WIN frames for a socket that is not
  connected, and has no SYN|ACK recorded, are strays now. v4 let them
  wait in the backlog to be freed when the owner released the socket.
  One visible change: such a frame is a NO_SOCKET drop now, with or
  without an owner, while net frees it with a plain kfree_skb(). A WIN
  without data is the exception: it is consumed, as on net
- 6/10, same review: every frame for a closed socket is a stray: a
  SYN|ACK that found the socket before its close() no longer connects
  it
- 6/10: the notes now say what a caller sees differently from net when
  a frame comes in while the call owns the socket, each case measured
  on net and on v5. The two cases left at "by inspection" in v4 are
  tested: a pfmemalloc skb refused by the backlog, and the SOCK_ZAPPED
  check in afiucv_hs_apply()
- 4/10 and 5/10: no change of their own; their context changes with 1/10
- 2/10 stays a patch of its own [11]. No changelog got a sentence on
  stable: all but 5/10 and 10/10 already say what a user of a released
  kernel sees without the patch
- 2/10, 3/10, 7/10, 8/10: unchanged. 7/10 and 8/10: their notes changed
- on net 1c7d06746474; net/iucv has not changed since v4's base

Not in v5, and what that costs: five of my 53 default tests (the set v2
was tested with) fail on v5, as they do on net and did on v4. With the
three pieces that v3 dropped put back on top (the rest of the
iucv_send_ctrl() rewrite, the window update only while connected, the
credit reset), all 53 pass.

- iucv_send_ctrl() still needs room in sk_sndbuf for every control
  frame. With the send memory used up, which on HiperSockets lasts until
  tx completion, shutdown(SHUT_WR) sends no SHT and the peer never reads
  EOF (two tests), and the NETDEV_GOING_DOWN FIN does not go out (one)
- recvmsg() still sends a window update after the peer's FIN, a frame
  nobody uses (one); [3] 2/2 has the test for it
- a window update that finds no room leaves its credit in place, and the
  SHT read next is counted past the window: WARN_ON() and -EFAULT where
  EOF was due (one). [3] 2/2 ends that by not counting the SHT

net fails three more: two that 3/10 fixes and one that 8/10 fixes.

Tested on s390x under QEMU TCG, KASAN + PROVE_LOCKING +
DEBUG_ATOMIC_SLEEP, on net main, with the real qeth and qdio drivers
on the emulated adapter and the emulated CP, as v4 was. Two vCPUs
under -icount, which runs one at a time. The race tests also ran with
seeded short slices, and the two-reader test of 4/10 and the
closed-socket test of 6/10 ran under MTTCG. No KASAN, lockdep or
atomic-sleep report on net, at any step of the series or on the
kernels listed next. What the logs do have: the WARN_ON() from the
last "Not in v5" item, in that test and in others where a frame is
counted past the window; up to 3/10, the WARN_ON() in
iucv_sock_destruct() that 4/10 ends; and, on the kernel without 6/10's
pfmemalloc check, the BUG_ON() in __sk_backlog_rcv().

I also took 38 pieces of the series out, or changed them, each in a
kernel of its own. Each of these kernels gives, in at least one test, a
result that the series does not give. Per patch: 6 for 1/10, 1 for 2/10,
3 for 3/10, 1 for 4/10, 19 for 6/10, 1 for 7/10, 3 for 8/10, 2 for 9/10
(one of them on net with only 9/10 applied) and 2 for 10/10. The build
with CONFIG_NET_DEV_REFCNT_TRACKER=y in the notes of 6/10 is not one of
them. Of the 38:

- 23 with nothing added
- 8 on top of a test kernel: one on a kernel that drops the SYN in
  transmit (1/10); one on a kernel that makes two waits overlap (2/10);
  three for 6/10, two on a kernel that counts the strays and the frames
  that wait in the backlog and one on a kernel that marks a frame as
  taken from the memory reserves; and the two for 9/10 and one for
  10/10, on a kernel that prints each notification
- 7 with a delay added to hold their race window open: the one that
  records the SYN only after its transmit (1/10); the one without
  7/10's spinlock; the one without the receive-queue check in 8/10's
  wait; and four for 6/10, the two that each lack one of the
  SOCK_ZAPPED checks, the one whose connect() applies the reply only
  before its wait, and the one that keeps a recorded reply whose SYN is
  no longer recorded

The numbers are below the --- of each patch. Logs on request.

Still open, as in v4: afiucv_hs_callback_txnotify() and the z/VM
callbacks change sk_state without checking whether a task owns the
socket, and so does afiucv_netdev_event(), whose fix Nagamani is holding
for this series [4]. backlog_skb_q stays unbounded for a peer that
ignores its window. A listener with a full accept queue still leaks
the child of the SYN it refuses (measured on net and with the series,
numbers under 6/10), and it leaks one as well when the SYN|ACK fails to
go out (by inspection) [5]. connect() tests sk_state before
lock_sock() [2]; since 1/10 a HiperSockets socket that got connected in
between sends no second SYN. On a z/VM socket, iucv_sock_shutdown() and
recvmsg() update sk_shutdown under lock_sock() while
iucv_callback_shutdown() updates it under bh_lock_sock(), so either
side can lose its bit. iucv_callback_rx() tests RCV_SHUTDOWN there with
no lock; 7/10 takes the spinlock on the HiperSockets branch only. And
iucv_callback_connreq() answers a path request for a listener that
close() is emptying, the race 6/10 closes for a HiperSockets SYN.

Seen while working on v4, in net too, and not touched in v5 either:

- a HiperSockets recv() that owes a window update while the send memory
  is full sets IUCV_DISCONN: iucv_send_ctrl() finds no room and
  recvmsg() takes that for a dead path. It is the same failed update as
  in the last item of "Not in v5": that item is about what the next
  read does with the credit, this one about the state the socket is
  left in. Measured on net and with the series
- a z/VM sendmsg() that waits for send memory does not return when the
  peer severs the path: the memory is freed only at close(). By
  inspection
- afiucv_hs_send() passes NET_XMIT_DROP through, so a send() or
  connect() whose frame the qdisc dropped returns 1. By inspection for
  the qdisc; the test kernel that drops the SYN in transmit (the one
  under the first of the 8 above) shows the connect() half

[1] https://lore.kernel.org/all/20260724222917.134769-1-hexlabsecurity@proton.me/
[2] https://lore.kernel.org/all/sashiko-outbox-210383@kernel.org/
[3] https://lore.kernel.org/netdev/20261028-b4-disp-dd3e4ebb-v2-0-3747658d59bd@proton.me/
[4] https://lore.kernel.org/netdev/1d9d3cc1-24fb-40e0-a4c7-6fbfbcf4dc37@linux.ibm.com/
[5] https://lore.kernel.org/netdev/5f88daf4-cd8e-4464-b132-ac45be205121@linux.ibm.com/
[6] https://lore.kernel.org/netdev/20261114-b4-disp-fc0634a3-v4-0-f96c506447ce@proton.me/
[7] https://lore.kernel.org/all/sashiko-outbox-215997@kernel.org/
[8] https://lore.kernel.org/netdev/082654a9-aa48-40c0-b8e4-1495d0ac232c@linux.ibm.com/
[9] https://lore.kernel.org/netdev/84aab20f-387a-4ec4-9f25-c7491dd45ca5@linux.ibm.com/
[10] https://lore.kernel.org/netdev/38c4aaed-3cf6-43d7-a6b8-845f809a4ec6@linux.ibm.com/
[11] https://lore.kernel.org/netdev/da6ea2bb-7226-4b4c-81a4-88ffc3a98f91@linux.ibm.com/

---
Bryam Vargas (10):
      net/iucv: record that a HiperSockets socket sent its SYN
      net/iucv: do not clear SEND_SHUTDOWN to send a control frame
      net/iucv: fail sendmsg() with EPIPE once sending is shut down
      net/iucv: run recvmsg() under the socket lock
      net/iucv: factor out the HiperSockets frame dispatch and state changes
      net/iucv: serialize HiperSockets receive with the socket lock
      net/iucv: set RCV_SHUTDOWN under the socket spinlock
      net/iucv: return EOF to a reader parked when the peer closes
      net/iucv: decrement pendings when a pending frame's transmit fails
      net/iucv: forget a SYN that the device reports unreachable

 include/net/iucv/af_iucv.h |   8 +
 net/iucv/af_iucv.c         | 763 ++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 653 insertions(+), 118 deletions(-)
---
base-commit: 1c7d0674647435c06a72da9a331e02103063d8a4
change-id: 20261203-b4-disp-8029c32d-5788db65cd4e

Best regards,
--  
Bryam Vargas <hexlabsecurity@proton.me>



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-12-04 18:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  3:02 [PATCH RFC net v5 00/10] net/iucv: serialize the HiperSockets receive path with the socket lock Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 01/10] net/iucv: record that a HiperSockets socket sent its SYN Bryam Vargas via B4 Relay
2026-12-04 18:58   ` Alexandra Winter
2026-12-04  3:02 ` [PATCH RFC net v5 02/10] net/iucv: do not clear SEND_SHUTDOWN to send a control frame Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 03/10] net/iucv: fail sendmsg() with EPIPE once sending is shut down Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 04/10] net/iucv: run recvmsg() under the socket lock Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 05/10] net/iucv: factor out the HiperSockets frame dispatch and state changes Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 06/10] net/iucv: serialize HiperSockets receive with the socket lock Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 07/10] net/iucv: set RCV_SHUTDOWN under the socket spinlock Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 08/10] net/iucv: return EOF to a reader parked when the peer closes Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 09/10] net/iucv: decrement pendings when a pending frame's transmit fails Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 10/10] net/iucv: forget a SYN that the device reports unreachable Bryam Vargas via B4 Relay
2026-12-04 11:05 ` [PATCH RFC net v5 00/10] net/iucv: serialize the HiperSockets receive path with the socket lock Hidayath Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox