From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Laurent Vivier" <lvivier@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"David Hildenbrand" <david@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"Alex Williamson" <alex.williamson@redhat.com>,
"Claudio Fontana" <cfontana@suse.de>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Igor Mammedov" <imammedo@redhat.com>
Subject: [PATCH v1 4/5] softmmu/memory_mapping: factor out adding physical memory ranges
Date: Wed, 10 Feb 2021 18:15:36 +0100 [thread overview]
Message-ID: <20210210171537.32932-5-david@redhat.com> (raw)
In-Reply-To: <20210210171537.32932-1-david@redhat.com>
Let's factor out adding an item to the list, to be reused in
RamDiscardMgr context next.
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Claudio Fontana <cfontana@suse.de>
Cc: Thomas Huth <thuth@redhat.com>
Cc: "Alex Bennée" <alex.bennee@linaro.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
softmmu/memory_mapping.c | 64 +++++++++++++++++++++-------------------
1 file changed, 34 insertions(+), 30 deletions(-)
diff --git a/softmmu/memory_mapping.c b/softmmu/memory_mapping.c
index ad4911427a..05e8270edc 100644
--- a/softmmu/memory_mapping.c
+++ b/softmmu/memory_mapping.c
@@ -194,35 +194,17 @@ typedef struct GuestPhysListener {
MemoryListener listener;
} GuestPhysListener;
-static void guest_phys_blocks_region_add(MemoryListener *listener,
- MemoryRegionSection *section)
+static void guest_phys_block_add(GuestPhysBlockList *list, MemoryRegion *mr,
+ hwaddr target_start, hwaddr target_end,
+ uint8_t *host_addr)
{
- GuestPhysListener *g;
- uint64_t section_size;
- hwaddr target_start, target_end;
- uint8_t *host_addr;
- GuestPhysBlock *predecessor;
-
- /* we only care about RAM */
- if (!memory_region_is_ram(section->mr) ||
- memory_region_is_ram_device(section->mr) ||
- memory_region_is_nonvolatile(section->mr)) {
- return;
- }
-
- g = container_of(listener, GuestPhysListener, listener);
- section_size = int128_get64(section->size);
- target_start = section->offset_within_address_space;
- target_end = target_start + section_size;
- host_addr = memory_region_get_ram_ptr(section->mr) +
- section->offset_within_region;
- predecessor = NULL;
+ GuestPhysBlock *predecessor = NULL;
/* find continuity in guest physical address space */
- if (!QTAILQ_EMPTY(&g->list->head)) {
+ if (!QTAILQ_EMPTY(&list->head)) {
hwaddr predecessor_size;
- predecessor = QTAILQ_LAST(&g->list->head);
+ predecessor = QTAILQ_LAST(&list->head);
predecessor_size = predecessor->target_end - predecessor->target_start;
/* the memory API guarantees monotonically increasing traversal */
@@ -231,7 +213,7 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,
/* we want continuity in both guest-physical and host-virtual memory */
if (predecessor->target_end < target_start ||
predecessor->host_addr + predecessor_size != host_addr ||
- predecessor->mr != section->mr) {
+ predecessor->mr != mr) {
predecessor = NULL;
}
}
@@ -243,11 +225,11 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,
block->target_start = target_start;
block->target_end = target_end;
block->host_addr = host_addr;
- block->mr = section->mr;
- memory_region_ref(section->mr);
+ block->mr = mr;
+ memory_region_ref(mr);
- QTAILQ_INSERT_TAIL(&g->list->head, block, next);
- ++g->list->num;
+ QTAILQ_INSERT_TAIL(&list->head, block, next);
+ ++list->num;
} else {
/* expand predecessor until @target_end; predecessor's start doesn't
* change
@@ -258,10 +240,32 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,
#ifdef DEBUG_GUEST_PHYS_REGION_ADD
fprintf(stderr, "%s: target_start=" TARGET_FMT_plx " target_end="
TARGET_FMT_plx ": %s (count: %u)\n", __func__, target_start,
- target_end, predecessor ? "joined" : "added", g->list->num);
+ target_end, predecessor ? "joined" : "added", list->num);
#endif
}
+static void guest_phys_blocks_region_add(MemoryListener *listener,
+ MemoryRegionSection *section)
+{
+ GuestPhysListener *g = container_of(listener, GuestPhysListener, listener);
+ hwaddr target_start, target_end;
+ uint8_t *host_addr;
+
+ /* we only care about RAM */
+ if (!memory_region_is_ram(section->mr) ||
+ memory_region_is_ram_device(section->mr) ||
+ memory_region_is_nonvolatile(section->mr)) {
+ return;
+ }
+
+ target_start = section->offset_within_address_space;
+ target_end = target_start + int128_get64(section->size);
+ host_addr = memory_region_get_ram_ptr(section->mr) +
+ section->offset_within_region;
+ guest_phys_block_add(g->list, section->mr, target_start, target_end,
+ host_addr);
+}
+
void guest_phys_blocks_append(GuestPhysBlockList *list)
{
GuestPhysListener g = { 0 };
--
2.29.2
next prev parent reply other threads:[~2021-02-10 17:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-10 17:15 [PATCH v1 0/5] softmmu/memory_mapping: optimize dump/tpm for virtio-mem David Hildenbrand
2021-02-10 17:15 ` [PATCH v1 1/5] tpm: mark correct memory region range dirty when clearing RAM David Hildenbrand
2021-02-14 0:38 ` Stefan Berger
2021-02-10 17:15 ` [PATCH v1 2/5] softmmu/memory_mapping: reuse qemu_get_guest_simple_memory_mapping() David Hildenbrand
2021-02-10 17:15 ` [PATCH v1 3/5] softmmu/memory_mapping: never merge ranges accross memory regions David Hildenbrand
2021-02-10 17:15 ` David Hildenbrand [this message]
2021-02-10 17:15 ` [PATCH v1 5/5] softmmu/memory_mapping: optimize for RamDiscardMgr sections David Hildenbrand
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=20210210171537.32932-5-david@redhat.com \
--to=david@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=alex.williamson@redhat.com \
--cc=cfontana@suse.de \
--cc=dgilbert@redhat.com \
--cc=imammedo@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@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).