From patchwork Tue Jan 28 14:21:44 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: 13952589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA573C0218D for ; Tue, 28 Jan 2025 14:22:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcmTf-0007kh-HX; Tue, 28 Jan 2025 09:22:07 -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 1tcmTc-0007jf-VI for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:04 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tcmTa-0002JG-N8 for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:04 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-436ce2ab251so37750095e9.1 for ; Tue, 28 Jan 2025 06:22:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738074119; x=1738678919; 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=kO0uRE/b6a4B7/JlExmMlApMO3OGmNzh+eMs/4hpwh4=; b=q7YwtX2ev05otBtPPal4VgwXNkUdUzIcKGUN0z8E4z4izdflPyA4XNYwRd0MRtmBbD 2QUrmzA4Y15K97GXt6AiRj2Hz6acI9aWQYsaZg+LS1vbrFv+v6hqzEekjbDwEXCYq9WV TbPhm92DzwPaAysLlwe/I6JFfGAOZ9VhWXzKNpdvvnBbfbCqo+kao74dggbmufamN60e llz8hCbVxipkFHu5FsWBvGeUhFQx0NYU90M4F73N4RhxuTwtpc1cTfTVFLzb0TQXxk+D QWoBGMefaaWkMYyCfvXIBplfC3rFBd6hLyjWI3rDOWJILetpZpUA7zhmuAyHZhoXj3fv 8yxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738074119; x=1738678919; 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=kO0uRE/b6a4B7/JlExmMlApMO3OGmNzh+eMs/4hpwh4=; b=lTFHvF7jjIpl3MIDVuQqkZRaIVGCIKC70H1u/wRUVx8QfwkQyylrZHhNWEkhU1KYPn w6CLrfcyn6s/ot6z4TIK3ixziCw9/C3nInA2EszGD0a/4yVf2t5slggkGPq+H473FO0D FQgNRPmW5mP+0GdjhnmZHvbzyDA04yuUzC/2Y4HcjUfPwbgGX8O/BKIdDhChQ0P8kIYM xWqf5rjuCU+LppkdpmDaZw3g20MPJI/DPlMPDSoqgS9IShau2h1Rm1o8LT8ONzieg9TN t6lBi+qD8hd7DfptSj5D+JuaxiW/Ui0P56aYg/Iq1cVJJTzBnVWOeL0I8Yb+MMQel+hb G/sw== X-Gm-Message-State: AOJu0YxALG2WWmRogHh2iTv0Y2EC0fOiRxL4WHRAlmrB9CgdLMcFM0Xq 0cD69Zqc/c9+bpTxyozmketcpGo7bBI0XfURP/bGJpf3PE0qCV/mETeYowKmTJnIYoq8Ik8KqmJ bkus= X-Gm-Gg: ASbGncvuI0jFWQZWtuf/HY20A/2SQpZPhrw2nU7lQGJhsv4ALwO9A87ASjQatJxJClC l8ivtDBtBHis3nKz5M4Bj6TwsCAyzV9TRYF4BjyuXTNMTmVZSCaeDFXKXLfTys1/sCj4QX+0rzT vBwksLn8gwqZQjQtS1d+EMRp5LqtFCXC2nn/qWv7daWLPuBiQfFZcRkWcLCtcy5B/AHvrsbJl2F tH2uSqMFT7M+u4WGQfpx+MUd8M0m/xLdIbBZM8d5pMVGxLjFFKEV+I3KbyxqPjNLf54gOvFRL4H GO3b42rMujgaP6dLvRJtI/jhAo/bxADMiTPsPjRrn8rASkdzxlNUjnPVhxdUIiFhTrKD0nA5YBF N X-Google-Smtp-Source: AGHT+IG02KmwhuUT6IfvBlK1pHwLP8uF0g7mnNTy6Q9yhDmta3+GBFm8pcBIROf6lvdBXsr32dkLzA== X-Received: by 2002:a05:600c:4e89:b0:434:f739:7ce3 with SMTP id 5b1f17b1804b1-438913cb518mr403560625e9.8.1738074119339; Tue, 28 Jan 2025 06:21:59 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd47f0fdsm174363075e9.5.2025.01.28.06.21.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Jan 2025 06:21:58 -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 1/9] accel/tcg: Simplify use of &first_cpu in rr_cpu_thread_fn() Date: Tue, 28 Jan 2025 15:21:44 +0100 Message-ID: <20250128142152.9889-2-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::334; envelope-from=philmd@linaro.org; helo=mail-wm1-x334.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Let vCPUs wait for themselves being ready first, then other ones. This allows the first thread to starts without the global vcpu queue (thus &first_cpu) being populated. Signed-off-by: Philippe Mathieu-Daudé --- accel/tcg/tcg-accel-ops-rr.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c index 028b385af9a..5ad3d617bce 100644 --- a/accel/tcg/tcg-accel-ops-rr.c +++ b/accel/tcg/tcg-accel-ops-rr.c @@ -197,20 +197,21 @@ static void *rr_cpu_thread_fn(void *arg) qemu_guest_random_seed_thread_part2(cpu->random_seed); /* wait for initial kick-off after machine start */ - while (first_cpu->stopped) { - qemu_cond_wait_bql(first_cpu->halt_cond); + while (cpu->stopped) { + CPUState *iter_cpu; + + qemu_cond_wait_bql(cpu->halt_cond); /* process any pending work */ - CPU_FOREACH(cpu) { - current_cpu = cpu; - qemu_wait_io_event_common(cpu); + CPU_FOREACH(iter_cpu) { + current_cpu = iter_cpu; + qemu_wait_io_event_common(iter_cpu); } } + g_assert(first_cpu); rr_start_kick_timer(); - cpu = first_cpu; - /* process any pending work */ cpu->exit_request = 1; From patchwork Tue Jan 28 14:21:45 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: 13952588 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1BF51C0218A for ; Tue, 28 Jan 2025 14:22:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcmTh-0007lK-MW; Tue, 28 Jan 2025 09:22:09 -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 1tcmTg-0007kj-DM for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:08 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tcmTe-0002Jm-TM for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:08 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-38637614567so2782493f8f.3 for ; Tue, 28 Jan 2025 06:22:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738074125; x=1738678925; 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=seznNsDAaQBVSpbp55D/hE//Nvg+4oVvDGjyXY54BGQ=; b=YRx7DfBT86YHuIWIWgciW0Z6EMmb1wgPrN/a2cJ4JkQxd2riiDxE8vVWb0xviFwUMY 8rHpAbXOmTKlDuX6qcGqhmKprMJ5hSUSqk6F4uIU1YGs+5VZfunB2xQ2jy9hsDafvsKY FtB7ssge/POqp3frHoQCRM+ZQEpGH7iST01nZLKQuTGKTSzgoJ5NKJimHiZBWp12BK+t +JAMi+OfDNXfekI6wOHdfu+xhP0roVefm5SbfOtXc+yCguEeYsoD8/qJlrN/UYStvGLE xGezmuHPRZ4kO2b289IGuKchBT3y9fnsOWR+4eeiKTvXrCnTJh6VLCH1wrjtbMoaOavy WNEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738074125; x=1738678925; 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=seznNsDAaQBVSpbp55D/hE//Nvg+4oVvDGjyXY54BGQ=; b=Pqz9d7uDlO5YuI4BxUKAN4xiZtB1nG83bISSiKbot2LWqAUC5BATnl5+Pr3yn0kqJb 7rq8t4BqzyUUzVBr1zErCxko58IR6zmvuAJhJ7RVhE6yvghOZTgWzRDQVchPIEis6vQp NV7Rj7++teDpVWNlwh/Jrv7v0D0K04zxysy9ip0eMee0l0jVRBvzbm1L5poy0dwqBZDU 13rglu+jD/bOZ1S1yEk7K2j6PKm+mIfUtKiBG41szEDksESLq8qF7jpYnDBmf2IFebpW dFDhHBtzssbnUpB0SOKRMpAeEt1DRP7tlDfaQTDVuINiQ0CeUC3ey+IaTkZxg1D538qm Gjng== X-Gm-Message-State: AOJu0YwTbQb0xlDkZ7UExQBDbiX5qBmtd710mqzYZqN+oulBBowBjGMM 5WBLRi31vP7XCQiOupp79Z9NyX77zpCWi1zhg2/565yGHZoT1UOFiFuVe7veAasuSVX7vO3WLN0 2v3w= X-Gm-Gg: ASbGncs0R1iyHx3Y9xTyQCPuHfRngf7kjFAOutB8g8mxgMZMgLBl1AmrgtMvPRvNPWs 3Tnk9vUCif+ljg0R75fTfIpwTMm0Hl7XbtY/Jp2btk24KB3GRXWRJjyeN4vVJmyLwwtw9s+FGfe /B+JasWM+5w+I3eLZMMMMZtSLxDOqzKeUEB3gRbf9Trt5Sw9hB+EVsQPWpLIeI03i7rbRp3D5Y7 5uCQIVRK8kjCyDbdZ5zWIc1LuU4BJkxSGfKUCH268g0+jwAInomistefWdVchRfxDLKpx77k0Gw WmxqCdQPUfDRUWAJZ8UAiku1SxQFO0ODNeXFLtOd7vPnsT5BN4q1YnEKgRpxdmvsng== X-Google-Smtp-Source: AGHT+IE++a185aCVAwGW9af+PNdrfc3K4O3/zeNI4/CnMV32fBXiZN0yIo7Y1YMI+EEIUBCDGyE+Pg== X-Received: by 2002:a5d:6d86:0:b0:385:df6b:7ef6 with SMTP id ffacd0b85a97d-38bf57c94a2mr50508168f8f.51.1738074124946; Tue, 28 Jan 2025 06:22:04 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd5732edsm169125225e9.36.2025.01.28.06.22.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Jan 2025 06:22:03 -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 2/9] accel/tcg: Invalidate TB jump cache with global vCPU queue locked Date: Tue, 28 Jan 2025 15:21:45 +0100 Message-ID: <20250128142152.9889-3-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::430; envelope-from=philmd@linaro.org; helo=mail-wr1-x430.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Invalidate TB with global vCPU queue locked. See commit 4731f89b3b9 ("cpu: free cpu->tb_jmp_cache with RCU"): Fixes the appended use-after-free. The root cause is that during tb invalidation we use CPU_FOREACH, and therefore to safely free a vCPU we must wait for an RCU grace period to elapse. Signed-off-by: Philippe Mathieu-Daudé --- accel/tcg/tb-maint.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index 3f1bebf6ab5..64471af439d 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -891,6 +891,8 @@ static void tb_jmp_cache_inval_tb(TranslationBlock *tb) } else { uint32_t h = tb_jmp_cache_hash_func(tb->pc); + QEMU_LOCK_GUARD(&qemu_cpu_list_lock); + CPU_FOREACH(cpu) { CPUJumpCache *jc = cpu->tb_jmp_cache; From patchwork Tue Jan 28 14:21:46 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: 13952613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7CD5CC0218A for ; Tue, 28 Jan 2025 14:24:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcmTo-0007nZ-0X; Tue, 28 Jan 2025 09:22:16 -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 1tcmTl-0007mP-I2 for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:13 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tcmTj-0002KR-TK for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:13 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4364a37a1d7so58378195e9.3 for ; Tue, 28 Jan 2025 06:22:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738074130; x=1738678930; 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=cztkPvSxh9km+ESKvRBcfElc50oeVn4euS866OSUDwg=; b=g/hrKUbDRZ7AVGBmJVLbpPOwjUuHc3ttkacePEjqXPWvPziZUc8zZdekcZrmhR4mZw dNCTNGOpBAg0JEMuhDXn3M8mNNnAtdnc9tiSD5ud5KwPFArKD7HjWXcjkQHyOHC5jUR3 oPCBYZb27Xmqy3829TYn0gH3Paw4hpsGMovdoZW1h/qzPfSDhb/pUQvDo/Sk88Qx7yT1 Y0eHJtf3jSHo1L3Si2sBa0tK+8k6k4pX1ing+GZNVwi9pCKfK/BxkIdJoh3txTVHu0+W 1lEeEJJdaGEYyLartzDQftwlrfCFE7CBs7lSSeWOkc0J7/p3JPvzdIlZfEYODlHqI2Jl 9svA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738074130; x=1738678930; 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=cztkPvSxh9km+ESKvRBcfElc50oeVn4euS866OSUDwg=; b=t/BA7hFqbYNiUwA4bJog8IskAS1v5r19fFKcKQ2uj6O2bcbRC3mzV60pMFirLMqRDE 94xNLKB2NswT/k59y0Bi4/iQ+n0ZXKg3pzOrEGW5AZaqDRD5wYMfZHVLdlQXNo4Z/yrh 7Yvq5noKZRN61OFCsTXEMEbHJIeN2Itd0j3XOctLZKvrIDu9v2yS33FVz7DjYdiBrJhD qyOt0eXj6oXIw4kjl4HiJKDYBzt3W7XPJyv2wctSnp1HV+hq5gjk/OEA2efHJXrWiQlk elA6GL/ScmJcbAMhXMzHPCxcNx2ugSNF3G/kM4K42DJ/UTKfvjJNbnOeIfsdc6cDImvJ 1gpQ== X-Gm-Message-State: AOJu0Yyw/UDRjSXc8hXo1J+PFLa3ODGAR1CpLEXzEsbdxUy6FjrLxwXb ITgNACQ/nCSVLYifiapn9b8KcxN8tBDpbpgqfiden9s+SDRCJHPNqcl5t0weanevZLmpkh/nb6x UrdA= X-Gm-Gg: ASbGnctDOkH2a898Q77CasXZEnc9FtJisBVXWCHVSU5aLt4qMS7yf+iuuq8i1d2bOoG udGfHiWEcAXE2j40cgVaXPxN6l6m5Jqv3TuPDzZ1tdwbSfLqHYMK3iAzSxZjQ46KVOooHWFDLOQ Vq3ZMX3TUKSZVRs0w9k8+VKcB+rrNk/05jzpSGvlnq9OxHzPtqQkkGWEir9lgqcVpoNWr/RqNtQ 1oDWsF3ApEOjMLwQ57CRgETdMqNS8O+WSVwpdMQp1nImZrM184hBfLitVNUz5ALSdOL91NkW1sD yPsJb1EM87leZ1EYC+ArMe0THOjDI3F3Lgc6xm9inujmwgyu/pG2cunCr/wg/w46sQ== X-Google-Smtp-Source: AGHT+IHoy1cVhuk2i3/eWFOT57s+jua+XxxBspEQhqzWsAL+PWt7YkjOAw9jQh7HykZ8ESVDxkMIkQ== X-Received: by 2002:a05:600c:4589:b0:436:f960:3428 with SMTP id 5b1f17b1804b1-4389144fbd4mr437166445e9.29.1738074130042; Tue, 28 Jan 2025 06:22:10 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4fa57csm178828725e9.4.2025.01.28.06.22.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Jan 2025 06:22:09 -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 3/9] cpus: Remove cpu from global queue after UNREALIZE completed Date: Tue, 28 Jan 2025 15:21:46 +0100 Message-ID: <20250128142152.9889-4-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::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Previous commit removed the restriction on completing the full QDev UNREALIZE step before removing vCPUs from global queue, it is now safe to call cpu_list_remove() after accel_cpu_common_unrealize(). Signed-off-by: Philippe Mathieu-Daudé --- cpu-target.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cpu-target.c b/cpu-target.c index 667688332c9..11592e2583f 100644 --- a/cpu-target.c +++ b/cpu-target.c @@ -172,12 +172,9 @@ void cpu_exec_unrealizefn(CPUState *cpu) } #endif - cpu_list_remove(cpu); - /* - * Now that the vCPU has been removed from the RCU list, we can call - * accel_cpu_common_unrealize, which may free fields using call_rcu. - */ accel_cpu_common_unrealize(cpu); + + cpu_list_remove(cpu); } /* From patchwork Tue Jan 28 14:21:47 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: 13952592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 71D26C02193 for ; Tue, 28 Jan 2025 14:23:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcmTw-0007sL-L2; Tue, 28 Jan 2025 09:22:24 -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 1tcmTs-0007pl-Pc for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:20 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tcmTq-0002LJ-Ob for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:20 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-43624b2d453so63131265e9.2 for ; Tue, 28 Jan 2025 06:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738074135; x=1738678935; 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=+boILYhYAtgeHGjq7jZm3ySgVoHBXMK8/hh/+aqTVRc=; b=zDKJ/uzzSbnVMhEOyWrbWTzi4EhJrFG1NPvkd+qVf5cp8ivj+C6fplNYZlCvoj3+iX BrkUg9rSTy6zQODNdtrU7UIIHijXiaJfKp1orT0nTU7prNKr/ZDD/Oa8JW99/f2x8PfC pHQjcxv2d0ZbIdzjX0AiaO64AZgA+uKvoWsM3RTZAdEwkZPGp03U21bhswQNaS22EJQJ AK1RewFv5Pa3xenVm13SCiqp3rahKzebYBUrshAmxVF15PVQIjcESCQBwgcm9lBDnoES LKNLYnk9XCoIqnNfalYZWbIhusdcQD/hiaAMdi6IvOYMnomAjAQI7k9eP/tKRgt9f7FO 2Pww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738074135; x=1738678935; 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=+boILYhYAtgeHGjq7jZm3ySgVoHBXMK8/hh/+aqTVRc=; b=UKil+ei9nhFmvQF5InLCPKQlPkyUOJkktMCa86WqvBosqZ1oa12523MYWH/nZbiM09 feEnD5bDpBEb91WqtIRvyozCKkH7uV+fu7dkmKQpK17BaU0Yc/VzUp3wQC0Fvlu0f1AL 4FBMAACAJ3Wjyan5YaN44IAEBoacM7U5qTrn0PjjOna7Sl4TW5LmnuqbWn3ANAUcMF0l Sr2lStwfGHowAnO5GYzTrj32ptEkiD7MpZa/b7Bdxd862QKaMc84rtRlxMCQ3FcelDsF 1BgBbi9m59UUPYV5AoDMlSyb6U0/NII2DXD2FXkhmkmbaCPxD+5XEQeeqph1/mvYP9TP 87cQ== X-Gm-Message-State: AOJu0YzUqRA5fitYnDcLZD1hJCqqk3FPYw9fcJSgI/OdQ4iQOfXegMzC OeCgyRP1+yENqQFXvv5oU2bxBBUxEjX5KAECAraQajqMyOEbvlLENdG++q5UCtd3IYSLms7O+is leVE= X-Gm-Gg: ASbGncsyVqMCB1URD9zqaR3vFbdCKPVOLa0t2IFuCwUYlpuwq7WySQuhKf5p60Oo9YU VFxQuBwohq6uYke8DR4UM+w0RwJeQveL+3nTm4EebREKBdpGWWB30/gWI6Obvm9n5IQvags+Vth ta6pptbZHSLla9/AR2BoV1kfpFe0MzXmiXdBW24lUP8QUanftTME4R1bnQLwmiEPafXDaPi6xFy Z2fycsC11uOALXDpogtZ3iNtRxUUGYWmFrmiKsa69ZLG9W/isYzu+1N+hnbtzXqRoOJCNj8YOZq YM43UQ2dQPvdi8zirkYPd2jG08t3V4302P/3Qc8sCxxPbLwwWZSyYiBLJfFAG2ubfQ== X-Google-Smtp-Source: AGHT+IGiyDf3PkdYsZe6jk+4/3mMAG2JXndCBMlzg8yxTvd0a+VKOSqbgVH5XTu3dPPXX+j4kBOFOQ== X-Received: by 2002:a05:600c:1386:b0:434:f739:7cd9 with SMTP id 5b1f17b1804b1-438913cf349mr381680345e9.9.1738074135029; Tue, 28 Jan 2025 06:22:15 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4857b8sm168810805e9.15.2025.01.28.06.22.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Jan 2025 06:22:14 -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 4/9] hw/qdev: Introduce DeviceClass::[un]wire() handlers Date: Tue, 28 Jan 2025 15:21:47 +0100 Message-ID: <20250128142152.9889-5-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::334; envelope-from=philmd@linaro.org; helo=mail-wm1-x334.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We are trying to understand what means "a qdev is realized". One explanation was "the device is guest visible"; however many devices are realized before being mapped, thus are not "guest visible". Some devices map / wire their IRQs before being realized (such ISA devices). There is a need for devices to be "automatically" mapped/wired (see [2]) such CLI-created devices, but this apply generically to dynamic machines. Currently the device creation steps are expected to roughly be: (external use) (QDev core) (Device Impl) ~~~~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~~ INIT enter -----> +----------------------+ | Allocate state | +----------------------+ -----> +---------------------+ | INIT children | | | | Alias children properties | | | Expose properties | INIT exit +---------------------+ <----------------------------------- +----------------+ | set properties | | | | set ClkIn | +----------------+ REALIZE enter ----------------------------------> +----------------------+ | Use config properties| | | | Realize children | | | | Init GPIOs/IRQs | | | | Init MemoryRegions | +----------------------+ REALIZE exit <----------------------------------- ---- "realized" / "guest visible" +-----------------+ | Explicit wiring:| | IRQs | | I/O / Mem | | ClkOut | +-----------------+ RESET enter ---------------------------------> +----------------------+ | Reset default values | +----------------------+ But as mentioned, various devices "wire" parts before they exit the "realize" step. In order to clarify, I'm trying to enforce what can be done *before* and *after* realization. *after* a device is expected to be stable (no more configurable) and fully usable. To be able to use internal/auto wiring (such ISA devices) and keep the current external/explicit wiring, I propose to add an extra "internal wiring" step, happening after the REALIZE step as: (external use) (QDev core) (Device Impl) ~~~~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~~ INIT enter -----> +----------------------+ | Allocate state | +----------------------+ -----> +---------------------+ | INIT children | | | | Alias children properties | | | Expose properties | INIT exit +---------------------+ <----------------------------------- +----------------+ | set properties | | | | set ClkIn | +----------------+ REALIZE enter ----------------------------------> +----------------------+ | Use config properties| | | | Realize children | | | | Init GPIOs/IRQs | | | | Init MemoryRegions | +----------------------+ REALIZE exit <--- +----------------------+ | Internal auto wiring | | IRQs | (i.e. ISA bus) | I/O / Mem | | ClkOut | +----------------------+ <--- ---- "realized" +-----------------+ | External wiring:| | IRQs | | I/O / Mem | | ClkOut | +-----------------+ RESET enter ---- "guest visible" ---------------------------------> +----------------------+ | Reset default values | +----------------------+ The "realized" point is not changed. "guest visible" concept only occurs *after* wiring, just before the reset phase. This change introduces the DeviceClass::wire handler within qdev core realization code. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/qdev-core.h | 7 +++++++ hw/core/qdev.c | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 530f3da7021..021bb7afdc0 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -102,7 +102,12 @@ typedef int (*DeviceSyncConfig)(DeviceState *dev, Error **errp); * @props: Properties accessing state fields. * @realize: Callback function invoked when the #DeviceState:realized * property is changed to %true. + * @wire: Callback function called after @realize to connect IRQs, + * clocks and map memories. Can not fail. + * @unwire: Callback function to undo @wire. Called before @unrealize. + * Can not fail. * @unrealize: Callback function invoked when the #DeviceState:realized + * property is changed to %false. Can not fail. * property is changed to %false. * @sync_config: Callback function invoked when QMP command device-sync-config * is called. Should synchronize device configuration from host to guest part @@ -171,6 +176,8 @@ struct DeviceClass { */ DeviceReset legacy_reset; DeviceRealize realize; + void (*wire)(DeviceState *dev); + void (*unwire)(DeviceState *dev); DeviceUnrealize unrealize; DeviceSyncConfig sync_config; diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 82bbdcb654e..38449255365 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -554,6 +554,15 @@ static void device_set_realized(Object *obj, bool value, Error **errp) } } + if (dc->wire) { + if (!dc->unwire) { + warn_report_once("wire() without unwire() for type '%s'", + object_get_typename(OBJECT(dev))); + } + dc->wire(dev); + } + + /* At this point the device is "guest visible". */ qatomic_store_release(&dev->realized, value); } else if (!value && dev->realized) { @@ -573,6 +582,15 @@ static void device_set_realized(Object *obj, bool value, Error **errp) */ smp_wmb(); + if (dc->unwire) { + if (!dc->wire) { + error_report("disconnect() without connect() for type '%s'", + object_get_typename(OBJECT(dev))); + abort(); + } + dc->unwire(dev); + } + QLIST_FOREACH(bus, &dev->child_bus, sibling) { qbus_unrealize(bus); } @@ -585,8 +603,8 @@ static void device_set_realized(Object *obj, bool value, Error **errp) dev->pending_deleted_event = true; DEVICE_LISTENER_CALL(unrealize, Reverse, dev); } - assert(local_err == NULL); + return; child_realize_fail: From patchwork Tue Jan 28 14:21:48 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: 13952591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60BAFC0218A for ; Tue, 28 Jan 2025 14:23:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcmU9-00085u-VE; Tue, 28 Jan 2025 09:22:38 -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 1tcmTx-0007xt-Bd for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:25 -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 1tcmTv-0002Lk-1v for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:24 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4363dc916ceso42395915e9.0 for ; Tue, 28 Jan 2025 06:22:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738074140; x=1738678940; 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=mCOhYMyVhf/9MTlWJYC1Pyb8EOr+qnDpIx/K4OIle8U=; b=HIXX8jpfYmx3orluh9tJuCSgZoXZhUMxVWmCNBwLqs+lQ2cOELDtbNhEi8FIn7KMTG D9GZrP3o5Rilow385pzHojPZYWXLFSKONzg9KyyLCpoD9iQj8oPEWZIK6c/Mq0GJ9C9N OfBXsSUVdQUSOh8+a844BI9ZyO9bz7JHyy/GxfQYn15nEjaOPfgOINdvVNMnSwWq8Qgk FrerrPoV+7O9Wvr7VnaFC37p4AZzSMme2QfEe0PkLnpa4EfdrlNKBi3wfLMwwrudZr1a 72xjRdu1LEKn5qOx7UCwVbs5iGuYEHahyvqBz+oUIVf27wiMgISfZ/viswW+0f7Eo2Zh D1Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738074140; x=1738678940; 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=mCOhYMyVhf/9MTlWJYC1Pyb8EOr+qnDpIx/K4OIle8U=; b=Y69Nu9Tnx/7snDTbOEyFzhP4RlHM+RrQqvuO/fcAKJov8X3kcvykYll/WdL8LrwXFz KkWbYWULLLUy3UPvylJUliedgLa0S69TyFMLXEwMFJXfNUIfVrNCIdb+RF0/fPXPDurC vBWK4/epo6DophsrXfvr3w4rHmaBU6qE0+iCSC1kGx/VXbxCC5agJ1dOuW9G7Qr7YqjB lVEQbXoT/KZXKCiOHpVkHKSZzAmoZ0cSQu30EqM3arGhHuwuERJo1AcH4w+cEM0i3YiY smZR3xcR4wKXGQ0ULIzgecJjWLT6DMo21FfLvcRRVdVCckLvLz7acEaTubgqc3Jj7jL4 K/Wg== X-Gm-Message-State: AOJu0YyOUSpTrPb/fkuv3BfAAHqVIjriASwsgH9IffBBrC+WydGtFkDd eEGBDO4zU2W1YTwSNxe0zyiewFU7zDMMP92dd4K+K0F/cTbEY4tAzT6Om6ZhUeqfYLjhltMWR88 +EYg= X-Gm-Gg: ASbGncuovb0nUC05K6IyTE2cdeCvJo5U1ys9YZp/uI4Gwm399GRlYhWRb5l0LCn7/ri 9+yGeGSTMN3uG+7uosHxx7CVUCEgS6eNTIrJ0netkMg+0LBwE5ypnXQaF5JNnWee3CwgX3hlfLH Wm+aOd40Ppd1bJM9uYRcblXwTIIaY+khv8ora5TNkyADOHyTigxBH4jVxyrYdJtgRzHOUXLHFIw 5AXGv1aC7M4oIik4PfGyunBIOoZVj6OnS+FDwuWgl0Fwm4pDUlqpuJvYls9ZCb4F8HDuwLBW0Ub d8Tji/uUVlnZhKYaEhUsE/EJxomilk9qD/YZErQ/gR96dyCvkIzlPr+IsZCV8OvrAA== X-Google-Smtp-Source: AGHT+IE44lMFstrRJbbKMMn+hBpz79bGQD7lLRHTYaowiK6y0WzRah7ztkDdk12TT/+zj/uGA78k7A== X-Received: by 2002:a05:600c:6c92:b0:437:c453:ff19 with SMTP id 5b1f17b1804b1-438d59b566dmr30503145e9.14.1738074139917; Tue, 28 Jan 2025 06:22:19 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd57325csm172106435e9.34.2025.01.28.06.22.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Jan 2025 06:22:19 -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: [PATCH 5/9] cpus: Add DeviceClass::[un]wire() stubs Date: Tue, 28 Jan 2025 15:21:48 +0100 Message-ID: <20250128142152.9889-6-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/core/cpu-common.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index cb79566cc51..9ee44a00277 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -219,6 +219,14 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) /* NOTE: latest generic point where the cpu is fully realized */ } +static void cpu_common_wire(DeviceState *dev) +{ +} + +static void cpu_common_unwire(DeviceState *dev) +{ +} + static void cpu_common_unrealizefn(DeviceState *dev) { CPUState *cpu = CPU(dev); @@ -311,6 +319,8 @@ static void cpu_common_class_init(ObjectClass *klass, void *data) k->gdb_write_register = cpu_common_gdb_write_register; set_bit(DEVICE_CATEGORY_CPU, dc->categories); dc->realize = cpu_common_realizefn; + dc->wire = cpu_common_wire; + dc->unwire = cpu_common_unwire; dc->unrealize = cpu_common_unrealizefn; rc->phases.hold = cpu_common_reset_hold; cpu_class_init_props(dc); From patchwork Tue Jan 28 14:21:49 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: 13952593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90093C0218A for ; Tue, 28 Jan 2025 14:23:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcmUK-0008Mw-RI; 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 1tcmU0-00085l-NA for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:32 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tcmTz-0002MH-3H for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:28 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-386329da1d9so2946761f8f.1 for ; Tue, 28 Jan 2025 06:22:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738074145; x=1738678945; 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=Tw046dW5+uhhYJLaed8H1nN+PEtNbdWPjJLIYS364MM=; b=YKno2KaP2dzwxTaB/PiXXuz+K/eXiPdccvmP5hSAxH1W5+BaYZckgTNiYgtREK3+QR CG2aRMqxBLjGcRAIcy/FM8e/+g+0knSti3rPq2CcKDiOokosZJ4H1bAOTvkPa1o8BQ+h 27690LMDUIt1+hVVBgyCVNbQ9KSpmaQndpP2bZFDl0WbgemVMM5TUo05bShR1FoLnoB8 n+/JILks46I06DWwF7VOfsEwSPUKHOynfWXWu9KR/B9lq49FxC5ao6pewTWKWhBCFzqU j6g1iu8V1V/ukBIS8fbHeQ3MbXuIiVu6KBDFjgAsDXBtvJsaHR81PepaAsIeMBBhktaB Ecug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738074145; x=1738678945; 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=Tw046dW5+uhhYJLaed8H1nN+PEtNbdWPjJLIYS364MM=; b=QN2Eb9T9pcbm1hoLnx3SSLcX7yQB71DVNN0ADFEyiFq6huy0Nf4DNJYOW2KKqAs3t1 L/tz10/PazGkFezFCCQ7NkhfKerKwHxoOYjppF+6hGMLMqhr/DOR+gc4wr3Jn8urb4Ks gzK5vvm0qbgikcGePN8vK+2X5HBvRWj/TAJ7/lMoET/edbmC04RyZ9FXw1SN7qtTYfbS 2CjKOqKdPoewvDZy7N7w8Jy/ZCZbzFU37wAvEAp1Vn7lIoWTqjFAIrJLE4doRZCFO8dq Gx4VxSn4iU3omUFHzp7XxhFI3pcmuYlDNjjkyDKlglvKssBoD0GZzeav5dYqdcHPyCFs MjwA== X-Gm-Message-State: AOJu0YyxUpYyqb96W0q8JPh298n0KhMJChwv/c6Or70WAGpcJH0tXmUu yyzqruKBuBVYvosGxxRoax5gAnFwy8tsXwPiE4hFM1DsTi8s0c81Ro8uv5wdQgk7e9+r/eDEHyV JnxI= X-Gm-Gg: ASbGncvWaq/Gv0fxPhXRkoX//UZKODyLs7CngiP/qrk+zbMDYuKHmEpl6gcO7hNIZnH k4f/RSc6V+3GhfP1CcCO5/UvFRw3SHvNqbCfaNJ48e0TYJRW0YnmCg4zRjjJ8iPLd65OmFMqR+h 3WAZGpml3fzv9ILAueFfX+nW8Q0fBsDM/DQbLGOi0OuIpAkClz4bOsNhvJf+PHy4IGeOHqxSlME pJsep1APKE+dNVp8Zx0BTLQyDTCS2u+Q23Ia+Yi+i1Q/kGV4THsNOHGQNK3mTqGxiOLP9/pVyIP ihAm5eDPot0qqQznhC9IYnlKxGiYcmSe9L5w1KLxoJysf86uxKZXv3BfK94na/AeIg== X-Google-Smtp-Source: AGHT+IEyyaAAlYQ5I3ppwUr7kelaVWlDzVIFlhZYrwH74VA7sdBpE5YrUhEnY7P3LEg7nQWsma+f4A== X-Received: by 2002:a5d:47ac:0:b0:38b:e919:4053 with SMTP id ffacd0b85a97d-38bf57a993dmr44371093f8f.44.1738074144814; Tue, 28 Jan 2025 06:22:24 -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-38c2a1bad92sm14282474f8f.61.2025.01.28.06.22.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Jan 2025 06:22:24 -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: [PATCH 6/9] cpus: Call hotplug handlers in DeviceWire() Date: Tue, 28 Jan 2025 15:21:49 +0100 Message-ID: <20250128142152.9889-7-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::434; envelope-from=philmd@linaro.org; helo=mail-wr1-x434.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org To call the hotplug handlers with REALIZED vCPU, we can use the DeviceWire handler. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/core/cpu-common.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 9ee44a00277..8a02ac146f6 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -211,16 +211,17 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) } } - if (dev->hotplugged) { - cpu_synchronize_post_init(cpu); - cpu_resume(cpu); - } - /* NOTE: latest generic point where the cpu is fully realized */ } static void cpu_common_wire(DeviceState *dev) { + CPUState *cpu = CPU(dev); + + if (dev->hotplugged) { + cpu_synchronize_post_init(cpu); + cpu_resume(cpu); + } } static void cpu_common_unwire(DeviceState *dev) 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: 13952590 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7C1CEC0218D for ; Tue, 28 Jan 2025 14:22:55 +0000 (UTC) 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-Google-Smtp-Source: AGHT+IGJgZU4Cp2hilxwmoMaixsHyforairgw/17QEoYqTReWbKeDv+qCHMAqmyxnXcqNHDKAhm1lA== 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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) From patchwork Tue Jan 28 14:21:51 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: 13952612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0333EC0218D for ; Tue, 28 Jan 2025 14:24:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcmUn-0000Q0-Er; Tue, 28 Jan 2025 09:23:19 -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 1tcmUA-0008B1-HX for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:39 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tcmU8-0002Nd-UV for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:38 -0500 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3862b40a6e0so4105758f8f.0 for ; Tue, 28 Jan 2025 06:22:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738074155; x=1738678955; 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=YRDTHlfvyOrER0eUl5RKITSLiEo3HyKeVBvSp+Og3D8=; b=EQ6Rz2q1RpHqCwi9yC8iP0Ps8Zmm9RzEwhWHQhgUStLFMG0E+gdFSDrirh7Fhga1bG W7TK1qhm0NA7wqotPZger2/wv5o41QviygPULx+BoPiLfPVLoQ/IVCNQIYL3uHcZcvOa AEIMxQEJNpf4byE9pVwfQoz11IXqs8K9ot15UF214pzhz36OfigOk1Plwh4+xseQUAkp +ktNLAw2gcZ18/IEZydfu0zBzGi+6GBckYg8KCNOhyGt0HVLYBiJYnfaD0Qvsy4v80Y+ 1qrt7qUq2mCuYGscEZ5FBqYOJPi9ByMiI1V6jJ4nmk1Jb1HpkWeK0SZFAHPucPdKcn+u Pe/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738074155; x=1738678955; 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=YRDTHlfvyOrER0eUl5RKITSLiEo3HyKeVBvSp+Og3D8=; b=YlEWfEuJZN8M74EobWpV4D+UxqfwTKWMaA+NoTz2UV6UaDK3zSpmByujx43w0Tgr0N e/eiEdwpd9HrpUfR3U+Ec8EAbp3NSnKqSRwjkK9C/21/o4xvQ44dq7lBAZ8vtypea1hA PiUww4cQvCbhMe+Xc2XMvEk7RC2JKLzlCVAnDtg3O4EyaQ7jAcJZY/A9kh9wOSkGpO95 8E2L21yT9OfB3iB92E1wkWzEzV4A46ugqrn/Kqn4PEdRdkuuD0pHnQ2fgMXrkcmNrbTP C7iTTw9RRZenqAbnZDTYirBn36oxYdEtUPBwunX71+4kEhZ7RsUjEszGqVHuNJlLFs5I pLPA== X-Gm-Message-State: AOJu0YxZT3L+ZC31Gs2ym852cU2su7b4OWa5WSggFo1Gt8Wr+oPuAoMI BAAwArOR13Y5gD4ljVo11xyHa7bZp0YAaZFmhhm+rkP010wHh4eltjBAKfMaL6dqRUaKgMA/4QV EnBI= X-Gm-Gg: ASbGncsvaGkPneE9CV+koFTAKZEOgQFo2degNcCQWWsC88WVNEOpZIeVwyL/1zXA3nn xJulGGdQqosPHIcrapx745ORk/x4M2G08IrMRNAB8DSjk2PwCEpEEjKHQs7lCRd+flh7kbnxqoc 5nak4VJLT/Vnli4hXwSeZsYBv5ecu2z1os180ALA8VFt7APRg0glbwVUVVvyq1J6BgHsFjLeHeG zU3KLKTRm+uPAUb4e0MXAdFDpCj3W6TK5QyOdtdCzxdRqgoA0ztXZMcnIyzFGtnDqGIxzp+xKBD gIGCxEmcO/YiNnxLqnZpeVxwvJGmZ44M1NIN8RvpYLDsjaclEYWVY7cas0/PlGmqiw== X-Google-Smtp-Source: AGHT+IGUPaLAqP3HpLzD0IitgxG+YT9FIQ6tbXwdivHVU4DsFGAjOBMGO6K9Ad7biFURl7kv8n/Uug== X-Received: by 2002:a5d:6c65:0:b0:38a:888c:676f with SMTP id ffacd0b85a97d-38bf565f13bmr45683211f8f.15.1738074154855; Tue, 28 Jan 2025 06:22:34 -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-38c2a1c3fedsm13952511f8f.85.2025.01.28.06.22.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Jan 2025 06:22:34 -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: [PATCH 8/9] accel/kvm: Assert vCPU is created when calling kvm_dirty_ring_reap*() Date: Tue, 28 Jan 2025 15:21:51 +0100 Message-ID: <20250128142152.9889-9-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::435; envelope-from=philmd@linaro.org; helo=mail-wr1-x435.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Previous commits made sure vCPUs are realized before accelerators (such KVM) use them. Ensure that by asserting the vCPU is created, no need to return. For more context, see commit 56adee407fc ("kvm: dirty-ring: Fix race with vcpu creation"). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- accel/kvm/kvm-all.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index c65b790433c..cb56d120a91 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -831,13 +831,11 @@ static uint32_t kvm_dirty_ring_reap_one(KVMState *s, CPUState *cpu) uint32_t count = 0, fetch = cpu->kvm_fetch_index; /* - * It's possible that we race with vcpu creation code where the vcpu is + * It's not possible that we race with vcpu creation code where the vcpu is * put onto the vcpus list but not yet initialized the dirty ring - * structures. If so, skip it. + * structures. */ - if (!cpu->created) { - return 0; - } + assert(cpu->created); assert(dirty_gfns && ring_size); trace_kvm_dirty_ring_reap_vcpu(cpu->cpu_index); From patchwork Tue Jan 28 14:21:52 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: 13952594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B0CBC0218A for ; Tue, 28 Jan 2025 14:24:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tcmUn-0000N3-EO; Tue, 28 Jan 2025 09:23:17 -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 1tcmUG-0008EY-3z for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:44 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tcmUD-0002O9-Ia for qemu-devel@nongnu.org; Tue, 28 Jan 2025 09:22:42 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3863c36a731so4736889f8f.1 for ; Tue, 28 Jan 2025 06:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738074159; x=1738678959; 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=jN7tNGrfnQkH1jp+7zEAfhWZCNwGy2KakJL6oRXbHIo=; b=TV29y09RKOW9xtqH++5r4H5mCmJPqDWmlztjWX8yRMiZkGVo/Jbw3GEhZWYSVjX4PY y/ge17IxfBxPD7KroxTHrSd3mgQEdltaM3SJuGG7OLzCbZ3FRTx6XV39yMRAgf7C4sCs lZsj7kKnPaq2dFuzjFufnDXAWvvz8krjU40TSOWItbvPXzuAVyXgoZtr0ysWfq9tzn9D dM3+W+B8SzrnrK0PR1Ec19OP+xP8dobdnzCpHGeWOJAwgm/8OThYMN7ANvhLqoREpImH 8uv65GqO0CDCtfYp3tNGFcy7MbkvuJA0zl6UGq2TaXVEAG6JGhBfZx92nxwEmCWPzyBQ Wc0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738074159; x=1738678959; 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=jN7tNGrfnQkH1jp+7zEAfhWZCNwGy2KakJL6oRXbHIo=; b=h5llxzRwTo168iBSOCU7YWSm3IogJsnPkEjRA4+p+H1AJdhKE6GhMDx3G5AQDhGfz4 L+9SAV1efDii9jlcak2U2lSy5Ncx8HRY9KFGnaBP5cPjUgrNXXSEDGm7NErIPkyMphZC /wU7Gqx2O0R5XljtArKlQ91IrGRo5WIK9ET7ztt+u87mMjeA3jk4MH/TCjDI6foMp7Pp bUZwZ/rLrtdphhHAFHaciHbJ7PliLQNDZxHRcGL6hVr8gX/QqmuuVT9U9KYLeftBYFlN a42Jqn/B7Um/cXafQyjn+SJHUiOUgefID2taxFSmZi87WFC1nukX6dMjeRsqZJVwqqah /leg== X-Gm-Message-State: AOJu0YwbPHk3RKoAtkIAjBLp27r9e3nyVmMGjrR6IpjjnOGzP7/5BBFr gOu9KmS75Tiw4n4c0JxkOiBO+pqFykJjV7l0qALmj1gjLGkT6npDG0gzluVwSBpizaE0xl5Ruav PjmM= X-Gm-Gg: ASbGncuhnzDNKHuzXOgk5Hr2Slz2Gge4iNeCVS/Vvm+EnWQv/k2P/LKbrNExNnRJ7xx 1PqhaAkXloKsQ/GIWoLmx9vLHZCeOT5ZRq0VvIUyBC0trBg13tNzafM+jRpAeIAzWVccSjrRpl2 uar7iz/zJKsJdCx32yWEB02E1Ck6z76+o8YjmJ29HwG2U6wXUHt6qyjDqrcfCwsU7IrRHXQOfAR gE5e9Jmr2awzxDjBlzywTlvcauK6ZUm05m3Ge8bXVHma+NmRj9I4R7B6O37SXXNRUJSrx6far8V J3iKvOr0JDGtw4+zNsl+woGVmsfATRLXdVAioE1RNiGoBmbqNuPY339z1rHz3P8NVQ== X-Google-Smtp-Source: AGHT+IHfjGCtubVM9RMAK88E03g9Q6/raB5p2ips8Ty3wdrHPHY423HNQ2wht5Ir+apIlpYx+7iAnw== X-Received: by 2002:a5d:64e9:0:b0:38a:88bc:bae4 with SMTP id ffacd0b85a97d-38bf5784ab8mr43777014f8f.18.1738074159686; Tue, 28 Jan 2025 06:22:39 -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-38c2a176434sm14462219f8f.13.2025.01.28.06.22.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 28 Jan 2025 06:22:39 -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: [PATCH 9/9] accel/kvm: Remove unreachable assertion in kvm_dirty_ring_reap*() Date: Tue, 28 Jan 2025 15:21:52 +0100 Message-ID: <20250128142152.9889-10-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::42d; envelope-from=philmd@linaro.org; helo=mail-wr1-x42d.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Previous commit passed all our CI tests, this assertion being never triggered. Remove it as dead code. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- accel/kvm/kvm-all.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index cb56d120a91..814b1a53eb8 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -830,13 +830,6 @@ static uint32_t kvm_dirty_ring_reap_one(KVMState *s, CPUState *cpu) uint32_t ring_size = s->kvm_dirty_ring_size; uint32_t count = 0, fetch = cpu->kvm_fetch_index; - /* - * It's not possible that we race with vcpu creation code where the vcpu is - * put onto the vcpus list but not yet initialized the dirty ring - * structures. - */ - assert(cpu->created); - assert(dirty_gfns && ring_size); trace_kvm_dirty_ring_reap_vcpu(cpu->cpu_index);