Re: [PATCH v7 5/9] virtio_ring: Support DMA APIs

From: Andy Lutomirski
Date: Wed Feb 03 2016 - 12:54:07 EST


On Feb 3, 2016 5:52 AM, "Michael S. Tsirkin" <mst@xxxxxxxxxx> wrote:
>
> On Tue, Feb 02, 2016 at 09:46:36PM -0800, Andy Lutomirski wrote:
> > virtio_ring currently sends the device (usually a hypervisor)
> > physical addresses of its I/O buffers. This is okay when DMA
> > addresses and physical addresses are the same thing, but this isn't
> > always the case. For example, this never works on Xen guests, and
> > it is likely to fail if a physical "virtio" device ever ends up
> > behind an IOMMU or swiotlb.
> >
> > The immediate use case for me is to enable virtio on Xen guests.
> > For that to work, we need vring to support DMA address translation
> > as well as a corresponding change to virtio_pci or to another
> > driver.
> >
> > Signed-off-by: Andy Lutomirski <luto@xxxxxxxxxx>
> > ---
> > drivers/virtio/Kconfig | 2 +-
> > drivers/virtio/virtio_ring.c | 200 ++++++++++++++++++++++++++++++++-------
> > tools/virtio/linux/dma-mapping.h | 17 ++++
> > 3 files changed, 183 insertions(+), 36 deletions(-)
> > create mode 100644 tools/virtio/linux/dma-mapping.h
> >
> > diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
> > index cab9f3f63a38..77590320d44c 100644
> > --- a/drivers/virtio/Kconfig
> > +++ b/drivers/virtio/Kconfig
> > @@ -60,7 +60,7 @@ config VIRTIO_INPUT
> >
> > config VIRTIO_MMIO
> > tristate "Platform bus driver for memory mapped virtio devices"
> > - depends on HAS_IOMEM
> > + depends on HAS_IOMEM && HAS_DMA
> > select VIRTIO
> > ---help---
> > This drivers provides support for memory mapped virtio
>
> What's this chunk doing here btw? Should be part of the mmio patch?
>

IIRC it was deliberate. Making virtio depend on HAS_DMA didn't work
right because kconfig doesn't propagate dependencies through select
intelligently. This patch makes core virtio depend on HAS_DMA, so I
added the dependency here, too.

--Andy