Skip to content

Commit 975f05a

Browse files
metze-sambasmfrench
authored andcommitted
smb: server: call smb_direct_post_recv_credits() when the negotiation is done
We now activate sc->recv_io.posted.refill_work and sc->idle.immediate_work only after a successful negotiation, before sending the negotiation response. It means the queue_work(sc->workqueue, &sc->recv_io.posted.refill_work) in put_recvmsg() of the negotiate request, is a no-op now. It also means our explicit smb_direct_post_recv_credits() will have queue_work(sc->workqueue, &sc->idle.immediate_work) as no-op. This should make sure we don't have races and post any immediate data_transfer message that tries to grant credits to the peer, before we send the negotiation response, as that will grant the initial credits to the peer. Fixes: 0626e66 ("cifsd: add server handler for central processing and tranport layers") Fixes: 1cde0a7 ("smb: server: don't use delayed_work for post_recv_credits_work") Cc: Namjae Jeon <[email protected]> Cc: Steve French <[email protected]> Cc: Tom Talpey <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Stefan Metzmacher <[email protected]> Acked-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 6f40e50 commit 975f05a

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

fs/smb/server/transport_rdma.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ static struct smb_direct_transport *alloc_transport(struct rdma_cm_id *cm_id)
418418

419419
sc->ib.dev = sc->rdma.cm_id->device;
420420

421-
INIT_WORK(&sc->recv_io.posted.refill_work,
422-
smb_direct_post_recv_credits);
423-
INIT_WORK(&sc->idle.immediate_work, smb_direct_send_immediate_work);
424421
INIT_DELAYED_WORK(&sc->idle.timer_work, smb_direct_idle_connection_timer);
425422

426423
conn = ksmbd_conn_alloc();
@@ -1904,7 +1901,6 @@ static int smb_direct_prepare_negotiation(struct smbdirect_socket *sc)
19041901
goto out_err;
19051902
}
19061903

1907-
smb_direct_post_recv_credits(&sc->recv_io.posted.refill_work);
19081904
return 0;
19091905
out_err:
19101906
put_recvmsg(sc, recvmsg);
@@ -2249,8 +2245,8 @@ static int smb_direct_prepare(struct ksmbd_transport *t)
22492245
return -ECONNABORTED;
22502246

22512247
ret = smb_direct_check_recvmsg(recvmsg);
2252-
if (ret == -ECONNABORTED)
2253-
goto out;
2248+
if (ret)
2249+
goto put;
22542250

22552251
req = (struct smbdirect_negotiate_req *)recvmsg->packet;
22562252
sp->max_recv_size = min_t(int, sp->max_recv_size,
@@ -2265,14 +2261,38 @@ static int smb_direct_prepare(struct ksmbd_transport *t)
22652261
sc->recv_io.credits.target = min_t(u16, sc->recv_io.credits.target, sp->recv_credit_max);
22662262
sc->recv_io.credits.target = max_t(u16, sc->recv_io.credits.target, 1);
22672263

2268-
ret = smb_direct_send_negotiate_response(sc, ret);
2269-
out:
2264+
put:
22702265
spin_lock_irqsave(&sc->recv_io.reassembly.lock, flags);
22712266
sc->recv_io.reassembly.queue_length--;
22722267
list_del(&recvmsg->list);
22732268
spin_unlock_irqrestore(&sc->recv_io.reassembly.lock, flags);
22742269
put_recvmsg(sc, recvmsg);
22752270

2271+
if (ret == -ECONNABORTED)
2272+
return ret;
2273+
2274+
if (ret)
2275+
goto respond;
2276+
2277+
/*
2278+
* We negotiated with success, so we need to refill the recv queue.
2279+
* We do that with sc->idle.immediate_work still being disabled
2280+
* via smbdirect_socket_init(), so that queue_work(sc->workqueue,
2281+
* &sc->idle.immediate_work) in smb_direct_post_recv_credits()
2282+
* is a no-op.
2283+
*
2284+
* The message that grants the credits to the client is
2285+
* the negotiate response.
2286+
*/
2287+
INIT_WORK(&sc->recv_io.posted.refill_work, smb_direct_post_recv_credits);
2288+
smb_direct_post_recv_credits(&sc->recv_io.posted.refill_work);
2289+
if (unlikely(sc->first_error))
2290+
return sc->first_error;
2291+
INIT_WORK(&sc->idle.immediate_work, smb_direct_send_immediate_work);
2292+
2293+
respond:
2294+
ret = smb_direct_send_negotiate_response(sc, ret);
2295+
22762296
return ret;
22772297
}
22782298

0 commit comments

Comments
 (0)