From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com,
vkaplans@redhat.com, alex.williamson@redhat.com, wexu@redhat.com,
cornelia.huck@de.ibm.com, dgibson@redhat.com
Subject: Re: [Qemu-devel] [PATCH 2/3] memory: add iommu_notify_flag
Date: Mon, 5 Sep 2016 11:56:12 +0200 [thread overview]
Message-ID: <dcb70f94-76da-da93-8c6a-38b1e40fa479@redhat.com> (raw)
In-Reply-To: <20160905083804.GB7761@pxdev.xzpeter.org>
On 05/09/2016 10:38, Peter Xu wrote:
> However in this patch I was not meant to do that. I made it an
> exclusive flag to identify two different use cases. I don't know
> whether this is good, but at least for Intel IOMMU's current use case,
> these two types should be totally isolated from each other:
>
> - IOMMU_NONE notification is used by future DMAR-enabled vhost, it
> should only be notified with device-IOTLB invalidations, this will
> only require "Device IOTLB" capability for Intel IOMMUs, and be
> notified in Device IOTLB invalidation handlers.
>
> - IOMMU_RW notifications should only be used for vfio-pci, notified
> with IOTLB invalidations. This will only require Cache Mode (CM=1)
> capability, and will be notified in common IOTLB invalidations (no
> matter whether it's an cache invalidation or not, we will all use
> IOMMU_RW flag for this kind of notifies).
>
> Maybe here naming the flags as IOMMU_{RW_NONE} is a little bit
> confusing (just to leverage existing access flags),
Yeah, if you really want to have these semantics, you need to define an
enum like this:
IOMMU_NOTIFIER_NONE = -1,
IOMMU_NOTIFIER_FLUSH = 0,
IOMMU_NOTIFIER_CHANGED_ENTRY = 1,
But I'm still not convinced of the exclusivity between "flush" and
"entry changed" notifiers. If I saw the above, my first reaction would
be that you need a bit mask:
IOMMU_NOTIFIER_NONE = -1,
IOMMU_NOTIFIER_FLUSH = 1,
IOMMU_NOTIFIER_CHANGED_ENTRY = 2,
But perhaps what you're looking for is to change the "notifier" to a
"listener" like
struct IOMMUListener {
void (*flush)(IOMMUListener *);
void (*entry_changed)(IOMMUListener *, IOMMUTLBEntry *);
QLIST_ENTRY(IOMMUListener) node;
};
The patches can start with an IOMMUListener that only has the
entry_changed callback and that replaces the current use of Notifier.
Then notify_started and notify_stopped can be called on every notifier
that is added/removed (see attached prototype), and the Intel IOMMU can
simply reject registration of a listener that has a non-NULL
iotlb_changed member.
Thanks,
Paolo
diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index 6bc4d4d..d8cbd90 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_listener_add(MemoryRegion *iommu, IOMMUListener *l)
{
- spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), true);
+ sPAPRTCETable *tcet = container_of(iommu, sPAPRTCETable, iommu);
+ if (tcet->users++ == 0) {
+ spapr_tce_set_need_vfio(tcet, true);
+ }
}
-static void spapr_tce_notify_stopped(MemoryRegion *iommu)
+static void spapr_tce_listener_del(MemoryRegion *iommu, IOMMUListener *l)
{
- spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), false);
+ sPAPRTCETable *tcet = container_of(iommu, sPAPRTCETable, iommu);
+ if (--tcet->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,
+ .listener_add = spapr_tce_listener_add,
+ .listener_del = spapr_tce_listener_del,
};
static int spapr_tce_table_realize(DeviceState *dev)
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index caf7be9..4761afd 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -558,6 +558,7 @@ struct sPAPRTCETable {
uint64_t *table;
uint32_t mig_nb_table;
uint64_t *mig_table;
+ int users;
bool bypass;
bool need_vfio;
int fd;
diff --git a/memory.c b/memory.c
index 0eb6895..e9f50af 100644
--- a/memory.c
+++ b/memory.c
@@ -1515,9 +1515,8 @@ bool memory_region_is_logging(MemoryRegion *mr, uint8_t client)
void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n)
{
- if (mr->iommu_ops->notify_started &&
- QLIST_EMPTY(&mr->iommu_notify.notifiers)) {
- mr->iommu_ops->notify_started(mr);
+ if (mr->iommu_ops->listener_add) {
+ mr->iommu_ops->listener_add(mr, ...);
}
notifier_list_add(&mr->iommu_notify, n);
}
@@ -1555,9 +1554,8 @@ void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, bool is_write)
void memory_region_unregister_iommu_notifier(MemoryRegion *mr, Notifier *n)
{
notifier_remove(n);
- if (mr->iommu_ops->notify_stopped &&
- QLIST_EMPTY(&mr->iommu_notify.notifiers)) {
- mr->iommu_ops->notify_stopped(mr);
+ if (mr->iommu_ops->listener_del) {
+ mr->iommu_ops->listener_del(mr, ...);
}
}
next prev parent reply other threads:[~2016-09-05 9:56 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-05 7:21 [Qemu-devel] [PATCH 0/3] memory: add IOMMU notifier type Peter Xu
2016-09-05 7:21 ` [Qemu-devel] [PATCH 1/3] memory: add one flag for IOMMU notifier Peter Xu
2016-09-05 7:21 ` [Qemu-devel] [PATCH 2/3] memory: add iommu_notify_flag Peter Xu
2016-09-05 8:04 ` Paolo Bonzini
2016-09-05 8:38 ` Peter Xu
2016-09-05 9:56 ` Paolo Bonzini [this message]
2016-09-06 5:27 ` Peter Xu
2016-09-06 7:51 ` Paolo Bonzini
2016-09-06 8:17 ` Peter Xu
2016-09-06 8:19 ` Paolo Bonzini
2016-09-06 10:31 ` Peter Xu
2016-09-07 5:44 ` David Gibson
2016-09-07 6:34 ` Peter Xu
2016-09-07 6:41 ` David Gibson
2016-09-08 9:07 ` Peter Xu
2016-09-12 1:26 ` David Gibson
2016-09-12 5:13 ` Peter Xu
2016-09-14 4:00 ` David Gibson
2016-09-14 5:43 ` Peter Xu
2016-09-06 5:18 ` David Gibson
2016-09-06 5:55 ` Peter Xu
2016-09-06 5:12 ` David Gibson
2016-09-06 5:33 ` Peter Xu
2016-09-05 7:21 ` [Qemu-devel] [PATCH 3/3] intel_iommu: allow IOMMU_NONE typed notifiers Peter Xu
2016-09-06 5:06 ` [Qemu-devel] [PATCH 0/3] memory: add IOMMU notifier type David Gibson
2016-09-06 5:49 ` Peter Xu
2016-09-06 6:26 ` Jason Wang
2016-09-07 4:38 ` David Gibson
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=dcb70f94-76da-da93-8c6a-38b1e40fa479@redhat.com \
--to=pbonzini@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=peterx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.