Skip to content

Commit

Permalink
memory: Clarify mapping requirements for RamDiscardManager
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
davidhildenbrand committed Oct 12, 2023
1 parent a233511 commit aa5317e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions include/exec/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions system/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit aa5317e

Please sign in to comment.