Source-Changes-HG archive

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

[src/netbsd-8]: src/sys Pull up following revision(s) (requested by ozaki-r i...



details:   https://anonhg.NetBSD.org/src/rev/d4711ca72c0c
branches:  netbsd-8
changeset: 851328:d4711ca72c0c
user:      snj <snj%NetBSD.org@localhost>
date:      Sat Feb 03 22:07:26 2018 +0000

description:
Pull up following revision(s) (requested by ozaki-r in ticket #514):
        sys/net/route.c: 1.205
        sys/net/rtsock.c: 1.237-1.238
        sys/netinet/in.c: 1.215
        sys/netinet/tcp_subr.c: 1.272
        sys/netinet/tcp_timer.c: 1.93
        sys/netinet/tcp_timer.h: 1.29
        sys/netinet/tcp_var.h: 1.182
        sys/netinet6/in6.c: 1.258
Remove extra pserialize_perform from in_purgeaddr
It's already performed in ifa_remove. Note so there (in in6_unlink_ifa too).
Release rt_so_mtx on updating a rtentry to avoid a deadlock with route_intr
The deadlock happened only if NET_MPSAFE on.
Run tcp_slowtimo in workqueue if NET_MPSAFE
If NET_MPSAFE is enabled, we have to avoid taking softnet_lock in softint as
much as possible to prevent any softint handlers including callout handlers
such as tcp_slowtimo from sticking on softnet_lock because it results in
undesired delays of executing subsequent softint handlers.
NFCI for !NET_MPSAFE
Fix a return value of rt_update_prepare
Callers expect it to be an errno.
Fix another deadlock
When waiting for a route update to finish, a waiter has to release its reference
to the route to avoid a deadlock. Because a updater tries to wait for references
to a target route (except for a reference by the updater itself) to be released.

diffstat:

 sys/net/route.c         |   6 +++---
 sys/net/rtsock.c        |  36 ++++++++++++++++++++++++++++++++++--
 sys/netinet/in.c        |   8 +++-----
 sys/netinet/tcp_subr.c  |   9 +++------
 sys/netinet/tcp_timer.c |  46 ++++++++++++++++++++++++++++++++++++++++++----
 sys/netinet/tcp_timer.h |   3 ++-
 sys/netinet/tcp_var.h   |   4 +---
 sys/netinet6/in6.c      |   5 +++--
 8 files changed, 91 insertions(+), 26 deletions(-)

diffs (truncated from 336 to 300 lines):

diff -r fda430895d3d -r d4711ca72c0c sys/net/route.c
--- a/sys/net/route.c   Sat Feb 03 22:02:02 2018 +0000
+++ b/sys/net/route.c   Sat Feb 03 22:07:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: route.c,v 1.194.6.4 2018/01/13 22:10:55 snj Exp $      */
+/*     $NetBSD: route.c,v 1.194.6.5 2018/02/03 22:07:26 snj 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.6.4 2018/01/13 22:10:55 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194.6.5 2018/02/03 22:07:26 snj Exp $");
 
 #include <sys/param.h>
 #ifdef RTFLUSH_DEBUG
@@ -747,7 +747,7 @@
        /* If the entry is being destroyed, don't proceed the update. */
        if (!ISSET(rt->rt_flags, RTF_UP)) {
                RT_UNLOCK();
-               return -1;
+               return ESRCH;
        }
        rt->rt_flags |= RTF_UPDATING;
        RT_UNLOCK();
diff -r fda430895d3d -r d4711ca72c0c sys/net/rtsock.c
--- a/sys/net/rtsock.c  Sat Feb 03 22:02:02 2018 +0000
+++ b/sys/net/rtsock.c  Sat Feb 03 22:07:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsock.c,v 1.213.2.5 2018/01/02 10:30:10 snj Exp $     */
+/*     $NetBSD: rtsock.c,v 1.213.2.6 2018/02/03 22:07:26 snj Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.5 2018/01/02 10:30:10 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.6 2018/02/03 22:07:26 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -82,6 +82,7 @@
 #include <sys/kauth.h>
 #include <sys/kmem.h>
 #include <sys/intr.h>
+#include <sys/condvar.h>
 
 #include <net/if.h>
 #include <net/if_llatbl.h>
@@ -187,6 +188,9 @@
 static struct rawcbhead rt_rawcb;
 #ifdef NET_MPSAFE
 static kmutex_t *rt_so_mtx;
+
+static bool rt_updating = false;
+static kcondvar_t rt_update_cv;
 #endif
 
 static void
@@ -1002,11 +1006,37 @@
 
                case RTM_CHANGE:
 #ifdef NET_MPSAFE
+                       /*
+                        * Release rt_so_mtx to avoid a deadlock with route_intr
+                        * and also serialize updating routes to avoid another.
+                        */
+                       if (rt_updating) {
+                               /* Release to allow the updater to proceed */
+                               rt_unref(rt);
+                               rt = NULL;
+                       }
+                       while (rt_updating) {
+                               error = cv_wait_sig(&rt_update_cv, rt_so_mtx);
+                               if (error != 0)
+                                       goto flush;
+                       }
+                       if (rt == NULL) {
+                               error = rtrequest1(RTM_GET, &info, &rt);
+                               if (error != 0)
+                                       goto flush;
+                       }
+                       rt_updating = true;
+                       mutex_exit(rt_so_mtx);
+
                        error = rt_update_prepare(rt);
                        if (error == 0) {
                                error = route_output_change(rt, &info, rtm);
                                rt_update_finish(rt);
                        }
+
+                       mutex_enter(rt_so_mtx);
+                       rt_updating = false;
+                       cv_broadcast(&rt_update_cv);
 #else
                        error = route_output_change(rt, &info, rtm);
 #endif
@@ -2105,6 +2135,8 @@
 #endif
 #ifdef NET_MPSAFE
        rt_so_mtx = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
+
+       cv_init(&rt_update_cv, "rtsock_cv");
 #endif
 
        sysctl_net_route_setup(NULL);
diff -r fda430895d3d -r d4711ca72c0c sys/netinet/in.c
--- a/sys/netinet/in.c  Sat Feb 03 22:02:02 2018 +0000
+++ b/sys/netinet/in.c  Sat Feb 03 22:07:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in.c,v 1.203.2.6 2018/01/13 05:45:06 snj Exp $ */
+/*     $NetBSD: in.c,v 1.203.2.7 2018/02/03 22:07:26 snj Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.203.2.6 2018/01/13 05:45:06 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.203.2.7 2018/02/03 22:07:26 snj Exp $");
 
 #include "arp.h"
 
@@ -855,9 +855,7 @@
        TAILQ_REMOVE(&in_ifaddrhead, ia, ia_list);
        IN_ADDRLIST_WRITER_REMOVE(ia);
        ifa_remove(ifp, &ia->ia_ifa);
-#ifdef NET_MPSAFE
-       pserialize_perform(in_ifaddrhash_psz);
-#endif
+       /* Assume ifa_remove called pserialize_perform and psref_destroy */
        mutex_exit(&in_ifaddr_lock);
        IN_ADDRHASH_ENTRY_DESTROY(ia);
        IN_ADDRLIST_ENTRY_DESTROY(ia);
diff -r fda430895d3d -r d4711ca72c0c sys/netinet/tcp_subr.c
--- a/sys/netinet/tcp_subr.c    Sat Feb 03 22:02:02 2018 +0000
+++ b/sys/netinet/tcp_subr.c    Sat Feb 03 22:07:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_subr.c,v 1.270 2017/03/03 07:13:06 ozaki-r Exp $   */
+/*     $NetBSD: tcp_subr.c,v 1.270.6.1 2018/02/03 22:07:26 snj Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.270 2017/03/03 07:13:06 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.270.6.1 2018/02/03 22:07:26 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -388,8 +388,6 @@
 struct mowner tcp_sock_tx_mowner = MOWNER_INIT("tcp", "sock tx");
 #endif
 
-callout_t tcp_slowtimo_ch;
-
 static int
 do_tcpinit(void)
 {
@@ -430,8 +428,7 @@
 
        vtw_earlyinit();
 
-       callout_init(&tcp_slowtimo_ch, CALLOUT_MPSAFE);
-       callout_reset(&tcp_slowtimo_ch, 1, tcp_slowtimo, NULL);
+       tcp_slowtimo_init();
 
        return 0;
 }
diff -r fda430895d3d -r d4711ca72c0c sys/netinet/tcp_timer.c
--- a/sys/netinet/tcp_timer.c   Sat Feb 03 22:02:02 2018 +0000
+++ b/sys/netinet/tcp_timer.c   Sat Feb 03 22:07:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_timer.c,v 1.91 2016/07/25 00:10:38 knakahara Exp $ */
+/*     $NetBSD: tcp_timer.c,v 1.91.8.1 2018/02/03 22:07:26 snj Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,11 +93,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.91 2016/07/25 00:10:38 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.91.8.1 2018/02/03 22:07:26 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
 #include "opt_tcp_debug.h"
+#include "opt_net_mpsafe.h"
 #endif
 
 #include <sys/param.h>
@@ -108,6 +109,8 @@
 #include <sys/protosw.h>
 #include <sys/errno.h>
 #include <sys/kernel.h>
+#include <sys/callout.h>
+#include <sys/workqueue.h>
 
 #include <net/if.h>
 
@@ -149,6 +152,15 @@
 
 int    tcp_maxpersistidle = 0;         /* max idle time in persist */
 
+static callout_t       tcp_slowtimo_ch;
+#ifdef NET_MPSAFE
+static struct workqueue        *tcp_slowtimo_wq;
+static struct work     tcp_slowtimo_wk;
+#endif
+
+static void tcp_slowtimo_work(struct work *, void *);
+static void tcp_slowtimo(void *);
+
 /*
  * Time to delay the ACK.  This is initialized in tcp_init(), unless
  * its patched.
@@ -193,6 +205,21 @@
                tcp_delack_ticks = TCP_DELACK_TICKS;
 }
 
+void
+tcp_slowtimo_init(void)
+{
+#ifdef NET_MPSAFE
+       int error;
+
+       error = workqueue_create(&tcp_slowtimo_wq, "tcp_slowtimo",
+           tcp_slowtimo_work, NULL, PRI_SOFTNET, IPL_SOFTNET, WQ_MPSAFE);
+       if (error != 0)
+               panic("%s: workqueue_create failed (%d)\n", __func__, error);
+#endif
+       callout_init(&tcp_slowtimo_ch, CALLOUT_MPSAFE);
+       callout_reset(&tcp_slowtimo_ch, 1, tcp_slowtimo, NULL);
+}
+
 /*
  * Callout to process delayed ACKs for a TCPCB.
  */
@@ -229,8 +256,8 @@
  * Updates the timers in all active tcb's and
  * causes finite state machine actions if timers expire.
  */
-void
-tcp_slowtimo(void *arg)
+static void
+tcp_slowtimo_work(struct work *wk, void *arg)
 {
 
        mutex_enter(softnet_lock);
@@ -241,6 +268,17 @@
        callout_schedule(&tcp_slowtimo_ch, hz / PR_SLOWHZ);
 }
 
+static void
+tcp_slowtimo(void *arg)
+{
+
+#ifdef NET_MPSAFE
+       workqueue_enqueue(tcp_slowtimo_wq, &tcp_slowtimo_wk, NULL);
+#else
+       tcp_slowtimo_work(NULL, NULL);
+#endif
+}
+
 /*
  * Cancel all timers for TCP tp.
  */
diff -r fda430895d3d -r d4711ca72c0c sys/netinet/tcp_timer.h
--- a/sys/netinet/tcp_timer.h   Sat Feb 03 22:02:02 2018 +0000
+++ b/sys/netinet/tcp_timer.h   Sat Feb 03 22:07:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_timer.h,v 1.28 2011/05/24 18:37:52 gdt Exp $       */
+/*     $NetBSD: tcp_timer.h,v 1.28.48.1 2018/02/03 22:07:26 snj Exp $  */
 
 /*-
  * Copyright (c) 2001, 2005 The NetBSD Foundation, Inc.
@@ -190,6 +190,7 @@
 extern const int tcp_backoff[];
 
 void   tcp_timer_init(void);
+void   tcp_slowtimo_init(void);
 #endif
 
 #endif /* !_NETINET_TCP_TIMER_H_ */
diff -r fda430895d3d -r d4711ca72c0c sys/netinet/tcp_var.h
--- a/sys/netinet/tcp_var.h     Sat Feb 03 22:02:02 2018 +0000
+++ b/sys/netinet/tcp_var.h     Sat Feb 03 22:07:26 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_var.h,v 1.177.10.1 2017/10/21 19:43:54 snj Exp $   */
+/*     $NetBSD: tcp_var.h,v 1.177.10.2 2018/02/03 22:07:26 snj Exp $   */
 
 /*



Home | Main Index | Thread Index | Old Index