From patchwork Mon Apr 18 11:47:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 8871731 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3866DBF29F for ; Mon, 18 Apr 2016 11:47:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 37D2E2028D for ; Mon, 18 Apr 2016 11:47:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4D418200EC for ; Mon, 18 Apr 2016 11:47:52 +0000 (UTC) Received: from localhost ([::1]:36011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1as7eh-0003hW-H3 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Apr 2016 07:47:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1as7eY-0003cv-Pl for qemu-devel@nongnu.org; Mon, 18 Apr 2016 07:47:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1as7eX-0001Sl-PX for qemu-devel@nongnu.org; Mon, 18 Apr 2016 07:47:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43184) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1as7eP-0001N0-I2; Mon, 18 Apr 2016 07:47:33 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B428B63156; Mon, 18 Apr 2016 11:47:32 +0000 (UTC) Received: from redhat.com (ovpn-116-32.ams2.redhat.com [10.36.116.32]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u3IBlPLY010591; Mon, 18 Apr 2016 07:47:26 -0400 Date: Mon, 18 Apr 2016 14:47:24 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org, linux-kernel@vger.kernel.org Message-ID: <1460979793-6621-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 18 Apr 2016 11:47:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC] fixup! virtio: convert to use DMA api X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Wei Liu , Andy Lutomirski , qemu-block@nongnu.org, Christian Borntraeger , Jason Wang , peterx@redhat.com, virtualization@lists.linux-foundation.org, Amit Shah , Alex Williamson , Stefan Hajnoczi , kvm@vger.kernel.org, cornelia.huck@de.ibm.com, pbonzini@redhat.com, David Woodhouse Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds a flag to enable/disable bypassing the IOMMU by virtio devices. This is on top of patch http://article.gmane.org/gmane.comp.emulators.qemu/403467 virtio: convert to use DMA api Tested with patchset http://article.gmane.org/gmane.linux.kernel.virtualization/27545 virtio-pci: iommu support Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-access.h | 3 ++- include/hw/virtio/virtio.h | 6 +++++- include/standard-headers/linux/virtio_config.h | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h index 967cc75..bb6f34e 100644 --- a/include/hw/virtio/virtio-access.h +++ b/include/hw/virtio/virtio-access.h @@ -23,7 +23,8 @@ 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 (k->get_dma_as) { + if ((vdev->host_features & (0x1ULL << VIRTIO_F_IOMMU_PLATFORM)) && + k->get_dma_as) { return k->get_dma_as(qbus->parent); } return &address_space_memory; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b12faa9..34d3041 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -228,7 +228,11 @@ typedef struct VirtIORNGConf VirtIORNGConf; DEFINE_PROP_BIT64("notify_on_empty", _state, _field, \ VIRTIO_F_NOTIFY_ON_EMPTY, true), \ DEFINE_PROP_BIT64("any_layout", _state, _field, \ - VIRTIO_F_ANY_LAYOUT, true) + VIRTIO_F_ANY_LAYOUT, true), \ + DEFINE_PROP_BIT64("iommu_passthrough", _state, _field, \ + VIRTIO_F_IOMMU_PASSTHROUGH, false), \ + DEFINE_PROP_BIT64("iommu_platform", _state, _field, \ + VIRTIO_F_IOMMU_PLATFORM, false) hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n); hwaddr virtio_queue_get_avail_addr(VirtIODevice *vdev, int n); diff --git a/include/standard-headers/linux/virtio_config.h b/include/standard-headers/linux/virtio_config.h index bcc445b..5564dab 100644 --- a/include/standard-headers/linux/virtio_config.h +++ b/include/standard-headers/linux/virtio_config.h @@ -61,4 +61,12 @@ /* v1.0 compliant. */ #define VIRTIO_F_VERSION_1 32 +/* Request IOMMU passthrough (if available) + * Without VIRTIO_F_IOMMU_PLATFORM: bypass the IOMMU even if enabled. + * With VIRTIO_F_IOMMU_PLATFORM: suggest disabling IOMMU. + */ +#define VIRTIO_F_IOMMU_PASSTHROUGH 33 + +/* Do not bypass the IOMMU (if configured) */ +#define VIRTIO_F_IOMMU_PLATFORM 34 #endif /* _LINUX_VIRTIO_CONFIG_H */