From: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx> The PKRU hardware is permissive by default: all reads and writes are allowed. The in-kernel policy is restrictive by default: deny all unnecessary access until explicitly requested. That policy can be modified with a debugfs file: "x86/init_pkru". This file is created unconditionally, regardless of PKRU support in the hardware, which is a little silly. Avoid creating the file when pkeys are not available. This also removes the need to check for pkey support at runtime, which would be required once the new pkey modification infrastructure is put in place later in this series. Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: Borislav Petkov <bp@xxxxxxxxx> Cc: x86@xxxxxxxxxx Cc: Andy Lutomirski <luto@xxxxxxxxxx> Cc: Shuah Khan <shuah@xxxxxxxxxx> Cc: Babu Moger <babu.moger@xxxxxxx> Cc: Dave Kleikamp <dave.kleikamp@xxxxxxxxxx> Cc: Ram Pai <linuxram@xxxxxxxxxx> Cc: Thiago Jung Bauermann <bauerman@xxxxxxxxxxxxx> Cc: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> --- b/arch/x86/mm/pkeys.c | 4 ++++ 1 file changed, 4 insertions(+) diff -puN arch/x86/mm/pkeys.c~x86-pkeys-skip-debugfs-file arch/x86/mm/pkeys.c --- a/arch/x86/mm/pkeys.c~x86-pkeys-skip-debugfs-file 2021-05-27 16:40:25.847705465 -0700 +++ b/arch/x86/mm/pkeys.c 2021-05-27 16:40:25.852705465 -0700 @@ -193,6 +193,10 @@ static const struct file_operations fops static int __init create_init_pkru_value(void) { + /* Do not expose the file if pkeys are not supported. */ + if (!cpu_feature_enabled(X86_FEATURE_OSPKE)) + return 0; + debugfs_create_file("init_pkru", S_IRUSR | S_IWUSR, arch_debugfs_dir, NULL, &fops_init_pkru); return 0; _