yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
4ec855
From e7dc49f6bf6fd242b5b7a83bc270664a1ca45879 Mon Sep 17 00:00:00 2001
4ec855
From: Paolo Bonzini <pbonzini@redhat.com>
4ec855
Date: Mon, 22 Jul 2019 18:22:08 +0100
4ec855
Subject: [PATCH 27/39] KVM: Introduce kvm_arch_destroy_vcpu()
4ec855
4ec855
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
4ec855
Message-id: <20190722182220.19374-7-pbonzini@redhat.com>
4ec855
Patchwork-id: 89623
4ec855
O-Subject: [RHEL-8.1.0 PATCH qemu-kvm v3 06/18] KVM: Introduce kvm_arch_destroy_vcpu()
4ec855
Bugzilla: 1689269
4ec855
RH-Acked-by: Peter Xu <zhexu@redhat.com>
4ec855
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
4ec855
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
4ec855
4ec855
From: Liran Alon <liran.alon@oracle.com>
4ec855
4ec855
Simiar to how kvm_init_vcpu() calls kvm_arch_init_vcpu() to perform
4ec855
arch-dependent initialisation, introduce kvm_arch_destroy_vcpu()
4ec855
to be called from kvm_destroy_vcpu() to perform arch-dependent
4ec855
destruction.
4ec855
4ec855
This was added because some architectures (Such as i386)
4ec855
currently do not free memory that it have allocated in
4ec855
kvm_arch_init_vcpu().
4ec855
4ec855
Suggested-by: Maran Wilson <maran.wilson@oracle.com>
4ec855
Reviewed-by: Maran Wilson <maran.wilson@oracle.com>
4ec855
Signed-off-by: Liran Alon <liran.alon@oracle.com>
4ec855
Message-Id: <20190619162140.133674-3-liran.alon@oracle.com>
4ec855
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4ec855
(cherry picked from commit b1115c99919cf158bb859865f14c3198a0e6f679)
4ec855
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
4ec855
---
4ec855
 accel/kvm/kvm-all.c  |  5 +++++
4ec855
 include/sysemu/kvm.h |  1 +
4ec855
 target/arm/kvm32.c   |  5 +++++
4ec855
 target/arm/kvm64.c   |  5 +++++
4ec855
 target/i386/kvm.c    | 12 ++++++++++++
4ec855
 target/mips/kvm.c    |  5 +++++
4ec855
 target/ppc/kvm.c     |  5 +++++
4ec855
 target/s390x/kvm.c   | 10 ++++++++++
4ec855
 8 files changed, 48 insertions(+)
4ec855
4ec855
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
4ec855
index 3a7c8a3..a939b26 100644
4ec855
--- a/accel/kvm/kvm-all.c
4ec855
+++ b/accel/kvm/kvm-all.c
4ec855
@@ -290,6 +290,11 @@ int kvm_destroy_vcpu(CPUState *cpu)
4ec855
 
4ec855
     DPRINTF("kvm_destroy_vcpu\n");
4ec855
 
4ec855
+    ret = kvm_arch_destroy_vcpu(cpu);
4ec855
+    if (ret < 0) {
4ec855
+        goto err;
4ec855
+    }
4ec855
+
4ec855
     mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
4ec855
     if (mmap_size < 0) {
4ec855
         ret = mmap_size;
4ec855
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
4ec855
index 3d8f294..a5a6dff 100644
4ec855
--- a/include/sysemu/kvm.h
4ec855
+++ b/include/sysemu/kvm.h
4ec855
@@ -372,6 +372,7 @@ int kvm_arch_put_registers(CPUState *cpu, int level);
4ec855
 int kvm_arch_init(MachineState *ms, KVMState *s);
4ec855
 
4ec855
 int kvm_arch_init_vcpu(CPUState *cpu);
4ec855
+int kvm_arch_destroy_vcpu(CPUState *cpu);
4ec855
 
4ec855
 bool kvm_vcpu_id_is_valid(int vcpu_id);
4ec855
 
4ec855
diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
4ec855
index 1740cda..056f016 100644
4ec855
--- a/target/arm/kvm32.c
4ec855
+++ b/target/arm/kvm32.c
4ec855
@@ -237,6 +237,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
4ec855
     return kvm_arm_init_cpreg_list(cpu);
4ec855
 }
4ec855
 
4ec855
+int kvm_arch_destroy_vcpu(CPUState *cs)
4ec855
+{
4ec855
+	return 0;
4ec855
+}
4ec855
+
4ec855
 typedef struct Reg {
4ec855
     uint64_t id;
4ec855
     int offset;
4ec855
diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
4ec855
index e0b8246..c9c761e 100644
4ec855
--- a/target/arm/kvm64.c
4ec855
+++ b/target/arm/kvm64.c
4ec855
@@ -549,6 +549,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
4ec855
     return kvm_arm_init_cpreg_list(cpu);
4ec855
 }
4ec855
 
4ec855
+int kvm_arch_destroy_vcpu(CPUState *cs)
4ec855
+{
4ec855
+    return 0;
4ec855
+}
4ec855
+
4ec855
 bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx)
4ec855
 {
4ec855
     /* Return true if the regidx is a register we should synchronize
4ec855
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
4ec855
index 8e861a1..305809f 100644
4ec855
--- a/target/i386/kvm.c
4ec855
+++ b/target/i386/kvm.c
4ec855
@@ -1196,6 +1196,18 @@ int kvm_arch_init_vcpu(CPUState *cs)
4ec855
     return r;
4ec855
 }
4ec855
 
4ec855
+int kvm_arch_destroy_vcpu(CPUState *cs)
4ec855
+{
4ec855
+    X86CPU *cpu = X86_CPU(cs);
4ec855
+
4ec855
+    if (cpu->kvm_msr_buf) {
4ec855
+        g_free(cpu->kvm_msr_buf);
4ec855
+        cpu->kvm_msr_buf = NULL;
4ec855
+    }
4ec855
+
4ec855
+    return 0;
4ec855
+}
4ec855
+
4ec855
 void kvm_arch_reset_vcpu(X86CPU *cpu)
4ec855
 {
4ec855
     CPUX86State *env = &cpu->env;
4ec855
diff --git a/target/mips/kvm.c b/target/mips/kvm.c
4ec855
index 8e72850..938f8f1 100644
4ec855
--- a/target/mips/kvm.c
4ec855
+++ b/target/mips/kvm.c
4ec855
@@ -91,6 +91,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
4ec855
     return ret;
4ec855
 }
4ec855
 
4ec855
+int kvm_arch_destroy_vcpu(CPUState *cs)
4ec855
+{
4ec855
+    return 0;
4ec855
+}
4ec855
+
4ec855
 void kvm_mips_reset_vcpu(MIPSCPU *cpu)
4ec855
 {
4ec855
     CPUMIPSState *env = &cpu->env;
4ec855
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
4ec855
index 058dcbe..b9858fa 100644
4ec855
--- a/target/ppc/kvm.c
4ec855
+++ b/target/ppc/kvm.c
4ec855
@@ -607,6 +607,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
4ec855
     return ret;
4ec855
 }
4ec855
 
4ec855
+int kvm_arch_destroy_vcpu(CPUState *cs)
4ec855
+{
4ec855
+    return 0;
4ec855
+}
4ec855
+
4ec855
 static void kvm_sw_tlb_put(PowerPCCPU *cpu)
4ec855
 {
4ec855
     CPUPPCState *env = &cpu->env;
4ec855
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
4ec855
index 1d6cc33..0814333 100644
4ec855
--- a/target/s390x/kvm.c
4ec855
+++ b/target/s390x/kvm.c
4ec855
@@ -370,6 +370,16 @@ int kvm_arch_init_vcpu(CPUState *cs)
4ec855
     return 0;
4ec855
 }
4ec855
 
4ec855
+int kvm_arch_destroy_vcpu(CPUState *cs)
4ec855
+{
4ec855
+    S390CPU *cpu = S390_CPU(cs);
4ec855
+
4ec855
+    g_free(cpu->irqstate);
4ec855
+    cpu->irqstate = NULL;
4ec855
+
4ec855
+    return 0;
4ec855
+}
4ec855
+
4ec855
 void kvm_s390_reset_vcpu(S390CPU *cpu)
4ec855
 {
4ec855
     CPUState *cs = CPU(cpu);
4ec855
-- 
4ec855
1.8.3.1
4ec855