git: 0ba87ded9d07 - main - inpcb: make in_pcbdisconnect() acquire the hash lock internally
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 12 Apr 2026 18:35:33 UTC
The branch main has been updated by glebius:
URL: https://cgit.FreeBSD.org/src/commit/?id=0ba87ded9d072b7b0605d2f4e8a7232b33b8787e
commit 0ba87ded9d072b7b0605d2f4e8a7232b33b8787e
Author: Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2026-04-12 18:32:06 +0000
Commit: Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2026-04-12 18:32:06 +0000
inpcb: make in_pcbdisconnect() acquire the hash lock internally
Should be no functional change.
Reviewed by: pouria, markj
Differential Revision: https://reviews.freebsd.org/D55968
---
sys/netinet/in_pcb.c | 3 ++-
sys/netinet/udp_usrreq.c | 12 ------------
sys/netinet6/in6_pcb.c | 3 ++-
sys/netinet6/udp6_usrreq.c | 12 ------------
4 files changed, 4 insertions(+), 26 deletions(-)
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index cb5b7fa274f6..8bc90de239c2 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -1423,13 +1423,14 @@ in_pcbdisconnect(struct inpcb *inp)
{
INP_WLOCK_ASSERT(inp);
- INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);
KASSERT(inp->inp_smr == SMR_SEQ_INVALID,
("%s: inp %p was already disconnected", __func__, inp));
+ INP_HASH_WLOCK(inp->inp_pcbinfo);
in_pcbremhash(inp);
CK_LIST_INSERT_HEAD(&inp->inp_pcbinfo->ipi_list_unconn, inp,
inp_unconn_list);
+ INP_HASH_WUNLOCK(inp->inp_pcbinfo);
if ((inp->inp_socket->so_proto->pr_flags & PR_CONNREQUIRED) == 0) {
/* See the comment in in_pcbinshash(). */
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index eb37ceddace0..e425af92048d 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -1528,16 +1528,12 @@ void
udp_abort(struct socket *so)
{
struct inpcb *inp;
- struct inpcbinfo *pcbinfo;
- pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("udp_abort: inp == NULL"));
INP_WLOCK(inp);
if (inp->inp_faddr.s_addr != INADDR_ANY) {
- INP_HASH_WLOCK(pcbinfo);
in_pcbdisconnect(inp);
- INP_HASH_WUNLOCK(pcbinfo);
soisdisconnected(so);
}
INP_WUNLOCK(inp);
@@ -1638,16 +1634,12 @@ static void
udp_close(struct socket *so)
{
struct inpcb *inp;
- struct inpcbinfo *pcbinfo;
- pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("udp_close: inp == NULL"));
INP_WLOCK(inp);
if (inp->inp_faddr.s_addr != INADDR_ANY) {
- INP_HASH_WLOCK(pcbinfo);
in_pcbdisconnect(inp);
- INP_HASH_WUNLOCK(pcbinfo);
soisdisconnected(so);
}
INP_WUNLOCK(inp);
@@ -1710,9 +1702,7 @@ int
udp_disconnect(struct socket *so)
{
struct inpcb *inp;
- struct inpcbinfo *pcbinfo;
- pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("udp_disconnect: inp == NULL"));
INP_WLOCK(inp);
@@ -1720,9 +1710,7 @@ udp_disconnect(struct socket *so)
INP_WUNLOCK(inp);
return (ENOTCONN);
}
- INP_HASH_WLOCK(pcbinfo);
in_pcbdisconnect(inp);
- INP_HASH_WUNLOCK(pcbinfo);
SOCK_LOCK(so);
so->so_state &= ~SS_ISCONNECTED; /* XXX */
SOCK_UNLOCK(so);
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
index 8a644f96f72e..bc21c31bf446 100644
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -504,13 +504,14 @@ in6_pcbdisconnect(struct inpcb *inp)
{
INP_WLOCK_ASSERT(inp);
- INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo);
KASSERT(inp->inp_smr == SMR_SEQ_INVALID,
("%s: inp %p was already disconnected", __func__, inp));
+ INP_HASH_WLOCK(inp->inp_pcbinfo);
in_pcbremhash(inp);
CK_LIST_INSERT_HEAD(&inp->inp_pcbinfo->ipi_list_unconn, inp,
inp_unconn_list);
+ INP_HASH_WUNLOCK(inp->inp_pcbinfo);
if ((inp->inp_socket->so_proto->pr_flags & PR_CONNREQUIRED) == 0) {
/* See the comment in in_pcbinshash(). */
diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c
index 729be392668a..715f43f0d47c 100644
--- a/sys/netinet6/udp6_usrreq.c
+++ b/sys/netinet6/udp6_usrreq.c
@@ -986,9 +986,7 @@ static void
udp6_abort(struct socket *so)
{
struct inpcb *inp;
- struct inpcbinfo *pcbinfo;
- pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("udp6_abort: inp == NULL"));
@@ -1002,9 +1000,7 @@ udp6_abort(struct socket *so)
#endif
if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
- INP_HASH_WLOCK(pcbinfo);
in6_pcbdisconnect(inp);
- INP_HASH_WUNLOCK(pcbinfo);
soisdisconnected(so);
}
INP_WUNLOCK(inp);
@@ -1104,9 +1100,7 @@ static void
udp6_close(struct socket *so)
{
struct inpcb *inp;
- struct inpcbinfo *pcbinfo;
- pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("udp6_close: inp == NULL"));
@@ -1119,9 +1113,7 @@ udp6_close(struct socket *so)
}
#endif
if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) {
- INP_HASH_WLOCK(pcbinfo);
in6_pcbdisconnect(inp);
- INP_HASH_WUNLOCK(pcbinfo);
soisdisconnected(so);
}
INP_WUNLOCK(inp);
@@ -1243,9 +1235,7 @@ static int
udp6_disconnect(struct socket *so)
{
struct inpcb *inp;
- struct inpcbinfo *pcbinfo;
- pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("udp6_disconnect: inp == NULL"));
@@ -1263,9 +1253,7 @@ udp6_disconnect(struct socket *so)
return (ENOTCONN);
}
- INP_HASH_WLOCK(pcbinfo);
in6_pcbdisconnect(inp);
- INP_HASH_WUNLOCK(pcbinfo);
SOCK_LOCK(so);
so->so_state &= ~SS_ISCONNECTED; /* XXX */
SOCK_UNLOCK(so);