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