Source-Changes-HG archive

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

[src/rmind-smpnet]: src/sys Checkpoint work in progress:



details:   https://anonhg.NetBSD.org/src/rev/cd6bff2cbdb6
branches:  rmind-smpnet
changeset: 787707:cd6bff2cbdb6
user:      rmind <rmind%NetBSD.org@localhost>
date:      Wed Aug 28 15:21:48 2013 +0000

description:
Checkpoint work in progress:
- Initial split of the protocol user-request method into the following
  methods: pr_attach, pr_detach and pr_generic for old the pr_usrreq.
- Adjust socreate(9) and sonewconn(9) to call pr_attach without the
  socket lock held (as a preparation for the locking scheme adjustment).
- Adjust all pr_attach routines to assert that PCB is not set.
- Sprinkle various comments, document some routines and their locking.
- Remove M_PCB, replace with kmem(9).
- Fix few bugs spotted on the way.

diffstat:

 sys/compat/common/if_43.c      |    6 +-
 sys/dev/kttcp.c                |   24 ++--
 sys/kern/kern_malloc.c         |    5 +-
 sys/kern/sys_socket.c          |   12 +-
 sys/kern/uipc_proto.c          |   21 +--
 sys/kern/uipc_socket.c         |  165 ++++++++++++++++++----------------
 sys/kern/uipc_socket2.c        |  136 +++++++++++++++++-----------
 sys/kern/uipc_syscalls.c       |   78 ++++++++--------
 sys/kern/uipc_usrreq.c         |  139 ++++++++++++-----------------
 sys/miscfs/fifofs/fifo_vnops.c |    9 +-
 sys/net/if.c                   |   19 ++-
 sys/net/if_gre.c               |   17 ++-
 sys/net/if_stf.c               |   19 ++-
 sys/net/link_proto.c           |   37 +++++-
 sys/net/raw_cb.c               |   75 ++++++++-------
 sys/net/raw_cb.h               |    4 +-
 sys/net/raw_usrreq.c           |   69 ++++----------
 sys/net/rtsock.c               |  104 +++++++++++++---------
 sys/netatalk/at_extern.h       |    6 +-
 sys/netatalk/at_proto.c        |   10 +-
 sys/netatalk/ddp_usrreq.c      |   87 ++++++++----------
 sys/netbt/bluetooth.h          |   13 ++-
 sys/netbt/bt_proto.c           |   24 +---
 sys/netbt/hci.h                |    5 +-
 sys/netbt/hci_socket.c         |  120 ++++++++++++++----------
 sys/netbt/l2cap.h              |    7 +-
 sys/netbt/l2cap_socket.c       |   77 ++++++++++-----
 sys/netbt/l2cap_upper.c        |    7 +-
 sys/netbt/rfcomm.h             |    7 +-
 sys/netbt/rfcomm_socket.c      |   97 ++++++++++++--------
 sys/netbt/rfcomm_upper.c       |   16 +--
 sys/netbt/sco.h                |    6 +-
 sys/netbt/sco_socket.c         |   67 +++++++++----
 sys/netbt/sco_upper.c          |   10 +-
 sys/netinet/if_arp.c           |    7 +-
 sys/netinet/in_gif.c           |   19 ++-
 sys/netinet/in_pcb.c           |    6 +-
 sys/netinet/in_proto.c         |   36 ++----
 sys/netinet/ip_icmp.c          |   11 +-
 sys/netinet/ip_mroute.c        |   18 ++-
 sys/netinet/ip_var.h           |    3 +-
 sys/netinet/raw_ip.c           |  103 +++++++++++++--------
 sys/netinet/tcp_usrreq.c       |  192 +++++++++++++++++++++++++---------------
 sys/netinet/tcp_var.h          |    8 +-
 sys/netinet/udp_usrreq.c       |  103 ++++++++++++++-------
 sys/netinet/udp_var.h          |    9 +-
 sys/netinet6/icmp6.c           |   11 +-
 sys/netinet6/in6_gif.c         |   22 ++-
 sys/netinet6/in6_proto.c       |   32 ++----
 sys/netinet6/ip6_var.h         |    4 +-
 sys/netinet6/ip6protosw.h      |    4 +-
 sys/netinet6/raw_ip6.c         |  134 +++++++++++++++++-----------
 sys/netinet6/udp6_usrreq.c     |   93 +++++++++++++------
 sys/netinet6/udp6_var.h        |    5 +-
 sys/netipsec/keysock.c         |  123 ++++++++++++++++----------
 sys/netipsec/keysock.h         |   12 +-
 sys/netipsec/xform_ipip.c      |   12 +-
 sys/netmpls/mpls_proto.c       |   61 ++++++++----
 sys/netnatm/natm.c             |  107 ++++++++++++----------
 sys/netnatm/natm.h             |   13 +-
 sys/netnatm/natm_pcb.c         |   32 ++----
 sys/netnatm/natm_proto.c       |   15 +--
 sys/netsmb/smb_trantcp.c       |   12 +-
 sys/nfs/nfs_socket.c           |   12 +-
 sys/sys/malloc.h               |    3 +-
 sys/sys/mbuf.h                 |    3 +-
 sys/sys/protosw.h              |   15 ++-
 sys/sys/socketvar.h            |    6 +-
 sys/sys/un.h                   |   10 +-
 69 files changed, 1519 insertions(+), 1235 deletions(-)

diffs (truncated from 5916 to 300 lines):

diff -r 89fc12ca14ed -r cd6bff2cbdb6 sys/compat/common/if_43.c
--- a/sys/compat/common/if_43.c Wed Jul 17 03:16:31 2013 +0000
+++ b/sys/compat/common/if_43.c Wed Aug 28 15:21:48 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_43.c,v 1.4 2011/01/19 10:21:16 tsutsui Exp $        */
+/*     $NetBSD: if_43.c,v 1.4.20.1 2013/08/28 15:21:48 rmind Exp $     */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1990, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.4 2011/01/19 10:21:16 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.4.20.1 2013/08/28 15:21:48 rmind Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -256,7 +256,7 @@
                cmd = SIOCGIFNETMASK;
        }
 
-       error = (*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
+       error = (*so->so_proto->pr_usrreqs->pr_generic)(so, PRU_CONTROL,
            (struct mbuf *)cmd, (struct mbuf *)ifr, (struct mbuf *)ifp, l);
 
        switch (ocmd) {
diff -r 89fc12ca14ed -r cd6bff2cbdb6 sys/dev/kttcp.c
--- a/sys/dev/kttcp.c   Wed Jul 17 03:16:31 2013 +0000
+++ b/sys/dev/kttcp.c   Wed Aug 28 15:21:48 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kttcp.c,v 1.30 2011/12/22 02:00:19 jakllsch Exp $      */
+/*     $NetBSD: kttcp.c,v 1.30.10.1 2013/08/28 15:21:48 rmind Exp $    */
 
 /*
  * Copyright (c) 2002 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kttcp.c,v 1.30 2011/12/22 02:00:19 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kttcp.c,v 1.30.10.1 2013/08/28 15:21:48 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -310,7 +310,7 @@
                                so->so_options |= SO_DONTROUTE;
                        if (resid > 0)
                                so->so_state |= SS_MORETOCOME;
-                       error = (*so->so_proto->pr_usrreq)(so,
+                       error = (*so->so_proto->pr_usrreqs->pr_generic)(so,
                            (flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND,
                            top, NULL, NULL, l);
                        if (dontroute)
@@ -358,7 +358,7 @@
        if (flags & MSG_OOB) {
                m = m_get(M_WAIT, MT_DATA);
                solock(so);
-               error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m,
+               error = (*pr->pr_usrreqs->pr_generic)(so, PRU_RCVOOB, m,
                    (struct mbuf *)(long)(flags & MSG_PEEK), NULL, NULL);
                sounlock(so);
                if (error)
@@ -375,8 +375,10 @@
        if (mp)
                *mp = NULL;
        solock(so);
-       if (so->so_state & SS_ISCONFIRMING && resid)
-               (*pr->pr_usrreq)(so, PRU_RCVD, NULL, NULL, NULL, NULL);
+       if (so->so_state & SS_ISCONFIRMING && resid) {
+               (*pr->pr_usrreqs->pr_generic)(so, PRU_RCVD,
+                   NULL, NULL, NULL, NULL);
+       }
  restart:
        if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0)
                return (error);
@@ -624,9 +626,10 @@
                         * protocol in case it needs to do something to
                         * get it filled again.
                         */
-                       if ((pr->pr_flags & PR_WANTRCVD) && so->so_pcb)
-                               (*pr->pr_usrreq)(so, PRU_RCVD, NULL,
+                       if ((pr->pr_flags & PR_WANTRCVD) && so->so_pcb) {
+                               (*pr->pr_usrreqs->pr_generic)(so, PRU_RCVD, NULL,
                                    (struct mbuf *)(long)flags, NULL, NULL);
+                       }
                        SBLASTRECORDCHK(&so->so_rcv,
                            "kttcp_soreceive sbwait 2");
                        SBLASTMBUFCHK(&so->so_rcv,
@@ -663,9 +666,10 @@
                }
                SBLASTRECORDCHK(&so->so_rcv, "kttcp_soreceive 4");
                SBLASTMBUFCHK(&so->so_rcv, "kttcp_soreceive 4");
-               if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
-                       (*pr->pr_usrreq)(so, PRU_RCVD, NULL,
+               if (pr->pr_flags & PR_WANTRCVD && so->so_pcb) {
+                       (*pr->pr_usrreqs->pr_generic)(so, PRU_RCVD, NULL,
                            (struct mbuf *)(long)flags, NULL, NULL);
+               }
        }
        if (orig_resid == resid && orig_resid &&
            (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {
diff -r 89fc12ca14ed -r cd6bff2cbdb6 sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c    Wed Jul 17 03:16:31 2013 +0000
+++ b/sys/kern/kern_malloc.c    Wed Aug 28 15:21:48 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_malloc.c,v 1.142 2012/04/30 22:51:27 rmind Exp $  */
+/*     $NetBSD: kern_malloc.c,v 1.142.4.1 2013/08/28 15:21:48 rmind Exp $      */
 
 /*
  * Copyright (c) 1987, 1991, 1993
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.142 2012/04/30 22:51:27 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.142.4.1 2013/08/28 15:21:48 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/malloc.h>
@@ -84,7 +84,6 @@
 MALLOC_DEFINE(M_DEVBUF, "devbuf", "device driver memory");
 MALLOC_DEFINE(M_DMAMAP, "DMA map", "bus_dma(9) structures");
 MALLOC_DEFINE(M_FREE, "free", "should be on free list");
-MALLOC_DEFINE(M_PCB, "pcb", "protocol control block");
 MALLOC_DEFINE(M_TEMP, "temp", "misc. temporary data buffers");
 MALLOC_DEFINE(M_RTABLE, "routetbl", "routing tables");
 MALLOC_DEFINE(M_FTABLE, "fragtbl", "fragment reassembly header");
diff -r 89fc12ca14ed -r cd6bff2cbdb6 sys/kern/sys_socket.c
--- a/sys/kern/sys_socket.c     Wed Jul 17 03:16:31 2013 +0000
+++ b/sys/kern/sys_socket.c     Wed Aug 28 15:21:48 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_socket.c,v 1.65 2011/12/20 23:56:28 christos Exp $ */
+/*     $NetBSD: sys_socket.c,v 1.65.10.1 2013/08/28 15:21:48 rmind Exp $       */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.65 2011/12/20 23:56:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.65.10.1 2013/08/28 15:21:48 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -201,9 +201,9 @@
                else if (IOCGROUP(cmd) == 'r')
                        error = rtioctl(cmd, data, curlwp);
                else {
-                       error = (*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
-                           (struct mbuf *)cmd, (struct mbuf *)data, NULL,
-                            curlwp);
+                       error = (*so->so_proto->pr_usrreqs->pr_generic)(so,
+                           PRU_CONTROL, (struct mbuf *)cmd,
+                           (struct mbuf *)data, NULL, curlwp);
                }
                KERNEL_UNLOCK_ONE(NULL);
                break;
@@ -240,7 +240,7 @@
        ub->st_mode = S_IFSOCK;
 
        solock(so);
-       error = (*so->so_proto->pr_usrreq)(so, PRU_SENSE,
+       error = (*so->so_proto->pr_usrreqs->pr_generic)(so, PRU_SENSE,
            (struct mbuf *)ub, NULL, NULL, curlwp);
        sounlock(so);
 
diff -r 89fc12ca14ed -r cd6bff2cbdb6 sys/kern/uipc_proto.c
--- a/sys/kern/uipc_proto.c     Wed Jul 17 03:16:31 2013 +0000
+++ b/sys/kern/uipc_proto.c     Wed Aug 28 15:21:48 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_proto.c,v 1.22 2011/05/29 03:32:46 manu Exp $     */
+/*     $NetBSD: uipc_proto.c,v 1.22.18.1 2013/08/28 15:21:48 rmind Exp $       */
 
 /*-
  * Copyright (c) 1982, 1986, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_proto.c,v 1.22 2011/05/29 03:32:46 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_proto.c,v 1.22.18.1 2013/08/28 15:21:48 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -57,25 +57,22 @@
                .pr_domain = &unixdomain,
                .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS|PR_LISTEN,
                .pr_ctloutput = uipc_ctloutput,
-               .pr_usrreq = uipc_usrreq,
-       }, {
+               .pr_usrreqs = &unp_usrreqs,
+       },
+       {
                .pr_type = SOCK_DGRAM,
                .pr_domain = &unixdomain,
                .pr_flags = PR_ATOMIC|PR_ADDR|PR_RIGHTS,
                .pr_ctloutput = uipc_ctloutput,
-               .pr_usrreq = uipc_usrreq,
-       }, {
+               .pr_usrreqs = &unp_usrreqs,
+       },
+       {
                .pr_type = SOCK_SEQPACKET,
                .pr_domain = &unixdomain,
                .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS|PR_LISTEN|
                            PR_ATOMIC,
                .pr_ctloutput = uipc_ctloutput,
-               .pr_usrreq = uipc_usrreq,
-       }, {
-               .pr_input = raw_input,
-               .pr_ctlinput = raw_ctlinput,
-               .pr_usrreq = raw_usrreq,
-               .pr_init = raw_init,
+               .pr_usrreqs = &unp_usrreqs,
        }
 };
 
diff -r 89fc12ca14ed -r cd6bff2cbdb6 sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c    Wed Jul 17 03:16:31 2013 +0000
+++ b/sys/kern/uipc_socket.c    Wed Aug 28 15:21:48 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket.c,v 1.215 2013/04/08 21:12:33 skrll Exp $  */
+/*     $NetBSD: uipc_socket.c,v 1.215.4.1 2013/08/28 15:21:48 rmind Exp $      */
 
 /*-
  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -62,8 +62,16 @@
  *     @(#)uipc_socket.c       8.6 (Berkeley) 5/2/95
  */
 
+/*
+ * Socket operation routines.
+ *
+ * These routines are called by the routines in sys_socket.c or from a
+ * system process, and implement the semantics of socket operations by
+ * switching out to the protocol specific routines.
+ */
+
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.215 2013/04/08 21:12:33 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.215.4.1 2013/08/28 15:21:48 rmind Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_sock_counters.h"
@@ -103,7 +111,6 @@
 #include <uvm/uvm_loan.h>
 #include <uvm/uvm_page.h>
 
-MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options");
 MALLOC_DEFINE(M_SONAME, "soname", "socket name");
 
 extern const struct fileops socketops;
@@ -479,13 +486,11 @@
 }
 
 /*
- * Socket operation routines.
- * These routines are called by the routines in
- * sys_socket.c or from a system process, and
- * implement the semantics of socket operations by
- * switching out to the protocol specific routines.
+ * socreate: create a new socket of the specified type and the protocol.
+ *
+ * => Caller may specify another socket for lock sharing (must not be held).
+ * => Returns the new socket without lock held.
  */
-/*ARGSUSED*/
 int
 socreate(int dom, struct socket **aso, int type, int proto, struct lwp *l,
         struct socket *lockso)
@@ -515,7 +520,7 @@
                        return EPROTOTYPE;
                return EPROTONOSUPPORT;
        }
-       if (prp->pr_usrreq == NULL)
+       if (prp->pr_usrreqs == NULL)
                return EPROTONOSUPPORT;
        if (prp->pr_type != type)
                return EPROTOTYPE;
@@ -533,62 +538,72 @@
        uid = kauth_cred_geteuid(l->l_cred);
        so->so_uidinfo = uid_find(uid);
        so->so_cpid = l->l_proc->p_pid;
-       if (lockso != NULL) {
-               /* Caller wants us to share a lock. */
+
+       /*
+        * Lock assigned and taken during pr_attach, unless we share
+        * the lock with another socket, e.g. socketpair(2) case.
+        */
+       if (lockso) {
                lock = lockso->so_lock;
                so->so_lock = lock;
                mutex_obj_hold(lock);
-               /* XXX Why is this not solock, to match sounlock? */
-               mutex_enter(lock);
-       } else {
-               /* Lock assigned and taken during PRU_ATTACH. */



Home | Main Index | Thread Index | Old Index