@@ -2811,6 +2811,18 @@ static void kvm_eat_signals(CPUState *cpu)
} while (sigismember(&chkset, SIG_IPI));
}
+static void kvm_cpu_set_in_ioctl(CPUState *cpu, bool in_ioctl)
+{
+ if (unlikely(qemu_mutex_iothread_locked())) {
+ return;
+ }
+ if (in_ioctl) {
+ qemu_lockcnt_inc(&cpu->in_ioctl_lock);
+ } else {
+ qemu_lockcnt_dec(&cpu->in_ioctl_lock);
+ }
+}
+
static void kvm_set_in_ioctl(bool in_ioctl)
{
if (likely(qemu_mutex_iothread_locked())) {
@@ -3049,7 +3061,9 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...)
va_end(ap);
trace_kvm_vcpu_ioctl(cpu->cpu_index, type, arg);
+ kvm_cpu_set_in_ioctl(cpu, true);
ret = ioctl(cpu->kvm_fd, type, arg);
+ kvm_cpu_set_in_ioctl(cpu, false);
if (ret == -1) {
ret = -errno;
}
@@ -237,6 +237,7 @@ static void cpu_common_initfn(Object *obj)
cpu->nr_threads = 1;
qemu_mutex_init(&cpu->work_mutex);
+ qemu_lockcnt_init(&cpu->in_ioctl_lock);
QSIMPLEQ_INIT(&cpu->work_list);
QTAILQ_INIT(&cpu->breakpoints);
QTAILQ_INIT(&cpu->watchpoints);
@@ -248,6 +249,7 @@ static void cpu_common_finalize(Object *obj)
{
CPUState *cpu = CPU(obj);
+ qemu_lockcnt_destroy(&cpu->in_ioctl_lock);
qemu_mutex_destroy(&cpu->work_mutex);
}
@@ -397,6 +397,9 @@ struct CPUState {
uint32_t kvm_fetch_index;
uint64_t dirty_pages;
+ /* kvm only for now: CPU is in kvm_vcpu_ioctl() (esp. KVM_RUN) */
+ QemuLockCnt in_ioctl_lock;
+
/* Used for events with 'vcpu' and *without* the 'disabled' properties */
DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS);
DECLARE_BITMAP(trace_dstate, CPU_TRACE_DSTATE_MAX_EVENTS);