Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: x86: Fix xsave cpuid exposing bug

From 00c920c96127d20d4c3bb790082700ae375c39a0 Mon Sep 17 00:00:00 2001
From: Liu Jinsong <jinsong.liu@intel.com>
Date: Fri, 21 Feb 2014 23:47:18 +0800
Subject: [PATCH] KVM: x86: Fix xsave cpuid exposing bug

EBX of cpuid(0xD, 0) is dynamic per XCR0 features enable/disable.
Bit 63 of XCR0 is reserved for future expansion.

Signed-off-by: Liu Jinsong <jinsong.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Liu, Jinsong and committed by
Paolo Bonzini
56c103ec 49345f13

+10 -5
+2
arch/x86/include/asm/xsave.h
··· 13 13 #define XSTATE_BNDCSR 0x10 14 14 15 15 #define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE) 16 + /* Bit 63 of XCR0 is reserved for future expansion */ 17 + #define XSTATE_EXTEND_MASK (~(XSTATE_FPSSE | (1ULL << 63))) 16 18 17 19 #define FXSAVE_SIZE 512 18 20
+3 -3
arch/x86/kvm/cpuid.c
··· 28 28 int feature_bit = 0; 29 29 u32 ret = XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET; 30 30 31 - xstate_bv &= ~XSTATE_FPSSE; 31 + xstate_bv &= XSTATE_EXTEND_MASK; 32 32 while (xstate_bv) { 33 33 if (xstate_bv & 0x1) { 34 34 u32 eax, ebx, ecx, edx; ··· 74 74 vcpu->arch.guest_supported_xcr0 = 75 75 (best->eax | ((u64)best->edx << 32)) & 76 76 host_xcr0 & KVM_SUPPORTED_XCR0; 77 - vcpu->arch.guest_xstate_size = 78 - xstate_required_size(vcpu->arch.guest_supported_xcr0); 77 + vcpu->arch.guest_xstate_size = best->ebx = 78 + xstate_required_size(vcpu->arch.xcr0); 79 79 } 80 80 81 81 kvm_pmu_cpuid_update(vcpu);
+5 -2
arch/x86/kvm/x86.c
··· 595 595 596 596 int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) 597 597 { 598 - u64 xcr0; 598 + u64 xcr0 = xcr; 599 + u64 old_xcr0 = vcpu->arch.xcr0; 599 600 u64 valid_bits; 600 601 601 602 /* Only support XCR_XFEATURE_ENABLED_MASK(xcr0) now */ 602 603 if (index != XCR_XFEATURE_ENABLED_MASK) 603 604 return 1; 604 - xcr0 = xcr; 605 605 if (!(xcr0 & XSTATE_FP)) 606 606 return 1; 607 607 if ((xcr0 & XSTATE_YMM) && !(xcr0 & XSTATE_SSE)) ··· 618 618 619 619 kvm_put_guest_xcr0(vcpu); 620 620 vcpu->arch.xcr0 = xcr0; 621 + 622 + if ((xcr0 ^ old_xcr0) & XSTATE_EXTEND_MASK) 623 + kvm_update_cpuid(vcpu); 621 624 return 0; 622 625 } 623 626