Skip to content

Commit

Permalink
nvmf: Fail pass through commands while a controller is not associated
Browse files Browse the repository at this point in the history
Previously this just dereferenced NULL qp pointers and panicked.
Instead, use a shared lock on the connection lock to protect access to
the qp pointers and allocate a request.  If the controller is not
associated, fail the request with ECONNABORTED.

Possibly this should be honoring kern.nvmf.fail_on_disconnection and
block waiting for a reconnect request while disconnected if that
tunable is false.

Reported by:	Suhas Lokesha <[email protected]>
Sponsored by:	Chelsio Communications
  • Loading branch information
bsdjhb committed Oct 17, 2024
1 parent b08d332 commit d1516ec
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sys/dev/nvmf/host/nvmf.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,12 +972,21 @@ nvmf_passthrough_cmd(struct nvmf_softc *sc, struct nvme_pt_command *pt,
cmd.cdw14 = pt->cmd.cdw14;
cmd.cdw15 = pt->cmd.cdw15;

sx_slock(&sc->connection_lock);
if (sc->admin == NULL || sc->detaching) {
device_printf(sc->dev,
"failed to send passthrough command\n");
error = ECONNABORTED;
sx_sunlock(&sc->connection_lock);
goto error;
}
if (admin)
qp = sc->admin;
else
qp = nvmf_select_io_queue(sc);
nvmf_status_init(&status);
req = nvmf_allocate_request(qp, &cmd, nvmf_complete, &status, M_WAITOK);
sx_sunlock(&sc->connection_lock);
if (req == NULL) {
device_printf(sc->dev, "failed to send passthrough command\n");
error = ECONNABORTED;
Expand Down

0 comments on commit d1516ec

Please sign in to comment.