qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] vfio/common: Some fixes about region_add/region_del
@ 2021-08-23 11:56 Kunkun Jiang
  2021-08-23 11:56 ` [PATCH 1/2] vfio/common: Add trace point when a MMIO RAM section less than minimum size Kunkun Jiang
  2021-08-23 11:56 ` [PATCH 2/2] vfio/common: Fix address alignment in region_add/region_del Kunkun Jiang
  0 siblings, 2 replies; 3+ messages in thread
From: Kunkun Jiang @ 2021-08-23 11:56 UTC (permalink / raw)
  To: Alex Williamson, Eric Auger, open list:All patches CC here
  Cc: wanghaibin.wang, Kunkun Jiang

This series include patches as below:

Patch 1:
- Add a trace point to informe users when a MMIO RAM section less than minimum size

Patch 2:
- Fix address alignment in region_add/regiondel with vfio iommu smallest page size

Kunkun Jiang (2):
  vfio/common: Add trace point when a MMIO RAM section less than minimum
    size
  vfio/common: Fix address alignment in region_add/region_del

 hw/vfio/common.c | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

-- 
2.23.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] vfio/common: Add trace point when a MMIO RAM section less than minimum size
  2021-08-23 11:56 [PATCH 0/2] vfio/common: Some fixes about region_add/region_del Kunkun Jiang
@ 2021-08-23 11:56 ` Kunkun Jiang
  2021-08-23 11:56 ` [PATCH 2/2] vfio/common: Fix address alignment in region_add/region_del Kunkun Jiang
  1 sibling, 0 replies; 3+ messages in thread
From: Kunkun Jiang @ 2021-08-23 11:56 UTC (permalink / raw)
  To: Alex Williamson, Eric Auger, open list:All patches CC here
  Cc: wanghaibin.wang, Kunkun Jiang

I recently did some tests about the 82599 NIC, and found a strange
scenario. The MSIX-Table size of this NIC is 0x30 and the offset
in Bar 3(64KB) is 0x0. And CPU page size is 64KB. The region_add()
will return early at 'int128_ge((int128_make64(iova), llend))' and
hasn't any message. Let's add a trace point to informed users.

Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com>
---
 hw/vfio/common.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 7d80f43e39..bbb8d1ea0c 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -892,6 +892,13 @@ static void vfio_listener_region_add(MemoryListener *listener,
     llend = int128_and(llend, int128_exts64(qemu_real_host_page_mask));
 
     if (int128_ge(int128_make64(iova), llend)) {
+        if (memory_region_is_ram_device(section->mr)) {
+            trace_vfio_listener_region_add_no_dma_map(
+                memory_region_name(section->mr),
+                section->offset_within_address_space,
+                int128_getlo(section->size),
+                qemu_real_host_page_size);
+        }
         return;
     }
     end = int128_get64(int128_sub(llend, int128_one()));
-- 
2.23.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] vfio/common: Fix address alignment in region_add/region_del
  2021-08-23 11:56 [PATCH 0/2] vfio/common: Some fixes about region_add/region_del Kunkun Jiang
  2021-08-23 11:56 ` [PATCH 1/2] vfio/common: Add trace point when a MMIO RAM section less than minimum size Kunkun Jiang
@ 2021-08-23 11:56 ` Kunkun Jiang
  1 sibling, 0 replies; 3+ messages in thread
From: Kunkun Jiang @ 2021-08-23 11:56 UTC (permalink / raw)
  To: Alex Williamson, Eric Auger, open list:All patches CC here
  Cc: wanghaibin.wang, Kunkun Jiang

The page sizes supported by IOMMU may not match the CPU page size.
For example, the CPU page size is 16KB, but ARM SMMU may not support
16KB. So it is inappropriate to use qemu_real_host_page_mask in
region_add/region_del.

The vfio iommu page sizes exposed via VFIO_IOMMU_GET_INFO. So use
the smallest page size to align the address.

Fixes: 1eb7f642750 (vfio: Support host translation granule size)
Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com>
---
 hw/vfio/common.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index bbb8d1ea0c..62f338cd78 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -859,10 +859,13 @@ static void vfio_unregister_ram_discard_listener(VFIOContainer *container,
     g_free(vrdl);
 }
 
+#define VFIO_IOMMU_MIN_PAGE_ALIGN(addr, pgsize) ROUND_UP((addr), (pgsize))
+
 static void vfio_listener_region_add(MemoryListener *listener,
                                      MemoryRegionSection *section)
 {
     VFIOContainer *container = container_of(listener, VFIOContainer, listener);
+    uint64_t vfio_iommu_min_page_size, vfio_iommu_min_page_mask;
     hwaddr iova, end;
     Int128 llend, llsize;
     void *vaddr;
@@ -879,17 +882,21 @@ static void vfio_listener_region_add(MemoryListener *listener,
         return;
     }
 
+    vfio_iommu_min_page_size = 1 << ctz64(container->pgsizes);
+    vfio_iommu_min_page_mask = ~(vfio_iommu_min_page_size - 1);
+
     if (unlikely((section->offset_within_address_space &
-                  ~qemu_real_host_page_mask) !=
-                 (section->offset_within_region & ~qemu_real_host_page_mask))) {
+                  ~vfio_iommu_min_page_mask) !=
+                 (section->offset_within_region & ~vfio_iommu_min_page_mask))) {
         error_report("%s received unaligned region", __func__);
         return;
     }
 
-    iova = REAL_HOST_PAGE_ALIGN(section->offset_within_address_space);
+    iova = VFIO_IOMMU_MIN_PAGE_ALIGN(section->offset_within_address_space,
+                                     vfio_iommu_min_page_size);
     llend = int128_make64(section->offset_within_address_space);
     llend = int128_add(llend, section->size);
-    llend = int128_and(llend, int128_exts64(qemu_real_host_page_mask));
+    llend = int128_and(llend, int128_exts64(vfio_iommu_min_page_mask));
 
     if (int128_ge(int128_make64(iova), llend)) {
         if (memory_region_is_ram_device(section->mr)) {
@@ -897,7 +904,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
                 memory_region_name(section->mr),
                 section->offset_within_address_space,
                 int128_getlo(section->size),
-                qemu_real_host_page_size);
+                vfio_iommu_min_page_size);
         }
         return;
     }
@@ -1102,6 +1109,7 @@ static void vfio_listener_region_del(MemoryListener *listener,
                                      MemoryRegionSection *section)
 {
     VFIOContainer *container = container_of(listener, VFIOContainer, listener);
+    uint64_t vfio_iommu_min_page_size, vfio_iommu_min_page_mask;
     hwaddr iova, end;
     Int128 llend, llsize;
     int ret;
@@ -1115,9 +1123,12 @@ static void vfio_listener_region_del(MemoryListener *listener,
         return;
     }
 
+    vfio_iommu_min_page_size = 1 << ctz64(container->pgsizes);
+    vfio_iommu_min_page_mask = ~(vfio_iommu_min_page_size - 1);
+
     if (unlikely((section->offset_within_address_space &
-                  ~qemu_real_host_page_mask) !=
-                 (section->offset_within_region & ~qemu_real_host_page_mask))) {
+                  ~vfio_iommu_min_page_mask) !=
+                 (section->offset_within_region & ~vfio_iommu_min_page_mask))) {
         error_report("%s received unaligned region", __func__);
         return;
     }
@@ -1145,10 +1156,11 @@ static void vfio_listener_region_del(MemoryListener *listener,
          */
     }
 
-    iova = REAL_HOST_PAGE_ALIGN(section->offset_within_address_space);
+    iova = VFIO_IOMMU_MIN_PAGE_ALIGN(section->offset_within_address_space,
+                                     vfio_iommu_min_page_size);
     llend = int128_make64(section->offset_within_address_space);
     llend = int128_add(llend, section->size);
-    llend = int128_and(llend, int128_exts64(qemu_real_host_page_mask));
+    llend = int128_and(llend, int128_exts64(vfio_iommu_min_page_mask));
 
     if (int128_ge(int128_make64(iova), llend)) {
         return;
-- 
2.23.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-23 11:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 11:56 [PATCH 0/2] vfio/common: Some fixes about region_add/region_del Kunkun Jiang
2021-08-23 11:56 ` [PATCH 1/2] vfio/common: Add trace point when a MMIO RAM section less than minimum size Kunkun Jiang
2021-08-23 11:56 ` [PATCH 2/2] vfio/common: Fix address alignment in region_add/region_del Kunkun Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).