97168e
From 9bacf8c4104ff3cff2e0e2c2179ec4fda633167f Mon Sep 17 00:00:00 2001
97168e
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
Date: Mon, 16 Jan 2023 07:51:08 -0500
97168e
Subject: [PATCH 05/11] KVM: keep track of running ioctls
97168e
97168e
RH-Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
RH-MergeRequest: 247: accel: introduce accelerator blocker API
97168e
RH-Bugzilla: 2161188
97168e
RH-Acked-by: David Hildenbrand <david@redhat.com>
97168e
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
97168e
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
97168e
RH-Commit: [2/3] 357508389e2a0fd996206b406e9e235e50b5f0b6
97168e
97168e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2161188
97168e
97168e
commit a27dd2de68f37ba96fe164a42121daa5f0750afc
97168e
Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
Date:   Fri Nov 11 10:47:57 2022 -0500
97168e
97168e
    KVM: keep track of running ioctls
97168e
97168e
    Using the new accel-blocker API, mark where ioctls are being called
97168e
    in KVM. Next, we will implement the critical section that will take
97168e
    care of performing memslots modifications atomically, therefore
97168e
    preventing any new ioctl from running and allowing the running ones
97168e
    to finish.
97168e
97168e
    Signed-off-by: David Hildenbrand <david@redhat.com>
97168e
    Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
    Message-Id: <20221111154758.1372674-3-eesposit@redhat.com>
97168e
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
97168e
97168e
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
97168e
---
97168e
 accel/kvm/kvm-all.c | 7 +++++++
97168e
 1 file changed, 7 insertions(+)
97168e
97168e
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
97168e
index 8f2a53438f..221aadfda7 100644
97168e
--- a/accel/kvm/kvm-all.c
97168e
+++ b/accel/kvm/kvm-all.c
97168e
@@ -2337,6 +2337,7 @@ static int kvm_init(MachineState *ms)
97168e
     assert(TARGET_PAGE_SIZE <= qemu_real_host_page_size);
97168e
 
97168e
     s->sigmask_len = 8;
97168e
+    accel_blocker_init();
97168e
 
97168e
 #ifdef KVM_CAP_SET_GUEST_DEBUG
97168e
     QTAILQ_INIT(&s->kvm_sw_breakpoints);
97168e
@@ -3018,7 +3019,9 @@ int kvm_vm_ioctl(KVMState *s, int type, ...)
97168e
     va_end(ap);
97168e
 
97168e
     trace_kvm_vm_ioctl(type, arg);
97168e
+    accel_ioctl_begin();
97168e
     ret = ioctl(s->vmfd, type, arg);
97168e
+    accel_ioctl_end();
97168e
     if (ret == -1) {
97168e
         ret = -errno;
97168e
     }
97168e
@@ -3036,7 +3039,9 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...)
97168e
     va_end(ap);
97168e
 
97168e
     trace_kvm_vcpu_ioctl(cpu->cpu_index, type, arg);
97168e
+    accel_cpu_ioctl_begin(cpu);
97168e
     ret = ioctl(cpu->kvm_fd, type, arg);
97168e
+    accel_cpu_ioctl_end(cpu);
97168e
     if (ret == -1) {
97168e
         ret = -errno;
97168e
     }
97168e
@@ -3054,7 +3059,9 @@ int kvm_device_ioctl(int fd, int type, ...)
97168e
     va_end(ap);
97168e
 
97168e
     trace_kvm_device_ioctl(fd, type, arg);
97168e
+    accel_ioctl_begin();
97168e
     ret = ioctl(fd, type, arg);
97168e
+    accel_ioctl_end();
97168e
     if (ret == -1) {
97168e
         ret = -errno;
97168e
     }
97168e
-- 
97168e
2.37.3
97168e