RE: [PATCH v4 18/36] cpu: Define attack vectors

From: Kaplan, David
Date: Mon Apr 14 2025 - 17:21:10 EST


[AMD Official Use Only - AMD Internal Distribution Only]

> -----Original Message-----
> From: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> Sent: Thursday, April 10, 2025 1:12 PM
> To: Kaplan, David <David.Kaplan@xxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>; Borislav Petkov <bp@xxxxxxxxx>;
> Peter Zijlstra <peterz@xxxxxxxxxxxxx>; 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; Brendan Jackman
> <jackmanb@xxxxxxxxxx>; Derek Manwaring <derekmn@xxxxxxxxxx>
> Subject: Re: [PATCH v4 18/36] cpu: Define attack vectors
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> On Mon, Mar 10, 2025 at 11:40:05AM -0500, David Kaplan wrote:
> > @@ -3178,8 +3179,38 @@ void __init boot_cpu_hotplug_init(void)
> >
> > #ifdef CONFIG_CPU_MITIGATIONS
> > /*
> > - * These are used for a global "mitigations=" cmdline option for
> > toggling
> > - * optional CPU mitigations.
> > + * All except the cross-thread attack vector are mitigated by default.
> > + * Cross-thread mitigation often requires disabling SMT which is too
> > + expensive
> > + * to be enabled by default.
>
> Cross-thread is *partially* mitigated by default (everything except disabling SMT).
>

Will fix comment

> > +bool cpu_mitigate_attack_vector(enum cpu_attack_vectors v) {
> > + if (v < NR_CPU_ATTACK_VECTORS)
> > + return attack_vectors[v];
> > +
> > + WARN_ON_ONCE(v >= NR_CPU_ATTACK_VECTORS);
>
> This can be a WARN_ONCE(), v is already known to be invalid here.

Ack

>
> > static int __init mitigations_parse_cmdline(char *arg) {
> > - if (!strcmp(arg, "off"))
> > - cpu_mitigations = CPU_MITIGATIONS_OFF;
> > - else if (!strcmp(arg, "auto"))
> > - cpu_mitigations = CPU_MITIGATIONS_AUTO;
> > - else if (!strcmp(arg, "auto,nosmt"))
> > - cpu_mitigations = CPU_MITIGATIONS_AUTO_NOSMT;
> > - else
> > - pr_crit("Unsupported mitigations=%s, system may still be vulnerable\n",
> > - arg);
> > + char *s, *p;
> > + int len;
> > +
> > + len = mitigations_parse_global_opt(arg);
> > +
> > + if (cpu_mitigations_off()) {
> > + memset(attack_vectors, 0, sizeof(attack_vectors));
> > + smt_mitigations = SMT_MITIGATIONS_OFF;
> > + } else if (cpu_mitigations_auto_nosmt())
> > + smt_mitigations = SMT_MITIGATIONS_ON;
>
> Kernel coding style wants consistent braces for if-then-else:
>
> if (cpu_mitigations_off()) {
> memset(attack_vectors, 0, sizeof(attack_vectors));
> smt_mitigations = SMT_MITIGATIONS_OFF;
> } else if (cpu_mitigations_auto_nosmt()) {
> smt_mitigations = SMT_MITIGATIONS_ON;
> }
>

Ack

Thanks --David Kaplan