qemu/include/exec
David Hildenbrand 533f5d6679 memory,vhost: Allow for marking memory device memory regions unmergeable
Let's allow for marking memory regions unmergeable, to teach
flatview code and vhost to not merge adjacent aliases to the same memory
region into a larger memory section; instead, we want separate aliases to
stay separate such that we can atomically map/unmap aliases without
affecting other aliases.

This is desired for virtio-mem mapping device memory located on a RAM
memory region via multiple aliases into a memory region container,
resulting in separate memslots that can get (un)mapped atomically.

As an example with virtio-mem, the layout would look something like this:
  [...]
  0000000240000000-00000020bfffffff (prio 0, i/o): device-memory
    0000000240000000-000000043fffffff (prio 0, i/o): virtio-mem
      0000000240000000-000000027fffffff (prio 0, ram): alias memslot-0 @mem2 0000000000000000-000000003fffffff
      0000000280000000-00000002bfffffff (prio 0, ram): alias memslot-1 @mem2 0000000040000000-000000007fffffff
      00000002c0000000-00000002ffffffff (prio 0, ram): alias memslot-2 @mem2 0000000080000000-00000000bfffffff
  [...]

Without unmergable memory regions, all three memslots would get merged into
a single memory section. For example, when mapping another alias (e.g.,
virtio-mem-memslot-3) or when unmapping any of the mapped aliases,
memory listeners will first get notified about the removal of the big
memory section to then get notified about re-adding of the new
(differently merged) memory section(s).

In an ideal world, memory listeners would be able to deal with that
atomically, like KVM nowadays does. However, (a) supporting this for other
memory listeners (vhost-user, vfio) is fairly hard: temporary removal
can result in all kinds of issues on concurrent access to guest memory;
and (b) this handling is undesired, because temporarily removing+readding
can consume quite some time on bigger memslots and is not efficient
(e.g., vfio unpinning and repinning pages ...).

Let's allow for marking a memory region unmergeable, such that we
can atomically (un)map aliases to the same memory region, similar to
(un)mapping individual DIMMs.

Similarly, teach vhost code to not redo what flatview core stopped doing:
don't merge such sections. Merging in vhost code is really only relevant
for handling random holes in boot memory where; without this merging,
the vhost-user backend wouldn't be able to mmap() some boot memory
backed on hugetlb.

We'll use this for virtio-mem next.

Message-ID: <20230926185738.277351-18-david@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
2023-10-12 14:15:22 +02:00
..
user thunk: Delete checks for old host definitions 2023-09-15 05:26:50 -07:00
address-spaces.h exec/address-spaces.h: Remove unuseful 'exec/memory.h' include 2023-08-31 19:47:43 +02:00
confidential-guest-support.h confidential guest support: Introduce cgs "ready" flag 2021-02-08 16:57:38 +11:00
cpu-all.h accel/tcg: Restrict dump_exec_info() declaration 2023-10-04 11:03:54 -07:00
cpu-common.h softmmu/physmem: Fixup qemu_ram_block_from_host() documentation 2023-10-12 14:15:21 +02:00
cpu-defs.h accel/tcg: Move CPUTLB definitions from cpu-defs.h 2023-10-03 08:01:02 -07:00
cpu_ldst.h accel/tcg: Modify tlb_*() to use CPUState 2023-10-04 11:03:54 -07:00
cputlb.h overall/alpha tcg cpus|hppa: Fix Lesser GPL version number 2020-11-15 16:43:54 +01:00
exec-all.h exec: Move cpu_loop_foo() target agnostic functions to 'cpu-common.h' 2023-10-04 11:03:54 -07:00
gdbstub.h gdbstub: Remove gdb_has_xml variable 2023-10-11 08:46:33 +01:00
helper-gen-common.h tcg: Split helper-gen.h 2023-06-05 12:04:29 -07:00
helper-gen.h tcg: Split helper-gen.h 2023-06-05 12:04:29 -07:00
helper-gen.h.inc tcg: Split helper-gen.h 2023-06-05 12:04:29 -07:00
helper-head.h tcg: Move env defines out of NEED_CPU_H in helper-head.h 2023-06-05 12:04:29 -07:00
helper-info.c.inc tcg: Pass TCGHelperInfo to tcg_gen_callN 2023-06-05 12:04:29 -07:00
helper-proto-common.h tcg: Use HAVE_CMPXCHG128 instead of CONFIG_CMPXCHG128 2023-07-15 08:02:49 +01:00
helper-proto.h tcg: Split helper-proto.h 2023-06-05 12:04:29 -07:00
helper-proto.h.inc tcg: Split helper-proto.h 2023-06-05 12:04:29 -07:00
hwaddr.h bulk: Rename TARGET_FMT_plx -> HWADDR_FMT_plx 2023-01-18 11:14:34 +01:00
ioport.h nomaintainer: Fix Lesser GPL version number 2020-11-15 17:04:40 +01:00
log.h include/exec/log: Do not reference QemuLogFile directly 2022-04-20 10:51:11 -07:00
memattrs.h include/exec/memattrs: Add two bits of space to MemTxAttrs 2023-06-23 11:15:44 +01:00
memop.h include/exec/memop: Add MO_ATOM_* 2023-05-16 15:21:38 -07:00
memopidx.h Normalize header guard symbol definition 2022-05-11 16:50:26 +02:00
memory-internal.h exec/memory: Expose memory_region_access_valid() 2023-01-09 13:50:13 +01:00
memory.h memory,vhost: Allow for marking memory device memory regions unmergeable 2023-10-12 14:15:22 +02:00
memory_ldst.h.inc bulk: Do not declare function prototypes using 'extern' keyword 2023-08-31 19:47:43 +02:00
memory_ldst_cached.h.inc exec/memory_ldst_cached: Use correct type size 2021-05-26 08:35:51 -07:00
memory_ldst_phys.h.inc exec/memory_ldst_phys: Use correct type sizes 2021-05-26 08:35:51 -07:00
page-vary.h bulk: Do not declare function prototypes using 'extern' keyword 2023-08-31 19:47:43 +02:00
plugin-gen.h plugins: Set final instruction count in plugin_gen_tb_end 2023-10-11 08:46:39 +01:00
poison.h accel: Remove HAX accelerator 2023-08-31 19:46:43 +02:00
ram_addr.h softmmu/physmem: Distinguish between file access mode and mmap protection 2023-09-19 10:23:21 +02:00
ramblock.h hostmem-file: add offset option 2023-05-23 16:47:03 +02:00
ramlist.h qapi: introduce x-query-ramblock QMP command 2021-11-02 15:55:14 +00:00
replay-core.h replay: Extract core API to 'exec/replay-core.h' 2023-02-27 22:29:01 +01:00
target_long.h include: split target_long definition from cpu-defs 2023-03-07 20:44:09 +00:00
target_page.h softmmu: Introduce qemu_target_page_mask() helper 2023-06-23 02:54:44 -04:00
tb-flush.h includes: move tb_flush into its own header 2023-03-07 17:06:33 +00:00
tlb-common.h tcg: Add tlb_fast_offset to TCGContext 2023-06-05 12:04:28 -07:00
translate-all.h accel/tcg: Move remainder of page locking to tb-maint.c 2022-12-20 17:11:12 -08:00
translation-block.h exec/translation-block: Clean up includes 2023-08-31 19:47:43 +02:00
translator.h accel/tcg: Add plugin_enabled to DisasContextBase 2023-10-11 08:46:33 +01:00
tswap.h include/exec: Provide the tswap() functions for target independent code, too 2023-04-20 11:25:32 +02:00