Module Name: src
Committed By: riastradh
Date: Thu Feb 23 14:56:12 UTC 2023
Modified Files:
src/sys/arch/powerpc/powerpc: locore_subr.S
Log Message:
powerpc: Add missing barriers in cpu_switchto.
Details in comments.
PR kern/57240
XXX pullup-8
XXX pullup-9
XXX pullup-10
To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/powerpc/powerpc/locore_subr.S
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/powerpc/powerpc/locore_subr.S
diff -u src/sys/arch/powerpc/powerpc/locore_subr.S:1.66 src/sys/arch/powerpc/powerpc/locore_subr.S:1.67
--- src/sys/arch/powerpc/powerpc/locore_subr.S:1.66 Wed Mar 16 09:48:23 2022
+++ src/sys/arch/powerpc/powerpc/locore_subr.S Thu Feb 23 14:56:11 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: locore_subr.S,v 1.66 2022/03/16 09:48:23 andvar Exp $ */
+/* $NetBSD: locore_subr.S,v 1.67 2023/02/23 14:56:11 riastradh Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -215,7 +215,32 @@ ENTRY(cpu_switchto)
*/
GET_CPUINFO(%r7)
+
+ /*
+ * Issue barriers to coordinate mutex_exit on this CPU with
+ * mutex_vector_enter on another CPU.
+ *
+ * 1. Any prior mutex_exit by oldlwp must be visible to other
+ * CPUs before we set ci_curlwp := newlwp on this one,
+ * requiring a store-before-store barrier.
+ *
+ * 2. ci_curlwp := newlwp must be visible on all other CPUs
+ * before any subsequent mutex_exit by newlwp can even test
+ * whether there might be waiters, requiring a
+ * store-before-load barrier.
+ *
+ * See kern_mutex.c for details -- this is necessary for
+ * adaptive mutexes to detect whether the lwp is on the CPU in
+ * order to safely block without requiring atomic r/m/w in
+ * mutex_exit.
+ */
+#ifdef MULTIPROCESSOR
+ sync /* store-before-store XXX use eieio if available -- cheaper */
+#endif
stptr %r31,CI_CURLWP(%r7)
+#ifdef MULTIPROCESSOR
+ sync /* store-before-load */
+#endif
mr %r13,%r31
#ifdef PPC_BOOKE
mtsprg2 %r31 /* save curlwp in sprg2 */
@@ -389,7 +414,13 @@ _ENTRY(softint_fast_dispatch)
* to a kernel thread
*/
+#ifdef MULTIPROCESSOR
+ sync /* XXX eieio */ /* for mutex_enter; see cpu_switchto */
+#endif
stptr %r3, CI_CURLWP(%r7)
+#ifdef MULTIPROCESSOR
+ sync /* for mutex_enter; see cpu_switchto */
+#endif
mr %r13, %r3
#ifdef PPC_BOOKE
mtsprg2 %r3
@@ -423,7 +454,13 @@ _ENTRY(softint_fast_dispatch)
#endif
GET_CPUINFO(%r7)
+#ifdef MULTIPROCESSOR
+ sync /* XXX eieio */ /* for mutex_enter; see cpu_switchto */
+#endif
stptr %r30, CI_CURLWP(%r7)
+#ifdef MULTIPROCESSOR
+ sync /* for mutex_enter; see cpu_switchto */
+#endif
mr %r13, %r30
#ifdef PPC_BOOKE
mtsprg2 %r30