From nobody Fri Aug 7 05:50:14 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 4hGYCB3CkXz6nxg1 for ; Fri, 07 Aug 2026 05:50:14 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hGYCB20tvz3L2f for ; Fri, 07 Aug 2026 05:50:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786081814; 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=bxcWjF7tL4sGYdYzTzODRNLMmxeRl6tuRXvyU+WN6nk=; b=qWZl5F8Ke1pH/1KXSJFTxzp0LBtb1d+GU7kHH1SUfuVC+/IY6kVwVokRAJ4HZdWyldbGhd wVylIz0POOm7e9A6GbB5KfY8chEUhzusCHkV2hD0spaBwzKqpSjV0eZlfdwMMfBzjCDSYt 5tsV6q3xwgac0NSd2LddUKnWL1U7InOzj64/FSO/DNfZoJ/eQhqjC1wDp8SgM4VwGkmgYV Qehimb2cSSu3XZr0FFew7iw707onTzQxlYVJmwq/hpGIlYEvqnzRNqMgUS7IHnJDzba5pN 43dkI59eXs1BEwjL6az3iZ5oc67sqPd9mrBRUfFXg71kMfDGyIezaPBz8Uljyg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786081814; a=rsa-sha256; cv=none; b=pdsNjvlnEfCI4ztFt7VGyvBKWgaE366jdQqPTMGi4sclrbSozvIggc+3aJsS8Ayzb2IqNM Cmr41Zvst8QmtfveyU+G1wNpSrQOqPiOPJ+pLgZS5i/LIKJSC4G2BGZv0BA47RpFRNYlqG 4KEyJB2tJq5QQiE6Y4gahie6F6uPUOr4sFbn9trHHKBUk4vVbmASH+9bSzBhcnLEeYHlx/ lELOZj32yLTyB5Oj7tJ29SAuoS/AMT1+8amKjzmthAWRgmbEuOMFfvge3iSG8HTA6wIpdb 8wsp/U3lL+WKW/zbo46z2Dc1AhqLVUDLuWjFlZuah5xcPqHZaNb98A5F/fl2hg== 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=1786081814; 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=bxcWjF7tL4sGYdYzTzODRNLMmxeRl6tuRXvyU+WN6nk=; b=eyDxc2SFuK8L3ZIkH6p8T4s+wRJk9cgg8efNlnoYsMhBKQc7iEWDbGHtvWx4uof4hiEa8p 2Kfh8AZ62nsNCgd6p/TSyGIroy/wFht/zxbH7YVBzRa5uon+24P/6vOllzhtntldh3QghY A1VUr4eQXSSG6886MDCidukQl56OV+FvMfdoJtn2/LOv9rGPVxkktNtUmCcjNG4hcOXLbH o+lb6fWb6/5p+1FUKdZ5aiuw/5nGSU4qS1DSqtTh9D6OqtdfmZuUZtpxA8+S1b+lpzKHw8 M2eBsJrWXml+yK3X9Tvi3/BvGXbxd0Lw4R/zWBEIugeBC/MISSN461EnqMQOtg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hGYCB0SKszv4R for ; Fri, 07 Aug 2026 05:50:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 37567 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 07 Aug 2026 05:50:14 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kevin Bowling Subject: git: 114f4a68f213 - main - pci: Optionally disable endpoints with unsafe MPS 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 114f4a68f21345e1e6680b7acf1bf733d9047002 Auto-Submitted: auto-generated Date: Fri, 07 Aug 2026 05:50:14 +0000 Message-Id: <6a757216.37567.1c1a1bf0@gitrepo.freebsd.org> The branch main has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=114f4a68f21345e1e6680b7acf1bf733d9047002 commit 114f4a68f21345e1e6680b7acf1bf733d9047002 Author: Kevin Bowling AuthorDate: 2026-08-06 06:42:26 +0000 Commit: Kevin Bowling CommitDate: 2026-08-07 05:49:55 +0000 pci: Optionally disable endpoints with unsafe MPS Keep warn-only behavior as the default. Add an opt-in policy that clears endpoint decoding and bus mastering when a newly discovered function cannot match its active path, while never disabling bridge functions and their subtrees. MFC after: 2 weeks --- share/man/man4/pci.4 | 13 +++++++++++++ sys/dev/pci/pci.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/share/man/man4/pci.4 b/share/man/man4/pci.4 index dc4bf4387057..c84051b1b988 100644 --- a/share/man/man4/pci.4 +++ b/share/man/man4/pci.4 @@ -617,6 +617,19 @@ The maximum amount of memory permitted for the configuration parameters used when creating Virtual Functions via SR-IOV. This tunable can also be changed at runtime via .Xr sysctl 8 . +.It Va hw.pci.mps_enforce Pq Defaults to 0 +Disable a newly discovered PCI-express endpoint if its MPS cannot be safely +reconciled with the active hierarchy. +The default behavior reports the conflict and leaves the device enabled. +When enforcement is enabled, an under-capable endpoint below a PCI-express +switch is disabled rather than retuning the shared path. +PCI bridge functions are never disabled by this policy because doing so could +disconnect otherwise compatible devices in their downstream subtrees. +An administrator can explicitly override the policy with the +.Cm enable +command of +.Xr devctl 8 ; +the device is then attached without repeating the MPS safety check. .It Va hw.pci.mps_limit Pq Defaults to 0 Limit the MPS selected while reconciling a PCI-express hierarchy during cold enumeration. diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 02642ad40239..4663fe043073 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -442,6 +442,11 @@ SYSCTL_INT(_hw_pci, OID_AUTO, mps_limit, CTLFLAG_RDTUN, &pci_mps_limit, 0, "Limit PCIe MPS to this many bytes (power of two from 128 to 4096)"); static bool pci_mps_limit_warned; +static bool pci_mps_enforce; +SYSCTL_BOOL(_hw_pci, OID_AUTO, mps_enforce, CTLFLAG_RDTUN, + &pci_mps_enforce, 0, + "Disable PCIe endpoints with an MPS incompatible with their shared path"); + static bool pci_intx_reroute = true; SYSCTL_BOOL(_hw_pci, OID_AUTO, intx_reroute, CTLFLAG_RWTUN, &pci_intx_reroute, 0, "Re-route INTx interrupts when scanning devices"); @@ -4518,26 +4523,60 @@ pcie_mps_conflict(device_t dev, uint16_t path_mps, uint16_t max_mps) pcie_mps_bytes(max_mps), pcie_mps_bytes(path_mps)); } +static bool +pcie_mps_is_bridge(struct pci_devinfo *dinfo) +{ + uint8_t hdrtype; + + hdrtype = dinfo->cfg.hdrtype & PCIM_HDRTYPE; + return (hdrtype == PCIM_HDRTYPE_BRIDGE || + hdrtype == PCIM_HDRTYPE_CARDBUS); +} + static void pcie_mps_active_conflict(device_t dev, uint16_t path_mps, uint16_t device_mps) { + struct pci_devinfo *dinfo; + const char *action; if (!pcie_mps_first_warning(dev)) return; + dinfo = device_get_ivars(dev); + if (pci_mps_enforce && !pcie_mps_is_bridge(dinfo)) + action = "disabling device"; + else + action = "leaving device unchanged"; device_printf(dev, "configured MPS %d does not match path MPS %d while bus " - "mastering is enabled; leaving device unchanged\n", - pcie_mps_bytes(device_mps), pcie_mps_bytes(path_mps)); + "mastering is enabled; %s\n", pcie_mps_bytes(device_mps), + pcie_mps_bytes(path_mps), action); } static void pcie_mps_mark_unreconciled(device_t dev) { struct pci_devinfo *dinfo; + uint16_t cmd; dinfo = device_get_ivars(dev); + if ((dinfo->cfg.flags & PCICFG_MPS_UNRECONCILED) != 0) + return; dinfo->cfg.flags |= PCICFG_MPS_UNRECONCILED; + if (!pci_mps_enforce) + return; + if (pcie_mps_is_bridge(dinfo)) { + device_printf(dev, + "not disabled by hw.pci.mps_enforce because it is a bridge\n"); + return; + } + cmd = pci_read_config(dev, PCIR_COMMAND, 2); + cmd &= ~(PCIM_CMD_PORTEN | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN); + pci_write_config(dev, PCIR_COMMAND, cmd, 2); + dinfo->cfg.cmdreg = cmd; + device_disable(dev); + device_printf(dev, + "disabled because its MPS cannot be safely configured\n"); } static void