From: kn Date: Thu, 6 Jul 2023 19:46:53 +0000 (+0000) Subject: use refcnt API for multicast addresses, add tracepoint:refcnt:ethmulti probe X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=69761fb125b16d61f88297209c708431fdccb40f;p=openbsd use refcnt API for multicast addresses, add tracepoint:refcnt:ethmulti probe Replace hand-rolled reference counting with refcnt_init(9) and hook it up with a new dt(4) probe. OK mvs Feedback OK bluhm --- diff --git a/sys/dev/dt/dt_prov_static.c b/sys/dev/dt/dt_prov_static.c index e446844f575..dc2398175dd 100644 --- a/sys/dev/dt/dt_prov_static.c +++ b/sys/dev/dt/dt_prov_static.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dt_prov_static.c,v 1.19 2023/06/28 11:49:49 kn Exp $ */ +/* $OpenBSD: dt_prov_static.c,v 1.20 2023/07/06 19:46:53 kn Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot @@ -92,6 +92,7 @@ DT_STATIC_PROBE2(smr, thread, "uint64_t", "uint64_t"); * reference counting, keep in sync with sys/refcnt.h */ DT_STATIC_PROBE0(refcnt, none); +DT_STATIC_PROBE3(refcnt, ethmulti, "void *", "int", "int"); DT_STATIC_PROBE3(refcnt, ifaddr, "void *", "int", "int"); DT_STATIC_PROBE3(refcnt, ifmaddr, "void *", "int", "int"); DT_STATIC_PROBE3(refcnt, inpcb, "void *", "int", "int"); @@ -140,6 +141,7 @@ struct dt_probe *const dtps_static[] = { &_DT_STATIC_P(smr, thread), /* refcnt */ &_DT_STATIC_P(refcnt, none), + &_DT_STATIC_P(refcnt, ethmulti), &_DT_STATIC_P(refcnt, ifaddr), &_DT_STATIC_P(refcnt, ifmaddr), &_DT_STATIC_P(refcnt, inpcb), diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 4656fd8d2f8..20f7a9aee2e 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ethersubr.c,v 1.289 2023/07/03 15:52:51 kn Exp $ */ +/* $OpenBSD: if_ethersubr.c,v 1.290 2023/07/06 19:46:53 kn Exp $ */ /* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */ /* @@ -931,7 +931,7 @@ ether_addmulti(struct ifreq *ifr, struct arpcom *ac) /* * Found it; just increment the reference count. */ - ++enm->enm_refcount; + refcnt_take(&enm->enm_refcnt); splx(s); return (0); } @@ -946,7 +946,7 @@ ether_addmulti(struct ifreq *ifr, struct arpcom *ac) } memcpy(enm->enm_addrlo, addrlo, ETHER_ADDR_LEN); memcpy(enm->enm_addrhi, addrhi, ETHER_ADDR_LEN); - enm->enm_refcount = 1; + refcnt_init_trace(&enm->enm_refcnt, DT_REFCNT_IDX_ETHMULTI); LIST_INSERT_HEAD(&ac->ac_multiaddrs, enm, enm_list); ac->ac_multicnt++; if (memcmp(addrlo, addrhi, ETHER_ADDR_LEN) != 0) @@ -984,7 +984,7 @@ ether_delmulti(struct ifreq *ifr, struct arpcom *ac) splx(s); return (ENXIO); } - if (--enm->enm_refcount != 0) { + if (refcnt_rele(&enm->enm_refcnt) == 0) { /* * Still some claims to this record. */ diff --git a/sys/netinet/if_ether.h b/sys/netinet/if_ether.h index f05dbf41c52..9ff5baeaed1 100644 --- a/sys/netinet/if_ether.h +++ b/sys/netinet/if_ether.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ether.h,v 1.88 2023/02/07 16:14:55 bluhm Exp $ */ +/* $OpenBSD: if_ether.h,v 1.89 2023/07/06 19:46:53 kn Exp $ */ /* $NetBSD: if_ether.h,v 1.22 1996/05/11 13:00:00 mycroft Exp $ */ /* @@ -181,6 +181,9 @@ struct sockaddr_inarp { #define RTF_PERMANENT_ARP RTF_PROTO3 /* only manual overwrite of entry */ #ifdef _KERNEL + +#include + /* * Macro to map an IP multicast address to an Ethernet multicast address. * The high-order 25 bits of the Ethernet address are statically assigned, @@ -318,7 +321,7 @@ void ether_extract_headers(struct mbuf *, struct ether_extracted *); struct ether_multi { u_int8_t enm_addrlo[ETHER_ADDR_LEN]; /* low or only address of range */ u_int8_t enm_addrhi[ETHER_ADDR_LEN]; /* high or only address of range */ - u_int enm_refcount; /* no. claims to this addr/range */ + struct refcnt enm_refcnt; /* no. claims to this addr/range */ LIST_ENTRY(ether_multi) enm_list; }; diff --git a/sys/sys/refcnt.h b/sys/sys/refcnt.h index 47a40f61bef..c0f048214fc 100644 --- a/sys/sys/refcnt.h +++ b/sys/sys/refcnt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: refcnt.h,v 1.10 2023/06/28 11:49:49 kn Exp $ */ +/* $OpenBSD: refcnt.h,v 1.11 2023/07/06 19:46:53 kn Exp $ */ /* * Copyright (c) 2015 David Gwynne @@ -44,11 +44,12 @@ int refcnt_shared(struct refcnt *); unsigned int refcnt_read(struct refcnt *); /* sorted alphabetically, keep in sync with dev/dt/dt_prov_static.c */ -#define DT_REFCNT_IDX_IFADDR 1 -#define DT_REFCNT_IDX_IFMADDR 2 -#define DT_REFCNT_IDX_INPCB 3 -#define DT_REFCNT_IDX_RTENTRY 4 -#define DT_REFCNT_IDX_TDB 5 +#define DT_REFCNT_IDX_ETHMULTI 1 +#define DT_REFCNT_IDX_IFADDR 2 +#define DT_REFCNT_IDX_IFMADDR 3 +#define DT_REFCNT_IDX_INPCB 4 +#define DT_REFCNT_IDX_RTENTRY 5 +#define DT_REFCNT_IDX_TDB 6 #endif /* _KERNEL */