GNU Linux-libre 4.19.286-gnu1
[releases.git] / arch / x86 / include / asm / sync_core.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_SYNC_CORE_H
3 #define _ASM_X86_SYNC_CORE_H
4
5 #include <linux/preempt.h>
6 #include <asm/processor.h>
7 #include <asm/cpufeature.h>
8
9 /*
10  * Ensure that a core serializing instruction is issued before returning
11  * to user-mode. x86 implements return to user-space through sysexit,
12  * sysrel, and sysretq, which are not core serializing.
13  */
14 static inline void sync_core_before_usermode(void)
15 {
16         /* With PTI, we unconditionally serialize before running user code. */
17         if (static_cpu_has(X86_FEATURE_PTI))
18                 return;
19
20         /*
21          * Even if we're in an interrupt, we might reschedule before returning,
22          * in which case we could switch to a different thread in the same mm
23          * and return using SYSRET or SYSEXIT.  Instead of trying to keep
24          * track of our need to sync the core, just sync right away.
25          */
26         sync_core();
27 }
28
29 #endif /* _ASM_X86_SYNC_CORE_H */