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 v6 2/6] x86/sev: Initialize RMPOPT configuration MSRs
Date: Tue, 02 Jun 2026 20:36:26 +0000	[thread overview]
Message-ID: <20260602203627.37D0D1F00893@smtp.kernel.org> (raw)
In-Reply-To: <87d473d05c26458773b7957fb96e9b2948641753.1780427587.git.ashish.kalra@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Late clearing of X86_FEATURE_RMPOPT via setup_clear_cpu_cap() fails to un-patch CPU alternatives, causing snp_setup_rmpopt() to dangerously enable RMPOPT on unsupported Contiguous RMP configurations.
--

commit 551ddbd8061d6e0326ab620a808e849941500d13
Author: Ashish Kalra <ashish.kalra@amd.com>

x86/sev: Initialize RMPOPT configuration MSRs

This commit introduces RMPOPT instruction support to manage per-CPU RMP
optimization structures. It sets up the RMPOPT table base to enable
optimizations for up to 2TB of system RAM once SNP is enabled. It also
attempts to clear the RMPOPT CPU capability if Segmented RMP is disabled.

> diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c
> index 989ca9f72ba30..7fdef00ca8f22 100644
> --- a/arch/x86/coco/core.c
> +++ b/arch/x86/coco/core.c
> @@ -172,6 +172,7 @@ static void amd_cc_platform_clear(enum cc_attr attr)
>  	switch (attr) {
>  	case CC_ATTR_HOST_SEV_SNP:
>  		cc_flags.host_sev_snp = 0;
> +		setup_clear_cpu_cap(X86_FEATURE_RMPOPT);
>  		break;
>  	default:
>  		break;

[ ... ]

> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index 8bcdce98f6dce..089c9a14edc74 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c

[ ... ]

> @@ -488,9 +491,13 @@ static bool __init setup_segmented_rmptable(void)
>  static bool __init setup_rmptable(void)
>  {
>  	if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) {
> -		if (!setup_segmented_rmptable())
> +		if (!setup_segmented_rmptable()) {
> +			setup_clear_cpu_cap(X86_FEATURE_RMPOPT);
>  			return false;
> +		}
>  	} else {
> +		/* Note that Segmented RMP must be enabled to enable RMPOPT. */
> +		setup_clear_cpu_cap(X86_FEATURE_RMPOPT);

[Severity: High]
Will calling setup_clear_cpu_cap() this late in the boot sequence effectively
disable the feature?

Since setup_rmptable() and amd_cc_platform_clear() are invoked during late
IOMMU initialization, this executes after check_bugs() has already permanently
patched the alternative instructions.

While do_clear_cpu_cap() will trigger a kernel WARNING and update the
in-memory boot_cpu_data array, it cannot undo the static code patching of
static_cpu_has().

>  		if (!setup_contiguous_rmptable())
>  			return false;
>  	}

[ ... ]

> +void snp_setup_rmpopt(void)
> +{
> +	u64 rmpopt_base;
> +	int cpu;
> +
> +	if (!cpu_feature_enabled(X86_FEATURE_RMPOPT))
> +		return;

[Severity: High]
If setup_clear_cpu_cap() failed to un-patch the alternatives earlier, will
cpu_feature_enabled() incorrectly return true here even when falling back to
Contiguous RMP?

Because cpu_feature_enabled() relies on static_cpu_has(), it seems it will
execute the previously patched instruction and erroneously bypass this check.

Would this result in snp_setup_rmpopt() wrongly configuring
MSR_AMD64_RMPOPT_BASE and dangerously enabling RMPOPT on unsupported
configurations, risking CPU exceptions or memory corruption?

Could a global boolean flag be used to track the RMPOPT state instead of
dynamically mutating a CPU feature after alternatives are patched?

> +
> +	cpus_read_lock();

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

  reply	other threads:[~2026-06-02 20:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02 20:00 [PATCH v6 0/6] Add RMPOPT support Ashish Kalra
2026-06-02 20:00 ` [PATCH v6 1/6] x86/cpufeatures: Add X86_FEATURE_AMD_RMPOPT feature flag Ashish Kalra
2026-06-02 20:10   ` sashiko-bot
2026-06-02 20:01 ` [PATCH v6 2/6] x86/sev: Initialize RMPOPT configuration MSRs Ashish Kalra
2026-06-02 20:36   ` sashiko-bot [this message]
2026-06-02 20:01 ` [PATCH v6 3/6] x86/sev: Add support to perform RMP optimizations asynchronously Ashish Kalra
2026-06-02 20:46   ` sashiko-bot
2026-06-02 20:01 ` [PATCH v6 4/6] x86/sev: Add interface to re-enable RMP optimizations Ashish Kalra
2026-06-02 20:54   ` sashiko-bot
2026-06-02 20:02 ` [PATCH v6 5/6] KVM: SEV: Perform RMP optimizations on SNP guest shutdown Ashish Kalra
2026-06-02 20:02 ` [PATCH v6 6/6] x86/sev: Add debugfs support for RMPOPT Ashish Kalra

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=20260602203627.37D0D1F00893@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.