From 872527097680c6cf1b32ba9c5f884d29604e6659 Mon Sep 17 00:00:00 2001 From: sashan Date: Mon, 10 Sep 2018 16:18:34 +0000 Subject: [PATCH] - if_cloners list populated at boot time only then becomes immutable, so we can let go if_cloners_lock. OK tb@, claudio@, bluhm@, kn@, henning@ --- sys/kern/init_main.c | 8 +++++++- sys/net/if.c | 34 ++++++++++------------------------ sys/net/if_var.h | 3 +-- sys/sys/device.h | 7 ++++++- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index aa4c0a83ef7..91070090bb1 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.280 2018/08/13 15:26:17 visa Exp $ */ +/* $OpenBSD: init_main.c,v 1.281 2018/09/10 16:18:34 sashan Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -174,6 +174,9 @@ struct emul emul_native = { sigcoderet }; +#ifdef DIAGNOSTIC +int pdevinit_done = 0; +#endif /* * System startup; initialize the world, create process 0, mount root @@ -401,6 +404,9 @@ main(void *framep) for (pdev = pdevinit; pdev->pdev_attach != NULL; pdev++) if (pdev->pdev_count > 0) (*pdev->pdev_attach)(pdev->pdev_count); +#ifdef DIAGNOSTIC + pdevinit_done = 1; +#endif #ifdef CRYPTO crypto_init(); diff --git a/sys/net/if.c b/sys/net/if.c index f4978c1112d..0e0c767cc3b 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.562 2018/09/10 16:07:20 henning Exp $ */ +/* $OpenBSD: if.c,v 1.563 2018/09/10 16:18:34 sashan Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -129,6 +129,8 @@ #include #endif +#include + void if_attachsetup(struct ifnet *); void if_attachdomain(struct ifnet *); void if_attach_common(struct ifnet *); @@ -220,8 +222,6 @@ void if_idxmap_remove(struct ifnet *); TAILQ_HEAD(, ifg_group) ifg_head = TAILQ_HEAD_INITIALIZER(ifg_head); -/* Serialize access to &if_cloners and if_cloners_count */ -struct rwlock if_cloners_lock = RWLOCK_INITIALIZER("ifclonerslk"); LIST_HEAD(, if_clone) if_cloners = LIST_HEAD_INITIALIZER(if_cloners); int if_cloners_count; @@ -1253,13 +1253,11 @@ if_clone_lookup(const char *name, int *unitp) if (cp - name < IFNAMSIZ-1 && *cp == '0' && cp[1] != '\0') return (NULL); /* unit number 0 padded */ - rw_enter_read(&if_cloners_lock); LIST_FOREACH(ifc, &if_cloners, ifc_list) { if (strlen(ifc->ifc_name) == cp - name && !strncmp(name, ifc->ifc_name, cp - name)) break; } - rw_exit_read(&if_cloners_lock); if (ifc == NULL) return (NULL); @@ -1285,22 +1283,15 @@ if_clone_lookup(const char *name, int *unitp) void if_clone_attach(struct if_clone *ifc) { - rw_enter_write(&if_cloners_lock); + /* + * we are called at kernel boot by main(), when pseudo devices are + * being attached. The main() is the only guy which may alter the + * if_cloners. While system is running and main() is done with + * initialization, the if_cloners becomes immutable. + */ + KASSERT(pdevinit_done == 0); LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list); if_cloners_count++; - rw_exit_write(&if_cloners_lock); -} - -/* - * Unregister a network interface cloner. - */ -void -if_clone_detach(struct if_clone *ifc) -{ - rw_enter_write(&if_cloners_lock); - LIST_REMOVE(ifc, ifc_list); - if_cloners_count--; - rw_exit_write(&if_cloners_lock); } /* @@ -1315,17 +1306,13 @@ if_clone_list(struct if_clonereq *ifcr) if ((dst = ifcr->ifcr_buffer) == NULL) { /* Just asking how many there are. */ - rw_enter_read(&if_cloners_lock); ifcr->ifcr_total = if_cloners_count; - rw_exit_read(&if_cloners_lock); return (0); } if (ifcr->ifcr_count < 0) return (EINVAL); - rw_enter_read(&if_cloners_lock); - ifcr->ifcr_total = if_cloners_count; count = MIN(if_cloners_count, ifcr->ifcr_count); @@ -1341,7 +1328,6 @@ if_clone_list(struct if_clonereq *ifcr) dst += IFNAMSIZ; } - rw_exit_read(&if_cloners_lock); return (error); } diff --git a/sys/net/if_var.h b/sys/net/if_var.h index e9f69c964cb..564b59037fd 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_var.h,v 1.89 2018/01/10 23:50:39 dlg Exp $ */ +/* $OpenBSD: if_var.h,v 1.90 2018/09/10 16:18:34 sashan Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -328,7 +328,6 @@ void ifafree(struct ifaddr *); int if_isconnected(const struct ifnet *, unsigned int); void if_clone_attach(struct if_clone *); -void if_clone_detach(struct if_clone *); int if_clone_create(const char *, int); int if_clone_destroy(const char *); diff --git a/sys/sys/device.h b/sys/sys/device.h index 00a1f6ad2a6..1faa0192a99 100644 --- a/sys/sys/device.h +++ b/sys/sys/device.h @@ -1,4 +1,4 @@ -/* $OpenBSD: device.h,v 1.54 2015/12/11 16:07:02 mpi Exp $ */ +/* $OpenBSD: device.h,v 1.55 2018/09/10 16:18:34 sashan Exp $ */ /* $NetBSD: device.h,v 1.15 1996/04/09 20:55:24 cgd Exp $ */ /* @@ -164,6 +164,11 @@ struct pdevinit { }; #ifdef _KERNEL + +#ifdef DIAGNOSTIC +extern int pdevinit_done; +#endif + extern struct devicelist alldevs; /* list of all devices */ extern int autoconf_verbose; -- 2.20.1