hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/arch/x86/mm/pkeys.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Intel Memory Protection Keys management
34 * Copyright (c) 2015, Intel Corporation.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
- * more details.
135 */
146 #include <linux/debugfs.h> /* debugfs_create_u32() */
157 #include <linux/mm_types.h> /* mm_struct, vma, etc... */
....@@ -39,17 +31,12 @@
3931 * dance to set PKRU if we do not need to. Check it
4032 * first and assume that if the execute-only pkey is
4133 * write-disabled that we do not have to set it
42
- * ourselves. We need preempt off so that nobody
43
- * can make fpregs inactive.
34
+ * ourselves.
4435 */
45
- preempt_disable();
4636 if (!need_to_set_mm_pkey &&
47
- current->thread.fpu.initialized &&
4837 !__pkru_allows_read(read_pkru(), execute_only_pkey)) {
49
- preempt_enable();
5038 return execute_only_pkey;
5139 }
52
- preempt_enable();
5340
5441 /*
5542 * Set up PKRU so that it denies access for everything
....@@ -75,7 +62,7 @@
7562 static inline bool vma_is_pkey_exec_only(struct vm_area_struct *vma)
7663 {
7764 /* Do this check first since the vm_flags should be hot */
78
- if ((vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) != VM_EXEC)
65
+ if ((vma->vm_flags & VM_ACCESS_FLAGS) != VM_EXEC)
7966 return false;
8067 if (vma_pkey(vma) != vma->vm_mm->context.execute_only_pkey)
8168 return false;
....@@ -146,13 +133,6 @@
146133 void copy_init_pkru_to_fpregs(void)
147134 {
148135 u32 init_pkru_value_snapshot = READ_ONCE(init_pkru_value);
149
- /*
150
- * Any write to PKRU takes it out of the XSAVE 'init
151
- * state' which increases context switch cost. Avoid
152
- * writing 0 when PKRU was already 0.
153
- */
154
- if (!init_pkru_value_snapshot && !read_pkru())
155
- return;
156136 /*
157137 * Override the PKRU state that came from 'init_fpstate'
158138 * with the baseline from the process.