Re: [PATCH v4 4/8] KVM: x86: nSVM: Redirect IA32_PAT accesses to either hPAT or gPAT

From: Sean Christopherson

Date: Tue Feb 17 2026 - 18:44:20 EST


On Tue, Feb 17, 2026, Yosry Ahmed wrote:
> > @@ -2838,16 +2876,7 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
> > msr_info->data = svm->msr_decfg;
> > break;
> > case MSR_IA32_CR_PAT:
> > - /*
> > - * When nested NPT is enabled, L2 has a separate PAT from
> > - * L1. Guest accesses to IA32_PAT while running L2 target
> > - * L2's gPAT; host-initiated accesses always target L1's
> > - * hPAT for backward and forward KVM_GET_MSRS compatibility
> > - * with older kernels.
> > - */
> > - WARN_ON_ONCE(msr_info->host_initiated && vcpu->wants_to_run);
> > - if (!msr_info->host_initiated && is_guest_mode(vcpu) &&
> > - nested_npt_enabled(svm))
> > + if (svm_is_access_to_gpat(vcpu, msr_info->host_initiated))
> > msr_info->data = svm->nested.save.g_pat;
> > else
> > msr_info->data = vcpu->arch.pat;
>
> I'd go a step further here and add svm_get_pat(), then this just
> becomes:
>
> msr_info->data = svm_get_pat(vcpu, msr_info->host_initiated);
>
> It's more consistent with svm_set_msr(), and completely abstracts the L1
> vs. L2 PAT logic with the helpers.

Either way works for me.