Let's factor out adding a MemoryRegionSection to the list, to be reused in
RamDiscardManager context next.
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Eduardo Habkost <ehabkost@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>
Cc: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
softmmu/memory_mapping.c | 41 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/softmmu/memory_mapping.c b/softmmu/memory_mapping.c
index c149bad44a..b7e4f3f788 100644
--- a/softmmu/memory_mapping.c
+++ b/softmmu/memory_mapping.c
@@ -193,29 +193,14 @@ typedef struct GuestPhysListener {
MemoryListener listener;
} GuestPhysListener;
-static void guest_phys_blocks_region_add(MemoryListener *listener,
+static void guest_phys_block_add_section(GuestPhysListener *g,
MemoryRegionSection *section)
{
- 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;
+ const hwaddr target_start = section->offset_within_address_space;
+ const hwaddr target_end = target_start + int128_get64(section->size);
+ uint8_t *host_addr = memory_region_get_ram_ptr(section->mr) +
+ section->offset_within_region;
+ GuestPhysBlock *predecessor = NULL;
/* find continuity in guest physical address space */
if (!QTAILQ_EMPTY(&g->list->head)) {
@@ -261,6 +246,20 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,
#endif
}
+static void guest_phys_blocks_region_add(MemoryListener *listener,
+ MemoryRegionSection *section)
+{
+ GuestPhysListener *g = container_of(listener, GuestPhysListener, listener);
+
+ /* 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;
+ }
+ guest_phys_block_add_section(g, section);
+}
+
void guest_phys_blocks_append(GuestPhysBlockList *list)
{
GuestPhysListener g = { 0 };
--
2.31.1
On 7/20/21 9:03 AM, David Hildenbrand wrote:
> Let's factor out adding a MemoryRegionSection to the list, to be reused in
> RamDiscardManager context next.
>
> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Eduardo Habkost <ehabkost@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>
> Cc: Stefan Berger <stefanb@linux.ibm.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> softmmu/memory_mapping.c | 41 ++++++++++++++++++++--------------------
> 1 file changed, 20 insertions(+), 21 deletions(-)
>
> diff --git a/softmmu/memory_mapping.c b/softmmu/memory_mapping.c
> index c149bad44a..b7e4f3f788 100644
> --- a/softmmu/memory_mapping.c
> +++ b/softmmu/memory_mapping.c
> @@ -193,29 +193,14 @@ typedef struct GuestPhysListener {
> MemoryListener listener;
> } GuestPhysListener;
>
> -static void guest_phys_blocks_region_add(MemoryListener *listener,
> +static void guest_phys_block_add_section(GuestPhysListener *g,
> MemoryRegionSection *section)
> {
> - 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;
> + const hwaddr target_start = section->offset_within_address_space;
> + const hwaddr target_end = target_start + int128_get64(section->size);
> + uint8_t *host_addr = memory_region_get_ram_ptr(section->mr) +
> + section->offset_within_region;
> + GuestPhysBlock *predecessor = NULL;
>
> /* find continuity in guest physical address space */
> if (!QTAILQ_EMPTY(&g->list->head)) {
> @@ -261,6 +246,20 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,
> #endif
> }
>
> +static void guest_phys_blocks_region_add(MemoryListener *listener,
> + MemoryRegionSection *section)
> +{
> + GuestPhysListener *g = container_of(listener, GuestPhysListener, listener);
> +
> + /* 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;
> + }
> + guest_phys_block_add_section(g, section);
> +}
> +
> void guest_phys_blocks_append(GuestPhysBlockList *list)
> {
> GuestPhysListener g = { 0 };
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
© 2016 - 2026 Red Hat, Inc.