Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

x86/cpu: Enable modifying CPU bug flags with '{clear,set}puid='

Sometimes it can be very useful to run CPU vulnerability mitigations on
systems where they aren't known to mitigate any real-world
vulnerabilities. This can be handy for mundane reasons like debugging
HW-agnostic logic on whatever machine is to hand, but also for research
reasons: while some mitigations are focused on individual vulns and
uarches, others are fairly general, and it's strategically useful to
have an idea how they'd perform on systems where they aren't currently
needed.

As evidence for this being useful, a flag specifically for Retbleed was
added in:

5c9a92dec323 ("x86/bugs: Add retbleed=force").

Since CPU bugs are tracked using the same basic mechanism as features,
and there are already parameters for manipulating them by hand, extend
that mechanism to support bug as well as capabilities.

With this patch and setcpuid=srso, a QEMU guest running on an Intel host
will boot with Safe-RET enabled.

Signed-off-by: Brendan Jackman <jackmanb@google.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20241220-force-cpu-bug-v2-3-7dc71bce742a@google.com

authored by

Brendan Jackman and committed by
Ingo Molnar
ab68d2e3 814165e9

+13 -4
+1
arch/x86/include/asm/cpufeature.h
··· 50 50 * X86_BUG_<name> - NCAPINTS*32. 51 51 */ 52 52 extern const char * const x86_bug_flags[NBUGINTS*32]; 53 + #define x86_bug_flag(flag) x86_bug_flags[flag] 53 54 54 55 #define test_cpu_cap(c, bit) \ 55 56 arch_test_bit(bit, (unsigned long *)((c)->x86_capability))
+12 -4
arch/x86/kernel/cpu/common.c
··· 1494 1494 1495 1495 /* 1496 1496 * Handle naked numbers first for feature flags which don't 1497 - * have names. 1497 + * have names. It doesn't make sense for a bug not to have a 1498 + * name so don't handle bug flags here. 1498 1499 */ 1499 1500 if (!kstrtouint(opt, 10, &bit)) { 1500 1501 if (bit < NCAPINTS * 32) { ··· 1519 1518 continue; 1520 1519 } 1521 1520 1522 - for (bit = 0; bit < 32 * NCAPINTS; bit++) { 1523 - if (!x86_cap_flag(bit)) 1521 + for (bit = 0; bit < 32 * (NCAPINTS + NBUGINTS); bit++) { 1522 + const char *flag; 1523 + 1524 + if (bit < 32 * NCAPINTS) 1525 + flag = x86_cap_flag(bit); 1526 + else 1527 + flag = x86_bug_flag(bit - (32 * NCAPINTS)); 1528 + 1529 + if (!flag) 1524 1530 continue; 1525 1531 1526 - if (strcmp(x86_cap_flag(bit), opt)) 1532 + if (strcmp(flag, opt)) 1527 1533 continue; 1528 1534 1529 1535 pr_cont(" %s", opt);