[tip: x86/sev] x86/sev: Do RMP optimizations on SNP guest shutdown
From: tip-bot2 for Ashish Kalra
Date: Fri Sep 18 2026 - 20:12:22 EST
The following commit has been merged into the x86/sev branch of tip:
Commit-ID: edb1b49e724ea102b3eaeb0b57f8ca33cd445887
Gitweb: https://git.kernel.org/tip/edb1b49e724ea102b3eaeb0b57f8ca33cd445887
Author: Ashish Kalra <ashish.kalra@xxxxxxx>
AuthorDate: Wed, 16 Sep 2026 22:15:37
Committer: Borislav Petkov (AMD) <bp@xxxxxxxxx>
CommitterDate: Fri, 18 Sep 2026 16:58:20 -07:00
x86/sev: Do RMP optimizations on SNP guest shutdown
The RMPOPT table is a per-CPU table which indicates whether 1GB regions
of physical memory are entirely hypervisor-owned.
When performing host memory accesses in hypervisor mode as well as
non-SNP guest mode, the processor may consult the RMPOPT table to
potentially skip an RMP access and improve performance.
Normal guest events disable RMP optimizations: pages are converted from
shared to private as SNP guests are launched, and large pages are split
and collapsed during guest operation -- both disable the RMPOPT
optimizations for the affected 1GB regions.
When guests are torn down, their pages are converted back to shared, so those
regions may become eligible for RMP optimizations again. Without some
intervention, all those optimizations would eventually be lost, so optimize
all of physical memory on SNP guest teardown.
snp_enable_rmpopt() performs the re-optimization after a delay, which gets
reset on each call. This way multiple guest terminations are batched into
a single pass: the re-optimization runs 10 seconds after the *last*
termination rather than after the first. mod_delayed_work() also re-queues
work that is already in-flight, so a re-scan request during an active scan is
not silently dropped.
Guest teardown is currently the only event that returns guest memory to
hypervisor ownership: SNP guests do not support ballooning or memory hotplug,
so pages freed during a guest's lifetime remain guest-owned. It is therefore
the only point at which memory becomes eligible for RMP re-optimization, which
is why re-optimization is driven by guest teardown rather than by a periodic
scan.
[ bp: Massage commit message. ]
Signed-off-by: Ashish Kalra <ashish.kalra@xxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Reviewed-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>
Reviewed-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
Reviewed-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Link: https://patch.msgid.link/7a15a880ea6b6d53b3702def3b3434307656afd7.1789594774.git.ashish.kalra@xxxxxxx
---
arch/x86/kvm/svm/sev.c | 2 ++
arch/x86/virt/svm/sev.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 5705723..4d5e30a 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -3032,6 +3032,8 @@ void sev_vm_destroy(struct kvm *kvm)
*/
if (snp_decommission_context(kvm))
return;
+
+ snp_enable_rmpopt();
} else {
sev_unbind_asid(kvm, sev->handle);
}
diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
index 2d2a8b1..bd70c4d 100644
--- a/arch/x86/virt/svm/sev.c
+++ b/arch/x86/virt/svm/sev.c
@@ -691,7 +691,7 @@ void snp_enable_rmpopt(void)
mod_delayed_work(rmpopt_wq, &rmpopt_delayed_work,
msecs_to_jiffies(RMPOPT_WORK_TIMEOUT));
}
-EXPORT_SYMBOL_FOR_MODULES(snp_enable_rmpopt, "ccp");
+EXPORT_SYMBOL_FOR_MODULES(snp_enable_rmpopt, "ccp,kvm-amd");
/*
* Do the necessary preparations which are verified by the firmware as