Pull thread_info flag accessor helper updates from Borislav Petkov: "Add a set of thread_info.flags accessors which snapshot it before accesing it in order to prevent any potential data races, and convert all users to those new accessors" * tag 'core_entry_for_v5.17_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: powerpc: Snapshot thread flags powerpc: Avoid discarding flags in system_call_exception() openrisc: Snapshot thread flags microblaze: Snapshot thread flags arm64: Snapshot thread flags ARM: Snapshot thread flags alpha: Snapshot thread flags sched: Snapshot thread flags entry: Snapshot thread flags x86: Snapshot thread flags thread_info: Add helpers to snapshot thread flags
Showing the changes to include (2 of 19 files). Show all
Unified · Split
| @@ -75,7 +75,7 @@ static inline void xfer_to_guest_mode_prepare(void) · 74 unmodified lines | ||
| 75 | 75 | */ |
| 76 | 76 | static inline bool __xfer_to_guest_mode_work_pending(void) |
| 77 | 77 | { |
| 78 | − unsigned long ti_work = READ_ONCE(current_thread_info()->flags); | |
| 78 | + unsigned long ti_work = read_thread_flags(); | |
| 79 | 79 | |
| 80 | 80 | return !!(ti_work & XFER_TO_GUEST_MODE_WORK); |
| 81 | 81 | } |
| @@ -118,6 +118,15 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag) · 117 unmodified lines | ||
| 118 | 118 | return test_bit(flag, (unsigned long *)&ti->flags); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | +/* | |
| 122 | + * This may be used in noinstr code, and needs to be __always_inline to prevent | |
| 123 | + * inadvertent instrumentation. | |
| 124 | + */ | |
| 125 | +static __always_inline unsigned long read_ti_thread_flags(struct thread_info *ti) | |
| 126 | +{ | |
| 127 | + return READ_ONCE(ti->flags); | |
| 128 | +} | |
| 129 | + | |
| 121 | 130 | #define set_thread_flag(flag) \ |
| 122 | 131 | set_ti_thread_flag(current_thread_info(), flag) |
| 123 | 132 | #define clear_thread_flag(flag) \ |
| @@ -130,6 +139,11 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag) · 6 unmodified lines | ||
| 130 | 139 | test_and_clear_ti_thread_flag(current_thread_info(), flag) |
| 131 | 140 | #define test_thread_flag(flag) \ |
| 132 | 141 | test_ti_thread_flag(current_thread_info(), flag) |
| 142 | +#define read_thread_flags() \ | |
| 143 | + read_ti_thread_flags(current_thread_info()) | |
| 144 | + | |
| 145 | +#define read_task_thread_flags(t) \ | |
| 146 | + read_ti_thread_flags(task_thread_info(t)) | |
| 133 | 147 | |
| 134 | 148 | #ifdef CONFIG_GENERIC_ENTRY |
| 135 | 149 | #define set_syscall_work(fl) \ |