From e7519bc2f99dd623d2385d11933bd11a3e3d517d Mon Sep 17 00:00:00 2001 From: Chen Qun Date: Tue, 7 Sep 2021 15:14:12 +0800 Subject: [PATCH] vfio/common: Fix incorrect address alignment in vfio_dma_map_ram_section The 'iova' will be passed to host kernel for mapping with the HPA. It is related to the host page size. So TARGET_PAGE_ALIGN should be replaced by REAL_HOST_PAGE_ALIGN. In the case of large granularity (64K), it may return early when map MMIO RAM section. And because of the inconsistency with vfio_dma_unmap_ram_section, it may cause 'assert(qrange)' in vfio_dma_unmap. Signed-off-by: Kunkun Jiang Signed-off-by: Zenghui Yu Signed-off-by: imxcc (cherry picked from commit af442e7ad177338fae5a5399de604cf8bef777ee) --- ...incorrect-address-alignment-in-vfio_.patch | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 vfio-common-Fix-incorrect-address-alignment-in-vfio_.patch diff --git a/vfio-common-Fix-incorrect-address-alignment-in-vfio_.patch b/vfio-common-Fix-incorrect-address-alignment-in-vfio_.patch new file mode 100644 index 0000000..d61408e --- /dev/null +++ b/vfio-common-Fix-incorrect-address-alignment-in-vfio_.patch @@ -0,0 +1,40 @@ +From c2a4ce033db6ab74256e28da382c797a98047d4b Mon Sep 17 00:00:00 2001 +From: Kunkun Jiang +Date: Tue, 7 Sep 2021 15:14:12 +0800 +Subject: [PATCH] vfio/common: Fix incorrect address alignment in + vfio_dma_map_ram_section + +The 'iova' will be passed to host kernel for mapping with the +HPA. It is related to the host page size. So TARGET_PAGE_ALIGN +should be replaced by REAL_HOST_PAGE_ALIGN. In the case of +large granularity (64K), it may return early when map MMIO RAM +section. And because of the inconsistency with +vfio_dma_unmap_ram_section, it may cause 'assert(qrange)' +in vfio_dma_unmap. + +Signed-off-by: Kunkun Jiang +Signed-off-by: Zenghui Yu +--- + hw/vfio/common.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/hw/vfio/common.c b/hw/vfio/common.c +index 65f3979492..89c49f5508 100644 +--- a/hw/vfio/common.c ++++ b/hw/vfio/common.c +@@ -1059,10 +1059,10 @@ static int vfio_dma_map_ram_section(VFIOContainer *container, + + assert(memory_region_is_ram(section->mr)); + +- iova = TARGET_PAGE_ALIGN(section->offset_within_address_space); ++ iova = REAL_HOST_PAGE_ALIGN(section->offset_within_address_space); + llend = int128_make64(section->offset_within_address_space); + llend = int128_add(llend, section->size); +- llend = int128_and(llend, int128_exts64(TARGET_PAGE_MASK)); ++ llend = int128_and(llend, int128_exts64(qemu_real_host_page_mask)); + end = int128_get64(int128_sub(llend, int128_one())); + + vaddr = memory_region_get_ram_ptr(section->mr) + +-- +2.27.0 +