Module Name:    src
Committed By:   maxv
Date:           Mon Nov 11 09:50:11 UTC 2019

Modified Files:
        src/sys/kern: subr_xcall.c

Log Message:
Remove lockless reads of 'xc_donep'. This is an uint64_t, and we cannot
expect the accesses to be MP-safe on 32bit arches.

Found by KCSAN.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/kern/subr_xcall.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_xcall.c
diff -u src/sys/kern/subr_xcall.c:1.27 src/sys/kern/subr_xcall.c:1.28
--- src/sys/kern/subr_xcall.c:1.27	Sun Oct  6 15:11:17 2019
+++ src/sys/kern/subr_xcall.c	Mon Nov 11 09:50:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_xcall.c,v 1.27 2019/10/06 15:11:17 uwe Exp $	*/
+/*	$NetBSD: subr_xcall.c,v 1.28 2019/11/11 09:50:11 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2007-2010 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_xcall.c,v 1.27 2019/10/06 15:11:17 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_xcall.c,v 1.28 2019/11/11 09:50:11 maxv Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -334,12 +334,7 @@ xc_wait(uint64_t where)
 		xc = &xc_low_pri;
 	}
 
-	/* Fast path, if already done. */
-	if (xc->xc_donep >= where) {
-		return;
-	}
-
-	/* Slow path: block until awoken. */
+	/* Block until awoken. */
 	mutex_enter(&xc->xc_lock);
 	while (xc->xc_donep < where) {
 		cv_wait(&xc->xc_busy, &xc->xc_lock);
@@ -462,7 +457,6 @@ xc__highpri_intr(void *dummy)
 	 * Lock-less fetch of function and its arguments.
 	 * Safe since it cannot change at this point.
 	 */
-	KASSERT(xc->xc_donep < xc->xc_headp);
 	func = xc->xc_func;
 	arg1 = xc->xc_arg1;
 	arg2 = xc->xc_arg2;
@@ -475,6 +469,7 @@ xc__highpri_intr(void *dummy)
 	 * cross-call has been processed - notify waiters, if any.
 	 */
 	mutex_enter(&xc->xc_lock);
+	KASSERT(xc->xc_donep < xc->xc_headp);
 	if (++xc->xc_donep == xc->xc_headp) {
 		cv_broadcast(&xc->xc_busy);
 	}

Reply via email to