[PATCH 04/10] KVM: x86: nSVM: Restore L1's PAT on emulated #VMEXIT from L2 to L1

Jim Mattson posted 10 patches 3 weeks, 5 days ago
There is a newer version of this series
[PATCH 04/10] KVM: x86: nSVM: Restore L1's PAT on emulated #VMEXIT from L2 to L1
Posted by Jim Mattson 3 weeks, 5 days ago
KVM doesn't implement a separate G_PAT register to hold the guest's
PAT in guest mode with nested NPT enabled. Consequently, L1's IA32_PAT
MSR must be restored on emulated #VMEXIT from L2 to L1.

Note: if L2 uses shadow paging, L1 and L2 share the same IA32_PAT MSR.

Signed-off-by: Jim Mattson <jmattson@google.com>
---
 arch/x86/kvm/svm/nested.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index c751be470364..9aec836ac04c 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1292,6 +1292,16 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
 	kvm_rsp_write(vcpu, vmcb01->save.rsp);
 	kvm_rip_write(vcpu, vmcb01->save.rip);
 
+	/*
+	 * KVM doesn't implement a separate guest PAT
+	 * register. Instead, the guest PAT lives in vcpu->arch.pat
+	 * while in guest mode with nested NPT enabled. Hence, the
+	 * IA32_PAT MSR has to be restored from the vmcb01 g_pat at
+	 * #VMEXIT.
+	 */
+	if (nested_npt_enabled(svm))
+		vcpu->arch.pat = vmcb01->save.g_pat;
+
 	svm->vcpu.arch.dr7 = DR7_FIXED_1;
 	kvm_update_dr7(&svm->vcpu);
 
-- 
2.52.0.457.g6b5491de43-goog
Re: [PATCH 04/10] KVM: x86: nSVM: Restore L1's PAT on emulated #VMEXIT from L2 to L1
Posted by Sean Christopherson 3 weeks, 3 days ago
On Mon, Jan 12, 2026, Jim Mattson wrote:
> KVM doesn't implement a separate G_PAT register to hold the guest's
> PAT in guest mode with nested NPT enabled. Consequently, L1's IA32_PAT
> MSR must be restored on emulated #VMEXIT from L2 to L1.
> 
> Note: if L2 uses shadow paging, L1 and L2 share the same IA32_PAT MSR.
> 
> Signed-off-by: Jim Mattson <jmattson@google.com>
> ---
>  arch/x86/kvm/svm/nested.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index c751be470364..9aec836ac04c 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -1292,6 +1292,16 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
>  	kvm_rsp_write(vcpu, vmcb01->save.rsp);
>  	kvm_rip_write(vcpu, vmcb01->save.rip);
>  
> +	/*
> +	 * KVM doesn't implement a separate guest PAT
> +	 * register. Instead, the guest PAT lives in vcpu->arch.pat
> +	 * while in guest mode with nested NPT enabled. Hence, the
> +	 * IA32_PAT MSR has to be restored from the vmcb01 g_pat at
> +	 * #VMEXIT.

Wrap closer to 80 chars.

> +	 */
> +	if (nested_npt_enabled(svm))
> +		vcpu->arch.pat = vmcb01->save.g_pat;
> +
>  	svm->vcpu.arch.dr7 = DR7_FIXED_1;
>  	kvm_update_dr7(&svm->vcpu);
>  
> -- 
> 2.52.0.457.g6b5491de43-goog
>