Received: from eggs.gnu.org ([2001:4830:134:3::10]:37250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bedWQ-0003KS-5z for qemu-devel@nongnu.org; Tue, 30 Aug 2016 03:31:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bedWH-0003Pw-PG for qemu-devel@nongnu.org; Tue, 30 Aug 2016 03:31:50 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58937) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bedWH-0003Pg-Fu for qemu-devel@nongnu.org; Tue, 30 Aug 2016 03:31:41 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u7U7TXTu120148 for ; Tue, 30 Aug 2016 03:31:39 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 255362dhb1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 30 Aug 2016 03:31:39 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 30 Aug 2016 08:31:35 +0100 Date: Tue, 30 Aug 2016 09:31:27 +0200 From: Cornelia Huck In-Reply-To: <1472526419-5900-3-git-send-email-jasowang@redhat.com> References: <1472526419-5900-1-git-send-email-jasowang@redhat.com> <1472526419-5900-3-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-Id: <20160830093127.49463d9d.cornelia.huck@de.ibm.com> Subject: Re: [Qemu-devel] [PATCH for 2.8 02/11] virtio: convert to use DMA api List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Wang Cc: mst@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com, peterx@redhat.com, wexu@redhat.com, vkaplans@redhat.com, Stefan Hajnoczi , Kevin Wolf , Amit Shah , qemu-block@nongnu.org On Tue, 30 Aug 2016 11:06:50 +0800 Jason Wang wrote: > Currently, all virtio devices bypass IOMMU completely. This is because > address_space_memory is assumed and used during DMA emulation. This > patch converts the virtio core API to use DMA API. This idea is > > - introducing a new transport specific helper to query the dma address > space. (only pci version is implemented). > - query and use this address space during virtio device guest memory > accessing when iommu platform (VIRTIO_F_IOMMU_PLATFORM) was enabled > for this device. > > Cc: Michael S. Tsirkin > Cc: Stefan Hajnoczi > Cc: Kevin Wolf > Cc: Amit Shah > Cc: Paolo Bonzini > Cc: qemu-block@nongnu.org > Signed-off-by: Jason Wang > --- > hw/block/virtio-blk.c | 2 +- > hw/char/virtio-serial-bus.c | 3 +- > hw/scsi/virtio-scsi.c | 4 ++- > hw/virtio/virtio-pci.c | 14 +++++++++ > hw/virtio/virtio.c | 62 ++++++++++++++++++++++++--------------- > include/hw/virtio/virtio-access.h | 43 ++++++++++++++++++++------- > include/hw/virtio/virtio-bus.h | 1 + > include/hw/virtio/virtio.h | 8 +++-- > 8 files changed, 98 insertions(+), 39 deletions(-) > > diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h > index 440b455..4071dad 100644 > --- a/include/hw/virtio/virtio-access.h > +++ b/include/hw/virtio/virtio-access.h > @@ -17,12 +17,25 @@ > #define QEMU_VIRTIO_ACCESS_H > > #include "hw/virtio/virtio.h" > +#include "hw/virtio/virtio-bus.h" > #include "exec/address-spaces.h" > > #if defined(TARGET_PPC64) || defined(TARGET_ARM) > #define LEGACY_VIRTIO_IS_BIENDIAN 1 > #endif > > +static inline AddressSpace *virtio_get_dma_as(VirtIODevice *vdev) > +{ > + BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); > + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); > + > + if (virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM) && > + k->get_dma_as) { > + return k->get_dma_as(qbus->parent); > + } > + return &address_space_memory; > +} One thing I'm a bit worried about is that we're introducing a check even if we know that the device will never support VIRTIO_F_IOMMU_PLATFORM (i.e. virtio-ccw). The qom incantations will add cycles to any invocation of this. Is the address space likely to change during device lifetime? Can we cache it in some way?