From: Alexander Graf <agraf@suse.de>
To: "Gabriel L. Somlo" <gsomlo@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org, mst@redhat.com
Subject: Re: [PATCH v2] kvm: x86: emulate monitor and mwait instructions as nop
Date: Wed, 04 Jun 2014 17:09:49 +0200 [thread overview]
Message-ID: <538F36BD.9040404@suse.de> (raw)
In-Reply-To: <20140604150519.GG1653@ERROL.INI.CMU.EDU>
On 04.06.14 17:05, Gabriel L. Somlo wrote:
> On Wed, Jun 04, 2014 at 04:44:13PM +0200, Alexander Graf wrote:
>> On 04.06.14 16:39, Gabriel L. Somlo wrote:
>>> Paolo,
>>>
>>> I noticed the monitor=mwait=nop patch is making its way upstream, so
>>> thanks !
>>>
>>> I'm still interested in following up with something that would enable
>>> this behavior only conditionally (e.g. following an ioctl call from
>>> userspace to enable it only for the (set of) vcpu(s) belonging to one
>>> guest VM at a time), which should then also include advertising the
>>> feature in CPUID.
>>>
>>> I grep-ed through the kvm sources for KVM_CAP for some inspiration,
>>> and it looks more like KVM_CAP_* is a way to tell userspace what the
>>> kernel supports, but nothing I saw showed me an example of a "tunable"
>>> feature that userspace may ask to be turned on or off (e.g per-vcpu).
>>>
>>> Is there something like that I could use as an example ?
>> Sure, we use it all over the place on PPC :).
> Allright, I'll grep harder, then :)
>
>>> Obviously, if you really like the current behavior better you can
>>> always reject whatever patch I'll come up with, but I'd like to at
>>> least try and see what it would look like :)
>> I think it's perfectly fine to leave mwait always implemented as NOP - it's
>> valid behavior.
> NOP is valid MWAIT behavior, *unless* MWAIT should generate an invalid
> opcode (i.e., if CPUID says mwait not supported). In that respect,
> we're cheating only to hook up guests which misbehave. I'd feel less
> "dirty" if I could explicitly tell KVM "ok, just this once is OK, but
> don't make a habit of it" :)
We don't limit instructions the guest can execute properly anyway. If
CPUID doesn't expose AVX, but the host CPU supports AVX, the guest can
still call AVX instructions.
So I think we're safe to always handle MWAIT :).
>
>> As for the CPUID exposure, that should be a pure QEMU thing. If overriding
>> CPUID bits the kernel mask tells us doesn't work today, we should just make
>> it possible :).
>>
>> Eventually I really think that -cpu foo,+mwait,+monitor or whatever the bits
>> are should override any safety net that KVM gives us on features it thinks
>> are safe to use.
> I need to look at the qemu source, doing what you said
> (+monitor,+mwait,+whatever) right now "works", doesn't generate an error,
> but silently ignores you if it's not implemented. So I'd actually have to
> generate a patch to make something happen when they're present on the
> command line.
>
> The part I'm unsure about is "how bad is it to cheat the way we do right
> now", vs. "how much is it worth to be pedantic and require explicitly
> enabling things, in both qemu and kvm"... I feel like I don't know
> enough to 1. have a strong opinion either way, and 2. have my opinion
> be *right* :) Which is why I won't let it go already (and thanks for
> all your patience, BTW) :)
I think it's sane behavior to not expose the MWAIT capability in the
default CPUID mask (which comes from KVM) unless we can actually emulate
it properly ;).
However, I think it's very important to be able to force CPUID bits to
on from QEMU even when KVM says it doesn't support them. I actually
thought we could do that already, but that code got refactored a number
of times over the years, so maybe that ability got lost.
Basically KVM gives QEMU 2 ioctls:
* get list of KVM supported CPUIDs
* set guest exposed CPUIDs
Whether QEMU wants to only set CPUID bits that the kernel actually
supports is up to its own implementation. Usually the "enforce" option
is there to guarantee that all CPUID bits are actually supported.
Apparently all unsupported bits just get dropped silently today. IMHO
they shouldn't if they were specified through -cpu ...,+feature.
Alex
next prev parent reply other threads:[~2014-06-04 15:09 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-07 20:52 [PATCH v2] kvm: x86: emulate monitor and mwait instructions as nop Gabriel L. Somlo
2014-06-02 19:25 ` Gabriel L. Somlo
2014-06-02 19:48 ` Alexander Graf
2014-06-02 20:20 ` Michael S. Tsirkin
2014-06-02 20:35 ` Alexander Graf
2014-06-02 20:41 ` Michael S. Tsirkin
2014-06-02 21:01 ` Alexander Graf
2014-06-03 1:55 ` Gabriel L. Somlo
2014-06-02 20:24 ` Michael S. Tsirkin
2014-06-03 9:17 ` Paolo Bonzini
2014-06-03 14:21 ` Gabriel L. Somlo
2014-06-03 15:37 ` Alexander Graf
2014-06-03 19:07 ` Gabriel L. Somlo
2014-06-10 10:16 ` Michael S. Tsirkin
2014-06-04 14:39 ` Gabriel L. Somlo
2014-06-04 14:44 ` Alexander Graf
2014-06-04 15:05 ` Gabriel L. Somlo
2014-06-04 15:09 ` Alexander Graf [this message]
2014-06-04 17:07 ` Gabriel L. Somlo
2014-06-04 19:06 ` Michael S. Tsirkin
2014-06-04 19:24 ` Gabriel L. Somlo
2014-06-04 19:37 ` Michael S. Tsirkin
2014-06-04 16:34 ` Paolo Bonzini
2014-06-04 19:08 ` Michael S. Tsirkin
2014-06-04 19:33 ` Gabriel L. Somlo
2014-06-04 19:40 ` Michael S. Tsirkin
2014-06-04 19:12 ` Nadav Amit
2014-06-04 19:43 ` Gabriel L. Somlo
2014-06-04 20:44 ` Borislav Petkov
2014-06-05 14:40 ` Eduardo Habkost
2014-06-05 20:59 ` Eric Northup
2014-06-05 21:19 ` Gabriel L. Somlo
[not found] <46EF8587-E226-44C5-930A-49E4F7FBBC82@gmail.com>
2014-06-04 20:01 ` Nadav Amit
2014-06-04 20:11 ` Gabriel L. Somlo
2014-06-04 20:55 ` Nadav Amit
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=538F36BD.9040404@suse.de \
--to=agraf@suse.de \
--cc=gsomlo@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
/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