From: Jon Kohler <jon@nutanix.com>
To: Chao Gao <chao.gao@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>,
Peter Zijlstra <peterz@infradead.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Pawan Gupta <pawan.kumar.gupta@linux.intel.com>,
Ingo Molnar <mingo@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
X86 ML <x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
LKML <linux-kernel@vger.kernel.org>,
"kvm @ vger . kernel . org" <kvm@vger.kernel.org>
Subject: Re: [PATCH] x86/bhi: avoid hardware mitigation for 'spectre_bhi=vmexit'
Date: Fri, 13 Sep 2024 15:52:07 +0000 [thread overview]
Message-ID: <49173342-7518-4A69-9B45-01DA7FCB6831@nutanix.com> (raw)
In-Reply-To: <ZuPQKHrUcC/YejXx@intel.com>
> On Sep 13, 2024, at 1:39 AM, Chao Gao <chao.gao@intel.com> wrote:
>
> !-------------------------------------------------------------------|
> CAUTION: External Email
>
> |-------------------------------------------------------------------!
>
> On Thu, Sep 12, 2024 at 07:11:56AM -0700, Jon Kohler wrote:
>> On hardware that supports BHI_DIS_S/X86_FEATURE_BHI_CTRL, do not use
>> hardware mitigation when using BHI_MITIGATION_VMEXIT_ONLY, as this
>> causes the value of MSR_IA32_SPEC_CTRL to change, which inflicts
>> additional KVM overhead.
>>
>> Example: In a typical eIBRS enabled system, such as Intel SPR, the
>> SPEC_CTRL may be commonly set to val == 1 to reflect eIBRS enablement;
>> however, SPEC_CTRL_BHI_DIS_S causes val == 1025. If the guests that
>> KVM is virtualizing do not also set the guest side value == 1025,
>> KVM will constantly have to wrmsr toggle the guest vs host value on
>> both entry and exit, delaying both.
>
> Putting aside the security concern, this patch isn't a net positive
> because it causes additional overhead to guests with spec_ctrl = 1025.
See my other note with a different approach and testing to match.
Responding to this point here that this would require VMM to expose BHI_CTRL
which for example QEMU does not, so this is not yet a problem at least
today
>
>>
>> Signed-off-by: Jon Kohler <jon@nutanix.com>
>> ---
>> arch/x86/kernel/cpu/bugs.c | 12 ++++++++++--
>> 1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
>> index 45675da354f3..df7535f5e882 100644
>> --- a/arch/x86/kernel/cpu/bugs.c
>> +++ b/arch/x86/kernel/cpu/bugs.c
>> @@ -1662,8 +1662,16 @@ static void __init bhi_select_mitigation(void)
>> return;
>> }
>>
>> - /* Mitigate in hardware if supported */
>> - if (spec_ctrl_bhi_dis())
>> + /*
>> + * Mitigate in hardware if appropriate.
>> + * Note: for vmexit only, do not mitigate in hardware to avoid changing
>> + * the value of MSR_IA32_SPEC_CTRL to include SPEC_CTRL_BHI_DIS_S. If a
>> + * guest does not also set their own SPEC_CTRL to include this, KVM has
>> + * to toggle on every vmexit and vmentry if the host value does not
>> + * match the guest value. Instead, depend on software loop mitigation
>> + * only.
>> + */
>> + if (bhi_mitigation != BHI_MITIGATION_VMEXIT_ONLY && spec_ctrl_bhi_dis())
>> return;
>>
>> if (!IS_ENABLED(CONFIG_X86_64))
>> --
>> 2.43.0
>>
>>
prev parent reply other threads:[~2024-09-13 15:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-12 14:11 Jon Kohler
2024-09-12 15:14 ` Pawan Gupta
2024-09-12 15:44 ` Jon Kohler
2024-09-12 16:24 ` Pawan Gupta
2024-09-13 5:28 ` Chao Gao
2024-09-13 15:51 ` Jon Kohler
2024-09-13 17:33 ` Pawan Gupta
2024-09-13 18:01 ` Jon Kohler
2024-09-13 18:39 ` Jim Mattson
2024-09-13 23:04 ` Jim Mattson
2024-09-14 0:16 ` Pawan Gupta
2024-09-14 2:35 ` Jim Mattson
2024-09-13 5:39 ` Chao Gao
2024-09-13 15:52 ` Jon Kohler [this message]
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=49173342-7518-4A69-9B45-01DA7FCB6831@nutanix.com \
--to=jon@nutanix.com \
--cc=bp@alien8.de \
--cc=chao.gao@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jpoimboe@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--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®