Received: by 2002:a17:907:8744:b0:9bd:85f7:2662 with SMTP id qo4csp324646ejc; Wed, 11 Oct 2023 12:47:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFh3euasITsK0I1YaqjnJ//NRI4xVVrm7wZwuby0Eot2RLOthLM8C7Z4e5L1NCo+/Qqx/b X-Received: by 2002:adf:f452:0:b0:31f:fed4:d79d with SMTP id f18-20020adff452000000b0031ffed4d79dmr19695169wrp.30.1697053627781; Wed, 11 Oct 2023 12:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697053627; cv=none; d=google.com; s=arc-20160816; b=VIjuXufLez4VV50pu/qBUYpVJMK6AnlwFW/OaHYTS5Ip4o1095P+NNvPKWj+yiyc4P aS5PWutDJBwFugNl1+NNtdyrANFeTQnpu87vS53+FFAkwMoVjD3rndvmD6AfCrVBjqN6 qj3ZA8CwbEVubb3zzwiebYNNb9TPRzDEeRyxQ5tje8gz6Ex4v/XFAHfq2RRQexYrR2zC CXLbbBnax8xFSzawpsp5HhZCZr1Ni4RZRzLMxrAUJfXYZQAbNZ8f46VCPJ7bNqczP90l dZM8JP8y42/ZIC9fcB9iHBUOFXSu+U/wBtZCxvgh+0PT71jaIwjIHuj1xXlpI2CX7Sma KC7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=shmbEgZOU+ojyyZlYeVxZsb05THA5ctiaTkio0PArXo=; fh=I+6CS2uJqPEgP3gz8gmk6tLbm1jsmO9tblK+QTjWHxs=; b=jWL5BjV9NJnKNlGKWPDy0lB6N+JfWSam5CdX0mxqzDfEd5w+AqYyQeEalp2oeXSw2u XkZOLyq2gcvEWHuGji+6S0Kmdv6+0Pmwc2Mu8MoYNFzyRiWgcKjplZWGFP1otlld5Pnt frAF3rbRsFBiZQWSeHFSV0dErgs/gquFwmbmVX54EdyMGM7ApbWDRB+RPNJb4PJWhCCC RBwn4ALu59QNe7qXwx3GB4AG8rz95arREQrD5qgBeJzeYOTGCsYv8TrQnSJpIL1AcS81 yTcEd9CHVHZTgZdiRDTnuW7Louzphg+2ypfAJyyv4a4APX0gVTJyjxxIxCOVIkJciLlc v9Dw== 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 z7-20020a056000110700b0032d56bd29c0si1822521wrw.677.2023.10.11.12.47.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2023 12:47:07 -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 lhrpeml500001.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4S5NZF0cjkz6K7F5; Thu, 12 Oct 2023 03:46:45 +0800 (CST) Received: from A190218597.china.huawei.com (10.126.169.226) by lhrpeml500001.china.huawei.com (7.191.163.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 11 Oct 2023 20:46:49 +0100 From: Salil Mehta To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH V5 8/9] physmem: Add helper function to destroy CPU AddressSpace Date: Wed, 11 Oct 2023 20:43:54 +0100 Message-ID: <20231011194355.15628-9-salil.mehta@huawei.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20231011194355.15628-1-salil.mehta@huawei.com> References: <20231011194355.15628-1-salil.mehta@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.169.226] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To lhrpeml500001.china.huawei.com (7.191.163.213) X-CFilter-Loop: Reflected X-TUID: GFN4U4kMi1cv 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 --- include/exec/cpu-common.h | 8 ++++++++ include/hw/core/cpu.h | 1 + softmmu/physmem.c | 25 +++++++++++++++++++++++++ 3 files changed, 34 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 648b5b3586..65d2ae4581 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -355,6 +355,7 @@ struct CPUState { QSIMPLEQ_HEAD(, qemu_work_item) work_list; CPUAddressSpace *cpu_ases; + int cpu_ases_count; int num_ases; AddressSpace *as; MemoryRegion *memory; diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 4f6ca653b3..4dfa0ca66f 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_count = cpu->num_ases; } newas = &cpu->cpu_ases[asidx]; @@ -774,6 +775,30 @@ 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); + g_free_rcu(cpuas->as, rcu); + + if (cpu->cpu_ases_count == 1) { + g_free(cpu->cpu_ases); + cpu->cpu_ases = NULL; + } + + cpu->cpu_ases_count--; +} + AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) { /* Return the AddressSpace corresponding to the specified index */ -- 2.34.1