From a773ed9a9a313ec51a18582f60a98b6e5906fb43 Mon Sep 17 00:00:00 2001 From: Jun Zeng Date: Mon, 13 Jun 2022 16:47:42 +0800 Subject: [PATCH] lib/vfio_user: change the calculation of bar_addr When calculating the bar_addr which is used to access SPARSE MMAP area, we should use the (offset - region->mmaps[i].offset) as the increment to get the valid access address. Signed-off-by: Jun Zeng Change-Id: Ie5d0c63cf572847d15dc92f0995fddecf35f1cdc Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13021 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu Reviewed-by: Xiaodong Liu Reviewed-by: Jim Harris Reviewed-by: Dong Yi Tested-by: SPDK CI Jenkins --- lib/vfio_user/host/vfio_user_pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vfio_user/host/vfio_user_pci.c b/lib/vfio_user/host/vfio_user_pci.c index 254033957..9ff6cf0ba 100644 --- a/lib/vfio_user/host/vfio_user_pci.c +++ b/lib/vfio_user/host/vfio_user_pci.c @@ -38,7 +38,7 @@ spdk_vfio_user_pci_bar_access(struct vfio_device *dev, uint32_t index, uint64_t if ((offset >= region->mmaps[i].offset) && (offset + len <= region->mmaps[i].offset + region->mmaps[i].size)) { assert(region->mmaps[i].mem != NULL); - void *bar_addr = region->mmaps[i].mem + offset; + void *bar_addr = region->mmaps[i].mem + offset - region->mmaps[i].offset; if (is_write) { memcpy(bar_addr, buf, len); } else {