From nobody Fri Aug 21 00:44:46 2026 X-Original-To: dev-commits-src-branches@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 4hR1mG58xMz6pPKg for ; Fri, 21 Aug 2026 00:44:46 +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 4hR1mG1s0Bz4538 for ; Fri, 21 Aug 2026 00:44:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787273086; 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=vTL01Xy9ZBvSVHM+BKlmhvB+w19OiqBbLFbn1Ah6tJ8=; b=HKUZl55RHobV/clF+BIzc6wBV9iQwudiuhed7RmqDWOgE0lxPQejysYGOjCDbl1pAitv8y O2l7cV8RwdlhpS+xoC2HuTIh++Xg0MxpivyCQQKmNXHa8WgKMn+DTfBs/MLHrETXzT8K+Y 1S68ktzJEnYCNnjf5Y9XcMZLQe+Ud7Gc1SBnZnHYr3CRpsyxvK+N25fYlEK0MXsJ987Yn5 BS3hVHi1yV6HkK+Zvj/cKAUi84Y2UJG+df6oCcBChuOt1S0aCpDCKBu3kcKWR0kCoeGj5/ NM+2kFRVNgrlRmntr1bNXA0ZhmNFHbnR6ON6B7FyrE/Yh1V5Sd6K2uHotqDLUA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787273086; a=rsa-sha256; cv=none; b=lHno9NlEw/UTds39vkc+j+vwuGG5rWkKF3G4U/Iyl87od4wEQHNnMGHK52oTgbi8tqmSuv 8waxauq3iQafe86PFJHMe9sF4qRn2sUYCa/5MGfyLAgNTf7g/zWQjNGhDdSPJOAf+wl+DO DKDHc37aq4qjLexss3N7u9NR0o9FNYXla2QuebrLZ0bOsGoulwvXSdfrNNuyHkOhnWDM8s spFeL3etymYPYhyPL8kqWKYzPPIzzh7ONHZHU+bz2L4bUAoaQQy/Z9aKufwlG/F9TXLCxr sUlVGn9KGOYX3TFevvYyTJDLVFB3yeHtf2A+95Z13l+Dv/c8urvugCBTZUwdYw== 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=1787273086; 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=vTL01Xy9ZBvSVHM+BKlmhvB+w19OiqBbLFbn1Ah6tJ8=; b=OwXxecZK0nR6LQkr+iJ7aLEgDB43PThr0z5Ox0Ml5SDzUyG1mo2u4Z1FyT0QDjO0zN45Gj BA7NtC4EVFhfhpGgRRLcZ1vvDTVbYcyHYOeLIqxYmeUDjZt7RTvSwVeAvqrz2jBWBt1P17 zen+iF+3S20K62fDTnqVH5jJXzcHsd3pLp8rnFQ6gxyXi/7p5A5pBxS6aGTwgbF9/CrV0x PUioYjPT4slo9CecgJ6xauNIqxVTeqexBwgcgchO3qeK/wH42tiNsgJ3CYjUG06O2EgPsP 0oTsDNsXXSXtUti3Xz+RNMCBUte29dPTXFkMhnK36U7VqT9s6xbN0io8usvlEg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hR1mG0nDpzhVh for ; Fri, 21 Aug 2026 00:44:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2363b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 21 Aug 2026 00:44:46 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: 32ba894e1fbb - stable/14 - pci: Optionally disable endpoints with unsafe MPS List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/14 X-Git-Reftype: branch X-Git-Commit: 32ba894e1fbb0403f4dd6d8c9cee747857f1aa60 Auto-Submitted: auto-generated Date: Fri, 21 Aug 2026 00:44:46 +0000 Message-Id: <6a879f7e.2363b.6b112366@gitrepo.freebsd.org> The branch stable/14 has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=32ba894e1fbb0403f4dd6d8c9cee747857f1aa60 commit 32ba894e1fbb0403f4dd6d8c9cee747857f1aa60 Author: Kevin Bowling AuthorDate: 2026-08-06 06:42:26 +0000 Commit: Kevin Bowling CommitDate: 2026-08-21 00:41:49 +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 1e00c50f2beb..29f1d1d6850c 100644 --- a/share/man/man4/pci.4 +++ b/share/man/man4/pci.4 @@ -600,6 +600,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 a073e684bb14..b56a6052e855 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -451,6 +451,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"); @@ -4505,26 +4510,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