thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
902636
From e11643b5363262e9f809762a1f2bb5c4a8f26c2a Mon Sep 17 00:00:00 2001
902636
From: Thomas Huth <thuth@redhat.com>
902636
Date: Fri, 29 May 2020 05:53:56 -0400
902636
Subject: [PATCH 14/42] s390x: Add missing vcpu reset functions
902636
MIME-Version: 1.0
902636
Content-Type: text/plain; charset=UTF-8
902636
Content-Transfer-Encoding: 8bit
902636
902636
RH-Author: Thomas Huth <thuth@redhat.com>
902636
Message-id: <20200529055420.16855-15-thuth@redhat.com>
902636
Patchwork-id: 97023
902636
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH v2 14/38] s390x: Add missing vcpu reset functions
902636
Bugzilla: 1828317
902636
RH-Acked-by: Claudio Imbrenda <cimbrend@redhat.com>
902636
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
902636
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
902636
RH-Acked-by: David Hildenbrand <david@redhat.com>
902636
902636
From: Janosch Frank <frankja@linux.ibm.com>
902636
902636
Up to now we only had an ioctl to reset vcpu data QEMU couldn't reach
902636
for the initial reset, which was also called for the clear reset. To
902636
be architecture compliant, we also need to clear local interrupts on a
902636
normal reset.
902636
902636
Because of this and the upcoming protvirt support we need to add
902636
ioctls for the missing clear and normal resets.
902636
902636
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
902636
Reviewed-by: Thomas Huth <thuth@redhat.com>
902636
Acked-by: David Hildenbrand <david@redhat.com>
902636
Message-Id: <20200214151636.8764-3-frankja@linux.ibm.com>
902636
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
902636
(cherry picked from commit b91a03946e0f65ddd22927dd80ca1276bf89c5af)
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 target/s390x/cpu.c       | 14 ++++++++++++--
902636
 target/s390x/kvm-stub.c  | 10 +++++++++-
902636
 target/s390x/kvm.c       | 42 ++++++++++++++++++++++++++++++++--------
902636
 target/s390x/kvm_s390x.h |  4 +++-
902636
 4 files changed, 58 insertions(+), 12 deletions(-)
902636
902636
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
902636
index e538a4a3e2..c0dd502b84 100644
902636
--- a/target/s390x/cpu.c
902636
+++ b/target/s390x/cpu.c
902636
@@ -144,8 +144,18 @@ static void s390_cpu_reset(CPUState *s, cpu_reset_type type)
902636
     }
902636
 
902636
     /* Reset state inside the kernel that we cannot access yet from QEMU. */
902636
-    if (kvm_enabled() && type != S390_CPU_RESET_NORMAL) {
902636
-        kvm_s390_reset_vcpu(cpu);
902636
+    if (kvm_enabled()) {
902636
+        switch (type) {
902636
+        case S390_CPU_RESET_CLEAR:
902636
+            kvm_s390_reset_vcpu_clear(cpu);
902636
+            break;
902636
+        case S390_CPU_RESET_INITIAL:
902636
+            kvm_s390_reset_vcpu_initial(cpu);
902636
+            break;
902636
+        case S390_CPU_RESET_NORMAL:
902636
+            kvm_s390_reset_vcpu_normal(cpu);
902636
+            break;
902636
+        }
902636
     }
902636
 }
902636
 
902636
diff --git a/target/s390x/kvm-stub.c b/target/s390x/kvm-stub.c
902636
index 5152e2bdf1..c4cd497f85 100644
902636
--- a/target/s390x/kvm-stub.c
902636
+++ b/target/s390x/kvm-stub.c
902636
@@ -83,7 +83,15 @@ void kvm_s390_cmma_reset(void)
902636
 {
902636
 }
902636
 
902636
-void kvm_s390_reset_vcpu(S390CPU *cpu)
902636
+void kvm_s390_reset_vcpu_initial(S390CPU *cpu)
902636
+{
902636
+}
902636
+
902636
+void kvm_s390_reset_vcpu_clear(S390CPU *cpu)
902636
+{
902636
+}
902636
+
902636
+void kvm_s390_reset_vcpu_normal(S390CPU *cpu)
902636
 {
902636
 }
902636
 
902636
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
902636
index 1c5bc7a2f9..75d82af6fc 100644
902636
--- a/target/s390x/kvm.c
902636
+++ b/target/s390x/kvm.c
902636
@@ -151,6 +151,7 @@ static int cap_s390_irq;
902636
 static int cap_ri;
902636
 static int cap_gs;
902636
 static int cap_hpage_1m;
902636
+static int cap_vcpu_resets;
902636
 
902636
 static int active_cmma;
902636
 
902636
@@ -342,6 +343,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
902636
     cap_async_pf = kvm_check_extension(s, KVM_CAP_ASYNC_PF);
902636
     cap_mem_op = kvm_check_extension(s, KVM_CAP_S390_MEM_OP);
902636
     cap_s390_irq = kvm_check_extension(s, KVM_CAP_S390_INJECT_IRQ);
902636
+    cap_vcpu_resets = kvm_check_extension(s, KVM_CAP_S390_VCPU_RESETS);
902636
 
902636
     if (!kvm_check_extension(s, KVM_CAP_S390_GMAP)
902636
         || !kvm_check_extension(s, KVM_CAP_S390_COW)) {
902636
@@ -403,17 +405,41 @@ int kvm_arch_destroy_vcpu(CPUState *cs)
902636
     return 0;
902636
 }
902636
 
902636
-void kvm_s390_reset_vcpu(S390CPU *cpu)
902636
+static void kvm_s390_reset_vcpu(S390CPU *cpu, unsigned long type)
902636
 {
902636
     CPUState *cs = CPU(cpu);
902636
 
902636
-    /* The initial reset call is needed here to reset in-kernel
902636
-     * vcpu data that we can't access directly from QEMU
902636
-     * (i.e. with older kernels which don't support sync_regs/ONE_REG).
902636
-     * Before this ioctl cpu_synchronize_state() is called in common kvm
902636
-     * code (kvm-all) */
902636
-    if (kvm_vcpu_ioctl(cs, KVM_S390_INITIAL_RESET, NULL)) {
902636
-        error_report("Initial CPU reset failed on CPU %i", cs->cpu_index);
902636
+    /*
902636
+     * The reset call is needed here to reset in-kernel vcpu data that
902636
+     * we can't access directly from QEMU (i.e. with older kernels
902636
+     * which don't support sync_regs/ONE_REG).  Before this ioctl
902636
+     * cpu_synchronize_state() is called in common kvm code
902636
+     * (kvm-all).
902636
+     */
902636
+    if (kvm_vcpu_ioctl(cs, type)) {
902636
+        error_report("CPU reset failed on CPU %i type %lx",
902636
+                     cs->cpu_index, type);
902636
+    }
902636
+}
902636
+
902636
+void kvm_s390_reset_vcpu_initial(S390CPU *cpu)
902636
+{
902636
+    kvm_s390_reset_vcpu(cpu, KVM_S390_INITIAL_RESET);
902636
+}
902636
+
902636
+void kvm_s390_reset_vcpu_clear(S390CPU *cpu)
902636
+{
902636
+    if (cap_vcpu_resets) {
902636
+        kvm_s390_reset_vcpu(cpu, KVM_S390_CLEAR_RESET);
902636
+    } else {
902636
+        kvm_s390_reset_vcpu(cpu, KVM_S390_INITIAL_RESET);
902636
+    }
902636
+}
902636
+
902636
+void kvm_s390_reset_vcpu_normal(S390CPU *cpu)
902636
+{
902636
+    if (cap_vcpu_resets) {
902636
+        kvm_s390_reset_vcpu(cpu, KVM_S390_NORMAL_RESET);
902636
     }
902636
 }
902636
 
902636
diff --git a/target/s390x/kvm_s390x.h b/target/s390x/kvm_s390x.h
902636
index caf985955b..0b21789796 100644
902636
--- a/target/s390x/kvm_s390x.h
902636
+++ b/target/s390x/kvm_s390x.h
902636
@@ -34,7 +34,9 @@ int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch,
902636
                                     int vq, bool assign);
902636
 int kvm_s390_cmma_active(void);
902636
 void kvm_s390_cmma_reset(void);
902636
-void kvm_s390_reset_vcpu(S390CPU *cpu);
902636
+void kvm_s390_reset_vcpu_clear(S390CPU *cpu);
902636
+void kvm_s390_reset_vcpu_normal(S390CPU *cpu);
902636
+void kvm_s390_reset_vcpu_initial(S390CPU *cpu);
902636
 int kvm_s390_set_mem_limit(uint64_t new_limit, uint64_t *hw_limit);
902636
 void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp);
902636
 void kvm_s390_crypto_reset(void);
902636
-- 
902636
2.27.0
902636