From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH V5 4/9] KVM, pkeys: save/restore PKRU when guest/host switches Date: Mon, 21 Mar 2016 11:28:09 +0100 Message-ID: <56EFCCB9.80901@redhat.com> References: <1458554760-4374-1-git-send-email-huaitong.han@intel.com> <1458554760-4374-5-git-send-email-huaitong.han@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, guangrong.xiao@linux.intel.com To: Huaitong Han , gleb@kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:40346 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752925AbcCUK2O (ORCPT ); Mon, 21 Mar 2016 06:28:14 -0400 In-Reply-To: <1458554760-4374-5-git-send-email-huaitong.han@intel.com> Sender: kvm-owner@vger.kernel.org List-ID: On 21/03/2016 11:05, Huaitong Han wrote: > + if (vmx->guest_pkru_valid) > + write_pkru(vmx->guest_pkru); This can be __write_pkru. > atomic_switch_perf_msrs(vmx); > debugctlmsr = get_debugctlmsr(); > > @@ -8734,6 +8743,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) > vmx->exit_reason = vmcs_read32(VM_EXIT_REASON); > > /* > + * eager fpu is enabled if PKEY is supported and CR4 is switched > + * back on host, so it is safe to read guest PKRU from current > + * XSAVE. > + */ > + vmx->guest_pkru = read_pkru(); > + if (vmx->guest_pkru != vmx->host_pkru) { > + vmx->guest_pkru_valid = true; > + write_pkru(vmx->host_pkru); > + } else > + vmx->guest_pkru_valid = false; Should this code instead be enclosed in if (boot_cpu_has(X86_FEATURE_OSPKE)) and use __read_pkru/__write_pkru? Paolo