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