qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] i386: Allow monitor / mwait cpuid override
@ 2017-03-27 14:26 Alexander Graf
  2017-03-27 15:46 ` Eduardo Habkost
  2018-02-27  9:52 ` Gonglei (Arei)
  0 siblings, 2 replies; 12+ messages in thread
From: Alexander Graf @ 2017-03-27 14:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Richard Henderson, Eduardo Habkost

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 <agraf@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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-02-28 12:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-27 14:26 [Qemu-devel] [PATCH] i386: Allow monitor / mwait cpuid override Alexander Graf
2017-03-27 15:46 ` Eduardo Habkost
2017-03-27 16:10   ` Alexander Graf
2017-03-27 16:33     ` Eduardo Habkost
2017-03-27 16:42       ` Alexander Graf
2017-03-27 18:06         ` Eduardo Habkost
2017-03-27 16:22   ` Alexander Graf
2017-03-27 16:27     ` Paolo Bonzini
2018-02-27  9:52 ` Gonglei (Arei)
2018-02-27 23:55   ` Alexander Graf
2018-02-28 11:50     ` Paolo Bonzini
2018-02-28 12:24       ` Wanpeng Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).