diff mbox series

[1/1] Remove flatview_simplify()

Message ID 20210329121408.17862-2-FelixCui-oc@zhaoxin.com
State New
Headers show
Series Remove flatview_simplify() | expand

Commit Message

FelixCui-oc March 29, 2021, 12:14 p.m. UTC
Flatview_simplify() can merge many small memory ranges
into a large one and contains EHCI dma buffers.
For example,the merged range maybe0xc0000-0xbfffffff.
When seabios write PAM register to change the properties
of part of the merged range from RW to readonly,
this action cause the merged IOVA mapping will be
unmapped.But EHCI device still send DMA cycles
and then IOMMU blocks the DMA cycles of EHCI device.

Because the merged range is too large,there will be
problems even if EHCI device is configured to not
allocate buffers in low memory.
So this patch wants to remove flatview_simplify() completely.

Signed-off-by: FelixCuioc <FelixCui-oc@zhaoxin.com>
---
 softmmu/memory.c | 37 -------------------------------------
 1 file changed, 37 deletions(-)

Comments

Richard Henderson March 30, 2021, 4:33 p.m. UTC | #1
On 3/29/21 6:14 AM, FelixCuioc wrote:
> Flatview_simplify() can merge many small memory ranges
> into a large one and contains EHCI dma buffers.
> For example,the merged range maybe0xc0000-0xbfffffff.
> When seabios write PAM register to change the properties
> of part of the merged range from RW to readonly,
> this action cause the merged IOVA mapping will be
> unmapped.But EHCI device still send DMA cycles
> and then IOMMU blocks the DMA cycles of EHCI device.

You've described the problem, and it is quite obviously *not* in memory.c.


r~
Paolo Bonzini March 30, 2021, 4:35 p.m. UTC | #2
On 30/03/21 18:33, Richard Henderson wrote:
> 
>> Flatview_simplify() can merge many small memory ranges
>> into a large one and contains EHCI dma buffers.
>> For example,the merged range maybe0xc0000-0xbfffffff.
>> When seabios write PAM register to change the properties
>> of part of the merged range from RW to readonly,
>> this action cause the merged IOVA mapping will be
>> unmapped.But EHCI device still send DMA cycles
>> and then IOMMU blocks the DMA cycles of EHCI device.
> 
> You've described the problem, and it is quite obviously *not* in memory.c.

Well, sort of.

The problem is that neither VFIO nor KVM support atomically switching 
the memory map.  For KVM that would be possible, for VFIO based on past 
discussion it would be much harder.  Removing flatview_simplify() seems 
to be the easiest way to bypass the issue.

That said, perhaps it's better to keep the simplification within a 
page-sized range, to avoid introducing subpages unnecessarily.

Paolo
FelixCui-oc April 1, 2021, 8:04 a.m. UTC | #3
>That said, perhaps it's better to keep the simplification within a
>page-sized range, to avoid introducing subpages unnecessarily.


hi  paolo,

               The sizes of all flatranges merged by flatview_simplify() are page aligned.

                Flatview_simplify() seems to have the opportunity to do some merging actions only when

                starting the virtual machine.

                We can temporarily remove flatview_simplify().


Thanks

Felixcui
diff mbox series

Patch

diff --git a/softmmu/memory.c b/softmmu/memory.c
index d4493ef9e4..aaace8c03f 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -314,42 +314,6 @@  void flatview_unref(FlatView *view)
     }
 }
 
-static bool can_merge(FlatRange *r1, FlatRange *r2)
-{
-    return int128_eq(addrrange_end(r1->addr), r2->addr.start)
-        && r1->mr == r2->mr
-        && int128_eq(int128_add(int128_make64(r1->offset_in_region),
-                                r1->addr.size),
-                     int128_make64(r2->offset_in_region))
-        && r1->dirty_log_mask == r2->dirty_log_mask
-        && r1->romd_mode == r2->romd_mode
-        && r1->readonly == r2->readonly
-        && r1->nonvolatile == r2->nonvolatile;
-}
-
-/* Attempt to simplify a view by merging adjacent ranges */
-static void flatview_simplify(FlatView *view)
-{
-    unsigned i, j, k;
-
-    i = 0;
-    while (i < view->nr) {
-        j = i + 1;
-        while (j < view->nr
-               && can_merge(&view->ranges[j-1], &view->ranges[j])) {
-            int128_addto(&view->ranges[i].addr.size, view->ranges[j].addr.size);
-            ++j;
-        }
-        ++i;
-        for (k = i; k < j; k++) {
-            memory_region_unref(view->ranges[k].mr);
-        }
-        memmove(&view->ranges[i], &view->ranges[j],
-                (view->nr - j) * sizeof(view->ranges[j]));
-        view->nr -= j - i;
-    }
-}
-
 static bool memory_region_big_endian(MemoryRegion *mr)
 {
 #ifdef TARGET_WORDS_BIGENDIAN
@@ -735,7 +699,6 @@  static FlatView *generate_memory_topology(MemoryRegion *mr)
                              addrrange_make(int128_zero(), int128_2_64()),
                              false, false);
     }
-    flatview_simplify(view);
 
     view->dispatch = address_space_dispatch_new(view);
     for (i = 0; i < view->nr; i++) {