From patchwork Tue Nov 7 14:23:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 741896 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1648052wrr; Tue, 7 Nov 2023 06:27:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZgSfBKLG6ktrQwdxfLPGtPeH7ldwN7LaIs1f+XKDM/+zXtdyrg9+lgt0gMCH+R7C8WKb3 X-Received: by 2002:a05:651c:490:b0:2c6:c5ed:5619 with SMTP id s16-20020a05651c049000b002c6c5ed5619mr17911634ljc.38.1699367226689; Tue, 07 Nov 2023 06:27:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699367226; cv=none; d=google.com; s=arc-20160816; b=LItIdtpsoeALFbSwySwFhYUdSBdj6oFkpIMI0VYqw5hcOndIqkw+qlovZcoad8L8Db RFP/7xp0p59Xg0y90BMNG+SCk+Y1WIrG6CjaaFWu2QgMILU9lscpFkciqIDormgVGpBv oXhTdNQScIgIvk8AhLOlK1jUYOJpXkgVD66XMMdHfGwdWkHOn/a5e1cYK6REiAR1CT80 +tRK/KxaHokRTOesGyyVGbRxjHIBluXyhmDg+TGE76X4EYCXJEvh9gimWYEyLvhDwK9e BpuTI4r/Lq5fHm8szxpNoQckpz0WQ8PrP7A0rbjYAltk+AsbiX4zOMVS4g7omCpvBDIJ 5Sug== 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=mtDpNZGc7bpiPdq3AvEGwADJunLb29I37B0SspqL8mk=; fh=u60v56TdB5PrUBnJqQvxhILE3vhYB1rlxDC6O9oGPHs=; b=OKWdHN0ruv8ML99aCJerbg0ZuDiy17HqBdkSsn34CEV29gW/G4fPfbgroTumMv1ZO4 Tu5Z17IknVTbRiTcfddU2BP2MN/paB3xoerBJQFxNxQuywwEHK9KZe3UP8aawwVWmEvH Zy4aLJpD2lXl3LpOOu1keQmikNhl/m3rhY57bJwx47dq4crIdW10ypgrzF/GG6027178 cyaGaE1v6rIOyh6Z1T80arP+S2HiWDb7CiisON6n/hZwkB+os/yoN5nrLlQSmGToEeUU MhLDPpX7OuMRsYmQjo+3AXCtUARQ3Ypm/a7WUt2Nqfw8rwQJD63yyEv5jggC4m+Wm0js 4Rbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jAq1zHgV; 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 h10-20020adff18a000000b003248821249asi1747918wro.472.2023.11.07.06.27.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Nov 2023 06:27:06 -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=jAq1zHgV; 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 1r0N0K-0004Tr-2e; Tue, 07 Nov 2023 09:24:32 -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 1r0N02-0004GF-GZ for qemu-devel@nongnu.org; Tue, 07 Nov 2023 09:24:14 -0500 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r0Mzw-0007bk-VE for qemu-devel@nongnu.org; Tue, 07 Nov 2023 09:24:13 -0500 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-507a29c7eefso7247857e87.1 for ; Tue, 07 Nov 2023 06:24:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699367047; x=1699971847; 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=mtDpNZGc7bpiPdq3AvEGwADJunLb29I37B0SspqL8mk=; b=jAq1zHgVNomIUNYWFsRslqsJp/z8QqpxKSjDjPZnJ2zNX1dWVxwf+DJogxQNUMbNxG no7zJD6V5d938UXIbdhL7ZgNqD5P6h8qHUi4Ux0Vz7en5K9gVSMbXejrE/kzYthUzFLs /BOsul3TvoWxH3HEuqUIiUCTXc8ypNUSr/yR3amzAyphuENusZL16b6yHJnjd8Wlt6dW l03zFNRnSw3QyljmZGDAKKMUqXY3bOtRW2cY3P7ozlogH4fpMxKIHIy5nw6sAp6yH6W2 mDWYI2v0v+q+o0duaMS8563tjQn1iol4aOuqhcz0RwfANRSw1yaAdXOARpFeRNpHfwW8 bVAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699367047; x=1699971847; 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=mtDpNZGc7bpiPdq3AvEGwADJunLb29I37B0SspqL8mk=; b=Veuq8fDVGTFE8Dw/PwGqxzJBZY85dMNJNc3ygg1a/sQ+T79YGIVb7DCZIdFP8oqd0X xiIDcgGELRh/auDno3W4+6q66KE8q06bhsiPEV9o4oogogIMoYscWb3TdScUZopnbtOU 0LRR8kD9mIqe2Y3kT4qY5TxJNQcuG3qAlnNqIDYhmWgiUfQ/bsqJQ0SyqN1JAObsHJ0c FCxGa6fgVJl2QpJunld4ZoB2d19CEGmjrC4F3tWVyH+7m32zG/U9VhV3CNn9WFy4Jktp 9f/qvrB3tcAaYIP4JKbIaTQ2WbTPUckmSqsTPPJ0Wg1tNieaeZmG8nPx/vEVuFAcuMCS +BKQ== X-Gm-Message-State: AOJu0YwQyRj3+WTdkSVVvHdvWfZ3SCC6z9x6yD4omApgkoVw6o9HaFOY 1Va4hqTtCbEoVVncxMrAHgmtCw== X-Received: by 2002:a05:6512:1085:b0:509:458a:6c1 with SMTP id j5-20020a056512108500b00509458a06c1mr15561705lfg.19.1699367047239; Tue, 07 Nov 2023 06:24:07 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id x4-20020adfdd84000000b0032fb0e2087asm2492340wrl.82.2023.11.07.06.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 06:24:03 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 989BB5F790; Tue, 7 Nov 2023 14:23:55 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Paolo Bonzini Subject: [PULL 11/23] cpu: Call plugin hooks only when ready Date: Tue, 7 Nov 2023 14:23:42 +0000 Message-Id: <20231107142354.3151266-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231107142354.3151266-1-alex.bennee@linaro.org> References: <20231107142354.3151266-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12a; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x12a.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 From: Akihiko Odaki 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 Message-Id: <20231025093128.33116-16-akihiko.odaki@daynix.com> Signed-off-by: Alex Bennée Message-Id: <20231106185112.2755262-12-alex.bennee@linaro.org> 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 bab8942c30..0acfed4c0f 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -209,6 +209,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 */ } @@ -216,6 +221,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); }