mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 21:57:43 +00:00
e3c1d51868
commita493d1ca1a
upstream. sync_core_before_usermode() had an incorrect optimization. If the kernel returns from an interrupt, it can get to usermode without IRET. It just has to schedule to a different task in the same mm and do SYSRET. Fortunately, there were no callers of sync_core_before_usermode() that could have had in_irq() or in_nmi() equal to true, because it's only ever called from the scheduler. While at it, clarify a related comment. Fixes:70216e18e5
("membarrier: Provide core serializing command, *_SYNC_CORE") Signed-off-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/5afc7632be1422f91eaf7611aaaa1b5b8580a086.1607058304.git.luto@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
29 lines
894 B
C
29 lines
894 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _ASM_X86_SYNC_CORE_H
|
|
#define _ASM_X86_SYNC_CORE_H
|
|
|
|
#include <linux/preempt.h>
|
|
#include <asm/processor.h>
|
|
#include <asm/cpufeature.h>
|
|
|
|
/*
|
|
* Ensure that a core serializing instruction is issued before returning
|
|
* to user-mode. x86 implements return to user-space through sysexit,
|
|
* sysrel, and sysretq, which are not core serializing.
|
|
*/
|
|
static inline void sync_core_before_usermode(void)
|
|
{
|
|
/* With PTI, we unconditionally serialize before running user code. */
|
|
if (static_cpu_has(X86_FEATURE_PTI))
|
|
return;
|
|
|
|
/*
|
|
* Even if we're in an interrupt, we might reschedule before returning,
|
|
* in which case we could switch to a different thread in the same mm
|
|
* and return using SYSRET or SYSEXIT. Instead of trying to keep
|
|
* track of our need to sync the core, just sync right away.
|
|
*/
|
|
sync_core();
|
|
}
|
|
|
|
#endif /* _ASM_X86_SYNC_CORE_H */
|