The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/12] smb: client: don't sleep through reconnects and umount
@ 2026-12-04 13:33 Stefan Metzmacher
  2026-12-04 13:33 ` [PATCH v2 01/12] smb: client: don't add a decrypted mid back to an exiting server Stefan Metzmacher
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Stefan Metzmacher @ 2026-12-04 13:33 UTC (permalink / raw)
  To: Paulo Alcantara
  Cc: metze, Namjae Jeon, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey,
	Bharath SM, Eduard Zateev, linux-cifs, samba-technical,
	linux-kernel, stable

Hi Paulo,

these remove fixed sleeps from the client's reconnect and shutdown
paths, which delayed e.g. an umount after the server or the local
address went away.

The first five patches fix the lifetime of struct TCP_Server_Info,
which the rest relies on: since commit 482c117c6dbe ("smb: client:
hold server info until cifsd exits") only the session side and the
cifsd thread hold references, so cifsd frees the struct at the end
of clean_demultiplex_info() while in-flight requests may still use
it, which the 46 second sleep only made unlikely:

  - Don't add a decrypted mid back to pending_mid_q while the server
    is exiting, clean_demultiplex_info() may already have completed
    the pending mids, so nobody would complete it.

  - Convert the references to a kref with get/put helpers.

  - Let every mid hold a server reference, and compound_send_recv()
    and cifs_call_async() one across the whole request.

  - Let the decrypt offload work hold one, it uses the server before
    it owns a mid.

  - Let a channel hold a reference of its primary server struct.

Eduard: these build on your commit, which is already in mainline and
stable, the session side and cifsd remain holders as before.

A remaining gap, not addressed here: cifs_pick_channel() returns a
channel server without a reference, which netfs keeps in the read and
write subrequests and which e.g. the replay back-off and
cifs_wait_for_server_reconnect() wait on, only protected by the
srv_count the session holds for the channel. Fixing that touches many
callers, so it's for a separate series.

The rest:

  - The reconnect loops slept 3 seconds between attempts, also when
    the server was already exiting; wait on server->response_q
    instead.

  - clean_demultiplex_info() slept 46 seconds if mids were still
    pending; wait until they are gone instead (with the same maximum).

  - Add cifs_server_wait_for_exit_ms() and use it for the retry and
    RFC 1002 sleeps in the demultiplex thread and for the replay
    back-off. The two 125 ms sleeps in clean_demultiplex_info() stay.

  - SMB Direct connections ignored the srcaddr= mount option, bind
    the smbdirect socket to it like the TCP connect does, and let
    smbdirect fail a connect from an address of another family with
    -EAFNOSUPPORT like TCP. A srcaddr= without an RDMA device now
    fails with -ENODEV instead of being ignored.

  - Soft mounts give up waiting for the reconnect once the next
    reconnect attempt failed with a local error (e.g. the address was
    removed: -ENETDOWN, -ENODEV, -EAFNOSUPPORT, -EPERM, or
    -EADDRNOTAVAIL, -ENETUNREACH, -EHOSTUNREACH, -EACCES if there is
    no usable route to the server) instead of 10 seconds per target;
    short outages like a server restart or ICMP errors from a router
    on the way still keep waiting.

The long fixed sleeps in the reconnect, exit and replay paths are gone
for all transports. Giving up early on local errors doesn't depend on
the transport either: the classification only looks at the error of
the failed reconnect attempt and at the local routing table for the
server's IP address, and smbdirect passes the rdma_cm status of a
failed connect through like the TCP connect does. For SMB Direct the
route check is only an approximation, it uses the inputs of the TCP
connect, iWARP uses port 5445 instead.

Not addressed here, possible follow-ups:

  - Since every mid and request holds a server reference,
    clean_demultiplex_info() wouldn't need to wait for pending_mid_q
    to drain at all anymore, which would also remove the wakeup and
    barrier on every mid removal. I kept the wait, it still gives
    in-flight requests the chance to complete normally.

  - Each request now does at least 4 atomic operations on the shared
    server reference count (2 + 2 per mid of a compound), which could
    matter for many CPUs doing small I/O to one server. Taking the
    mid reference only when a mid is handed off (cancelled or async)
    or a percpu_ref would avoid that.

  - The replay back-off is called at about 25 places, like the
    msleep() it replaces, a common helper for the back-off would be
    a cleanup on its own.

These patches were developed with the help of Claude (Anthropic),
which was used for code analysis, writing parts of the code and the
commit messages. I reviewed all changes and take full responsibility
for them.

Testing: on our RDMA test setup (TCP and SMB Direct over rxe, irdma
RoCEv2 and mlx5 against ksmbd) soft mounts give up after the next
failed reconnect for an unreachable or prohibit route and a cgroup
BPF program denying the connect (IPv4 and IPv6), and keep waiting
about 10 seconds for a stopped ksmbd, ICMP errors from the server and
a local firewall REJECT. Mounts with srcaddr= work over SMB Direct
and fail for an address without RDMA device, and ksmbd restarts
under I/O reconnect as before. The DFS part of patch 12 wasn't
tested, there's no DFS setup there.

Changes in v2 (thanks to the reviews by Sashiko and Claude):

  - New patch 1: a decrypted mid added back while the server exits
    was never completed.
  - New patches 2-5: the wakeup in "smb: client: wait for pending
    mids instead of sleeping 46 seconds" (now patch 7) let cifsd free
    the server while the waking request still used it. The race
    already existed with the 46 second sleep, the new patches fix it.
  - Patch 6: the wait between reconnect attempts is a helper used by
    both reconnect loops.
  - Patch 7: add a barrier between removing the mid and checking for
    CifsExiting, so that cifsd can't miss the wakeup, and also wake up
    cifsd when __smb2_find_mid() removes the last mid, e.g. from
    smb2_decrypt_offload().
  - Patch 8 ("smb: client: add cifs_server_wait_for_exit_ms()"): also
    Fixes: 665e18794804, which added the sleep after a negative
    RFC 1002 session response, and a note why it carries the Fixes tag
    of the replay back-off patch. The reconnect loops keep the wait
    of patch 6, which also ends when another reconnect succeeded.
  - Patch 9: only record the shared back-off of a write retry pass if
    it wasn't ended early because the server of the subrequest is
    exiting, and let the reopen retry back off on the primary server
    of the session, not on the channel of the subrequest.
  - New patches 10 and 11: let SMB Direct connections use srcaddr=,
    so that the route check of patch 12 looks at the address actually
    used, smbdirect returns -EAFNOSUPPORT for a srcaddr= of another
    family.
  - Patch 12: -EADDRNOTAVAIL, -ENETUNREACH, -EHOSTUNREACH and -EACCES
    only count as a local error if a route lookup to the server fails,
    with the same inputs as the TCP connect, as they also come from
    ICMP errors of a router on the way. A removed IPv6 srcaddr is
    checked explicitly, as the IPv6 route lookup doesn't. The counter
    is an atomic_t, as SMB1 also reconnects from a request. IPC tcons,
    e.g. the one used for DFS referrals, keep waiting as before.
    -EAFNOSUPPORT (e.g. IPv6 disabled) and -EPERM (a cgroup BPF
    program denied the connect or bind) are local errors as well. For
    DFS a reconnect attempt only counts as failed locally if all
    targets failed locally.

v1: https://lore.kernel.org/linux-cifs/cover.1796142565.git.metze@samba.org/

Base: paulo-linux/cifs-next (9012a6ef4cd4). It merges cleanly with
linux-next, including the switch of cifs to a bvecq in
smb2_decrypt_offload().

Stefan Metzmacher (12):
  smb: client: don't add a decrypted mid back to an exiting server
  smb: client: use kref for the TCP_Server_Info object references
  smb: client: let in-flight requests hold a TCP_Server_Info reference
  smb: client: let the decrypt offload work hold a TCP_Server_Info
    reference
  smb: client: let channels hold a reference of the primary server
    struct
  smb: client: stop waiting between reconnect attempts once the server
    exits
  smb: client: wait for pending mids instead of sleeping 46 seconds
  smb: client: add cifs_server_wait_for_exit_ms()
  smb: client: use cifs_server_wait_for_exit_ms() for the replay
    back-off
  smb: smbdirect: fail a connect from another address family
  smb: client: let SMB Direct connections use the srcaddr= mount option
  smb: client: soft mounts only wait until a reconnect attempt failed
    locally

 fs/smb/client/cached_dir.c    |   2 +-
 fs/smb/client/cifsglob.h      |   8 +-
 fs/smb/client/cifsproto.h     |   5 +
 fs/smb/client/connect.c       | 266 ++++++++++++++++++++++++++++++++--
 fs/smb/client/file.c          |  20 ++-
 fs/smb/client/link.c          |   2 +-
 fs/smb/client/misc.c          |  48 +++++-
 fs/smb/client/smb1transport.c |   2 +
 fs/smb/client/smb2inode.c     |   6 +-
 fs/smb/client/smb2ops.c       |  30 +++-
 fs/smb/client/smb2pdu.c       |  28 ++--
 fs/smb/client/smb2transport.c |   2 +
 fs/smb/client/smbdirect.c     |  16 ++
 fs/smb/client/transport.c     | 106 ++++++++++++--
 fs/smb/smbdirect/connect.c    |   7 +
 15 files changed, 482 insertions(+), 66 deletions(-)

-- 
2.43.0


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

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

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 13:33 [PATCH 0/12] smb: client: don't sleep through reconnects and umount Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 01/12] smb: client: don't add a decrypted mid back to an exiting server Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 02/12] smb: client: use kref for the TCP_Server_Info object references Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 03/12] smb: client: let in-flight requests hold a TCP_Server_Info reference Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 04/12] smb: client: let the decrypt offload work " Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 05/12] smb: client: let channels hold a reference of the primary server struct Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 06/12] smb: client: stop waiting between reconnect attempts once the server exits Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 07/12] smb: client: wait for pending mids instead of sleeping 46 seconds Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 08/12] smb: client: add cifs_server_wait_for_exit_ms() Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 09/12] smb: client: use cifs_server_wait_for_exit_ms() for the replay back-off Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 10/12] smb: smbdirect: fail a connect from another address family Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 11/12] smb: client: let SMB Direct connections use the srcaddr= mount option Stefan Metzmacher
2026-12-04 13:33 ` [PATCH v2 12/12] smb: client: soft mounts only wait until a reconnect attempt failed locally Stefan Metzmacher

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