Merge tag 'riscv-for-linus-6.9-mw2' of git://git.kernel.org/pub/scm/linux/kernel...
[sfrench/cifs-2.6.git] / kernel / sched / membarrier.c
index 4e715b9b278e7fd7fbea70110f5a829635a4bc01..809194cd779f42fa57759b731c52685a14744f83 100644 (file)
@@ -254,7 +254,7 @@ static int membarrier_global_expedited(void)
                return 0;
 
        /*
-        * Matches memory barriers around rq->curr modification in
+        * Matches memory barriers after rq->curr modification in
         * scheduler.
         */
        smp_mb();       /* system call entry is not a mb. */
@@ -304,7 +304,7 @@ static int membarrier_global_expedited(void)
 
        /*
         * Memory barrier on the caller thread _after_ we finished
-        * waiting for the last IPI. Matches memory barriers around
+        * waiting for the last IPI. Matches memory barriers before
         * rq->curr modification in scheduler.
         */
        smp_mb();       /* exit from system call is not a mb */
@@ -324,6 +324,7 @@ static int membarrier_private_expedited(int flags, int cpu_id)
                      MEMBARRIER_STATE_PRIVATE_EXPEDITED_SYNC_CORE_READY))
                        return -EPERM;
                ipi_func = ipi_sync_core;
+               prepare_sync_core_cmd(mm);
        } else if (flags == MEMBARRIER_FLAG_RSEQ) {
                if (!IS_ENABLED(CONFIG_RSEQ))
                        return -EINVAL;
@@ -343,8 +344,12 @@ static int membarrier_private_expedited(int flags, int cpu_id)
                return 0;
 
        /*
-        * Matches memory barriers around rq->curr modification in
+        * Matches memory barriers after rq->curr modification in
         * scheduler.
+        *
+        * On RISC-V, this barrier pairing is also needed for the
+        * SYNC_CORE command when switching between processes, cf.
+        * the inline comments in membarrier_arch_switch_mm().
         */
        smp_mb();       /* system call entry is not a mb. */
 
@@ -420,7 +425,7 @@ out:
 
        /*
         * Memory barrier on the caller thread _after_ we finished
-        * waiting for the last IPI. Matches memory barriers around
+        * waiting for the last IPI. Matches memory barriers before
         * rq->curr modification in scheduler.
         */
        smp_mb();       /* exit from system call is not a mb */