Source-Changes-HG archive

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

[src/trunk]: src/sys/rump PR/55664: Ruslan Nikolaev: Fix:



details:   https://anonhg.NetBSD.org/src/rev/200ab4d86977
branches:  trunk
changeset: 977802:200ab4d86977
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Nov 01 20:58:38 2020 +0000

description:
PR/55664: Ruslan Nikolaev: Fix:

1. A race condition (bug) in sys/rump/librump/rumpkern/intr.c since
   rumpuser_cv_signal() is called without holding a mutex
2. sleepq is implemented using a single (global) conditional
   variable; that should be done per each sleepq separately

diffstat:

 sys/rump/include/rump-sys/kern.h      |   3 +-
 sys/rump/include/sys/sleeptab.h       |  40 +++++++++++++++++++++++++++++++++++
 sys/rump/librump/rumpkern/intr.c      |   6 ++--
 sys/rump/librump/rumpkern/scheduler.c |  14 ++++++++++-
 sys/rump/librump/rumpkern/sleepq.c    |  31 +++++++++++---------------
 5 files changed, 70 insertions(+), 24 deletions(-)

diffs (202 lines):

diff -r 20524b7e295b -r 200ab4d86977 sys/rump/include/rump-sys/kern.h
--- a/sys/rump/include/rump-sys/kern.h  Sun Nov 01 20:56:24 2020 +0000
+++ b/sys/rump/include/rump-sys/kern.h  Sun Nov 01 20:58:38 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern.h,v 1.4 2018/08/10 21:44:59 pgoyette Exp $        */
+/*     $NetBSD: kern.h,v 1.5 2020/11/01 20:58:38 christos Exp $        */
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -174,6 +174,7 @@
 void   rump_schedlock_cv_wait(struct rumpuser_cv *);
 int    rump_schedlock_cv_timedwait(struct rumpuser_cv *,
                                    const struct timespec *);
+void   rump_schedlock_cv_signal(struct cpu_info *, struct rumpuser_cv *);
 
 void   rump_user_schedule(int, void *);
 void   rump_user_unschedule(int, int *, void *);
diff -r 20524b7e295b -r 200ab4d86977 sys/rump/include/sys/sleeptab.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/include/sys/sleeptab.h   Sun Nov 01 20:58:38 2020 +0000
@@ -0,0 +1,40 @@
+/*     $NetBSD: sleeptab.h,v 1.1 2020/11/01 20:58:38 christos Exp $    */
+
+/*
+ * Copyright (c) 2020
+ *     The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef        _RUMP_SYS_SLEEPTAB_H_
+#define        _RUMP_SYS_SLEEPTAB_H_
+
+struct sleepq {
+       LIST_HEAD(, lwp);       /* anonymous struct */
+       kcondvar_t sq_cv;
+};
+
+void    sleepq_destroy(sleepq_t *); 
+
+#endif /* _RUMP_SYS_SLEEPTAB_H_ */
diff -r 20524b7e295b -r 200ab4d86977 sys/rump/librump/rumpkern/intr.c
--- a/sys/rump/librump/rumpkern/intr.c  Sun Nov 01 20:56:24 2020 +0000
+++ b/sys/rump/librump/rumpkern/intr.c  Sun Nov 01 20:58:38 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.55 2019/12/16 22:47:55 ad Exp $     */
+/*     $NetBSD: intr.c,v 1.56 2020/11/01 20:58:38 christos Exp $       */
 
 /*
  * Copyright (c) 2008-2010, 2015 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.55 2019/12/16 22:47:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.56 2020/11/01 20:58:38 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -464,7 +464,7 @@
 
        for (i = 0; i < SOFTINT_COUNT; i++) {
                if (!TAILQ_EMPTY(&si_lvl[i].si_pending))
-                       rumpuser_cv_signal(si_lvl[i].si_cv);
+                       rump_schedlock_cv_signal(ci, si_lvl[i].si_cv);
        }
 }
 
diff -r 20524b7e295b -r 200ab4d86977 sys/rump/librump/rumpkern/scheduler.c
--- a/sys/rump/librump/rumpkern/scheduler.c     Sun Nov 01 20:56:24 2020 +0000
+++ b/sys/rump/librump/rumpkern/scheduler.c     Sun Nov 01 20:58:38 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: scheduler.c,v 1.51 2020/03/14 18:08:39 ad Exp $       */
+/*      $NetBSD: scheduler.c,v 1.52 2020/11/01 20:58:38 christos Exp $ */
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.51 2020/03/14 18:08:39 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.52 2020/11/01 20:58:38 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -179,6 +179,16 @@
        mutex_init(&unruntime_lock, MUTEX_DEFAULT, IPL_SCHED);
 }
 
+void
+rump_schedlock_cv_signal(struct cpu_info *ci, struct rumpuser_cv *cv)
+{
+       struct rumpcpu *rcpu = cpuinfo_to_rumpcpu(ci);
+
+       rumpuser_mutex_enter_nowrap(rcpu->rcpu_mtx);
+       rumpuser_cv_signal(cv);
+       rumpuser_mutex_exit(rcpu->rcpu_mtx);
+}
+
 /*
  * condvar ops using scheduler lock as the rumpuser interlock.
  */
diff -r 20524b7e295b -r 200ab4d86977 sys/rump/librump/rumpkern/sleepq.c
--- a/sys/rump/librump/rumpkern/sleepq.c        Sun Nov 01 20:56:24 2020 +0000
+++ b/sys/rump/librump/rumpkern/sleepq.c        Sun Nov 01 20:58:38 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sleepq.c,v 1.20 2020/04/25 15:42:15 bouyer Exp $       */
+/*     $NetBSD: sleepq.c,v 1.21 2020/11/01 20:58:38 christos Exp $     */
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sleepq.c,v 1.20 2020/04/25 15:42:15 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sleepq.c,v 1.21 2020/11/01 20:58:38 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -40,25 +40,20 @@
 #include <rump-sys/kern.h>
 
 syncobj_t sleep_syncobj;
-static kcondvar_t sq_cv;
-
-static int
-sqinit1(void)
-{
-
-       cv_init(&sq_cv, "sleepq");
-
-       return 0;
-}
 
 void
 sleepq_init(sleepq_t *sq)
 {
-       static ONCE_DECL(sqctl);
-
-       RUN_ONCE(&sqctl, sqinit1);
 
        LIST_INIT(sq);
+       cv_init(&sq->sq_cv, "sleepq");
+}
+
+void
+sleepq_destroy(sleepq_t *sq)
+{
+
+       cv_destroy(&sq->sq_cv);
 }
 
 void
@@ -83,7 +78,7 @@
 
        while (l->l_wchan) {
                l->l_mutex = mp; /* keep sleepq lock until woken up */
-               error = cv_timedwait(&sq_cv, mp, timo);
+               error = cv_timedwait(&l->l_sleepq->sq_cv, mp, timo);
                if (error == EWOULDBLOCK || error == EINTR) {
                        if (l->l_wchan) {
                                LIST_REMOVE(l, l_sleepchain);
@@ -118,7 +113,7 @@
                }
        }
        if (found)
-               cv_broadcast(&sq_cv);
+               cv_broadcast(&sq->sq_cv);
 
        mutex_spin_exit(mp);
 }
@@ -130,7 +125,7 @@
        l->l_wchan = NULL;
        l->l_wmesg = NULL;
        LIST_REMOVE(l, l_sleepchain);
-       cv_broadcast(&sq_cv);
+       cv_broadcast(&l->l_sleepq->sq_cv);
 
        if (cleanup) {
                mutex_spin_exit(l->l_mutex);



Home | Main Index | Thread Index | Old Index