From patchwork Wed Oct 2 14:06:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 2974951 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2A0439F2B8 for ; Wed, 2 Oct 2013 14:07:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 83C0F20319 for ; Wed, 2 Oct 2013 14:07:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C86B2203E8 for ; Wed, 2 Oct 2013 14:06:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753046Ab3JBOG3 (ORCPT ); Wed, 2 Oct 2013 10:06:29 -0400 Received: from mail-ee0-f43.google.com ([74.125.83.43]:64431 "EHLO mail-ee0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752864Ab3JBOG0 (ORCPT ); Wed, 2 Oct 2013 10:06:26 -0400 Received: by mail-ee0-f43.google.com with SMTP id e52so424596eek.16 for ; Wed, 02 Oct 2013 07:06:25 -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=Xp6aJ+0r/W3Xrqjnl1xOFz89CIrjW2qGFZJwalTsvyA=; b=UboqFz8f2+z8VwydPGkzGyGbRw4WcZHzCmq5frJlXL6El2zMyh952ahBQTMjbPthbO QW8onWwehrR0reFmT2n30MKH1YzgicebmFXRB6WlFm1AREUjAfLJpO09Cw4dkpRw5VyF Ej+34rhvMoDhEbqKehJDbl88Km/mkShX6Q+D/jMVc98wWit86mOGjMpdZe1k4fDZ5Chi z2EYGVNP9y1MN4yj02qb6hBKnEA6uid7HnoOIaQXxIgSZbElUXAmEZT347O8IYJWGPYJ 6bjBiZCZWOVzAweE3fmxuYJszfMzy++tJvW8Bi62V0D0BKNL+MOGqoDncijOHThuGQjn KQJQ== X-Received: by 10.14.210.8 with SMTP id t8mr3880370eeo.39.1380722785317; Wed, 02 Oct 2013 07:06:25 -0700 (PDT) Received: from playground.lan (net-2-39-10-130.cust.dsl.vodafone.it. [2.39.10.130]) by mx.google.com with ESMTPSA id a1sm4241370eem.1.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 02 Oct 2013 07:06:24 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, gleb@redhat.com Subject: [PATCH 1/3] KVM: x86: mask unsupported XSAVE entries from leaf 0Dh index 0 Date: Wed, 2 Oct 2013 16:06:14 +0200 Message-Id: <1380722776-12358-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1380722776-12358-1-git-send-email-pbonzini@redhat.com> References: <1380722776-12358-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.4 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 XSAVE entries that KVM does not support are reported by KVM_GET_SUPPORTED_CPUID for leaf 0Dh index 0 if the host supports them; they should be left out unless there is also hypervisor support for them. Sub-leafs are correctly handled in supported_xcr0_bit, fix index 0 to match. Signed-off-by: Paolo Bonzini --- arch/x86/kvm/cpuid.c | 4 +++- arch/x86/kvm/x86.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index b110fe6..a03a9fa 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -182,7 +182,7 @@ static bool supported_xcr0_bit(unsigned bit) { u64 mask = ((u64)1 << bit); - return mask & (XSTATE_FP | XSTATE_SSE | XSTATE_YMM) & host_xcr0; + return mask & KVM_SUPPORTED_XCR0 & host_xcr0; } #define F(x) bit(X86_FEATURE_##x) @@ -383,6 +383,8 @@ static int do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, case 0xd: { int idx, i; + entry->eax &= host_xcr0 & KVM_SUPPORTED_XCR0; + entry->edx &= (host_xcr0 & KVM_SUPPORTED_XCR0) >> 32; entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; for (idx = 1, i = 1; idx < 64; ++idx) { if (*nent >= maxnent) diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index e224f7a..587fb9e 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -122,6 +122,7 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt, gva_t addr, void *val, unsigned int bytes, struct x86_exception *exception); +#define KVM_SUPPORTED_XCR0 (XSTATE_FP | XSTATE_SSE | XSTATE_YMM) extern u64 host_xcr0; extern struct static_key kvm_no_apic_vcpu;