From 1afe4de585c3f2562e3dea2301d109db11d8f8dd Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Mon, 9 Aug 2021 18:23:46 +0800 Subject: [PATCH] nvmf/vfio-user: refactor map_admin_cmd_req() PRP1 value 0 is a valid Guest physical address and it may use two vectors for one page, so we need to set `iovcnt` as the IO commands. Also fix the calculation for Get Log Page command. Change-Id: Ib036bcf1ca9f6644dfd8a7406fea37269cea5c73 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9122 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/nvmf/vfio_user.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index a5668ea33..1e7017503 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -2579,22 +2579,30 @@ map_admin_cmd_req(struct nvmf_vfio_user_ctrlr *ctrlr, struct spdk_nvmf_request * uint32_t len = 0; int iovcnt; - req->xfer = cmd->opc & 0x3; + req->xfer = spdk_nvme_opc_get_data_transfer(cmd->opc); req->length = 0; req->data = NULL; - switch (cmd->opc) { - case SPDK_NVME_OPC_IDENTIFY: - len = 4096; /* TODO: there should be a define somewhere for this */ - break; - case SPDK_NVME_OPC_GET_LOG_PAGE: - len = (cmd->cdw10_bits.get_log_page.numdl + 1) * 4; - break; - } - - if (!cmd->dptr.prp.prp1 || !len) { + if (req->xfer == SPDK_NVME_DATA_NONE) { return 0; } + + switch (cmd->opc) { + case SPDK_NVME_OPC_IDENTIFY: + len = 4096; + break; + case SPDK_NVME_OPC_GET_LOG_PAGE: + len = (((cmd->cdw11_bits.get_log_page.numdu << 16) | cmd->cdw10_bits.get_log_page.numdl) + 1) * 4; + break; + default: + /* + * CREATE IO SQ/CQ are processed separately in handle_create_io_q(). + * GET/SET FEATURES: no need to support Host Identifier for vfio-user transport. + * Let the NVMf library to decide other commands. + */ + return 0; + } + /* ADMIN command will not use SGL */ assert(req->cmd->nvme_cmd.psdt == 0); iovcnt = vfio_user_map_cmd(ctrlr, req, req->iov, len); @@ -2603,9 +2611,9 @@ map_admin_cmd_req(struct nvmf_vfio_user_ctrlr *ctrlr, struct spdk_nvmf_request * ctrlr_id(ctrlr), cmd->opc); return -1; } - req->length = len; req->data = req->iov[0].iov_base; + req->iovcnt = iovcnt; return 0; }