nvmf/vfio-user: unregister the memory region whether controller is active or not

The controller may be freed eailer than endpoint, so we still
need to unregister the memory region from SPDK.  The case
can happen when removing the listener while VM is connected.

Change-Id: I95d49cefdbff3e0bdea316fac824ef8b218fcd2c
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10378
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Changpeng Liu 2021-12-09 20:04:04 +08:00 committed by Jim Harris
parent 69dc63da50
commit c2fa2d50e1

View File

@ -1617,31 +1617,30 @@ memory_region_remove_cb(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info)
}
assert(endpoint != NULL);
if (endpoint->ctrlr == NULL) {
return 0;
}
ctrlr = endpoint->ctrlr;
if (endpoint->ctrlr != NULL) {
ctrlr = endpoint->ctrlr;
SPDK_DEBUGLOG(nvmf_vfio, "%s: unmap IOVA %#lx-%#lx\n", ctrlr_id(ctrlr),
(uintptr_t)info->mapping.iov_base,
(uintptr_t)info->mapping.iov_base + info->mapping.iov_len);
SPDK_DEBUGLOG(nvmf_vfio, "%s: unmap IOVA %#lx-%#lx\n", ctrlr_id(ctrlr),
(uintptr_t)info->mapping.iov_base,
(uintptr_t)info->mapping.iov_base + info->mapping.iov_len);
map_start = info->mapping.iov_base;
map_end = info->mapping.iov_base + info->mapping.iov_len;
map_start = info->mapping.iov_base;
map_end = info->mapping.iov_base + info->mapping.iov_len;
pthread_mutex_lock(&endpoint->lock);
TAILQ_FOREACH(qpair, &ctrlr->connected_qps, tailq) {
if (qpair->sq.addr >= map_start && qpair->sq.addr <= map_end) {
unmap_q(ctrlr, &qpair->sq);
qpair->sq_state = VFIO_USER_SQ_INACTIVE;
}
cqpair = ctrlr->qp[qpair->sq.cqid];
if (cqpair->cq.addr >= map_start && cqpair->cq.addr <= map_end) {
unmap_q(ctrlr, &cqpair->cq);
pthread_mutex_lock(&endpoint->lock);
TAILQ_FOREACH(qpair, &ctrlr->connected_qps, tailq) {
if (qpair->sq.addr >= map_start && qpair->sq.addr <= map_end) {
unmap_q(ctrlr, &qpair->sq);
qpair->sq_state = VFIO_USER_SQ_INACTIVE;
}
cqpair = ctrlr->qp[qpair->sq.cqid];
if (cqpair->cq.addr >= map_start && cqpair->cq.addr <= map_end) {
unmap_q(ctrlr, &cqpair->cq);
}
}
pthread_mutex_unlock(&endpoint->lock);
}
pthread_mutex_unlock(&endpoint->lock);
if (info->prot == (PROT_WRITE | PROT_READ)) {
ret = spdk_mem_unregister(info->mapping.iov_base, info->mapping.iov_len);