qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] memory: Optimize replay of guest mapping
@ 2023-02-15  6:52 Zhenzhong Duan
  2023-02-15 14:46 ` Peter Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Zhenzhong Duan @ 2023-02-15  6:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, peterx, jasowang, pbonzini, richard.henderson, eduardo,
	marcel.apfelbaum, david, philmd

On x86, there are two notifiers registered due to vtd-ir memory region
splitting the whole address space. During replay of the address space
for each notifier, the whole address space is scanned which is
unnecessory.

We only need to scan the space belong to notifier montiored space.

Assert when notifier is used to monitor beyond iommu memory region's
address space.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
v2: Add an assertion per Peter Xu
Tested only on x86 with a net card passed to guest(kvm/tcg), ping/ssh pass.

 hw/i386/intel_iommu.c | 2 +-
 softmmu/memory.c      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 98a5c304a7d7..6b1de80e8573 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3831,7 +3831,7 @@ static void vtd_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
                 .domain_id = vtd_get_domain_id(s, &ce, vtd_as->pasid),
             };
 
-            vtd_page_walk(s, &ce, 0, ~0ULL, &info, vtd_as->pasid);
+            vtd_page_walk(s, &ce, n->start, n->end, &info, vtd_as->pasid);
         }
     } else {
         trace_vtd_replay_ce_invalid(bus_n, PCI_SLOT(vtd_as->devfn),
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 9d64efca269b..da7d84661972 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1900,6 +1900,7 @@ int memory_region_register_iommu_notifier(MemoryRegion *mr,
     iommu_mr = IOMMU_MEMORY_REGION(mr);
     assert(n->notifier_flags != IOMMU_NOTIFIER_NONE);
     assert(n->start <= n->end);
+    assert(n->end <= memory_region_size(mr));
     assert(n->iommu_idx >= 0 &&
            n->iommu_idx < memory_region_iommu_num_indexes(iommu_mr));
 
@@ -1923,7 +1924,6 @@ uint64_t memory_region_iommu_get_min_page_size(IOMMUMemoryRegion *iommu_mr)
 
 void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
 {
-    MemoryRegion *mr = MEMORY_REGION(iommu_mr);
     IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_GET_CLASS(iommu_mr);
     hwaddr addr, granularity;
     IOMMUTLBEntry iotlb;
@@ -1936,7 +1936,7 @@ void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
 
     granularity = memory_region_iommu_get_min_page_size(iommu_mr);
 
-    for (addr = 0; addr < memory_region_size(mr); addr += granularity) {
+    for (addr = n->start; addr < n->end; addr += granularity) {
         iotlb = imrc->translate(iommu_mr, addr, IOMMU_NONE, n->iommu_idx);
         if (iotlb.perm != IOMMU_NONE) {
             n->notify(n, &iotlb);
-- 
2.25.1



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

* Re: [PATCH v2] memory: Optimize replay of guest mapping
  2023-02-15  6:52 [PATCH v2] memory: Optimize replay of guest mapping Zhenzhong Duan
@ 2023-02-15 14:46 ` Peter Xu
  2023-02-16  4:21   ` Jason Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Xu @ 2023-02-15 14:46 UTC (permalink / raw)
  To: Zhenzhong Duan
  Cc: qemu-devel, mst, jasowang, pbonzini, richard.henderson, eduardo,
	marcel.apfelbaum, david, philmd

On Wed, Feb 15, 2023 at 02:52:38PM +0800, Zhenzhong Duan wrote:
> On x86, there are two notifiers registered due to vtd-ir memory region
> splitting the whole address space. During replay of the address space
> for each notifier, the whole address space is scanned which is
> unnecessory.
> 
> We only need to scan the space belong to notifier montiored space.
> 
> Assert when notifier is used to monitor beyond iommu memory region's
> address space.
> 
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>

Acked-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu



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

* Re: [PATCH v2] memory: Optimize replay of guest mapping
  2023-02-15 14:46 ` Peter Xu
@ 2023-02-16  4:21   ` Jason Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Wang @ 2023-02-16  4:21 UTC (permalink / raw)
  To: Peter Xu
  Cc: Zhenzhong Duan, qemu-devel, mst, pbonzini, richard.henderson,
	eduardo, marcel.apfelbaum, david, philmd

On Wed, Feb 15, 2023 at 10:46 PM Peter Xu <peterx@redhat.com> wrote:
>
> On Wed, Feb 15, 2023 at 02:52:38PM +0800, Zhenzhong Duan wrote:
> > On x86, there are two notifiers registered due to vtd-ir memory region
> > splitting the whole address space. During replay of the address space
> > for each notifier, the whole address space is scanned which is
> > unnecessory.
> >
> > We only need to scan the space belong to notifier montiored space.
> >
> > Assert when notifier is used to monitor beyond iommu memory region's
> > address space.
> >
> > Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>
> Acked-by: Peter Xu <peterx@redhat.com>

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

>
> --
> Peter Xu
>



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

end of thread, other threads:[~2023-02-16  4:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-15  6:52 [PATCH v2] memory: Optimize replay of guest mapping Zhenzhong Duan
2023-02-15 14:46 ` Peter Xu
2023-02-16  4:21   ` Jason Wang

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).