From dc032663661db4efeaf18d84d594307a15ecb55c Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Fri, 12 Mar 2021 21:14:56 +0800 Subject: [PATCH] nvmf/vfio-user: unmap queue pairs when removing memory region Actually we already do this when removeing a memory region, but the check for it is too strict, we should unmap queue pairs when the queue pair is in the memory region. Change-Id: Ia646a0255e32ecdd0a70537a8011ce622eb59195 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6861 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- lib/nvmf/vfio_user.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index 9e921d550..a06c3a890 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -1066,15 +1066,13 @@ memory_region_add_cb(vfu_ctx_t *vfu_ctx, uint64_t iova, uint64_t len, uint32_t p int i, ret; assert(endpoint != NULL); - if (endpoint->ctrlr == NULL) { return; } - ctrlr = endpoint->ctrlr; SPDK_DEBUGLOG(nvmf_vfio, "%s: map IOVA %#lx-%#lx\n", - ctrlr_id(ctrlr), iova, len); + ctrlr_id(ctrlr), iova, iova + len); for (i = 0; i < NVMF_VFIO_USER_DEFAULT_MAX_QPAIRS_PER_CTRLR; i++) { qpair = ctrlr->qp[i]; @@ -1109,7 +1107,6 @@ memory_region_add_cb(vfu_ctx_t *vfu_ctx, uint64_t iova, uint64_t len, uint32_t p i, cq->prp1, cq->prp1 + cq->size * 16); continue; } - qpair->state = VFIO_USER_QPAIR_ACTIVE; } } @@ -1121,27 +1118,28 @@ memory_region_remove_cb(vfu_ctx_t *vfu_ctx, uint64_t iova, uint64_t len) struct nvmf_vfio_user_endpoint *endpoint = vfu_get_private(vfu_ctx); struct nvmf_vfio_user_ctrlr *ctrlr; + struct nvmf_vfio_user_qpair *qpair; int i; assert(endpoint != NULL); - if (endpoint->ctrlr == NULL) { return 0; } - ctrlr = endpoint->ctrlr; - SPDK_DEBUGLOG(nvmf_vfio, "%s: unmap IOVA %#lx\n", - ctrlr_id(ctrlr), iova); + SPDK_DEBUGLOG(nvmf_vfio, "%s: unmap IOVA %#lx-%#lx\n", + ctrlr_id(ctrlr), iova, iova + len); for (i = 0; i < NVMF_VFIO_USER_DEFAULT_MAX_QPAIRS_PER_CTRLR; i++) { - if (ctrlr->qp[i] == NULL) { + qpair = ctrlr->qp[i]; + if (qpair == NULL) { continue; } - if (ctrlr->qp[i]->cq.sg.dma_addr == iova || - ctrlr->qp[i]->sq.sg.dma_addr == iova) { - unmap_qp(ctrlr->qp[i]); - ctrlr->qp[i]->state = VFIO_USER_QPAIR_INACTIVE; + + if ((qpair->cq.sg.dma_addr >= iova && qpair->cq.sg.dma_addr < iova + len) || + (qpair->sq.sg.dma_addr >= iova && qpair->sq.sg.dma_addr < iova + len)) { + unmap_qp(qpair); + qpair->state = VFIO_USER_QPAIR_INACTIVE; } } @@ -1183,12 +1181,14 @@ nvmf_vfio_user_prop_req_rsp(struct nvmf_vfio_user_req *req, void *cb_arg) SPDK_ERRLOG("%s: failed to map Admin queue\n", ctrlr_id(qpair->ctrlr)); return ret; } + qpair->state = VFIO_USER_QPAIR_ACTIVE; } else if ((cc->bits.en == 0 && cc->bits.shn == 0) || (cc->bits.en == 1 && cc->bits.shn != 0)) { SPDK_DEBUGLOG(nvmf_vfio, "%s: UNMAP Admin queue\n", ctrlr_id(qpair->ctrlr)); unmap_admin_queue(qpair->ctrlr); + qpair->state = VFIO_USER_QPAIR_INACTIVE; } } }