Patchwork [21/30] memory: Add iommu map/unmap notifiers

login
register
mail settings
Submitter Paolo Bonzini
Date May 21, 2013, 10:57 a.m.
Message ID <1369133851-1894-22-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/245281/
State New
Headers show

Comments

Paolo Bonzini - May 21, 2013, 10:57 a.m.
From: David Gibson <david@gibson.dropbear.id.au>

This patch adds a NotifierList to MemoryRegions which represent IOMMUs
allowing other parts of the code to register interest in mappings or
unmappings from the IOMMU.  All IOMMU implementations will need to call
memory_region_notify_iommu() to inform those waiting on the notifier list,
whenever an IOMMU mapping is made or removed.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 include/exec/memory.h |  7 +++++++
 memory.c              | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+)
Peter Maydell - May 23, 2013, 6:27 p.m.
On 21 May 2013 11:57, Paolo Bonzini <pbonzini@redhat.com> wrote:
> From: David Gibson <david@gibson.dropbear.id.au>
>
> This patch adds a NotifierList to MemoryRegions which represent IOMMUs
> allowing other parts of the code to register interest in mappings or
> unmappings from the IOMMU.  All IOMMU implementations will need to call
> memory_region_notify_iommu() to inform those waiting on the notifier list,
> whenever an IOMMU mapping is made or removed.
>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> @@ -423,6 +425,11 @@ static inline bool memory_region_is_romd(MemoryRegion *mr)
>   */
>  bool memory_region_is_iommu(MemoryRegion *mr);
>
> +void memory_region_notify_iommu(MemoryRegion *mr,
> +                                IOMMUTLBEntry entry);
> +void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n);
> +void memory_region_unregister_iommu_notifier(Notifier *n);

These all need doc comments.

The code looks good.

thanks
-- PMM
Paolo Bonzini - May 23, 2013, 7:24 p.m.
Il 23/05/2013 20:27, Peter Maydell ha scritto:
> On 21 May 2013 11:57, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> From: David Gibson <david@gibson.dropbear.id.au>
>>
>> This patch adds a NotifierList to MemoryRegions which represent IOMMUs
>> allowing other parts of the code to register interest in mappings or
>> unmappings from the IOMMU.  All IOMMU implementations will need to call
>> memory_region_notify_iommu() to inform those waiting on the notifier list,
>> whenever an IOMMU mapping is made or removed.
>>
>> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
>> @@ -423,6 +425,11 @@ static inline bool memory_region_is_romd(MemoryRegion *mr)
>>   */
>>  bool memory_region_is_iommu(MemoryRegion *mr);
>>
>> +void memory_region_notify_iommu(MemoryRegion *mr,
>> +                                IOMMUTLBEntry entry);
>> +void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n);
>> +void memory_region_unregister_iommu_notifier(Notifier *n);
> 
> These all need doc comments.

David, can you provide them?  (If not as a patch, just an inline reply
to this email will do).

Paolo
David Gibson - May 29, 2013, 4:08 a.m.
On Thu, May 23, 2013 at 09:24:30PM +0200, Paolo Bonzini wrote:
> Il 23/05/2013 20:27, Peter Maydell ha scritto:
> > On 21 May 2013 11:57, Paolo Bonzini <pbonzini@redhat.com> wrote:
> >> From: David Gibson <david@gibson.dropbear.id.au>
> >>
> >> This patch adds a NotifierList to MemoryRegions which represent IOMMUs
> >> allowing other parts of the code to register interest in mappings or
> >> unmappings from the IOMMU.  All IOMMU implementations will need to call
> >> memory_region_notify_iommu() to inform those waiting on the notifier list,
> >> whenever an IOMMU mapping is made or removed.
> >>
> >> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> >> @@ -423,6 +425,11 @@ static inline bool memory_region_is_romd(MemoryRegion *mr)
> >>   */
> >>  bool memory_region_is_iommu(MemoryRegion *mr);
> >>
> >> +void memory_region_notify_iommu(MemoryRegion *mr,
> >> +                                IOMMUTLBEntry entry);
> >> +void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n);
> >> +void memory_region_unregister_iommu_notifier(Notifier *n);
> > 
> > These all need doc comments.
> 
> David, can you provide them?  (If not as a patch, just an inline reply
> to this email will do).

I'll see what I can do.  Working on this is no longer my day job, so
it may be a little while...

Patch

diff --git a/include/exec/memory.h b/include/exec/memory.h
index e5cad03..05b9bb2 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -25,6 +25,7 @@ 
 #include "exec/iorange.h"
 #include "exec/ioport.h"
 #include "qemu/int128.h"
+#include "qemu/notify.h"
 
 #define MAX_PHYS_ADDR_SPACE_BITS 62
 #define MAX_PHYS_ADDR            (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
@@ -172,6 +173,7 @@  struct MemoryRegion {
     unsigned ioeventfd_nb;
     MemoryRegionIoeventfd *ioeventfds;
     struct AddressSpace *iommu_target_as;
+    NotifierList iommu_notify;
 };
 
 struct MemoryRegionPortio {
@@ -423,6 +425,11 @@  static inline bool memory_region_is_romd(MemoryRegion *mr)
  */
 bool memory_region_is_iommu(MemoryRegion *mr);
 
+void memory_region_notify_iommu(MemoryRegion *mr,
+                                IOMMUTLBEntry entry);
+void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n);
+void memory_region_unregister_iommu_notifier(Notifier *n);
+
 /**
  * memory_region_name: get a memory region's name
  *
diff --git a/memory.c b/memory.c
index b25d21d..e3970bf 100644
--- a/memory.c
+++ b/memory.c
@@ -991,6 +991,7 @@  void memory_region_init_iommu(MemoryRegion *mr,
     mr->terminates = true;  /* then re-forwards */
     mr->destructor = memory_region_destructor_none;
     mr->iommu_target_as = target_as;
+    notifier_list_init(&mr->iommu_notify);
 }
 
 static uint64_t invalid_read(void *opaque, hwaddr addr,
@@ -1072,6 +1073,23 @@  bool memory_region_is_iommu(MemoryRegion *mr)
     return mr->iommu_ops;
 }
 
+void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n)
+{
+    notifier_list_add(&mr->iommu_notify, n);
+}
+
+void memory_region_unregister_iommu_notifier(Notifier *n)
+{
+    notifier_remove(n);
+}
+
+void memory_region_notify_iommu(MemoryRegion *mr,
+                                IOMMUTLBEntry entry)
+{
+    assert(memory_region_is_iommu(mr));
+    notifier_list_notify(&mr->iommu_notify, &entry);
+}
+
 void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client)
 {
     uint8_t mask = 1 << client;