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; } } }