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 knakahara...



details:   https://anonhg.NetBSD.org/src/rev/b0cd7db2c251
branches:  netbsd-8
changeset: 454673:b0cd7db2c251
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Sep 24 18:27:09 2019 +0000

description:
Pull up following revision(s) (requested by knakahara in ticket #1385):

        sys/net/if.c                            1.461
        sys/net/if.h                            1.277
        sys/net/if_gif.c                        1.149
        sys/net/if_gif.h                        1.33
        sys/net/if_ipsec.c                      1.19,1.20,1.24
        sys/net/if_ipsec.h                      1.5
        sys/net/if_l2tp.c                       1.33,1.36-1.39
        sys/net/if_l2tp.h                       1.7,1.8
        sys/net/route.c                         1.220,1.221
        sys/net/route.h                         1.125
        sys/netinet/in_gif.c                    1.95
        sys/netinet/in_l2tp.c                   1.17
        sys/netinet/ip_input.c                  1.391,1.392
        sys/netinet/wqinput.c                   1.6
        sys/netinet6/in6_gif.c                  1.94
        sys/netinet6/in6_l2tp.c                 1.18
        sys/netinet6/ip6_forward.c              1.97
        sys/netinet6/ip6_input.c                1.210,1.211
        sys/netipsec/ipsec_output.c             1.82,1.83 (patched)
        sys/netipsec/ipsecif.c                  1.12,1.13,1.15,1.17 (patched)
        sys/netipsec/key.c                      1.259,1.260

ipsecif(4) support input drop packet counter.

ipsecif(4) should not increment drop counter by errors not related to if_snd. Pointed out by ozaki-r@n.o, thanks.
Remove unnecessary addresses in PF_KEY message.

MOBIKE Extensions for PF_KEY draft-schilcher-mobike-pfkey-extension-01.txt says
====================
5.  SPD Update
// snip
   SADB_X_SPDADD:
// snip
      sadb_x_ipsecrequest_reqid:
         An ID for that SA can be passed to the kernel in the
         sadb_x_ipsecrequest_reqid field.
      If tunnel mode is specified, the sadb_x_ipsecrequest structure is
      followed by two sockaddr structures that define the tunnel
      endpoint addresses.  In the case that transport mode is used, no
      additional addresses are specified.
====================
see: <a  rel="nofollow" href="https://tools.ietf.org/html/draft-schilcher-mobike-pfkey-extension-01";>https://tools.ietf.org/html/draft-schilcher-mobike-pfkey-extension-01</a>

ipsecif(4) uses transport mode, so it should not add addresses.

ipsecif(4) supports multiple peers in the same NAPT.

E.g. ipsec0 connects between NetBSD_A and NetBSD_B, ipsec1 connects
NetBSD_A and NetBSD_C at the following figure.
                                        +----------+
                                   +----| NetBSD_B |
 +----------+           +------+   |    +----------+
 | NetBSD_A |--- ... ---| NAPT |---+
 +----------+           +------+   |    +----------+
                                   +----| NetBSD_C |
                                        +----------+

Add ATF later.

l2tp(4): fix output bytes counter. Pointed by k-goda@IIJ, thanks.
remove a variable which is no longer used.

l2tp: initialize mowner variables for MBUFTRACE

Avoid having a rtcache directly in a percpu storage
percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Using rtcache, i.e., packet processing, typically involves sleepable operations
such as rwlock so we must avoid dereferencing a rtcache that is directly stored
in a percpu storage during packet processing.  Address this situation by having
just a pointer to a rtcache in a percpu storage instead.

Reviewed by knakahara@ and yamaguchi@


wqinput: avoid having struct wqinput_worklist directly in a percpu storage
percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.

A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Input handlers of wqinput normally involves sleepable operations so we must
avoid dereferencing a percpu data (struct wqinput_worklist) after executing
an input handler.  Address this situation by having just a pointer to the data
in a percpu storage instead.

Reviewed by knakahara@ and yamaguchi@

Add missing #include <sys/kmem.h>

Divide Tx context of l2tp(4) to improve performance.
It seems l2tp(4) call path is too long for instruction cache. So, dividing
l2tp(4) Tx context improves CPU use efficiency.

After this commit, l2tp(4) throughput gains 10% on my machine(Atom C3000).

Apply some missing changes lost on the previous commit

Avoid having a rtcache directly in a percpu storage for tunnel protocols.
percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Using rtcache, i.e., packet processing, typically involves sleepable operations
such as rwlock so we must avoid dereferencing a rtcache that is directly stored
in a percpu storage during packet processing.  Address this situation by having
just a pointer to a rtcache in a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@

l2tp(4): avoid having struct ifqueue directly in a percpu storage.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.

A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Tx processing of l2tp(4) uses normally involves sleepable operations so we
must avoid dereferencing a percpu data (struct ifqueue) after executing Tx
processing.  Address this situation by having just a pointer to the data in
a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@

diffstat:

 sys/net/if.c                |   61 ++++++++++-
 sys/net/if.h                |   29 ++++-
 sys/net/if_gif.c            |   39 +-----
 sys/net/if_gif.h            |   15 +-
 sys/net/if_ipsec.c          |   39 +-----
 sys/net/if_ipsec.h          |   11 +-
 sys/net/if_l2tp.c           |  259 +++++++++++++++++++++++++++++--------------
 sys/net/if_l2tp.h           |   14 +-
 sys/net/route.c             |   28 ++++-
 sys/net/route.h             |   21 +++-
 sys/netinet/in_gif.c        |   33 ++---
 sys/netinet/in_l2tp.c       |   30 ++--
 sys/netinet/ip_input.c      |   24 ++--
 sys/netinet/wqinput.c       |   38 +++++-
 sys/netinet6/in6_gif.c      |   46 +++----
 sys/netinet6/in6_l2tp.c     |   29 ++--
 sys/netinet6/ip6_forward.c  |    8 +-
 sys/netinet6/ip6_input.c    |   22 +-
 sys/netipsec/ipsec_output.c |   36 ++++-
 sys/netipsec/ipsecif.c      |  111 +++++++++++-------
 sys/netipsec/key.c          |   26 +++-
 21 files changed, 561 insertions(+), 358 deletions(-)

diffs (truncated from 1999 to 300 lines):

diff -r 4e1940c89cb4 -r b0cd7db2c251 sys/net/if.c
--- a/sys/net/if.c      Mon Sep 23 14:37:34 2019 +0000
+++ b/sys/net/if.c      Tue Sep 24 18:27:09 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.394.2.17 2019/08/19 14:27:16 martin Exp $     */
+/*     $NetBSD: if.c,v 1.394.2.18 2019/09/24 18:27:09 martin Exp $     */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.17 2019/08/19 14:27:16 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.18 2019/09/24 18:27:09 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2892,6 +2892,63 @@
        return 0;
 }
 
+static void
+if_tunnel_ro_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+       struct tunnel_ro *tro = p;
+
+       tro->tr_ro = kmem_zalloc(sizeof(*tro->tr_ro), KM_SLEEP);
+       tro->tr_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
+}
+
+percpu_t *
+if_tunnel_alloc_ro_percpu(void)
+{
+       percpu_t *ro_percpu;
+
+       ro_percpu = percpu_alloc(sizeof(struct tunnel_ro));
+       percpu_foreach(ro_percpu, if_tunnel_ro_init_pc, NULL);
+
+       return ro_percpu;
+}
+
+static void
+if_tunnel_ro_fini_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+       struct tunnel_ro *tro = p;
+
+       rtcache_free(tro->tr_ro);
+       kmem_free(tro->tr_ro, sizeof(*tro->tr_ro));
+
+       mutex_obj_free(tro->tr_lock);
+}
+
+void
+if_tunnel_free_ro_percpu(percpu_t *ro_percpu)
+{
+
+       percpu_foreach(ro_percpu, if_tunnel_ro_fini_pc, NULL);
+       percpu_free(ro_percpu, sizeof(struct tunnel_ro));
+}
+
+
+static void
+if_tunnel_rtcache_free_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+       struct tunnel_ro *tro = p;
+
+       mutex_enter(tro->tr_lock);
+       rtcache_free(tro->tr_ro);
+       mutex_exit(tro->tr_lock);
+}
+
+void if_tunnel_ro_percpu_rtcache_free(percpu_t *ro_percpu)
+{
+
+       percpu_foreach(ro_percpu, if_tunnel_rtcache_free_pc, NULL);
+}
+
+
 /* common */
 int
 ifioctl_common(struct ifnet *ifp, u_long cmd, void *data)
diff -r 4e1940c89cb4 -r b0cd7db2c251 sys/net/if.h
--- a/sys/net/if.h      Mon Sep 23 14:37:34 2019 +0000
+++ b/sys/net/if.h      Tue Sep 24 18:27:09 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.239.2.7 2018/07/13 15:49:55 martin Exp $      */
+/*     $NetBSD: if.h,v 1.239.2.8 2019/09/24 18:27:09 martin Exp $      */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -1111,6 +1111,33 @@
 #define        if_release      if_put
 
 int if_tunnel_check_nesting(struct ifnet *, struct mbuf *, int);
+percpu_t *if_tunnel_alloc_ro_percpu(void);
+void if_tunnel_free_ro_percpu(percpu_t *);
+void if_tunnel_ro_percpu_rtcache_free(percpu_t *);
+
+struct tunnel_ro {
+       struct route *tr_ro;
+       kmutex_t *tr_lock;
+};
+
+static inline void
+if_tunnel_get_ro(percpu_t *ro_percpu, struct route **ro, kmutex_t **lock)
+{
+       struct tunnel_ro *tro;
+
+       tro = percpu_getref(ro_percpu);
+       *ro = tro->tr_ro;
+       *lock = tro->tr_lock;
+       mutex_enter(*lock);
+}
+
+static inline void
+if_tunnel_put_ro(percpu_t *ro_percpu, kmutex_t *lock)
+{
+
+       mutex_exit(lock);
+       percpu_putref(ro_percpu);
+}
 
 static inline if_index_t
 if_get_index(const struct ifnet *ifp)
diff -r 4e1940c89cb4 -r b0cd7db2c251 sys/net/if_gif.c
--- a/sys/net/if_gif.c  Mon Sep 23 14:37:34 2019 +0000
+++ b/sys/net/if_gif.c  Tue Sep 24 18:27:09 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_gif.c,v 1.126.2.14 2019/04/22 09:06:49 martin Exp $ */
+/*     $NetBSD: if_gif.c,v 1.126.2.15 2019/09/24 18:27:09 martin Exp $ */
 /*     $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $    */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.14 2019/04/22 09:06:49 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.15 2019/09/24 18:27:09 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -107,9 +107,6 @@
 
 struct psref_class *gv_psref_class __read_mostly;
 
-static void    gif_ro_init_pc(void *, void *, struct cpu_info *);
-static void    gif_ro_fini_pc(void *, void *, struct cpu_info *);
-
 static int     gifattach0(struct gif_softc *);
 static int     gif_output(struct ifnet *, struct mbuf *,
                           const struct sockaddr *, const struct rtentry *);
@@ -274,8 +271,7 @@
        mutex_init(&sc->gif_lock, MUTEX_DEFAULT, IPL_NONE);
        sc->gif_psz = pserialize_create();
 
-       sc->gif_ro_percpu = percpu_alloc(sizeof(struct gif_ro));
-       percpu_foreach(sc->gif_ro_percpu, gif_ro_init_pc, NULL);
+       sc->gif_ro_percpu = if_tunnel_alloc_ro_percpu();
        mutex_enter(&gif_softcs.lock);
        LIST_INSERT_HEAD(&gif_softcs.list, sc, gif_list);
        mutex_exit(&gif_softcs.lock);
@@ -312,32 +308,6 @@
        return 0;
 }
 
-static void
-gif_ro_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
-{
-       struct gif_ro *gro = p;
-
-       gro->gr_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
-}
-
-static void
-gif_ro_fini_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
-{
-       struct gif_ro *gro = p;
-
-       rtcache_free(&gro->gr_ro);
-
-       mutex_obj_free(gro->gr_lock);
-}
-
-void
-gif_rtcache_free_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
-{
-       struct gif_ro *gro = p;
-
-       rtcache_free(&gro->gr_ro);
-}
-
 static int
 gif_clone_destroy(struct ifnet *ifp)
 {
@@ -350,8 +320,7 @@
        bpf_detach(ifp);
        if_detach(ifp);
 
-       percpu_foreach(sc->gif_ro_percpu, gif_ro_fini_pc, NULL);
-       percpu_free(sc->gif_ro_percpu, sizeof(struct gif_ro));
+       if_tunnel_free_ro_percpu(sc->gif_ro_percpu);
 
        pserialize_destroy(sc->gif_psz);
        mutex_destroy(&sc->gif_lock);
diff -r 4e1940c89cb4 -r b0cd7db2c251 sys/net/if_gif.h
--- a/sys/net/if_gif.h  Mon Sep 23 14:37:34 2019 +0000
+++ b/sys/net/if_gif.h  Tue Sep 24 18:27:09 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_gif.h,v 1.25.8.4 2018/10/21 11:55:54 martin Exp $   */
+/*     $NetBSD: if_gif.h,v 1.25.8.5 2019/09/24 18:27:09 martin Exp $   */
 /*     $KAME: if_gif.h,v 1.23 2001/07/27 09:21:42 itojun Exp $ */
 
 /*
@@ -55,11 +55,6 @@
 
 struct encaptab;
 
-struct gif_ro {
-       struct route gr_ro;
-       kmutex_t *gr_lock;
-};
-
 struct gif_variant {
        struct gif_softc *gv_softc;
        struct sockaddr *gv_psrc; /* Physical src addr */
@@ -73,7 +68,7 @@
 
 struct gif_softc {
        struct ifnet    gif_if;         /* common area - must be at the top */
-       percpu_t *gif_ro_percpu;        /* struct gif_ro */
+       percpu_t *gif_ro_percpu;        /* struct tunnel_ro */
        struct gif_variant *gif_var;    /*
                                         * reader must use gif_getref_variant()
                                         * instead of direct dereference.
@@ -131,8 +126,6 @@
 /* Prototypes */
 void   gif_input(struct mbuf *, int, struct ifnet *);
 
-void   gif_rtcache_free_pc(void *, void *, struct cpu_info *);
-
 #ifdef GIF_ENCAPCHECK
 int    gif_encapcheck(struct mbuf *, int, int, void *);
 #endif
@@ -147,8 +140,8 @@
  *   - gif_var->gv_psref for reader
  *       gif_softc->gif_var is used for variant values while the gif tunnel
  *       exists.
- * + Each CPU's gif_ro.gr_ro of gif_ro_percpu are protected by
- *   percpu'ed gif_ro.gr_lock.
+ * + Each CPU's tunnel_ro.tr_ro of gif_ro_percpu are protected by
+ *   percpu'ed tunnel_ro.tr_lock.
  *
  * Locking order:
  *     - encap_lock => gif_softc->gif_lock => gif_softcs.lock
diff -r 4e1940c89cb4 -r b0cd7db2c251 sys/net/if_ipsec.c
--- a/sys/net/if_ipsec.c        Mon Sep 23 14:37:34 2019 +0000
+++ b/sys/net/if_ipsec.c        Tue Sep 24 18:27:09 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ipsec.c,v 1.3.2.11 2019/03/15 14:47:22 martin Exp $  */
+/*     $NetBSD: if_ipsec.c,v 1.3.2.12 2019/09/24 18:27:09 martin Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.11 2019/03/15 14:47:22 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3.2.12 2019/09/24 18:27:09 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -80,9 +80,6 @@
 #include <netipsec/ipsec.h>
 #include <netipsec/ipsecif.h>
 
-static void if_ipsec_ro_init_pc(void *, void *, struct cpu_info *);
-static void if_ipsec_ro_fini_pc(void *, void *, struct cpu_info *);
-
 static int if_ipsec_clone_create(struct if_clone *, int);
 static int if_ipsec_clone_destroy(struct ifnet *);
 
@@ -183,8 +180,7 @@
        sc->ipsec_var = var;
        mutex_init(&sc->ipsec_lock, MUTEX_DEFAULT, IPL_NONE);
        sc->ipsec_psz = pserialize_create();
-       sc->ipsec_ro_percpu = percpu_alloc(sizeof(struct ipsec_ro));
-       percpu_foreach(sc->ipsec_ro_percpu, if_ipsec_ro_init_pc, NULL);
+       sc->ipsec_ro_percpu = if_tunnel_alloc_ro_percpu();
 
        mutex_enter(&ipsec_softcs.lock);
        LIST_INSERT_HEAD(&ipsec_softcs.list, sc, ipsec_list);
@@ -214,24 +210,6 @@
        if_register(&sc->ipsec_if);
 }
 
-static void
-if_ipsec_ro_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)



Home | Main Index | Thread Index | Old Index