From b70b16acba89013c07cc95f97f52b12364a34340 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Tue, 1 Jun 2021 20:02:25 +0800 Subject: [PATCH] nvmf: don't use request internal variable after req_complete callback vfio-user transport `req_complete` callback will zero the internal NVMe command and response fields, the common NVMf library should not use them after the callback, so here we use stack variables to save them before the `req_complete` callback. Fix issue #1965. Change-Id: Iff2342b6095d9496cdf112d657a0a99ce1fb5d12 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8129 Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Karol Latecki Reviewed-by: Reviewed-by: Jim Harris --- lib/nvmf/ctrlr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/nvmf/ctrlr.c b/lib/nvmf/ctrlr.c index a0b7a3306..4b98fe091 100644 --- a/lib/nvmf/ctrlr.c +++ b/lib/nvmf/ctrlr.c @@ -3579,10 +3579,13 @@ _nvmf_request_complete(void *ctx) bool is_aer = false; uint32_t nsid; bool paused; + uint8_t opcode; rsp->sqid = 0; rsp->status.p = 0; rsp->cid = req->cmd->nvme_cmd.cid; + nsid = req->cmd->nvme_cmd.nsid; + opcode = req->cmd->nvmf_cmd.opcode; qpair = req->qpair; if (qpair->ctrlr) { @@ -3615,13 +3618,11 @@ _nvmf_request_complete(void *ctx) /* AER cmd is an exception */ if (sgroup && !is_aer) { - if (spdk_unlikely(req->cmd->nvmf_cmd.opcode == SPDK_NVME_OPC_FABRIC || + if (spdk_unlikely(opcode == SPDK_NVME_OPC_FABRIC || nvmf_qpair_is_admin_queue(qpair))) { assert(sgroup->mgmt_io_outstanding > 0); sgroup->mgmt_io_outstanding--; } else { - nsid = req->cmd->nvme_cmd.nsid; - /* NOTE: This implicitly also checks for 0, since 0 - 1 wraps around to UINT32_MAX. */ if (spdk_likely(nsid - 1 < sgroup->num_ns)) { sgroup->ns_info[nsid - 1].io_outstanding--;