diff options
author | John Levon <john.levon@nutanix.com> | 2021-05-24 10:42:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-24 10:42:42 +0100 |
commit | bf3938dec68e1c820063db4f63aa2355c5703e4b (patch) | |
tree | ddb63a16a166d52ee8f5506f649faee79ada2240 /samples/client.c | |
parent | 300f87e1b02e979da8cec444249f09ea0ef167a0 (diff) | |
download | libvfio-user-bf3938dec68e1c820063db4f63aa2355c5703e4b.zip libvfio-user-bf3938dec68e1c820063db4f63aa2355c5703e4b.tar.gz libvfio-user-bf3938dec68e1c820063db4f63aa2355c5703e4b.tar.bz2 |
fix region offset handling (#485)
The specification states that the region offset given in the region info should
be used as the "offset" when mmap()ing the region from the client side. However,
the library instead implemented a fixed offset scheme similar to that of vfio -
and no clients actually set up the file like that.
Instead, let servers define their own offsets, and pass them through to clients
as is. It's up to the server to decide how its backing file or files is
organized.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'samples/client.c')
-rw-r--r-- | samples/client.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/samples/client.c b/samples/client.c index 420269c..a533d4f 100644 --- a/samples/client.c +++ b/samples/client.c @@ -262,7 +262,8 @@ do_get_device_region_info(int sock, struct vfio_region_info *region_info, } static void -mmap_sparse_areas(int *fds, struct vfio_region_info_cap_sparse_mmap *sparse) +mmap_sparse_areas(int *fds, struct vfio_region_info *region_info, + struct vfio_region_info_cap_sparse_mmap *sparse) { size_t i; @@ -281,7 +282,8 @@ mmap_sparse_areas(int *fds, struct vfio_region_info_cap_sparse_mmap *sparse) } buf[ret + 1] = '\0'; addr = mmap(NULL, sparse->areas[i].size, PROT_READ | PROT_WRITE, - MAP_SHARED, fds[i], sparse->areas[i].offset); + MAP_SHARED, fds[i], region_info->offset + + sparse->areas[i].offset); if (addr == MAP_FAILED) { err(EXIT_FAILURE, "failed to mmap sparse region #%lu in %s (%#llx-%#llx)", @@ -331,7 +333,7 @@ get_device_region_info(int sock, uint32_t index) assert((index == VFU_PCI_DEV_BAR1_REGION_IDX && nr_fds == 2) || (index == VFU_PCI_DEV_MIGR_REGION_IDX && nr_fds == 1)); assert(nr_fds == sparse->nr_areas); - mmap_sparse_areas(fds, sparse); + mmap_sparse_areas(fds, region_info, sparse); } } } |