-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
membarrier: riscv: Add full memory barrier in switch_mm()
BugLink: https://bugs.launchpad.net/bugs/2085849 commit d6cfd17 upstream. The membarrier system call requires a full memory barrier after storing to rq->curr, before going back to user-space. The barrier is only needed when switching between processes: the barrier is implied by mmdrop() when switching from kernel to userspace, and it's not needed when switching from userspace to kernel. Rely on the feature/mechanism ARCH_HAS_MEMBARRIER_CALLBACKS and on the primitive membarrier_arch_switch_mm(), already adopted by the PowerPC architecture, to insert the required barrier. Fixes: fab957c ("RISC-V: Atomic and Locking Code") Signed-off-by: Andrea Parri <[email protected]> Reviewed-by: Mathieu Desnoyers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]> Signed-off-by: WangYuli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Manuel Diewald <[email protected]> Signed-off-by: Roxana Nicolescu <[email protected]>
- Loading branch information
Showing
5 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14067,7 +14067,7 @@ M: Mathieu Desnoyers <[email protected]> | |
M: "Paul E. McKenney" <[email protected]> | ||
L: [email protected] | ||
S: Supported | ||
F: arch/powerpc/include/asm/membarrier.h | ||
F: arch/*/include/asm/membarrier.h | ||
F: include/uapi/linux/membarrier.h | ||
F: kernel/sched/membarrier.c | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
#ifndef _ASM_RISCV_MEMBARRIER_H | ||
#define _ASM_RISCV_MEMBARRIER_H | ||
|
||
static inline void membarrier_arch_switch_mm(struct mm_struct *prev, | ||
struct mm_struct *next, | ||
struct task_struct *tsk) | ||
{ | ||
/* | ||
* Only need the full barrier when switching between processes. | ||
* Barrier when switching from kernel to userspace is not | ||
* required here, given that it is implied by mmdrop(). Barrier | ||
* when switching from userspace to kernel is not needed after | ||
* store to rq->curr. | ||
*/ | ||
if (IS_ENABLED(CONFIG_SMP) && | ||
likely(!(atomic_read(&next->membarrier_state) & | ||
(MEMBARRIER_STATE_PRIVATE_EXPEDITED | | ||
MEMBARRIER_STATE_GLOBAL_EXPEDITED)) || !prev)) | ||
return; | ||
|
||
/* | ||
* The membarrier system call requires a full memory barrier | ||
* after storing to rq->curr, before going back to user-space. | ||
* Matches a full barrier in the proximity of the membarrier | ||
* system call entry. | ||
*/ | ||
smp_mb(); | ||
} | ||
|
||
#endif /* _ASM_RISCV_MEMBARRIER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters