Re: [PATCH v11 2/6] x86/sev: Disable CPU hotplug while SNP is active

"Kalra, Ashish" <[email protected]> Fri, 31 Jul 2026 15:27:58 -0500
Newsgroups org.kernel.vger.linux-crypto,dev.linux.lists.linux-coco,org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Hello Tom,

On 7/31/2026 2:35 PM, Tom Lendacky wrote:
>>  int __init snp_rmptable_init(void)
>>  {
>> +	u64 val;
>> +
>>  	if (WARN_ON_ONCE(!cc_platform_has(CC_ATTR_HOST_SEV_SNP)))
>>  		return -ENOSYS;
>>  
>> @@ -586,6 +596,15 @@ int __init snp_rmptable_init(void)
>>  	if (!setup_rmptable())
>>  		return -ENOSYS;
>>  
>> +	/*
>> +	 * On a kexec boot SNP may already be enabled (legacy firmware leaves
>> +	 * SnpEn set across shutdown), in which case snp_prepare() bails without
>> +	 * disabling CPU hotplug, so disable it here.
>> +	 */
>> +	rdmsrq(MSR_AMD64_SYSCFG, val);
>> +	if (val & MSR_AMD64_SYSCFG_SNP_EN)
>> +		cpu_hotplug_disable();
>> +
> Why not just put the cpu_hotplug_disable() at the start of snp_prepare()
> then? Wouldn't that take care of both situations and only end up with a
> single disable point?

The difference is SnpEn: on normal boot it isn't set until snp_prepare(), so hotplug during that IOMMU init -> ccp load window 
is harmless and the online == present check refuses to enable SNP if the CPU set is incomplete — detect-and-refuse at the enable moment.

On kexec SnpEn could already be set from the previous kernel, so that same window is now dangerous (there'd be a window from 
IOMMU-init -> ccp-load where CPU could be offlined/onlined while SnpEn is set) and additionally there's no enable moment to gate — 
snp_prepare() bails before the check because SNP is already on. So we can't detect-and-refuse and so we have to prevent the window
by disabling hotplug early, at the IOMMU-init point (snp_rmptable_init()).

Thanks,
Ashish