From patchwork Mon Nov 6 18:51:01 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: 741425 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1255110wrr; Mon, 6 Nov 2023 10:52:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZeZPbHpKLeWVA07dYsh0IbwLknKJxtEsyHQn88GIcEM4qVJHxPVOqsjsHxm3maLR8PEiO X-Received: by 2002:a05:620a:3729:b0:777:73d3:1f55 with SMTP id de41-20020a05620a372900b0077773d31f55mr529776qkb.6.1699296758959; Mon, 06 Nov 2023 10:52:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699296758; cv=none; d=google.com; s=arc-20160816; b=IhvNi9gFn6Jy/fpA/GBXzU8lPHlS/Ovm1rRUFba1t04sWzoNfw/c+iTMhSHLr3qsCK ZjqBI1l+2ZtZggn2zVOyWHrhoo0bPyU2uuc+y6TyMNpMz0QIDPNg6DUWP65NPaxA9n4G RhumyIPxeAcQ/2jFwy2XTAcwkvQbY0WjjvdpuzVNN+WVbZGkViM8CxsUR+m3Dq8/abRo BdRguSdw2kCMkzt0704fKuuuEp7IKkkUYek39Y83WtZ0bcamMHNprI3Hl39ZD8G5G4ib vyA247bouQqm7vVhpfsHmU8XkayfN3GpdrshkhyOpTME3BqSH9CvKP73OYkNSpL8jyDV Mn+g== 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=MH6reWsIJbO30PCgx+SNdzqaOig4Me7urqqeVULhhmk=; fh=QpeTAvHhnTko3wrHMxWRvx4UcZ87hia2zOY3VJVcfak=; b=CD2Xe9mbTTfivBMyFnIh/zxZ2wkuTdNpuQNJGsb/2pT4KRc9XM139MyUmp0AzKbeOq 9vmXtTYijgkgDntvFMOD8OoXvVC97lB1VhmlzlfzhOfnuNTzW4K8dUNIvcKx8owogxpH sHvZ897czwmy4N3p5LtxoqcIvul7JF2Wq/rblqvxDN58pHIJwbtikNXCk1c9dzZe7ALk gCdmsjAwliTAyWKCrhqLQMJUrSpIBXP7+70NhZtT8bwF6Pc93McUYrJxgGMP2m0s2yFV JuoKoXOs2CqS3397HxUVU/ycTexVnQdLtM3Y3U3FAZ0WQboBYo0g2GsEjPObFGbzRdwj eFjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NFRuOB0T; 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 h6-20020a05620a284600b00775d0319908si6387052qkp.16.2023.11.06.10.52.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Nov 2023 10:52:38 -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=NFRuOB0T; 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 1r04hB-0006D9-UA; Mon, 06 Nov 2023 13:51:33 -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 1r04h9-0006A6-6g for qemu-devel@nongnu.org; Mon, 06 Nov 2023 13:51:31 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r04h3-00010R-TL for qemu-devel@nongnu.org; Mon, 06 Nov 2023 13:51:30 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-32deb2809daso2888957f8f.3 for ; Mon, 06 Nov 2023 10:51:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699296684; x=1699901484; 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=MH6reWsIJbO30PCgx+SNdzqaOig4Me7urqqeVULhhmk=; b=NFRuOB0TaKNtfxjLBRk1q3FxAs5UfIdfMbP1LbDkbEJIRjFjGuaICeSeljxP65YAht ukIY45kjUjlXFMiqsTCFg9jR7FoT6QfPEQJ/yIdbqndPViRFXRu4/GRCw7vQr3Hz0FAc Je1Ua7YbxEV/Pqr0EQOMWYIZdCOqdAjYXEGNn4zYMNrt2ZsXravo4NiL61rXrwcBqqGa lH/krMUzTJc+jP0qi/LIFgPmEUEFQowlTas1X/QZ3edpmeHHNKCfZXlBODH5i+htIrav 1MniAk2ld2cPphCYEtPDnAKGHxyt1Yr1KWRIL1i/5NEr51avgUP6JSoe2zIs/WTXJ5Ox 7UDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699296684; x=1699901484; 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=MH6reWsIJbO30PCgx+SNdzqaOig4Me7urqqeVULhhmk=; b=OuXmnfdjoVlG6fq2WR2WgcLbhQ575qI6qZ1Koz8+otkCi8y8IaMy/IuQYi3SXxWmHn TXpGHa3h8m7mbUUR9jze4+1S8yag1hRg4hxeZK1pA4+9gNmDJbGJyDgTC6D90PrfKR7t 5sjvZTvMA7b+iQ3xjjEsZYfozKLjYUG7tuXfCh/DlMkg/mKBxmP1naMAEPpPi6TtHPY9 L/Nf2Vh+oiHNWKTEXW1tZUlUBBy7D6WHmE/ht5MHo6XiIuVuRDMn6WDrnTP+MxUhX09F UdpmuEBgWO4548Wu3IrQ8jj/elSAq+GEA6EUk7U9hyTQz7pbkiPypKOfizhFaOzIqxcZ SVeg== X-Gm-Message-State: AOJu0Ywn35b34dfHmf2z/mRY5QiCWjbNBlgO34NW9l+hhRB2ryLUTa7u zMuXXqf/AkDlH221ABuqlLtDHw== X-Received: by 2002:a05:6000:154a:b0:32f:79e5:8109 with SMTP id 10-20020a056000154a00b0032f79e58109mr27062604wry.2.1699296684299; Mon, 06 Nov 2023 10:51:24 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id o12-20020a5d4a8c000000b0032fbd0c7d04sm304416wrq.55.2023.11.06.10.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 10:51:19 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 763C665565; Mon, 6 Nov 2023 18:51:13 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Laurent Vivier , =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Cleber Rosa , Wainer dos Santos Moschetta , Paolo Bonzini , Thomas Huth , Beraldo Leal , Alexandre Iooss , John Snow , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Chris Wulff , Marek Vasut , Richard Henderson , Akihiko Odaki Subject: [PATCH 11/22] cpu: Call plugin hooks only when ready Date: Mon, 6 Nov 2023 18:51:01 +0000 Message-Id: <20231106185112.2755262-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106185112.2755262-1-alex.bennee@linaro.org> References: <20231106185112.2755262-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x436.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=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+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: <20231103195956.1998255-23-alex.bennee@linaro.org> --- 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 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); }