D.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" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dWm7S4sbtz4LKV for ; Wed, 17 Dec 2025 20:47:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766004420; 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=7jXXEljmSoQqBVyklVAeDyqKYMcstkwZyA2AqnhwClE=; b=skDEJ5YdaTGD0e76H+XDAtaDl7OZJ79M32heGe21JZ14Pcyymhg6Lf72IbjpDz0xtPjyDQ Ki006uVmBX8Imiu4iTQK0w0Ne8SOb1mor7bkfemUJ8UW1Xp6tbQhdd5KUawm5lVGePvJxg PSPcPkVEQbgIyUobM+rISJfJr8Ni8M27XHNY+r15I8H2Q/BcZCipoeMv4Ob+nFxo479Hfu EPGbrIG8Jo2Y6el18/bWsSw6K8JAFYxLVE14+zk5CruKKEzntmuQHSS/zJeQ7FOcVlrATJ F+y4F3+YLIaX2S3uVABtd/kZGFV5b5xXshh3SchSSrEiYCn3mo2UIx5EFoECoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766004420; 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=7jXXEljmSoQqBVyklVAeDyqKYMcstkwZyA2AqnhwClE=; b=vctht5afmBMlGSBKRIpfQpQOa9dlKI5m6q1zabLHIQFxsLmaWhomyuPOH4CggFwvcpCkpN ISGaMutaRisrqvLMgOiczIXMIEdybXaMhkvXQgFiNVxDcn9ZbIRCIXFFzwZaA6rNxR3hjY aR3L3DQ4bdNlUU3ZqZcuswAOSQTLXKriReApDcOzmFV1Spgpe7t7z1GzzovuN3s6amVgcp Ui6xgyY2frjyMO7lO/3ONqArycM+SjktX22MOhaJrpKaXhYTdIwAcYd9In/IM7nNwf2XqY SztgBUqDiokuhyIrfp4YFIGT3XiCdAoDlB5hxTFqsxfutkTHFFgf/LvKCEPeZQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1766004420; a=rsa-sha256; cv=none; b=jFEAVOsbvq0RPPz8h5nttfx/GOPXY3uHZrM7inRNZgwePb5wWknqJeN6kqgyhi5IvfrGd7 T69UFkgjYmseDR/awVKbZ1pQB8Y5gWZVr/f4u3YEtxaCjPLur/G2BbnMRHuTznbmtl2R5J elr9vXti+m4j116HfN/mIICSBPnpzxtpDBq3lSTGaj4cMg7+FsQtON6F1zd0OBSlWhjBRF ++L8qsOuTKr4LYX0X4/yeZrs3pLqEfiwnmsso6J12VP7O+WBDFDmZZzGBtisZoyrVMrgfJ ZB45+znlrfMBh9V81c7qetFn/czVu3DytJ7DYGtymC5RS3KT7myGD2wusvwFMQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dWm7S4SQzz174R for ; Wed, 17 Dec 2025 20:47:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3d86b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 17 Dec 2025 20:47:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 0bf42a0a05b9 - main - bpf: virtualize bpf_iflist 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: 0bf42a0a05b9c802a6d9ca4a6b8696b29a26e08b Auto-Submitted: auto-generated Date: Wed, 17 Dec 2025 20:47:00 +0000 Message-Id: <694316c4.3d86b.2da7d434@gitrepo.freebsd.org> The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=0bf42a0a05b9c802a6d9ca4a6b8696b29a26e08b commit 0bf42a0a05b9c802a6d9ca4a6b8696b29a26e08b Author: Gleb Smirnoff AuthorDate: 2025-12-17 20:41:05 +0000 Commit: Gleb Smirnoff CommitDate: 2025-12-17 20:41:05 +0000 bpf: virtualize bpf_iflist The reason the global list worked before 8774a990ee40 is that bpf_setif() used if_unit(), which is a VNET-aware function, and then went through the global list looking for bpf_if with matching pointer. PR: 291735 Fixes: 8774a990ee4094f16d596d4b78e0f3239e5d0c88 --- sys/net/bpf.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 4026c44112ab..54da49f3d656 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -221,7 +221,8 @@ struct bpf_dltlist32 { * structures registered by different layers in the stack (i.e., 802.11 * frames, ethernet frames, etc). */ -static LIST_HEAD(, bpf_if) bpf_iflist = LIST_HEAD_INITIALIZER(); +VNET_DEFINE_STATIC(LIST_HEAD(, bpf_if), bpf_iflist) = LIST_HEAD_INITIALIZER(); +#define V_bpf_iflist VNET(bpf_iflist) static struct sx bpf_sx; /* bpf global lock */ static void bpfif_ref(struct bpf_if *); @@ -257,7 +258,8 @@ SYSCTL_INT(_net_bpf, OID_AUTO, maxinsns, CTLFLAG_RW, static int bpf_zerocopy_enable = 0; SYSCTL_INT(_net_bpf, OID_AUTO, zerocopy_enable, CTLFLAG_RW, &bpf_zerocopy_enable, 0, "Enable new zero-copy BPF buffer sessions"); -static SYSCTL_NODE(_net_bpf, OID_AUTO, stats, CTLFLAG_MPSAFE | CTLFLAG_RW, +static SYSCTL_NODE(_net_bpf, OID_AUTO, stats, + CTLFLAG_VNET | CTLFLAG_MPSAFE | CTLFLAG_RW, bpf_stats_sysctl, "bpf statistics portal"); VNET_DEFINE_STATIC(int, bpf_optimize_writers) = 0; @@ -1401,7 +1403,7 @@ bpfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, /* * Look through attached interfaces for the named one. */ - LIST_FOREACH(bp, &bpf_iflist, bif_next) { + LIST_FOREACH(bp, &V_bpf_iflist, bif_next) { if (strncmp(ifr->ifr_name, bp->bif_name, sizeof(ifr->ifr_name)) == 0) break; @@ -1728,7 +1730,7 @@ bpf_getiflist(struct bpf_iflist *bi) BPF_LOCK(); cnt = allsize = size = 0; - LIST_FOREACH(bp, &bpf_iflist, bif_next) { + LIST_FOREACH(bp, &V_bpf_iflist, bif_next) { allsize += strlen(bp->bif_name) + 1; if (++cnt == bi->bi_count) size = allsize; @@ -1748,7 +1750,7 @@ bpf_getiflist(struct bpf_iflist *bi) uaddr = bi->bi_ubuf; cnt = 0; - LIST_FOREACH(bp, &bpf_iflist, bif_next) { + LIST_FOREACH(bp, &V_bpf_iflist, bif_next) { u_int len; int error; @@ -2654,7 +2656,7 @@ bpf_attach(const char *name, u_int dlt, u_int hdrlen, bp->bif_methods = methods; refcount_init(&bp->bif_refcnt, 1); BPF_LOCK(); - LIST_INSERT_HEAD(&bpf_iflist, bp, bif_next); + LIST_INSERT_HEAD(&V_bpf_iflist, bp, bif_next); BPF_UNLOCK(); return (bp); @@ -2672,7 +2674,7 @@ bpf_ifdetach(struct ifnet *ifp) struct bpf_d *d; BPF_LOCK(); - LIST_FOREACH(bp, &bpf_iflist, bif_next) { + LIST_FOREACH(bp, &V_bpf_iflist, bif_next) { /* XXXGL: assuming softc is ifnet here */ if (bp->bif_softc != ifp) continue; @@ -2743,7 +2745,7 @@ bpf_getdltlist(struct bpf_d *d, struct bpf_dltlist *bfl) name = d->bd_bif->bif_name; n1 = 0; - LIST_FOREACH(bp, &bpf_iflist, bif_next) { + LIST_FOREACH(bp, &V_bpf_iflist, bif_next) { if (bp->bif_name == name) n1++; } @@ -2756,7 +2758,7 @@ bpf_getdltlist(struct bpf_d *d, struct bpf_dltlist *bfl) lst = malloc(n1 * sizeof(u_int), M_TEMP, M_WAITOK); n = 0; - LIST_FOREACH(bp, &bpf_iflist, bif_next) { + LIST_FOREACH(bp, &V_bpf_iflist, bif_next) { if (bp->bif_name != name) continue; lst[n++] = bp->bif_dlt; @@ -2795,7 +2797,7 @@ bpf_setdlt(struct bpf_d *d, u_int dlt) return (0); name = d->bd_bif->bif_name; - LIST_FOREACH(bp, &bpf_iflist, bif_next) { + LIST_FOREACH(bp, &V_bpf_iflist, bif_next) { if (bp->bif_name == name && bp->bif_dlt == dlt) break; } @@ -2843,7 +2845,7 @@ bpf_zero_counters(void) * We are protected by global lock here, interfaces and * descriptors can not be deleted while we hold it. */ - LIST_FOREACH(bp, &bpf_iflist, bif_next) { + LIST_FOREACH(bp, &V_bpf_iflist, bif_next) { CK_LIST_FOREACH(bd, &bp->bif_dlist, bd_next) { counter_u64_zero(bd->bd_rcount); counter_u64_zero(bd->bd_dcount); @@ -2930,7 +2932,7 @@ bpf_stats_sysctl(SYSCTL_HANDLER_ARGS) } bpfd_cnt = 0; BPF_LOCK(); - LIST_FOREACH(bp, &bpf_iflist, bif_next) { + LIST_FOREACH(bp, &V_bpf_iflist, bif_next) { CK_LIST_FOREACH(bd, &bp->bif_wlist, bd_next) bpfd_cnt++; CK_LIST_FOREACH(bd, &bp->bif_dlist, bd_next) @@ -2946,7 +2948,7 @@ bpf_stats_sysctl(SYSCTL_HANDLER_ARGS) } xbdbuf = malloc(bpfd_cnt * sizeof(*xbd), M_BPF, M_WAITOK); index = 0; - LIST_FOREACH(bp, &bpf_iflist, bif_next) { + LIST_FOREACH(bp, &V_bpf_iflist, bif_next) { /* Send writers-only first */ CK_LIST_FOREACH(bd, &bp->bif_wlist, bd_next) { MPASS(index <= bpfd_cnt);