Example #1
0
void kvm_update_cpuid(struct kvm_vcpu *vcpu)
{
    struct kvm_cpuid_entry2 *best;
    struct kvm_lapic *apic = vcpu->arch.apic;

    best = kvm_find_cpuid_entry(vcpu, 1, 0);
    if (!best)
        return;

    /* Update OSXSAVE bit */
    if (cpu_has_xsave && best->function == 0x1) {
        best->ecx &= ~(bit(X86_FEATURE_OSXSAVE));
        if (kvm_read_cr4_bits(vcpu, X86_CR4_OSXSAVE))
            best->ecx |= bit(X86_FEATURE_OSXSAVE);
    }

    if (apic) {
        if (best->ecx & bit(X86_FEATURE_TSC_DEADLINE_TIMER))
            apic->lapic_timer.timer_mode_mask = 3 << 17;
        else
            apic->lapic_timer.timer_mode_mask = 1 << 17;
    }

    kvm_pmu_cpuid_update(vcpu);
}
Example #2
0
void kvm_update_cpuid(struct kvm_vcpu *vcpu)
{
	struct kvm_cpuid_entry2 *best;
	struct kvm_lapic *apic = vcpu->arch.apic;

	best = kvm_find_cpuid_entry(vcpu, 1, 0);
	if (!best)
		return;

	/* Update OSXSAVE bit */
	if (cpu_has_xsave && best->function == 0x1) {
		best->ecx &= ~(bit(X86_FEATURE_OSXSAVE));
		if (kvm_read_cr4_bits(vcpu, X86_CR4_OSXSAVE))
			best->ecx |= bit(X86_FEATURE_OSXSAVE);
	}

	if (apic) {
		if (best->ecx & bit(X86_FEATURE_TSC_DEADLINE_TIMER))
			apic->lapic_timer.timer_mode_mask = 3 << 17;
		else
			apic->lapic_timer.timer_mode_mask = 1 << 17;
	}

	best = kvm_find_cpuid_entry(vcpu, 0xD, 0);
	if (!best) {
		vcpu->arch.guest_supported_xcr0 = 0;
		vcpu->arch.guest_xstate_size = XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET;
	} else {
		vcpu->arch.guest_supported_xcr0 =
			(best->eax | ((u64)best->edx << 32)) &
			kvm_supported_xcr0();
		vcpu->arch.guest_xstate_size = best->ebx =
			xstate_required_size(vcpu->arch.xcr0);
	}

	kvm_pmu_cpuid_update(vcpu);
}