diff mbox series

[RFC,3/4] memory: add interface for triggering IOMMU notify_flag_changed handler

Message ID 20230424112147.17083-4-viktor@daynix.com
State New
Headers show
Series [RFC,1/4] pci: add handling of Enable bit in ATS Control Register | expand

Commit Message

Viktor Prutyanov April 24, 2023, 11:21 a.m. UTC
This interface helps if IOMMU notify_flag_changed should be triggered
after changing IOMMU notifier flags in the runtime.

Signed-off-by: Viktor Prutyanov <viktor@daynix.com>
---
 include/exec/memory.h |  2 ++
 softmmu/memory.c      | 12 ++++++++++++
 2 files changed, 14 insertions(+)

Comments

Peter Xu April 26, 2023, 2:20 p.m. UTC | #1
On Mon, Apr 24, 2023 at 02:21:46PM +0300, Viktor Prutyanov wrote:
> +void memory_region_iommu_notify_flags_changed(MemoryRegion *mr)
> +{
> +    IOMMUMemoryRegion *iommu_mr;
> +
> +    if (mr->alias) {
> +        memory_region_iommu_notify_flags_changed(mr->alias);
> +        return;
> +    }
> +    iommu_mr = IOMMU_MEMORY_REGION(mr);
> +    memory_region_update_iommu_notify_flags(iommu_mr, NULL);

Do we still want to trap the error if the update failed?

The other question: whether vhost can simply use the existing register /
unregister calls for iommu notifiers, rather than modifying the flags on
its own?  I'd assume this happens very rare anyway.  Or is there other
concerns?
diff mbox series

Patch

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 2e602a2fad..c8d5f69add 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1772,6 +1772,8 @@  void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n);
 void memory_region_unregister_iommu_notifier(MemoryRegion *mr,
                                              IOMMUNotifier *n);
 
+void memory_region_iommu_notify_flags_changed(MemoryRegion *mr);
+
 /**
  * memory_region_iommu_get_attr: return an IOMMU attr if get_attr() is
  * defined on the IOMMU.
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 9d64efca26..e4a53cde6c 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1950,6 +1950,18 @@  void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
     }
 }
 
+void memory_region_iommu_notify_flags_changed(MemoryRegion *mr)
+{
+    IOMMUMemoryRegion *iommu_mr;
+
+    if (mr->alias) {
+        memory_region_iommu_notify_flags_changed(mr->alias);
+        return;
+    }
+    iommu_mr = IOMMU_MEMORY_REGION(mr);
+    memory_region_update_iommu_notify_flags(iommu_mr, NULL);
+}
+
 void memory_region_unregister_iommu_notifier(MemoryRegion *mr,
                                              IOMMUNotifier *n)
 {