All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ashish Kalra" <Ashish.Kalra@amd.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v13 5/5] x86/sev: Re-enable RMP optimizations on SNP guest shutdown
Date: Wed, 02 Sep 2026 22:01:40 +0000	[thread overview]
Message-ID: <20260902220140.BE6131F000E9@smtp.kernel.org> (raw)
In-Reply-To: <e8a8d0ec63bda2db61cde7cf298a4ccb6a502c20.1788296083.git.ashish.kalra@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

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?

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?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788296083.git.ashish.kalra@amd.com?part=5

  parent reply	other threads:[~2026-09-02 22:01 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 [this message]
2026-09-02 22:45     ` Kalra, Ashish
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=20260902220140.BE6131F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=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.