On Wed, Nov 02, 2022 at 04:33:15PM +0000, Sean Christopherson wrote: > On Wed, Nov 02, 2022, Peter Xu wrote: > > Might be slightly off-topic: I didn't quickly spot how do we guarantee two > > threads doing KVM_RUN ioctl on the same vcpu fd concurrently. I know > > that's insane and could have corrupted things, but I just want to make sure > > e.g. even a malicious guest app won't be able to trigger host warnings. > > kvm_vcpu_ioctl() takes the vCPU's mutex: > > static long kvm_vcpu_ioctl(struct file *filp, > unsigned int ioctl, unsigned long arg) > { > ... > > /* > * Some architectures have vcpu ioctls that are asynchronous to vcpu > * execution; mutex_lock() would break them. > */ > r = kvm_arch_vcpu_async_ioctl(filp, ioctl, arg); > if (r != -ENOIOCTLCMD) > return r; > > if (mutex_lock_killable(&vcpu->mutex)) > return -EINTR; > switch (ioctl) { > case KVM_RUN: { Ah, makes sense, thanks! -- Peter Xu