From: mvs Date: Tue, 18 Apr 2023 22:00:19 +0000 (+0000) Subject: Document `ifnetlist' locking. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a6b8260995b7cce5f7c2b4922e0b7f1c61321c01;p=openbsd Document `ifnetlist' locking. We use both kernel and net lock for protect `ifnetlist'. This means we do modification with both locks held, but for read-only access only one lock required. Some places doing `ifnetlist' foreach loop are protected by kernel lock and context switch can't be introduced there. This is the exception, so "XXXSMP:" comment added. Proposed and ok by bluhm@ --- diff --git a/sys/net/if.c b/sys/net/if.c index e4675704a3b..1cd91f8fa80 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.688 2023/04/08 13:49:38 mvs Exp $ */ +/* $OpenBSD: if.c,v 1.689 2023/04/18 22:00:19 mvs Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -272,6 +272,10 @@ ifinit(void) static struct if_idxmap if_idxmap; +/* + * XXXSMP: For `ifnetlist' modification both kernel and net locks + * should be taken. For read-only access only one lock of them required. + */ struct ifnet_head ifnetlist = TAILQ_HEAD_INITIALIZER(ifnetlist); static inline unsigned int diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 49b38eaf797..0eeebdc9bbb 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_var.h,v 1.123 2023/04/05 19:35:23 bluhm Exp $ */ +/* $OpenBSD: if_var.h,v 1.124 2023/04/18 22:00:19 mvs Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -121,7 +121,7 @@ TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */ struct ifnet { /* and the entries */ void *if_softc; /* [I] lower-level data for this if */ struct refcnt if_refcnt; - TAILQ_ENTRY(ifnet) if_list; /* [K] all struct ifnets are chained */ + TAILQ_ENTRY(ifnet) if_list; /* [NK] all struct ifnets are chained */ TAILQ_HEAD(, ifaddr) if_addrlist; /* [N] list of addresses per if */ TAILQ_HEAD(, ifmaddr) if_maddrlist; /* [N] list of multicast records */ TAILQ_HEAD(, ifg_list) if_groups; /* [N] list of groups per if */