qemu-cr16/include/system
Magnus Kulke efc4093358 accel/mshv: Handle overlapping mem mappings
QEMU maps certain regions into the guest multiple times, as seen in the
trace below. Currently the MSHV kernel driver will reject those
mappings. To workaround this, a record is kept (a static global list of
"slots", inspired by what the HVF accelerator has implemented). An
overlapping region is not registered at the hypervisor, and marked as
mapped=false. If there is an UNMAPPED_GPA exit, we can look for a slot
that is unmapped and would cover the GPA. In this case we map out the
conflicting slot and map in the requested region.

mshv_set_phys_mem       add=1 name=pc.bios
mshv_map_memory      => u_a=7ffff4e00000 gpa=00fffc0000 size=00040000
mshv_set_phys_mem       add=1 name=ioapic
mshv_set_phys_mem       add=1 name=hpet
mshv_set_phys_mem       add=0 name=pc.ram
mshv_unmap_memory       u_a=7fff67e00000 gpa=0000000000 size=80000000
mshv_set_phys_mem       add=1 name=pc.ram
mshv_map_memory         u_a=7fff67e00000 gpa=0000000000 size=000c0000
mshv_set_phys_mem       add=1 name=pc.rom
mshv_map_memory         u_a=7ffff4c00000 gpa=00000c0000 size=00020000
mshv_set_phys_mem       add=1 name=pc.bios
mshv_remap_attempt   => u_a=7ffff4e20000 gpa=00000e0000 size=00020000

The mapping table is guarded by a mutex for concurrent modification and
RCU mechanisms for concurrent reads. Writes occur rarely, but we'll have
to verify whether an unmapped region exist for each UNMAPPED_GPA exit,
which happens frequently.

Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
Link: https://lore.kernel.org/r/20250916164847.77883-24-magnuskulke@linux.microsoft.com
[Fix format strings for trace-events; mshv.h/mshv_int.h split. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-08 19:17:31 +02:00
..
accel-blocker.h
accel-irq.h hw/intc: Generalize APIC helper names from kvm_* to accel_* 2025-10-08 19:17:29 +02:00
address-spaces.h include/system: Move exec/address-spaces.h to system/address-spaces.h 2025-04-23 14:08:21 -07:00
arch_init.h system: Replace arch_type global by qemu_arch_available() helper 2025-03-11 20:03:26 +01:00
balloon.h
block-backend-common.h
block-backend-global-state.h block-backend: mark blk_io_limits_disable() as GRAPH_UNLOCKED 2025-07-14 15:42:12 +02:00
block-backend-io.h block: Improve blk_get_attached_dev_id() docstring 2025-02-06 13:59:00 +01:00
block-backend.h
block-ram-registrar.h
blockdev.h
confidential-guest-support.h backends/confidential-guest-support: Add set_guest_policy() function 2025-07-12 15:28:21 +02:00
cpu-throttle.h
cpu-timers-internal.h
cpu-timers.h include/exec: Split out icount.h 2025-04-23 14:08:44 -07:00
cpus.h bsd-user, linux-user: introduce qemu_process_cpu_events 2025-09-17 19:00:56 +02:00
cryptodev-vhost-user.h
cryptodev-vhost.h
cryptodev.h
device_tree.h hw: Centralize handling of -machine dumpdtb option 2025-02-24 15:03:42 +00:00
dirtylimit.h
dirtyrate.h
dma.h include/system: Move exec/address-spaces.h to system/address-spaces.h 2025-04-23 14:08:21 -07:00
dump-arch.h
dump.h
event-loop-base.h
host_iommu_device.h vfio/iommufd: Save vendor specific device info 2025-06-05 10:40:38 +02:00
hostmem.h include/system: Move exec/memory.h to system/memory.h 2025-04-23 14:08:21 -07:00
hvf.h accel/hvf: Restrict internal declarations 2025-07-04 14:43:45 +02:00
hvf_int.h accel: Extract AccelClass definition to 'accel/accel-ops.h' 2025-07-15 19:34:33 +02:00
hw_accel.h accel/system: Document cpu_synchronize_state_post_init/reset() 2025-07-04 14:43:46 +02:00
igvm-cfg.h sev: Provide sev_features flags from IGVM VMSA to KVM_SEV_INIT2 2025-07-12 15:28:21 +02:00
iommufd.h vfio/iommufd: register container for cpr 2025-07-03 13:42:28 +02:00
ioport.h include/system: Move exec/ioport.h to system/ioport.h 2025-04-23 14:08:21 -07:00
iothread.h
kvm.h kvm/kvm-all: make kvm_park/unpark_vcpu local to kvm-all.c 2025-08-27 10:57:03 +02:00
kvm_int.h accel: Extract AccelClass definition to 'accel/accel-ops.h' 2025-07-15 19:34:33 +02:00
kvm_xen.h
memory.h memory: reintroduce BQL-free fine-grained PIO/MMIO 2025-08-29 12:48:14 +02:00
memory_mapping.h
mshv.h target/i386/mshv: Implement mshv_store_regs() 2025-10-08 19:17:30 +02:00
mshv_int.h accel/mshv: Handle overlapping mem mappings 2025-10-08 19:17:31 +02:00
numa.h
nvmm.h accel/nvmm: Expose nvmm_enabled() to common code 2025-07-04 14:43:46 +02:00
os-posix.h os: add an ability to lock memory on_fault 2025-02-12 11:36:01 -05:00
os-wasm.h include/qemu/osdep.h: Add Emscripten-specific OS dependencies 2025-05-06 16:02:04 +02:00
os-win32.h error: Kill @error_warn 2025-10-01 08:33:24 +02:00
qtest.h include/system: Remove ifndef CONFIG_USER_ONLY in qtest.h 2025-04-23 14:08:44 -07:00
ram_addr.h include: Remove 'exec/exec-all.h' 2025-04-30 12:45:05 -07:00
ramblock.h physmem: Support coordinated discarding of RAM with guest_memfd 2025-06-23 16:03:59 -04:00
replay.h meson: Only allow CONFIG_USER_ONLY from certain source sets 2025-04-23 14:08:44 -07:00
reset.h
rng-random.h
rng.h
rtc.h
runstate-action.h
runstate.h Accelerators patches 2025-07-16 07:13:40 -04:00
seccomp.h
spdm-socket.h
stats.h
system.h system: drop the -old-param option 2025-09-16 17:31:54 +01:00
tcg.h tcg: Move qemu_tcg_mttcg_enabled() to 'system/tcg.h' 2025-04-23 15:07:32 -07:00
tpm.h
tpm_backend.h
tpm_util.h
vhost-user-backend.h vhost-user: return failure if backend crash when live migration 2025-05-14 05:39:15 -04:00
watchdog.h
whpx.h accel/whpx: Expose whpx_enabled() to common code 2025-07-04 14:43:46 +02:00
xen-mapcache.h system/xen: remove inline stubs 2025-04-23 13:52:37 -07:00
xen.h meson: Only allow CONFIG_USER_ONLY from certain source sets 2025-04-23 14:08:44 -07:00