~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/riscv/include/asm/membarrier.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-only */
  2 #ifndef _ASM_RISCV_MEMBARRIER_H
  3 #define _ASM_RISCV_MEMBARRIER_H
  4 
  5 static inline void membarrier_arch_switch_mm(struct mm_struct *prev,
  6                                              struct mm_struct *next,
  7                                              struct task_struct *tsk)
  8 {
  9         /*
 10          * Only need the full barrier when switching between processes.
 11          * Barrier when switching from kernel to userspace is not
 12          * required here, given that it is implied by mmdrop(). Barrier
 13          * when switching from userspace to kernel is not needed after
 14          * store to rq->curr.
 15          */
 16         if (IS_ENABLED(CONFIG_SMP) &&
 17             likely(!(atomic_read(&next->membarrier_state) &
 18                      (MEMBARRIER_STATE_PRIVATE_EXPEDITED |
 19                       MEMBARRIER_STATE_GLOBAL_EXPEDITED)) || !prev))
 20                 return;
 21 
 22         /*
 23          * The membarrier system call requires a full memory barrier
 24          * after storing to rq->curr, before going back to user-space.
 25          *
 26          * This barrier is also needed for the SYNC_CORE command when
 27          * switching between processes; in particular, on a transition
 28          * from a thread belonging to another mm to a thread belonging
 29          * to the mm for which a membarrier SYNC_CORE is done on CPU0:
 30          *
 31          *   - [CPU0] sets all bits in the mm icache_stale_mask (in
 32          *     prepare_sync_core_cmd());
 33          *
 34          *   - [CPU1] stores to rq->curr (by the scheduler);
 35          *
 36          *   - [CPU0] loads rq->curr within membarrier and observes
 37          *     cpu_rq(1)->curr->mm != mm, so the IPI is skipped on
 38          *     CPU1; this means membarrier relies on switch_mm() to
 39          *     issue the sync-core;
 40          *
 41          *   - [CPU1] switch_mm() loads icache_stale_mask; if the bit
 42          *     is zero, switch_mm() may incorrectly skip the sync-core.
 43          *
 44          * Matches a full barrier in the proximity of the membarrier
 45          * system call entry.
 46          */
 47         smp_mb();
 48 }
 49 
 50 #endif /* _ASM_RISCV_MEMBARRIER_H */
 51 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php