From b163a887154edb89161337ed2a817bac4034f3ab Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Wed, 7 Apr 2021 21:54:26 +0800 Subject: [PATCH] nvmf/vfio-user: calculate MDTS based on transport iovcnt This will ensure that we can't exceed the iovcnt when parse NVMe PRP list to req->iov. Also comment that the iovcnt in vfio-user transport is used to track each gpa_to_vva map, for NVMe PRP list command, the PRP2 itself also will use one entry, so we need add one more entry for this case. Fix issue #1864. Change-Id: I06c7137e2c4637c9501f82a9eb1c8e4395d819cd Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7264 Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Reviewed-by: Jim Harris --- lib/nvmf/vfio_user.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index f3a5ab7b2..6689e7c6c 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -55,8 +55,8 @@ #define NVMF_VFIO_USER_DEFAULT_AQ_DEPTH 32 #define NVMF_VFIO_USER_DEFAULT_MAX_QPAIRS_PER_CTRLR 64 #define NVMF_VFIO_USER_DEFAULT_IN_CAPSULE_DATA_SIZE 0 -#define NVMF_VFIO_USER_DEFAULT_MAX_IO_SIZE 131072 -#define NVMF_VFIO_USER_DEFAULT_IO_UNIT_SIZE 131072 +#define NVMF_VFIO_USER_DEFAULT_MAX_IO_SIZE ((NVMF_REQ_MAX_BUFFERS - 1) << SHIFT_4KB) +#define NVMF_VFIO_USER_DEFAULT_IO_UNIT_SIZE NVMF_VFIO_USER_DEFAULT_MAX_IO_SIZE #define NVMF_VFIO_USER_DEFAULT_NUM_SHARED_BUFFERS 512 /* internal buf size */ #define NVMF_VFIO_USER_DEFAULT_BUFFER_CACHE_SIZE 0 @@ -73,8 +73,8 @@ struct nvmf_vfio_user_qpair; typedef int (*nvmf_vfio_user_req_cb_fn)(struct nvmf_vfio_user_req *req, void *cb_arg); -#define NVMF_VFIO_USER_MDTS 32 -#define NVMF_VFIO_USER_MAX_IOVECS (NVMF_VFIO_USER_MDTS + 1) +/* 1 more for PRP2 list itself */ +#define NVMF_VFIO_USER_MAX_IOVECS (NVMF_REQ_MAX_BUFFERS + 1) struct nvmf_vfio_user_req { struct spdk_nvmf_request req; @@ -85,6 +85,7 @@ struct nvmf_vfio_user_req { nvmf_vfio_user_req_cb_fn cb_fn; void *cb_arg; + /* placeholder for gpa_to_vva memory map table, the IO buffer doesn't use it */ dma_sg_t sg[NVMF_VFIO_USER_MAX_IOVECS]; struct iovec iov[NVMF_VFIO_USER_MAX_IOVECS]; uint8_t iovcnt;