Source-Changes-HG archive

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

[src/trunk]: src/sys/net Fix locking in rtalloc1 (affected only if NET_MPSAFE)



details:   https://anonhg.NetBSD.org/src/rev/25d44d8e8023
branches:  trunk
changeset: 824873:25d44d8e8023
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Jun 22 08:31:54 2017 +0000

description:
Fix locking in rtalloc1 (affected only if NET_MPSAFE)

diffstat:

 sys/net/route.c |  19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diffs (75 lines):

diff -r 930f49e82294 -r 25d44d8e8023 sys/net/route.c
--- a/sys/net/route.c   Thu Jun 22 08:10:29 2017 +0000
+++ b/sys/net/route.c   Thu Jun 22 08:31:54 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: route.c,v 1.194 2017/03/24 03:45:02 ozaki-r Exp $      */
+/*     $NetBSD: route.c,v 1.195 2017/06/22 08:31:54 ozaki-r Exp $      */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194 2017/03/24 03:45:02 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.195 2017/06/22 08:31:54 ozaki-r Exp $");
 
 #include <sys/param.h>
 #ifdef RTFLUSH_DEBUG
@@ -280,7 +280,7 @@
 static void rt_ref(struct rtentry *);
 
 static struct rtentry *
-    rtalloc1_locked(const struct sockaddr *, int, bool);
+    rtalloc1_locked(const struct sockaddr *, int, bool, bool);
 static struct rtentry *
     rtcache_validate_locked(struct route *);
 static void rtcache_free_locked(struct route *);
@@ -557,7 +557,8 @@
  * will be incremented. The caller has to rtfree it by itself.
  */
 struct rtentry *
-rtalloc1_locked(const struct sockaddr *dst, int report, bool wait_ok)
+rtalloc1_locked(const struct sockaddr *dst, int report, bool wait_ok,
+    bool wlock)
 {
        rtbl_t *rtbl;
        struct rtentry *rt;
@@ -599,6 +600,10 @@
 
                if (need_lock)
                        RTCACHE_WLOCK();
+               if (wlock)
+                       RT_WLOCK();
+               else
+                       RT_RLOCK();
                goto retry;
        }
 #endif /* NET_MPSAFE */
@@ -627,7 +632,7 @@
        struct rtentry *rt;
 
        RT_RLOCK();
-       rt = rtalloc1_locked(dst, report, true);
+       rt = rtalloc1_locked(dst, report, true, false);
        RT_UNLOCK();
 
        return rt;
@@ -1026,7 +1031,7 @@
 
                /* XXX we cannot call rtalloc1 if holding the rt lock */
                if (RT_LOCKED())
-                       rt = rtalloc1_locked(gateway, 0, true);
+                       rt = rtalloc1_locked(gateway, 0, true, true);
                else
                        rt = rtalloc1(gateway, 0);
                if (rt == NULL)
@@ -1387,7 +1392,7 @@
 
                /* XXX we cannot call rtalloc1 if holding the rt lock */
                if (RT_LOCKED())
-                       gwrt = rtalloc1_locked(gate, 1, false);
+                       gwrt = rtalloc1_locked(gate, 1, false, true);
                else
                        gwrt = rtalloc1(gate, 1);
                /*



Home | Main Index | Thread Index | Old Index