From nobody Sun Sep 28 00:33:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1561082752; cv=none; d=zoho.com; s=zohoarc; b=Q1lvs4KgSfh60mZCzCl3FZiwXeFXkN0n4Kko97KRZnRjtkllJN+IkJtKUQTORpbe31HRk2b1QNOV+h9xfpOy+Rz+jiAYoN28NR6mrBaDTPmldBey/UT694vQ3GxLWnhLhKmyZwFuq5ugcuNLzRe981Z/huWBrOJdAcl/FfU57yU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561082752; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6T+CvKxhIT/wD43F8C6X0mfQEc7rDvNDe6JNobc9BRE=; b=edZpLRLUwaDygm7kB59uPw0eNSCKuTw1tkseiLlmaD5iw+Q+kPs3g2MkX8lwg/8DwnZOiS7EvjtvSMB6IEVTrM+5ubrmNVWLBrTM7PmMZaGLyAEhWnnxDDevZZOY0h/OyfFK7MWEbsSubVAD/1g76vJb2GweHBlvA+ezdcxdVsw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561082752311286.4651859953269; Thu, 20 Jun 2019 19:05:52 -0700 (PDT) Received: from localhost ([::1]:54124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1he8vs-0003rR-M8 for importer@patchew.org; Thu, 20 Jun 2019 22:05:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41104) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1he8a3-0006b2-Pv for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1he8a1-0006Yj-UT for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:07 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:39749) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1he8Zw-0006Ki-Ml for qemu-devel@nongnu.org; Thu, 20 Jun 2019 21:43:01 -0400 Received: by mail-wr1-x432.google.com with SMTP id x4so4878741wrt.6 for ; Thu, 20 Jun 2019 18:42:48 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d1sm1123125wru.41.2019.06.20.18.42.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 18:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=6T+CvKxhIT/wD43F8C6X0mfQEc7rDvNDe6JNobc9BRE=; b=XDhqWwpP8SOls3rUCVN3Fdp9LDJoXkaD3Xr12NwOSvCRJIeludk44jelRs+W3zLi38 zpIzqU6SfVtRgpa7HMmUH7EpA8fS1n5PWwiw2dgPT2ORR4EFhO4mZOXDl0Ox01H8eisU yQBaFI+jeLJUfAbxP9JAeFo5MrH0Z5ykhMYl7hLqd4FjMmTwo19Tl2KFNykl3mZJrqVk K66/wr5f+Wi/afGXIqmk9+kab6kkda5qF5pE6RwNBeZTiZ+o4/cne8b0sdEAbLsHxUqx cZlz4HfEUkg1O6+A/76wXeZSXs2y4hmx9HUJcq8nuNNV3iVWbwSraMCiHG7cJvtqU60/ 4MsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=6T+CvKxhIT/wD43F8C6X0mfQEc7rDvNDe6JNobc9BRE=; b=prOixgobMnzwMTKLMsAuiCcNLs51JomboFqUilWmDg5KjaiUO3sQpFpf6TWV8pGzsM FP+6Dvt2VXdS9N5rA9L3bxdAVM++YzzOfXqsuMwQnIrk9UZp9d3u5LcxdwN0AX0ggLlK ZTGarhsHRj4O3eJmo/jE8eqR2Q6nuTekqA1DbggDFXumZRymbDXWoN29SDQV8mt1Zwq6 PqHn22lTFwE7ipBfFKpoFF9a2G86SRqeXmqf+sx5Hg504NlC6wg9gcojhoeI4pXqEf+t S6RdpmEg09WU2BAIwNZoGGQZ6BJt0apTxlcf/Tb3Y6xj4mf23eTsvLtZ2aaeK5XwYNDd ldDQ== X-Gm-Message-State: APjAAAWxD+uz98FXPK1g/EFT5YaIp9fT3m++o9kFsCkVmYDuu/66vDMA s36PGX9E5MnHccBMevAJuesn4zKZ X-Google-Smtp-Source: APXvYqx8ElBEfZ/vW5ce+4tsoc7CJ/352laHkfQ61vXO7xS+1cYyCCzbBX46GPwUREsBNfRNjeB/bw== X-Received: by 2002:a5d:484e:: with SMTP id n14mr8853354wrs.348.1561081367029; Thu, 20 Jun 2019 18:42:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 03:42:19 +0200 Message-Id: <1561081350-3723-15-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561081350-3723-1-git-send-email-pbonzini@redhat.com> References: <1561081350-3723-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::432 Subject: [Qemu-devel] [PULL 14/25] KVM: Introduce kvm_arch_destroy_vcpu() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Liran Alon 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 Reviewed-by: Maran Wilson Signed-off-by: Liran Alon Message-Id: <20190619162140.133674-3-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 5 +++++ include/sysemu/kvm.h | 1 + target/arm/kvm32.c | 5 +++++ target/arm/kvm64.c | 5 +++++ target/i386/kvm.c | 12 ++++++++++++ target/mips/kvm.c | 5 +++++ target/ppc/kvm.c | 5 +++++ target/s390x/kvm.c | 10 ++++++++++ 8 files changed, 48 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index d2f481a..f0f5ab8 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -291,6 +291,11 @@ int kvm_destroy_vcpu(CPUState *cpu) =20 DPRINTF("kvm_destroy_vcpu\n"); =20 + ret =3D kvm_arch_destroy_vcpu(cpu); + if (ret < 0) { + goto err; + } + mmap_size =3D kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0); if (mmap_size < 0) { ret =3D mmap_size; diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index a6d1cd1..64f55e5 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -371,6 +371,7 @@ int kvm_arch_put_registers(CPUState *cpu, int level); int kvm_arch_init(MachineState *ms, KVMState *s); =20 int kvm_arch_init_vcpu(CPUState *cpu); +int kvm_arch_destroy_vcpu(CPUState *cpu); =20 bool kvm_vcpu_id_is_valid(int vcpu_id); =20 diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c index 4e54e37..51f78f7 100644 --- a/target/arm/kvm32.c +++ b/target/arm/kvm32.c @@ -240,6 +240,11 @@ int kvm_arch_init_vcpu(CPUState *cs) return kvm_arm_init_cpreg_list(cpu); } =20 +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + return 0; +} + typedef struct Reg { uint64_t id; int offset; diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 998d21f..22d19c9 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -654,6 +654,11 @@ int kvm_arch_init_vcpu(CPUState *cs) return kvm_arm_init_cpreg_list(cpu); } =20 +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 diff --git a/target/i386/kvm.c b/target/i386/kvm.c index c5cbead..26d8c61 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1679,6 +1679,18 @@ int kvm_arch_init_vcpu(CPUState *cs) return r; } =20 +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + X86CPU *cpu =3D X86_CPU(cs); + + if (cpu->kvm_msr_buf) { + g_free(cpu->kvm_msr_buf); + cpu->kvm_msr_buf =3D NULL; + } + + return 0; +} + void kvm_arch_reset_vcpu(X86CPU *cpu) { CPUX86State *env =3D &cpu->env; diff --git a/target/mips/kvm.c b/target/mips/kvm.c index 8e72850..938f8f1 100644 --- a/target/mips/kvm.c +++ b/target/mips/kvm.c @@ -91,6 +91,11 @@ int kvm_arch_init_vcpu(CPUState *cs) return ret; } =20 +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + return 0; +} + void kvm_mips_reset_vcpu(MIPSCPU *cpu) { CPUMIPSState *env =3D &cpu->env; diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index d4107dd..4b4989c 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -521,6 +521,11 @@ int kvm_arch_init_vcpu(CPUState *cs) return ret; } =20 +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + return 0; +} + static void kvm_sw_tlb_put(PowerPCCPU *cpu) { CPUPPCState *env =3D &cpu->env; diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index bcec979..0267c6c 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -368,6 +368,16 @@ int kvm_arch_init_vcpu(CPUState *cs) return 0; } =20 +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + S390CPU *cpu =3D S390_CPU(cs); + + g_free(cpu->irqstate); + cpu->irqstate =3D NULL; + + return 0; +} + void kvm_s390_reset_vcpu(S390CPU *cpu) { CPUState *cs =3D CPU(cpu); --=20 1.8.3.1