[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <kj7lqm5dsyaywgbpykat5iuy6lr25xb4myxuw73zrekgo6fdzk@pfvq24hkexyx>
Date: Thu, 22 Jan 2026 01:54:42 +0000
From: Yosry Ahmed <yosry.ahmed@...ux.dev>
To: Jim Mattson <jmattson@...gle.com>
Cc: Sean Christopherson <seanjc@...gle.com>,
Paolo Bonzini <pbonzini@...hat.com>, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org, "H. Peter Anvin" <hpa@...or.com>,
Shuah Khan <shuah@...nel.org>, kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org
Subject: Re: [PATCH v2 4/8] KVM: x86: nSVM: Set vmcb02.g_pat correctly for
nested NPT
On Thu, Jan 15, 2026 at 03:21:43PM -0800, Jim Mattson wrote:
> When nested NPT is enabled in vmcb12, copy the (cached and validated)
> vmcb12 g_pat field to the guest PAT register. Under KVM, the guest PAT
> register lives in the vmcb02 g_pat field.
>
> When NPT is enabled, but nested NPT is disabled, copy L1's IA32_PAT MSR to
> the vmcb02 g_pat field, since L2 shares the IA32_PAT MSR with L1,
>
> When NPT is disabled, the vmcb02 g_pat field is ignored by hardware.
>
> Fixes: 15038e147247 ("KVM: SVM: obey guest PAT")
> Signed-off-by: Jim Mattson <jmattson@...gle.com>
> ---
> arch/x86/kvm/svm/nested.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index e65291434be9..b0c0184e6e24 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -656,9 +656,6 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12
> struct vmcb *vmcb02 = svm->nested.vmcb02.ptr;
> struct kvm_vcpu *vcpu = &svm->vcpu;
>
> - nested_vmcb02_compute_g_pat(svm);
This is last use of the function, right? Should we drop it now?
> - vmcb_mark_dirty(vmcb02, VMCB_NPT);
> -
> /* Load the nested guest state */
> if (svm->nested.vmcb12_gpa != svm->nested.last_vmcb12_gpa) {
> new_vmcb12 = true;
> @@ -666,6 +663,19 @@ static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *vmcb12
> svm->nested.force_msr_bitmap_recalc = true;
> }
>
> + if (npt_enabled) {
> + if (nested_npt_enabled(svm)) {
> + if (unlikely(new_vmcb12 ||
> + vmcb_is_dirty(vmcb12, VMCB_NPT))) {
> + vmcb02->save.g_pat = svm->nested.save.g_pat;
> + vmcb_mark_dirty(vmcb02, VMCB_NPT);
> + }
> + } else {
> + vmcb02->save.g_pat = vcpu->arch.pat;
> + vmcb_mark_dirty(vmcb02, VMCB_NPT);
> + }
> + }
> +
> if (unlikely(new_vmcb12 || vmcb_is_dirty(vmcb12, VMCB_SEG))) {
> vmcb02->save.es = vmcb12->save.es;
> vmcb02->save.cs = vmcb12->save.cs;
> --
> 2.52.0.457.g6b5491de43-goog
>
Powered by blists - more mailing lists