All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: "David Hildenbrand" <david@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Xiao Guangrong" <xiaoguangrong.eric@gmail.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Michal Privoznik" <mprivozn@redhat.com>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Gavin Shan" <gshan@redhat.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Maciej S . Szmigiero" <mail@maciej.szmigiero.name>,
	kvm@vger.kernel.org
Subject: [PATCH v3 13/16] memory: Clarify mapping requirements for RamDiscardManager
Date: Fri,  8 Sep 2023 16:21:33 +0200	[thread overview]
Message-ID: <20230908142136.403541-14-david@redhat.com> (raw)
In-Reply-To: <20230908142136.403541-1-david@redhat.com>

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.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 include/exec/memory.h | 5 +++--
 softmmu/memory.c      | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 68284428f8..5feb704585 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -593,8 +593,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/softmmu/memory.c b/softmmu/memory.c
index 7d9494ce70..c1e8aa133f 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -2081,7 +2081,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;
@@ -2090,7 +2090,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


  parent reply	other threads:[~2023-09-08 14:23 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08 14:21 [PATCH v3 00/16] virtio-mem: Expose device memory through multiple memslots David Hildenbrand
2023-09-08 14:21 ` [PATCH v3 01/16] vhost: Rework memslot filtering and fix "used_memslot" tracking David Hildenbrand
2023-09-08 14:21 ` [PATCH v3 02/16] vhost: Remove vhost_backend_can_merge() callback David Hildenbrand
2023-09-08 14:21 ` [PATCH v3 03/16] softmmu/physmem: Fixup qemu_ram_block_from_host() documentation David Hildenbrand
2023-09-08 14:21 ` [PATCH v3 04/16] kvm: Return number of free memslots David Hildenbrand
2023-09-16 16:05   ` Maciej S. Szmigiero
2023-09-08 14:21 ` [PATCH v3 05/16] vhost: " David Hildenbrand
2023-09-16 16:07   ` Maciej S. Szmigiero
2023-09-08 14:21 ` [PATCH v3 06/16] memory-device: Support memory devices with multiple memslots David Hildenbrand
2023-09-16 16:27   ` Maciej S. Szmigiero
2023-09-08 14:21 ` [PATCH v3 07/16] stubs: Rename qmp_memory_device.c to memory_device.c David Hildenbrand
2023-09-16 16:28   ` Maciej S. Szmigiero
2023-09-08 14:21 ` [PATCH v3 08/16] memory-device: Track required and actually used memslots in DeviceMemoryState David Hildenbrand
2023-09-16 16:36   ` Maciej S. Szmigiero
2023-09-08 14:21 ` [PATCH v3 09/16] memory-device,vhost: Support memory devices that dynamically consume memslots David Hildenbrand
2023-09-08 14:21   ` [PATCH v3 09/16] memory-device, vhost: " David Hildenbrand
2023-09-16 17:52   ` Maciej S. Szmigiero
2023-09-16 17:52     ` [PATCH v3 09/16] memory-device,vhost: " Maciej S. Szmigiero
2023-09-08 14:21 ` [PATCH v3 10/16] kvm: Add stub for kvm_get_max_memslots() David Hildenbrand
2023-09-16 17:13   ` Maciej S. Szmigiero
2023-09-08 14:21 ` [PATCH v3 11/16] vhost: Add vhost_get_max_memslots() David Hildenbrand
2023-09-16 17:16   ` Maciej S. Szmigiero
2023-09-08 14:21 ` [PATCH v3 12/16] memory-device,vhost: Support automatic decision on the number of memslots David Hildenbrand
2023-09-08 14:21   ` [PATCH v3 12/16] memory-device, vhost: " David Hildenbrand
2023-09-17 10:46   ` [PATCH v3 12/16] memory-device,vhost: " Maciej S. Szmigiero
2023-09-17 10:46     ` [PATCH v3 12/16] memory-device, vhost: " Maciej S. Szmigiero
2023-09-18 12:33     ` David Hildenbrand
2023-09-18 12:33       ` [PATCH v3 12/16] memory-device,vhost: " David Hildenbrand
2023-09-08 14:21 ` David Hildenbrand [this message]
2023-09-16 17:31   ` [PATCH v3 13/16] memory: Clarify mapping requirements for RamDiscardManager Maciej S. Szmigiero
2023-09-08 14:21 ` [PATCH v3 14/16] virtio-mem: Expose device memory via multiple memslots if enabled David Hildenbrand
2023-09-17 11:47   ` Maciej S. Szmigiero
2023-09-19  8:08     ` David Hildenbrand
2023-09-08 14:21 ` [PATCH v3 15/16] memory,vhost: Allow for marking memory device memory regions unmergeable David Hildenbrand
2023-09-08 14:21   ` [PATCH v3 15/16] memory, vhost: " David Hildenbrand
2023-09-08 14:21 ` [PATCH v3 16/16] virtio-mem: Mark memslot alias " David Hildenbrand
2023-09-11  7:45 ` [PATCH v3 00/16] virtio-mem: Expose device memory through multiple memslots David Hildenbrand
2023-09-19  8:20   ` David Hildenbrand
2023-09-19  9:34     ` 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=20230908142136.403541-14-david@redhat.com \
    --to=david@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=gshan@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mail@maciej.szmigiero.name \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mprivozn@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=wangyanan55@huawei.com \
    --cc=xiaoguangrong.eric@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.