diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2021-03-04 16:23:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-04 16:23:45 +0000 |
commit | a8242d117118d5191dad69a96e28a21d66fe8b50 (patch) | |
tree | 0e68a9f63e7bdb7933a732f90edaed2ca9e9b16c /lib | |
parent | b0cebe8340579c0a31b95af1e07bb7d214ac79c8 (diff) | |
download | libvfio-user-a8242d117118d5191dad69a96e28a21d66fe8b50.zip libvfio-user-a8242d117118d5191dad69a96e28a21d66fe8b50.tar.gz libvfio-user-a8242d117118d5191dad69a96e28a21d66fe8b50.tar.bz2 |
don't munmap(2) unmapped DMA region (#384)
Plus always notify user when DMA region is removed.
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Reviewed-by: John Levon <john.levon@nutanix.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dma.c | 43 |
1 files changed, 22 insertions, 21 deletions
@@ -156,29 +156,30 @@ dma_controller_remove_region(dma_controller_t *dma, for (idx = 0; idx < dma->nregions; idx++) { region = &dma->regions[idx]; - if (region->dma_addr == dma_addr && region->size == size) { - if (region->refcnt > 0) { - err = unmap_dma(data, region->dma_addr, region->size); - if (err != 0) { - vfu_log(dma->vfu_ctx, LOG_ERR, - "failed to notify of removal of DMA region %#lx-%#lx: %s\n", - region->dma_addr, region->dma_addr + region->size, - strerror(-err)); - return err; - } - assert(region->refcnt == 0); - } + if (region->dma_addr != dma_addr || region->size != size) { + continue; + } + err = unmap_dma(data, region->dma_addr, region->size); + if (err != 0) { + vfu_log(dma->vfu_ctx, LOG_ERR, + "failed to notify of removal of DMA region %#lx-%#lx: %s\n", + region->dma_addr, region->dma_addr + region->size, + strerror(-err)); + return err; + } + assert(region->refcnt == 0); + if (region->virt_addr != NULL) { _dma_controller_do_remove_region(dma, region); - if (dma->nregions > 1) - /* - * FIXME valgrind complains with 'Source and destination overlap in memcpy', - * check whether memmove eliminates this warning. - */ - memcpy(region, &dma->regions[dma->nregions - 1], - sizeof(*region)); - dma->nregions--; - return 0; } + if (dma->nregions > 1) + /* + * FIXME valgrind complains with 'Source and destination overlap in memcpy', + * check whether memmove eliminates this warning. + */ + memcpy(region, &dma->regions[dma->nregions - 1], + sizeof(*region)); + dma->nregions--; + return 0; } return -ENOENT; } |