qemu-e2k/include/sysemu
David Hildenbrand f39b7d2b96 kvm: Atomic memslot updates
If we update an existing memslot (e.g., resize, split), we temporarily
remove the memslot to re-add it immediately afterwards. These updates
are not atomic, especially not for KVM VCPU threads, such that we can
get spurious faults.

Let's inhibit most KVM ioctls while performing relevant updates, such
that we can perform the update just as if it would happen atomically
without additional kernel support.

We capture the add/del changes and apply them in the notifier commit
stage instead. There, we can check for overlaps and perform the ioctl
inhibiting only if really required (-> overlap).

To keep things simple we don't perform additional checks that wouldn't
actually result in an overlap -- such as !RAM memory regions in some
cases (see kvm_set_phys_mem()).

To minimize cache-line bouncing, use a separate indicator
(in_ioctl_lock) per CPU.  Also, make sure to hold the kvm_slots_lock
while performing both actions (removing+re-adding).

We have to wait until all IOCTLs were exited and block new ones from
getting executed.

This approach cannot result in a deadlock as long as the inhibitor does
not hold any locks that might hinder an IOCTL from getting finished and
exited - something fairly unusual. The inhibitor will always hold the BQL.

AFAIKs, one possible candidate would be userfaultfd. If a page cannot be
placed (e.g., during postcopy), because we're waiting for a lock, or if the
userfaultfd thread cannot process a fault, because it is waiting for a
lock, there could be a deadlock. However, the BQL is not applicable here,
because any other guest memory access while holding the BQL would already
result in a deadlock.

Nothing else in the kernel should block forever and wait for userspace
intervention.

Note: pause_all_vcpus()/resume_all_vcpus() or
start_exclusive()/end_exclusive() cannot be used, as they either drop
the BQL or require to be called without the BQL - something inhibitors
cannot handle. We need a low-level locking mechanism that is
deadlock-free even when not releasing the BQL.

Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Tested-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Message-Id: <20221111154758.1372674-4-eesposit@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2023-01-11 09:59:39 +01:00
..
accel-blocker.h
accel-ops.h
arch_init.h
balloon.h
block-backend-common.h
block-backend-global-state.h
block-backend-io.h
block-backend.h
block-ram-registrar.h
blockdev.h
cpu-throttle.h
cpu-timers.h
cpus.h
cryptodev-vhost-user.h
cryptodev-vhost.h
cryptodev.h
device_tree.h
dirtylimit.h
dirtyrate.h
dma.h
dump-arch.h
dump.h
event-loop-base.h
hax.h
hostmem.h
hvf_int.h
hvf.h
hw_accel.h
iothread.h
kvm_int.h kvm: Atomic memslot updates 2023-01-11 09:59:39 +01:00
kvm.h
memory_mapping.h
numa.h
nvmm.h
os-posix.h
os-win32.h
qtest.h
replay.h
reset.h
rng-random.h
rng.h
rtc.h
runstate-action.h
runstate.h
seccomp.h
sysemu.h
tcg.h
tpm_backend.h
tpm_util.h
tpm.h
vhost-user-backend.h
watchdog.h
whpx.h
xen-mapcache.h
xen.h