.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Intel Memory Protection Keys management |
---|
3 | 4 | * 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. |
---|
13 | 5 | */ |
---|
14 | 6 | #include <linux/debugfs.h> /* debugfs_create_u32() */ |
---|
15 | 7 | #include <linux/mm_types.h> /* mm_struct, vma, etc... */ |
---|
.. | .. |
---|
39 | 31 | * dance to set PKRU if we do not need to. Check it |
---|
40 | 32 | * first and assume that if the execute-only pkey is |
---|
41 | 33 | * 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. |
---|
44 | 35 | */ |
---|
45 | | - preempt_disable(); |
---|
46 | 36 | if (!need_to_set_mm_pkey && |
---|
47 | | - current->thread.fpu.initialized && |
---|
48 | 37 | !__pkru_allows_read(read_pkru(), execute_only_pkey)) { |
---|
49 | | - preempt_enable(); |
---|
50 | 38 | return execute_only_pkey; |
---|
51 | 39 | } |
---|
52 | | - preempt_enable(); |
---|
53 | 40 | |
---|
54 | 41 | /* |
---|
55 | 42 | * Set up PKRU so that it denies access for everything |
---|
.. | .. |
---|
75 | 62 | static inline bool vma_is_pkey_exec_only(struct vm_area_struct *vma) |
---|
76 | 63 | { |
---|
77 | 64 | /* 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) |
---|
79 | 66 | return false; |
---|
80 | 67 | if (vma_pkey(vma) != vma->vm_mm->context.execute_only_pkey) |
---|
81 | 68 | return false; |
---|
.. | .. |
---|
146 | 133 | void copy_init_pkru_to_fpregs(void) |
---|
147 | 134 | { |
---|
148 | 135 | 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; |
---|
156 | 136 | /* |
---|
157 | 137 | * Override the PKRU state that came from 'init_fpstate' |
---|
158 | 138 | * with the baseline from the process. |
---|