Robin Murphy
2022-Jul-14 12:01 UTC
[PATCH] iommu/virtio: Advertise IOMMU_CAP_CACHE_COHERENCY
On 2022-07-14 12:11, Jean-Philippe Brucker wrote:> Fix virtio-iommu interaction with VFIO, as VFIO now requires > IOMMU_CAP_CACHE_COHERENCY. virtio-iommu does not support non-cacheable > mappings, and always expects to be called with IOMMU_CACHE.Can we know this is actually true though? What if the virtio-iommu implementation is backed by something other than VFIO, and the underlying hardware isn't coherent? AFAICS the spec doesn't disallow that. Thanks, Robin.> Fixes: e8ae0e140c05 ("vfio: Require that devices support DMA cache coherence") > Signed-off-by: Jean-Philippe Brucker <jean-philippe at linaro.org> > --- > drivers/iommu/virtio-iommu.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c > index 25be4b822aa0..bf340d779c10 100644 > --- a/drivers/iommu/virtio-iommu.c > +++ b/drivers/iommu/virtio-iommu.c > @@ -1006,7 +1006,18 @@ static int viommu_of_xlate(struct device *dev, struct of_phandle_args *args) > return iommu_fwspec_add_ids(dev, args->args, 1); > } > > +static bool viommu_capable(enum iommu_cap cap) > +{ > + switch (cap) { > + case IOMMU_CAP_CACHE_COHERENCY: > + return true; > + default: > + return false; > + } > +} > + > static struct iommu_ops viommu_ops = { > + .capable = viommu_capable, > .domain_alloc = viommu_domain_alloc, > .probe_device = viommu_probe_device, > .probe_finalize = viommu_probe_finalize,
Jean-Philippe Brucker
2022-Jul-14 13:00 UTC
[PATCH] iommu/virtio: Advertise IOMMU_CAP_CACHE_COHERENCY
On Thu, Jul 14, 2022 at 01:01:37PM +0100, Robin Murphy wrote:> On 2022-07-14 12:11, Jean-Philippe Brucker wrote: > > Fix virtio-iommu interaction with VFIO, as VFIO now requires > > IOMMU_CAP_CACHE_COHERENCY. virtio-iommu does not support non-cacheable > > mappings, and always expects to be called with IOMMU_CACHE. > > Can we know this is actually true though? What if the virtio-iommu > implementation is backed by something other than VFIO, and the underlying > hardware isn't coherent? AFAICS the spec doesn't disallow that.Right, I should add a note about that. If someone does actually want to support non-coherent device, I assume we'll add a per-device property, a 'non-cacheable' mapping flag, and IOMMU_CAP_CACHE_COHERENCY will hold. I'm also planning to add a check on (IOMMU_CACHE && !IOMMU_NOEXEC) in viommu_map(), but not as a fix. In the meantime we do need to restore VFIO support under virtio-iommu, since userspace still expects that to work, and the existing use-cases are coherent devices. Thanks, Jean> > Thanks, > Robin. > > > Fixes: e8ae0e140c05 ("vfio: Require that devices support DMA cache coherence") > > Signed-off-by: Jean-Philippe Brucker <jean-philippe at linaro.org> > > --- > > drivers/iommu/virtio-iommu.c | 11 +++++++++++ > > 1 file changed, 11 insertions(+) > > > > diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c > > index 25be4b822aa0..bf340d779c10 100644 > > --- a/drivers/iommu/virtio-iommu.c > > +++ b/drivers/iommu/virtio-iommu.c > > @@ -1006,7 +1006,18 @@ static int viommu_of_xlate(struct device *dev, struct of_phandle_args *args) > > return iommu_fwspec_add_ids(dev, args->args, 1); > > } > > +static bool viommu_capable(enum iommu_cap cap) > > +{ > > + switch (cap) { > > + case IOMMU_CAP_CACHE_COHERENCY: > > + return true; > > + default: > > + return false; > > + } > > +} > > + > > static struct iommu_ops viommu_ops = { > > + .capable = viommu_capable, > > .domain_alloc = viommu_domain_alloc, > > .probe_device = viommu_probe_device, > > .probe_finalize = viommu_probe_finalize,