Linux-CIFS Archive mirror
 help / color / mirror / Atom feed
From: Henrique Carvalho <henrique.carvalho@suse.com>
To: sfrench@samba.org
Cc: pc@manguebit.org, ronniesahlberg@gmail.com,
	sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com,
	ematsumiya@suse.de, linux-cifs@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH 1/2] smb: client: serialize channel scaling path
Date: Mon, 13 Apr 2026 16:11:09 -0300	[thread overview]
Message-ID: <20260413191110.1508848-1-henrique.carvalho@suse.com> (raw)

Channel scaling serialization was coded at several call sites with plain
flag values in ses->flags, which duplicated the same bookkeeping in
reconnect and remount paths, and was missing in the mount path.

Move the CIFS_SES_FLAG_SCALE_CHANNELS acquisition and release inside
smb3_update_ses_channels(), and convert the session flags to bit indices
and their operations to bitops.

Make smb3_update_ses_channels return -EBUSY if there is already an
ongoing channel scaling operation.

Fixes: 556bb341f9f2e ("smb: client: introduce multichannel async work during mount")
Cc: stable@vger.kernel.org
Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
---
 fs/smb/client/cifsglob.h   |  6 +++---
 fs/smb/client/fs_context.c | 15 ---------------
 fs/smb/client/smb2pdu.c    | 24 ++++++++----------------
 3 files changed, 11 insertions(+), 34 deletions(-)

diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
index 709e96e07791..7b1323927711 100644
--- a/fs/smb/client/cifsglob.h
+++ b/fs/smb/client/cifsglob.h
@@ -1049,8 +1049,8 @@ struct cifs_chan {
 	__u8 signkey[SMB3_SIGN_KEY_SIZE];
 };
 
-#define CIFS_SES_FLAG_SCALE_CHANNELS (0x1)
-#define CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES (0x2)
+#define CIFS_SES_FLAG_SCALE_CHANNELS 0
+#define CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES 1
 
 /*
  * Session structure.  One of these for each uid session with a particular host
@@ -1089,7 +1089,7 @@ struct cifs_ses {
 	bool domainAuto:1;
 	bool expired_pwd;  /* track if access denied or expired pwd so can know if need to update */
 	int unicode;
-	unsigned int flags;
+	unsigned long flags;
 	__u16 session_flags;
 	__u8 smb3signingkey[SMB3_SIGN_KEY_SIZE];
 	__u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE];
diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c
index a46764c24710..e0e13c22e159 100644
--- a/fs/smb/client/fs_context.c
+++ b/fs/smb/client/fs_context.c
@@ -1166,27 +1166,12 @@ static int smb3_reconfigure(struct fs_context *fc)
 
 		/* Synchronize ses->chan_max with the new mount context */
 		smb3_sync_ses_chan_max(ses, ctx->max_channels);
-		/* Now update the session's channels to match the new configuration */
-		/* Prevent concurrent scaling operations */
-		spin_lock(&ses->ses_lock);
-		if (ses->flags & CIFS_SES_FLAG_SCALE_CHANNELS) {
-			spin_unlock(&ses->ses_lock);
-			mutex_unlock(&ses->session_mutex);
-			return -EINVAL;
-		}
-		ses->flags |= CIFS_SES_FLAG_SCALE_CHANNELS;
-		spin_unlock(&ses->ses_lock);
 
 		mutex_unlock(&ses->session_mutex);
 
 		rc = smb3_update_ses_channels(ses, ses->server,
 					       false /* from_reconnect */,
 					       false /* disable_mchan */);
-
-		/* Clear scaling flag after operation */
-		spin_lock(&ses->ses_lock);
-		ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS;
-		spin_unlock(&ses->ses_lock);
 	} else {
 		mutex_unlock(&ses->session_mutex);
 	}
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index 5188218c25be..2eb13b2665a4 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -228,6 +228,10 @@ int smb3_update_ses_channels(struct cifs_ses *ses, struct TCP_Server_Info *serve
 			bool from_reconnect, bool disable_mchan)
 {
 	int rc = 0;
+
+	if (test_and_set_bit(CIFS_SES_FLAG_SCALE_CHANNELS, &ses->flags))
+		return -EBUSY;
+
 	/*
 	 * Manage session channels based on current count vs max:
 	 * - If disable requested, skip or disable the channel
@@ -243,6 +247,7 @@ int smb3_update_ses_channels(struct cifs_ses *ses, struct TCP_Server_Info *serve
 			rc = cifs_chan_skip_or_disable(ses, server, from_reconnect, disable_mchan);
 	}
 
+	clear_bit(CIFS_SES_FLAG_SCALE_CHANNELS, &ses->flags);
 	return rc;
 }
 
@@ -432,15 +437,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
 		goto out;
 	}
 
-	spin_lock(&ses->ses_lock);
-	if (ses->flags & CIFS_SES_FLAG_SCALE_CHANNELS) {
-		spin_unlock(&ses->ses_lock);
-		mutex_unlock(&ses->session_mutex);
-		goto skip_add_channels;
-	}
-	ses->flags |= CIFS_SES_FLAG_SCALE_CHANNELS;
-	spin_unlock(&ses->ses_lock);
-
 	if (!rc &&
 	    (server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL) &&
 	    server->ops->query_server_interfaces) {
@@ -450,11 +446,11 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
 		 * is in progress. This will be used to avoid calling
 		 * smb2_reconnect recursively.
 		 */
-		ses->flags |= CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES;
+		set_bit(CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES, &ses->flags);
 		xid = get_xid();
 		rc = server->ops->query_server_interfaces(xid, tcon, false);
 		free_xid(xid);
-		ses->flags &= ~CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES;
+		clear_bit(CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES, &ses->flags);
 
 		if (!tcon->ipc && !tcon->dummy)
 			queue_delayed_work(cifsiod_wq, &tcon->query_interfaces,
@@ -492,10 +488,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
 	}
 
 skip_add_channels:
-	spin_lock(&ses->ses_lock);
-	ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS;
-	spin_unlock(&ses->ses_lock);
-
 	if (smb2_command != SMB2_INTERNAL_CMD)
 		cifs_queue_server_reconn(server);
 
@@ -609,7 +601,7 @@ static int smb2_ioctl_req_init(u32 opcode, struct cifs_tcon *tcon,
 	 */
 	if (opcode == FSCTL_VALIDATE_NEGOTIATE_INFO ||
 	    (opcode == FSCTL_QUERY_NETWORK_INTERFACE_INFO &&
-	     (tcon->ses->flags & CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES)))
+	     test_bit(CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES, &tcon->ses->flags)))
 		return __smb2_plain_req_init(SMB2_IOCTL, tcon, server,
 					     request_buf, total_len);
 
-- 
2.53.0


             reply	other threads:[~2026-04-13 19:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13 19:11 Henrique Carvalho [this message]
2026-04-13 19:11 ` [PATCH 2/2] smb: client: pass correct from_reconnect to cifs_put_tcp_session() Henrique Carvalho
2026-04-16  5:59   ` RAJASI MANDAL

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260413191110.1508848-1-henrique.carvalho@suse.com \
    --to=henrique.carvalho@suse.com \
    --cc=bharathsm@microsoft.com \
    --cc=ematsumiya@suse.de \
    --cc=linux-cifs@vger.kernel.org \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=sfrench@samba.org \
    --cc=sprasad@microsoft.com \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).