linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Matlack <dmatlack@google.com>
To: Xiao Guangrong <guangrong.xiao@linux.intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	X86 ML <x86@kernel.org>, kvm list <kvm@vger.kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Ingo Molnar <mingo@redhat.com>, Andy Lutomirski <luto@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Eric Northup <digitaleric@google.com>
Subject: Re: [PATCH 0/1] KVM: x86: using the fpu in interrupt context with a guest's xcr0
Date: Tue, 15 Mar 2016 12:01:45 -0700	[thread overview]
Message-ID: <CALzav=dKwN8uojO73D+QtOoTNmvHS=X=AoMKX1rCZJUho2k0Yg@mail.gmail.com> (raw)
In-Reply-To: <56E66C57.9080802@linux.intel.com>

On Mon, Mar 14, 2016 at 12:46 AM, Xiao Guangrong
<guangrong.xiao@linux.intel.com> wrote:
>
>
> On 03/12/2016 04:47 AM, David Matlack wrote:
>
>> I have not been able to trigger this bug on Linux 4.3, and suspect
>> it is due to this commit from Linux 4.2:
>>
>> 653f52c kvm,x86: load guest FPU context more eagerly
>>
>> With this commit, as long as the host is using eagerfpu, the guest's
>> fpu is always loaded just before the guest's xcr0 (vcpu->fpu_active
>> is always 1 in the following snippet):
>>
>> 6569         if (vcpu->fpu_active)
>> 6570                 kvm_load_guest_fpu(vcpu);
>> 6571         kvm_load_guest_xcr0(vcpu);
>>
>> When the guest's fpu is loaded, irq_fpu_usable() returns false.
>
>
> Er, i did not see that commit introduced this change.
>
>>
>> We've included our workaround for this bug, which applies to Linux 3.11.
>> It does not apply cleanly to HEAD since the fpu subsystem was refactored
>> in Linux 4.2. While the latest kernel does not look vulnerable, we may
>> want to apply a fix to the vulnerable stable kernels.
>
>
> Is the latest kvm safe if we use !eager fpu?

Yes I believe so. When !eagerfpu, interrupted_kernel_fpu_idle()
returns "!current->thread.fpu.fpregs_active && (read_cr0() &
X86_CR0_TS)". This should ensure the interrupt handler never does
XSAVE/XRSTOR with the guest's xcr0.

> Under this case,
> kvm_load_guest_fpu()
> is not called for every single VM-enter, that means kernel will use guest's
> xcr0 to
> save/restore XSAVE area.
>
> Maybe a simpler fix is just calling __kernel_fpu_begin() when the CPU
> switches
> to vCPU and reverts it when the vCPU is scheduled out or returns to
> userspace.
>

  reply	other threads:[~2016-03-15 19:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-11 20:47 [PATCH 0/1] KVM: x86: using the fpu in interrupt context with a guest's xcr0 David Matlack
2016-03-11 20:47 ` [PATCH 1/1] KVM: don't allow irq_fpu_usable when the VCPU's XCR0 is loaded David Matlack
2016-03-11 21:14   ` Andy Lutomirski
2016-03-11 21:33     ` David Matlack
2016-03-14 13:17       ` Paolo Bonzini
2016-03-15 18:27         ` Andy Lutomirski
2016-03-15 19:32           ` Paolo Bonzini
2016-03-16  3:55             ` Xiao Guangrong
2016-03-16 12:01               ` Paolo Bonzini
2016-03-14  7:46 ` [PATCH 0/1] KVM: x86: using the fpu in interrupt context with a guest's xcr0 Xiao Guangrong
2016-03-15 19:01   ` David Matlack [this message]
2016-03-16  3:43     ` Xiao Guangrong
2016-03-16  3:48       ` Andy Lutomirski
2016-03-16 17:11         ` David Matlack
2016-03-16 17:09       ` David Matlack

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='CALzav=dKwN8uojO73D+QtOoTNmvHS=X=AoMKX1rCZJUho2k0Yg@mail.gmail.com' \
    --to=dmatlack@google.com \
    --cc=digitaleric@google.com \
    --cc=guangrong.xiao@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).