Skip to content

Commit d4e5160

Browse files
longlimsftsmfrench
authored andcommitted
cifs: smbd: Update receive credits before sending and deal with credits roll back on failure before sending
Recevie credits should be updated before sending the packet, not before a work is scheduled. Also, the value needs roll back if something fails and cannot send. Signed-off-by: Long Li <[email protected]> Reported-by: kbuild test robot <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 3ffbe78 commit d4e5160

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

fs/cifs/smbdirect.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,6 @@ static void smbd_post_send_credits(struct work_struct *work)
450450
info->new_credits_offered += ret;
451451
spin_unlock(&info->lock_new_credits_offered);
452452

453-
atomic_add(ret, &info->receive_credits);
454-
455453
/* Check if we can post new receive and grant credits to peer */
456454
check_and_send_immediate(info);
457455
}
@@ -822,6 +820,7 @@ static int smbd_create_header(struct smbd_connection *info,
822820
struct smbd_request *request;
823821
struct smbd_data_transfer *packet;
824822
int header_length;
823+
int new_credits;
825824
int rc;
826825

827826
/* Wait for send credits. A SMBD packet needs one credit */
@@ -840,16 +839,19 @@ static int smbd_create_header(struct smbd_connection *info,
840839
request = mempool_alloc(info->request_mempool, GFP_KERNEL);
841840
if (!request) {
842841
rc = -ENOMEM;
843-
goto err;
842+
goto err_alloc;
844843
}
845844

846845
request->info = info;
847846

848847
/* Fill in the packet header */
849848
packet = smbd_request_payload(request);
850849
packet->credits_requested = cpu_to_le16(info->send_credit_target);
851-
packet->credits_granted =
852-
cpu_to_le16(manage_credits_prior_sending(info));
850+
851+
new_credits = manage_credits_prior_sending(info);
852+
atomic_add(new_credits, &info->receive_credits);
853+
packet->credits_granted = cpu_to_le16(new_credits);
854+
853855
info->send_immediate = false;
854856

855857
packet->flags = 0;
@@ -887,7 +889,7 @@ static int smbd_create_header(struct smbd_connection *info,
887889
if (ib_dma_mapping_error(info->id->device, request->sge[0].addr)) {
888890
mempool_free(request, info->request_mempool);
889891
rc = -EIO;
890-
goto err;
892+
goto err_dma;
891893
}
892894

893895
request->sge[0].length = header_length;
@@ -896,8 +898,17 @@ static int smbd_create_header(struct smbd_connection *info,
896898
*request_out = request;
897899
return 0;
898900

899-
err:
901+
err_dma:
902+
/* roll back receive credits */
903+
spin_lock(&info->lock_new_credits_offered);
904+
info->new_credits_offered += new_credits;
905+
spin_unlock(&info->lock_new_credits_offered);
906+
atomic_sub(new_credits, &info->receive_credits);
907+
908+
err_alloc:
909+
/* roll back send credits */
900910
atomic_inc(&info->send_credits);
911+
901912
return rc;
902913
}
903914

0 commit comments

Comments
 (0)