diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2019-09-04 09:05:29 -0400 |
---|---|---|
committer | Felipe Franciosi <felipe@nutanix.com> | 2019-09-05 16:45:35 +0100 |
commit | 6822da67762583e4a056566649578eea21801c9d (patch) | |
tree | c6ac6ea5488ab811cd3a64900c0ba89652eb55e5 /lib | |
parent | 97318bf57b28859ef70181754d904488ede83aec (diff) | |
download | libvfio-user-6822da67762583e4a056566649578eea21801c9d.zip libvfio-user-6822da67762583e4a056566649578eea21801c9d.tar.gz libvfio-user-6822da67762583e4a056566649578eea21801c9d.tar.bz2 |
fix offset to (region ID) * (1 << 40)
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libmuser.c | 15 | ||||
-rw-r--r-- | lib/libmuser_pci.c | 4 | ||||
-rw-r--r-- | lib/muser.h | 5 | ||||
-rw-r--r-- | lib/muser_priv.h | 3 |
4 files changed, 16 insertions, 11 deletions
diff --git a/lib/libmuser.c b/lib/libmuser.c index 3f92ee2..a66e5e7 100644 --- a/lib/libmuser.c +++ b/lib/libmuser.c @@ -417,6 +417,12 @@ dev_get_sparse_mmap_cap(lm_ctx_t *lm_ctx, lm_reg_info_t *lm_reg, return 0; } +uint64_t +region_offset(const uint32_t region) +{ + return (uint64_t)region << 40; +} + static long dev_get_reginfo(lm_ctx_t * lm_ctx, struct vfio_region_info *vfio_reg) { @@ -433,7 +439,7 @@ dev_get_reginfo(lm_ctx_t * lm_ctx, struct vfio_region_info *vfio_reg) return -EINVAL; } - vfio_reg->offset = lm_reg->offset; + vfio_reg->offset = region_offset(vfio_reg->index); vfio_reg->flags = lm_reg->flags; vfio_reg->size = lm_reg->size; @@ -633,9 +639,10 @@ lm_get_region(lm_ctx_t * const lm_ctx, const loff_t pos, const size_t count, for (i = 0; i < LM_DEV_NUM_REGS; i++) { const lm_reg_info_t * const reg_info = &pci_info->reg_info[i]; - if (pos >= reg_info->offset) { - if (pos - reg_info->offset + count <= reg_info->size) { - *off = pos - reg_info->offset; + const uint64_t _region_offset = region_offset(i); + if (pos >= _region_offset) { + if (pos - _region_offset + count <= reg_info->size) { + *off = pos - _region_offset; return i; } } diff --git a/lib/libmuser_pci.c b/lib/libmuser_pci.c index a33f14c..7131e94 100644 --- a/lib/libmuser_pci.c +++ b/lib/libmuser_pci.c @@ -275,7 +275,7 @@ muser_do_pci_hdr_access(lm_ctx_t * const lm_ctx, size_t * const count, assert(pos); assert(buf); - _pos = *pos - lm_get_region_info(lm_ctx)[LM_DEV_CFG_REG_IDX].offset; + _pos = *pos - region_offset(LM_DEV_CFG_REG_IDX); _count = MIN(*count, PCI_STD_HEADER_SIZEOF - _pos); if (is_write) { @@ -291,7 +291,7 @@ muser_do_pci_hdr_access(lm_ctx_t * const lm_ctx, size_t * const count, static inline bool muser_is_pci_hdr_access(const lm_reg_info_t * const reg_info, const loff_t pos) { - const off_t off = (loff_t) reg_info[LM_DEV_CFG_REG_IDX].offset; + const off_t off = (loff_t) region_offset(LM_DEV_CFG_REG_IDX); return pos - off >= 0 && pos - off < PCI_STD_HEADER_SIZEOF; } diff --git a/lib/muser.h b/lib/muser.h index c038e98..ac31a2e 100644 --- a/lib/muser.h +++ b/lib/muser.h @@ -122,11 +122,6 @@ typedef struct { uint32_t size; /* - * Region offset. - */ - uint64_t offset; - - /* * Callback function that is called when the region is read or written. */ lm_region_access_t *fn; diff --git a/lib/muser_priv.h b/lib/muser_priv.h index 45d3a3f..4df8b25 100644 --- a/lib/muser_priv.h +++ b/lib/muser_priv.h @@ -6,3 +6,6 @@ muser_pci_hdr_access(lm_ctx_t * const lm_ctx, size_t * const count, unsigned char *const buf); lm_reg_info_t *lm_get_region_info(lm_ctx_t * const lm_ctx); + +uint64_t region_offset(const uint32_t region); + |