@samitouri / QOSamiQemu / commits / 94ab400266

target/i386: emulate: add new callbacks

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> Link: https://lore.kernel.org/r/20260324151323.74473-7-mohamed@unpredictable.fr Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Mohamed Mediouni committed Mar 24, 2026 at 16:13 UTC 94ab4002661071c7de101da764230c25452f34fe
3 files changed +12
target/i386/emulate/x86_emu.h
+3
@@ -32,6 +32,9 @@ struct x86_emul_ops {
32 int size, int count);
33 void (*simulate_rdmsr)(CPUState *cs);
34 void (*simulate_wrmsr)(CPUState *cs);
35 + bool (*is_protected_mode)(CPUState *cpu);
36 + bool (*is_long_mode)(CPUState *cpu);
37 + bool (*is_user_mode)(CPUState *cpu);
38 };
39
40 extern const struct x86_emul_ops *emul_ops;
target/i386/emulate/x86_helpers.c
+6
@@ -211,6 +211,9 @@ bool x86_is_protected(CPUState *cpu)
211 X86CPU *x86_cpu = X86_CPU(cpu);
212 CPUX86State *env = &x86_cpu->env;
213 uint64_t cr0 = env->cr[0];
214 + if (emul_ops->is_protected_mode) {
215 + return emul_ops->is_protected_mode(cpu);
216 + }
217
218 return cr0 & CR0_PE_MASK;
219 }
@@ -234,6 +237,9 @@ bool x86_is_long_mode(CPUState *cpu)
237 uint64_t efer = env->efer;
238 uint64_t lme_lma = (MSR_EFER_LME | MSR_EFER_LMA);
239
240 + if (emul_ops->is_long_mode) {
241 + return emul_ops->is_long_mode(cpu);
242 + }
243 return ((efer & lme_lma) == lme_lma);
244 }
245
target/i386/emulate/x86_mmu.c
+3
@@ -49,6 +49,9 @@
49
50 static bool is_user(CPUState *cpu)
51 {
52 + if (emul_ops->is_user_mode) {
53 + return emul_ops->is_user_mode(cpu);
54 + }
55 return false;
56 }
57