From: Steve Sistare <steven.sistare@oracle.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Alex Williamson" <alex.williamson@redhat.com>,
"Steve Sistare" <steven.sistare@oracle.com>
Subject: [PATCH V2 11/20] memory: flat section iterator
Date: Tue, 7 Feb 2023 10:51:27 -0800 [thread overview]
Message-ID: <1675795887-235277-1-git-send-email-steven.sistare@oracle.com> (raw)
Add an iterator over the sections of a flattened address space.
This will be needed by cpr to issue vfio ioctl's on the same memory
ranges that are already programmed.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/exec/memory.h | 31 +++++++++++++++++++++++++++++++
softmmu/memory.c | 21 +++++++++++++++++++++
2 files changed, 52 insertions(+)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 3224e09..b6ca3f5 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2376,6 +2376,37 @@ void memory_region_set_ram_discard_manager(MemoryRegion *mr,
RamDiscardManager *rdm);
/**
+ * memory_region_section_cb: callback for address_space_flat_for_each_section()
+ *
+ * @mrs: MemoryRegionSection of the range
+ * @opaque: data pointer passed to address_space_flat_for_each_section()
+ * @errp: error message, returned to the address_space_flat_for_each_section
+ * caller.
+ *
+ * Returns: non-zero to stop the iteration, and 0 to continue. The same
+ * non-zero value is returned to the address_space_flat_for_each_section caller.
+ */
+
+typedef int (*memory_region_section_cb)(MemoryRegionSection *mrs,
+ void *opaque,
+ Error **errp);
+
+/**
+ * address_space_flat_for_each_section: walk the ranges in the address space
+ * flat view and call @func for each. Return 0 on success, else return non-zero
+ * with a message in @errp.
+ *
+ * @as: target address space
+ * @func: callback function
+ * @opaque: passed to @func
+ * @errp: passed to @func
+ */
+int address_space_flat_for_each_section(AddressSpace *as,
+ memory_region_section_cb func,
+ void *opaque,
+ Error **errp);
+
+/**
* memory_region_find: translate an address/size relative to a
* MemoryRegion into a #MemoryRegionSection.
*
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 9d64efc..57c3131 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -2748,6 +2748,27 @@ bool memory_region_is_mapped(MemoryRegion *mr)
return !!mr->container || mr->mapped_via_alias;
}
+int address_space_flat_for_each_section(AddressSpace *as,
+ memory_region_section_cb func,
+ void *opaque,
+ Error **errp)
+{
+ FlatView *view = address_space_get_flatview(as);
+ FlatRange *fr;
+ int ret;
+
+ FOR_EACH_FLAT_RANGE(fr, view) {
+ MemoryRegionSection mrs = section_from_flat_range(fr, view);
+ ret = func(&mrs, opaque, errp);
+ if (ret) {
+ return ret;
+ }
+ }
+
+ flatview_unref(view);
+ return 0;
+}
+
/* Same as memory_region_find, but it does not add a reference to the
* returned region. It must be called from an RCU critical section.
*/
--
1.8.3.1
reply other threads:[~2023-02-07 18:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1675795887-235277-1-git-send-email-steven.sistare@oracle.com \
--to=steven.sistare@oracle.com \
--cc=alex.williamson@redhat.com \
--cc=david@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).