RE: [PATCH v5 03/16] x86/bugs: Restructure MMIO mitigation

From: Kaplan, David
Date: Fri Apr 25 2025 - 09:28:51 EST


[AMD Official Use Only - AMD Internal Distribution Only]

> -----Original Message-----
> From: Borislav Petkov <bp@xxxxxxxxx>
> Sent: Friday, April 25, 2025 4:10 AM
> To: Kaplan, David <David.Kaplan@xxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>; Peter Zijlstra <peterz@xxxxxxxxxxxxx>;
> Josh Poimboeuf <jpoimboe@xxxxxxxxxx>; Pawan Gupta
> <pawan.kumar.gupta@xxxxxxxxxxxxxxx>; Ingo Molnar <mingo@xxxxxxxxxx>; Dave
> Hansen <dave.hansen@xxxxxxxxxxxxxxx>; x86@xxxxxxxxxx; H . Peter Anvin
> <hpa@xxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH v5 03/16] x86/bugs: Restructure MMIO mitigation
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> On Thu, Apr 24, 2025 at 08:31:25PM +0000, Kaplan, David wrote:
> > verw_mitigation_selected implies that X86_FEATURE_CLEAR_CPU_BUF will
> > be enabled, which does a VERW on kernel/vmm exits.
>
> Does it imply that though? As explained, it simply says that *a* VERW mitigation
> has been selected.
>
> And only in the MMIO case which mandates that both spots - kernel entry and
> VMENTER - should be mitigated, it basically says that this
> CLEAR_CPU_BUFFERS macro should be active. And that macro does VERW on
> kernel entry and right before VMLAUNCH.

It was the intent to imply that. If you look at patch 1, 2, and 4 then if verw_mitigation_selected is ever set to true, it means that some mitigation is going to force X86_FEATURE_CLEAR_CPU_BUF.

Maybe the solution here is to clarify the comment above verw_mitigation_selected that it is set if any of those 4 bugs are going to enable X86_FEATURE_CLEAR_CPU_BUF. So it implies that specific VERW-based mitigation.

Or perhaps I could even rename the variable to be 'clear_cpu_buf_selected'?

>
> And when the machine is not affected by MDS+TAA, then it enables this
> cpu_buf_vm_clear thing which does VERW in C code, a bit earlier before
> VMLAUNCH.
>
> > So I'm not sure the comment is really wrong, but it can be rephrased.
>
> Yes please.
>
> > But it kind of does. !verw_mitigation_selected means that the
> > X86_FEATURE bit there isn't set. So the VMM-based mitigation (the
> > static branch) is only used if the broader X86_FEATURE_CLEAR_CPU_BUF
> > is not being used.
>
> Right, except that implication is not fully clear, I think.
>
> > I'm ok with this patch, as long as 'full VERW mitigation' is
> > considered a clear enough term. I think the updated comment in the
> > apply function does explain what that means, so if that's good enough
> > I'm ok.
>
> Right.
>
> So, I did beef up the comments some and renamed the key. Diff ontop of yours
> below. How does that look?
>

I think clarifying what verw_mitigation_selected means is better. When that becomes clear, I think that the existing comments make sense.

Thanks
--David Kaplan