From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 86D8E36F43C for ; Mon, 9 Feb 2026 11:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770637415; cv=none; b=gjps3Odc+r2eMPNZjNm1PI5gwDlzKEAUPFDvozETXspigrtxTN05lmU4aK8kB0XOsCTR/9K72ozJeDa9Yrl1+i/jm03q6A9Ml9TtTti2Seg1MIBYiLvFpZXerZ1N0Lzm1zTqjaPPetH3Sn2o0+tpiqK+SX89uvQ2jGAk2hPUANc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770637415; c=relaxed/simple; bh=ZlCsJRJJAfS5TjFdAY3MUHqS7ewIBNYYOaA7yaL2R+g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=S9NLNrcNcSLHSpPrl9HSobBfAZBXaP8yWWWDKLUBSRC+/CiMpzyUIu6SqrhoIq48AsbrD+8EBrFCuT23ef+OQo3s7XVxY2wCkh024a+VipdutB683+Q92wXyCz2tyq4xhEkakOQ6UQR9zgC2FzejBSz1On3pGPh/7ZheumNFs64= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=byq8Secf; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=jQFFoTgU; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=byq8Secf; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=jQFFoTgU; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="byq8Secf"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="jQFFoTgU"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="byq8Secf"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="jQFFoTgU" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CBAEC3E6F5; Mon, 9 Feb 2026 11:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1770637413; h=from:from:reply-to: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=3a3kIicM5sBZ4RGa33aXgI4s/G8RklC2RL/Gfa+ujCw=; b=byq8Secfa3LGmBrWkiaVvUoijLkjzOqDwbi12IBZ0XgZ47kWWORqOE6/9wkRO5djDb0bXB 8dV65F00ezR5iooWYrJu3sMn3HK95bdJ0gYVRXlfAOmortAsLUJY/oCUoRoUUq6g6aSLJs cAOzpj2gY1hoRtCIdAp0bExH0eS5E28= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1770637413; h=from:from:reply-to: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=3a3kIicM5sBZ4RGa33aXgI4s/G8RklC2RL/Gfa+ujCw=; b=jQFFoTgUGecrmE012TYG37NJbOL5yIy/M/sUhAa3ZNy6hR9CeOYpCxWz5hhzcRdmFlrnJi UzhqgPGiMw4E7cCg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1770637413; h=from:from:reply-to: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=3a3kIicM5sBZ4RGa33aXgI4s/G8RklC2RL/Gfa+ujCw=; b=byq8Secfa3LGmBrWkiaVvUoijLkjzOqDwbi12IBZ0XgZ47kWWORqOE6/9wkRO5djDb0bXB 8dV65F00ezR5iooWYrJu3sMn3HK95bdJ0gYVRXlfAOmortAsLUJY/oCUoRoUUq6g6aSLJs cAOzpj2gY1hoRtCIdAp0bExH0eS5E28= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1770637413; h=from:from:reply-to: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=3a3kIicM5sBZ4RGa33aXgI4s/G8RklC2RL/Gfa+ujCw=; b=jQFFoTgUGecrmE012TYG37NJbOL5yIy/M/sUhAa3ZNy6hR9CeOYpCxWz5hhzcRdmFlrnJi UzhqgPGiMw4E7cCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2AAC33EA63; Mon, 9 Feb 2026 11:43:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id sju4B2XIiWmHSQAAD6G6ig (envelope-from ); Mon, 09 Feb 2026 11:43:33 +0000 Message-ID: <2c59c666-9f6a-460d-8582-55af31ee302d@suse.de> Date: Mon, 9 Feb 2026 12:43:32 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] KVM: x86: synthesize TSA CPUID bits via SCATTERED_F() To: Binbin Wu , seanjc@google.com Cc: bp@alien8.de, kvm@vger.kernel.org, Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" References: <20260208164233.30405-1-clopez@suse.de> <3afa5004-412a-4ab8-b0b9-46bd3982438d@linux.intel.com> Content-Language: en-US From: =?UTF-8?Q?Carlos_L=C3=B3pez?= In-Reply-To: <3afa5004-412a-4ab8-b0b9-46bd3982438d@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_SEVEN(0.00)[11]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid] X-Spam-Flag: NO X-Spam-Score: -4.30 X-Spam-Level: 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.