diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2021-05-28 15:43:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-28 15:43:33 +0100 |
commit | ad88ffd9acdf4deec83cb3f5fdae4fd62ec30efe (patch) | |
tree | 6063b57cd78f168832413c740ac9948e939811b3 /samples/client.c | |
parent | 226e04e322d1c2c5dc88561b5c8e0017cf793733 (diff) | |
download | libvfio-user-ad88ffd9acdf4deec83cb3f5fdae4fd62ec30efe.zip libvfio-user-ad88ffd9acdf4deec83cb3f5fdae4fd62ec30efe.tar.gz libvfio-user-ad88ffd9acdf4deec83cb3f5fdae4fd62ec30efe.tar.bz2 |
restore argsz for DMA map/unmap (#523)
use DMA map/unmap format similar to VFIO's
Using a DMA map/unmap format similar to VFIO's (vfio_iommu_type1_dma_map / vfio_iommu_type1_dma_unmap) makes it easier to adapt to future changes. Consequently we also honor the passed argsz.
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Reviewed-by: John Levon <john.levon@nutanitx.com>
Diffstat (limited to 'samples/client.c')
-rw-r--r-- | samples/client.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/samples/client.c b/samples/client.c index 0de23cf..82cb12b 100644 --- a/samples/client.c +++ b/samples/client.c @@ -540,7 +540,7 @@ wait_for_irq(int irq_fd) } static void -handle_dma_write(int sock, struct vfio_user_dma_region *dma_regions, +handle_dma_write(int sock, struct vfio_user_dma_map *dma_regions, int nr_dma_regions, int *dma_region_fds) { struct vfio_user_dma_region_access dma_access; @@ -589,7 +589,7 @@ handle_dma_write(int sock, struct vfio_user_dma_region *dma_regions, } static void -handle_dma_read(int sock, struct vfio_user_dma_region *dma_regions, +handle_dma_read(int sock, struct vfio_user_dma_map *dma_regions, int nr_dma_regions, int *dma_region_fds) { struct vfio_user_dma_region_access dma_access, *response; @@ -632,7 +632,7 @@ handle_dma_read(int sock, struct vfio_user_dma_region *dma_regions, } static void -handle_dma_io(int sock, struct vfio_user_dma_region *dma_regions, +handle_dma_io(int sock, struct vfio_user_dma_map *dma_regions, int nr_dma_regions, int *dma_region_fds) { handle_dma_write(sock, dma_regions, nr_dma_regions, dma_region_fds); @@ -640,7 +640,7 @@ handle_dma_io(int sock, struct vfio_user_dma_region *dma_regions, } static void -get_dirty_bitmaps(int sock, struct vfio_user_dma_region *dma_regions, +get_dirty_bitmaps(int sock, struct vfio_user_dma_map *dma_regions, UNUSED int nr_dma_regions) { struct vfio_iommu_type1_dirty_bitmap dirty_bitmap = { 0 }; @@ -1039,7 +1039,7 @@ migrate_to(char *old_sock_path, int *server_max_fds, } static void -map_dma_regions(int sock, struct vfio_user_dma_region *dma_regions, +map_dma_regions(int sock, struct vfio_user_dma_map *dma_regions, int *dma_region_fds, int nr_dma_regions) { int i, ret; @@ -1065,7 +1065,7 @@ map_dma_regions(int sock, struct vfio_user_dma_region *dma_regions, int main(int argc, char *argv[]) { int ret, sock, irq_fd; - struct vfio_user_dma_region *dma_regions; + struct vfio_user_dma_map *dma_regions; struct vfio_user_device_info client_dev_info = {0}; int *dma_region_fds; int i; @@ -1154,11 +1154,11 @@ int main(int argc, char *argv[]) dma_region_fds = alloca(sizeof(*dma_region_fds) * nr_dma_regions); for (i = 0; i < nr_dma_regions; i++) { + dma_regions[i].argsz = sizeof(struct vfio_user_dma_map); dma_regions[i].addr = i * sysconf(_SC_PAGESIZE); dma_regions[i].size = sysconf(_SC_PAGESIZE); dma_regions[i].offset = dma_regions[i].addr; - dma_regions[i].prot = PROT_READ | PROT_WRITE; - dma_regions[i].flags = VFIO_USER_F_DMA_REGION_MAPPABLE; + dma_regions[i].flags = VFIO_USER_F_DMA_REGION_READ | VFIO_USER_F_DMA_REGION_WRITE | VFIO_USER_F_DMA_REGION_MAPPABLE; dma_region_fds[i] = fileno(fp); } @@ -1212,19 +1212,18 @@ int main(int argc, char *argv[]) * * unmap the first group of the DMA regions */ - { - struct vfio_user_dma_region r[server_max_fds]; - memcpy(r, dma_regions, sizeof(r)); - for (i = 0; i < (int)ARRAY_SIZE(r); i++) { - r[i].flags = 0; - ret = tran_sock_msg(sock, 7, VFIO_USER_DMA_UNMAP, &r[i], - sizeof(struct vfio_user_dma_region), - NULL, NULL, 0); + for (i = 0; i < server_max_fds; i++) { + struct vfio_user_dma_unmap r = { + .argsz = sizeof(r), + .addr = dma_regions[i].addr, + .size = dma_regions[i].size + }; + ret = tran_sock_msg(sock, 7, VFIO_USER_DMA_UNMAP, &r, sizeof(r), + NULL, &r, sizeof(r)); + if (ret < 0) { + err(EXIT_FAILURE, "failed to unmap DMA region"); } } - if (ret < 0) { - err(EXIT_FAILURE, "failed to unmap DMA regions"); - } /* * Schedule an interrupt in 3 seconds from now in the old server and then |