From nobody Sun Apr 12 00:56:45 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772441226; cv=none; d=zohomail.com; s=zohoarc; b=RW7toeWYuAOVJKonvjmgDqdhT6kh7oS+/NL9vlZq1Mo0vaz4LUyz/VR/RgZfRyDHK3fBznDRXUgENrLfnK3naXlLik6TONTXjcLTuujlkqTqwAzoZ4rMvKFb7rmqDehp+r1VMaoa7VKUtZN8lpUE09pRj/CWIHtyOEKXkh0Ub0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772441226; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wm3ocIz5yPuGAgAzqL1S37jXenPDu6rAMForht0QG5U=; b=hoagUqpuypihzNlGyBy5p50iw4f9J2OFZY165wAljwVXgFD9/VPmHUjmEnjuLIqKeROfeJv2mE44ONqxMq0kaHn2ZW12zlS7LZZy+Z8AfHh1kuGXPbctfmoGX6cpg9kIyVXC5lnFLFJTjHYJlgh5llrKxNn/ikLveSA4w1aKOwE= 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772441226046441.4449826448481; Mon, 2 Mar 2026 00:47:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vwytR-0001nj-L3; Mon, 02 Mar 2026 03:44:48 -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 1vwytD-0001j8-Aw for qemu-devel@nongnu.org; Mon, 02 Mar 2026 03:44:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vwytB-0001Ya-4M for qemu-devel@nongnu.org; Mon, 02 Mar 2026 03:44:31 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-340-pxzqF27OMnCSKN9iAQ0h5g-1; Mon, 02 Mar 2026 03:44:26 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4836abfc742so33317225e9.0 for ; Mon, 02 Mar 2026 00:44:26 -0800 (PST) Received: from [192.168.10.48] ([151.95.144.138]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483bfb296bfsm154969135e9.0.2026.03.02.00.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 00:44:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772441067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wm3ocIz5yPuGAgAzqL1S37jXenPDu6rAMForht0QG5U=; b=K8sv/0WPSi//Xc+wgntrAe782J14femFg6Vi9VvCx3ADRNgyOPg/pg1Jt1UE+05CGaTFpP 6wvs8bUAFbYcGjxvSUBvMZqSW/CJCXiBDz7E/yOmTZK4gijzZCpMqn0cCEAaYDrP9m5soe 3K06rdubsfCPeAYZeSJz8lTOX52AmZI= X-MC-Unique: pxzqF27OMnCSKN9iAQ0h5g-1 X-Mimecast-MFC-AGG-ID: pxzqF27OMnCSKN9iAQ0h5g_1772441065 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1772441064; x=1773045864; 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=wm3ocIz5yPuGAgAzqL1S37jXenPDu6rAMForht0QG5U=; b=ZNxkrc9h2EA0LAUaGHTlzTiAgvI80VrZ6svA9enSshFTULK08Qv6U2Mg4UpI2TZJj2 KQU/ihljaEdDpHEB+dl5TkrWFM/V0kFKZCrCIafL/rJxKHBZ7iiksZxZ+r61TStXkz7k k7L8Egrq6oTWfS+eh2OHTbA7GZgU8/14wAieCZBiQUSO0c/kiqeTc6hNmfe3metbfQba cUfOZth8sI+FQUfmfKSVzTGXi7sKNwiybCKzAb1eaixQRHBoxXs3YtSXFULmSn+XfgM8 40sV+uzsMukCzRErNZTR5OcEB5FhdmWm5ekP5fZQjF7ypqm54PVo9k3ndtcbgexC91zX svqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772441064; x=1773045864; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=wm3ocIz5yPuGAgAzqL1S37jXenPDu6rAMForht0QG5U=; b=C5gNOEMFVS8WIRbMQsyg37gxOZD8NNKoxZmnzA6kCcHdCc4jZxtUXIFHNQM0H1Sg6q 8mmQQAdcF0uIrCBHcl3hrynraowg3ix/ZuBKfmS3aQ5HgjtM62kO5L67rNbqM4bHfeYn iTeFX5FyXsYaXuWeeVRSe39coBnIthR1rCK74CgjM0EmPa3vq99Tfb4mzy1guA5GLpxk SIkJJE+jBllBPFCAG7uUVEEOWU7e/AZtK+KtyqNuyGOtUjueQxGOBXQiA5GZeNbycpbw tn1J7ynsYzp0PFdsBsHKtzkOjeXa0MV1vok1QXgxVH8u877Q8tJfxOMPFnNh3n9jV51O /w0A== X-Gm-Message-State: AOJu0YxE3tZ9Lq+2XyLpsAQZJeizRWYQTl8O3xajdPlzCPfgcQ3JNTRs s8Hp19zsQqotkjvPDYXIiBtSRtvLCe9b56jNw51DLPn8uxUGaM4yejyf9nGvFaUOauq88WYCYR8 OAIO6b3upKc3ysnDewSsq0TGIPJNs5E9yRSHgZMk1gGmkc46h8YTDNHCP/qoQHXtoG0fovqntBN UGN9v/BGJVHoX3XHrhVW1pN1J8mwLsTFMq8mcz+xGE X-Gm-Gg: ATEYQzzZoOd8d2l8HrwtaVkbntM6Mim5sJ3GdNlOvp1s1eJe+/craFqdgBEmMIx0N/4 bUDISxy316Scg8EsXDBMNDUO7ZaKmrObJrRPke+ldMEJLG6lO/fhPZMZMzQavsO/g5x2SMEGHXN QjyhuvmkkxfSIQym73XuA8j/xj6yTMCB7Q//cKoOxjFw3rD7z6/UKcwEFclIrH/oB8mJv702jm1 RrbOel9KoUdXo76eto7qifU/lC81IXwvwTtRKt+wThYft2F3WopxtyuhZAD0AqAJwhk8GTCkJ8v /EOWmENLD8n2mR+EXX2m4ZnA19bdjvzEiTKtNPwiVjWegD1HPOiNJMBPW6DQLecIsyPVZe4TCIZ vMHDWDTTCWrj/HXjE6aZBrgBToDH0QmnomQdwXSGOSeeurqv8hig7INFF3QE/S7yvK8rh/PN2+k f5lrBSjtnUnXt5ki2DSpyifLwu5fY= X-Received: by 2002:a05:600c:1d12:b0:483:9cdc:8ac1 with SMTP id 5b1f17b1804b1-483c9b9eb7amr184465915e9.11.1772441064499; Mon, 02 Mar 2026 00:44:24 -0800 (PST) X-Received: by 2002:a05:600c:1d12:b0:483:9cdc:8ac1 with SMTP id 5b1f17b1804b1-483c9b9eb7amr184465355e9.11.1772441063910; Mon, 02 Mar 2026 00:44:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Mohamed Mediouni , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 016/102] whpx: common, i386, arm: rework state levels Date: Mon, 2 Mar 2026 09:42:11 +0100 Message-ID: <20260302084338.473368-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302084338.473368-1-pbonzini@redhat.com> References: <20260302084338.473368-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.012, RCVD_IN_VALIDITY_RPBL_BLOCKED=1.188, SPF_HELO_PASS=-0.001, SPF_PASS=-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: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1772441228095158500 From: Mohamed Mediouni Change state levels from a set of ifdefs to an enum. Make register state loads use state levels too. Signed-off-by: Mohamed Mediouni Reviewed-by: Philippe Mathieu-Daud=C3=A9 Link: https://lore.kernel.org/r/20260223233950.96076-16-mohamed@unpredictab= le.fr Signed-off-by: Paolo Bonzini --- include/system/whpx-accel-ops.h | 16 ++++++++++------ include/system/whpx-all.h | 6 ++++-- accel/whpx/whpx-common.c | 8 ++++---- target/arm/whpx/whpx-all.c | 8 ++++---- target/i386/whpx/whpx-all.c | 16 ++++++++-------- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/include/system/whpx-accel-ops.h b/include/system/whpx-accel-op= s.h index ed9d4c49f4d..4b2a7326548 100644 --- a/include/system/whpx-accel-ops.h +++ b/include/system/whpx-accel-ops.h @@ -22,11 +22,15 @@ void whpx_cpu_synchronize_post_reset(CPUState *cpu); void whpx_cpu_synchronize_post_init(CPUState *cpu); void whpx_cpu_synchronize_pre_loadvm(CPUState *cpu); =20 -/* state subset only touched by the VCPU itself during runtime */ -#define WHPX_SET_RUNTIME_STATE 1 -/* state subset modified during VCPU reset */ -#define WHPX_SET_RESET_STATE 2 -/* full state set, modified during initialization or on vmload */ -#define WHPX_SET_FULL_STATE 3 +typedef enum WHPXStateLevel { + /* subset of runtime state for faster returns from vmexit */ + WHPX_LEVEL_FAST_RUNTIME_STATE, + /* state subset only touched by the VCPU itself during runtime */ + WHPX_LEVEL_RUNTIME_STATE, + /* state subset modified during VCPU reset */ + WHPX_LEVEL_RESET_STATE, + /* full state set, modified during initialization or on vmload */ + WHPX_LEVEL_FULL_STATE +} WHPXStateLevel; =20 #endif /* TARGET_I386_WHPX_ACCEL_OPS_H */ diff --git a/include/system/whpx-all.h b/include/system/whpx-all.h index b831c463b0b..2cbea71b149 100644 --- a/include/system/whpx-all.h +++ b/include/system/whpx-all.h @@ -2,10 +2,12 @@ #ifndef SYSTEM_WHPX_ALL_H #define SYSTEM_WHPX_ALL_H =20 +#include "system/whpx-accel-ops.h" + /* Called by whpx-common */ int whpx_vcpu_run(CPUState *cpu); -void whpx_get_registers(CPUState *cpu); -void whpx_set_registers(CPUState *cpu, int level); +void whpx_get_registers(CPUState *cpu, WHPXStateLevel level); +void whpx_set_registers(CPUState *cpu, WHPXStateLevel level); int whpx_accel_init(AccelState *as, MachineState *ms); void whpx_cpu_instance_init(CPUState *cs); HRESULT whpx_set_exception_exit_bitmap(UINT64 exceptions); diff --git a/accel/whpx/whpx-common.c b/accel/whpx/whpx-common.c index 88eef557998..4863fc86631 100644 --- a/accel/whpx/whpx-common.c +++ b/accel/whpx/whpx-common.c @@ -46,7 +46,7 @@ struct WHPDispatch whp_dispatch; void whpx_flush_cpu_state(CPUState *cpu) { if (cpu->vcpu_dirty) { - whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE); cpu->vcpu_dirty =3D false; } } @@ -180,7 +180,7 @@ int whpx_last_vcpu_stopping(CPUState *cpu) static void do_whpx_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data a= rg) { if (!cpu->vcpu_dirty) { - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); cpu->vcpu_dirty =3D true; } } @@ -188,14 +188,14 @@ static void do_whpx_cpu_synchronize_state(CPUState *c= pu, run_on_cpu_data arg) static void do_whpx_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg) { - whpx_set_registers(cpu, WHPX_SET_RESET_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_RESET_STATE); cpu->vcpu_dirty =3D false; } =20 static void do_whpx_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg) { - whpx_set_registers(cpu, WHPX_SET_FULL_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_FULL_STATE); cpu->vcpu_dirty =3D false; } =20 diff --git a/target/arm/whpx/whpx-all.c b/target/arm/whpx/whpx-all.c index 0d56e468bdf..bb94eac7bf8 100644 --- a/target/arm/whpx/whpx-all.c +++ b/target/arm/whpx/whpx-all.c @@ -417,7 +417,7 @@ int whpx_vcpu_run(CPUState *cpu) do { bool advance_pc =3D false; if (cpu->vcpu_dirty) { - whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE); cpu->vcpu_dirty =3D false; } =20 @@ -482,7 +482,7 @@ int whpx_vcpu_run(CPUState *cpu) default: error_report("WHPX: Unexpected VP exit code 0x%08x", vcpu->exit_ctx.ExitReason); - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); bql_lock(); qemu_system_guest_panicked(cpu_get_crash_info(cpu)); bql_unlock(); @@ -516,7 +516,7 @@ static void clean_whv_register_value(WHV_REGISTER_VALUE= *val) memset(val, 0, sizeof(WHV_REGISTER_VALUE)); } =20 -void whpx_get_registers(CPUState *cpu) +void whpx_get_registers(CPUState *cpu, WHPXStateLevel level) { ARMCPU *arm_cpu =3D ARM_CPU(cpu); CPUARMState *env =3D &arm_cpu->env; @@ -563,7 +563,7 @@ void whpx_get_registers(CPUState *cpu) aarch64_restore_sp(env, arm_current_el(env)); } =20 -void whpx_set_registers(CPUState *cpu, int level) +void whpx_set_registers(CPUState *cpu, WHPXStateLevel level) { ARMCPU *arm_cpu =3D ARM_CPU(cpu); CPUARMState *env =3D &arm_cpu->env; diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index baa3169c55c..c09d9affefa 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -367,7 +367,7 @@ static uint64_t whpx_cr8_to_apic_tpr(uint64_t cr8) return cr8 << 4; } =20 -void whpx_set_registers(CPUState *cpu, int level) +void whpx_set_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx =3D &whpx_global; AccelCPUState *vcpu =3D cpu->accel; @@ -386,7 +386,7 @@ void whpx_set_registers(CPUState *cpu, int level) * Following MSRs have side effects on the guest or are too heavy for * runtime. Limit them to full state update. */ - if (level >=3D WHPX_SET_RESET_STATE) { + if (level >=3D WHPX_LEVEL_RESET_STATE) { whpx_set_tsc(cpu); } =20 @@ -583,7 +583,7 @@ static void whpx_get_xcrs(CPUState *cpu) cpu_env(cpu)->xcr0 =3D xcr0.Reg64; } =20 -void whpx_get_registers(CPUState *cpu) +void whpx_get_registers(CPUState *cpu, WHPXStateLevel level) { struct whpx_state *whpx =3D &whpx_global; AccelCPUState *vcpu =3D cpu->accel; @@ -770,10 +770,10 @@ static int emulate_instruction(CPUState *cpu, const u= int8_t *insn_bytes, size_t struct x86_decode decode =3D { 0 }; x86_insn_stream stream =3D { .bytes =3D insn_bytes, .len =3D insn_len = }; =20 - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FAST_RUNTIME_STATE); decode_instruction_stream(env, &decode, &stream); exec_instruction(env, &decode); - whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_FAST_RUNTIME_STATE); =20 return 0; } @@ -1589,7 +1589,7 @@ int whpx_vcpu_run(CPUState *cpu) =20 do { if (cpu->vcpu_dirty) { - whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + whpx_set_registers(cpu, WHPX_LEVEL_RUNTIME_STATE); cpu->vcpu_dirty =3D false; } =20 @@ -1796,7 +1796,7 @@ int whpx_vcpu_run(CPUState *cpu) break; } case WHvRunVpExitReasonException: - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); =20 if ((vcpu->exit_ctx.VpException.ExceptionType =3D=3D WHvX64ExceptionTypeDebugTrapOrFault) && @@ -1828,7 +1828,7 @@ int whpx_vcpu_run(CPUState *cpu) default: error_report("WHPX: Unexpected VP exit code %d", vcpu->exit_ctx.ExitReason); - whpx_get_registers(cpu); + whpx_get_registers(cpu, WHPX_LEVEL_FULL_STATE); bql_lock(); qemu_system_guest_panicked(cpu_get_crash_info(cpu)); bql_unlock(); --=20 2.53.0