From nobody Fri Aug 21 00:30:32 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 4hR1Rr6N2Vz6pMwT for ; Fri, 21 Aug 2026 00:30:32 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hR1Rr5Q2tz3wRw for ; Fri, 21 Aug 2026 00:30:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787272232; 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=mowCyr7VyhPurMWpjxjCkD09IPJzyOiSGUqbnhAh5p8=; b=PaF7yriJPfP2uSb7GsA5+wd5m2MQLSzxBzWMLb3w+YRrrFVJSF9Qft/jTKs63kLCrTq99Z 0d0SdUt6yzCfKQ86VShs/mdmydp4SwhR+uZw5TgztnLGyqR82Hn1EC+zD+/21DHCtG5yyf veDUJOShuuqv8Yfa+Ht5uYP0tZ4vl5YBfYl4f5CqCFLEfmA9YmtEY28kzisPlJr3E/jc9q N8pVsHEe7XL40HuGVxD1C5ZnyIeKaKMUcQ3Of4HBXtu0cK6/bsoi2Dm7lpt2dTYyJjDqtn gm/h26IYH1RigmSTnnXlfqtoATIek7ArZ00CdD5dxsLKEUhqsngPrK8etadYxQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787272232; a=rsa-sha256; cv=none; b=si3liqu9OAojb0CccYqqZu048SE1lzKdC6g+uy68ZJG7fExPTXqwkpi5017QyZ1DRiB7E7 obTE+VtqfhgMKFmYUcKqhDXe7XrVi9laAYA1IhxqMXml6P3AuuRENCZQM9nlwwLr9gQFTw +s8KJ3CbWQHKS08xdCddWjI6V2wMua/B37TDbud36vZr+JY1sgB+QHIQ+xSk8mkE0kBcUt HjSH1w2PT4Yo8NZEcUdVza6rH5tB+7MgZSLwEUuwOBL9M8k7kw3ZPXHv8BGwJA4D9j+R4N 8cPDLVczYdESxQSVk0uEbrBPN1j5zAqJz6H2Qhdms747aJ3gBt3mb/gvLjgi9Q== 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=1787272232; 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=mowCyr7VyhPurMWpjxjCkD09IPJzyOiSGUqbnhAh5p8=; b=Zmx4I8X991EM4P4y90iQYgJFk054ZkHARNZDBXX6L+zCtqUAy9LXbNKblKLV+UXKcZAezR HUgH7fl6QS3mhhORkRmwGEOokboTT5Wml5YQ6l+G/P2ePSvOVpFvSXHFJYE/Opnibknro8 YVgxjJ5LF1t/RolPEIC1wT5ZkTKO1x+K0pZV46huONOGItkVmjgRInsvFXSOGhiEmUe0ZO wE+A6mI568T+Tappve9/iE1DGjziUL3nYjPHjhgahA/42hHINqj6arCjf7XaXUqmYiaWy0 SDOBItWVWlEtrfcLSEse9ARMEKqDudB3qcxdnNpWTziodLnEHBFxkoivcD7d6g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hR1Rr4HTszgsW for ; Fri, 21 Aug 2026 00:30:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 21079 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 21 Aug 2026 00:30:32 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: e66dcff1385d - stable/15 - 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/stable/15 X-Git-Reftype: branch X-Git-Commit: e66dcff1385dc08bff1eb87c847f9e0d262dbe64 Auto-Submitted: auto-generated Date: Fri, 21 Aug 2026 00:30:32 +0000 Message-Id: <6a879c28.21079.176ae357@gitrepo.freebsd.org> The branch stable/15 has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=e66dcff1385dc08bff1eb87c847f9e0d262dbe64 commit e66dcff1385dc08bff1eb87c847f9e0d262dbe64 Author: Kevin Bowling AuthorDate: 2026-08-06 06:42:26 +0000 Commit: Kevin Bowling CommitDate: 2026-08-21 00:30:23 +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. (cherry picked from commit 114f4a68f21345e1e6680b7acf1bf733d9047002) --- 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 8c28c25e9dcf..fd4dc7413785 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -449,6 +449,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"); @@ -4526,26 +4531,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