On Mon, Apr 04, 2016 at 07:33:39PM +1000, Alexey Kardashevskiy wrote: > Every IOMMU has some granularity which MemoryRegionIOMMUOps::translate > uses when translating, however this information is not available outside > the translate context for various checks. > > This adds a get_page_sizes callback to MemoryRegionIOMMUOps and > a wrapper for it so IOMMU users (such as VFIO) can know the actual > page size(s) used by an IOMMU. > > As IOMMU MR represents a guest IOMMU, this uses TARGET_PAGE_SIZE > as fallback. > > This removes vfio_container_granularity() and uses new callback in > memory_region_iommu_replay() when replaying IOMMU mappings on added > IOMMU memory region. > > Signed-off-by: Alexey Kardashevskiy <a...@ozlabs.ru>
Reviewed-by: David Gibson <da...@gibson.dropbear.id.au> .. with the exception of one nit: [snip] > diff --git a/memory.c b/memory.c > index 95f7209..c37dbc9 100644 > --- a/memory.c > +++ b/memory.c > @@ -1512,12 +1512,14 @@ void > memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n) > notifier_list_add(&mr->iommu_notify, n); > } > > -void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, > - hwaddr granularity, bool is_write) > +void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, bool is_write) > { > - hwaddr addr; > + hwaddr addr, granularity; > IOMMUTLBEntry iotlb; > > + g_assert(mr->iommu_ops && mr->iommu_ops->get_page_sizes); > + granularity = (hwaddr)1 << ctz64(mr->iommu_ops->get_page_sizes(mr)); So here, replay requires that the get_page_sizes() callback be populated. However, if you move memory_region_iommu_get_page_sizes() just above this, you can use that and have the replay fall back to TARGET_PAGE_SIZE as well. > for (addr = 0; addr < memory_region_size(mr); addr += granularity) { > iotlb = mr->iommu_ops->translate(mr, addr, is_write); > if (iotlb.perm != IOMMU_NONE) { > @@ -1544,6 +1546,15 @@ void memory_region_notify_iommu(MemoryRegion *mr, > notifier_list_notify(&mr->iommu_notify, &entry); > } > > +uint64_t memory_region_iommu_get_page_sizes(MemoryRegion *mr) > +{ > + assert(memory_region_is_iommu(mr)); > + if (mr->iommu_ops && mr->iommu_ops->get_page_sizes) { > + return mr->iommu_ops->get_page_sizes(mr); > + } > + return TARGET_PAGE_SIZE; > +} > + > void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) > { > uint8_t mask = 1 << client; -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
signature.asc
Description: PGP signature