From: Rik van Riel <riel@redhat.com>
To: David Hildenbrand <david@redhat.com>, pbonzini@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
tglx@linutronix.de, rkrcmar@redhat.com, borntraeger@de.ibm.com
Subject: Re: [PATCH] x86,kvm: move qemu/guest FPU switching out to vcpu_run
Date: Tue, 14 Nov 2017 16:11:22 -0500 [thread overview]
Message-ID: <1510693882.1080.3.camel@redhat.com> (raw)
In-Reply-To: <6f73cff1-eddf-7dc6-a93c-31c20e8520d7@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2398 bytes --]
On Tue, 2017-11-14 at 20:40 +0100, David Hildenbrand wrote:
> On 14.11.2017 19:07, Rik van Riel wrote:
> > On Tue, 2017-11-14 at 17:57 +0100, David Hildenbrand wrote:
> > >
> > > > diff --git a/arch/x86/include/asm/kvm_host.h
> > > > b/arch/x86/include/asm/kvm_host.h
> > > > index c73e493adf07..92e66685249e 100644
> > > > --- a/arch/x86/include/asm/kvm_host.h
> > > > +++ b/arch/x86/include/asm/kvm_host.h
> > >
> > > We should also get rid of guest_fpu_loaded now, right?
> >
> > Indeed, we no longer need that member. I'll get rid of it.
> >
> > > emulator_get_fpu() does a kvm_load_guest_fpu(). Doesn't that mean
> > > that
> > > this is now not needed anymore? (at least when emulator code is
> > > called
> > > from inside the loop?)
> >
> > Now that is a very good question!
> >
> > When called from inside the loop, it is indeed not
> > needed.
> >
> > My question is, can the in-kernel emulator code ever
> > be called from OUTSIDE the KVM_RUN ioctl loop?
> >
> > If so, we need to restore the user FPU context before
> > returning from the emulator code. Given that the current
> > emulator code does not do that, I suspect this is not
> > the case. I also see no path from the kvm ioctl into
> > the emulator code, other than via KVM_RUN.
> >
> > The FPU and XSAVE ioctls all work on the saved
> > vcpu->arch.guest_fpu data, and never directly on the
> > registers.
> >
> > Looks like we can completely get rid of .get_fpu and
> > .put_fpu...
> >
> > Unless Paolo has any objection, I'll go do that :)
>
>
> I think we should check all get/put_fpu callers if they need
> preempt_disable().
>
> E.g. em_fxrstor() needs disabled preemption as we temporarily
> save + restore some host register (via fxsave + fxrstor) under some
> circumstances that are not saved/restored when switching to/back from
> another process. We should double check.
>
> @Paolo what about complete_userspace_io? It can end up calling
> emulate_instruction(). So maybe we have to move load/put fpu further
> out
> or add special handling.
It looks like all complete_userspace_io causes is for
the vcpu_run loop to exit, and return to userspace
from the KVM_RUN ioctl code.
In other words, the userspace qemu FPU context should
be restored before we return to userspace, even with
my patch (v2 on the way).
--
All rights reversed
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2017-11-14 21:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-14 5:12 [PATCH] x86,kvm: move qemu/guest FPU switching out to vcpu_run Rik van Riel
2017-11-14 16:57 ` David Hildenbrand
2017-11-14 18:07 ` Rik van Riel
2017-11-14 18:09 ` Paolo Bonzini
2017-11-14 19:40 ` David Hildenbrand
2017-11-14 21:11 ` Rik van Riel [this message]
2017-11-15 8:34 ` Paolo Bonzini
2017-11-15 9:23 ` David Hildenbrand
2017-11-15 14:50 ` Rik van Riel
2017-11-15 15:20 ` David Hildenbrand
2017-12-04 2:15 ` Wanpeng Li
2017-12-05 17:09 ` Radim Krcmar
2017-12-06 2:48 ` Wanpeng Li
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=1510693882.1080.3.camel@redhat.com \
--to=riel@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=david@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=tglx@linutronix.de \
/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