From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03BDA2D7DF2 for ; Fri, 6 Feb 2026 18:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770402220; cv=none; b=CUfcuhmMTV9N98C3+jlpnz4DQD05XhKk0OiC8w5eFpvnhgwQ9HrHkLtFXiOcluo2P7LCWFAqZe/V4x+Nt1CG7d3UvypSs+rrdtEBGJuZVbESXE4D+OLqJ51wKhHkPIBHT68ePUPa8WqVRrPl4GpqOaeaBFsMNI109mDkYSIiPcE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770402220; c=relaxed/simple; bh=PPmf/TTwe2EPf5X2ReEiLE8ehMGgo5rNVgEZzhhuGAw=; h=MIME-Version:Date:Content-Type:From:Message-ID:Subject:To:Cc: In-Reply-To:References; b=BA02S6V8YVM44QpSpcQTQr6vH+lCMim9sluUnj07nzbjWOrSa2tm7i0+D/WK+q0+UGmfXUjjMAbWQcohzADjFONmDKfHF/+W4kY5wiDIRaTx1MIqLqu8sYdYYLle9FCi9TMFP8XvB3xpAZS+BYKjJOJRmlgJa0IFJtOnQjhhfAo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Gv4P5OBM; arc=none smtp.client-ip=91.218.175.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Gv4P5OBM" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1770402217; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j8eeD2/8SMFZNgS0pJi9UHSBdDAom1iHyyBEp3tHmS4=; b=Gv4P5OBMyA8MEpTQ3IJyh7Lc47yvlyQnmg10qe4R0sWzykYphIRwK3LanUcUMaIXRIajBQ OmTmSqezteSFncYhEQ8ccI0xyyUZVTYu0gDVMS5Sryn3ukafrg5qycxUFTOcoEom7KoFwk MbHU5YcArar7fkInc4t5m33uiofyOZA= Date: Fri, 06 Feb 2026 18:23:35 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: "Yosry Ahmed" Message-ID: TLS-Required: No Subject: Re: [PATCH v3 2/8] KVM: x86: nSVM: Cache and validate vmcb12 g_pat To: "Sean Christopherson" , "Jim Mattson" Cc: "Paolo Bonzini" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "H. Peter Anvin" , "Shuah Khan" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org In-Reply-To: References: <20260205214326.1029278-1-jmattson@google.com> <20260205214326.1029278-3-jmattson@google.com> X-Migadu-Flow: FLOW_OUT February 6, 2026 at 10:19 AM, "Sean Christopherson" w= rote: >=20 >=20On Thu, Feb 05, 2026, Jim Mattson wrote: >=20 >=20>=20 >=20> Cache g_pat from vmcb12 in svm->nested.gpat to avoid TOCTTOU issues= , and > > add a validity check so that when nested paging is enabled for vmcb1= 2, an > > invalid g_pat causes an immediate VMEXIT with exit code VMEXIT_INVAL= ID, as > > specified in the APM, volume 2: "Nested Paging and VMRUN/VMEXIT." > >=20=20 >=20> Fixes: 3d6368ef580a ("KVM: SVM: Add VMRUN handler") > > Signed-off-by: Jim Mattson > > --- > > arch/x86/kvm/svm/nested.c | 4 +++- > > arch/x86/kvm/svm/svm.h | 3 +++ > > 2 files changed, 6 insertions(+), 1 deletion(-) > >=20=20 >=20> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c > > index f72dbd10dcad..1d4ff6408b34 100644 > > --- a/arch/x86/kvm/svm/nested.c > > +++ b/arch/x86/kvm/svm/nested.c > > @@ -1027,9 +1027,11 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu) > >=20=20 >=20> nested_copy_vmcb_control_to_cache(svm, &vmcb12->control); > > nested_copy_vmcb_save_to_cache(svm, &vmcb12->save); > > + svm->nested.gpat =3D vmcb12->save.g_pat; > >=20=20 >=20> if (!nested_vmcb_check_save(vcpu) || > > - !nested_vmcb_check_controls(vcpu)) { > > + !nested_vmcb_check_controls(vcpu) || > > + (nested_npt_enabled(svm) && !kvm_pat_valid(svm->nested.gpat))) { > > vmcb12->control.exit_code =3D SVM_EXIT_ERR; > > vmcb12->control.exit_info_1 =3D 0; > > vmcb12->control.exit_info_2 =3D 0; > > diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h > > index 986d90f2d4ca..42a4bf83b3aa 100644 > > --- a/arch/x86/kvm/svm/svm.h > > +++ b/arch/x86/kvm/svm/svm.h > > @@ -208,6 +208,9 @@ struct svm_nested_state { > > */ > > struct vmcb_save_area_cached save; > >=20=20 >=20> + /* Cached guest PAT from vmcb12.save.g_pat */ > > + u64 gpat; > >=20 >=20Shouldn't this go in vmcb_save_area_cached? I believe Jim changed it after this discussion on v2: https://lore.kernel= .org/kvm/20260115232154.3021475-4-jmattson@google.com/.