Received: by 2002:a17:906:eec5:b0:a5d:17e5:aef9 with SMTP id wu5csp1753157ejb; Mon, 20 May 2024 16:35:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUMFVnZMa45mHUwTwRSmiVy3M5Ntpdo8vH/QOlW0Nk2BpWmkWDkQlUe7F+UOPt3BYkXrURVRYanWkN8CznnuMkWRMYn4jS6 X-Google-Smtp-Source: AGHT+IH+VrR4QUGPYYPJyulcq5R/o9RtaCCu+IgA4OAuhROytMPgiDtbJH9vRxpi7Rzh0TaQVIoo X-Received: by 2002:a5d:5b8d:0:b0:34d:a738:798c with SMTP id ffacd0b85a97d-3504aa66a56mr19726797f8f.64.1716248145409; Mon, 20 May 2024 16:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716248145; cv=none; d=google.com; s=arc-20160816; b=kE2H017YId+yFWTQLwVSqalKwwJQuGz2CM3t5qxr5QIY35vnRIK37T66GrbMUDQnBw SLFKRbYGHC05a1S5eg+NMnwYqsf4dlhK6tL1TGcubSqmwpz6Fy5nJTOfSykI1CofJ2vM CDQ/HLoKf/nFmvlO+32XPpBCIWeOqgbK2jQsNv8VdzSACqpf8pQX/+uxvJYHlnH0knF2 RZ4WPAz1zOx8GIjalX78nQSU0+fIwOUMyPvwZuQLLn5r7Sm3C/VzMUA0W1Mkxfd1loCJ noS/WTy3eYFrzBZZOAqjZojbc/BsyDNDJ81X4PLO8z+qsosJUbpPg0XOhER+705Ka4Cv WyXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Kbp3lWXuKoYK8bc+4BNhpBDv+ayDXaYg3uuzWeL4Agc=; fh=H0Ocb1F6OX7lJ2ZIq00L95YQd0stuI+T6mW0qgz5F80=; b=oM3xWBm860BxcCGh5JJMVUTtIhZbhr7a8qJ7qGEpH3lzPxr6zkPV1BaeHimcEtzdbe B60zsKJjE38qwetoJvC8Ki3kyz3Hu60ilYKDJ8HjdZxFjUka/sQtXVK72Ml9nFFoU2KK 5iYtkPX2tOvHtpiNmTa0c9G24MXlODGbctRsDjl4Eb9KAhJOfCCS1dpDm0DZrSgP6m5K Wao3xozeJcZAPS6qLulaM3IeFQgVpUBEryTzo5QyenX5rPYQtvmFsejbYyisn7s23NWT 6yIV6okUuvSJxezOwLMj1Oo48ID1uPOHCe3oxOxCbQqfdYRbN3t8TRLs7rDO+JXH3PLk Vmcw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of salil.mehta@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=salil.mehta@huawei.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from frasgout.his.huawei.com (frasgout.his.huawei.com. [185.176.79.56]) by mx.google.com with ESMTPS id ffacd0b85a97d-354c5b948casi1777268f8f.70.2024.05.20.16.35.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 May 2024 16:35:45 -0700 (PDT) Received-SPF: pass (google.com: domain of salil.mehta@huawei.com designates 185.176.79.56 as permitted sender) client-ip=185.176.79.56; Authentication-Results: mx.google.com; spf=pass (google.com: domain of salil.mehta@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=salil.mehta@huawei.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Vjv744rVsz6J7L4; Tue, 21 May 2024 07:34:56 +0800 (CST) Received: from lhrpeml500001.china.huawei.com (unknown [7.191.163.213]) by mail.maildlp.com (Postfix) with ESMTPS id 4F9F3140516; Tue, 21 May 2024 07:35:44 +0800 (CST) Received: from 00293818-MRGF.china.huawei.com (10.126.174.235) by lhrpeml500001.china.huawei.com (7.191.163.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 21 May 2024 00:35:22 +0100 From: Salil Mehta To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Shaoqin Huang Subject: [PATCH V10 6/8] physmem: Add helper function to destroy CPU AddressSpace Date: Tue, 21 May 2024 00:32:39 +0100 Message-ID: <20240520233241.229675-7-salil.mehta@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240520233241.229675-1-salil.mehta@huawei.com> References: <20240520233241.229675-1-salil.mehta@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.174.235] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To lhrpeml500001.china.huawei.com (7.191.163.213) X-TUID: +z8fT7sI3YnO Virtual CPU Hot-unplug leads to unrealization of a CPU object. This also involves destruction of the CPU AddressSpace. Add common function to help destroy the CPU AddressSpace. Signed-off-by: Salil Mehta Tested-by: Vishnu Pajjuri Reviewed-by: Gavin Shan Tested-by: Xianglai Li Tested-by: Miguel Luis Reviewed-by: Shaoqin Huang --- include/exec/cpu-common.h | 8 ++++++++ include/hw/core/cpu.h | 1 + system/physmem.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 815342d043..240ee04369 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -129,6 +129,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 bb398e8237..60b160d0b4 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -486,6 +486,7 @@ struct CPUState { QSIMPLEQ_HEAD(, qemu_work_item) work_list; struct CPUAddressSpace *cpu_ases; + int cpu_ases_count; int num_ases; AddressSpace *as; MemoryRegion *memory; diff --git a/system/physmem.c b/system/physmem.c index 342b7a8fd4..146f17826a 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -763,6 +763,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_count = cpu->num_ases; } newas = &cpu->cpu_ases[asidx]; @@ -776,6 +777,34 @@ void cpu_address_space_init(CPUState *cpu, int asidx, } } +void cpu_address_space_destroy(CPUState *cpu, int asidx) +{ + CPUAddressSpace *cpuas; + + assert(cpu->cpu_ases); + assert(asidx >= 0 && asidx < cpu->num_ases); + /* KVM cannot currently support multiple address spaces. */ + assert(asidx == 0 || !kvm_enabled()); + + cpuas = &cpu->cpu_ases[asidx]; + if (tcg_enabled()) { + memory_listener_unregister(&cpuas->tcg_as_listener); + } + + address_space_destroy(cpuas->as); + g_free_rcu(cpuas->as, rcu); + + if (asidx == 0) { + /* reset the convenience alias for address space 0 */ + cpu->as = NULL; + } + + if (--cpu->cpu_ases_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.34.1