From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=144.76.82.148 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796391226; b=43IfZIUd4BZbQc/5IZXUT0C4RX1wsnol6RZPJYYiaKMWN8869eqq7/r5NXhQh+WHrlqC 8Pt0oyoeIkYepE+uuqCPMnplB31YFYMA36M+NtXqfIyTTvvWg/SmmCRPn6Cm2n7Fvu9Bv M31UbSkNj1rdhMQOGhY/wb5hhPH/pVt0acQnnVfeZOE+44h0HhCCvfPmU01tT5hSrV0gp z5+dxqJOdDPQzCrqV8cLuBLt/Wq1lV93e+22UvVwZIRLNLJOp/gWSHNjy072XltatJEsr TbwfFjPM/rcxP6Jyhee8wBW3szzJFAycgdYj6NQNaNWfeaKdYdLgcw+zZckeLl0xooQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796391226; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=PfdwDhs/nUkZ2OZx0m3F6jF7b/9upk9sbi0smfpGdI4=; b=rpzJhetK7EOJjrw9IYzCcIKvdv0uNDXkPg9xVXWdNmUlMA0rGPjNy19zjBfh/ti9LRiU 0fBNRebEh7Xz2uxlQUTctaz92G/J6vKJEBymQmrFbrNQBIxc2cLPVpPde0mh8jl7oTj0M AfxzVgNwKn0NzRUvXBxSFDDVrgK8PrKz++gW9H5iDd6pgYU4EIeaKC2DFihfKb57J0mif tW0KQh3b3FRPTIrOmuSXQIkk1nqAQ6s3Yfbo1YoYMvoJffGY+4PdtCUrXxtVtvt0ei7yl JeIXuCdHwzgwbJKwL4PSdhfaDzs44F5Il30iFVdrYBY+jCVWTQWLWz6JetUHS8aye7g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samba.org; spf=pass smtp.mailfrom=samba.org; dkim=pass header.d=samba.org header.i=@samba.org header.a=rsa-sha256 header.s=42 header.b=FENz7951; arc=none smtp.remote-ip=144.76.82.148 Received: from hr2.samba.org (hr2.samba.org [144.76.82.148]) (using TLSv1.3 with cipher TLS_CHACHA20_POLY1305_SHA256 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4BE2606A330; Fri, 4 Dec 2026 13:33:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D4BE2606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=samba.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samba.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (3072-bit key) header.d=samba.org header.i=@samba.org header.a=rsa-sha256 header.s=42 header.b=FENz7951 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=samba.org; s=42; h=Message-ID:Date:Cc:To:From; bh=PfdwDhs/nUkZ2OZx0m3F6jF7b/9upk9sbi0smfpGdI4=; b=FENz79515ZyYn9908jLIPE9vwB Taaf76JTeIPRFdfwbNJekspsktGROT/sIJNgDsKDH68jetpUIlZ7M0TtoMJc2KIo966jZVR1W8rcH 0Jd2N3E7LtaEh1XUBXTKKTmSq2KQnSFzTtT17399D4ksvGvHsDzJ0Jbq4DcP/bBwJAUwaXbmgAhma B13S9L1kCczV7AGXd6Ur86vvViXYAGDOwN+5Pgj6nrGv8pvqth3W6emh/xb7BdPAwjOCRKuLWHsbN KJmD61utWeIKDBzcpwhOg357ZYzZSZNLMAxn5+Wni+BhlKWU1lCBPYiwQ/TDw7Byrs2OqU4e14uE8 C5NoEGQmaj4OtySFqlfcCeJ5/tkTG7YRqI1SnQPkmjk1BR1Tw5LVQ2gDB6Kdf2lZlxSCgY004WqHH pfDXogW70Qo+NigOwcfM0zZR8EyqfLagbHHGFxELJHcjiMiL62EK1uzjiEfyLSV/VPAxC3vm1XVSB VU+FNgeMn9W/1zVV5cL9X6Gj; Received: from [127.0.0.2] (localhost [127.0.0.1]) by hr2.samba.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__ECDSA_SECP256R1_SHA256__CHACHA20_POLY1305:256) (Exim) id 1xZTPx-00000000I7w-37EW; Fri, 04 Dec 2026 13:33:41 +0000 From: Stefan Metzmacher To: Paulo Alcantara Cc: metze@samba.org, Namjae Jeon , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , Eduard Zateev , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 0/12] smb: client: don't sleep through reconnects and umount Date: Fri, 4 Dec 2026 14:33:25 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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