On 09/11/2015 12:54, Huaitong Han wrote:
> This patch exposes X86_FEATURE_OSPKE to guest, X86_FEATURE_OSPKE is
> software support for pkeys, enumerated with CPUID.7.0.ECX[4]:OSPKE,
> and it reflects the setting of CR4.PKE.
> 
> Signed-off-by: Huaitong Han <huaitong....@intel.com>
> 
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 29e6502..ece687b 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -81,6 +81,17 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
>                       apic->lapic_timer.timer_mode_mask = 1 << 17;
>       }
>  
> +     best = kvm_find_cpuid_entry(vcpu, 7, 0);
> +     if (!best)
> +             return 0;
> +
> +     /*Update OSPKE bit */
> +     if (boot_cpu_has(X86_FEATURE_PKU) && best->function == 0x7) {
> +             best->ecx &= ~F(OSPKE);
> +             if (kvm_read_cr4_bits(vcpu, X86_CR4_PKE))
> +                     best->ecx |= F(OSPKE);
> +     }
> +
>       best = kvm_find_cpuid_entry(vcpu, 0xD, 0);
>       if (!best) {
>               vcpu->arch.guest_supported_xcr0 = 0;
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d268da0..5181834 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -754,7 +754,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
>           (!(cr4 & X86_CR4_PCIDE) && (old_cr4 & X86_CR4_PCIDE)))
>               kvm_mmu_reset_context(vcpu);
>  
> -     if ((cr4 ^ old_cr4) & X86_CR4_OSXSAVE)
> +     if ((cr4 ^ old_cr4) & (X86_CR4_OSXSAVE | X86_CR4_PKE))
>               kvm_update_cpuid(vcpu);
>  
>       return 0;
> @@ -6841,7 +6841,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
>  
>       mmu_reset_needed |= kvm_read_cr4(vcpu) != sregs->cr4;
>       kvm_x86_ops->set_cr4(vcpu, sregs->cr4);
> -     if (sregs->cr4 & X86_CR4_OSXSAVE)
> +     if (sregs->cr4 & (X86_CR4_OSXSAVE | X86_CR4_PKE))
>               kvm_update_cpuid(vcpu);
>  
>       idx = srcu_read_lock(&vcpu->kvm->srcu);
> 

Hi, please squash these first three patches and move them last.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to