From: "Carlos López" <clopez@suse.de>
To: Binbin Wu <binbin.wu@linux.intel.com>, seanjc@google.com
Cc: bp@alien8.de, kvm@vger.kernel.org,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
"open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] KVM: x86: synthesize TSA CPUID bits via SCATTERED_F()
Date: Mon, 9 Feb 2026 12:43:32 +0100 [thread overview]
Message-ID: <2c59c666-9f6a-460d-8582-55af31ee302d@suse.de> (raw)
In-Reply-To: <3afa5004-412a-4ab8-b0b9-46bd3982438d@linux.intel.com>
Hi,
On 2/9/26 11:02 AM, Binbin Wu wrote:
>
>
> On 2/9/2026 12:42 AM, Carlos López wrote:
>> KVM incorrectly synthesizes TSA_SQ_NO and TSA_L1_NO when running
>> on AMD Family 19h CPUs by using SYNTHESIZED_F(), which unconditionally
>> enables features for KVM-only CPUID leaves (as is the case with
>> CPUID_8000_0021_ECX), regardless of the kernel's synthesis logic in
>> tsa_init(). This is due to the following logic in kvm_cpu_cap_init():
>>
>> if (leaf < NCAPINTS)
>> kvm_cpu_caps[leaf] &= kernel_cpu_caps[leaf];
>
> Since TSA_SQ_NO and TSA_L1_NO are defined in CPUID_8000_0021_ECX, and
> CPUID_8000_0021_ECX > NCAPINTS, the code above doesn't take effect.
I should have explained it better, but that is precisely what I meant.
Since the &= never takes place, kvm_cpu_cap_features always has the bits
set. In other words: the branch always evaluates to false for KVM-only
CPUID leaves, so the bits are always set.
> The code makes the two bits set unconditionally is:
> SYNTHESIZED_F() sets kvm_cpu_cap_synthesized
> and later
> kvm_cpu_caps[leaf] &= (raw_cpuid_get(cpuid) |
> kvm_cpu_cap_synthesized);
>
>>
>> This can cause an unexpected failure on Family 19h CPUs during SEV-SNP
>> guest setup, when userspace issues SNP_LAUNCH_UPDATE, as setting these
>> bits in the CPUID page on vulnerable CPUs is explicitly rejected by SNP
>> firmware.
>>
>> Switch to SCATTERED_F(), so that the bits are only set if the features
>> have been force-set by the kernel in tsa_init(), or if they are reported
>> in the raw CPUID.
>
> When you switch to SCATTERED_F(), if the two bits are not in raw cpuid, the two
> bits will not be set to kvm_cpu_caps[CPUID_8000_0021_ECX], regardless the
> setting initialized in tsa_init().
Yes, I think you're right.
> TSA_SQ_NO and TSA_L1_NO are conditional kernel synthesis bits, should
> SYNTHESIZED_F() check that the related bit is actually synthesized into
> boot_cpu_data before setting to kvm_cpu_cap_synthesized?
Right, I thought this is what SCATTERED_F() already did, but I missed
that there is the logical AND with the raw CPUID later. See the diff in
my reply to Jim Mattson, I think that is what you propose as well.
prev parent reply other threads:[~2026-02-09 11:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-08 16:42 Carlos López
2026-02-08 18:28 ` Borislav Petkov
2026-02-08 20:50 ` Jim Mattson
2026-02-08 21:13 ` Borislav Petkov
2026-02-09 5:48 ` Jim Mattson
2026-02-09 11:40 ` Carlos López
2026-02-09 15:06 ` Sean Christopherson
2026-02-09 15:32 ` Borislav Petkov
2026-02-09 16:29 ` Sean Christopherson
2026-02-09 17:45 ` Borislav Petkov
2026-02-09 21:12 ` Sean Christopherson
2026-02-10 20:07 ` Borislav Petkov
2026-02-10 23:48 ` Sean Christopherson
2026-02-11 13:32 ` Borislav Petkov
2026-02-11 15:54 ` Sean Christopherson
2026-02-11 16:17 ` Borislav Petkov
2026-02-11 16:28 ` Sean Christopherson
2026-02-09 10:02 ` Binbin Wu
2026-02-09 11:43 ` Carlos López [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2c59c666-9f6a-460d-8582-55af31ee302d@suse.de \
--to=clopez@suse.de \
--cc=binbin.wu@linux.intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®