Message ID | 1456823441-46757-9-git-send-email-aik@ozlabs.ru (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, Mar 01, 2016 at 08:10:33PM +1100, 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. > > The qemu_real_host_page_mask is used as fallback. > > Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> I'm going to have to see how this gets used to really analyze it. But, a preliminary comment: Once this is added, it should be possible to remove the explicit page size parameter from the iommu_replay function (since it could be derived from the IOMMU page sizes). > --- > Changes: > v4: > * s/1<<TARGET_PAGE_BITS/qemu_real_host_page_size/ > --- > hw/ppc/spapr_iommu.c | 8 ++++++++ > include/exec/memory.h | 11 +++++++++++ > memory.c | 9 +++++++++ > 3 files changed, 28 insertions(+) > > diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c > index 67a8356..4c52cf4 100644 > --- a/hw/ppc/spapr_iommu.c > +++ b/hw/ppc/spapr_iommu.c > @@ -143,6 +143,13 @@ static int spapr_tce_vfio_notify(MemoryRegion *iommu, bool attached) > return spapr_tce_vfio_notify_owner(tcet->owner, tcet, attached); > } > > +static uint64_t spapr_tce_get_page_sizes(MemoryRegion *iommu) > +{ > + sPAPRTCETable *tcet = container_of(iommu, sPAPRTCETable, iommu); > + > + return 1ULL << tcet->page_shift; > +} > + > static int spapr_tce_table_post_load(void *opaque, int version_id) > { > sPAPRTCETable *tcet = SPAPR_TCE_TABLE(opaque); > @@ -175,6 +182,7 @@ static const VMStateDescription vmstate_spapr_tce_table = { > static MemoryRegionIOMMUOps spapr_iommu_ops = { > .translate = spapr_tce_translate_iommu, > .vfio_notify = spapr_tce_vfio_notify, > + .get_page_sizes = spapr_tce_get_page_sizes, > }; > > static int spapr_tce_table_realize(DeviceState *dev) > diff --git a/include/exec/memory.h b/include/exec/memory.h > index 9f82629..c34e67c 100644 > --- a/include/exec/memory.h > +++ b/include/exec/memory.h > @@ -152,6 +152,8 @@ struct MemoryRegionIOMMUOps { > IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write); > /* Called when VFIO starts/stops using this */ > int (*vfio_notify)(MemoryRegion *iommu, bool attached); > + /* Returns supported page sizes */ > + uint64_t (*get_page_sizes)(MemoryRegion *iommu); > }; > > typedef struct CoalescedMemoryRange CoalescedMemoryRange; > @@ -576,6 +578,15 @@ static inline bool memory_region_is_iommu(MemoryRegion *mr) > > > /** > + * memory_region_iommu_get_page_sizes: get supported page sizes in an iommu > + * > + * Returns %bitmap of supported page sizes for an iommu. > + * > + * @mr: the memory region being queried > + */ > +uint64_t memory_region_iommu_get_page_sizes(MemoryRegion *mr); > + > +/** > * memory_region_notify_iommu: notify a change in an IOMMU translation entry. > * > * @mr: the memory region that was changed > diff --git a/memory.c b/memory.c > index 0dd9695..5d8453d 100644 > --- a/memory.c > +++ b/memory.c > @@ -1462,6 +1462,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 qemu_real_host_page_size; > +} > + > void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) > { > uint8_t mask = 1 << client;
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index 67a8356..4c52cf4 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -143,6 +143,13 @@ static int spapr_tce_vfio_notify(MemoryRegion *iommu, bool attached) return spapr_tce_vfio_notify_owner(tcet->owner, tcet, attached); } +static uint64_t spapr_tce_get_page_sizes(MemoryRegion *iommu) +{ + sPAPRTCETable *tcet = container_of(iommu, sPAPRTCETable, iommu); + + return 1ULL << tcet->page_shift; +} + static int spapr_tce_table_post_load(void *opaque, int version_id) { sPAPRTCETable *tcet = SPAPR_TCE_TABLE(opaque); @@ -175,6 +182,7 @@ static const VMStateDescription vmstate_spapr_tce_table = { static MemoryRegionIOMMUOps spapr_iommu_ops = { .translate = spapr_tce_translate_iommu, .vfio_notify = spapr_tce_vfio_notify, + .get_page_sizes = spapr_tce_get_page_sizes, }; static int spapr_tce_table_realize(DeviceState *dev) diff --git a/include/exec/memory.h b/include/exec/memory.h index 9f82629..c34e67c 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -152,6 +152,8 @@ struct MemoryRegionIOMMUOps { IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write); /* Called when VFIO starts/stops using this */ int (*vfio_notify)(MemoryRegion *iommu, bool attached); + /* Returns supported page sizes */ + uint64_t (*get_page_sizes)(MemoryRegion *iommu); }; typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -576,6 +578,15 @@ static inline bool memory_region_is_iommu(MemoryRegion *mr) /** + * memory_region_iommu_get_page_sizes: get supported page sizes in an iommu + * + * Returns %bitmap of supported page sizes for an iommu. + * + * @mr: the memory region being queried + */ +uint64_t memory_region_iommu_get_page_sizes(MemoryRegion *mr); + +/** * memory_region_notify_iommu: notify a change in an IOMMU translation entry. * * @mr: the memory region that was changed diff --git a/memory.c b/memory.c index 0dd9695..5d8453d 100644 --- a/memory.c +++ b/memory.c @@ -1462,6 +1462,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 qemu_real_host_page_size; +} + void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) { uint8_t mask = 1 << client;
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. The qemu_real_host_page_mask is used as fallback. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> --- Changes: v4: * s/1<<TARGET_PAGE_BITS/qemu_real_host_page_size/ --- hw/ppc/spapr_iommu.c | 8 ++++++++ include/exec/memory.h | 11 +++++++++++ memory.c | 9 +++++++++ 3 files changed, 28 insertions(+)