From patchwork Mon Sep 5 07:21:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 9313149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A027607D3 for ; Mon, 5 Sep 2016 07:22:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50BA728911 for ; Mon, 5 Sep 2016 07:22:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4526C289B7; Mon, 5 Sep 2016 07:22:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id B6C0A28911 for ; Mon, 5 Sep 2016 07:22:37 +0000 (UTC) Received: from localhost ([::1]:52698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgoEm-0007mL-Vc for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Sep 2016 03:22:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgoDv-0007Sk-2r for qemu-devel@nongnu.org; Mon, 05 Sep 2016 03:21:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bgoDn-000708-SS for qemu-devel@nongnu.org; Mon, 05 Sep 2016 03:21:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47824) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgoDn-000703-K8 for qemu-devel@nongnu.org; Mon, 05 Sep 2016 03:21:35 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 46644C0467CF; Mon, 5 Sep 2016 07:21:35 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-105.nay.redhat.com [10.66.14.105]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u857LS7M002036; Mon, 5 Sep 2016 03:21:32 -0400 From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Sep 2016 15:21:19 +0800 Message-Id: <1473060081-17835-2-git-send-email-peterx@redhat.com> In-Reply-To: <1473060081-17835-1-git-send-email-peterx@redhat.com> References: <1473060081-17835-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 05 Sep 2016 07:21:35 +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 1/3] memory: add one flag for IOMMU notifier 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: mst@redhat.com, jasowang@redhat.com, peterx@redhat.com, vkaplans@redhat.com, alex.williamson@redhat.com, wexu@redhat.com, pbonzini@redhat.com, cornelia.huck@de.ibm.com, dgibson@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP With the new flag, now we allow to register two kinds of IOMMU notifiers: - IOMMU_RW: All DMA mapping changes will be notified. - IOMMU_NONE: will only be notified when there are cache invalidations. Here IOMMU_RW is the original scemantics for existing IOMMU notifiers. VFIO is the only register for IOMMU notifier, and it's with type IOMMU_RW. Suggested-by: Alex Williamson Signed-off-by: Peter Xu --- hw/i386/intel_iommu.c | 3 ++- hw/ppc/spapr_iommu.c | 3 ++- hw/vfio/common.c | 3 ++- include/exec/memory.h | 8 ++++++-- memory.c | 6 ++++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 28c31a2..e0d4f23 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1974,7 +1974,8 @@ static IOMMUTLBEntry vtd_iommu_translate(MemoryRegion *iommu, hwaddr addr, return ret; } -static void vtd_iommu_notify_started(MemoryRegion *iommu) +static void vtd_iommu_notify_started(MemoryRegion *iommu, + IOMMUAccessFlags flag) { VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu); diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index 6bc4d4d..09660fc 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -156,7 +156,8 @@ static uint64_t spapr_tce_get_min_page_size(MemoryRegion *iommu) return 1ULL << tcet->page_shift; } -static void spapr_tce_notify_started(MemoryRegion *iommu) +static void spapr_tce_notify_started(MemoryRegion *iommu, + IOMMUAccessFlags flag) { spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), true); } diff --git a/hw/vfio/common.c b/hw/vfio/common.c index b313e7c..b2d1fad 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -456,7 +456,8 @@ static void vfio_listener_region_add(MemoryListener *listener, giommu->n.notify = vfio_iommu_map_notify; QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next); - memory_region_register_iommu_notifier(giommu->iommu, &giommu->n); + memory_region_register_iommu_notifier(giommu->iommu, &giommu->n, + IOMMU_RW); memory_region_iommu_replay(giommu->iommu, &giommu->n, false); return; diff --git a/include/exec/memory.h b/include/exec/memory.h index 3e4d416..6c16a86 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -154,7 +154,7 @@ struct MemoryRegionIOMMUOps { /* Returns minimum supported page size */ uint64_t (*get_min_page_size)(MemoryRegion *iommu); /* Called when the first notifier is set */ - void (*notify_started)(MemoryRegion *iommu); + void (*notify_started)(MemoryRegion *iommu, IOMMUAccessFlags flag); /* Called when the last notifier is removed */ void (*notify_stopped)(MemoryRegion *iommu); }; @@ -623,8 +623,12 @@ void memory_region_notify_iommu(MemoryRegion *mr, * @n: the notifier to be added; the notifier receives a pointer to an * #IOMMUTLBEntry as the opaque value; the pointer ceases to be * valid on exit from the notifier. + * @flag: kind of notifer to request. IOMMU_RW for notifying all + * events (including additions), and IOMMU_NONE for notifying + * cache invalidations only. */ -void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n); +void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n, + IOMMUAccessFlags flag); /** * memory_region_iommu_replay: replay existing IOMMU translations to diff --git a/memory.c b/memory.c index 0eb6895..747a9ec 100644 --- a/memory.c +++ b/memory.c @@ -1513,11 +1513,13 @@ bool memory_region_is_logging(MemoryRegion *mr, uint8_t client) return memory_region_get_dirty_log_mask(mr) & (1 << client); } -void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n) +void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n, + IOMMUAccessFlags flag) { + assert(flag == IOMMU_NONE || flag == IOMMU_RW); if (mr->iommu_ops->notify_started && QLIST_EMPTY(&mr->iommu_notify.notifiers)) { - mr->iommu_ops->notify_started(mr); + mr->iommu_ops->notify_started(mr, flag); } notifier_list_add(&mr->iommu_notify, n); }