]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
KVM: Introduce kvm_arch_destroy_vcpu()
authorLiran Alon <liran.alon@oracle.com>
Wed, 19 Jun 2019 16:21:32 +0000 (19:21 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 21 Jun 2019 00:29:39 +0000 (02:29 +0200)
Simiar to how kvm_init_vcpu() calls kvm_arch_init_vcpu() to perform
arch-dependent initialisation, introduce kvm_arch_destroy_vcpu()
to be called from kvm_destroy_vcpu() to perform arch-dependent
destruction.

This was added because some architectures (Such as i386)
currently do not free memory that it have allocated in
kvm_arch_init_vcpu().

Suggested-by: Maran Wilson <maran.wilson@oracle.com>
Reviewed-by: Maran Wilson <maran.wilson@oracle.com>
Signed-off-by: Liran Alon <liran.alon@oracle.com>
Message-Id: <20190619162140.133674-3-liran.alon@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
accel/kvm/kvm-all.c
include/sysemu/kvm.h
target/arm/kvm32.c
target/arm/kvm64.c
target/i386/kvm.c
target/mips/kvm.c
target/ppc/kvm.c
target/s390x/kvm.c

index d2f481a3474dbab261721ff639a69472facfb621..f0f5ab833be982e7fed3838855a835a4691bf695 100644 (file)
@@ -291,6 +291,11 @@ int kvm_destroy_vcpu(CPUState *cpu)
 
     DPRINTF("kvm_destroy_vcpu\n");
 
+    ret = kvm_arch_destroy_vcpu(cpu);
+    if (ret < 0) {
+        goto err;
+    }
+
     mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
     if (mmap_size < 0) {
         ret = mmap_size;
index a6d1cd190fed62e07489a1b29050305e22dbc66c..64f55e519df79807d2b6a1811283ce468f77701f 100644 (file)
@@ -371,6 +371,7 @@ int kvm_arch_put_registers(CPUState *cpu, int level);
 int kvm_arch_init(MachineState *ms, KVMState *s);
 
 int kvm_arch_init_vcpu(CPUState *cpu);
+int kvm_arch_destroy_vcpu(CPUState *cpu);
 
 bool kvm_vcpu_id_is_valid(int vcpu_id);
 
index 4e54e372a6688eb0312f9a999fe511191421e202..51f78f722b1884fb6b5cad9af19a20fef7229af1 100644 (file)
@@ -240,6 +240,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
     return kvm_arm_init_cpreg_list(cpu);
 }
 
+int kvm_arch_destroy_vcpu(CPUState *cs)
+{
+       return 0;
+}
+
 typedef struct Reg {
     uint64_t id;
     int offset;
index 998d21f399f4886cd25c703cd8d46c7cdbc51e34..22d19c9aec6f8291bffbf2cf309f3ac4056d1e87 100644 (file)
@@ -654,6 +654,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
     return kvm_arm_init_cpreg_list(cpu);
 }
 
+int kvm_arch_destroy_vcpu(CPUState *cs)
+{
+    return 0;
+}
+
 bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx)
 {
     /* Return true if the regidx is a register we should synchronize
index c5cbeaddd13cd1ce813de2dfa56169b8320850ee..26d8c61a5f637d56e1a33ee4d50854c81919340d 100644 (file)
@@ -1679,6 +1679,18 @@ int kvm_arch_init_vcpu(CPUState *cs)
     return r;
 }
 
+int kvm_arch_destroy_vcpu(CPUState *cs)
+{
+    X86CPU *cpu = X86_CPU(cs);
+
+    if (cpu->kvm_msr_buf) {
+        g_free(cpu->kvm_msr_buf);
+        cpu->kvm_msr_buf = NULL;
+    }
+
+    return 0;
+}
+
 void kvm_arch_reset_vcpu(X86CPU *cpu)
 {
     CPUX86State *env = &cpu->env;
index 8e72850962e1c9e186bccca10e64c425f3592b62..938f8f144b74a9ee9c051781aaa9165613c7e733 100644 (file)
@@ -91,6 +91,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
     return ret;
 }
 
+int kvm_arch_destroy_vcpu(CPUState *cs)
+{
+    return 0;
+}
+
 void kvm_mips_reset_vcpu(MIPSCPU *cpu)
 {
     CPUMIPSState *env = &cpu->env;
index d4107dd70d21590b29abdb85432f24e0d45c7239..4b4989c0af50d031dc9ee8064ff7b8a97c81fbd1 100644 (file)
@@ -521,6 +521,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
     return ret;
 }
 
+int kvm_arch_destroy_vcpu(CPUState *cs)
+{
+    return 0;
+}
+
 static void kvm_sw_tlb_put(PowerPCCPU *cpu)
 {
     CPUPPCState *env = &cpu->env;
index bcec9795ec802887bf53b0e4e4d4b97d64a8dcff..0267c6c2f6daafe746f3af3267f2e64bff61b873 100644 (file)
@@ -368,6 +368,16 @@ int kvm_arch_init_vcpu(CPUState *cs)
     return 0;
 }
 
+int kvm_arch_destroy_vcpu(CPUState *cs)
+{
+    S390CPU *cpu = S390_CPU(cs);
+
+    g_free(cpu->irqstate);
+    cpu->irqstate = NULL;
+
+    return 0;
+}
+
 void kvm_s390_reset_vcpu(S390CPU *cpu)
 {
     CPUState *cs = CPU(cpu);