From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A0A33612D6 for ; Fri, 13 Feb 2026 15:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770996033; cv=none; b=Xhiblw0GjzzW6EcG18Cmi9ny6tCq/kYkX6v13/I26gpB5cTIJkN/fX3MX0A78n9j9ZCnUXMlcN0hT+gvhY4aeh8leQqBvTIcZOKBHU7wPxXHYY17Yg8pNWRJ8SmO/6lh8C7fugZBjBeqzUFP5usSZSdONXTUq4DcCYZTKvZRGKA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770996033; c=relaxed/simple; bh=Rttl4d9sGgG3Lhh7v6oLA+vPF2preIIqOyYcVD4IJkw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=d1G+M9npC4q5hSneHoJNQTo1JZpH/YsOAhqX0nSjSR/n0wwoFZmA2lnWVadTsyIcbaiGvrnF5+EMxuxiJ6FgJhvnZfNf4DpwxIQipLYeZns3P945JDaKf6e/heVED3N9RohWKsBcOvSaNhIYRgOXYDE1/eT4pdOUihzcfO4hQIg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=p6yPUz0K; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="p6yPUz0K" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c6e1d32a128so724818a12.3 for ; Fri, 13 Feb 2026 07:20:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770996030; x=1771600830; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DXZgws1eGwFodcFEr+AzFaRA44BFbU5sqkzQqm7Vi/g=; b=p6yPUz0KaPYL/rL6Wu8Isz56jaZb5L3X3EcnX+A3LHfm2WpjGdrbwTdaEh9bHv77sd E34ItJt27w8LVnpfGwxUyVvTsZ2reAhyL8Ep0Ja+EusUl1LEPAy0DdYizWx5dKOCDhPW 3I/itbDOcHCoHjFA7/FG3Scg+Ej3QCoYzs0vGoY+rM6dlU1IAmNlnkfjs8LoTN/hiTQb AH3RNF4dr62pPAbFH4HFCo90/AJRhvPrRG36b8x5B7v11zPnjmxBkKRfGryZIYkV7RrP vxnUWyzDCChOf3+H1hceMD1U8PnlpBKEbz/51DvjDscS0K2OXtTR3vFhYWOcQ4lI582i e1NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770996030; x=1771600830; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DXZgws1eGwFodcFEr+AzFaRA44BFbU5sqkzQqm7Vi/g=; b=aeuJdVVoat2N2yxQm5qi2s0+p1Mtb/7acfjaiOFQE3ijp95in49dOHis/hKTEDeRFi Z2IUMvv6FVkBEskwECnHIMgeBnYMmLCavgro8OYh+XWjJYEwQ3XyIfd59QNqbZrjkT18 sJsOKC+b1zHVnkiwbdGa9MBaGycoVk6Y2FPWZreFrpzQzVZkTQ0yiJOimxwOUL5KU9kZ w6rMKhcWH+E1W+CnICgpr3I3UZ/x7NK62l7uQDFy62mUodwJod6tJ7lNpvN7WurhB8Z/ VgcZGkdBiAuYt88AX7InNnGOa9ZwNiIEi3k3vbeK5nxIYvk3A6RwzsJ0Tf5lG+ZRPvj5 qLhg== X-Forwarded-Encrypted: i=1; AJvYcCVuECpL1qOkzKB68z1pOWJzI9YxBryqvbpsPpbec+uDn0IOrrdcUbdtb/1220PNNNbtlLritua6x+7T0ks=@vger.kernel.org X-Gm-Message-State: AOJu0YzzbfE9hlfgbn2Ky/olxFq2fGCcbq8RghsEefZI69bs5E8Qmvu4 YiTWCon+niQR3wdC30+T6L0Hg4vn2VajJlM/W/ED9J6U+M1YiGGFl2MqK0XylQY8/fcvt/6Wrlr l4UXupQ== X-Received: from pjvn19.prod.google.com ([2002:a17:90a:de93:b0:34c:c510:f186]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:486:b0:2bf:183c:ac86 with SMTP id adf61e73a8af0-3946c816108mr1883855637.25.1770996030340; Fri, 13 Feb 2026 07:20:30 -0800 (PST) Date: Fri, 13 Feb 2026 07:20:28 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260212155905.3448571-1-jmattson@google.com> <20260212155905.3448571-5-jmattson@google.com> Message-ID: Subject: Re: [PATCH v4 4/8] KVM: x86: nSVM: Redirect IA32_PAT accesses to either hPAT or gPAT From: Sean Christopherson To: Yosry Ahmed Cc: Jim Mattson , 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 Content-Type: text/plain; charset="us-ascii" Please trim your replies. Scrolling through 100+ lines of quoted text to find the ~12 lines of context that actually matter is annoying. On Fri, Feb 13, 2026, Yosry Ahmed wrote: > On Thu, Feb 12, 2026 at 07:58:52AM -0800, Jim Mattson wrote: > > diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h > > index a49c48459e0b..88549705133f 100644 > > --- a/arch/x86/kvm/svm/svm.h > > +++ b/arch/x86/kvm/svm/svm.h > > @@ -607,6 +607,22 @@ static inline bool nested_npt_enabled(struct vcpu_svm *svm) > > return svm->nested.ctl.misc_ctl & SVM_MISC_ENABLE_NP; > > } > > > > +static inline void svm_set_gpat(struct vcpu_svm *svm, u64 data) > > +{ > > + svm->nested.save.g_pat = data; > > + vmcb_set_gpat(svm->nested.vmcb02.ptr, data); > > +} > > + > > +static inline void svm_set_hpat(struct vcpu_svm *svm, u64 data) > > +{ > > + svm->vcpu.arch.pat = data; > > + if (npt_enabled) { Peeking at the future patches, if we make this: if (!npt_enabled) return; then we can end up with this: if (npt_enabled) return; vmcb_set_gpat(svm->vmcb01.ptr, data); if (is_guest_mode(&svm->vcpu) && !nested_npt_enabled(svm)) vmcb_set_gpat(svm->nested.vmcb02.ptr, data); if (svm->nested.legacy_gpat_semantics) svm_set_l2_pat(svm, data); Because legacy_gpat_semantics can only be true if npt_enabled is true. Without that guard, KVM _looks_ buggy because it's setting gpat in the VMCB even when it shouldn't exist. Actually, calling svm_set_l2_pat() when !is_guest_mode() is wrong too, no? E.g. shouldn't we end up with this? static inline void svm_set_l1_pat(struct vcpu_svm *svm, u64 data) { svm->vcpu.arch.pat = data; if (npt_enabled) return; vmcb_set_gpat(svm->vmcb01.ptr, data); if (is_guest_mode(&svm->vcpu)) { if (svm->nested.legacy_gpat_semantics) svm_set_l2_pat(svm, data); else if (!nested_npt_enabled(svm)) vmcb_set_gpat(svm->nested.vmcb02.ptr, data); } } > > + vmcb_set_gpat(svm->vmcb01.ptr, data); > > + if (is_guest_mode(&svm->vcpu) && !nested_npt_enabled(svm)) > > + vmcb_set_gpat(svm->nested.vmcb02.ptr, data); > > + } > > +} > > Is it me, or is it a bit confusing that svm_set_gpat() sets L2's gPAT > not L1's, and svm_set_hpat() calls vmcb_set_gpat()? It's not just you. I don't find it confusing per se, more that it's really subtle. > "gpat" means different things in the context of the VMCB or otherwise, > which kinda makes sense but is also not super clear. Maybe > svm_set_l1_gpat() and svm_set_l2_gpat() is more clear? I think just svm_set_l1_pat() and svm_set_l2_pat(), because gpat straight up doesn't exist when NPT is disabled/unsupported.