From nobody Tue Feb 10 19:17:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1692197981; cv=none; d=zohomail.com; s=zohoarc; b=iHGz/4+awPPYg1hQESd9EdZszRLJ1ifkLKEC7uGCCYXNSjA8pAyc79VQwdx0qE7MrliovBAa1sxdcuFbIXBt9l34s/mtG8IbV2HmSCAZ5J6DU1cVFgdv3aGY6XDF2+jNbnFO6O2fnWiu+uCKLLRKqNgSZXn2jztO4pJxC4Rniew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692197981; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject; bh=0qn3f+dV41vakExUKDLgOPwYM5dZMF/vR3FB6T+MC1c=; b=NiHOkLyN2FDPO/5ZKNMC8ENk3Df02jUONqkuOTHCWLRXMWG+ZszKbPxrvPg0Em4qgOl68eLN2QYNVNS6hJl+UpAQPNh2X0ezI3m/Sj6CkWATvxEU3bloH73n6IrKm0NBfw4wUoLmGGgUlPXWM4JL4oAk8ztq5kkzP4K91wsi+Oo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692197981773528.3184679122364; Wed, 16 Aug 2023 07:59:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWHvz-0005MI-Uw; Wed, 16 Aug 2023 10:55:43 -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 1qWHvy-0005ES-F3 for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:42 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0: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 1qWHvu-0002KN-8E for qemu-devel@nongnu.org; Wed, 16 Aug 2023 10:55:42 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6887ccba675so603249b3a.3 for ; Wed, 16 Aug 2023 07:55:37 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id fk26-20020a056a003a9a00b0068892c40253sm1156568pfb.216.2023.08.16.07.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 07:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1692197737; x=1692802537; 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=0qn3f+dV41vakExUKDLgOPwYM5dZMF/vR3FB6T+MC1c=; b=2L6AVfTz8CvAuULFJ42gQy1cf81eTocVTR9UQPe1fZA45I6oVAj44sl+BwBrM78/VK HUFfz3K443rrxYfy5KN2ngwKcKC60/Ui3zZs/BoXrxAm1ocq4NC8GNYkfB6hdnzL0BHI /JKw/tUOcQSKCGXzNY5SHv2+yb1j5/evBRsoonu7IYBSSQfgCQQRrPly2NlcwYhWru4Q 7hbwGsWwzSuKfjdmsPQPoDZC5iUPONhwx357Qu+/XtVOcIzPKuuE1JigqsYBC1mYMU3r yCaOe62NjZTsz6SmSOS8kJCn0auKsjtQ4xYc837Bix9YbhG7UrntGc9K+RBD5XFKXdBm IkDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692197737; x=1692802537; 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=0qn3f+dV41vakExUKDLgOPwYM5dZMF/vR3FB6T+MC1c=; b=BPLCyJjTgDE4v7q0rUd3+PMV3Ba4/7iTLpGGu2whwyJhfiQ7J7K0+tYapvYBGBy+8N L7D+Q2vj5EsQIThT9J9UhEPMSUgMaAoamfLwE3AOUszdtzRYckZtJoNp5SbEy/QEEbrp EtmeecLNAaXqE/iWVgWj8MUu06REIT2RQALlmeP5CGZx0FwmYStbPNQx0cqH2SvW2Xim HejWGueAr+R6apg4nSjTLNxrayeGaboIZBMUqa0mra9HzWW6NyDFNzXBbUS+ojt4mDOr VEn7JdE+NjQnuCejHllDREKVp3GnpQo1QC6rExTEshwHyKcY1zjRwToPYaR2/U4dez7a 0SEg== X-Gm-Message-State: AOJu0YwKoJ3cq5eyxi7d8XvZnJlSCjUOMLERRT7i41Ncpgd4our52e4h iPjtE7fo5i+Hw+uysQi78OUw8g== X-Google-Smtp-Source: AGHT+IHaIIuGZ2gUrulonpwa65Nz3Io06fPnbVxiGrNLkLfEmh35nLZt8QKhsSDdZF7/OhNxd0e1YQ== X-Received: by 2002:a05:6a20:9189:b0:134:2b31:e2a9 with SMTP id v9-20020a056a20918900b001342b31e2a9mr2356825pzd.0.1692197737066; Wed, 16 Aug 2023 07:55:37 -0700 (PDT) From: Akihiko Odaki To: Cc: Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , John Snow , Cleber Rosa , Peter Maydell , Michael Rolnik , "Edgar E . Iglesias" , Brian Cain , Song Gao , Xiaojuan Yang , Laurent Vivier , Aurelien Jarno , Jiaxun Yang , Aleksandar Rikalo , Chris Wulff , Marek Vasut , Stafford Horne , Daniel Henrique Barboza , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Nicholas Piggin , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Liu Zhiwei , Yoshinori Sato , David Hildenbrand , Ilya Leoshkevich , Mark Cave-Ayland , Artyom Tarasenko , Bastian Koppelmann , Max Filippov , qemu-devel@nongnu.org, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Anton Kochkov , Akihiko Odaki Subject: [PATCH v4 21/25] cpu: Call plugin hooks only when ready Date: Wed, 16 Aug 2023 23:51:42 +0900 Message-ID: <20230816145155.21049-22-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230816145155.21049-1-akihiko.odaki@daynix.com> References: <20230816145155.21049-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::42d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1692197983392100001 Content-Type: text/plain; charset="utf-8" The initialization and exit hooks will not affect the state of vCPU, but they may depend on the state of vCPU. Therefore, it's better to call plugin hooks after the vCPU state is fully initialized and before it gets uninitialized. Signed-off-by: Akihiko Odaki --- cpu.c | 11 ----------- hw/core/cpu-common.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cpu.c b/cpu.c index 1c948d1161..2552c85249 100644 --- a/cpu.c +++ b/cpu.c @@ -42,7 +42,6 @@ #include "hw/core/accel-cpu.h" #include "trace/trace-root.h" #include "qemu/accel.h" -#include "qemu/plugin.h" =20 uintptr_t qemu_host_page_size; intptr_t qemu_host_page_mask; @@ -148,11 +147,6 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) /* Wait until cpu initialization complete before exposing cpu. */ cpu_list_add(cpu); =20 - /* Plugin initialization must wait until cpu_index assigned. */ - if (tcg_enabled()) { - qemu_plugin_vcpu_init_hook(cpu); - } - #ifdef CONFIG_USER_ONLY assert(qdev_get_vmsd(DEVICE(cpu)) =3D=3D NULL || qdev_get_vmsd(DEVICE(cpu))->unmigratable); @@ -179,11 +173,6 @@ void cpu_exec_unrealizefn(CPUState *cpu) } #endif =20 - /* Call the plugin hook before clearing cpu->cpu_index in cpu_list_rem= ove */ - if (tcg_enabled()) { - qemu_plugin_vcpu_exit_hook(cpu); - } - cpu_list_remove(cpu); /* * Now that the vCPU has been removed from the RCU list, we can call diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 549f52f46f..e06a70007a 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -211,6 +211,11 @@ static void cpu_common_realizefn(DeviceState *dev, Err= or **errp) cpu_resume(cpu); } =20 + /* Plugin initialization must wait until the cpu is fully realized. */ + if (tcg_enabled()) { + qemu_plugin_vcpu_init_hook(cpu); + } + /* NOTE: latest generic point where the cpu is fully realized */ } =20 @@ -218,6 +223,11 @@ static void cpu_common_unrealizefn(DeviceState *dev) { CPUState *cpu =3D CPU(dev); =20 + /* Call the plugin hook before clearing the cpu is fully unrealized */ + if (tcg_enabled()) { + qemu_plugin_vcpu_exit_hook(cpu); + } + /* NOTE: latest generic point before the cpu is fully unrealized */ cpu_exec_unrealizefn(cpu); } --=20 2.41.0