git: ef052adf09f2 - main - nvmf: Narrow scope of sim lock in nvmf_sim_io

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 26 Sep 2024 01:15:24 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=ef052adf09f25a20e694c3375cc7a0edd4cb0a52

commit ef052adf09f25a20e694c3375cc7a0edd4cb0a52
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-09-26 01:14:06 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-09-26 01:14:06 +0000

    nvmf: Narrow scope of sim lock in nvmf_sim_io
    
    nvmf_submit_request() handles races with concurrent queue pair
    destruction (or the queue pair being destroyed between
    nvmf_allocate_request and nvmf_submit_request), so the lock is not
    needed here.  This avoids holding the lock across transport-specific
    logic such as queueing mbufs for PDUs to a socket buffer, etc.
    
    Holding the lock across nvmf_allocate_request() ensures that the queue
    pair pointers in the softc are still valid as shutdown attempts will
    block on the lock before destroying the queue pairs.
    
    Sponsored by:   Chelsio Communications
---
 sys/dev/nvmf/host/nvmf_sim.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sys/dev/nvmf/host/nvmf_sim.c b/sys/dev/nvmf/host/nvmf_sim.c
index 8850174edf24..de9e958d8afd 100644
--- a/sys/dev/nvmf/host/nvmf_sim.c
+++ b/sys/dev/nvmf/host/nvmf_sim.c
@@ -125,8 +125,8 @@ nvmf_sim_io(struct nvmf_softc *sc, union ccb *ccb)
 		qp = sc->admin;
 	req = nvmf_allocate_request(qp, &nvmeio->cmd, nvmf_ccb_complete,
 	    ccb, M_NOWAIT);
+	mtx_unlock(&sc->sim_mtx);
 	if (req == NULL) {
-		mtx_unlock(&sc->sim_mtx);
 		nvmeio->ccb_h.status = CAM_RESRC_UNAVAIL;
 		xpt_done(ccb);
 		return;
@@ -150,7 +150,6 @@ nvmf_sim_io(struct nvmf_softc *sc, union ccb *ccb)
 	    ("%s: incoming CCB is not in-progress", __func__));
 	ccb->ccb_h.status |= CAM_SIM_QUEUED;
 	nvmf_submit_request(req);
-	mtx_unlock(&sc->sim_mtx);
 }
 
 static void