Re: [PATCH v10 2/6] x86/sev: Initialize RMPOPT configuration MSRs

"Kalra, Ashish" <[email protected]>
Newsgroups dev.linux.lists.linux-coco,org.kernel.vger.kvm,org.kernel.vger.linux-crypto,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Hello Boris,

On 7/20/2026 8:48 PM, Borislav Petkov wrote:
> On Mon, Jul 20, 2026 at 05:38:05PM -0500, Kalra, Ashish wrote:
>> Agreed on dropping the bool — I'll derive it in a local helper.
>>
>> One issue though: rmp_segment_table != NULL isn't segmented-only. setup_contiguous_rmptable() also allocates rmp_segment_table
>> (the contiguous RMP is stored as a single segment in the same table), so it's non-NULL for the contiguous case too.
>>
>> To keep it segmented-only, I'll also need to gate on the segmented-RMP mode, something like: 
>>
>>   static bool rmpopt_capable(void)
>>   {
>>         return cpu_feature_enabled(X86_FEATURE_RMPOPT) &&
>>                cc_platform_has(CC_ATTR_HOST_SEV_SNP) &&
>>                (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) &&
>>                rmp_segment_table;
>>   }
>>
>> The CC_ATTR_HOST_SEV_SNP check also handles SNP being disabled at runtime, so snp_clear_rmpopt_capable() and its caller go away as well.
> 
 Ok, you can simply do:
> 
> 	setup_clear_cpu_cap(X86_FEATURE_RMPOPT)
> 
> and clear our internal representation of RMPOPT support and make it a lot
> simpler.
> 

We did exactly that in v4, but had to drop it in v7 (flagged during Sashiko review) because it's unreliable here — we only
find out whether RMPOPT is usable after alternatives are patched — too late for setup_clear_cpu_cap() to take effect.

Segmented RMP (which RMPOPT requires) is only determined in setup_rmptable(), reached via:

  rootfs_initcall(pci_iommu_init)
    -> amd_iommu_init() 
	-> state_next() 
		-> iommu_snp_enable()
      			-> snp_rmptable_init() 
				-> setup_rmptable()

That's a rootfs_initcall, which runs after alternative_instructions(). By then static_cpu_has(X86_FEATURE_RMPOPT) is already
patched, so a setup_clear_cpu_cap() at that point doesn't take effect and cpu_feature_enabled(X86_FEATURE_RMPOPT) keeps returning true.

That's why v7 moved to a runtime check. In v11 (as i mentioned) this will be a small local helper,  it will also handles two things
the cap-clear can't:
  - a contiguous (non-segmented) RMP, where RMPOPT isn't usable even with X86_FEATURE_RMPOPT set.
  - SNP being disabled at runtime (CC_ATTR_HOST_SEV_SNP).

  static bool rmpopt_capable(void)
  {
        return cpu_feature_enabled(X86_FEATURE_RMPOPT) &&
               cc_platform_has(CC_ATTR_HOST_SEV_SNP) &&
               (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) &&
               rmp_segment_table;
  }

Thanks,
Ashish
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.