From patchwork Thu Oct 17 14:50:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 3061311 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2AC76BF924 for ; Thu, 17 Oct 2013 14:51:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 623E020220 for ; Thu, 17 Oct 2013 14:51:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 46572201F5 for ; Thu, 17 Oct 2013 14:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757212Ab3JQOu6 (ORCPT ); Thu, 17 Oct 2013 10:50:58 -0400 Received: from mail-ea0-f179.google.com ([209.85.215.179]:55177 "EHLO mail-ea0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756427Ab3JQOu4 (ORCPT ); Thu, 17 Oct 2013 10:50:56 -0400 Received: by mail-ea0-f179.google.com with SMTP id b10so1115001eae.38 for ; Thu, 17 Oct 2013 07:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=85svq+WyDMt0U+dzKarBoSbUgl9aXDKTjwzKoi6EUC8=; b=Vvlq0v3anTXHJmxuaM/1+vSnB3eXpXABnNSbltBVL1vQBCvJbEk5v8PSy90zgDy3wd bRGfPcOdBJk9sAne1Oi3p8DtHbLfBZauWvF6afA85QeHNx4TjkajYmEKG/MuK3QHF56s 7WmNCl6vKz93JH/ajR7a55Lt3ruAI1ruNn2HBpRhmG7VeuWc47eOoq6lc91B1jGsDVDb q/m6fZls1L3KfORIQbqwpM0XUBjShFP38GfEfYBJ3iTaqdESQ0gMiA9xJAO57KZPUrW2 ZMZFV2crK6F8ToMiIcDkmiY3vKK6V13gEhFYyZbvx8zBsW046PbrMO3XiMGc2jSXMmlX Dx2Q== X-Received: by 10.15.35.196 with SMTP id g44mr13292326eev.18.1382021455752; Thu, 17 Oct 2013 07:50:55 -0700 (PDT) Received: from playground.lan (net-37-116-196-7.cust.dsl.vodafone.it. [37.116.196.7]) by mx.google.com with ESMTPSA id i1sm193733166eeg.0.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 17 Oct 2013 07:50:54 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org Cc: gleb@redhat.com, agraf@suse.de, chao.zhou@intel.com, magnus@boden.cx, kvm@vger.kernel.org Subject: [PATCH 1/2] KVM: x86: fix KVM_SET_XCRS for CPUs that do not support XSAVE Date: Thu, 17 Oct 2013 16:50:46 +0200 Message-Id: <1382021447-20216-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1382021447-20216-1-git-send-email-pbonzini@redhat.com> References: <1382021447-20216-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The KVM_SET_XCRS ioctl must accept anything that KVM_GET_XCRS could return. XCR0's bit 0 is always 1 in real processors with XSAVE, and KVM_GET_XCRS will always leave bit 0 set even if the emulated processor does not have XSAVE. So, KVM_SET_XCRS must ignore that bit when checking for attempts to enable unsupported save states. Signed-off-by: Paolo Bonzini --- Introduced between v2 and v3, when I stopped hardcoding XSTATE_FPSSE in guest_supported_xcr0. arch/x86/kvm/x86.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c951c71..f4e1391 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -577,6 +577,7 @@ static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu) int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) { u64 xcr0; + u64 valid_bits; /* Only support XCR_XFEATURE_ENABLED_MASK(xcr0) now */ if (index != XCR_XFEATURE_ENABLED_MASK) @@ -586,8 +587,16 @@ int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) return 1; if ((xcr0 & XSTATE_YMM) && !(xcr0 & XSTATE_SSE)) return 1; - if (xcr0 & ~vcpu->arch.guest_supported_xcr0) + + /* + * Do not allow the guest to set bits that we do not support + * saving. However, xcr0 bit 0 is always set, even if the + * emulated CPU does not support XSAVE (see fx_init). + */ + valid_bits = vcpu->arch.guest_supported_xcr0 | XSTATE_FP; + if (xcr0 & ~valid_bits) return 1; + kvm_put_guest_xcr0(vcpu); vcpu->arch.xcr0 = xcr0; return 0;