Skip to content

Commit dc8e8ad

Browse files
piastrygregkh
authored andcommitted
CIFS: Do not skip SMB2 message IDs on send failures
commit c781af7 upstream. When we hit failures during constructing MIDs or sending PDUs through the network, we end up not using message IDs assigned to the packet. The next SMB packet will skip those message IDs and continue with the next one. This behavior may lead to a server not granting us credits until we use the skipped IDs. Fix this by reverting the current ID to the original value if any errors occur before we push the packet through the network stack. This patch fixes the generic/310 test from the xfs-tests. Cc: <stable@vger.kernel.org> # 4.19.x Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3ed9f22 commit dc8e8ad

4 files changed

Lines changed: 49 additions & 3 deletions

File tree

‎fs/cifs/cifsglob.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ struct smb_version_operations {
235235
int * (*get_credits_field)(struct TCP_Server_Info *, const int);
236236
unsigned int (*get_credits)(struct mid_q_entry *);
237237
__u64 (*get_next_mid)(struct TCP_Server_Info *);
238+
void (*revert_current_mid)(struct TCP_Server_Info *server,
239+
const unsigned int val);
238240
/* data offset from read response message */
239241
unsigned int (*read_data_offset)(char *);
240242
/*
@@ -756,6 +758,22 @@ get_next_mid(struct TCP_Server_Info *server)
756758
return cpu_to_le16(mid);
757759
}
758760

761+
static inline void
762+
revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
763+
{
764+
if (server->ops->revert_current_mid)
765+
server->ops->revert_current_mid(server, val);
766+
}
767+
768+
static inline void
769+
revert_current_mid_from_hdr(struct TCP_Server_Info *server,
770+
const struct smb2_sync_hdr *shdr)
771+
{
772+
unsigned int num = le16_to_cpu(shdr->CreditCharge);
773+
774+
return revert_current_mid(server, num > 0 ? num : 1);
775+
}
776+
759777
static inline __u16
760778
get_mid(const struct smb_hdr *smb)
761779
{
@@ -1391,6 +1409,7 @@ struct mid_q_entry {
13911409
struct kref refcount;
13921410
struct TCP_Server_Info *server; /* server corresponding to this mid */
13931411
__u64 mid; /* multiplex id */
1412+
__u16 credits; /* number of credits consumed by this mid */
13941413
__u32 pid; /* process id */
13951414
__u32 sequence_number; /* for CIFS signing */
13961415
unsigned long when_alloc; /* when mid was created */

‎fs/cifs/smb2ops.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ smb2_get_next_mid(struct TCP_Server_Info *server)
204204
return mid;
205205
}
206206

207+
static void
208+
smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
209+
{
210+
spin_lock(&GlobalMid_Lock);
211+
if (server->CurrentMid >= val)
212+
server->CurrentMid -= val;
213+
spin_unlock(&GlobalMid_Lock);
214+
}
215+
207216
static struct mid_q_entry *
208217
smb2_find_mid(struct TCP_Server_Info *server, char *buf)
209218
{
@@ -3256,6 +3265,7 @@ struct smb_version_operations smb20_operations = {
32563265
.get_credits = smb2_get_credits,
32573266
.wait_mtu_credits = cifs_wait_mtu_credits,
32583267
.get_next_mid = smb2_get_next_mid,
3268+
.revert_current_mid = smb2_revert_current_mid,
32593269
.read_data_offset = smb2_read_data_offset,
32603270
.read_data_length = smb2_read_data_length,
32613271
.map_error = map_smb2_to_linux_error,
@@ -3350,6 +3360,7 @@ struct smb_version_operations smb21_operations = {
33503360
.get_credits = smb2_get_credits,
33513361
.wait_mtu_credits = smb2_wait_mtu_credits,
33523362
.get_next_mid = smb2_get_next_mid,
3363+
.revert_current_mid = smb2_revert_current_mid,
33533364
.read_data_offset = smb2_read_data_offset,
33543365
.read_data_length = smb2_read_data_length,
33553366
.map_error = map_smb2_to_linux_error,
@@ -3445,6 +3456,7 @@ struct smb_version_operations smb30_operations = {
34453456
.get_credits = smb2_get_credits,
34463457
.wait_mtu_credits = smb2_wait_mtu_credits,
34473458
.get_next_mid = smb2_get_next_mid,
3459+
.revert_current_mid = smb2_revert_current_mid,
34483460
.read_data_offset = smb2_read_data_offset,
34493461
.read_data_length = smb2_read_data_length,
34503462
.map_error = map_smb2_to_linux_error,
@@ -3549,6 +3561,7 @@ struct smb_version_operations smb311_operations = {
35493561
.get_credits = smb2_get_credits,
35503562
.wait_mtu_credits = smb2_wait_mtu_credits,
35513563
.get_next_mid = smb2_get_next_mid,
3564+
.revert_current_mid = smb2_revert_current_mid,
35523565
.read_data_offset = smb2_read_data_offset,
35533566
.read_data_length = smb2_read_data_length,
35543567
.map_error = map_smb2_to_linux_error,

‎fs/cifs/smb2transport.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ smb2_mid_entry_alloc(const struct smb2_sync_hdr *shdr,
576576
struct TCP_Server_Info *server)
577577
{
578578
struct mid_q_entry *temp;
579+
unsigned int credits = le16_to_cpu(shdr->CreditCharge);
579580

580581
if (server == NULL) {
581582
cifs_dbg(VFS, "Null TCP session in smb2_mid_entry_alloc\n");
@@ -586,6 +587,7 @@ smb2_mid_entry_alloc(const struct smb2_sync_hdr *shdr,
586587
memset(temp, 0, sizeof(struct mid_q_entry));
587588
kref_init(&temp->refcount);
588589
temp->mid = le64_to_cpu(shdr->MessageId);
590+
temp->credits = credits > 0 ? credits : 1;
589591
temp->pid = current->pid;
590592
temp->command = shdr->Command; /* Always LE */
591593
temp->when_alloc = jiffies;
@@ -674,13 +676,18 @@ smb2_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst)
674676
smb2_seq_num_into_buf(ses->server, shdr);
675677

676678
rc = smb2_get_mid_entry(ses, shdr, &mid);
677-
if (rc)
679+
if (rc) {
680+
revert_current_mid_from_hdr(ses->server, shdr);
678681
return ERR_PTR(rc);
682+
}
683+
679684
rc = smb2_sign_rqst(rqst, ses->server);
680685
if (rc) {
686+
revert_current_mid_from_hdr(ses->server, shdr);
681687
cifs_delete_mid(mid);
682688
return ERR_PTR(rc);
683689
}
690+
684691
return mid;
685692
}
686693

@@ -695,11 +702,14 @@ smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)
695702
smb2_seq_num_into_buf(server, shdr);
696703

697704
mid = smb2_mid_entry_alloc(shdr, server);
698-
if (mid == NULL)
705+
if (mid == NULL) {
706+
revert_current_mid_from_hdr(server, shdr);
699707
return ERR_PTR(-ENOMEM);
708+
}
700709

701710
rc = smb2_sign_rqst(rqst, server);
702711
if (rc) {
712+
revert_current_mid_from_hdr(server, shdr);
703713
DeleteMidQEntry(mid);
704714
return ERR_PTR(rc);
705715
}

‎fs/cifs/transport.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,
638638
cifs_in_send_dec(server);
639639

640640
if (rc < 0) {
641+
revert_current_mid(server, mid->credits);
641642
server->sequence_number -= 2;
642643
cifs_delete_mid(mid);
643644
}
@@ -842,6 +843,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
842843
for (i = 0; i < num_rqst; i++) {
843844
midQ[i] = ses->server->ops->setup_request(ses, &rqst[i]);
844845
if (IS_ERR(midQ[i])) {
846+
revert_current_mid(ses->server, i);
845847
for (j = 0; j < i; j++)
846848
cifs_delete_mid(midQ[j]);
847849
mutex_unlock(&ses->server->srv_mutex);
@@ -867,8 +869,10 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
867869
for (i = 0; i < num_rqst; i++)
868870
cifs_save_when_sent(midQ[i]);
869871

870-
if (rc < 0)
872+
if (rc < 0) {
873+
revert_current_mid(ses->server, num_rqst);
871874
ses->server->sequence_number -= 2;
875+
}
872876

873877
mutex_unlock(&ses->server->srv_mutex);
874878

0 commit comments

Comments
 (0)