KVM allows trap and emulate (read: NOP) of the MONITOR and MWAIT instructions. There is work undergoing to enable actual execution of these inside of KVM, but nobody really wants to expose the feature to the guest by default, as it would eat up all of the host CPU.
So today there is no streamlined way to actually notify the guest that it's ok to execute MONITOR / MWAIT, even when we want to explicitly leave the guest in guest context. This patch adds a new -cpu parameter called "mwait" which - when enabled - force enables the MONITOR / MWAIT CPUID flag, even when the underlying accel framework does not explicitly advertise support. With that in place, we can explicitly allow users to specify that they want have the guest execute MONITOR / MWAIT in its idle loop. Signed-off-by: Alexander Graf <ag...@suse.de> --- target/i386/cpu.c | 5 +++++ target/i386/cpu.h | 1 + 2 files changed, 6 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7aa7622..c44020b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3460,6 +3460,10 @@ static int x86_cpu_filter_features(X86CPU *cpu) x86_cpu_get_supported_feature_word(w, false); uint32_t requested_features = env->features[w]; env->features[w] &= host_feat; + if (cpu->expose_monitor && (w == FEAT_1_ECX)) { + /* Force monitor feature in */ + env->features[w] |= CPUID_EXT_MONITOR; + } cpu->filtered_features[w] = requested_features & ~env->features[w]; if (cpu->filtered_features[w]) { rv = 1; @@ -3988,6 +3992,7 @@ static Property x86_cpu_properties[] = { DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false), DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true), + DEFINE_PROP_BOOL("mwait", X86CPU, expose_monitor, false), DEFINE_PROP_UINT32("phys-bits", X86CPU, phys_bits, 0), DEFINE_PROP_BOOL("host-phys-bits", X86CPU, host_phys_bits, false), DEFINE_PROP_BOOL("fill-mtrr-mask", X86CPU, fill_mtrr_mask, true), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 07401ad..7400d00 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1214,6 +1214,7 @@ struct X86CPU { bool check_cpuid; bool enforce_cpuid; bool expose_kvm; + bool expose_monitor; bool migratable; bool max_features; /* Enable all supported features automatically */ uint32_t apic_id; -- 1.8.5.6