Christoph Hellwig
2018-Jun-13 07:41 UTC
[RFC V2] virtio: Add platform specific DMA API translation for virito devices
On Mon, Jun 11, 2018 at 01:29:18PM +1000, Benjamin Herrenschmidt wrote:> At the risk of repeating myself, let's just do the first pass which is > to switch virtio over to always using the DMA API in the actual data > flow code, with a hook at initialization time that replaces the DMA ops > with some home cooked "direct" ops in the case where the IOMMU flag > isn't set. > > This will be equivalent to what we have today but avoids having 2 > separate code path all over the driver. > > Then a second stage, I think, is to replace this "hook" so that the > architecture gets a say in the matter.I don't think we can actually use dma_direct_ops. It still allows architectures to override parts of the dma setup, which virtio seems to blindly assume phys == dma and not cache flushing. I think the right way forward is to either add a new VIRTIO_F_IS_PCI_DEVICE (or redefine the existing iommu flag if deemed possible). And then make sure recent qemu always sets it.
Benjamin Herrenschmidt
2018-Jun-13 12:25 UTC
[RFC V2] virtio: Add platform specific DMA API translation for virito devices
On Wed, 2018-06-13 at 00:41 -0700, Christoph Hellwig wrote:> On Mon, Jun 11, 2018 at 01:29:18PM +1000, Benjamin Herrenschmidt wrote: > > At the risk of repeating myself, let's just do the first pass which is > > to switch virtio over to always using the DMA API in the actual data > > flow code, with a hook at initialization time that replaces the DMA ops > > with some home cooked "direct" ops in the case where the IOMMU flag > > isn't set. > > > > This will be equivalent to what we have today but avoids having 2 > > separate code path all over the driver. > > > > Then a second stage, I think, is to replace this "hook" so that the > > architecture gets a say in the matter. > > I don't think we can actually use dma_direct_ops. It still allows > architectures to override parts of the dma setup, which virtio seems > to blindly assume phys == dma and not cache flushing.By direct ops I didn't mean *the* dma_direct_ops but a virtio-local variants that effectively reproduces the existing expectations (ie, virtio-dma-legacy-ops or something).> I think the right way forward is to either add a new > VIRTIO_F_IS_PCI_DEVICE (or redefine the existing iommu flag if deemed > possible). And then make sure recent qemu always sets it.Ben.
Benjamin Herrenschmidt
2018-Jun-13 13:11 UTC
[RFC V2] virtio: Add platform specific DMA API translation for virito devices
On Wed, 2018-06-13 at 22:25 +1000, Benjamin Herrenschmidt wrote:> On Wed, 2018-06-13 at 00:41 -0700, Christoph Hellwig wrote: > > On Mon, Jun 11, 2018 at 01:29:18PM +1000, Benjamin Herrenschmidt wrote: > > > At the risk of repeating myself, let's just do the first pass which is > > > to switch virtio over to always using the DMA API in the actual data > > > flow code, with a hook at initialization time that replaces the DMA ops > > > with some home cooked "direct" ops in the case where the IOMMU flag > > > isn't set. > > > > > > This will be equivalent to what we have today but avoids having 2 > > > separate code path all over the driver. > > > > > > Then a second stage, I think, is to replace this "hook" so that the > > > architecture gets a say in the matter. > > > > I don't think we can actually use dma_direct_ops. It still allows > > architectures to override parts of the dma setup, which virtio seems > > to blindly assume phys == dma and not cache flushing. > > By direct ops I didn't mean *the* dma_direct_ops but a virtio-local > variants that effectively reproduces the existing expectations (ie, > virtio-dma-legacy-ops or something).Actually ... the stuff in lib/dma-direct.c seems to be just it, no ? There's no cache flushing and there's no architecture hooks that I can see other than the AMD security stuff which is probably fine. Or am I missing something ? Cheers, Ben.> > > I think the right way forward is to either add a new > > VIRTIO_F_IS_PCI_DEVICE (or redefine the existing iommu flag if deemed > > possible). And then make sure recent qemu always sets it. > > Ben.
Michael S. Tsirkin
2018-Jun-13 13:59 UTC
[RFC V2] virtio: Add platform specific DMA API translation for virito devices
On Wed, Jun 13, 2018 at 12:41:41AM -0700, Christoph Hellwig wrote:> On Mon, Jun 11, 2018 at 01:29:18PM +1000, Benjamin Herrenschmidt wrote: > > At the risk of repeating myself, let's just do the first pass which is > > to switch virtio over to always using the DMA API in the actual data > > flow code, with a hook at initialization time that replaces the DMA ops > > with some home cooked "direct" ops in the case where the IOMMU flag > > isn't set. > > > > This will be equivalent to what we have today but avoids having 2 > > separate code path all over the driver. > > > > Then a second stage, I think, is to replace this "hook" so that the > > architecture gets a say in the matter. > > I don't think we can actually use dma_direct_ops. It still allows > architectures to override parts of the dma setup, which virtio seems > to blindly assume phys == dma and not cache flushing. > > I think the right way forward is to either add a new > VIRTIO_F_IS_PCI_DEVICE (or redefine the existing iommu flag if deemed > possible).Given this is exactly what happens now, this seems possible, but maybe we want a non-PCI specific name.> And then make sure recent qemu always sets it.I don't think that part is going to happen, sorry. Hypervisors can set it when they *actually have* a real PCI device. People emulate systems which have a bunch of overhead in the DMA API which is required for real DMA. Your proposal would double that overhead by first doing it in guest then re-doing it in host. I don't think it's justified when 99% of the world doesn't need it. -- MST
Apparently Analagous Threads
- [RFC V2] virtio: Add platform specific DMA API translation for virito devices
- [RFC V2] virtio: Add platform specific DMA API translation for virito devices
- [RFC V2] virtio: Add platform specific DMA API translation for virito devices
- [RFC V2] virtio: Add platform specific DMA API translation for virito devices
- [RFC V2] virtio: Add platform specific DMA API translation for virito devices