Re: [PATCH v4 2/2] x86/sev: Set up RMPOPT only on an active SNP host
From: Tom Lendacky
Date: Thu Oct 29 2026 - 11:36:12 EST
On 10/28/26 14:49, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@xxxxxxx>
>
> rmpopt_init() allocates the RMPOPT workqueue and prints "RMPOPT
> optimizations enabled", gated only on X86_FEATURE_RMPOPT - a CPUID bit
> advertised independently of whether SNP is active. As a device_initcall
> it runs on every system with that bit, so on a host where SNP is not
> enabled (disabled in the BIOS, or AMD IOMMU initialization fails to bring
> it up) the workqueue is allocated and the message is printed at boot even
> though RMPOPT is never used: snp_enable_rmpopt() bails out on a non-SNP
> host.
>
> Rather than add an explicit SNP-host gate to the initcall, set RMPOPT up
> where the host SNP state is established. Call rmpopt_init() from the tail
> of snp_rmptable_init(), which runs only once the host RMP table has been
> set up and CC_ATTR_HOST_SEV_SNP is guaranteed (it WARN_ON_ONCE()s
> otherwise), and drop the device_initcall. rmpopt_init() keeps its
> original X86_FEATURE_RMPOPT-only gate and no longer needs a separate
> SNP-host check.
>
> This is soft initialization only - the workqueue and the announcement; the
> actual RMPOPT_BASE programming is still done later by snp_enable_rmpopt(),
> which re-checks X86_FEATURE_RMPOPT, CC_ATTR_HOST_SEV_SNP and
> rmpopt_soft_init. An rmpopt_init() failure is non-fatal to SNP and is
> intentionally ignored by snp_rmptable_init().
>
> Suggested-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
> Fixes: c6c6f156d192 ("x86/sev: Perform RMP optimizations asynchronously")
> Signed-off-by: Ashish Kalra <ashish.kalra@xxxxxxx>
Reviewed-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
> ---
> arch/x86/virt/svm/sev.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index cd0412b9d251..39d3943cdc49 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c
> @@ -662,7 +662,6 @@ static int __init rmpopt_init(void)
>
> return 0;
> }
> -device_initcall(rmpopt_init);
>
> void snp_enable_rmpopt(void)
> {
> @@ -726,6 +725,8 @@ int __init snp_rmptable_init(void)
> */
> crash_kexec_post_notifiers = true;
>
> + rmpopt_init();
> +
> return 0;
> }
>