From: "Kalra, Ashish" <ashish.kalra@amd.com>
To: sashiko-reviews@lists.linux.dev
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v13 5/5] x86/sev: Re-enable RMP optimizations on SNP guest shutdown
Date: Wed, 2 Sep 2026 17:45:15 -0500 [thread overview]
Message-ID: <77e56212-95cf-46db-852c-6ceb0b9589bc@amd.com> (raw)
In-Reply-To: <20260902220140.BE6131F000E9@smtp.kernel.org>
On 9/2/2026 5:01 PM, sashiko-bot@kernel.org wrote:
> Pre-existing issues:
> - [High] Redundant and costly RMP optimization scan in hardirq context causing severe CPU stalls
> --
>
> commit f95e55ff4f3219c5a1e0b2d2fc34fde539f227f7
> Author: Ashish Kalra <ashish.kalra@amd.com>
> x86/sev: Re-enable RMP optimizations on SNP guest shutdown
>
> This commit introduces a mechanism to re-optimize memory on SNP guest
> shutdown using a delayed work queue to batch multiple terminations.
>
>> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
>> index a4c0fe49b9ec7..fb66a1aa6fc35 100644
>> --- a/arch/x86/virt/svm/sev.c
>> +++ b/arch/x86/virt/svm/sev.c
> [ ... ]
>> @@ -659,6 +659,33 @@ static void do_rmpopt_work(struct work_struct *work)
>> on_each_cpu_mask(cpu_primary_thread_mask, rmpopt_scan_range, NULL, true);
>> }
>>
>> +/*
>> + * Delay, in milliseconds, before the RMP re-optimization pass runs after an
>> + * SNP guest is torn down.
> [ ... ]
>> +void snp_rmpopt_all_physmem(void)
>> +{
>> + if (!rmpopt_capable())
>> + return;
>> +
>> + guard(mutex)(&rmpopt_wq_mutex);
>> +
>> + if (!rmpopt_wq)
>> + return;
>> +
>> + mod_delayed_work(rmpopt_wq, &rmpopt_delayed_work,
>> + msecs_to_jiffies(RMPOPT_WORK_TIMEOUT));
>> +}
> [Severity: High]
> This is a pre-existing issue, but queueing the do_rmpopt_work task upon guest
> teardown exposes the host to severe CPU stalls.
>
> Looking at do_rmpopt_work, it broadcasts an IPI to all primary threads:
>
> arch/x86/virt/svm/sev.c:do_rmpopt_work() {
> ...
> migrate_disable();
> rmpopt_scan_range(NULL);
> migrate_enable();
>
> on_each_cpu_mask(cpu_primary_thread_mask, rmpopt_scan_range, NULL, true);
> }
>
> The IPI handler rmpopt_scan_range executes the rmpopt hardware instruction
> in hardirq context over up to 2TB of memory:
>
> arch/x86/virt/svm/sev.c:rmpopt_scan_range() {
> ...
> for (pa = rmpopt_pa_start; pa < rmpopt_pa_end; pa += SZ_1G)
> rmpopt(pa);
> ...
> }
>
> Since rmpopt is a very slow instruction, does iterating it over massive
> memory ranges inside an IPI handler lead to soft lockups or host denial of
> service, especially if frequent VM churn repeatedly tears down SNP guests
> to trigger this scan?
Two things bound this:
1. Coalescing. snp_rmpopt_all_physmem() uses mod_delayed_work() with a 10 s
delay that is reset on every call, so a burst of guest teardowns does not
queue one scan per teardown — the pass runs once, 10 s after the last
teardown. Frequent VM churn is coalesced into a single pass, not amplified.
2. The IPI does not run an uncached scan. do_rmpopt_work() first runs
rmpopt_scan_range() once on the worker's own CPU under migrate_disable()
(interrupts on, preemptible), which does the expensive part and populates
the shared RMPOPT table — all primary threads share the same RMPOPT_BASE.
Only then does on_each_cpu_mask() fan out, and those RMPOPTs are cache hits
(reads of the already-computed result), so the IRQ-disabled window per CPU
is bounded by the cache-hit cost, not the scan cost — measured at ~320 ms
over the largest configuration tested, well under the soft-lockup/NMI
thresholds.
>
> Additionally, because rmpopt_wq is created as WQ_UNBOUND, the worker
> thread might run on an SMT sibling. If so, wouldn't the initial local scan
> execute on a CPU where MSR_AMD64_RMPOPT_BASE was never configured,
> potentially leading to undefined behavior or faults?
MSR_AMD64_RMPOPT_BASE has core scope, so programming it on each core's primary
thread configures it for both SMT threads of that core. A WQ_UNBOUND worker
that happens to run on a secondary thread therefore still executes RMPOPT
against a validly-configured RMPOPT_BASE (its core's), and since CPU hotplug
is disabled while SNP is active, every core stays configured. There is no CPU
on which RMPOPT_BASE is unconfigured, so no fault or undefined behaviour.
Thanks,
Ashish
next prev parent reply other threads:[~2026-09-02 22:45 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 21:27 [PATCH v13 0/5] Add RMPOPT support Ashish Kalra
2026-09-02 21:27 ` [PATCH v13 1/5] x86/cpufeatures: Add X86_FEATURE_RMPOPT feature flag Ashish Kalra
2026-09-02 21:28 ` [PATCH v13 2/5] x86/sev: Disable CPU hotplug while SNP is active Ashish Kalra
2026-09-02 21:51 ` sashiko-bot
2026-09-02 22:12 ` Kalra, Ashish
2026-09-02 21:28 ` [PATCH v13 3/5] x86/sev: Initialize RMPOPT configuration MSRs Ashish Kalra
2026-09-02 21:44 ` sashiko-bot
2026-09-02 21:56 ` Kalra, Ashish
2026-09-02 21:28 ` [PATCH v13 4/5] x86/sev: Add support to perform RMP optimizations asynchronously Ashish Kalra
2026-09-02 21:36 ` Dave Hansen
2026-09-02 21:57 ` sashiko-bot
2026-09-02 22:36 ` Kalra, Ashish
2026-09-05 1:29 ` Borislav Petkov
2026-09-08 20:21 ` Kalra, Ashish
2026-09-09 1:52 ` Borislav Petkov
2026-09-09 13:55 ` Kalra, Ashish
2026-09-02 21:29 ` [PATCH v13 5/5] x86/sev: Re-enable RMP optimizations on SNP guest shutdown Ashish Kalra
2026-09-02 21:37 ` Dave Hansen
2026-09-02 22:01 ` sashiko-bot
2026-09-02 22:45 ` Kalra, Ashish [this message]
2026-09-06 17:24 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=77e56212-95cf-46db-852c-6ceb0b9589bc@amd.com \
--to=ashish.kalra@amd.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.