diff options
author | John Levon <john.levon@nutanix.com> | 2021-08-17 17:08:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-17 17:08:05 +0100 |
commit | 46ed1dbd8e692ee53a544022dd70151f21a4e725 (patch) | |
tree | f702a1538d0bc001d794c652a6edb189f97fcb48 | |
parent | b4760d54d0f75eac27b1439e436eea84c7338bda (diff) | |
download | libvfio-user-46ed1dbd8e692ee53a544022dd70151f21a4e725.zip libvfio-user-46ed1dbd8e692ee53a544022dd70151f21a4e725.tar.gz libvfio-user-46ed1dbd8e692ee53a544022dd70151f21a4e725.tar.bz2 |
fix dma_{map,unmap}_sg() array handling (#586)
Multiple places in dma_map_sg() and dma_unmap_sg() were dereferencing sg[0]
instead of the correct index.
Take the opportunity to improve the doc comments at the same time.
Reported-by: Changpeng Liu <changpeng.liu@intel.com>
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
-rw-r--r-- | include/libvfio-user.h | 18 | ||||
-rw-r--r-- | lib/dma.h | 12 |
2 files changed, 15 insertions, 15 deletions
diff --git a/include/libvfio-user.h b/include/libvfio-user.h index f91f3c7..5e379df 100644 --- a/include/libvfio-user.h +++ b/include/libvfio-user.h @@ -624,9 +624,9 @@ int vfu_irq_trigger(vfu_ctx_t *vfu_ctx, uint32_t subindex); /** - * Takes a guest physical address and returns a list of scatter/gather entries - * than can be individually mapped in the program's virtual memory. A single - * linear guest physical address span may need to be split into multiple + * Takes a guest physical address range and populates an array of scatter/gather + * entries than can be individually mapped in the program's virtual memory. A + * single linear guest physical address span may need to be split into multiple * scatter/gather regions due to limitations of how memory can be mapped. * * vfu_setup_device_dma() must have been called prior to using this function. @@ -650,9 +650,9 @@ vfu_addr_to_sg(vfu_ctx_t *vfu_ctx, vfu_dma_addr_t dma_addr, size_t len, dma_sg_t *sg, int max_sg, int prot); /** - * Maps a list scatter/gather entries from the guest's physical address space - * to the program's virtual memory. It is the caller's responsibility to remove - * the mappings by calling vfu_unmap_sg(). + * Maps scatter/gather entries from the guest's physical address space to the + * process's virtual memory. It is the caller's responsibility to remove the + * mappings by calling vfu_unmap_sg(). * * This is only supported when a @dma_unregister callback is provided to * vfu_setup_device_dma(). @@ -660,7 +660,7 @@ vfu_addr_to_sg(vfu_ctx_t *vfu_ctx, vfu_dma_addr_t dma_addr, size_t len, * @vfu_ctx: the libvfio-user context * @sg: array of scatter/gather entries returned by vfu_addr_to_sg. These * entries must not be modified and the array must not be deallocated - * until vfu_unmap_sg() has been called for each entry. + * until vfu_unmap_sg() has been called. * @iov: array of iovec structures (defined in <sys/uio.h>) to receive each * mapping * @cnt: number of scatter/gather entries to map @@ -673,8 +673,8 @@ vfu_map_sg(vfu_ctx_t *vfu_ctx, dma_sg_t *sg, struct iovec *iov, int cnt, int flags); /** - * Unmaps a list scatter/gather entries (previously mapped by vfu_map_sg()) from - * the program's virtual memory. + * Unmaps scatter/gather entries (previously mapped by vfu_map_sg()) from + * the process's virtual memory. * * @vfu_ctx: the libvfio-user context * @sg: array of scatter/gather entries to unmap @@ -245,15 +245,15 @@ dma_map_sg(dma_controller_t *dma, dma_sg_t *sg, struct iovec *iov, return ERROR_INT(EFAULT); } - if (sg->writeable) { + if (sg[i].writeable) { if (dma->dirty_pgsize > 0) { - _dma_mark_dirty(dma, region, sg); + _dma_mark_dirty(dma, region, &sg[i]); } LIST_INSERT_HEAD(&dma->maps, &sg[i], entry); } vfu_log(dma->vfu_ctx, LOG_DEBUG, "map %p-%p", - sg->dma_addr + sg->offset, - sg->dma_addr + sg->offset + sg->length); + sg[i].dma_addr + sg[i].offset, + sg[i].dma_addr + sg[i].offset + sg[i].length); iov[i].iov_base = region->info.vaddr + sg[i].offset; iov[i].iov_len = sg[i].length; region->refcnt++; @@ -282,8 +282,8 @@ dma_unmap_sg(dma_controller_t *dma, const dma_sg_t *sg, /* bad region */ continue; } - if (sg->writeable) { - LIST_REMOVE(sg, entry); + if (sg[i].writeable) { + LIST_REMOVE(&sg[i], entry); } vfu_log(dma->vfu_ctx, LOG_DEBUG, "unmap %p-%p", sg[i].dma_addr + sg[i].offset, |