From nobody Mon Sep 16 20:03:14 2024 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=1694851460; cv=none; d=zohomail.com; s=zohoarc; b=gvHSMr5Tbgz07OnkTkBvlAUA6C+pi9cvpBUKfnEySoMYZIiyIpyejl7H0LgsAGFw9jGjGp+PAvpAFJ7qAZUUAf4LQhO2vgqHcVyxvafEWmIG4JPRwOtQ70YjMgtIQLSv0vowppUrTButJ05uAWPwHrgjtgEuOucPW0a9KcLsDdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694851460; 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=du4pvBFajNyLkLy2seo77TR3Uw7N6iMFpyL/5U/v0Hk=; b=IgDws5Wwr+J0js/vAiZNDVJyIr38whuLPxYthC+mC7vGOvVRwzhDXH7Ax+3piKyMv5HyhfFSvgTwlehvIk/773mVzbBd68psUfoUf1yyiSF3jDD1z1le5IgOvcqf5Wi3w7xCURvAzbpvKv2iVgBcpiXtMM0TjAS1vXgxUPjXgCs= 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 1694851460815737.4773452397363; Sat, 16 Sep 2023 01:04:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhQGk-00046T-2K; Sat, 16 Sep 2023 04:03:10 -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 1qhQGh-00044o-Sg for qemu-devel@nongnu.org; Sat, 16 Sep 2023 04:03:07 -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 1qhQGg-0006Cs-6x for qemu-devel@nongnu.org; Sat, 16 Sep 2023 04:03:07 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68fe2470d81so2686610b3a.1 for ; Sat, 16 Sep 2023 01:03:05 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id z21-20020aa791d5000000b0068a46cd4120sm4029484pfa.199.2023.09.16.01.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 01:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694851385; x=1695456185; 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=du4pvBFajNyLkLy2seo77TR3Uw7N6iMFpyL/5U/v0Hk=; b=S/9YbuPHTiJYKMwLxuvsi14XMg7diUh9LszRrLNsFO0Ka+zoOE6EU/DZdfM1j9+ho7 vHqe0T9bT4Y7h49PfrFnyNBj+qzJVLLLKbUmxBTNmR2lgE8PmKwu55qhstUt4ftiPf8Q asiAWofKOfSOlHNg8XmjHB3qLqlVEgpzGwHTSYXlvvD/VI0YrczCZP2q2Mu0UHGhuOd5 /FP+TK2HKG2zF+88J++6lN6muqINrAC/MkKJPx8hEXlnFOI9KnZnqbqmwESbrUY6hhn3 Hu5drotMLW9Mbs6pU3o5czyR+FLBu0a7AnhxYOkBpaKJXoPqxta6gJyDMd3x1C1GFa34 4/UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694851385; x=1695456185; 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=du4pvBFajNyLkLy2seo77TR3Uw7N6iMFpyL/5U/v0Hk=; b=wP0oeHmDGwGccL/jpcJTesSXivU2wwCdWgH7wPHU4wA/kf19iOMgarQvK2ila2XCaa FGvL6zb4lmduQQ4BSutKP8B/RYT0XBN50H2QOF0cp9MhmBrcWRCgG9zvVL+pQg0lXURj Vwm6HgP2olBSJ47EnE7/W/wX07cgvn0ORDiSQvkBKULowWC/zavHLmlbss6cK3YbDlZZ uZn/Wj1BO76R2FubqxcKQczUVH1ME5jwidhiMUrFLcP+OQbuPf8/5LVfpiRGBXjjwqlX czczhQFYzpo0QPy1YdqjwOT3rWpyIISOy+bbnQTSGxPq9s7bXuhxB6GThbW74jFyn1lw wFGw== X-Gm-Message-State: AOJu0Yy0cT66QCr/l4PSKjRc/Bh/IUqm2Vy5kMqF2xz5TKYIxhTYescA LeVX0BwDX7gVcuqZhVvNZz64yA== X-Google-Smtp-Source: AGHT+IGZVJ0+iTdscgFe5KI7kBCxb7bNro4R6gZ2hWIeSNs60n6w+iaQ+0asWopU4Ch1mOoDtFi0pQ== X-Received: by 2002:a05:6a00:248a:b0:68e:496a:7852 with SMTP id c10-20020a056a00248a00b0068e496a7852mr4281560pfv.27.1694851385048; Sat, 16 Sep 2023 01:03:05 -0700 (PDT) From: Akihiko Odaki To: Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Akihiko Odaki , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang Subject: [PATCH v8 15/19] cpu: Call plugin hooks only when ready Date: Sat, 16 Sep 2023 17:01:32 +0900 Message-ID: <20230916080149.129989-16-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230916080149.129989-1-akihiko.odaki@daynix.com> References: <20230916080149.129989-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=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1694851462478100003 Content-Type: text/plain; charset="utf-8" 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 --- 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 88a1d186a6..d5e1eac8b3 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -210,6 +210,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 @@ -217,6 +222,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.42.0