xemu/system
Paolo Bonzini 852f0048f3 RAMBlock: make guest_memfd require uncoordinated discard
Some subsystems like VFIO might disable ram block discard, but guest_memfd
uses discard operations to implement conversions between private and
shared memory.  Because of this, sequences like the following can result
in stale IOMMU mappings:

1. allocate shared page
2. convert page shared->private
3. discard shared page
4. convert page private->shared
5. allocate shared page
6. issue DMA operations against that shared page

This is not a use-after-free, because after step 3 VFIO is still pinning
the page.  However, DMA operations in step 6 will hit the old mapping
that was allocated in step 1.

Address this by taking ram_block_discard_is_enabled() into account when
deciding whether or not to discard pages.

Since kvm_convert_memory()/guest_memfd doesn't implement a
RamDiscardManager handler to convey and replay discard operations,
this is a case of uncoordinated discard, which is blocked/released
by ram_block_discard_require().  Interestingly, this function had
no use so far.

Alternative approaches would be to block discard of shared pages, but
this would cause guests to consume twice the memory if they use VFIO;
or to implement a RamDiscardManager and only block uncoordinated
discard, i.e. use ram_block_coordinated_discard_require().

[Commit message mostly by Michael Roth <michael.roth@amd.com>]

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-04-23 17:35:26 +02:00
..
arch_init.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
async-teardown.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
balloon.c balloon: Fix a misleading error message 2023-11-17 10:07:52 +01:00
bootdevice.c system/bootdevice: Don't unregister reset handler in restore_boot_order() 2024-02-27 13:01:42 +00:00
cpu-throttle.c qemu/main-loop: rename qemu_cond_wait_iothread() to qemu_cond_wait_bql() 2024-01-08 10:45:43 -05:00
cpu-timers.c system/cpu-timers: Introduce ICountMode enumerator 2024-01-19 12:28:59 +01:00
cpus.c qemu/main-loop: rename qemu_cond_wait_iothread() to qemu_cond_wait_bql() 2024-01-08 10:45:43 -05:00
datadir.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
device_tree.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
dirtylimit.c migration: migration_thread_is_self 2024-03-11 16:28:59 -04:00
dma-helpers.c scsi: assert that callbacks run in the correct AioContext 2023-12-21 22:49:27 +01:00
globals.c ide, vl: turn -win2k-hack into a property on IDE devices 2024-02-28 00:23:39 +01:00
ioport.c exec/ioport: Add portio_list_set_enabled() 2024-02-14 06:09:32 -05:00
main.c softmmu: pass the main loop status to gdb "Wxx" packet 2023-10-12 12:33:24 +10:00
memory.c RAMBlock: Add support of KVM private guest memfd 2024-04-23 17:35:25 +02:00
memory_ldst.c.inc system: Move memory_ldst.c.inc to system 2024-02-13 10:59:25 +03:00
memory_mapping.c memory: follow Error API guidelines 2023-10-19 23:13:27 +02:00
meson.build configure, meson: rename targetos to host_os 2023-12-31 09:11:29 +01:00
physmem.c RAMBlock: make guest_memfd require uncoordinated discard 2024-04-23 17:35:26 +02:00
qdev-monitor.c qdev-monitor: fix error message in find_device_state() 2024-04-09 02:31:33 -04:00
qemu-seccomp.c seccomp: report EPERM instead of killing process for spawn set 2024-03-19 20:17:12 +00:00
qtest.c system/qtest: Include missing 'hw/core/cpu.h' header 2023-12-20 10:29:23 +01:00
rtc.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
runstate-action.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
runstate-hmp-cmds.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
runstate.c runstate: skip initial CPU reset if reset is not actually possible 2024-04-23 17:35:25 +02:00
tpm-hmp-cmds.c system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
tpm.c * util/log: re-allow switching away from stderr log file 2023-10-09 10:11:18 -04:00
trace-events system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
trace.h system: Rename softmmu/ directory as system/ 2023-10-08 21:08:08 +02:00
vl.c vl: do not assert if sev-guest is used together with TCG 2024-03-18 22:53:23 +01:00
watchpoint.c system/watchpoint: Move TCG specific code to accel/tcg/ 2024-01-19 12:28:59 +01:00