From patchwork Tue Oct 31 05:06:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Yi L" X-Patchwork-Id: 832241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yR0C32Gbvz9t2V for ; Tue, 31 Oct 2017 16:24:15 +1100 (AEDT) Received: from localhost ([::1]:43755 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P25-00012p-BO for incoming@patchwork.ozlabs.org; Tue, 31 Oct 2017 01:24:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P1Q-00012U-DU for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9P1L-0004dq-KO for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:32 -0400 Received: from mga07.intel.com ([134.134.136.100]:53480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e9P1L-0004cw-9v for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:27 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 30 Oct 2017 22:23:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,322,1505804400"; d="scan'208";a="169289717" Received: from sky-dev.bj.intel.com ([10.238.144.127]) by fmsmga005.fm.intel.com with ESMTP; 30 Oct 2017 22:23:23 -0700 From: "Liu, Yi L" To: qemu-devel@nongnu.org, mst@redhat.com, david@gibson.dropbear.id.au, pbonzini@redhat.com, alex.williamson@redhat.com Date: Tue, 31 Oct 2017 13:06:59 +0800 Message-Id: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.100 Subject: [Qemu-devel] [PATCH 0/6] Introduce new iommu notifier framework 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: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, jasowang@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patchset is a follow-up of Peter Xu's patchset as the link below. In brief, Peter's patchset is to introduce a common IOMMU object which is not depending on platform (x86/ppc/...), or bus (PCI/...). And based on it, a iommu object based notifier framework is introduced and also AddressSpaceOps is added to provide methods like getting IOMMUObject behind an AddressSpace. It could be used to detect the exposure of vIOMMU. https://lists.gnu.org/archive/html/qemu-devel/2017-04/msg05360.html Here let me try to address why we need such change. I'm working on virt-SVM enabling for passthru devices on Intel platform. This work is to extend the existing intel iommu emulator in Qemu. Among the extensions, there are two requirements which ae related to the topic we are talking here. * intel iommu emulator needs to propagate a guest pasid table pointer to host through VFIO. So that host intel iommu driver could set it to its ctx table. With guest pasid table pointer set, host would be able to get guest CR3 table after guest calls intel_svm_bind_mm(). Then HW iommu could do nested translation to get GVA->GPA GPA->HPA. Thus enables Shared Virtual Memory in guest. * intel iommu emulator needs to propagate guest's iotlb(1st level cache) flush to host through VFIO. Since the two requirements need to talk with VFIO, so notifiers are needed. Meanwhile, the notifiers should be registered as long as there is vIOMMU exposed to guest. Qemu has an existing notifier framework based on MemoryRegion. And we are using it for MAP/UNMAP. However, we cannot use it here. Reason is as below: * IOMMU MemoryRegion notifiers depends on IOMMU MemoryRegion. If guest iommu driver configs to bypass the IOVA adress translation. The address space would be system ram address space. The MemoryRegion would be the RAM MemoryRegion. Details can be got in Peter's patch to allow dynamic switch of IOMMU region. https://lists.gnu.org/archive/html/qemu-devel/2016-12/msg02690.html * virt-SVM requires guest to config to bypass the IOVA address translation With such config, we can make sure host would have a GPA->HPA mapping, and meanwhile intel iommu emulator could propagate the guest CR3 table (GVA->GPA) to host. With nested translation, we are able to achieve GVA->GPA and then GPA->HPA translation. However, if so, the IOMMU MemoryRegion notifiers would not be registered. It means for virt-SVM, we need another notifier framework. Based on Peter's patch, I did some clean up and fulfill the notifier framework based on IOMMUObject and also provide an example of the newly introduced notifier framework. The notifier framework introduced here is going to be used in my virt-SVM patchset. For virt-SVM design details, you may refer to svm RFC patch. https://lists.gnu.org/archive/html/qemu-devel/2017-04/msg04925.html Liu, Yi L (3): vfio: rename GuestIOMMU to be GuestIOMMUMR vfio/pci: add notify framework based on IOMMUObject vfio/pci: register vfio_iommu_bind_pasidtbl_notify notifier Peter Xu (3): memory: rename existing iommu notifier to be iommu mr notifier memory: introduce AddressSpaceOps and IOMMUObject intel_iommu: provide AddressSpaceOps.iommu_get instance hw/core/Makefile.objs | 1 + hw/core/iommu.c | 58 ++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.c | 6 ++-- hw/i386/intel_iommu.c | 41 +++++++++++++---------- hw/ppc/spapr_iommu.c | 8 ++--- hw/s390x/s390-pci-bus.c | 2 +- hw/vfio/common.c | 25 +++++++------- hw/vfio/pci.c | 53 ++++++++++++++++++++++++++++- hw/virtio/vhost.c | 10 +++--- include/exec/memory.h | 77 ++++++++++++++++++++++++++++--------------- include/hw/core/iommu.h | 73 ++++++++++++++++++++++++++++++++++++++++ include/hw/i386/intel_iommu.h | 10 +++--- include/hw/vfio/vfio-common.h | 16 ++++++--- include/hw/virtio/vhost.h | 4 +-- memory.c | 45 +++++++++++++++---------- 15 files changed, 331 insertions(+), 98 deletions(-) create mode 100644 hw/core/iommu.c create mode 100644 include/hw/core/iommu.h