Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Remove lockless reads of 'xc_donep'. This is an uin...



details:   https://anonhg.NetBSD.org/src/rev/348d3865b89a
branches:  trunk
changeset: 1004717:348d3865b89a
user:      maxv <maxv%NetBSD.org@localhost>
date:      Mon Nov 11 09:50:11 2019 +0000

description:
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.

diffstat:

 sys/kern/subr_xcall.c |  13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)

diffs (48 lines):

diff -r b6454a98d663 -r 348d3865b89a sys/kern/subr_xcall.c
--- a/sys/kern/subr_xcall.c     Mon Nov 11 09:24:56 2019 +0000
+++ b/sys/kern/subr_xcall.c     Mon Nov 11 09:50:11 2019 +0000
@@ -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 = &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 @@
         * 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 @@
         * 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);
        }



Home | Main Index | Thread Index | Old Index