From nobody Tue Apr 28 06:45:01 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 4g4WC20tyGz6bRVY for ; Tue, 28 Apr 2026 06:45:02 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g4WC14gCzz3ZQN for ; Tue, 28 Apr 2026 06:45:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777358701; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KQcS5QL++D/H3Lp8qc9QD1IpFE3SUDNuMK3SHePpzuY=; b=yh0BCn6dFGeIBYs0hp9cso7jsOqwCI7YWg2w+8CnusQfVK4ER7wUYNPUXRC196VJmbx9Si z6wGlK7k5b78XA4hTqCK7Y/rkTP53auZ6kE/9DNT/jPTvSmh4FIhhAss4dyzx5/6fsxbfD pE5KyWOOIBlU7wcJgXKtdMXTPIKCaKg/Zh3nn3EPz6IexfsGJxvYCGcZF1xd/4KexIwgbF ILWO2knKkJVWJH4TEsl4rCbEpWiq+fF2yJ5viM2zkL0yYOOs/PeSrqHt4IS2OcWRWNbC8L txx85fKULlX6nJTb9cd8eSPDKTdW75JvUAglISIOnh0Qqyz7O0Jie/8dV4Lr5w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777358701; a=rsa-sha256; cv=none; b=ruauyrIzahOVuKJ850iJgsck0YyS82+g7rlYR3alYbMukKXbLRehWlf+b28BW9ZyQor2Ta x09nyZKyS0y2C9mwQ1zOt2OyJIEuiU4uuzUwVBw711yH5zO8cVkMxw9t0asQj8qGq6k7Og Fr1ZUDAr6mIvBGsT0Sz/WgG2src5DRtaKabPZYdIGqSh03nUMoBPQ0y9w68K9Elxa243tP uWXGyG4qoaOs/gkLZceOC1YIu79zq5pvT5CjnmApHYnKSaRnJmmkLOdLLQ5682HyNS9Af7 Z9RY04dGg680EWt5uugqvH6rnVomoY8Xj/S17SYXB2eZYD6d2F5835sUgwn5Bg== 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=1777358701; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KQcS5QL++D/H3Lp8qc9QD1IpFE3SUDNuMK3SHePpzuY=; b=yoTM5uun3TivZ0BZe9YKGrACajC46GDo0DQpw64yIeCv43/ijUnlRseBFI10KdS6bFSLqE sPT4hpQKtJDvImr1UwSr8+gS0LJZzDfEeB8GnysClup+vY5EmewFD5+1M05sUKBXri56tG D89T0hgmsvqgwWbY4lAJqNTiHnG3sRqpmZFqoQpDFlerKNKfkPziiSk5wFbNEFE+OLsHjk ItmnFvMX3e/J3tOHqG0Qj4dRHSiTu3MaAJap6IUPuMn9X0x6bmkvtO0LDJb0rUiPxadI54 PbP1T3+6PBowVli7rZCLLra6Uh/LhzYAB2Qoo609YVDuev1Qs7g5aRKHks4K0Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g4WC13kK6zjdR for ; Tue, 28 Apr 2026 06:45:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 31bac by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 28 Apr 2026 06:45:01 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Chandrakanth Patil From: Sumit Saxena Subject: git: ea4ab7e36ed9 - main - bnxt_en: Add per-VF trust, spoof-check and promiscuous controls 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: ssaxena X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ea4ab7e36ed9cf153c374782be446254a7d11822 Auto-Submitted: auto-generated Date: Tue, 28 Apr 2026 06:45:01 +0000 Message-Id: <69f0576d.31bac.79d6ce26@gitrepo.freebsd.org> The branch main has been updated by ssaxena: URL: https://cgit.FreeBSD.org/src/commit/?id=ea4ab7e36ed9cf153c374782be446254a7d11822 commit ea4ab7e36ed9cf153c374782be446254a7d11822 Author: Chandrakanth Patil AuthorDate: 2026-03-31 16:59:01 +0000 Commit: Sumit Saxena CommitDate: 2026-04-28 06:32:12 +0000 bnxt_en: Add per-VF trust, spoof-check and promiscuous controls Expose per-VF policy knobs via the FreeBSD sysctl tree and enforce them at the data-path level. Trust (dev.bnxt..vfN.trusted): bnxt_set_vf_trust() sets/clears BNXT_VF_TRUST and sends HWRM_FUNC_CFG with FLAGS_TRUSTED_VF_ENABLE/DISABLE. bnxt_create_trusted_vf_sysctls() / bnxt_destroy_trusted_vf_sysctls() manage the sysctl lifetime with VF creation/teardown. Spoof-check (dev.bnxt..vfN.spoofchk): bnxt_set_vf_spoofchk() issues HWRM_FUNC_CFG with SRC_MAC_ADDR_CHECK_ENABLE/DISABLE. Promiscuous gating: bnxt_is_trusted_vf() queries firmware via HWRM_FUNC_QCFG. bnxt_promisc_ok() returns false for untrusted VFs, preventing them from entering promiscuous mode. bnxt_promisc_set() is updated to gate the PROMISCUOUS and ANYVLAN_NONVLAN mask bits on bnxt_promisc_ok(). bnxt_iov_vf_add() applies the initial trust/spoof-check policy from the nvlist schema. bnxt_iov_init() creates the sysctl trees after bnxt_cfg_hw_sriov() succeeds. bnxt_iov_uninit() tears them down. MFC after: 1 month Reviewed by: ssaxena Differential Revision: https://reviews.freebsd.org/D56200 --- sys/dev/bnxt/bnxt_en/bnxt_sriov.c | 267 +++++++++++++++++++++++++++++++++++++- sys/dev/bnxt/bnxt_en/if_bnxt.c | 6 +- 2 files changed, 270 insertions(+), 3 deletions(-) diff --git a/sys/dev/bnxt/bnxt_en/bnxt_sriov.c b/sys/dev/bnxt/bnxt_en/bnxt_sriov.c index 9bec955f9890..2d9b43728c2d 100644 --- a/sys/dev/bnxt/bnxt_en/bnxt_sriov.c +++ b/sys/dev/bnxt/bnxt_en/bnxt_sriov.c @@ -7,7 +7,6 @@ #include "bnxt_hwrm.h" #include "bnxt_sriov.h" - static int bnxt_set_vf_admin_mac(struct bnxt_softc *softc, struct bnxt_vf_info *vf, const uint8_t *mac) @@ -89,6 +88,9 @@ bnxt_iov_vf_add(if_ctx_t ctx, uint16_t vfnum, const nvlist_t *params) vfnum, rc); } + (void)bnxt_set_vf_trust(softc, vfnum, vf->trusted); + (void)bnxt_set_vf_spoofchk(softc, vfnum, vf->spoofchk); + return 0; } @@ -157,6 +159,7 @@ void bnxt_iov_uninit(if_ctx_t ctx) if (rc) device_printf(softc->dev, "VF resource free HWRM failed: %d\n", rc); + bnxt_destroy_trusted_vf_sysctls(softc); bnxt_free_vf_resources(softc); BNXT_SRIOV_LOCK_DESTROY(softc); } @@ -349,6 +352,75 @@ bnxt_is_trusted_vf(struct bnxt_softc *softc, struct bnxt_vf_info *vf) return !!(vf->func_qcfg_flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF); } +bool bnxt_promisc_ok(struct bnxt_softc *softc) +{ + if (BNXT_VF(softc) && !bnxt_is_trusted_vf(softc, &softc->vf)) + return false; + return true; +} + +static int +bnxt_hwrm_set_trusted_vf(struct bnxt_softc *softc, struct bnxt_vf_info *vf) +{ + struct hwrm_func_cfg_input req = {0}; + int rc; + + if (!(softc->fw_cap & BNXT_FW_CAP_TRUSTED_VF)) + return (EOPNOTSUPP); + + bnxt_hwrm_cmd_hdr_init(softc, &req, HWRM_FUNC_CFG); + + req.fid = htole16(vf->fw_fid); + + if (vf->flags & BNXT_VF_TRUST) + req.flags = cpu_to_le32(HWRM_FUNC_CFG_INPUT_FLAGS_TRUSTED_VF_ENABLE); + else + req.flags = cpu_to_le32(HWRM_FUNC_CFG_INPUT_FLAGS_TRUSTED_VF_DISABLE); + + BNXT_HWRM_LOCK(softc); + rc = _hwrm_send_message(softc, &req, sizeof(req)); + BNXT_HWRM_UNLOCK(softc); + if (rc) + device_printf(softc->dev, "bnxt_hwrm_set_trusted_vf failed. rc:%d\n", rc); + + return rc; +} + +int +bnxt_set_vf_trust(struct bnxt_softc *softc, int vf_id, bool trusted) +{ + int rc; + struct bnxt_vf_info *vf = NULL; + + BNXT_SRIOV_LOCK(softc); + if (softc->pf.num_vfs == 0 || vf_id >= softc->pf.num_vfs) { + BNXT_SRIOV_UNLOCK(softc); + return (ENOENT); + } + vf = &softc->pf.vf[vf_id]; + + if (trusted) + vf->flags |= BNXT_VF_TRUST; + else + vf->flags &= ~BNXT_VF_TRUST; + + BNXT_SRIOV_UNLOCK(softc); + + rc = bnxt_hwrm_set_trusted_vf(softc, vf); + if (rc == 0) { + BNXT_SRIOV_LOCK(softc); + if (softc->pf.num_vfs != 0 && vf_id < softc->pf.num_vfs) { + vf = &softc->pf.vf[vf_id]; + if (trusted) + vf->flags |= BNXT_VF_TRUST; + else + vf->flags &= ~BNXT_VF_TRUST; + } + BNXT_SRIOV_UNLOCK(softc); + } + return rc; +} + static int bnxt_vf_configure_mac(struct bnxt_softc *softc, struct bnxt_vf_info *vf) { @@ -452,6 +524,186 @@ void bnxt_hwrm_exec_fwd_req(struct bnxt_softc *softc) } } +/* destroy VF sysctls when VFs are removed / PF detaches. */ +void +bnxt_destroy_trusted_vf_sysctls(struct bnxt_softc *softc) +{ + sysctl_ctx_free(&softc->pf.sysctl_ctx); +} + +/* Handler for: dev.bnxt..vf.trusted (0/1) */ +static int +bnxt_sysctl_vf_trusted(SYSCTL_HANDLER_ARGS) +{ + struct bnxt_softc *softc = (struct bnxt_softc *)arg1; + int vf_id = (int)arg2; + int val, rc; + + BNXT_SRIOV_LOCK(softc); + if (softc->pf.num_vfs == 0 || vf_id < 0 || vf_id >= softc->pf.num_vfs) { + BNXT_SRIOV_UNLOCK(softc); + return (ENOENT); + } + val = (softc->pf.vf[vf_id].flags & BNXT_VF_TRUST) ? 1 : 0; + BNXT_SRIOV_UNLOCK(softc); + + rc = sysctl_handle_int(oidp, &val, 0, req); + if (rc) + return rc; + + /* If no new value supplied, it was a READ */ + if (req->newptr == NULL) + return 0; + + /* WRITE path: 'val' now holds the user's 0/1 */ + rc = bnxt_set_vf_trust(softc, vf_id, (val != 0)); + + return rc; +} + +/* + * Create per-VF sysctls: + * dev.bnxt..vf0.trusted + * dev.bnxt..vf1.trusted + * .. + */ +int +bnxt_create_trusted_vf_sysctls(struct bnxt_softc *softc, uint16_t num_vfs) +{ + struct sysctl_oid_list *root_list; + struct sysctl_oid *vf_node; + char node_name[16]; + + /* use the device's sysctl tree as root: dev.bnxt.. */ + sysctl_ctx_init(&softc->pf.sysctl_ctx); + root_list = SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)); + + for (int i = 0; i < num_vfs; i++) { + snprintf(node_name, sizeof(node_name), "vf%d", i); + + /* dev.bnxt..vfN */ + vf_node = SYSCTL_ADD_NODE(&softc->pf.sysctl_ctx, + root_list, OID_AUTO, + node_name, CTLFLAG_RW, 0, "VF node"); + + /* dev.bnxt..vfN.trusted */ + SYSCTL_ADD_PROC(&softc->pf.sysctl_ctx, + SYSCTL_CHILDREN(vf_node), + OID_AUTO, "trusted", + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, + softc, i, bnxt_sysctl_vf_trusted, "I", + "0=untrusted (default), 1=trusted"); + } + return 0; +} + +static int +bnxt_hwrm_set_vf_spoofchk(struct bnxt_softc *sc, struct bnxt_vf_info *vf, + bool enable) +{ + struct hwrm_func_cfg_input req = {0}; + int rc = 0; + + bnxt_hwrm_cmd_hdr_init(sc, &req, HWRM_FUNC_CFG); + + req.fid = htole16(vf->fw_fid); + req.flags = htole32(enable ? + HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_ENABLE : + HWRM_FUNC_CFG_INPUT_FLAGS_SRC_MAC_ADDR_CHECK_DISABLE); + + BNXT_HWRM_LOCK(sc); + rc = _hwrm_send_message(sc, &req, sizeof(req)); + BNXT_HWRM_UNLOCK(sc); + if (rc) + device_printf(sc->dev, "bnxt_hwrm_set_vf_spoofchk failed. rc:%d\n", rc); + + return rc; +} + +int +bnxt_set_vf_spoofchk(struct bnxt_softc *sc, int vf_id, bool enable) +{ + struct bnxt_vf_info *vf; + int rc; + + BNXT_SRIOV_LOCK(sc); + if (sc->pf.num_vfs == 0 || vf_id >= sc->pf.num_vfs) { + BNXT_SRIOV_UNLOCK(sc); + return (ENOENT); + } + vf = &sc->pf.vf[vf_id]; + BNXT_SRIOV_UNLOCK(sc); + + rc = bnxt_hwrm_set_vf_spoofchk(sc, vf, enable); + if (rc == 0) { + BNXT_SRIOV_LOCK(sc); + if (sc->pf.num_vfs != 0 && vf_id < sc->pf.num_vfs) { + vf = &sc->pf.vf[vf_id]; + if (enable) + vf->flags |= BNXT_VF_SPOOFCHK; + else + vf->flags &= ~BNXT_VF_SPOOFCHK; + } + BNXT_SRIOV_UNLOCK(sc); + } + return rc; +} + +static int +bnxt_sysctl_vf_spoofchk(SYSCTL_HANDLER_ARGS) +{ + struct bnxt_softc *sc = (struct bnxt_softc *)arg1; + int vf_id = (int)arg2; + int val, rc; + + BNXT_SRIOV_LOCK(sc); + if (sc->pf.num_vfs == 0 || vf_id >= sc->pf.num_vfs) { + BNXT_SRIOV_UNLOCK(sc); + return (ENOENT); + } + val = (sc->pf.vf[vf_id].flags & BNXT_VF_SPOOFCHK) ? 1 : 0; + BNXT_SRIOV_UNLOCK(sc); + + rc = sysctl_handle_int(oidp, &val, 0, req); + if (rc || req->newptr == NULL) + return rc; + + return bnxt_set_vf_spoofchk(sc, vf_id, val != 0); +} + +/* + * Create per-VF spoofchk: + * dev.bnxt..vf0.spoofchk + * dev.bnxt..vf1.spoofchk + * .. + */ +int +bnxt_create_spoofchk_vf_sysctls(struct bnxt_softc *softc, uint16_t num_vfs) +{ + struct sysctl_oid_list *root_list; + struct sysctl_oid *vf_node; + char node_name[16]; + + /* Reuse the same ctx & root tree as trusted vf */ + root_list = SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)); + + for (int i = 0; i < num_vfs; i++) { + snprintf(node_name, sizeof(node_name), "vf%d", i); + + vf_node = SYSCTL_ADD_NODE(&softc->pf.sysctl_ctx, + root_list, OID_AUTO, + node_name, CTLFLAG_RW, 0, "VF node"); + + SYSCTL_ADD_PROC(&softc->pf.sysctl_ctx, + SYSCTL_CHILDREN(vf_node), + OID_AUTO, "spoofchk", + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, + softc, i, bnxt_sysctl_vf_spoofchk, "I", + "0=spoofchk off, 1=spoofchk on"); + } + return 0; +} + static int bnxt_hwrm_func_vf_resc_cfg(struct bnxt_softc *softc, int num_vfs, bool reset) { @@ -673,6 +925,17 @@ bnxt_iov_init(if_ctx_t ctx, uint16_t num_vfs, const nvlist_t *params) if (rc) goto fail_free_vf_resc; + rc = bnxt_create_trusted_vf_sysctls(softc, num_vfs); + if (rc) { + device_printf(softc->dev, "trusted VF sysctl creation failed (error=%d)\n", rc); + goto fail_free_hwrm_vf_resc; + } + + rc = bnxt_create_spoofchk_vf_sysctls(softc, num_vfs); + if (rc) { + device_printf(softc->dev, "spoof check VF sysctl creation failed (error=%d)\n", rc); + goto fail_free_hwrm_vf_resc; + } BNXT_SRIOV_LOCK(softc); softc->pf.num_vfs = num_vfs; @@ -680,6 +943,8 @@ bnxt_iov_init(if_ctx_t ctx, uint16_t num_vfs, const nvlist_t *params) return 0; +fail_free_hwrm_vf_resc: + bnxt_hwrm_func_vf_resource_free(softc, num_vfs); fail_free_vf_resc: bnxt_free_vf_resources(softc); fail_lock: diff --git a/sys/dev/bnxt/bnxt_en/if_bnxt.c b/sys/dev/bnxt/bnxt_en/if_bnxt.c index 83cace50291f..8023ee1524c5 100644 --- a/sys/dev/bnxt/bnxt_en/if_bnxt.c +++ b/sys/dev/bnxt/bnxt_en/if_bnxt.c @@ -3730,13 +3730,15 @@ bnxt_promisc_set(if_ctx_t ctx, int flags) softc->vnic_info.rx_mask &= ~HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST; - if (if_getflags(ifp) & IFF_PROMISC) + if ((if_getflags(ifp) & IFF_PROMISC) && + bnxt_promisc_ok(softc)) softc->vnic_info.rx_mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS | HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN; else softc->vnic_info.rx_mask &= - ~(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS); + ~(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS | + HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ANYVLAN_NONVLAN); rc = bnxt_hwrm_cfa_l2_set_rx_mask(softc, &softc->vnic_info);