public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: Mohamed Mediouni <mohamed@unpredictable.fr>
To: qemu-devel@nongnu.org
Cc: Roman Bolshakov <rbolshakov@ddn.com>,
	Mohamed Mediouni <mohamed@unpredictable.fr>,
	Wei Liu <wei.liu@kernel.org>,
	Phil Dennis-Jordan <phil@philjordan.eu>,
	Pedro Barbuda <pbarbuda@microsoft.com>
Subject: [PATCH v3 06/12] target/i386: emulate: add new callbacks
Date: Tue, 24 Mar 2026 16:13:17 +0100	[thread overview]
Message-ID: <20260324151323.74473-7-mohamed@unpredictable.fr> (raw)
In-Reply-To: <20260324151323.74473-1-mohamed@unpredictable.fr>

On Hyper-V fetching some guest registers is really expensive, so
add a way to query some state from information provided by Hyper-V
to save time on vmexits.

Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
---
 target/i386/emulate/x86_emu.h     | 3 +++
 target/i386/emulate/x86_helpers.c | 6 ++++++
 target/i386/emulate/x86_mmu.c     | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/target/i386/emulate/x86_emu.h b/target/i386/emulate/x86_emu.h
index 0f284b0c3d..4ed970bd53 100644
--- a/target/i386/emulate/x86_emu.h
+++ b/target/i386/emulate/x86_emu.h
@@ -32,6 +32,9 @@ struct x86_emul_ops {
                       int size, int count);
     void (*simulate_rdmsr)(CPUState *cs);
     void (*simulate_wrmsr)(CPUState *cs);
+    bool (*is_protected_mode)(CPUState *cpu);
+    bool (*is_long_mode)(CPUState *cpu);
+    bool (*is_user_mode)(CPUState *cpu);
 };
 
 extern const struct x86_emul_ops *emul_ops;
diff --git a/target/i386/emulate/x86_helpers.c b/target/i386/emulate/x86_helpers.c
index 024f9a2afc..ebbf40f2b0 100644
--- a/target/i386/emulate/x86_helpers.c
+++ b/target/i386/emulate/x86_helpers.c
@@ -211,6 +211,9 @@ bool x86_is_protected(CPUState *cpu)
     X86CPU *x86_cpu = X86_CPU(cpu);
     CPUX86State *env = &x86_cpu->env;
     uint64_t cr0 = env->cr[0];
+    if (emul_ops->is_protected_mode) {
+        return emul_ops->is_protected_mode(cpu);
+    }
 
     return cr0 & CR0_PE_MASK;
 }
@@ -234,6 +237,9 @@ bool x86_is_long_mode(CPUState *cpu)
     uint64_t efer = env->efer;
     uint64_t lme_lma = (MSR_EFER_LME | MSR_EFER_LMA);
 
+    if (emul_ops->is_long_mode) {
+        return emul_ops->is_long_mode(cpu);
+    }
     return ((efer & lme_lma) == lme_lma);
 }
 
diff --git a/target/i386/emulate/x86_mmu.c b/target/i386/emulate/x86_mmu.c
index 4e39bae025..670939acdb 100644
--- a/target/i386/emulate/x86_mmu.c
+++ b/target/i386/emulate/x86_mmu.c
@@ -49,6 +49,9 @@
 
 static bool is_user(CPUState *cpu)
 {
+    if (emul_ops->is_user_mode) {
+        return emul_ops->is_user_mode(cpu);
+    }
     return false;
 }
 
-- 
2.50.1 (Apple Git-155)



  parent reply	other threads:[~2026-03-24 15:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24 15:13 [PATCH v3 00/12] whpx: i386: Windows 10 and performance fixes Mohamed Mediouni
2026-03-24 15:13 ` [PATCH v3 01/12] whpx: i386: workaround for Windows 10 support Mohamed Mediouni
2026-03-24 15:13 ` [PATCH v3 02/12] whpx: i386: enable exceptions VM exit only when needed Mohamed Mediouni
2026-03-24 15:13 ` [PATCH v3 03/12] whpx: i386: skip TSC read for MMIO exits Mohamed Mediouni
2026-03-24 15:13 ` [PATCH v3 04/12] whpx: i386: skip XCRs " Mohamed Mediouni
2026-03-24 15:13 ` [PATCH v3 05/12] whpx: i386: don't restore segment registers after MMIO handling Mohamed Mediouni
2026-03-24 15:13 ` Mohamed Mediouni [this message]
2026-03-24 15:13 ` [PATCH v3 07/12] whpx: i386: add implementation of new x86_emul_ops Mohamed Mediouni
2026-03-24 15:13 ` [PATCH v3 08/12] target/i386: emulate: indirect access to CRs Mohamed Mediouni
2026-03-24 15:13 ` [PATCH v3 09/12] whpx: i386: " Mohamed Mediouni
2026-03-24 15:13 ` [PATCH v3 10/12] target/i386: emulate: segmentation rework Mohamed Mediouni
2026-03-24 15:13 ` [PATCH v3 11/12] whpx: i386: fetch segments on-demand Mohamed Mediouni
2026-03-24 15:13 ` [PATCH v3 12/12] whpx: i386: fast runtime state reads Mohamed Mediouni
2026-03-24 15:20 ` [PATCH v3 00/12] whpx: i386: Windows 10 and performance fixes Mohamed Mediouni
2026-03-24 17:19 ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260324151323.74473-7-mohamed@unpredictable.fr \
    --to=mohamed@unpredictable.fr \
    --cc=pbarbuda@microsoft.com \
    --cc=phil@philjordan.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=rbolshakov@ddn.com \
    --cc=wei.liu@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox