Received: by 2002:a17:504:3f1b:b0:1be9:327d:8ee3 with SMTP id x27csp100593njk; Tue, 16 Jul 2024 04:17:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW+D/4tyJ+/ftLsXz8ZVBKAZplHcaWG6u1PgMc79hGn19NDaxwJd6uT9/VB/Rf+a51e1WJLJOV5KHLeemI0B999pJ3LmULo X-Google-Smtp-Source: AGHT+IEzlvUSwSBfthNWeDGeJJdiajICT0cxCpE7QGoLrK+Ht+HPa9m0truDqspcWu3xhHbdQMhK X-Received: by 2002:a05:6358:9144:b0:1aa:d71f:692a with SMTP id e5c5f4694b2df-1ac90325d21mr168912055d.5.1721128650616; Tue, 16 Jul 2024 04:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721128650; cv=none; d=google.com; s=arc-20160816; b=s1qsyXJ/ObG9c3nQQ5eFRB6XuK77ryHsZ/xtVuuZ2w7dQWrUkZ0VEJabInBVCpgbmg wewFx5K3Z8vlbZRtD8v88JVVBWJeDCCnzt8r+OvdQaYChGsGU/C10xYMPP9V29X3mopI xB2Z13zGoW3uMVnIJUYGcsq3VTQQNqXNq+ZmnH3vrVbuB5Wno7JXg+bN9pVKlySpWOqj aYsoarC2NIpR0A7mEIgHUitCdHrsw0oZm+FtJQRYodbby/EivmEH+t+HmjD2SvVQtvt/ 0N+7xADf15ZQ9Rf4b6UZolssIbxBO/4Hw9YVjOwXiuOerXIU6O17IoELrRjVaxb6dKIQ NOhg== 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=cipL7I7uy7Uk2G6r6NauJqHvxrwXOxLhYjnxNZYTsGI=; fh=CjFwyFzaCSmkOKy2YiKnMv5LVRyC5Im7ETbbL0XKxCE=; b=lAjhNDWNAGyXXS4C5JjqD+XIXp2D2yEsjSdWVpcvpOnvA/CVheqVmNxUyakn0nvpXP 6H4XEJeX6jJViDsHozECs1BO1IPbjC2lHcw3UwB6UOnj/vLSSJFZa7tK4QZRO1YNnzEq 3RfLnLwUETO26YUh8yaayiEjRbBqvMeNC/Z8cCYPoWAlK6KAWUlxu6WvlzuzUgLq1EfM xy0bjB0iCS6Mc2CTiUk0LrlVcGFbxRYiwSgEPv/UzZXQoqmROo7sP0b38/ni2Nd2lU86 7eQnxcQ6ZqO2A68REjK7hak/JrwhSS8zF6PzQHmdp+f+QSl7NAsDbHbOwkIP7r4c8/BM jN1g==; 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 41be03b00d2f7-78e43192d0dsi6622238a12.487.2024.07.16.04.17.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2024 04:17:30 -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 4WNc2L6mxyz6JBF9; Tue, 16 Jul 2024 19:16:10 +0800 (CST) Received: from lhrpeml500001.china.huawei.com (unknown [7.191.163.213]) by mail.maildlp.com (Postfix) with ESMTPS id 4B9001400C8; Tue, 16 Jul 2024 19:17:26 +0800 (CST) Received: from 00293818-MRGF.huawei.com (10.126.170.92) 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, 16 Jul 2024 12:17:08 +0100 From: Salil Mehta To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Shaoqin Huang , Zhao Liu Subject: [PATCH V16 6/7] physmem: Add helper function to destroy CPU AddressSpace Date: Tue, 16 Jul 2024 12:15:01 +0100 Message-ID: <20240716111502.202344-7-salil.mehta@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240716111502.202344-1-salil.mehta@huawei.com> References: <20240716111502.202344-1-salil.mehta@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.170.92] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To lhrpeml500001.china.huawei.com (7.191.163.213) X-TUID: LjvVd7FfZD8d 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 Tested-by: Zhao Liu Acked-by: Igor Mammedov --- 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 a2c8536943..c7dbfdfb11 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -496,6 +496,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 14aa025d41..ddd1fc3a25 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