[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GIT PULL 13/18] memory: Clarify mapping requirements for RamDiscardMana
From: |
David Hildenbrand |
Subject: |
[GIT PULL 13/18] memory: Clarify mapping requirements for RamDiscardManager |
Date: |
Thu, 12 Oct 2023 16:36:50 +0200 |
We really only care about the RAM memory region not being mapped into
an address space yet as long as we're still setting up the
RamDiscardManager. Once mapped into an address space, memory notifiers
would get notified about such a region and any attempts to modify the
RamDiscardManager would be wrong.
While "mapped into an address space" is easy to check for RAM regions that
are mapped directly (following the ->container links), it's harder to
check when such regions are mapped indirectly via aliases. For now, we can
only detect that a region is mapped through an alias (->mapped_via_alias),
but we don't have a handle on these aliases to follow all their ->container
links to test if they are eventually mapped into an address space.
So relax the assertion in memory_region_set_ram_discard_manager(),
remove the check in memory_region_get_ram_discard_manager() and clarify
the doc.
Message-ID: <20230926185738.277351-14-david@redhat.com>
Reviewed-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/exec/memory.h | 5 +++--
system/memory.c | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index c99842d2fc..cf7c7dde91 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -599,8 +599,9 @@ typedef void (*ReplayRamDiscard)(MemoryRegionSection
*section, void *opaque);
* populated (consuming memory), to be used/accessed by the VM.
*
* A #RamDiscardManager can only be set for a RAM #MemoryRegion while the
- * #MemoryRegion isn't mapped yet; it cannot change while the #MemoryRegion is
- * mapped.
+ * #MemoryRegion isn't mapped into an address space yet (either directly
+ * or via an alias); it cannot change while the #MemoryRegion is
+ * mapped into an address space.
*
* The #RamDiscardManager is intended to be used by technologies that are
* incompatible with discarding of RAM (e.g., VFIO, which may pin all
diff --git a/system/memory.c b/system/memory.c
index fa1c99f9ba..e11bce5991 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -2085,7 +2085,7 @@ int memory_region_iommu_num_indexes(IOMMUMemoryRegion
*iommu_mr)
RamDiscardManager *memory_region_get_ram_discard_manager(MemoryRegion *mr)
{
- if (!memory_region_is_mapped(mr) || !memory_region_is_ram(mr)) {
+ if (!memory_region_is_ram(mr)) {
return NULL;
}
return mr->rdm;
@@ -2094,7 +2094,7 @@ RamDiscardManager
*memory_region_get_ram_discard_manager(MemoryRegion *mr)
void memory_region_set_ram_discard_manager(MemoryRegion *mr,
RamDiscardManager *rdm)
{
- g_assert(memory_region_is_ram(mr) && !memory_region_is_mapped(mr));
+ g_assert(memory_region_is_ram(mr));
g_assert(!rdm || !mr->rdm);
mr->rdm = rdm;
}
--
2.41.0
- [GIT PULL 02/18] vhost: Remove vhost_backend_can_merge() callback, (continued)
- [GIT PULL 02/18] vhost: Remove vhost_backend_can_merge() callback, David Hildenbrand, 2023/10/12
- [GIT PULL 01/18] vhost: Rework memslot filtering and fix "used_memslot" tracking, David Hildenbrand, 2023/10/12
- [GIT PULL 15/18] virtio-mem: Update state to match bitmap as soon as it's been migrated, David Hildenbrand, 2023/10/12
- [GIT PULL 14/18] virtio-mem: Pass non-const VirtIOMEM via virtio_mem_range_cb, David Hildenbrand, 2023/10/12
- [GIT PULL 04/18] kvm: Return number of free memslots, David Hildenbrand, 2023/10/12
- [GIT PULL 18/18] virtio-mem: Mark memslot alias memory regions unmergeable, David Hildenbrand, 2023/10/12
- [GIT PULL 17/18] memory, vhost: Allow for marking memory device memory regions unmergeable, David Hildenbrand, 2023/10/12
- [GIT PULL 16/18] virtio-mem: Expose device memory dynamically via multiple memslots if enabled, David Hildenbrand, 2023/10/12
- [GIT PULL 10/18] kvm: Add stub for kvm_get_max_memslots(), David Hildenbrand, 2023/10/12
- [GIT PULL 12/18] memory-device, vhost: Support automatic decision on the number of memslots, David Hildenbrand, 2023/10/12
- [GIT PULL 13/18] memory: Clarify mapping requirements for RamDiscardManager,
David Hildenbrand <=
- Re: [GIT PULL 00/18] Host Memory Backends and Memory devices queue 2023-10-12, Stefan Hajnoczi, 2023/10/16