Re: [PATCH v8 0/8] KVM: x86: nSVM: Improve PAT virtualization
From: Yosry Ahmed
Date: Wed May 20 2026 - 16:30:59 EST
On Mon, May 18, 2026 at 05:41:06PM -0700, Sean Christopherson wrote:
> On Tue, 07 Apr 2026 12:03:23 -0700, Jim Mattson wrote:
> > Currently, KVM's implementation of nested SVM treats the PAT MSR the same
> > way whether or not nested NPT is enabled: L1 and L2 share a single
> > PAT. However, the AMD APM specifies that when nested NPT is enabled, the host
> > (L1) and the guest (L2) should have independent PATs: hPAT for L1 and gPAT
> > for L2.
> >
> > This patch series implements independent PATs for L1 and L2 when nested NPT
> > is enabled, but only when a new quirk, KVM_X86_QUIRK_NESTED_SVM_SHARED_PAT,
> > is disabled. By default, the quirk is enabled, preserving KVM's legacy
> > behavior. When the quirk is disabled, KVM correctly virtualizes a separate
> > PAT register for L2, using the g_pat field in the VMCB.
> >
> > [...]
>
> Applied to kvm-x86 svm. Yosry and/or Jim, please double check the result, the
> goof with patch 5 was slightly more annoying than I was expecting.
The result looks good to me. I also ran the selftest from v7 and it
passes. I couldn't help myself from reworking it and cleaning it up, I
will send a patch your way soon.
>
> Thanks!
>
> [1/8] KVM: x86: Define KVM_X86_QUIRK_NESTED_SVM_SHARED_PAT
> https://github.com/kvm-x86/linux/commit/822790ab0149
> [2/8] KVM: x86: nSVM: Clear VMCB_NPT clean bit when updating hPAT from guest mode
> https://github.com/kvm-x86/linux/commit/0a8aeb15848e
> [3/8] KVM: x86: nSVM: Cache and validate vmcb12 g_pat
> https://github.com/kvm-x86/linux/commit/4b83e4ba836e
> [4/8] KVM: x86: nSVM: Set vmcb02.g_pat correctly for nested NPT
> https://github.com/kvm-x86/linux/commit/02233c73f8ae
> [6/8] KVM: x86: nSVM: Save gPAT to vmcb12.g_pat on VMEXIT
> https://github.com/kvm-x86/linux/commit/d65cf222b899
> [7/8] KVM: Documentation: document KVM_{GET,SET}_NESTED_STATE for SVM
> https://github.com/kvm-x86/linux/commit/32ebdbce3b23
> [8/8] KVM: x86: nSVM: Save/restore gPAT with KVM_{GET,SET}_NESTED_STATE
> https://github.com/kvm-x86/linux/commit/4f256d5770fe
>
> --
> https://github.com/kvm-x86/linux/tree/next