git: b0bbefc465ee - stable/14 - pci: Add hw.pci.intx_reroute sysctl/tunable

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Sat, 26 Apr 2025 19:21:48 UTC
The branch stable/14 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=b0bbefc465ee00deec8fb753fc0e4d0ecb7e4aff

commit b0bbefc465ee00deec8fb753fc0e4d0ecb7e4aff
Author:     Colin Percival <cperciva@FreeBSD.org>
AuthorDate: 2025-04-15 19:30:30 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-04-26 19:21:03 +0000

    pci: Add hw.pci.intx_reroute sysctl/tunable
    
    INTRng can leak resources when INTx interrupts are re-routed, which is
    typically harmless but can be fatal when devices are (repeatedly) hot
    plugged into PCI buses on INTRng systems.  Re-routing INTx interrupts
    is nonetheless still necessary on some systems, and identifying whether
    the re-routing should be enabled or disabled seems to be nontrivial.
    
    Add a hw.pci.intx_reroute sysctl/tunable so systems which don't want
    legacy PCI interrupt re-routing can turn it off.  This is probably not
    the best fix but it's something which can be safely included in FreeBSD
    14.3.
    
    Co-Authored-by: jhb
    Reviewed by:    bz, jhb
    MFC after:      3 days
    Sponsored by:   Amazon
    Differential Revision:  https://reviews.freebsd.org/D49849
    
    (cherry picked from commit 2187ec93ada1c7399f2f3537920f6277bec4a0ef)
---
 sys/dev/pci/pci.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
index 102027123976..dde50afd9319 100644
--- a/sys/dev/pci/pci.c
+++ b/sys/dev/pci/pci.c
@@ -431,6 +431,10 @@ SYSCTL_BOOL(_hw_pci, OID_AUTO, enable_mps_tune, CTLFLAG_RWTUN,
     &pci_enable_mps_tune, 1,
     "Enable tuning of MPS(maximum payload size)." );
 
+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");
+
 static int
 pci_has_quirk(uint32_t devid, int quirk)
 {
@@ -4097,7 +4101,8 @@ pci_add_resources(device_t bus, device_t dev, int force, uint32_t prefetchmask)
 		if (q->devid == devid && q->type == PCI_QUIRK_MAP_REG)
 			pci_add_map(bus, dev, q->arg1, rl, force, 0);
 
-	if (cfg->intpin > 0 && PCI_INTERRUPT_VALID(cfg->intline)) {
+	if (cfg->intpin > 0 && PCI_INTERRUPT_VALID(cfg->intline) &&
+	    pci_intx_reroute) {
 #ifdef __PCI_REROUTE_INTERRUPT
 		/*
 		 * Try to re-route interrupts. Sometimes the BIOS or