Re: [PATCH v10 2/6] x86/sev: Initialize RMPOPT configuration MSRs
From: Kalra, Ashish
Date: Wed Jul 22 2026 - 15:17:33 EST
On 7/21/2026 9:46 PM, K Prateek Nayak wrote:
> Hello Ashish,
>
> On 7/22/2026 2:16 AM, Kalra, Ashish wrote:
>> The one I'd keep is (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED). It's a runtime config bit, not the CPUID feature:
>> setup_rmptable() allocates rmp_segment_table and keeps CC_ATTR_HOST_SEV_SNP set for both segmented and contiguous RMP, so
>> the MSR bit is the only thing that distinguishes them — and RMPOPT needs a segmented RMP.
>>
>> Clearing X86_FEATURE_RMPOPT in snp_rmptable_init() won't work on its own as i mentioned in this reply earlier: it runs at
>> rootfs_initcall, after alternative_instructions(), so cpu_feature_enabled() keeps returning true off the already-patched
>> static_cpu_has().
>
> My bad! I actually meant in snp_probe_rmptable_info() during
> bsp_determine_snp(). Something like:
>
> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index 8bcdce98f6dc..3ad53ef16c2f 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c
> @@ -684,10 +684,12 @@ bool snp_probe_rmptable_info(void)
> if (cpu_feature_enabled(X86_FEATURE_SEGMENTED_RMP))
> rdmsrq(MSR_AMD64_RMP_CFG, rmp_cfg);
>
> - if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED)
> + if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) {
> return probe_segmented_rmptable_info();
> - else
> + } else {
> + setup_clear_cpu_cap(X86_FEATURE_RMPOPT);
> return probe_contiguous_rmptable_info();
> + }
> }
>
> /*
> ---
>
> Based on a quick look, it gets only called at bsp init and is early
> enough to allow patching alternatives and I don't see anything writing
> to MSR_AMD64_RMP_CFG.
>
> Thoughts?
>
Ah, that works — thanks.
With the contiguous case cleared early, X86_FEATURE_RMPOPT set now implies a segmented RMP, so the MSR-bit test drops out and the helper becomes:
static bool rmpopt_capable(void)
{
return cpu_feature_enabled(X86_FEATURE_RMPOPT) &&
cc_platform_has(CC_ATTR_HOST_SEV_SNP);
}
I'll keep cc_platform_has(CC_ATTR_HOST_SEV_SNP) for the late failures the early clear can't cover: setup_segmented_rmptable() can still
fail in snp_rmptable_init() (rootfs_initcall, i.e. post-alternatives, where clearing the feature bit wouldn't stick) — and on that path
iommu_snp_enable() clears CC_ATTR_HOST_SEV_SNP, so the helper returns false. Same term also covers SNP being disabled at runtime.
Thanks,
Ashish