Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933813AbcCNHrS (ORCPT ); Mon, 14 Mar 2016 03:47:18 -0400 Received: from mga02.intel.com ([134.134.136.20]:27708 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933603AbcCNHrG (ORCPT ); Mon, 14 Mar 2016 03:47:06 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,334,1455004800"; d="scan'208";a="669107191" Subject: Re: [PATCH 0/1] KVM: x86: using the fpu in interrupt context with a guest's xcr0 To: David Matlack , linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org References: <1457729240-3846-1-git-send-email-dmatlack@google.com> Cc: pbonzini@redhat.com, mingo@redhat.com, luto@kernel.org, hpa@zytor.com, digitaleric@google.com From: Xiao Guangrong Message-ID: <56E66C57.9080802@linux.intel.com> Date: Mon, 14 Mar 2016 15:46:31 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <1457729240-3846-1-git-send-email-dmatlack@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1288 Lines: 33 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? 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.