From patchwork Thu Oct 19 10:26:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1851535 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=FU6Sa1O4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SB3rT73GBz20Zj for ; Thu, 19 Oct 2023 21:30:17 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtQGZ-0002vl-2O; Thu, 19 Oct 2023 06:28:35 -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 1qtQGM-0002Yk-NI for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:28:22 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtQGK-00075g-K7 for qemu-devel@nongnu.org; Thu, 19 Oct 2023 06:28:22 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1ca74e77aecso4656835ad.1 for ; Thu, 19 Oct 2023 03:28:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697711299; x=1698316099; 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=cD/+KjPjtz2Km+8KJY7IRJQ+1wNJcewyU1Hou20qfyQ=; b=FU6Sa1O4WmEISWqYR19ovYgX77rjb+cGL5SxqHPCY4LDEK6d6nAPVciEXQsx01K+ru ZPhJxZkGY9MmKAH0CpqsdPwfqu7etE/uORrUY+cAjUaK0NfTgCkmB7WzAQGTyisY5ftl s8YjEJTS3rRXsGpLdXtPzXgjRAfCNna5BGplDvDWUGUCnJf213xpxXq9XGTnoBBbsg1v ZmDoR2j5vpIk2+AhvU/MMrRH/JKz2Aww+BLugrDL1W8M2r+NSjFBbNEnC5fWshtr50DJ UvxaZLwdZU/yM1vgU5k63uUVd9F5NuZIyV/xsBa7ql+IGlrN0W1Xt09dd5TfbuFF8wR+ wmmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697711299; x=1698316099; 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=cD/+KjPjtz2Km+8KJY7IRJQ+1wNJcewyU1Hou20qfyQ=; b=PRKYwJ/woiVkKVsK9y2jeL4swgbxUruTQl6aIHwHllBW29ko9mokQ59TlE6THbdtzb fpIaQkwGrrBCYK5g1ky4mq38VCYK6Af4PdTGb5GRw/TQ7pDwe5/WCmMQwYrKwkMzd3DX azAZkwAGqUMXeIm3s52Do6uiTv5vBfey/uo4F2YzC8s5TC/YxL54N9HsSs+DOMQEvNyo /Mopf5+HcP3DzTM3kd+em8xvd9S+Be8f0ZswGjyV5QTfw9YW2u6j3CiJzxL6itS4y6xQ xwPnC1Fjgn0In25j1onrKqXcQXpdnXRVnYL5g7HkfBMXC93AICdk4v6T1eGyju6akyVa kpwg== X-Gm-Message-State: AOJu0Yyx4TmOmAYZNO7kbj/7asmoLAzCfIyGljShLK+KlrPle1FHrEnG WzuGe3jJLPhxEt9Y7QDYqO2y0A== X-Google-Smtp-Source: AGHT+IGwLGp3qv//wN6oDP/Angrw1gCOzZFkn070OB7WKM1xPFUlctLrYrDbHcXdmhzY/WueD852MA== X-Received: by 2002:a17:902:d2ce:b0:1c9:dba6:417a with SMTP id n14-20020a170902d2ce00b001c9dba6417amr2299869plc.9.1697711299202; Thu, 19 Oct 2023 03:28:19 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id y6-20020a170902864600b001c0c86a5415sm1565408plt.154.2023.10.19.03.28.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Oct 2023 03:28:18 -0700 (PDT) From: Akihiko Odaki To: Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Akihiko Odaki , Richard Henderson , Paolo Bonzini Subject: [PATCH v14 15/18] cpu: Call plugin hooks only when ready Date: Thu, 19 Oct 2023 19:26:50 +0900 Message-ID: <20231019102657.129512-16-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231019102657.129512-1-akihiko.odaki@daynix.com> References: <20231019102657.129512-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::631; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x631.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=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The initialization and exit hooks will not affect the state of vCPU outside TCG context, 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 Reviewed-by: Alex Bennée Reviewed-by: Alex Bennée --- cpu-target.c | 11 ----------- hw/core/cpu-common.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cpu-target.c b/cpu-target.c index 79363ae370..00cd7f4d69 100644 --- a/cpu-target.c +++ b/cpu-target.c @@ -42,7 +42,6 @@ #include "hw/core/accel-cpu.h" #include "trace/trace-root.h" #include "qemu/accel.h" -#include "qemu/plugin.h" uintptr_t qemu_host_page_size; intptr_t qemu_host_page_mask; @@ -143,11 +142,6 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) /* Wait until cpu initialization complete before exposing cpu. */ cpu_list_add(cpu); - /* 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)) == NULL || qdev_get_vmsd(DEVICE(cpu))->unmigratable); @@ -174,11 +168,6 @@ void cpu_exec_unrealizefn(CPUState *cpu) } #endif - /* Call the plugin hook before clearing cpu->cpu_index in cpu_list_remove */ - 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 2a2a6eb3eb..409397e2b5 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -210,6 +210,11 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) cpu_resume(cpu); } + /* 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 */ } @@ -217,6 +222,11 @@ static void cpu_common_unrealizefn(DeviceState *dev) { CPUState *cpu = CPU(dev); + /* 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); }