Skip to content

Commit

Permalink
Merge tag 'v6.8-rc3-smb-client-fixes' of git://git.samba.org/sfrench/…
Browse files Browse the repository at this point in the history
…cifs-2.6

Pull smb client fixes from Steve French:
 "Five smb3 client fixes, mostly multichannel related:

   - four multichannel fixes including fix for channel allocation when
     multiple inactive channels, fix for unneeded race in channel
     deallocation, correct redundant channel scaling, and redundant
     multichannel disabling scenarios

   - add warning if max compound requests reached"

* tag 'v6.8-rc3-smb-client-fixes' of git://git.samba.org/sfrench/cifs-2.6:
  smb: client: increase number of PDUs allowed in a compound request
  cifs: failure to add channel on iface should bump up weight
  cifs: do not search for channel if server is terminating
  cifs: avoid redundant calls to disable multichannel
  cifs: make sure that channel scaling is done only once
  • Loading branch information
Linus Torvalds committed Feb 4, 2024
2 parents fc86e5c + 11d4d1d commit 9e28c7a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
5 changes: 4 additions & 1 deletion fs/smb/client/cifsglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
#define SMB_INTERFACE_POLL_INTERVAL 600

/* maximum number of PDUs in one compound */
#define MAX_COMPOUND 5
#define MAX_COMPOUND 7

/*
* Default number of credits to keep available for SMB3.
Expand Down Expand Up @@ -1032,6 +1032,8 @@ struct cifs_chan {
__u8 signkey[SMB3_SIGN_KEY_SIZE];
};

#define CIFS_SES_FLAG_SCALE_CHANNELS (0x1)

/*
* Session structure. One of these for each uid session with a particular host
*/
Expand Down Expand Up @@ -1064,6 +1066,7 @@ struct cifs_ses {
enum securityEnum sectype; /* what security flavor was specified? */
bool sign; /* is signing required? */
bool domainAuto:1;
unsigned int flags;
__u16 session_flags;
__u8 smb3signingkey[SMB3_SIGN_KEY_SIZE];
__u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE];
Expand Down
6 changes: 6 additions & 0 deletions fs/smb/client/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ cifs_ses_get_chan_index(struct cifs_ses *ses,
{
unsigned int i;

/* if the channel is waiting for termination */
if (server->terminate)
return CIFS_INVAL_CHAN_INDEX;

for (i = 0; i < ses->chan_count; i++) {
if (ses->chans[i].server == server)
return i;
Expand Down Expand Up @@ -269,6 +273,8 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
&iface->sockaddr,
rc);
kref_put(&iface->refcount, release_iface);
/* failure to add chan should increase weight */
iface->weight_fulfilled++;
continue;
}

Expand Down
24 changes: 19 additions & 5 deletions fs/smb/client/smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ cifs_chan_skip_or_disable(struct cifs_ses *ses,
}

ses->chans[chan_index].server = NULL;
server->terminate = true;
spin_unlock(&ses->chan_lock);

/*
Expand All @@ -188,7 +189,6 @@ cifs_chan_skip_or_disable(struct cifs_ses *ses,
*/
cifs_put_tcp_session(server, from_reconnect);

server->terminate = true;
cifs_signal_cifsd_for_reconnect(server, false);

/* mark primary server as needing reconnect */
Expand Down Expand Up @@ -399,6 +399,15 @@ 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)) {
mutex_unlock(&ses->session_mutex);
Expand All @@ -410,7 +419,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
rc = SMB3_request_interfaces(xid, tcon, false);
free_xid(xid);

if (rc == -EOPNOTSUPP) {
if (rc == -EOPNOTSUPP && ses->chan_count > 1) {
/*
* some servers like Azure SMB server do not advertise
* that multichannel has been disabled with server
Expand All @@ -428,17 +437,22 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
if (ses->chan_max > ses->chan_count &&
ses->iface_count &&
!SERVER_IS_CHAN(server)) {
if (ses->chan_count == 1)
if (ses->chan_count == 1) {
cifs_server_dbg(VFS, "supports multichannel now\n");
queue_delayed_work(cifsiod_wq, &tcon->query_interfaces,
(SMB_INTERFACE_POLL_INTERVAL * HZ));
}

cifs_try_adding_channels(ses);
queue_delayed_work(cifsiod_wq, &tcon->query_interfaces,
(SMB_INTERFACE_POLL_INTERVAL * HZ));
}
} else {
mutex_unlock(&ses->session_mutex);
}

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)
mod_delayed_work(cifsiod_wq, &server->reconnect, 0);
Expand Down
4 changes: 2 additions & 2 deletions fs/smb/client/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
if (!(flags & CIFS_TRANSFORM_REQ))
return __smb_send_rqst(server, num_rqst, rqst);

if (num_rqst > MAX_COMPOUND - 1)
return -ENOMEM;
if (WARN_ON_ONCE(num_rqst > MAX_COMPOUND - 1))
return -EIO;

if (!server->ops->init_transform_rq) {
cifs_server_dbg(VFS, "Encryption requested but transform callback is missing\n");
Expand Down

0 comments on commit 9e28c7a

Please sign in to comment.