Re: [PATCH v5 08/10] KVM: x86: nSVM: Save/restore gPAT with KVM_{GET,SET}_NESTED_STATE

From: Jim Mattson

Date: Wed Mar 04 2026 - 13:37:59 EST


On Wed, Mar 4, 2026 at 9:11 AM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index 991ee4c03363..099bf8ac10ee 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -1848,7 +1848,7 @@ static int svm_get_nested_state(struct kvm_vcpu *vcpu,
> if (is_guest_mode(vcpu)) {
> kvm_state.hdr.svm.vmcb_pa = svm->nested.vmcb12_gpa;
> if (nested_npt_enabled(svm)) {
> - kvm_state.hdr.svm.flags |= KVM_STATE_SVM_VALID_GPAT;
> + kvm_state->flags |= KVM_STATE_NESTED_GPAT_VALID;
> kvm_state.hdr.svm.gpat = svm->vmcb->save.g_pat;
> }
> kvm_state.size += KVM_STATE_NESTED_SVM_VMCB_SIZE;
> @@ -1914,7 +1914,8 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
>
> if (kvm_state->flags & ~(KVM_STATE_NESTED_GUEST_MODE |
> KVM_STATE_NESTED_RUN_PENDING |
> - KVM_STATE_NESTED_GIF_SET))
> + KVM_STATE_NESTED_GIF_SET |
> + KVM_STATE_NESTED_GPAT_VALID))
> return -EINVAL;

Unless I'm missing something, this breaks forward compatibility
completely. An older kernel will refuse to accept a nested state blob
with GPAT_VALID set.