From nobody Sun Apr 12 17:39:58 2026 X-Original-To: dev-commits-src-main@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 4ftyV6703Fz6YR1C for ; Sun, 12 Apr 2026 17:39:58 +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 4ftyV650QDz3LkK for ; Sun, 12 Apr 2026 17:39:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776015598; 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=z8fM6WbX4BSgh2NscXnwLxAKs8I85E+BpODpxuGM9RQ=; b=g/BrVuVW9+vkDLPuFnX/sV9g2Pe4V7FReiIHrZDu/lw5r+OC7wFTYlS0O+3Sx/OK8UB6i+ Ou8ePmH5vh2c3MsfYAzdpH6fR8cCFxgEHSWsJ/7iN9Z8Xs6M25JKpftaVU1QYImMPmfvLE 0cryH8xBRJxIkAHOzG82rLovZjULW7xZtBbwZ92k2dCULpxMONvplTJota6t3sQBAWI0kW pg3/OaCD/1+ZYfcn+Ngo6dZ5PJtsVgulUYM1u0t1deP1Mu1p2qMA4QaDWcwVwNbzmqUC+s 1i1taSkHRcDA0WNg7fU+c/MKLYoPLYcnaO8D6n1oWxlC3tu4zEEO8ACt07EjQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776015598; a=rsa-sha256; cv=none; b=AKGbUA/cxd5GwWVmUQz+al3Y/DjPMi1sG87JAZznSBj+s9gQdTeBPHFzTCyxskdJFRK3FK zlumYpP+cfFvD4/ZAJ6nuwTmXsjMJNDF0pO0wTBrOp0ANqH2awSemTF16pZjCZ7W0SFmvB xcVU/rTdrZ1xwySkVUMYXVKV/1sOnKgxT+ZzSoMl11u+vOgAs7zFJriNAdKRGUc7TjsVnc rLgpXOuzyJmCJF8VlMTLYIr2IJ4rju+BRuKnmplIzj9m5jf6lU1Mpe0SsN82HydMHqu8r2 S1+HiRW//IZnUBoR3QgKE3PD+foA4BBS6WGqAvn5YigNHeCS3n64rcHPu0ayww== 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=1776015598; 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=z8fM6WbX4BSgh2NscXnwLxAKs8I85E+BpODpxuGM9RQ=; b=ST3pyczH5qkTX8SCaXK2HOEAGEgg/AkYHDYb+0l5Jb0s4RhOw/vdaVVWdNZcRrckJ1eU8s glGnkVVpNNnco6c/CTkrXAMxHE9CnJjHnBTWBqS1ShTusygk9Ujcc6XwpXI4AIqEBEY9pz HvZcDG/B2nY8nBtLGYWc5idjDQiakbjIxouNO9p9TwfMXbWJPZP5viTxyW0q3b7LhHx6iD Q36PzJUbNvUBkcycT5wymd3R/p1IwhiPfupg1jyzJ+MDd9dKT+FqnOp/3VuOWEnrKJF1vS QecO9swONQXYFJPIIrvwA5z43HMQrg/hW2fyZhmpewmZi0z0af/YxFL/h8x2ow== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4ftyV64X58zB9Q for ; Sun, 12 Apr 2026 17:39:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 33737 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 12 Apr 2026 17:39:58 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 8e1513dc6738 - main - inpcb: use hashalloc(9) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 8e1513dc67388b8551f202d19440815b8c9120e3 Auto-Submitted: auto-generated Date: Sun, 12 Apr 2026 17:39:58 +0000 Message-Id: <69dbd8ee.33737.398425df@gitrepo.freebsd.org> The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=8e1513dc67388b8551f202d19440815b8c9120e3 commit 8e1513dc67388b8551f202d19440815b8c9120e3 Author: Gleb Smirnoff AuthorDate: 2026-04-12 17:25:57 +0000 Commit: Gleb Smirnoff CommitDate: 2026-04-12 17:25:57 +0000 inpcb: use hashalloc(9) While here remove ipi_lbgrouphashmask, as it is always has the same value as ipi_porthashmask. Differential Revision: https://reviews.freebsd.org/D56174 --- sys/netinet/in_pcb.c | 52 +++++++++++++++++++++++++++++--------------------- sys/netinet/in_pcb.h | 3 +-- sys/netinet6/in6_pcb.c | 2 +- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index f72260834a96..a997c643e8be 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -305,7 +305,7 @@ in_pcblbgroup_find(struct inpcb *inp) INP_HASH_LOCK_ASSERT(pcbinfo); hdr = &pcbinfo->ipi_lbgrouphashbase[ - INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_lbgrouphashmask)]; + INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_porthashmask)]; CK_LIST_FOREACH(grp, hdr, il_list) { struct inpcb *inp1; @@ -413,7 +413,7 @@ in_pcbinslbgrouphash(struct inpcb *inp, uint8_t numa_domain) } #endif - idx = INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_lbgrouphashmask); + idx = INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_porthashmask); hdr = &pcbinfo->ipi_lbgrouphashbase[idx]; CK_LIST_FOREACH(grp, hdr, il_list) { if (grp->il_cred->cr_prison == inp->inp_cred->cr_prison && @@ -474,7 +474,7 @@ in_pcbremlbgrouphash(struct inpcb *inp) INP_HASH_WLOCK_ASSERT(pcbinfo); hdr = &pcbinfo->ipi_lbgrouphashbase[ - INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_lbgrouphashmask)]; + INP_PCBPORTHASH(inp->inp_lport, pcbinfo->ipi_porthashmask)]; CK_LIST_FOREACH(grp, hdr, il_list) { for (i = 0; i < grp->il_inpcnt; ++i) { if (grp->il_inp[i] != inp) @@ -545,9 +545,6 @@ in_pcblbgroup_numa(struct inpcb *inp, int arg) return (error); } -/* Make sure it is safe to use hashinit(9) on CK_LIST. */ -CTASSERT(sizeof(struct inpcbhead) == sizeof(LIST_HEAD(, inpcb))); - /* * Initialize an inpcbinfo - a per-VNET instance of connections db. */ @@ -555,6 +552,11 @@ void in_pcbinfo_init(struct inpcbinfo *pcbinfo, struct inpcbstorage *pcbstor, u_int hash_nelements, u_int porthash_nelements) { + struct hashalloc_args ha = { + .mtype = M_PCB, + .mflags = M_WAITOK, + .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, @@ -564,15 +566,17 @@ in_pcbinfo_init(struct inpcbinfo *pcbinfo, struct inpcbstorage *pcbstor, #endif CK_LIST_INIT(&pcbinfo->ipi_listhead); pcbinfo->ipi_count = 0; - pcbinfo->ipi_hash_exact = hashinit(hash_nelements, M_PCB, - &pcbinfo->ipi_hashmask); - pcbinfo->ipi_hash_wild = hashinit(hash_nelements, M_PCB, - &pcbinfo->ipi_hashmask); - porthash_nelements = imin(porthash_nelements, IPPORT_MAX + 1); - pcbinfo->ipi_porthashbase = hashinit(porthash_nelements, M_PCB, - &pcbinfo->ipi_porthashmask); - pcbinfo->ipi_lbgrouphashbase = hashinit(porthash_nelements, M_PCB, - &pcbinfo->ipi_lbgrouphashmask); + + ha.size = hash_nelements; + pcbinfo->ipi_hash_exact = hashalloc(&ha); + pcbinfo->ipi_hash_wild = hashalloc(&ha); + pcbinfo->ipi_hashmask = ha.size - 1; + + ha.size = imin(porthash_nelements, IPPORT_MAX + 1); + pcbinfo->ipi_porthashbase = hashalloc(&ha); + pcbinfo->ipi_lbgrouphashbase = hashalloc(&ha); + pcbinfo->ipi_porthashmask = ha.size - 1; + pcbinfo->ipi_zone = pcbstor->ips_zone; pcbinfo->ipi_smr = uma_zone_get_smr(pcbinfo->ipi_zone); } @@ -583,16 +587,20 @@ in_pcbinfo_init(struct inpcbinfo *pcbinfo, struct inpcbstorage *pcbstor, void in_pcbinfo_destroy(struct inpcbinfo *pcbinfo) { + struct hashalloc_args ha = { + .mtype = M_PCB, + .head = HASH_HEAD_CK_LIST, + }; KASSERT(pcbinfo->ipi_count == 0, ("%s: ipi_count = %u", __func__, pcbinfo->ipi_count)); - hashdestroy(pcbinfo->ipi_hash_exact, M_PCB, pcbinfo->ipi_hashmask); - hashdestroy(pcbinfo->ipi_hash_wild, M_PCB, pcbinfo->ipi_hashmask); - hashdestroy(pcbinfo->ipi_porthashbase, M_PCB, - pcbinfo->ipi_porthashmask); - hashdestroy(pcbinfo->ipi_lbgrouphashbase, M_PCB, - pcbinfo->ipi_lbgrouphashmask); + ha.size = pcbinfo->ipi_hashmask + 1; + hashfree(pcbinfo->ipi_hash_exact, &ha); + hashfree(pcbinfo->ipi_hash_wild, &ha); + ha.size = pcbinfo->ipi_porthashmask + 1; + hashfree(pcbinfo->ipi_porthashbase, &ha); + hashfree(pcbinfo->ipi_lbgrouphashbase, &ha); mtx_destroy(&pcbinfo->ipi_hash_lock); mtx_destroy(&pcbinfo->ipi_lock); } @@ -2107,7 +2115,7 @@ in_pcblookup_lbgroup(const struct inpcbinfo *pcbinfo, NET_EPOCH_ASSERT(); hdr = &pcbinfo->ipi_lbgrouphashbase[ - INP_PCBPORTHASH(lport, pcbinfo->ipi_lbgrouphashmask)]; + INP_PCBPORTHASH(lport, pcbinfo->ipi_porthashmask)]; /* * Search for an LB group match based on the following criteria: diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 6f842f64775e..a1b547462d53 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -470,19 +470,18 @@ struct inpcbinfo { struct inpcbhead *ipi_hash_exact; /* (r:e/w:h) */ struct inpcbhead *ipi_hash_wild; /* (r:e/w:h) */ u_long ipi_hashmask; /* (c) */ + u_long ipi_porthashmask; /* (h) */ /* * Global hash of inpcbs, hashed by only local port number. */ struct inpcbhead *ipi_porthashbase; /* (h) */ - u_long ipi_porthashmask; /* (h) */ /* * Load balance groups used for the SO_REUSEPORT_LB option, * hashed by local port. */ struct inpcblbgrouphead *ipi_lbgrouphashbase; /* (r:e/w:h) */ - u_long ipi_lbgrouphashmask; /* (h) */ /* * Pointer to network stack instance diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 216051156767..f8ce64a65998 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -879,7 +879,7 @@ in6_pcblookup_lbgroup(const struct inpcbinfo *pcbinfo, NET_EPOCH_ASSERT(); hdr = &pcbinfo->ipi_lbgrouphashbase[ - INP_PCBPORTHASH(lport, pcbinfo->ipi_lbgrouphashmask)]; + INP_PCBPORTHASH(lport, pcbinfo->ipi_porthashmask)]; /* * Search for an LB group match based on the following criteria: