From nobody Sun Apr 12 18:35:36 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 4ftzkK25C6z6YW4r for ; Sun, 12 Apr 2026 18:35:37 +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 4ftzkJ5yfpz3ZxM for ; Sun, 12 Apr 2026 18:35:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776018936; 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=pW9Mp5fSEO5+XXM0DYw3uE1x04xXITganYCiCvSdoGU=; b=nnpK5OlO50SqvtY0l2nWIUdoa1zeMkL+2+HrNbLDZ1ZPx0fDiW6959yzbrqaHMy8p+GFNo XHt01hCZHTtM1Jk9+bRlbmUyXyoxlfYq3dDvRSrSo+YhjHlO9HLoq7hkbU6DnrPfI7wbH3 Id1093rFfqIXgmCG/VS3NvJry3MI//1P/N51wWHk1OBARYo91Q794VdZFbAHx3lmMJ8P1R T/iOKZjTPUYJH6npP8RKck7+P45ZV+KXfHhGKklQzmwyDgkTqxCTF5Z7cNjNlTXjQWUMUy wTMXSHtIs2lH/EZFYfYVFjv7Iyo6zZa2An3HWjkbQI/BHkf2QhEIEm44AvvZUw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776018936; a=rsa-sha256; cv=none; b=K8WJMvxhRUKFoa0RdXUt7xHuvj2JkYCLV36CY5cGbJiepQt9GSxvyw54Oz2JIhhED8flvE UYpcr8i58gi45buz7lODRT8LegOVJ4Ul1Wykzf0uvBtwCU/mlIuDSJA7G9mtWyBJK2gPPI SJwD8XnWJbcCKnH67JsMbmZMNDHPlP76zrH9p8K1b1E/tYQAfAoNeP/DI+ve4miLupA7gd Xe2zT866p1VRNbpOfamngJ4LX10U0qXb8XoH+yEUBuOwS5hYl1lk33R1n/X7SGiJwubfvk KXSskfkLPJbkTkNS31CBUSGNW3Ih1Uz2JkF5rKbImjEGUKDvR9jYUmHj1DDxtg== 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=1776018936; 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=pW9Mp5fSEO5+XXM0DYw3uE1x04xXITganYCiCvSdoGU=; b=Xd78Pcn7ySeFq5g5+ywda+4nsA7DnGtS4HW81UpPw356lKpS3EdWEbia6whRbp9j4WgsVU CJAqtXKaTi7DcP7hcnLd9LBPZmbPQR/tl5hUOzTXY28X2xq2zw6ScehJTxMrBr7AFSCR43 GoNBLbHFU21X6dID9OpXY+XAo05mU8lqUQFHx8DxvMeM/K9nyI9IAn3P8GtEXtFZ2f+uKF lMrnnQM2HzK4QIhbZpTxehlx65qP+n1v1KBJDSQpbETXzO3C0LhjVRDyKoEMpxlXMx2dVL UCxUpLSkZU+PeGUZBZxk7Z93yuV5yidDF74bspnmIw0c9NAPntXrDabYUoYEug== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4ftzkJ559qzDJR for ; Sun, 12 Apr 2026 18:35:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3a90c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 12 Apr 2026 18:35:36 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 8b4d0bec4311 - main - inpcb: make in_pcbbind() acquire the hash lock internally 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: 8b4d0bec43116f5d4d1fba89d1b81f1d05805147 Auto-Submitted: auto-generated Date: Sun, 12 Apr 2026 18:35:36 +0000 Message-Id: <69dbe5f8.3a90c.181a2a8d@gitrepo.freebsd.org> The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=8b4d0bec43116f5d4d1fba89d1b81f1d05805147 commit 8b4d0bec43116f5d4d1fba89d1b81f1d05805147 Author: Gleb Smirnoff AuthorDate: 2026-04-12 18:33:20 +0000 Commit: Gleb Smirnoff CommitDate: 2026-04-12 18:33:20 +0000 inpcb: make in_pcbbind() acquire the hash lock internally Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55970 --- sys/netinet/in_pcb.c | 9 +++++++-- sys/netinet/tcp_usrreq.c | 10 ---------- sys/netinet/udp_usrreq.c | 6 ------ sys/netinet6/in6_pcb.c | 15 +++++++++++---- sys/netinet6/udp6_usrreq.c | 4 ---- 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index f1053f6abe03..6c5b7869d945 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -727,22 +727,27 @@ in_pcbbind(struct inpcb *inp, struct sockaddr_in *sin, int flags, KASSERT(sin == NULL || sin->sin_len == sizeof(struct sockaddr_in), ("%s: invalid address length for %p", __func__, sin)); INP_WLOCK_ASSERT(inp); - INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo); if (inp->inp_lport != 0 || inp->inp_laddr.s_addr != INADDR_ANY) return (EINVAL); anonport = sin == NULL || sin->sin_port == 0; + + INP_HASH_WLOCK(inp->inp_pcbinfo); error = in_pcbbind_setup(inp, sin, &inp->inp_laddr.s_addr, &inp->inp_lport, flags, cred); - if (error) + if (error) { + INP_HASH_WUNLOCK(inp->inp_pcbinfo); return (error); + } if (__predict_false((error = in_pcbinshash(inp)) != 0)) { + INP_HASH_WUNLOCK(inp->inp_pcbinfo); MPASS(inp->inp_socket->so_options & SO_REUSEPORT_LB); inp->inp_laddr.s_addr = INADDR_ANY; inp->inp_lport = 0; inp->inp_flags &= ~INP_BOUNDFIB; return (error); } + INP_HASH_WUNLOCK(inp->inp_pcbinfo); if (anonport) inp->inp_flags |= INP_ANONPORT; return (0); diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index ce13f1a9cefe..72100a0fb9d9 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -256,10 +256,8 @@ tcp_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td) error = EAFNOSUPPORT; goto out; } - INP_HASH_WLOCK(&V_tcbinfo); error = in_pcbbind(inp, sinp, V_tcp_bind_all_fibs ? 0 : INPBIND_FIB, td->td_ucred); - INP_HASH_WUNLOCK(&V_tcbinfo); out: tcp_bblog_pru(tp, PRU_BIND, error); TCP_PROBE2(debug__user, tp, PRU_BIND); @@ -305,7 +303,6 @@ tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td) goto out; } - INP_HASH_WLOCK(&V_tcbinfo); inp->inp_vflag &= ~INP_IPV4; inp->inp_vflag |= INP_IPV6; #ifdef INET @@ -318,20 +315,17 @@ tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td) in6_sin6_2_sin(&sin, sin6); if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) { error = EAFNOSUPPORT; - INP_HASH_WUNLOCK(&V_tcbinfo); goto out; } inp->inp_vflag |= INP_IPV4; inp->inp_vflag &= ~INP_IPV6; error = in_pcbbind(inp, &sin, 0, td->td_ucred); - INP_HASH_WUNLOCK(&V_tcbinfo); goto out; } } #endif error = in6_pcbbind(inp, sin6, V_tcp_bind_all_fibs ? 0 : INPBIND_FIB, td->td_ucred); - INP_HASH_WUNLOCK(&V_tcbinfo); out: if (error != 0) inp->inp_vflag = vflagsav; @@ -368,10 +362,8 @@ tcp_usr_listen(struct socket *so, int backlog, struct thread *td) goto out; } if (inp->inp_lport == 0) { - INP_HASH_WLOCK(&V_tcbinfo); error = in_pcbbind(inp, NULL, V_tcp_bind_all_fibs ? 0 : INPBIND_FIB, td->td_ucred); - INP_HASH_WUNLOCK(&V_tcbinfo); } if (error == 0) { tcp_state_change(tp, TCPS_LISTEN); @@ -426,7 +418,6 @@ tcp6_usr_listen(struct socket *so, int backlog, struct thread *td) SOCK_UNLOCK(so); goto out; } - INP_HASH_WLOCK(&V_tcbinfo); if (inp->inp_lport == 0) { inp->inp_vflag &= ~INP_IPV4; if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) @@ -434,7 +425,6 @@ tcp6_usr_listen(struct socket *so, int backlog, struct thread *td) error = in6_pcbbind(inp, NULL, V_tcp_bind_all_fibs ? 0 : INPBIND_FIB, td->td_ucred); } - INP_HASH_WUNLOCK(&V_tcbinfo); if (error == 0) { tcp_state_change(tp, TCPS_LISTEN); solisten_proto(so, backlog); diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index e425af92048d..3e8011542753 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1356,10 +1356,8 @@ udp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, .sin_len = sizeof(struct sockaddr_in), }; - INP_HASH_WLOCK(pcbinfo); error = in_pcbbind(inp, &wild, V_udp_bind_all_fibs ? 0 : INPBIND_FIB, td->td_ucred); - INP_HASH_WUNLOCK(pcbinfo); if (error) goto release; lport = inp->inp_lport; @@ -1599,11 +1597,9 @@ static int udp_bind(struct socket *so, struct sockaddr *nam, struct thread *td) { struct inpcb *inp; - struct inpcbinfo *pcbinfo; struct sockaddr_in *sinp; int error; - pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol); inp = sotoinpcb(so); KASSERT(inp != NULL, ("udp_bind: inp == NULL")); @@ -1622,10 +1618,8 @@ udp_bind(struct socket *so, struct sockaddr *nam, struct thread *td) return (EINVAL); INP_WLOCK(inp); - INP_HASH_WLOCK(pcbinfo); error = in_pcbbind(inp, sinp, V_udp_bind_all_fibs ? 0 : INPBIND_FIB, td->td_ucred); - INP_HASH_WUNLOCK(pcbinfo); INP_WUNLOCK(inp); return (error); } diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 09a62a53e054..c4469136fc90 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -297,7 +297,6 @@ in6_pcbbind(struct inpcb *inp, struct sockaddr_in6 *sin6, int flags, int error, fib, lookupflags, sooptions; INP_WLOCK_ASSERT(inp); - INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo); if (inp->inp_lport || !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) return (EINVAL); @@ -310,6 +309,7 @@ in6_pcbbind(struct inpcb *inp, struct sockaddr_in6 *sin6, int flags, if ((error = prison_local_ip6(cred, &inp->in6p_laddr, ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0))) != 0) return (error); + INP_HASH_WLOCK(inp->inp_pcbinfo); } else { KASSERT(sin6->sin6_family == AF_INET6, ("%s: invalid address family for %p", __func__, sin6)); @@ -326,11 +326,14 @@ in6_pcbbind(struct inpcb *inp, struct sockaddr_in6 *sin6, int flags, fib = (flags & INPBIND_FIB) != 0 ? inp->inp_inc.inc_fibnum : RT_ALL_FIBS; + INP_HASH_WLOCK(inp->inp_pcbinfo); /* See if this address/port combo is available. */ - error = in6_pcbbind_avail(inp, sin6, fib, sooptions, lookupflags, - cred); - if (error != 0) + error = in6_pcbbind_avail(inp, sin6, fib, sooptions, + lookupflags, cred); + if (error != 0) { + INP_HASH_WUNLOCK(inp->inp_pcbinfo); return (error); + } lport = sin6->sin6_port; inp->in6p_laddr = sin6->sin6_addr; @@ -339,6 +342,7 @@ in6_pcbbind(struct inpcb *inp, struct sockaddr_in6 *sin6, int flags, inp->inp_flags |= INP_BOUNDFIB; if (lport == 0) { if ((error = in6_pcbsetport(&inp->in6p_laddr, inp, cred)) != 0) { + INP_HASH_WUNLOCK(inp->inp_pcbinfo); /* Undo an address bind that may have occurred. */ inp->inp_flags &= ~INP_BOUNDFIB; inp->in6p_laddr = in6addr_any; @@ -347,12 +351,15 @@ in6_pcbbind(struct inpcb *inp, struct sockaddr_in6 *sin6, int flags, } else { inp->inp_lport = lport; if (in_pcbinshash(inp) != 0) { + INP_HASH_WUNLOCK(inp->inp_pcbinfo); inp->inp_flags &= ~INP_BOUNDFIB; inp->in6p_laddr = in6addr_any; inp->inp_lport = 0; return (EAGAIN); } } + INP_HASH_WUNLOCK(inp->inp_pcbinfo); + return (0); } diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index 715f43f0d47c..6e37586f16e4 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -1046,11 +1046,9 @@ udp6_bind(struct socket *so, struct sockaddr *nam, struct thread *td) { struct sockaddr_in6 *sin6_p; struct inpcb *inp; - struct inpcbinfo *pcbinfo; int error; u_char vflagsav; - pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol); inp = sotoinpcb(so); KASSERT(inp != NULL, ("udp6_bind: inp == NULL")); @@ -1062,7 +1060,6 @@ udp6_bind(struct socket *so, struct sockaddr *nam, struct thread *td) sin6_p = (struct sockaddr_in6 *)nam; INP_WLOCK(inp); - INP_HASH_WLOCK(pcbinfo); vflagsav = inp->inp_vflag; inp->inp_vflag &= ~INP_IPV4; inp->inp_vflag |= INP_IPV6; @@ -1091,7 +1088,6 @@ out: #endif if (error != 0) inp->inp_vflag = vflagsav; - INP_HASH_WUNLOCK(pcbinfo); INP_WUNLOCK(inp); return (error); }