From patchwork Wed Sep 25 21:37:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11161527 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8723A76 for ; Wed, 25 Sep 2019 21:37:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 64D7621D82 for ; Wed, 25 Sep 2019 21:37:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728312AbfIYVhn (ORCPT ); Wed, 25 Sep 2019 17:37:43 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:38549 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728023AbfIYVhe (ORCPT ); Wed, 25 Sep 2019 17:37:34 -0400 Received: from localhost ([127.0.0.1] helo=flow.W.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1iDEyX-0002Dx-3W; Wed, 25 Sep 2019 23:37:29 +0200 From: Sebastian Andrzej Siewior To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Sebastian Andrzej Siewior Subject: [PATCH 1/2] KVM: x86: svm: Pass XSAVES to guest if available on host Date: Wed, 25 Sep 2019 23:37:20 +0200 Message-Id: <20190925213721.21245-2-bigeasy@linutronix.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190925213721.21245-1-bigeasy@linutronix.de> References: <20190925213721.21245-1-bigeasy@linutronix.de> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In commit 55412b2eda2b7 ("kvm: x86: Add kvm_x86_ops hook that enables XSAVES for guest") XSAVES was enabled on VMX with a few additional tweaks and was always disabled on SVM. Before ZEN XSAVES was not available so it made no difference. With Zen it is possible to expose it to the guest if it is available on the host. I didn't find anything close to VMX's "VM-Execution Controls" and exposing this flag based on the CPUID flags cause no harm so far. Expose the XSAVES flag to the guest if the host supports it. Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/kvm/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index e0368076a1ef9..3878eb766fa39 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -5992,7 +5992,7 @@ static bool svm_mpx_supported(void) static bool svm_xsaves_supported(void) { - return false; + return boot_cpu_has(X86_FEATURE_XSAVES); } static bool svm_umip_emulated(void) From patchwork Wed Sep 25 21:37:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11161521 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D89E76 for ; Wed, 25 Sep 2019 21:37:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 57084222BD for ; Wed, 25 Sep 2019 21:37:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728172AbfIYVhi (ORCPT ); Wed, 25 Sep 2019 17:37:38 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:38554 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728016AbfIYVhh (ORCPT ); Wed, 25 Sep 2019 17:37:37 -0400 Received: from localhost ([127.0.0.1] helo=flow.W.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1iDEyX-0002Dx-FF; Wed, 25 Sep 2019 23:37:29 +0200 From: Sebastian Andrzej Siewior To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Sebastian Andrzej Siewior Subject: [PATCH 2/2] KVM: x86: Expose CLZERO and XSAVEERPTR to the guest Date: Wed, 25 Sep 2019 23:37:21 +0200 Message-Id: <20190925213721.21245-3-bigeasy@linutronix.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190925213721.21245-1-bigeasy@linutronix.de> References: <20190925213721.21245-1-bigeasy@linutronix.de> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org I was surprised to see that the guest reported `fxsave_leak' while the host did not. After digging deeper I noticed that the bits are simply masked out during enumeration. The XSAVEERPTR feature is actually a bug fix on AMD which means the kernel can disable a workaround. While here, I've seen that CLZERO is also masked out. This opcode is unprivilged so exposing it to the guest should not make any difference. Pass CLZERO and XSAVEERPTR to the guest if available on the host. Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/kvm/cpuid.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 22c2720cd948e..0ae9194d0f4d2 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -473,6 +473,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, /* cpuid 0x80000008.ebx */ const u32 kvm_cpuid_8000_0008_ebx_x86_features = + F(CLZERO) | F(XSAVEERPTR) | F(WBNOINVD) | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) | F(AMD_SSB_NO) | F(AMD_STIBP) | F(AMD_STIBP_ALWAYS_ON);