On Wed, Sep 23, 2015 at 01:02:32PM +0200, Thomas Huth wrote: > On 18/09/15 01:31, David Gibson wrote: > > On Thu, Sep 17, 2015 at 10:54:24AM -0600, Alex Williamson wrote: > >> On Thu, 2015-09-17 at 23:09 +1000, David Gibson wrote: > >>> At present the memory listener used by vfio to keep host IOMMU mappings > >>> in sync with the guest memory image assumes that if a guest IOMMU > >>> appears, then it has no existing mappings. > >>> > >>> This may not be true if a VFIO device is hotplugged onto a guest bus > >>> which didn't previously include a VFIO device, and which has existing > >>> guest IOMMU mappings. > >>> > >>> Therefore, use the memory_region_register_iommu_notifier_replay() > >>> function in order to fix this case, replaying existing guest IOMMU > >>> mappings, bringing the host IOMMU into sync with the guest IOMMU. > >>> > >>> Signed-off-by: David Gibson <da...@gibson.dropbear.id.au> > >>> --- > >>> hw/vfio/common.c | 34 +++++++++++++++++++--------------- > >>> 1 file changed, 19 insertions(+), 15 deletions(-) > >>> > >>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c > >>> index daaac48..543c38e 100644 > >>> --- a/hw/vfio/common.c > >>> +++ b/hw/vfio/common.c > >>> @@ -312,6 +312,22 @@ out: > >>> rcu_read_unlock(); > >>> } > >>> > >>> +static hwaddr vfio_container_granularity(VFIOContainer *container) > >>> +{ > >>> + uint64_t pgsize; > >>> + > >>> + assert(container->iommu_data.iova_pgsizes); > >> > >> return (hwaddr)1 << (ffsl(container->iommu_data.iova_pgsizes) - 1; > > > > Ah, yes, that should work. I didn't do it that way mostly because I > > tend to confuse myself when I try to remember exactly how ffs > > semantics work. > > Maybe use ffsll instead of ffsl, in case the code ever runs on a 32-bit > host instead of a 64-bit host ?
Already done :) -- 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
pgpf_8b_uU5kO.pgp
Description: PGP signature