[PATCH v3 2/2] x86/sev: Only announce RMPOPT optimizations when SNP is enabled

From: Ashish Kalra

Date: Wed Oct 14 2026 - 19:08:55 EST


From: Ashish Kalra <ashish.kalra@xxxxxxx>

rmpopt_init() sets up the RMPOPT workqueue and prints "RMPOPT
optimizations enabled" gated only on X86_FEATURE_RMPOPT, which is a CPUID
bit advertised independently of whether SNP is active. On a system where
SNP is not enabled 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).

Gate rmpopt_init() on an active SNP host as well, using
cc_platform_has(CC_ATTR_HOST_SEV_SNP). This reflects the final host SNP
state: it is set at BSP initialization and cleared whenever SNP cannot be
brought up, whether disabled in the BIOS or when AMD IOMMU initialization
fails to enable SNP (which clears CC_ATTR_HOST_SEV_SNP but leaves the
X86_FEATURE_SEV_SNP CPUID bit set). It is settled before this
device_initcall runs and matches the gate used in snp_enable_rmpopt().

Suggested-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
Fixes: c6c6f156d192 ("x86/sev: Perform RMP optimizations asynchronously")
Signed-off-by: Ashish Kalra <ashish.kalra@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 43e4945e6cdf..fe78f512e7aa 100644
--- a/arch/x86/virt/svm/sev.c
+++ b/arch/x86/virt/svm/sev.c
@@ -639,7 +639,8 @@ static void do_rmpopt_work(struct work_struct *work)

static int __init rmpopt_init(void)
{
- if (!cpu_feature_enabled(X86_FEATURE_RMPOPT))
+ if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP) ||
+ !cpu_feature_enabled(X86_FEATURE_RMPOPT))
return -ENODEV;

rmpopt_wq = alloc_workqueue("rmpopt_wq", WQ_PERCPU, 1);
--
2.43.0