qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Laurent Vivier" <laurent@vivier.eu>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Peter Xu" <peterx@redhat.com>, "Anton Johansson" <anjo@rev.ng>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	kvm@vger.kernel.org, "Marek Vasut" <marex@denx.de>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Brian Cain" <bcain@quicinc.com>,
	"Yoshinori Sato" <ysato@users.sourceforge.jp>,
	"Edgar E . Iglesias" <edgar.iglesias@gmail.com>,
	"Claudio Fontana" <cfontana@suse.de>,
	"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
	"Artyom Tarasenko" <atar4qemu@gmail.com>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	qemu-ppc@nongnu.org, "Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
	"Aurelien Jarno" <aurelien@aurel32.net>,
	"Ilya Leoshkevich" <iii@linux.ibm.com>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"Bastian Koppelmann" <kbastian@mail.uni-paderborn.de>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Alessandro Di Federico" <ale@rev.ng>,
	"Song Gao" <gaosong@loongson.cn>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Chris Wulff" <crwulff@gmail.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Fabiano Rosas" <farosas@suse.de>,
	qemu-s390x@nongnu.org, "Yanan Wang" <wangyanan55@huawei.com>,
	"Luc Michel" <luc@lmichel.fr>, "Weiwei Li" <liweiwei@iscas.ac.cn>,
	"Bin Meng" <bin.meng@windriver.com>,
	"Stafford Horne" <shorne@gmail.com>,
	"Xiaojuan Yang" <yangxiaojuan@loongson.cn>,
	"Daniel P . Berrange" <berrange@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	qemu-arm@nongnu.org, "Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
	"Bernhard Beschow" <shentey@gmail.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	qemu-riscv@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Greg Kurz" <groug@kaod.org>,
	"Michael Rolnik" <mrolnik@gmail.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"xianglai li" <lixianglai@loongson.cn>,
	"Salil Mehta" <salil.mehta@opnsrc.net>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Ani Sinha" <anisinha@redhat.com>,
	"Bibo Mao" <maobibo@loongson.cn>
Subject: [PATCH 07/22] exec/cpu: Introduce the CPU address space destruction function
Date: Mon, 18 Sep 2023 18:02:40 +0200	[thread overview]
Message-ID: <20230918160257.30127-8-philmd@linaro.org> (raw)
In-Reply-To: <20230918160257.30127-1-philmd@linaro.org>

From: xianglai li <lixianglai@loongson.cn>

Introduce new function to destroy CPU address space resources
for cpu hot-(un)plug.

Co-authored-by: "Salil Mehta" <salil.mehta@opnsrc.net>
Cc: "Salil Mehta" <salil.mehta@opnsrc.net>
Cc: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Cc: Song Gao <gaosong@loongson.cn>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Ani Sinha <anisinha@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Eduardo Habkost <eduardo@habkost.net>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: Yanan Wang <wangyanan55@huawei.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: xianglai li <lixianglai@loongson.cn>
Message-ID: <3a4fc2a3df4b767c3c296a7da3bc15ca9c251316.1694433326.git.lixianglai@loongson.cn>
---
 include/exec/cpu-common.h |  8 ++++++++
 include/hw/core/cpu.h     |  1 +
 softmmu/physmem.c         | 24 ++++++++++++++++++++++++
 3 files changed, 33 insertions(+)

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 41788c0bdd..eb56a228a2 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -120,6 +120,14 @@ size_t qemu_ram_pagesize_largest(void);
  */
 void cpu_address_space_init(CPUState *cpu, int asidx,
                             const char *prefix, MemoryRegion *mr);
+/**
+ * cpu_address_space_destroy:
+ * @cpu: CPU for which address space needs to be destroyed
+ * @asidx: integer index of this address space
+ *
+ * Note that with KVM only one address space is supported.
+ */
+void cpu_address_space_destroy(CPUState *cpu, int asidx);
 
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             hwaddr len, bool is_write);
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 92a4234439..c90cf3a162 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -366,6 +366,7 @@ struct CPUState {
     QSIMPLEQ_HEAD(, qemu_work_item) work_list;
 
     CPUAddressSpace *cpu_ases;
+    int cpu_ases_ref_count;
     int num_ases;
     AddressSpace *as;
     MemoryRegion *memory;
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 18277ddd67..c75e3e8042 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -761,6 +761,7 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
 
     if (!cpu->cpu_ases) {
         cpu->cpu_ases = g_new0(CPUAddressSpace, cpu->num_ases);
+        cpu->cpu_ases_ref_count = cpu->num_ases;
     }
 
     newas = &cpu->cpu_ases[asidx];
@@ -774,6 +775,29 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
     }
 }
 
+void cpu_address_space_destroy(CPUState *cpu, int asidx)
+{
+    CPUAddressSpace *cpuas;
+
+    assert(asidx < cpu->num_ases);
+    assert(asidx == 0 || !kvm_enabled());
+    assert(cpu->cpu_ases);
+
+    cpuas = &cpu->cpu_ases[asidx];
+    if (tcg_enabled()) {
+        memory_listener_unregister(&cpuas->tcg_as_listener);
+    }
+
+    address_space_destroy(cpuas->as);
+
+    cpu->cpu_ases_ref_count--;
+    if (cpu->cpu_ases_ref_count == 0) {
+        g_free(cpu->cpu_ases);
+        cpu->cpu_ases = NULL;
+    }
+
+}
+
 AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
 {
     /* Return the AddressSpace corresponding to the specified index */
-- 
2.41.0



  parent reply	other threads:[~2023-09-18 16:07 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18 16:02 [PATCH 00/22] exec/cpu: Call cpu_exec_realizefn() once in cpu_common_realize() Philippe Mathieu-Daudé
2023-09-18 16:02 ` [PATCH 01/22] target/i386: Only realize existing APIC device Philippe Mathieu-Daudé
2023-09-29 20:57   ` Richard Henderson
2023-11-28 15:32   ` Igor Mammedov
2023-09-18 16:02 ` [PATCH 02/22] hw/intc/apic: Pass CPU using QOM link property Philippe Mathieu-Daudé
2023-09-29 21:01   ` Richard Henderson
2023-11-28 15:34   ` Igor Mammedov
2023-09-18 16:02 ` [PATCH 03/22] target/i386/kvm: Correct comment in kvm_cpu_realize() Philippe Mathieu-Daudé
2023-09-29 21:01   ` Richard Henderson
2023-11-28 15:50   ` Igor Mammedov
2023-09-18 16:02 ` [RFC PATCH 04/22] exec/cpu: Never call cpu_reset() before cpu_realize() Philippe Mathieu-Daudé
2023-09-29 21:03   ` Richard Henderson
2023-11-28 16:00   ` Igor Mammedov
2023-09-18 16:02 ` [PATCH 05/22] exec/cpu: Call qemu_init_vcpu() once in cpu_common_realize() Philippe Mathieu-Daudé
2023-09-29 21:04   ` Richard Henderson
2023-11-28 16:12   ` Igor Mammedov
2023-09-18 16:02 ` [PATCH 06/22] exec/cpu: Call cpu_remove_sync() once in cpu_common_unrealize() Philippe Mathieu-Daudé
2023-09-29 21:06   ` Richard Henderson
2023-11-28 16:42   ` Igor Mammedov
2025-01-16 18:05     ` Philippe Mathieu-Daudé
2025-01-16 19:02       ` Philippe Mathieu-Daudé
2025-01-22 14:20       ` Igor Mammedov
2023-09-18 16:02 ` Philippe Mathieu-Daudé [this message]
2023-09-29 21:09   ` [PATCH 07/22] exec/cpu: Introduce the CPU address space destruction function Richard Henderson
2023-10-02 11:03   ` Salil Mehta via
2023-10-02 11:03     ` Salil Mehta
2023-09-18 16:02 ` [PATCH 08/22] exec/cpu: RFC Destroy vCPU address spaces in cpu_common_unrealize() Philippe Mathieu-Daudé
2023-09-29 21:10   ` Richard Henderson
2023-09-18 16:02 ` [PATCH 09/22] target/arm: Create timers *after* accelerator vCPU is realized Philippe Mathieu-Daudé
2023-09-29 21:17   ` Richard Henderson
2023-09-18 16:02 ` [PATCH 10/22] target/hppa: Create timer " Philippe Mathieu-Daudé
2023-09-29 21:19   ` Richard Henderson
2023-09-18 16:02 ` [PATCH 11/22] target/nios2: Create IRQs " Philippe Mathieu-Daudé
2023-09-29 21:20   ` Richard Henderson
2023-09-18 16:02 ` [PATCH 12/22] target/mips: Create clock " Philippe Mathieu-Daudé
2023-09-29 21:20   ` Richard Henderson
2023-09-18 16:02 ` [PATCH 13/22] target/xtensa: Create IRQs " Philippe Mathieu-Daudé
2023-09-29 21:21   ` Richard Henderson
2023-09-18 16:02 ` [PATCH 14/22] target/sparc: Init CPU environment " Philippe Mathieu-Daudé
2023-09-29 21:21   ` Richard Henderson
2023-09-18 16:02 ` [PATCH 15/22] exec/cpu: Introduce CPUClass::verify_accel_features() Philippe Mathieu-Daudé
2023-09-29 21:22   ` Richard Henderson
2023-09-18 16:02 ` [PATCH 16/22] target/arm: Extract verify_accel_features() from cpu_realize() Philippe Mathieu-Daudé
2023-09-29 21:25   ` Richard Henderson
2023-09-18 16:02 ` [PATCH 17/22] target/i386: " Philippe Mathieu-Daudé
2023-09-18 16:02 ` [PATCH 18/22] target/s390x: Call s390_cpu_realize_sysemu from s390_realize_cpu_model Philippe Mathieu-Daudé
2023-09-18 16:34   ` David Hildenbrand
2023-09-18 16:02 ` [PATCH 19/22] target/s390x: Have s390_realize_cpu_model() return a boolean Philippe Mathieu-Daudé
2023-09-18 16:02 ` [PATCH 20/22] target/s390x: Use s390_realize_cpu_model() as verify_accel_features() Philippe Mathieu-Daudé
2023-09-18 16:02 ` [PATCH 21/22] exec/cpu: Have cpu_exec_realize() return a boolean Philippe Mathieu-Daudé
2023-09-29 21:28   ` Richard Henderson
2023-09-18 16:02 ` [PATCH 22/22] exec/cpu: Call cpu_exec_realizefn() once in cpu_common_realize() Philippe Mathieu-Daudé
2023-09-29 21:31   ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230918160257.30127-8-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=ale@rev.ng \
    --cc=aleksandar.rikalo@syrmia.com \
    --cc=alex.bennee@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=alistair@alistair23.me \
    --cc=anisinha@redhat.com \
    --cc=anjo@rev.ng \
    --cc=armbru@redhat.com \
    --cc=atar4qemu@gmail.com \
    --cc=aurelien@aurel32.net \
    --cc=bcain@quicinc.com \
    --cc=berrange@redhat.com \
    --cc=bin.meng@windriver.com \
    --cc=cfontana@suse.de \
    --cc=clg@kaod.org \
    --cc=crwulff@gmail.com \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=eduardo@habkost.net \
    --cc=farosas@suse.de \
    --cc=gaosong@loongson.cn \
    --cc=groug@kaod.org \
    --cc=iii@linux.ibm.com \
    --cc=imammedo@redhat.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=kbastian@mail.uni-paderborn.de \
    --cc=kvm@vger.kernel.org \
    --cc=laurent@vivier.eu \
    --cc=liweiwei@iscas.ac.cn \
    --cc=lixianglai@loongson.cn \
    --cc=luc@lmichel.fr \
    --cc=maobibo@loongson.cn \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=marex@denx.de \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mrolnik@gmail.com \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=salil.mehta@opnsrc.net \
    --cc=shentey@gmail.com \
    --cc=shorne@gmail.com \
    --cc=thuth@redhat.com \
    --cc=wangyanan55@huawei.com \
    --cc=yangxiaojuan@loongson.cn \
    --cc=ysato@users.sourceforge.jp \
    --cc=zhiwei_liu@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).