Skip to content

Commit

Permalink
nvme/util: do not unmap already mapped addresses
Browse files Browse the repository at this point in the history
In nvme_sync(), only unmap addresses that are not currently mapped.

Signed-off-by: Klaus Jensen <[email protected]>
  • Loading branch information
birkelund committed Apr 17, 2024
1 parent 2ad7c83 commit c16ef72
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/nvme/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,20 @@ int nvme_sync(struct nvme_ctrl *ctrl, struct nvme_sq *sq, void *sqe, void *buf,
struct nvme_cqe cqe;
struct nvme_rq *rq;
uint64_t iova;
bool do_unmap = false;
int ret = 0;

if (buf && iommu_map_vaddr(__iommu_ctx(ctrl), buf, len, &iova, IOMMU_MAP_EPHEMERAL)) {
log_debug("failed to map vaddr\n");
return -1;
if (buf) {
struct iommu_ctx *ctx = __iommu_ctx(ctrl);

if (!iommu_translate_vaddr(ctx, buf, &iova)) {
do_unmap = true;

if (iommu_map_vaddr(ctx, buf, len, &iova, IOMMU_MAP_EPHEMERAL)) {
log_debug("failed to map vaddr\n");
return -1;
}
}
}

rq = nvme_rq_acquire_atomic(sq);
Expand Down Expand Up @@ -120,7 +129,7 @@ int nvme_sync(struct nvme_ctrl *ctrl, struct nvme_sq *sq, void *sqe, void *buf,
release_rq:
nvme_rq_release_atomic(rq);

if (buf)
if (buf && do_unmap)
log_fatal_if(iommu_unmap_vaddr(__iommu_ctx(ctrl), buf, NULL),
"iommu_unmap_vaddr\n");

Expand Down

0 comments on commit c16ef72

Please sign in to comment.