Skip to content

Commit dd649bd

Browse files
amlutoKAGA-KOKO
authored andcommitted
x86/cpu: Add 'unsafe_fsgsbase' to enable CR4.FSGSBASE
This is temporary. It will allow the next few patches to be tested incrementally. Setting unsafe_fsgsbase is a root hole. Don't do it. Signed-off-by: Andy Lutomirski <[email protected]> Signed-off-by: Chang S. Bae <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Andi Kleen <[email protected]> Reviewed-by: Andy Lutomirski <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent fddf8ba commit dd649bd

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,6 +3079,9 @@
30793079
no5lvl [X86-64] Disable 5-level paging mode. Forces
30803080
kernel to use 4-level paging instead.
30813081

3082+
unsafe_fsgsbase [X86] Allow FSGSBASE instructions. This will be
3083+
replaced with a nofsgsbase flag.
3084+
30823085
no_console_suspend
30833086
[HW] Never suspend the console
30843087
Disable suspending of consoles during suspend and

arch/x86/kernel/cpu/common.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,22 @@ static void __init setup_cr_pinning(void)
441441
static_key_enable(&cr_pinning.key);
442442
}
443443

444+
/*
445+
* Temporary hack: FSGSBASE is unsafe until a few kernel code paths are
446+
* updated. This allows us to get the kernel ready incrementally.
447+
*
448+
* Once all the pieces are in place, these will go away and be replaced with
449+
* a nofsgsbase chicken flag.
450+
*/
451+
static bool unsafe_fsgsbase;
452+
453+
static __init int setup_unsafe_fsgsbase(char *arg)
454+
{
455+
unsafe_fsgsbase = true;
456+
return 1;
457+
}
458+
__setup("unsafe_fsgsbase", setup_unsafe_fsgsbase);
459+
444460
/*
445461
* Protection Keys are not available in 32-bit mode.
446462
*/
@@ -1495,6 +1511,14 @@ static void identify_cpu(struct cpuinfo_x86 *c)
14951511
setup_smap(c);
14961512
setup_umip(c);
14971513

1514+
/* Enable FSGSBASE instructions if available. */
1515+
if (cpu_has(c, X86_FEATURE_FSGSBASE)) {
1516+
if (unsafe_fsgsbase)
1517+
cr4_set_bits(X86_CR4_FSGSBASE);
1518+
else
1519+
clear_cpu_cap(c, X86_FEATURE_FSGSBASE);
1520+
}
1521+
14981522
/*
14991523
* The vendor-specific functions might have changed features.
15001524
* Now we do "generic changes."

0 commit comments

Comments
 (0)