From patchwork Mon Sep 18 16:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 724168 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp1774805wro; Mon, 18 Sep 2023 09:07:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMFPfc2IumnqryYsm7Z9GU9/tPTSXUqSO/ZcmGjYRTgZCsXgXKg86TgOkhkPErmtakkXyZ X-Received: by 2002:a05:620a:2ac4:b0:772:63e5:5ab8 with SMTP id bn4-20020a05620a2ac400b0077263e55ab8mr8975146qkb.3.1695053246145; Mon, 18 Sep 2023 09:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695053246; cv=none; d=google.com; s=arc-20160816; b=VdEr0bQ0lGkJbwbBG9Y3MEyHrypwCLte9okR4o5jsOuDzL9DOATQ9NceFb1pWN2F3l emWTvKK6K4ovDt4KQMkNY72DQRmADb9CEWW/j9o9hZMBFw53Sw2sBgjTLzoELggWKS5S BWyQ6F8i7KK/uXM+kGgGvWyUaGXd+gJUyHLxM2IYUNme0GV6HsNKEdQuT7S2Qr2pQIIp 8924O/UggxVk5MghQn653dtdXLU+VB1JOA1W9RE+97IUiwQ25UQYLwX6wWgIX89NmTiF NH0unleeDOXR7pjXjO80nmiysqSUekb9G0XldAsYJankjWW24+tzUuSlTkbfu82WRRBI M7dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kTBjPJZgBk13UdBUXwIisPTyIoW0XcuNCZty165NaD0=; fh=9HVYub9IUdGxYx1Tdl+8JO5e/0dtoki6g0y7v7HxI1I=; b=YXCsk8c7cXaF9LJJ/bTBVAagah68JIdglprErp5VBnJPE8fBMaqmNOMnBBxO+kGJyi lx30yJk+DIGWuqSUfOCIsN14nQD3WwCpPUPT+2xx/dIinUF15s9BLu8IcYHm3MBlFQFh ia/bc0etLyF8B2zRftpqdnr1fRU7148jVCMqjBsuKvOuAF7aKRZLve2RTVdJzrkQU4Hr AKkYla+Xr99zZgJ7SUPQQYmDr/yktAOHfVlDh/ZRYYBp/6tRL5iPCCWzRIfY3FGiowMz ARLl8jWIi3Q6V3chnSVpB49TlzzRhg3kPEqOnz/PMWqmZ15o+kd6khD194KQXBv5KrBC h2UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QFuhLp+w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j16-20020a05620a411000b0076d9e089c17si6503318qko.664.2023.09.18.09.07.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Sep 2023 09:07:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QFuhLp+w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiGjY-0007xZ-Ex; Mon, 18 Sep 2023 12:04:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiGir-0006VB-6U for qemu-devel@nongnu.org; Mon, 18 Sep 2023 12:03:42 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiGip-00043Y-1c for qemu-devel@nongnu.org; Mon, 18 Sep 2023 12:03:40 -0400 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-52683b68c2fso5743554a12.0 for ; Mon, 18 Sep 2023 09:03:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695053016; x=1695657816; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kTBjPJZgBk13UdBUXwIisPTyIoW0XcuNCZty165NaD0=; b=QFuhLp+wh9+g5gFDuBLFnLYe2X4wpVF9jcpDP1fBhMC0HG5Lgo8XwfaZ6KOqwW5VC/ BIPXFMYu/wMCwDAp4w1//5OijDv9+41EH1IOLRN/+yaMMAADwqJGctrB9YTC7fPN6tAJ m/dW7vgUVZvYsHMg6dMJnlc88iuk7D4DIaSO7+qBj19+p7+fwK05ZqKWks5RO1jQzwv+ A03MpQefzC/ZRpey6EgqZH++C8OXLfk37f4tIp/adk4gu3i5xu0hUgDeeCInJeYfYL/J uaeY0lTV2YNit5RpU0MUaL1nXwmgaPg/pNsQ3s8xXf9txi54uqUTlxiVwlBtAcgvjPoG X2CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695053016; x=1695657816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kTBjPJZgBk13UdBUXwIisPTyIoW0XcuNCZty165NaD0=; b=XXw70mIo/ILkjorH/8k1DuhsqkwRJFj+cyFIQqHMDIYGmLrwPx3wg1DAzTKWO+roRy OnSMVxh9pHrPCTPZ7SmSwn4h8DmTWq9Ah7Eg5YYmeyK0NZ4K/BB+AbiK+/GMf4fAcy+M d4j7Kf1eOIWXsjTjnOKS0nMDNTResG2hIFBjH25ElPla277cL6gFgzkA5FWtzQAA+v4b 2EQDJp2dlVGbe1qdeGeeWCLdSppdPqjsSQG6IZc8suoPx0M08SOO2xYm8GtGwfve32dn BLGfUOAWZjCLZyhSgqR3VD1MCW+z48ONM6jUMF95GBz4MyWbTzpSpD0kADxmlyvFKOzY EEgA== X-Gm-Message-State: AOJu0YxXYOG81QqgV0VbI0frxXSu8ut3V4YBfAKd2Ja8Vyq78Hcyz36w 1nsBNTl5fJ1aNLqkcacKU8lqENimHMfDc9BQOMazs1hW X-Received: by 2002:a05:6402:1bc8:b0:530:be79:49e7 with SMTP id ch8-20020a0564021bc800b00530be7949e7mr6068787edb.37.1695053016011; Mon, 18 Sep 2023 09:03:36 -0700 (PDT) Received: from localhost.localdomain (static-212-193-78-212.thenetworkfactory.nl. [212.78.193.212]) by smtp.gmail.com with ESMTPSA id eh16-20020a0564020f9000b005256aaa6e7asm1688491edb.78.2023.09.18.09.03.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Sep 2023 09:03:35 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Max Filippov , David Hildenbrand , Peter Xu , Anton Johansson , Peter Maydell , kvm@vger.kernel.org, Marek Vasut , David Gibson , Brian Cain , Yoshinori Sato , "Edgar E . Iglesias" , Claudio Fontana , Daniel Henrique Barboza , Artyom Tarasenko , Marcelo Tosatti , qemu-ppc@nongnu.org, Liu Zhiwei , Aurelien Jarno , Ilya Leoshkevich , Daniel Henrique Barboza , Bastian Koppelmann , =?utf-8?q?C=C3=A9dric_?= =?utf-8?q?Le_Goater?= , Alistair Francis , Alessandro Di Federico , Song Gao , Marcel Apfelbaum , Chris Wulff , "Michael S. Tsirkin" , Alistair Francis , Fabiano Rosas , qemu-s390x@nongnu.org, Yanan Wang , Luc Michel , Weiwei Li , Bin Meng , Stafford Horne , Xiaojuan Yang , "Daniel P . Berrange" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Jiaxun Yang , Richard Henderson , Aleksandar Rikalo , Bernhard Beschow , Mark Cave-Ayland , qemu-riscv@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , Nicholas Piggin , Greg Kurz , Michael Rolnik , Eduardo Habkost , Markus Armbruster , Palmer Dabbelt , xianglai li , "Salil Mehta" , Igor Mammedov , Ani Sinha , Bibo Mao Subject: [PATCH 07/22] exec/cpu: Introduce the CPU address space destruction function Date: Mon, 18 Sep 2023 18:02:40 +0200 Message-ID: <20230918160257.30127-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918160257.30127-1-philmd@linaro.org> References: <20230918160257.30127-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=philmd@linaro.org; helo=mail-ed1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: xianglai li Introduce new function to destroy CPU address space resources for cpu hot-(un)plug. Co-authored-by: "Salil Mehta" Cc: "Salil Mehta" Cc: Xiaojuan Yang Cc: Song Gao Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Ani Sinha Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: "Philippe Mathieu-Daudé" Cc: Yanan Wang Cc: "Daniel P. Berrangé" Cc: Peter Xu Cc: David Hildenbrand Cc: Bibo Mao Signed-off-by: xianglai li 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 */