[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 36/53] memory: Optimize replay of guest mapping
From: |
Michael S. Tsirkin |
Subject: |
[PULL 36/53] memory: Optimize replay of guest mapping |
Date: |
Thu, 2 Mar 2023 03:26:19 -0500 |
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
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>
Message-Id: <20230215065238.713041-1-zhenzhong.duan@intel.com>
Acked-by: Peter Xu <peterx@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
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 98a5c304a7..6b1de80e85 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 9d64efca26..da7d846619 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);
--
MST
- [PULL 39/53] memory: introduce memory_region_unmap_iommu_notifier_range(), (continued)
- [PULL 39/53] memory: introduce memory_region_unmap_iommu_notifier_range(), Michael S. Tsirkin, 2023/03/02
- [PULL 37/53] intel-iommu: fail MAP notifier without caching mode, Michael S. Tsirkin, 2023/03/02
- [PULL 42/53] MAINTAINERS: Add Fan Ni as Compute eXpress Link QEMU reviewer, Michael S. Tsirkin, 2023/03/02
- [PULL 43/53] hw/mem/cxl_type3: Improve error handling in realize(), Michael S. Tsirkin, 2023/03/02
- [PULL 48/53] hw/i386/acpi: Drop duplicate _UID entry for CXL root bridge, Michael S. Tsirkin, 2023/03/02
- [PULL 50/53] qemu/bswap: Add const_le64(), Michael S. Tsirkin, 2023/03/02
- [PULL 40/53] smmu: switch to use memory_region_unmap_iommu_notifier_range(), Michael S. Tsirkin, 2023/03/02
- [PULL 41/53] intel-iommu: send UNMAP notifications for domain or global inv desc, Michael S. Tsirkin, 2023/03/02
- [PULL 46/53] hw/cxl: Add CXL_CAPACITY_MULTIPLIER definition, Michael S. Tsirkin, 2023/03/02
- [PULL 44/53] hw/pci-bridge/cxl_downstream: Fix type naming mismatch, Michael S. Tsirkin, 2023/03/02
- [PULL 36/53] memory: Optimize replay of guest mapping,
Michael S. Tsirkin <=
- [PULL 45/53] hw/cxl: set cxl-type3 device type to PCI_CLASS_MEMORY_CXL, Michael S. Tsirkin, 2023/03/02
- [PULL 47/53] tests/acpi: Allow update of q35/DSDT.cxl, Michael S. Tsirkin, 2023/03/02
- [PULL 49/53] tests: acpi: Update q35/DSDT.cxl for removed duplicate UID, Michael S. Tsirkin, 2023/03/02
- [PULL 51/53] qemu/uuid: Add UUID static initializer, Michael S. Tsirkin, 2023/03/02
- [PULL 52/53] hw/cxl/mailbox: Use new UUID network order define for cel_uuid, Michael S. Tsirkin, 2023/03/02
- [PULL 53/53] tests/data/acpi/virt: drop (most) duplicate files., Michael S. Tsirkin, 2023/03/02
- Re: [PULL 00/53] virtio,pc,pci: features, cleanups, fixes, Michael Tokarev, 2023/03/02
- Re: [PULL 00/53] virtio,pc,pci: features, cleanups, fixes, Michael S. Tsirkin, 2023/03/02