diff mbox series

[v6,3/9] KVM: x86: Stuff vCPU's PAT with default value at RESET, not creation

Message ID 20240309012725.1409949-4-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series x86/cpu: KVM: Clean up PAT and VMX macros | expand

Commit Message

Sean Christopherson March 9, 2024, 1:27 a.m. UTC
Move the stuffing of the vCPU's PAT to the architectural "default" value
from kvm_arch_vcpu_create() to kvm_vcpu_reset(), guarded by !init_event,
to better capture that the default value is the value "Following Power-up
or Reset".  E.g. setting PAT only during creation would break if KVM were
to expose a RESET ioctl() to userspace (which is unlikely, but that's not
a good reason to have unintuitive code).

No functional change.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/x86.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Huang, Kai March 27, 2024, 11:22 a.m. UTC | #1
On Fri, 2024-03-08 at 17:27 -0800, Sean Christopherson wrote:
> Move the stuffing of the vCPU's PAT to the architectural "default" value
> from kvm_arch_vcpu_create() to kvm_vcpu_reset(), guarded by !init_event,
> to better capture that the default value is the value "Following Power-up
> or Reset".  E.g. setting PAT only during creation would break if KVM were
> to expose a RESET ioctl() to userspace (which is unlikely, but that's not
> a good reason to have unintuitive code).
> 
> No functional change.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> 

Reviewed-by: Kai Huang <kai.huang@intel.com>
Xiaoyao Li April 1, 2024, 6 a.m. UTC | #2
On 3/9/2024 9:27 AM, Sean Christopherson wrote:
> Move the stuffing of the vCPU's PAT to the architectural "default" value
> from kvm_arch_vcpu_create() to kvm_vcpu_reset(), guarded by !init_event,
> to better capture that the default value is the value "Following Power-up
> or Reset".  E.g. setting PAT only during creation would break if KVM were
> to expose a RESET ioctl() to userspace (which is unlikely, but that's not
> a good reason to have unintuitive code).
> 
> No functional change.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>

> ---
>   arch/x86/kvm/x86.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 66c4381460dc..eac97b1b8379 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -12134,8 +12134,6 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
>   	vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
>   	vcpu->arch.reserved_gpa_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu);
>   
> -	vcpu->arch.pat = MSR_IA32_CR_PAT_DEFAULT;
> -
>   	kvm_async_pf_hash_reset(vcpu);
>   
>   	vcpu->arch.perf_capabilities = kvm_caps.supported_perf_cap;
> @@ -12302,6 +12300,8 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
>   	if (!init_event) {
>   		vcpu->arch.smbase = 0x30000;
>   
> +		vcpu->arch.pat = MSR_IA32_CR_PAT_DEFAULT;
> +
>   		vcpu->arch.msr_misc_features_enables = 0;
>   		vcpu->arch.ia32_misc_enable_msr = MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL |
>   						  MSR_IA32_MISC_ENABLE_BTS_UNAVAIL;
diff mbox series

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 66c4381460dc..eac97b1b8379 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -12134,8 +12134,6 @@  int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 	vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
 	vcpu->arch.reserved_gpa_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu);
 
-	vcpu->arch.pat = MSR_IA32_CR_PAT_DEFAULT;
-
 	kvm_async_pf_hash_reset(vcpu);
 
 	vcpu->arch.perf_capabilities = kvm_caps.supported_perf_cap;
@@ -12302,6 +12300,8 @@  void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 	if (!init_event) {
 		vcpu->arch.smbase = 0x30000;
 
+		vcpu->arch.pat = MSR_IA32_CR_PAT_DEFAULT;
+
 		vcpu->arch.msr_misc_features_enables = 0;
 		vcpu->arch.ia32_misc_enable_msr = MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL |
 						  MSR_IA32_MISC_ENABLE_BTS_UNAVAIL;