From patchwork Tue Jan 28 14:21:50 2025 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: 860405 Delivered-To: patch@linaro.org Received: by 2002:a5d:6b8c:0:b0:385:e875:8a9e with SMTP id n12csp375669wrx; Tue, 28 Jan 2025 06:22:55 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVk8+rAn+NDxFlZ4fdEGNpuk6zzYf6BFxGaAKrKOPFCFNVmkvmwL0fMIJIb8gfeSIQZ5xoXcA==@linaro.org X-Google-Smtp-Source: AGHT+IF4tOdgcWMsaTYgFSKvpYXGyjhR//HCLchdsnCacqNV1y8a1cQy7ff1ytBehWE/msTw3Z35 X-Received: by 2002:a05:620a:2a0a:b0:7b1:4547:4910 with SMTP id af79cd13be357-7be6321c579mr6680406485a.20.1738074175301; Tue, 28 Jan 2025 06:22:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738074175; cv=none; d=google.com; s=arc-20240605; b=iEBKqnG9hgxwLXJ+QsjoA3mSehyUU1ugHY/nBMnX7VhDy1pJSqJMTxxk+M8taRjSlv 8A4GhanQiqtxPVwUlHQPFnzNUteQNsf7qGJvHvyr1C3BA6u72OuXZQ0YVy+mP2A/nmKt 8QNdIigqMMlgMKOZwnvjoWpBwK/AYm0AyNC+NE1jaiV6AFnxjoIkGG7FV3DlJvG/5Fhv 6xOSM0Dl4hH0Y22U0vioryJULuRS4pOHHWk41HYJ1OIBUQ9oFppMrOW24vTx8m/7DlWl Te2QmCF9HOyDOngP2HH7fR/ByLxpoAP5+ufr4h+NzQrEFHjlcrt9M8d+KeawtnOg0FNo u9GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=fwXtzSsp3Wrsq7TzutaYeT0jWiU8kps8I7b8yY/9nhU=; fh=U6T2d4RqSCGJNf6LOIblgdoe4xaHu2Qwae+meUOhpik=; b=bAKL4qFKJTR1ITym0H5+NuuSxVHA/EF0j2tSLBkosG56TjA7gq1oFoPy5Hy1zWZaZg OOzpN9YrSN8XeUr876KzuwkIpjIXST50QI1+gxPA42/7fCNkLy3wFfzVEqE4+XEXepkI cnYrjvt+uh2PzDl96fU0SzNsJ7p4nQuKHo26wQWomBLhOy18wx7UjdJUVyVEeMwG6Plt gQsXvWEi3cTw/6ZjiUCuMnFTMAdBnc6vgLJlq8gdXhMNQYIzALx6tYxGUgWGmk2O8c15 7h5BzphhpaNEhSAnRiTp+bhwrnbNOOiM+xLuoftUzWcWBHpedfngAr9/q8pAR71M7EsS CkTg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vR+5kYOu; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7be9af117bfsi1414383585a.502.2025.01.28.06.22.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jan 2025 06:22:55 -0800 (PST) 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=vR+5kYOu; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcmUJ-0008KG-TO; Tue, 28 Jan 2025 09:22:48 -0500 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 1tcmU5-00089B-FX for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:36 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tcmU3-0002Mt-JZ for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:33 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4361b6f9faeso36461625e9.1 for ; Tue, 28 Jan 2025 06:22:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738074150; x=1738678950; 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=fwXtzSsp3Wrsq7TzutaYeT0jWiU8kps8I7b8yY/9nhU=; b=vR+5kYOuo5nLCtHiXUYmRklsOoNxvJ322cR1L7dRRdsUyiqqm457bwG3T4P/beoCK9 vSQ2Z2jwwn4m9CHtLFVGrElEf+HCGiLxUgXVRx0Fva8qvklK8JllId2IVVUtgVOjKTc9 bqxLNDTesKDfcFaSEd9mbgHytoaODMK18PNX3JRwYwvj6hYjsK/jYuwEbnUJriq4AMOz 9YqLaJSkq8FekObaC1FvZqLKUcGPO4KnJ7Tm+oOCaWZ1KuEReV6BJ5Nfs7IYD36NxQlA rEQZhfTG67z/9BrhbKOx9UfX2bksJy04uxqb/YAmJ0nxNEaYzSLihVCWUmfWhbGt0mLs Lm0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738074150; x=1738678950; 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=fwXtzSsp3Wrsq7TzutaYeT0jWiU8kps8I7b8yY/9nhU=; b=tW7SvLV2GTkV6Fk7QM6INe/vx5xj7/bFUbV97lRuuNzKCQFJ5Ka2sUOP6UL4xYK7RU qp6FOC3qtyJF7QS9nv6G19biqumSHifbJGBg5uikdqhgc3eHyEjCG5E/+FIky/sddh/x QPiFu7VXY9S9hA8v2eojQelfJPqtXXmBqMPu7fRm/75ikBcw/hTm7KaKPFS1CmQDRqW+ xo41V/LPZBRSUoiWSxAcUas/zeyQ98YdXCY7x8Jk2Kp6riRTY4UiJWqdf0jpKLkwWBhv EahXfgBYIFziDQ1du7yOg0JMsBZkoyJaoHA4i+noRiqVND79KJtV35EMgNOlG40u9Ujy wyqg== X-Gm-Message-State: AOJu0YyU4VLK9UelG+qWVKXhbtpnxGyqSjWtD+qb2ly5X4/rY2t2+xT1 gZ4pA5JEO1tVH2706Ki/jaKGX9oDRrc152Jv0UKKBZIJnsG7qbMxZQMuSA+f77XDXTr4cDPs3Qd 6reM= X-Gm-Gg: ASbGncuRMa007jYHrANpXPvKv/8Nch7TelXd1lP+09+rjIslxJZFfc7X51Lm/lVDglQ DrikQDHKt3RuBle13j77jvw9VUevh5ZjcHU+NY69gAoWSfMr+YqElei+MqBFtC2tcomiFLLcXwk 4kNhWbk2vasuwXwxbHOP+AB1ua7ztx1S5J1YGzLNbPb9nGuZ19f0FgdJc09rOavsh1O/M8Jtgje T23GXkT0CGU0HmXOEogDexBC8CCaTV2vdOrfoHmDX3SvKObYYj/s3MbyQn58LLFpvzznbukSl3l sgqOiOhAGbTftNTYSnG7p208eyA7CSe/t98nY1fuDAFBVBgI28ZD0uHWMl4b97755Q== X-Received: by 2002:a05:600c:46d2:b0:434:f1bd:1e40 with SMTP id 5b1f17b1804b1-438d596d1bamr27108845e9.6.1738074149822; Tue, 28 Jan 2025 06:22:29 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a17d7bfsm14358242f8f.35.2025.01.28.06.22.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Jan 2025 06:22:29 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Peter Maydell , Yanan Wang , Eduardo Habkost , Harsh Prateek Bora , kvm@vger.kernel.org, Zhao Liu , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Markus Armbruster , Igor Mammedov , Marcel Apfelbaum , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Paolo Bonzini , Richard Henderson Subject: [RFC PATCH 7/9] cpus: Only expose REALIZED vCPUs to global &cpus_queue Date: Tue, 28 Jan 2025 15:21:50 +0100 Message-ID: <20250128142152.9889-8-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250128142152.9889-1-philmd@linaro.org> References: <20250128142152.9889-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philmd@linaro.org; helo=mail-wm1-x32f.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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 cpu_list_add() was doing 2 distinct things: - assign some index to vCPU - add unrealized (thus in inconsistent state) vcpu to &cpus_queue Code using CPU_FOREACH() macro would iterate over possibly unrealized vCPUs, often dealt with special casing. In order to avoid that, we move the addition of vCPU to global queue to the DeviceWire handler, which is called just before switching the vCPU to REALIZED state. This ensure all &cpus_queue users (like via &first_cpu or CPU_FOREACH) get a realized vCPU in consistent state. Similarly we remove it from the global queue at DeviceUnwire phase, just after marking the vCPU UNREALIZED. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- cpu-common.c | 2 -- hw/core/cpu-common.c | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cpu-common.c b/cpu-common.c index 4248b2d727e..72ee8dc414e 100644 --- a/cpu-common.c +++ b/cpu-common.c @@ -91,7 +91,6 @@ void cpu_list_add(CPUState *cpu) } else { assert(!cpu_index_auto_assigned); } - QTAILQ_INSERT_TAIL_RCU(&cpus_queue, cpu, node); cpu_list_generation_id++; } @@ -103,7 +102,6 @@ void cpu_list_remove(CPUState *cpu) return; } - QTAILQ_REMOVE_RCU(&cpus_queue, cpu, node); cpu->cpu_index = UNASSIGNED_CPU_INDEX; cpu_list_generation_id++; } diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 8a02ac146f6..df7a6913603 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -218,6 +218,8 @@ static void cpu_common_wire(DeviceState *dev) { CPUState *cpu = CPU(dev); + QTAILQ_INSERT_TAIL_RCU(&cpus_queue, cpu, node); + if (dev->hotplugged) { cpu_synchronize_post_init(cpu); cpu_resume(cpu); @@ -226,6 +228,9 @@ static void cpu_common_wire(DeviceState *dev) static void cpu_common_unwire(DeviceState *dev) { + CPUState *cpu = CPU(dev); + + QTAILQ_REMOVE_RCU(&cpus_queue, cpu, node); } static void cpu_common_unrealizefn(DeviceState *dev)