aboutsummaryrefslogtreecommitdiff
path: root/lib/libvfio-user.c
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-05-24 10:42:42 +0100
committerGitHub <noreply@github.com>2021-05-24 10:42:42 +0100
commitbf3938dec68e1c820063db4f63aa2355c5703e4b (patch)
treeddb63a16a166d52ee8f5506f649faee79ada2240 /lib/libvfio-user.c
parent300f87e1b02e979da8cec444249f09ea0ef167a0 (diff)
downloadlibvfio-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 'lib/libvfio-user.c')
-rw-r--r--lib/libvfio-user.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index c4f6c42..ffd603b 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -379,14 +379,6 @@ handle_device_get_info(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg)
return 0;
}
-#define VFU_REGION_SHIFT 40
-
-static inline uint64_t
-region_to_offset(uint32_t region)
-{
- return (uint64_t)region << VFU_REGION_SHIFT;
-}
-
int
handle_device_get_region_info(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg)
{
@@ -428,7 +420,7 @@ handle_device_get_region_info(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg)
/* This might be more than the buffer we actually return. */
out_info->argsz = sizeof(*out_info) + caps_size;
out_info->index = in_info->index;
- out_info->offset = region_to_offset(out_info->index);
+ out_info->offset = vfu_reg->offset;
out_info->size = vfu_reg->size;
out_info->flags = 0;
@@ -1325,7 +1317,8 @@ validate_sparse_mmaps_for_migr_reg(vfu_reg_info_t *reg)
int
vfu_setup_region(vfu_ctx_t *vfu_ctx, int region_idx, size_t size,
vfu_region_access_cb_t *cb, int flags,
- struct iovec *mmap_areas, uint32_t nr_mmap_areas, int fd)
+ struct iovec *mmap_areas, uint32_t nr_mmap_areas,
+ int fd, uint64_t offset)
{
struct iovec whole_region = { .iov_base = 0, .iov_len = size };
vfu_reg_info_t *reg;
@@ -1373,6 +1366,7 @@ vfu_setup_region(vfu_ctx_t *vfu_ctx, int region_idx, size_t size,
reg->size = size;
reg->cb = cb;
reg->fd = fd;
+ reg->offset = offset;
if (mmap_areas == NULL && reg->fd != -1) {
mmap_areas = &whole_region;
@@ -1596,10 +1590,4 @@ vfu_dma_write(vfu_ctx_t *vfu_ctx, dma_sg_t *sg, void *data)
return ret;
}
-uint64_t
-vfu_region_to_offset(uint32_t region)
-{
- return region_to_offset(region);
-}
-
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */