mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kim Phillips <kim.phillips@amd.com>
To: Borislav Petkov <bp@alien8.de>
Cc: <linux-kernel@vger.kernel.org>, <x86@kernel.org>,
	<linux-coco@lists.linux.dev>, <kvm@vger.kernel.org>,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	Nikunj A Dadhania <nikunj@amd.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Michael Roth <michael.roth@amd.com>,
	Naveen Rao <naveen.rao@amd.com>,
	David Kaplan <david.kaplan@amd.com>,
	Pawan Gupta <pawan.kumar.gupta@linux.intel.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Nathan Fontenot <nathan.fontenot@amd.com>
Subject: Re: [PATCH v5 1/8] x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs
Date: Fri, 18 Sep 2026 18:00:21 -0500	[thread overview]
Message-ID: <01b57e61-df45-44a6-848b-c19eae226ad0@amd.com> (raw)
In-Reply-To: <20260903040330.GNapjxkgMd2Ey38egR@fat_crate.local>

On 9/2/26 11:03 PM, Borislav Petkov wrote:
> On Wed, Aug 26, 2026 at 05:35:03PM -0500, Kim Phillips wrote:
>> spectre_v2=eibrs currently enables retpolines when SNP is enabled,
>> instead of AutoIBRS (EIBRS) because the commit that disabled
>> AutoIBRS if SNP is enabled stopped short of enabling
>> X86_FEATURE_IBRS_ENHANCED.
> This and the comment below in spectre_v2_select_mitigation() is somewhat
> hinting on what you're trying to do here, and I can only guess. But
> I shouldn't be guessing. Rather, the text should explain it clearly.
>
>> Change the logic to enable X86_FEATURE_IBRS_ENHANCED, and move the
>> decision to switch to retpolines in the default/"auto" case in
>> spectre_v2_select_mitigation().  This allows the existing
>> spectre_v2=eibrs logic to work as intended.
>>
>> Condition that switch on CONFIG_MITIGATION_RETPOLINE being built in.
>> Otherwise spectre_v2_select_retpoline() returns SPECTRE_V2_NONE and an
>> SNP host with AutoIBRS available would be left completely unmitigated
>> against Spectre v2 in the default/auto case, which is worse than the
>> userspace indirect branch performance loss AutoIBRS costs.
>>
>> Also emit a performance loss warning for using AutoIBRS with SNP
>> enabled.  AutoIBRS is activated for all three eIBRS modes via
>> spectre_v2_in_eibrs_mode(), so use that helper to cover
>> spectre_v2=eibrs, spectre_v2=eibrs,lfence, and
>> spectre_v2=eibrs,retpoline uniformly.  Word the warning in terms of the
>> eIBRS mitigation enabling AutoIBRS, rather than naming AutoIBRS as the
>> selected mitigation, so it reads correctly for the ,lfence and
>> ,retpoline variants where another component is also active.
> This whole text is explaining the diff. Never write about the "what" - but the
> "why". Why does this patch exist?
>
> Please structure your commit message something like this:
>
> 1. Prepare the context for the explanation briefly.
>
> 2. Explain the problem at hand.
>
> 3. "It happens because of <...>"
>
> 4. "Fix it by doing X"
>
> 5. "(Potentially do Y)."
>
> And some of those above are optional depending on the issue being
> explained.
>
> But do not explain the patch. If there are questions about it, I will ask.
>
> Thx.
>
How about the following as the new commit text?:

AMD's AutoIBRS is the hardware implementation of eIBRS.  When SNP is
active, AutoIBRS also applies to host userspace, which costs indirect
branch performance there, so commit acaa4b5c4c85 ("x86/speculation: Do
not enable Automatic IBRS if SEV-SNP is enabled") made SNP hosts use
retpolines instead.

That fallback cannot be overridden.  An admin running an SNP host whose
workload is dominated by guest activity rather than host userspace may
well prefer AutoIBRS, but asking for it with spectre_v2=eibrs silently
yields retpolines instead.

It happens because the SNP check sits in cpu_set_bug_bits() and simply
leaves X86_FEATURE_IBRS_ENHANCED clear.  Without that feature bit, the
command line parser cannot distinguish "this CPU has no eIBRS" from
"this CPU has eIBRS but policy turned it off", so spectre_v2=eibrs has
nothing left to select and falls back to auto.

Fix it by setting X86_FEATURE_IBRS_ENHANCED whenever the hardware
supports AutoIBRS, and moving the SNP policy decision into
spectre_v2_select_mitigation() where it applies to the default/auto
case only.  The default behaviour stays as it is today, and
spectre_v2=eibrs now means what it says.

Keep AutoIBRS in the default case when CONFIG_MITIGATION_RETPOLINE is
not built in: there is nothing to fall back to and an unmitigated SNP
host is worse than the userspace performance loss.

Finally, warn when eIBRS does end up enabling AutoIBRS on an SNP host so
that the performance cost is not silent.

Thanks,

Kim

  reply	other threads:[~2026-09-18 23:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 22:35 [PATCH v5 0/8] Add SEV-SNP BTB Isolation and IBPB-on-Entry guest features Kim Phillips
2026-08-26 22:35 ` [PATCH v5 1/8] x86/bugs: Allow forcing Automatic IBRS with SNP active using spectre_v2=eibrs Kim Phillips
2026-08-27  4:32   ` Pawan Gupta
2026-09-03  4:03   ` Borislav Petkov
2026-09-18 23:00     ` Kim Phillips [this message]
2026-08-26 22:35 ` [PATCH v5 2/8] x86/bugs: Allow spectre_v2=ibrs on x86 vendors other than Intel Kim Phillips
2026-08-27  4:33   ` Pawan Gupta
2026-09-09 21:01   ` Borislav Petkov
2026-09-18 23:01     ` Kim Phillips
2026-08-26 22:35 ` [PATCH v5 3/8] KVM: SVM: Define SVM_SEV_FEAT_* flags using BIT_ULL() Kim Phillips
2026-08-26 22:35 ` [PATCH v5 4/8] KVM: selftests: sev_init2: Use BIT_ULL for VMSA feature bit definition Kim Phillips
2026-08-26 22:35 ` [PATCH v5 5/8] KVM: SEV: Disallow setting SNP-only features for non-SNP guests via a single mask Kim Phillips
2026-08-26 22:35 ` [PATCH v5 6/8] KVM: SEV: Advertise SVM_SEV_FEAT_SNP_ACTIVE Kim Phillips
2026-08-26 22:35 ` [PATCH v5 7/8] KVM: SEV: Add support for IBPB-on-Entry Kim Phillips
2026-08-26 22:35 ` [PATCH v5 8/8] KVM: SEV: Add support for SNP BTB Isolation Kim Phillips

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=01b57e61-df45-44a6-848b-c19eae226ad0@amd.com \
    --to=kim.phillips@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=david.kaplan@amd.com \
    --cc=kprateek.nayak@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=nathan.fontenot@amd.com \
    --cc=naveen.rao@amd.com \
    --cc=nikunj@amd.com \
    --cc=pawan.kumar.gupta@linux.intel.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®