From nobody Sun Apr 12 18:35:31 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ftzkC3QKtz6YW74 for ; Sun, 12 Apr 2026 18:35:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ftzkC27lJz3ZlB for ; Sun, 12 Apr 2026 18:35:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776018931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=opfrPQ9Ki0sYTNcJjAlHG50yto9QkOIyv5QuKsqTK+4=; b=NAVavbmNAzvSqgeNAMSTUChbr62jVf6qChADJNEYmPXFKYrJq0QfSQolSo+BUZiMx36ksJ 6qTp0U+JLBunWabvGCGN9x0pjId+ch6U+6lZTG6zT/IC6xSb8wItHoF8W1v4zEq8R+QsyO LgiODHYpec1zfxL/+BgN3nc8fvgSrwoh5Rnsc9zEe2UqIi9KDtP6CwZkuAXkWjrgBog7wB XC+pPDXfHFtPdvhsfsm9AjOrMxxpIFgZg7a6j0AvogbxDFKOglhzN8PSluK8hizHSDAbMS gSZXQ8Xd0xkJIyf10kSJulhte8wkDNT5Gg0Vs05MztFJ/3yRX6OHwjDAMt6ygA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776018931; a=rsa-sha256; cv=none; b=ZTZ+B7H1TZ/7umPbbYyIFWerMt7PRoxDvz7TYohPvO5lNE9+RJXJNuR4OTUTP/JbtbM1q1 VzV0+cKK1xXIYb5YT9crz7+wLJCkUFp8cc5tCh65aPecn6k/BTPMHW61gtOQ16MCdlw7Hs qcwSz24V4zUGqkKgXy3loM/IKomvrIcE5s6GMNYw+Iuf8M/fjAfha0S4h/FQ/DbJxxMUhd F0RHNGuIZ3KcqcbTn8UQw54I1B152zl4V+fbETDp1xuKAhDutlIiLDtdTh6Lni13TS2VDT ZIPUsNe3NN31lpeV3gPZDMVRK9J20H9ksgUOv/DeezHwMSJLgn7H7Qt0U5YE9w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776018931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=opfrPQ9Ki0sYTNcJjAlHG50yto9QkOIyv5QuKsqTK+4=; b=yBcExOHzMvTLbNrY3IYGVjAXLXtzbiuJd0i4xwyi4T+rdEDJZgzskc0Maf86YdsgVr1Wqh bF4Vx7BnKPdJCshpoi7K/qaK6oMQnlGyUodCSTB0YtYXH4XdOACXOaS1gL69Kgibww40rp XMwHHqgcYWT+LgzHLe8Kut51EyaNvVO5i7/v9nvPiCvNWsRgxXSJvfTwTpAnqCMIyiC0Eu U22fUD1UTKeWXUiHBnjqMmp67wWwFAql3b7TrW8S+4qCCN3bS87u3qOv7fQhi3Zum3cKYy Gqjr9DTwgT9+tkCJtwwHpmmMDVsnje8k7KMzvlVR1XnHbsAIGHGdfvPMQT54NA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4ftzkC1YBhzDJM for ; Sun, 12 Apr 2026 18:35:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3917b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 12 Apr 2026 18:35:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 2cfe62664ab7 - main - inpcb: retire the inpcbinfo list lock List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2cfe62664ab74756e40e17f7b8692d7a07531b83 Auto-Submitted: auto-generated Date: Sun, 12 Apr 2026 18:35:31 +0000 Message-Id: <69dbe5f3.3917b.1cc856ee@gitrepo.freebsd.org> The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=2cfe62664ab74756e40e17f7b8692d7a07531b83 commit 2cfe62664ab74756e40e17f7b8692d7a07531b83 Author: Gleb Smirnoff AuthorDate: 2026-04-12 18:30:59 +0000 Commit: Gleb Smirnoff CommitDate: 2026-04-12 18:30:59 +0000 inpcb: retire the inpcbinfo list lock With the SMR locking of inpcbs the use of this lock reduced down to the global list and generation number. It was used only on an inpcb creation and destruction. Use the inpcbinfo hash lock for this purpose. Reviewed by: pouria, rrs, markj Differential Revision: https://reviews.freebsd.org/D55966 --- sys/netinet/in_pcb.c | 12 +++++------- sys/netinet/in_pcb.h | 28 +++++----------------------- sys/netinet/raw_ip.c | 2 +- sys/netinet/tcp_subr.c | 2 +- sys/netinet/udp_usrreq.c | 4 ++-- 5 files changed, 14 insertions(+), 34 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 98421a7f2232..d60c75ab45b5 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -558,7 +558,6 @@ in_pcbinfo_init(struct inpcbinfo *pcbinfo, struct inpcbstorage *pcbstor, .head = HASH_HEAD_CK_LIST, }; - mtx_init(&pcbinfo->ipi_lock, pcbstor->ips_infolock_name, NULL, MTX_DEF); mtx_init(&pcbinfo->ipi_hash_lock, pcbstor->ips_hashlock_name, NULL, MTX_DEF); #ifdef VIMAGE @@ -602,7 +601,6 @@ in_pcbinfo_destroy(struct inpcbinfo *pcbinfo) hashfree(pcbinfo->ipi_porthashbase, &ha); hashfree(pcbinfo->ipi_lbgrouphashbase, &ha); mtx_destroy(&pcbinfo->ipi_hash_lock); - mtx_destroy(&pcbinfo->ipi_lock); } /* @@ -697,11 +695,11 @@ in_pcballoc(struct socket *so, struct inpcbinfo *pcbinfo) inp->inp_route.ro_flags = RT_LLE_CACHE; refcount_init(&inp->inp_refcount, 1); /* Reference from socket. */ INP_WLOCK(inp); - INP_INFO_WLOCK(pcbinfo); + INP_HASH_WLOCK(pcbinfo); pcbinfo->ipi_count++; inp->inp_gencnt = ++pcbinfo->ipi_gencnt; CK_LIST_INSERT_HEAD(&pcbinfo->ipi_listhead, inp, inp_list); - INP_INFO_WUNLOCK(pcbinfo); + INP_HASH_WUNLOCK(pcbinfo); so->so_pcb = inp; return (0); @@ -1799,13 +1797,13 @@ in_pcbfree(struct inpcb *inp) * from the hash without acquiring inpcb lock, they rely on the hash * lock, thus in_pcbremhash() should be the first action. */ + INP_HASH_WLOCK(pcbinfo); if (inp->inp_flags & INP_INHASHLIST) - in_pcbremhash(inp); - INP_INFO_WLOCK(pcbinfo); + in_pcbremhash_locked(inp); inp->inp_gencnt = ++pcbinfo->ipi_gencnt; pcbinfo->ipi_count--; CK_LIST_REMOVE(inp, inp_list); - INP_INFO_WUNLOCK(pcbinfo); + INP_HASH_WUNLOCK(pcbinfo); #ifdef RATELIMIT if (inp->inp_snd_tag != NULL) diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index a1b547462d53..e76e3fa8e382 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -422,30 +422,23 @@ struct inpcb { * IPv4 and IPv6. * * The pcbs are protected with SMR section and thus all lists in inpcbinfo - * are CK-lists. Locking is required to insert a pcb into database. Two - * locks are provided: one for the hash and one for the global list of pcbs, - * as well as overall count and generation count. + * are CK-lists. Locking is required to insert a pcb into database. * * Locking key: * * (c) Constant or nearly constant after initialisation * (e) Protected by SMR section - * (g) Locked by ipi_lock * (h) Locked by ipi_hash_lock */ struct inpcbinfo { - /* - * Global lock protecting inpcb list modification - */ - struct mtx ipi_lock; - struct inpcbhead ipi_listhead; /* (r:e/w:g) */ - u_int ipi_count; /* (g) */ + struct inpcbhead ipi_listhead; /* (r:e/w:h) */ + u_int ipi_count; /* (h) */ /* * Generation count -- incremented each time a connection is allocated * or freed. */ - u_quad_t ipi_gencnt; /* (g) */ + u_quad_t ipi_gencnt; /* (h) */ /* * Fields associated with port lookup and allocation. @@ -498,11 +491,10 @@ struct inpcbstorage { uma_init ips_pcbinit; size_t ips_size; const char * ips_zone_name; - const char * ips_infolock_name; const char * ips_hashlock_name; }; -#define INPCBSTORAGE_DEFINE(prot, ppcb, lname, zname, iname, hname) \ +#define INPCBSTORAGE_DEFINE(prot, ppcb, lname, zname, hname) \ static int \ prot##_inpcb_init(void *mem, int size __unused, int flags __unused) \ { \ @@ -515,7 +507,6 @@ static struct inpcbstorage prot = { \ .ips_size = sizeof(struct ppcb), \ .ips_pcbinit = prot##_inpcb_init, \ .ips_zone_name = zname, \ - .ips_infolock_name = iname, \ .ips_hashlock_name = hname, \ }; \ SYSINIT(prot##_inpcbstorage_init, SI_SUB_PROTO_DOMAIN, \ @@ -564,15 +555,6 @@ struct socket * void inp_4tuple_get(struct inpcb *inp, uint32_t *laddr, uint16_t *lp, uint32_t *faddr, uint16_t *fp); -#define INP_INFO_WLOCK(ipi) mtx_lock(&(ipi)->ipi_lock) -#define INP_INFO_WLOCKED(ipi) mtx_owned(&(ipi)->ipi_lock) -#define INP_INFO_WUNLOCK(ipi) mtx_unlock(&(ipi)->ipi_lock) -#define INP_INFO_LOCK_ASSERT(ipi) MPASS(SMR_ENTERED((ipi)->ipi_smr) || \ - mtx_owned(&(ipi)->ipi_lock)) -#define INP_INFO_WLOCK_ASSERT(ipi) mtx_assert(&(ipi)->ipi_lock, MA_OWNED) -#define INP_INFO_WUNLOCK_ASSERT(ipi) \ - mtx_assert(&(ipi)->ipi_lock, MA_NOTOWNED) - #define INP_HASH_WLOCK(ipi) mtx_lock(&(ipi)->ipi_hash_lock) #define INP_HASH_WUNLOCK(ipi) mtx_unlock(&(ipi)->ipi_hash_lock) #define INP_HASH_LOCK_ASSERT(ipi) MPASS(SMR_ENTERED((ipi)->ipi_smr) || \ diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index a8a4fc1df9e2..f2fec876d077 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -181,7 +181,7 @@ rip_delhash(struct inpcb *inp) } #endif /* INET */ -INPCBSTORAGE_DEFINE(ripcbstor, inpcb, "rawinp", "ripcb", "rip", "riphash"); +INPCBSTORAGE_DEFINE(ripcbstor, inpcb, "rawinp", "ripcb", "riphash"); static void rip_init(void *arg __unused) diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index b6bb0221e872..43c430708926 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1140,7 +1140,7 @@ static struct mtx isn_mtx; #define ISN_LOCK() mtx_lock(&isn_mtx) #define ISN_UNLOCK() mtx_unlock(&isn_mtx) -INPCBSTORAGE_DEFINE(tcpcbstor, tcpcb, "tcpinp", "tcp_inpcb", "tcp", "tcphash"); +INPCBSTORAGE_DEFINE(tcpcbstor, tcpcb, "tcpinp", "tcp_inpcb", "tcphash"); /* * Take a value and get the next power of 2 that doesn't overflow. diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index e8847ea12f1e..eb37ceddace0 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -165,9 +165,9 @@ VNET_PCPUSTAT_SYSUNINIT(udpstat); static void udp_detach(struct socket *so); #endif -INPCBSTORAGE_DEFINE(udpcbstor, udpcb, "udpinp", "udp_inpcb", "udp", "udphash"); +INPCBSTORAGE_DEFINE(udpcbstor, udpcb, "udpinp", "udp_inpcb", "udphash"); INPCBSTORAGE_DEFINE(udplitecbstor, udpcb, "udpliteinp", "udplite_inpcb", - "udplite", "udplitehash"); + "udplitehash"); static void udp_vnet_init(void *arg __unused)