From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: dgibson@redhat.com, jasowang@redhat.com, mst@redhat.com,
pbonzini@redhat.com, cornelia.huck@de.ibm.com, wexu@redhat.com,
vkaplans@redhat.com, alex.williamson@redhat.com,
peterx@redhat.com
Subject: [Qemu-devel] [PATCH v2 2/3] memory: generalize iommu_ops.notify_started to notifier_add
Date: Tue, 6 Sep 2016 21:24:26 +0800 [thread overview]
Message-ID: <1473168267-25673-3-git-send-email-peterx@redhat.com> (raw)
In-Reply-To: <1473168267-25673-1-git-send-email-peterx@redhat.com>
Considering that we may have multiple IOMMU notifier consumers in the
future, converting iommu_ops.notify_{started|stopped} into some more
general form. Now we can trap all notifier registerations and
deregistrations, rather than only the first ones.
Power was leveraging the notifier_{started|stopped}, adding iommu_user
field for counting on Power guests to achieve the same goal.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
hw/i386/intel_iommu.c | 4 ++--
hw/ppc/spapr_iommu.c | 18 ++++++++++++------
include/exec/memory.h | 8 ++++----
include/hw/ppc/spapr.h | 1 +
memory.c | 10 ++++------
5 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 28c31a2..c6bd8f6 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -1974,7 +1974,7 @@ static IOMMUTLBEntry vtd_iommu_translate(MemoryRegion *iommu, hwaddr addr,
return ret;
}
-static void vtd_iommu_notify_started(MemoryRegion *iommu)
+static void vtd_iommu_notifier_add(MemoryRegion *iommu, IOMMUNotifier *n)
{
VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu);
@@ -2348,7 +2348,7 @@ static void vtd_init(IntelIOMMUState *s)
memset(s->womask, 0, DMAR_REG_SIZE);
s->iommu_ops.translate = vtd_iommu_translate;
- s->iommu_ops.notify_started = vtd_iommu_notify_started;
+ s->iommu_ops.notifier_add = vtd_iommu_notifier_add;
s->root = 0;
s->root_extended = false;
s->dmar_enabled = false;
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index 6bc4d4d..84421e0 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -156,14 +156,20 @@ 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_notifier_add(MemoryRegion *iommu, IOMMUNotifier *n)
{
- spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), true);
+ sPAPRTCETable *tcet = container_of(iommu, sPAPRTCETable, iommu);
+ if (tcet->iommu_users++ == 0) {
+ spapr_tce_set_need_vfio(tcet, true);
+ }
}
-static void spapr_tce_notify_stopped(MemoryRegion *iommu)
+static void spapr_tce_notifier_del(MemoryRegion *iommu)
{
- spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), false);
+ sPAPRTCETable *tcet = container_of(iommu, sPAPRTCETable, iommu);
+ if (--tcet->iommu_users == 0) {
+ spapr_tce_set_need_vfio(tcet, false);
+ }
}
static int spapr_tce_table_post_load(void *opaque, int version_id)
@@ -246,8 +252,8 @@ static const VMStateDescription vmstate_spapr_tce_table = {
static MemoryRegionIOMMUOps spapr_iommu_ops = {
.translate = spapr_tce_translate_iommu,
.get_min_page_size = spapr_tce_get_min_page_size,
- .notify_started = spapr_tce_notify_started,
- .notify_stopped = spapr_tce_notify_stopped,
+ .notifier_add = spapr_tce_notifier_add,
+ .notifier_del = spapr_tce_notifier_del,
};
static int spapr_tce_table_realize(DeviceState *dev)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 52914c1..3a2e7d8 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -174,10 +174,10 @@ struct MemoryRegionIOMMUOps {
IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write);
/* 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);
- /* Called when the last notifier is removed */
- void (*notify_stopped)(MemoryRegion *iommu);
+ /* Called when someone registers to the notify list */
+ void (*notifier_add)(MemoryRegion *iommu, IOMMUNotifier *n);
+ /* Called when someone unregisters from the notify list */
+ void (*notifier_del)(MemoryRegion *iommu, IOMMUNotifier *n);
};
typedef struct CoalescedMemoryRange CoalescedMemoryRange;
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index caf7be9..08627ec 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -564,6 +564,7 @@ struct sPAPRTCETable {
MemoryRegion root, iommu;
struct VIOsPAPRDevice *vdev; /* for @bypass migration compatibility only */
QLIST_ENTRY(sPAPRTCETable) list;
+ int iommu_users;
};
sPAPRTCETable *spapr_tce_find_by_liobn(target_ulong liobn);
diff --git a/memory.c b/memory.c
index f513c5a..a50e627 100644
--- a/memory.c
+++ b/memory.c
@@ -1518,9 +1518,8 @@ void memory_region_register_iommu_notifier(MemoryRegion *mr,
{
/* We need to register for at least one bitfield */
assert(n->notifier_caps != IOMMU_NOTIFIER_NONE);
- if (mr->iommu_ops->notify_started &&
- QLIST_EMPTY(&mr->iommu_notify.notifiers)) {
- mr->iommu_ops->notify_started(mr);
+ if (mr->iommu_ops->notifier_add) {
+ mr->iommu_ops->notifier_add(mr, n);
}
notifier_list_add(&mr->iommu_notify, &n->notifier);
}
@@ -1560,9 +1559,8 @@ void memory_region_unregister_iommu_notifier(MemoryRegion *mr,
IOMMUNotifier *n)
{
notifier_remove(&n->notifier);
- if (mr->iommu_ops->notify_stopped &&
- QLIST_EMPTY(&mr->iommu_notify.notifiers)) {
- mr->iommu_ops->notify_stopped(mr);
+ if (mr->iommu_ops->notifier_del) {
+ mr->iommu_ops->notifier_del(mr, n);
}
}
--
2.7.4
next prev parent reply other threads:[~2016-09-06 13:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-06 13:24 [Qemu-devel] [PATCH v2 0/3] Introduce IOMMUNotifier struct Peter Xu
2016-09-06 13:24 ` [Qemu-devel] [PATCH v2 1/3] memory: introduce IOMMUNotifier and its caps Peter Xu
2016-09-06 14:29 ` Paolo Bonzini
2016-09-07 4:55 ` Peter Xu
2016-09-06 13:24 ` Peter Xu [this message]
2016-09-06 13:24 ` [Qemu-devel] [PATCH v2 3/3] intel_iommu: allow invalidation typed notifiers Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1473168267-25673-3-git-send-email-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=cornelia.huck@de.ibm.com \
--cc=dgibson@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vkaplans@redhat.com \
--cc=wexu@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).