From nobody Mon Apr 29 03:14:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509427526854571.2056380332424; Mon, 30 Oct 2017 22:25:26 -0700 (PDT) Received: from localhost ([::1]:43761 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P3A-00026Q-PX for importer@patchew.org; Tue, 31 Oct 2017 01:25:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P1Q-00012X-IR for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9P1M-0004eY-Oh 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 1e9P1M-0004cw-9M for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:28 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 30 Oct 2017 22:23:27 -0700 Received: from sky-dev.bj.intel.com ([10.238.144.127]) by fmsmga005.fm.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="169289727" 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:07:00 +0800 Message-Id: <1509426425-23890-2-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> References: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> 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 1/6] memory: rename existing iommu notifier to be iommu mr 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: 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu IOMMU notifiers before are mostly used for [dev-]IOTLB stuffs. It is not suitable for other kind of notifiers (one example would be the future virt-svm support). Considering that current notifiers are targeted for per memory region, renaming the iommu notifier definitions. * all the notifier types from IOMMU_NOTIFIER_* prefix into IOMMU_MR_EVENT_* to better show its usage (for memory regions). * rename IOMMUNotifier to IOMMUMRNotifier * rename iommu_notifier to iommu_mr_notifier Signed-off-by: Peter Xu Signed-off-by: Liu, Yi L --- hw/i386/amd_iommu.c | 6 ++--- hw/i386/intel_iommu.c | 34 +++++++++++++------------- hw/ppc/spapr_iommu.c | 8 +++---- hw/s390x/s390-pci-bus.c | 2 +- hw/vfio/common.c | 10 ++++---- hw/virtio/vhost.c | 10 ++++---- include/exec/memory.h | 55 ++++++++++++++++++++++-----------------= ---- include/hw/i386/intel_iommu.h | 8 +++---- include/hw/vfio/vfio-common.h | 2 +- include/hw/virtio/vhost.h | 4 ++-- memory.c | 37 +++++++++++++++-------------- 11 files changed, 89 insertions(+), 87 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index ad8155c..8f756e8 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -1072,12 +1072,12 @@ static const MemoryRegionOps mmio_mem_ops =3D { }; =20 static void amdvi_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu, - IOMMUNotifierFlag old, - IOMMUNotifierFlag new) + IOMMUMREventFlag old, + IOMMUMREventFlag new) { AMDVIAddressSpace *as =3D container_of(iommu, AMDVIAddressSpace, iommu= ); =20 - if (new & IOMMU_NOTIFIER_MAP) { + if (new & IOMMU_MR_EVENT_MAP) { error_report("device %02x.%02x.%x requires iommu notifier which is= not " "currently supported", as->bus_num, PCI_SLOT(as->devf= n), PCI_FUNC(as->devfn)); diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 3a5bb0b..e81c706 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1234,7 +1234,7 @@ static void vtd_interrupt_remap_table_setup(IntelIOMM= UState *s) =20 static void vtd_iommu_replay_all(IntelIOMMUState *s) { - IntelIOMMUNotifierNode *node; + IntelIOMMUMRNotifierNode *node; =20 QLIST_FOREACH(node, &s->notifiers_list, next) { memory_region_iommu_replay_all(&node->vtd_as->iommu); @@ -1308,7 +1308,7 @@ static void vtd_context_device_invalidate(IntelIOMMUS= tate *s, /* * So a device is moving out of (or moving into) a * domain, a replay() suites here to notify all the - * IOMMU_NOTIFIER_MAP registers about this change. + * IOMMU_MR_EVENT_MAP registers about this change. * This won't bring bad even if we have no such * notifier registered - the IOMMU notification * framework will skip MAP notifications if that @@ -1358,7 +1358,7 @@ static void vtd_iotlb_global_invalidate(IntelIOMMUSta= te *s) =20 static void vtd_iotlb_domain_invalidate(IntelIOMMUState *s, uint16_t domai= n_id) { - IntelIOMMUNotifierNode *node; + IntelIOMMUMRNotifierNode *node; VTDContextEntry ce; VTDAddressSpace *vtd_as; =20 @@ -1388,7 +1388,7 @@ static void vtd_iotlb_page_invalidate_notify(IntelIOM= MUState *s, uint16_t domain_id, hwaddr addr, uint8_t am) { - IntelIOMMUNotifierNode *node; + IntelIOMMUMRNotifierNode *node; VTDContextEntry ce; int ret; =20 @@ -2318,21 +2318,21 @@ static IOMMUTLBEntry vtd_iommu_translate(IOMMUMemor= yRegion *iommu, hwaddr addr, } =20 static void vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu, - IOMMUNotifierFlag old, - IOMMUNotifierFlag new) + IOMMUMREventFlag old, + IOMMUMREventFlag new) { VTDAddressSpace *vtd_as =3D container_of(iommu, VTDAddressSpace, iommu= ); IntelIOMMUState *s =3D vtd_as->iommu_state; - IntelIOMMUNotifierNode *node =3D NULL; - IntelIOMMUNotifierNode *next_node =3D NULL; + IntelIOMMUMRNotifierNode *node =3D NULL; + IntelIOMMUMRNotifierNode *next_node =3D NULL; =20 - if (!s->caching_mode && new & IOMMU_NOTIFIER_MAP) { + if (!s->caching_mode && new & IOMMU_MR_EVENT_MAP) { error_report("We need to set cache_mode=3D1 for intel-iommu to ena= ble " "device assignment with IOMMU protection."); exit(1); } =20 - if (old =3D=3D IOMMU_NOTIFIER_NONE) { + if (old =3D=3D IOMMU_MR_EVENT_NONE) { node =3D g_malloc0(sizeof(*node)); node->vtd_as =3D vtd_as; QLIST_INSERT_HEAD(&s->notifiers_list, node, next); @@ -2342,7 +2342,7 @@ static void vtd_iommu_notify_flag_changed(IOMMUMemory= Region *iommu, /* update notifier node with new flags */ QLIST_FOREACH_SAFE(node, &s->notifiers_list, next, next_node) { if (node->vtd_as =3D=3D vtd_as) { - if (new =3D=3D IOMMU_NOTIFIER_NONE) { + if (new =3D=3D IOMMU_MR_EVENT_NONE) { QLIST_REMOVE(node, next); g_free(node); } @@ -2759,7 +2759,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, = PCIBus *bus, int devfn) } =20 /* Unmap the whole range in the notifier's scope. */ -static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) +static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUMRNotifier *= n) { IOMMUTLBEntry entry; hwaddr size; @@ -2814,13 +2814,13 @@ static void vtd_address_space_unmap(VTDAddressSpace= *as, IOMMUNotifier *n) =20 static void vtd_address_space_unmap_all(IntelIOMMUState *s) { - IntelIOMMUNotifierNode *node; + IntelIOMMUMRNotifierNode *node; VTDAddressSpace *vtd_as; - IOMMUNotifier *n; + IOMMUMRNotifier *n; =20 QLIST_FOREACH(node, &s->notifiers_list, next) { vtd_as =3D node->vtd_as; - IOMMU_NOTIFIER_FOREACH(n, &vtd_as->iommu) { + IOMMU_MR_NOTIFIER_FOREACH(n, &vtd_as->iommu) { vtd_address_space_unmap(vtd_as, n); } } @@ -2828,11 +2828,11 @@ static void vtd_address_space_unmap_all(IntelIOMMUS= tate *s) =20 static int vtd_replay_hook(IOMMUTLBEntry *entry, void *private) { - memory_region_notify_one((IOMMUNotifier *)private, entry); + memory_region_notify_one((IOMMUMRNotifier *)private, entry); return 0; } =20 -static void vtd_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n) +static void vtd_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUMRNotifier = *n) { VTDAddressSpace *vtd_as =3D container_of(iommu_mr, VTDAddressSpace, io= mmu); IntelIOMMUState *s =3D vtd_as->iommu_state; diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index 5ccd785..088f614 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -161,14 +161,14 @@ static uint64_t spapr_tce_get_min_page_size(IOMMUMemo= ryRegion *iommu) } =20 static void spapr_tce_notify_flag_changed(IOMMUMemoryRegion *iommu, - IOMMUNotifierFlag old, - IOMMUNotifierFlag new) + IOMMUMREventFlag old, + IOMMUMREventFlag new) { struct sPAPRTCETable *tbl =3D container_of(iommu, sPAPRTCETable, iommu= ); =20 - if (old =3D=3D IOMMU_NOTIFIER_NONE && new !=3D IOMMU_NOTIFIER_NONE) { + if (old =3D=3D IOMMU_MR_EVENT_NONE && new !=3D IOMMU_MR_EVENT_NONE) { spapr_tce_set_need_vfio(tbl, true); - } else if (old !=3D IOMMU_NOTIFIER_NONE && new =3D=3D IOMMU_NOTIFIER_N= ONE) { + } else if (old !=3D IOMMU_MR_EVENT_NONE && new =3D=3D IOMMU_MR_EVENT_N= ONE) { spapr_tce_set_need_vfio(tbl, false); } } diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index e7a58e8..10b7020 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -398,7 +398,7 @@ static IOMMUTLBEntry s390_translate_iommu(IOMMUMemoryRe= gion *mr, hwaddr addr, } =20 static void s390_pci_iommu_replay(IOMMUMemoryRegion *iommu, - IOMMUNotifier *notifier) + IOMMUMRNotifier *notifier) { /* It's impossible to plug a pci device on s390x that already has iommu * mappings which need to be replayed, that is due to the "one iommu p= er diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7b2924c..1f7d516 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -346,7 +346,7 @@ static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void *= *vaddr, return true; } =20 -static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) +static void vfio_iommu_map_notify(IOMMUMRNotifier *n, IOMMUTLBEntry *iotlb) { VFIOGuestIOMMU *giommu =3D container_of(n, VFIOGuestIOMMU, n); VFIOContainer *container =3D giommu->container; @@ -496,10 +496,10 @@ static void vfio_listener_region_add(MemoryListener *= listener, llend =3D int128_add(int128_make64(section->offset_within_region), section->size); llend =3D int128_sub(llend, int128_one()); - iommu_notifier_init(&giommu->n, vfio_iommu_map_notify, - IOMMU_NOTIFIER_ALL, - section->offset_within_region, - int128_get64(llend)); + iommu_mr_notifier_init(&giommu->n, vfio_iommu_map_notify, + IOMMU_MR_EVENT_ALL, + section->offset_within_region, + int128_get64(llend)); QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next); =20 memory_region_register_iommu_notifier(section->mr, &giommu->n); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index ddc42f0..e2c1228 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -719,7 +719,7 @@ static void vhost_region_del(MemoryListener *listener, } } =20 -static void vhost_iommu_unmap_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotl= b) +static void vhost_iommu_unmap_notify(IOMMUMRNotifier *n, IOMMUTLBEntry *io= tlb) { struct vhost_iommu *iommu =3D container_of(n, struct vhost_iommu, n); struct vhost_dev *hdev =3D iommu->hdev; @@ -747,10 +747,10 @@ static void vhost_iommu_region_add(MemoryListener *li= stener, end =3D int128_add(int128_make64(section->offset_within_region), section->size); end =3D int128_sub(end, int128_one()); - iommu_notifier_init(&iommu->n, vhost_iommu_unmap_notify, - IOMMU_NOTIFIER_UNMAP, - section->offset_within_region, - int128_get64(end)); + iommu_mr_notifier_init(&iommu->n, vhost_iommu_unmap_notify, + IOMMU_MR_EVENT_UNMAP, + section->offset_within_region, + int128_get64(end)); iommu->mr =3D section->mr; iommu->iommu_offset =3D section->offset_within_address_space - section->offset_within_region; diff --git a/include/exec/memory.h b/include/exec/memory.h index 5ed4042..03595e3 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -75,36 +75,36 @@ struct IOMMUTLBEntry { }; =20 /* - * Bitmap for different IOMMUNotifier capabilities. Each notifier can + * Bitmap for different IOMMUMRNotifier capabilities. Each notifier can * register with one or multiple IOMMU Notifier capability bit(s). */ typedef enum { - IOMMU_NOTIFIER_NONE =3D 0, + IOMMU_MR_EVENT_NONE =3D 0, /* Notify cache invalidations */ - IOMMU_NOTIFIER_UNMAP =3D 0x1, + IOMMU_MR_EVENT_UNMAP =3D 0x1, /* Notify entry changes (newly created entries) */ - IOMMU_NOTIFIER_MAP =3D 0x2, -} IOMMUNotifierFlag; + IOMMU_MR_EVENT_MAP =3D 0x2, +} IOMMUMREventFlag; =20 -#define IOMMU_NOTIFIER_ALL (IOMMU_NOTIFIER_MAP | IOMMU_NOTIFIER_UNMAP) +#define IOMMU_MR_EVENT_ALL (IOMMU_MR_EVENT_MAP | IOMMU_MR_EVENT_UNMAP) =20 -struct IOMMUNotifier; -typedef void (*IOMMUNotify)(struct IOMMUNotifier *notifier, +struct IOMMUMRNotifier; +typedef void (*IOMMUMRNotify)(struct IOMMUMRNotifier *notifier, IOMMUTLBEntry *data); =20 -struct IOMMUNotifier { - IOMMUNotify notify; - IOMMUNotifierFlag notifier_flags; +struct IOMMUMRNotifier { + IOMMUMRNotify notify; + IOMMUMREventFlag notifier_flags; /* Notify for address space range start <=3D addr <=3D end */ hwaddr start; hwaddr end; - QLIST_ENTRY(IOMMUNotifier) node; + QLIST_ENTRY(IOMMUMRNotifier) node; }; -typedef struct IOMMUNotifier IOMMUNotifier; +typedef struct IOMMUMRNotifier IOMMUMRNotifier; =20 -static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, - IOMMUNotifierFlag flags, - hwaddr start, hwaddr end) +static inline void iommu_mr_notifier_init(IOMMUMRNotifier *n, IOMMUMRNotif= y fn, + IOMMUMREventFlag flags, + hwaddr start, hwaddr end) { n->notify =3D fn; n->notifier_flags =3D flags; @@ -206,10 +206,10 @@ typedef struct IOMMUMemoryRegionClass { uint64_t (*get_min_page_size)(IOMMUMemoryRegion *iommu); /* Called when IOMMU Notifier flag changed */ void (*notify_flag_changed)(IOMMUMemoryRegion *iommu, - IOMMUNotifierFlag old_flags, - IOMMUNotifierFlag new_flags); + IOMMUMREventFlag old_flags, + IOMMUMREventFlag new_flags); /* Set this up to provide customized IOMMU replay function */ - void (*replay)(IOMMUMemoryRegion *iommu, IOMMUNotifier *notifier); + void (*replay)(IOMMUMemoryRegion *iommu, IOMMUMRNotifier *notifier); } IOMMUMemoryRegionClass; =20 typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -259,11 +259,11 @@ struct MemoryRegion { struct IOMMUMemoryRegion { MemoryRegion parent_obj; =20 - QLIST_HEAD(, IOMMUNotifier) iommu_notify; - IOMMUNotifierFlag iommu_notify_flags; + QLIST_HEAD(, IOMMUMRNotifier) iommu_notify; + IOMMUMREventFlag iommu_notify_flags; }; =20 -#define IOMMU_NOTIFIER_FOREACH(n, mr) \ +#define IOMMU_MR_NOTIFIER_FOREACH(n, mr) \ QLIST_FOREACH((n), &(mr)->iommu_notify, node) =20 /** @@ -879,7 +879,7 @@ void memory_region_notify_iommu(IOMMUMemoryRegion *iomm= u_mr, * replaces all old entries for the same virtual I/O address range. * Deleted entries have .@perm =3D=3D 0. */ -void memory_region_notify_one(IOMMUNotifier *notifier, +void memory_region_notify_one(IOMMUMRNotifier *notifier, IOMMUTLBEntry *entry); =20 /** @@ -887,12 +887,12 @@ void memory_region_notify_one(IOMMUNotifier *notifier, * IOMMU translation entries. * * @mr: the memory region to observe - * @n: the IOMMUNotifier to be added; the notify callback receives a + * @n: the IOMMUMRNotifier to be added; the notify callback receives a * pointer to an #IOMMUTLBEntry as the opaque value; the pointer * ceases to be valid on exit from the notifier. */ void memory_region_register_iommu_notifier(MemoryRegion *mr, - IOMMUNotifier *n); + IOMMUMRNotifier *n); =20 /** * memory_region_iommu_replay: replay existing IOMMU translations to @@ -902,7 +902,8 @@ void memory_region_register_iommu_notifier(MemoryRegion= *mr, * @iommu_mr: the memory region to observe * @n: the notifier to which to replay iommu mappings */ -void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier= *n); +void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, + IOMMUMRNotifier *n); =20 /** * memory_region_iommu_replay_all: replay existing IOMMU translations @@ -921,7 +922,7 @@ void memory_region_iommu_replay_all(IOMMUMemoryRegion *= iommu_mr); * @n: the notifier to be removed. */ void memory_region_unregister_iommu_notifier(MemoryRegion *mr, - IOMMUNotifier *n); + IOMMUMRNotifier *n); =20 /** * memory_region_name: get a memory region's name diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index ac15e6b..c85f9ff 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -65,7 +65,7 @@ typedef union VTD_IR_TableEntry VTD_IR_TableEntry; typedef union VTD_IR_MSIAddress VTD_IR_MSIAddress; typedef struct VTDIrq VTDIrq; typedef struct VTD_MSIMessage VTD_MSIMessage; -typedef struct IntelIOMMUNotifierNode IntelIOMMUNotifierNode; +typedef struct IntelIOMMUMRNotifierNode IntelIOMMUMRNotifierNode; =20 /* Context-Entry */ struct VTDContextEntry { @@ -251,9 +251,9 @@ struct VTD_MSIMessage { /* When IR is enabled, all MSI/MSI-X data bits should be zero */ #define VTD_IR_MSI_DATA (0) =20 -struct IntelIOMMUNotifierNode { +struct IntelIOMMUMRNotifierNode { VTDAddressSpace *vtd_as; - QLIST_ENTRY(IntelIOMMUNotifierNode) next; + QLIST_ENTRY(IntelIOMMUMRNotifierNode) next; }; =20 /* The iommu (DMAR) device state struct */ @@ -293,7 +293,7 @@ struct IntelIOMMUState { GHashTable *vtd_as_by_busptr; /* VTDBus objects indexed by PCIBus* r= eference */ VTDBus *vtd_as_by_bus_num[VTD_PCI_BUS_MAX]; /* VTDBus objects indexed = by bus number */ /* list of registered notifiers */ - QLIST_HEAD(, IntelIOMMUNotifierNode) notifiers_list; + QLIST_HEAD(, IntelIOMMUMRNotifierNode) notifiers_list; =20 /* interrupt remapping */ bool intr_enabled; /* Whether guest enabled IR */ diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index f3a2ac9..865e3e7 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -97,7 +97,7 @@ typedef struct VFIOGuestIOMMU { VFIOContainer *container; IOMMUMemoryRegion *iommu; hwaddr iommu_offset; - IOMMUNotifier n; + IOMMUMRNotifier n; QLIST_ENTRY(VFIOGuestIOMMU) giommu_next; } VFIOGuestIOMMU; =20 diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 467dc77..ffe9d9f 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -42,7 +42,7 @@ struct vhost_iommu { struct vhost_dev *hdev; MemoryRegion *mr; hwaddr iommu_offset; - IOMMUNotifier n; + IOMMUMRNotifier n; QLIST_ENTRY(vhost_iommu) iommu_next; }; =20 @@ -75,7 +75,7 @@ struct vhost_dev { struct vhost_log *log; QLIST_ENTRY(vhost_dev) entry; QLIST_HEAD(, vhost_iommu) iommu_list; - IOMMUNotifier n; + IOMMUMRNotifier n; }; =20 int vhost_dev_init(struct vhost_dev *hdev, void *opaque, diff --git a/memory.c b/memory.c index e26e5a3..77fb3ef 100644 --- a/memory.c +++ b/memory.c @@ -1689,7 +1689,7 @@ void memory_region_init_iommu(void *_iommu_mr, iommu_mr =3D IOMMU_MEMORY_REGION(mr); mr->terminates =3D true; /* then re-forwards */ QLIST_INIT(&iommu_mr->iommu_notify); - iommu_mr->iommu_notify_flags =3D IOMMU_NOTIFIER_NONE; + iommu_mr->iommu_notify_flags =3D IOMMU_MR_EVENT_NONE; } =20 static void memory_region_finalize(Object *obj) @@ -1786,12 +1786,12 @@ bool memory_region_is_logging(MemoryRegion *mr, uin= t8_t client) =20 static void memory_region_update_iommu_notify_flags(IOMMUMemoryRegion *iom= mu_mr) { - IOMMUNotifierFlag flags =3D IOMMU_NOTIFIER_NONE; - IOMMUNotifier *iommu_notifier; + IOMMUMREventFlag flags =3D IOMMU_MR_EVENT_NONE; + IOMMUMRNotifier *iommu_mr_notifier; IOMMUMemoryRegionClass *imrc =3D IOMMU_MEMORY_REGION_GET_CLASS(iommu_m= r); =20 - IOMMU_NOTIFIER_FOREACH(iommu_notifier, iommu_mr) { - flags |=3D iommu_notifier->notifier_flags; + IOMMU_MR_NOTIFIER_FOREACH(iommu_mr_notifier, iommu_mr) { + flags |=3D iommu_mr_notifier->notifier_flags; } =20 if (flags !=3D iommu_mr->iommu_notify_flags && imrc->notify_flag_chang= ed) { @@ -1804,7 +1804,7 @@ static void memory_region_update_iommu_notify_flags(I= OMMUMemoryRegion *iommu_mr) } =20 void memory_region_register_iommu_notifier(MemoryRegion *mr, - IOMMUNotifier *n) + IOMMUMRNotifier *n) { IOMMUMemoryRegion *iommu_mr; =20 @@ -1815,7 +1815,7 @@ void memory_region_register_iommu_notifier(MemoryRegi= on *mr, =20 /* We need to register for at least one bitfield */ iommu_mr =3D IOMMU_MEMORY_REGION(mr); - assert(n->notifier_flags !=3D IOMMU_NOTIFIER_NONE); + assert(n->notifier_flags !=3D IOMMU_MR_EVENT_NONE); assert(n->start <=3D n->end); QLIST_INSERT_HEAD(&iommu_mr->iommu_notify, n, node); memory_region_update_iommu_notify_flags(iommu_mr); @@ -1831,7 +1831,8 @@ uint64_t memory_region_iommu_get_min_page_size(IOMMUM= emoryRegion *iommu_mr) return TARGET_PAGE_SIZE; } =20 -void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier= *n) +void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, + IOMMUMRNotifier *n) { MemoryRegion *mr =3D MEMORY_REGION(iommu_mr); IOMMUMemoryRegionClass *imrc =3D IOMMU_MEMORY_REGION_GET_CLASS(iommu_m= r); @@ -1862,15 +1863,15 @@ void memory_region_iommu_replay(IOMMUMemoryRegion *= iommu_mr, IOMMUNotifier *n) =20 void memory_region_iommu_replay_all(IOMMUMemoryRegion *iommu_mr) { - IOMMUNotifier *notifier; + IOMMUMRNotifier *notifier; =20 - IOMMU_NOTIFIER_FOREACH(notifier, iommu_mr) { + IOMMU_MR_NOTIFIER_FOREACH(notifier, iommu_mr) { memory_region_iommu_replay(iommu_mr, notifier); } } =20 void memory_region_unregister_iommu_notifier(MemoryRegion *mr, - IOMMUNotifier *n) + IOMMUMRNotifier *n) { IOMMUMemoryRegion *iommu_mr; =20 @@ -1883,10 +1884,10 @@ void memory_region_unregister_iommu_notifier(Memory= Region *mr, memory_region_update_iommu_notify_flags(iommu_mr); } =20 -void memory_region_notify_one(IOMMUNotifier *notifier, +void memory_region_notify_one(IOMMUMRNotifier *notifier, IOMMUTLBEntry *entry) { - IOMMUNotifierFlag request_flags; + IOMMUMREventFlag request_flags; =20 /* * Skip the notification if the notification does not overlap @@ -1898,9 +1899,9 @@ void memory_region_notify_one(IOMMUNotifier *notifier, } =20 if (entry->perm & IOMMU_RW) { - request_flags =3D IOMMU_NOTIFIER_MAP; + request_flags =3D IOMMU_MR_EVENT_MAP; } else { - request_flags =3D IOMMU_NOTIFIER_UNMAP; + request_flags =3D IOMMU_MR_EVENT_UNMAP; } =20 if (notifier->notifier_flags & request_flags) { @@ -1911,12 +1912,12 @@ void memory_region_notify_one(IOMMUNotifier *notifi= er, void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, IOMMUTLBEntry entry) { - IOMMUNotifier *iommu_notifier; + IOMMUMRNotifier *iommu_mr_notifier; =20 assert(memory_region_is_iommu(MEMORY_REGION(iommu_mr))); =20 - IOMMU_NOTIFIER_FOREACH(iommu_notifier, iommu_mr) { - memory_region_notify_one(iommu_notifier, &entry); + IOMMU_MR_NOTIFIER_FOREACH(iommu_mr_notifier, iommu_mr) { + memory_region_notify_one(iommu_mr_notifier, &entry); } } =20 --=20 1.9.1 From nobody Mon Apr 29 03:14:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509427654970482.52375187270275; Mon, 30 Oct 2017 22:27:34 -0700 (PDT) Received: from localhost ([::1]:43771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P5E-0003vY-VZ for importer@patchew.org; Tue, 31 Oct 2017 01:27:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P1Q-00012Z-KP for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9P1O-0004ft-TE 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 1e9P1O-0004cw-HR for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:30 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 30 Oct 2017 22:23:30 -0700 Received: from sky-dev.bj.intel.com ([10.238.144.127]) by fmsmga005.fm.intel.com with ESMTP; 30 Oct 2017 22:23:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,322,1505804400"; d="scan'208";a="169289753" 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:07:01 +0800 Message-Id: <1509426425-23890-3-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> References: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> 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 2/6] memory: introduce AddressSpaceOps and IOMMUObject 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu AddressSpaceOps is similar to MemoryRegionOps, it's just for address spaces to store arch-specific hooks. The first hook I would like to introduce is iommu_get(). Return an IOMMUObject behind the AddressSpace. For systems that have IOMMUs, we will create a special address space per device which is different from system default address space for it (please refer to pci_device_iommu_address_space()). Normally when that happens, there will be one specific IOMMU (or say, translation unit) stands right behind that new address space. This iommu_get() fetches that guy behind the address space. Here, the guy is defined as IOMMUObject, which includes a notifier_list so far, may extend in future. Along with IOMMUObject, a new iommu notifier mechanism is introduced. It would be used for virt-svm. Also IOMMUObject can further have a IOMMUObjectOps which is similar to MemoryRegionOps. The difference is IOMMUObjectOps is not relied on MemoryRegion. Signed-off-by: Peter Xu Signed-off-by: Liu, Yi L --- hw/core/Makefile.objs | 1 + hw/core/iommu.c | 58 +++++++++++++++++++++++++++++++++++++++ include/exec/memory.h | 22 +++++++++++++++ include/hw/core/iommu.h | 73 +++++++++++++++++++++++++++++++++++++++++++++= ++++ memory.c | 8 ++++++ 5 files changed, 162 insertions(+) create mode 100644 hw/core/iommu.c create mode 100644 include/hw/core/iommu.h diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index f8d7a4a..d688412 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -5,6 +5,7 @@ common-obj-y +=3D fw-path-provider.o # irq.o needed for qdev GPIO handling: common-obj-y +=3D irq.o common-obj-y +=3D hotplug.o +common-obj-y +=3D iommu.o common-obj-y +=3D nmi.o =20 common-obj-$(CONFIG_EMPTY_SLOT) +=3D empty_slot.o diff --git a/hw/core/iommu.c b/hw/core/iommu.c new file mode 100644 index 0000000..7c4fcfe --- /dev/null +++ b/hw/core/iommu.c @@ -0,0 +1,58 @@ +/* + * QEMU emulation of IOMMU logic + * + * Copyright (C) 2017 Red Hat Inc. + * + * Authors: Peter Xu , + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/core/iommu.h" + +void iommu_notifier_register(IOMMUObject *iommu, + IOMMUNotifier *n, + IOMMUNotifyFn fn, + IOMMUEvent event) +{ + n->event =3D event; + n->iommu_notify =3D fn; + QLIST_INSERT_HEAD(&iommu->iommu_notifiers, n, node); + return; +} + +void iommu_notifier_unregister(IOMMUObject *iommu, + IOMMUNotifier *notifier) +{ + IOMMUNotifier *cur, *next; + + QLIST_FOREACH_SAFE(cur, &iommu->iommu_notifiers, node, next) { + if (cur =3D=3D notifier) { + QLIST_REMOVE(cur, node); + break; + } + } +} + +void iommu_notify(IOMMUObject *iommu, IOMMUEventData *event_data) +{ + IOMMUNotifier *cur; + + QLIST_FOREACH(cur, &iommu->iommu_notifiers, node) { + if ((cur->event =3D=3D event_data->event) && cur->iommu_notify) { + cur->iommu_notify(cur, event_data); + } + } +} diff --git a/include/exec/memory.h b/include/exec/memory.h index 03595e3..8350973 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -26,6 +26,7 @@ #include "qom/object.h" #include "qemu/rcu.h" #include "hw/qdev-core.h" +#include "hw/core/iommu.h" =20 #define RAM_ADDR_INVALID (~(ram_addr_t)0) =20 @@ -301,6 +302,19 @@ struct MemoryListener { }; =20 /** + * AddressSpaceOps: callbacks structure for address space specific operati= ons + * + * @iommu_get: returns an IOMMU object that backs the address space. + * Normally this should be NULL for generic address + * spaces, and it's only used when there is one + * translation unit behind this address space. + */ +struct AddressSpaceOps { + IOMMUObject *(*iommu_get)(AddressSpace *as); +}; +typedef struct AddressSpaceOps AddressSpaceOps; + +/** * AddressSpace: describes a mapping of addresses to #MemoryRegion objects */ struct AddressSpace { @@ -316,6 +330,7 @@ struct AddressSpace { struct MemoryRegionIoeventfd *ioeventfds; QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners; QTAILQ_ENTRY(AddressSpace) address_spaces_link; + AddressSpaceOps as_ops; }; =20 FlatView *address_space_to_flatview(AddressSpace *as); @@ -1988,6 +2003,13 @@ address_space_write_cached(MemoryRegionCache *cache,= hwaddr addr, address_space_write(cache->as, cache->xlat + addr, MEMTXATTRS_UNSPECIF= IED, buf, len); } =20 +/** + * address_space_iommu_get: Get the backend IOMMU for the address space + * + * @as: the address space to fetch IOMMU from + */ +IOMMUObject *address_space_iommu_get(AddressSpace *as); + #endif =20 #endif diff --git a/include/hw/core/iommu.h b/include/hw/core/iommu.h new file mode 100644 index 0000000..34387c0 --- /dev/null +++ b/include/hw/core/iommu.h @@ -0,0 +1,73 @@ +/* + * QEMU emulation of IOMMU logic + * + * Copyright (C) 2017 Red Hat Inc. + * + * Authors: Peter Xu , + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#ifndef HW_CORE_IOMMU_H +#define HW_CORE_IOMMU_H + +#include "qemu/queue.h" + +enum IOMMUEvent { + IOMMU_EVENT_BIND_PASIDT, +}; +typedef enum IOMMUEvent IOMMUEvent; + +struct IOMMUEventData { + IOMMUEvent event; + uint64_t length; + void *data; +}; +typedef struct IOMMUEventData IOMMUEventData; + +typedef struct IOMMUNotifier IOMMUNotifier; + +typedef void (*IOMMUNotifyFn)(IOMMUNotifier *notifier, + IOMMUEventData *event_data); + +struct IOMMUNotifier { + IOMMUNotifyFn iommu_notify; + /* + * What events we are listening to. Let's allow multiple event + * registrations from beginning. + */ + IOMMUEvent event; + QLIST_ENTRY(IOMMUNotifier) node; +}; + +typedef struct IOMMUObject IOMMUObject; + +/* + * This stands for an IOMMU unit. Any translation device should have + * this struct inside its own structure to make sure it can leverage + * common IOMMU functionalities. + */ +struct IOMMUObject { + QLIST_HEAD(, IOMMUNotifier) iommu_notifiers; +}; + +void iommu_notifier_register(IOMMUObject *iommu, + IOMMUNotifier *n, + IOMMUNotifyFn fn, + IOMMUEvent event); +void iommu_notifier_unregister(IOMMUObject *iommu, + IOMMUNotifier *notifier); +void iommu_notify(IOMMUObject *iommu, IOMMUEventData *event_data); + +#endif diff --git a/memory.c b/memory.c index 77fb3ef..ec67441 100644 --- a/memory.c +++ b/memory.c @@ -2793,6 +2793,14 @@ static void do_address_space_destroy(AddressSpace *a= s) memory_region_unref(as->root); } =20 +IOMMUObject *address_space_iommu_get(AddressSpace *as) +{ + if (!as->as_ops.iommu_get) { + return NULL; + } + return as->as_ops.iommu_get(as); +} + void address_space_destroy(AddressSpace *as) { MemoryRegion *root =3D as->root; --=20 1.9.1 From nobody Mon Apr 29 03:14:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509427744061133.37809944807248; Mon, 30 Oct 2017 22:29:04 -0700 (PDT) Received: from localhost ([::1]:43775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P6j-0005Fi-B6 for importer@patchew.org; Tue, 31 Oct 2017 01:29:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P1S-00012n-Ms for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9P1R-0004jJ-Tx for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:34 -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 1e9P1R-0004cw-Iu for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:33 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 30 Oct 2017 22:23:33 -0700 Received: from sky-dev.bj.intel.com ([10.238.144.127]) by fmsmga005.fm.intel.com with ESMTP; 30 Oct 2017 22:23:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,322,1505804400"; d="scan'208";a="169289762" 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:07:02 +0800 Message-Id: <1509426425-23890-4-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> References: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> 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 3/6] intel_iommu: provide AddressSpaceOps.iommu_get instance 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu Provide AddressSpaceOps.iommu_get() in Intel IOMMU emulator. Signed-off-by: Peter Xu Signed-off-by: Liu, Yi L --- hw/i386/intel_iommu.c | 7 +++++++ include/hw/i386/intel_iommu.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index e81c706..54343e5 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2687,6 +2687,12 @@ static const MemoryRegionOps vtd_mem_ir_ops =3D { }, }; =20 +static IOMMUObject *vtd_as_iommu_get(AddressSpace *as) +{ + VTDAddressSpace *vtd_dev_as =3D container_of(as, VTDAddressSpace, as); + return &vtd_dev_as->iommu_object; +} + VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, int devf= n) { uintptr_t key =3D (uintptr_t)bus; @@ -2748,6 +2754,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, = PCIBus *bus, int devfn) VTD_INTERRUPT_ADDR_FIRST, &vtd_dev_as->iommu_ir, 64); address_space_init(&vtd_dev_as->as, &vtd_dev_as->root, name); + vtd_dev_as->as.as_ops.iommu_get =3D vtd_as_iommu_get; memory_region_add_subregion_overlap(&vtd_dev_as->root, 0, &vtd_dev_as->sys_alias, 1); memory_region_add_subregion_overlap(&vtd_dev_as->root, 0, diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index c85f9ff..a3c6d45 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -27,6 +27,7 @@ #include "hw/i386/ioapic.h" #include "hw/pci/msi.h" #include "hw/sysbus.h" +#include "hw/core/iommu.h" =20 #define TYPE_INTEL_IOMMU_DEVICE "intel-iommu" #define INTEL_IOMMU_DEVICE(obj) \ @@ -90,6 +91,7 @@ struct VTDAddressSpace { MemoryRegion sys_alias; MemoryRegion iommu_ir; /* Interrupt region: 0xfeeXXXXX */ IntelIOMMUState *iommu_state; + IOMMUObject iommu_object; VTDContextCacheEntry context_cache_entry; }; =20 --=20 1.9.1 From nobody Mon Apr 29 03:14:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509427529237190.66398658610763; Mon, 30 Oct 2017 22:25:29 -0700 (PDT) Received: from localhost ([::1]:43763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P3I-0002CX-8R for importer@patchew.org; Tue, 31 Oct 2017 01:25:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P1W-00015o-Io for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9P1V-0004nU-KD for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:38 -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 1e9P1V-0004cw-Bi for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:37 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 30 Oct 2017 22:23:37 -0700 Received: from sky-dev.bj.intel.com ([10.238.144.127]) by fmsmga005.fm.intel.com with ESMTP; 30 Oct 2017 22:23:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,322,1505804400"; d="scan'208";a="169289776" 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:07:03 +0800 Message-Id: <1509426425-23890-5-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> References: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> 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 4/6] vfio: rename GuestIOMMU to be GuestIOMMUMR 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rename GuestIOMMU to GuestIOMMUMR as the existing GuestIOMMU is for MemoryRegion related notifiers. Signed-off-by: Liu, Yi L --- hw/vfio/common.c | 15 ++++++++------- include/hw/vfio/vfio-common.h | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 1f7d516..3d40bec 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -348,7 +348,7 @@ static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void *= *vaddr, =20 static void vfio_iommu_map_notify(IOMMUMRNotifier *n, IOMMUTLBEntry *iotlb) { - VFIOGuestIOMMU *giommu =3D container_of(n, VFIOGuestIOMMU, n); + VFIOGuestIOMMUMR *giommu =3D container_of(n, VFIOGuestIOMMUMR, n); VFIOContainer *container =3D giommu->container; hwaddr iova =3D iotlb->iova + giommu->iommu_offset; bool read_only; @@ -478,7 +478,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, memory_region_ref(section->mr); =20 if (memory_region_is_iommu(section->mr)) { - VFIOGuestIOMMU *giommu; + VFIOGuestIOMMUMR *giommu; IOMMUMemoryRegion *iommu_mr =3D IOMMU_MEMORY_REGION(section->mr); =20 trace_vfio_listener_region_add_iommu(iova, end); @@ -500,7 +500,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, IOMMU_MR_EVENT_ALL, section->offset_within_region, int128_get64(llend)); - QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next); + QLIST_INSERT_HEAD(&container->giommu_mr_list, giommu, giommu_next); =20 memory_region_register_iommu_notifier(section->mr, &giommu->n); memory_region_iommu_replay(giommu->iommu, &giommu->n); @@ -567,9 +567,9 @@ static void vfio_listener_region_del(MemoryListener *li= stener, } =20 if (memory_region_is_iommu(section->mr)) { - VFIOGuestIOMMU *giommu; + VFIOGuestIOMMUMR *giommu; =20 - QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) { + QLIST_FOREACH(giommu, &container->giommu_mr_list, giommu_next) { if (MEMORY_REGION(giommu->iommu) =3D=3D section->mr && giommu->n.start =3D=3D section->offset_within_region) { memory_region_unregister_iommu_notifier(section->mr, @@ -1163,12 +1163,13 @@ static void vfio_disconnect_container(VFIOGroup *gr= oup) =20 if (QLIST_EMPTY(&container->group_list)) { VFIOAddressSpace *space =3D container->space; - VFIOGuestIOMMU *giommu, *tmp; + VFIOGuestIOMMUMR *giommu, *tmp; =20 vfio_listener_release(container); QLIST_REMOVE(container, next); =20 - QLIST_FOREACH_SAFE(giommu, &container->giommu_list, giommu_next, t= mp) { + QLIST_FOREACH_SAFE(giommu, &container->giommu_mr_list, + giommu_next, tmp) { memory_region_unregister_iommu_notifier( MEMORY_REGION(giommu->iommu), &giommu->n); QLIST_REMOVE(giommu, giommu_next); diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 865e3e7..702a085 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -87,19 +87,19 @@ typedef struct VFIOContainer { * contiguous IOVA window. We may need to generalize that in * future */ - QLIST_HEAD(, VFIOGuestIOMMU) giommu_list; + QLIST_HEAD(, VFIOGuestIOMMUMR) giommu_mr_list; QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list; QLIST_HEAD(, VFIOGroup) group_list; QLIST_ENTRY(VFIOContainer) next; } VFIOContainer; =20 -typedef struct VFIOGuestIOMMU { +typedef struct VFIOGuestIOMMUMR { VFIOContainer *container; IOMMUMemoryRegion *iommu; hwaddr iommu_offset; IOMMUMRNotifier n; - QLIST_ENTRY(VFIOGuestIOMMU) giommu_next; -} VFIOGuestIOMMU; + QLIST_ENTRY(VFIOGuestIOMMUMR) giommu_next; +} VFIOGuestIOMMUMR; =20 typedef struct VFIOHostDMAWindow { hwaddr min_iova; --=20 1.9.1 From nobody Mon Apr 29 03:14:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150942766245354.85717400457577; Mon, 30 Oct 2017 22:27:42 -0700 (PDT) Received: from localhost ([::1]:43773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P5R-0004El-BD for importer@patchew.org; Tue, 31 Oct 2017 01:27:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P1b-0001AX-JO for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9P1Y-0004qr-6c for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:43 -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 1e9P1X-0004cw-RR for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:40 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 30 Oct 2017 22:23:39 -0700 Received: from sky-dev.bj.intel.com ([10.238.144.127]) by fmsmga005.fm.intel.com with ESMTP; 30 Oct 2017 22:23:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,322,1505804400"; d="scan'208";a="169289791" 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:07:04 +0800 Message-Id: <1509426425-23890-6-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> References: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> 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 5/6] vfio/pci: add notify framework based on IOMMUObject 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch introduce a notify framework for IOMMUObject.iommu_notifiers. Introduce VFIOGuestIOMMUObject is to link VFIO Container and the new IOMMUObject notififiers. VFIOGuestIOMMUObject instance is allocated when device is assigned and meanwhile vIOMMU is exposed to guest. If there is IOMMUObject behind the device AddressSpace(a.ka vIOMMU exposed). The VFIOGuestIOMMUObject instance would be allocated and inserted to the VFIOContainer.giommu_object_list. Signed-off-by: Liu, Yi L --- hw/vfio/pci.c | 39 ++++++++++++++++++++++++++++++++++++++- include/hw/vfio/vfio-common.h | 8 ++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c977ee3..5b77c7e 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2642,6 +2642,8 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) VFIOPCIDevice *vdev =3D DO_UPCAST(VFIOPCIDevice, pdev, pdev); VFIODevice *vbasedev_iter; VFIOGroup *group; + AddressSpace *as; + IOMMUObject *iommu; char *tmp, group_path[PATH_MAX], *group_name; Error *err =3D NULL; ssize_t len; @@ -2694,7 +2696,8 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) =20 trace_vfio_realize(vdev->vbasedev.name, groupid); =20 - group =3D vfio_get_group(groupid, pci_device_iommu_address_space(pdev)= , errp); + as =3D pci_device_iommu_address_space(pdev); + group =3D vfio_get_group(groupid, as, errp); if (!group) { goto error; } @@ -2877,6 +2880,17 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) vfio_register_req_notifier(vdev); vfio_setup_resetfn_quirk(vdev); =20 + iommu =3D address_space_iommu_get(as); + if (iommu !=3D NULL) { + VFIOGuestIOMMUObject *giommu; + giommu =3D g_malloc0(sizeof(*giommu)); + giommu->iommu =3D iommu; + giommu->container =3D group->container; + QLIST_INSERT_HEAD(&group->container->giommu_object_list, + giommu, + giommu_next); + } + return; =20 out_teardown: @@ -2907,6 +2921,28 @@ static void vfio_instance_finalize(Object *obj) vfio_put_group(group); } =20 +static void vfio_release_iommu_object(PCIDevice *pdev) +{ + VFIOPCIDevice *vdev =3D DO_UPCAST(VFIOPCIDevice, pdev, pdev); + AddressSpace *as; + IOMMUObject *iommu; + + as =3D pci_device_iommu_address_space(pdev); + iommu =3D address_space_iommu_get(as); + if (iommu !=3D NULL) { + VFIOGuestIOMMUObject *giommu, *tmp; + VFIOGroup *group; + group =3D vdev->vbasedev.group; + + QLIST_FOREACH_SAFE(giommu, + &group->container->giommu_object_list, + giommu_next, tmp) { + QLIST_REMOVE(giommu, giommu_next); + g_free(giommu); + } + } + return; +} static void vfio_exitfn(PCIDevice *pdev) { VFIOPCIDevice *vdev =3D DO_UPCAST(VFIOPCIDevice, pdev, pdev); @@ -2915,6 +2951,7 @@ static void vfio_exitfn(PCIDevice *pdev) vfio_unregister_err_notifier(vdev); pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); vfio_disable_interrupts(vdev); + vfio_release_iommu_object(pdev); if (vdev->intx.mmap_timer) { timer_free(vdev->intx.mmap_timer); } diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 702a085..e4963cc 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -88,6 +88,7 @@ typedef struct VFIOContainer { * future */ QLIST_HEAD(, VFIOGuestIOMMUMR) giommu_mr_list; + QLIST_HEAD(, VFIOGuestIOMMUObject) giommu_object_list; QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list; QLIST_HEAD(, VFIOGroup) group_list; QLIST_ENTRY(VFIOContainer) next; @@ -101,6 +102,13 @@ typedef struct VFIOGuestIOMMUMR { QLIST_ENTRY(VFIOGuestIOMMUMR) giommu_next; } VFIOGuestIOMMUMR; =20 +typedef struct VFIOGuestIOMMUObject { + VFIOContainer *container; + IOMMUObject *iommu; + IOMMUNotifier n; + QLIST_ENTRY(VFIOGuestIOMMUObject) giommu_next; +} VFIOGuestIOMMUObject; + typedef struct VFIOHostDMAWindow { hwaddr min_iova; hwaddr max_iova; --=20 1.9.1 From nobody Mon Apr 29 03:14:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509427657054706.2086730576963; Mon, 30 Oct 2017 22:27:37 -0700 (PDT) Received: from localhost ([::1]:43772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P5K-00048b-83 for importer@patchew.org; Tue, 31 Oct 2017 01:27:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9P1b-0001Ae-MF for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9P1a-0004t2-OD for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:43 -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 1e9P1a-0004cw-Fm for qemu-devel@nongnu.org; Tue, 31 Oct 2017 01:23:42 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 30 Oct 2017 22:23:42 -0700 Received: from sky-dev.bj.intel.com ([10.238.144.127]) by fmsmga005.fm.intel.com with ESMTP; 30 Oct 2017 22:23:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,322,1505804400"; d="scan'208";a="169289802" 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:07:05 +0800 Message-Id: <1509426425-23890-7-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> References: <1509426425-23890-1-git-send-email-yi.l.liu@linux.intel.com> 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 6/6] vfio/pci: register vfio_iommu_bind_pasidtbl_notify 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: 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is an example to show the usage of IOMMUObject based notifier. For passthru devices, if there is a vIOMMU exposed to guest, guest would issue iommu operation on the devices. And the iommu operations needs to be propagated to host iommu driver. In future, the IOMMUObject notifiers may include: * notifier for guest pasid table binding * notifier for guest iommu tlb invalidation Both of the two notifiers would be include in future virt-SVM patchset. In virt-SVM patchset, this notifier would be fulfilled. Signed-off-by: Liu, Yi L --- hw/vfio/pci.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 5b77c7e..3ed521e 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2637,6 +2637,14 @@ static void vfio_unregister_req_notifier(VFIOPCIDevi= ce *vdev) vdev->req_enabled =3D false; } =20 +static void vfio_iommu_bind_pasidtbl_notify(IOMMUNotifier *n, + IOMMUEventData *event_data) +{ +/* Sample code, would be detailed in coming virt-SVM patchset. + VFIOGuestIOMMUObject *giommu =3D container_of(n, VFIOGuestIOMMUObject,= n); + VFIOContainer *container =3D giommu->container; +*/ +} static void vfio_realize(PCIDevice *pdev, Error **errp) { VFIOPCIDevice *vdev =3D DO_UPCAST(VFIOPCIDevice, pdev, pdev); @@ -2889,6 +2897,12 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) QLIST_INSERT_HEAD(&group->container->giommu_object_list, giommu, giommu_next); + /* Register vfio_iommu_bind_pasidtbl_notify with event flag + IOMMU_EVENT_BIND_PASIDT */ + iommu_notifier_register(iommu, + &giommu->n, + vfio_iommu_bind_pasidtbl_notify, + IOMMU_EVENT_BIND_PASIDT); } =20 return; --=20 1.9.1