From nobody Wed Jun 05 16:50:49 2024 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 4VvYPP2lnsz5LF3j; Wed, 05 Jun 2024 16:50:49 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VvYPP2FzMz4N2k; Wed, 5 Jun 2024 16:50:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717606249; 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=uq5Cs26l2EblWISgbWyUASCSKiGx3n4OYwWc2+1hDcY=; b=hiVRfvncj/TqnIfT1dCae9W4aGZZc1O9m9dzwgKyOLp2jn3z4UxvQSmth/lZHgoxVHuqB6 acQwlgqTs1AYzC2F+AUttPwmHPzToEb0vEHs3sNz4Hlmi4KnrK2G1j2JlR9PSQpOEzcAeO zbFoxG/+DICwsbKDnVBR2i2zk/kOvu42i9g8r2MvFWqy0z8WRUvZVJCA6qCPHEYLITeImH 0RLckdhOrdPsKvHANwEMX2r11QHyh1hg6NtC3q/h8loHCT3FZ744wmWtQRhA58vtfGNtiS G5blEET2Pp1uDi6xUMp1KrPguGBGdlKHUYCAI2PG++yhT0YvVGlQTribKIDvHw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717606249; a=rsa-sha256; cv=none; b=K9tHQ3E4EeXySy3GyVQGJKfF7IIOAQRvijeqGZouW1YREVNYh4v33AE7kfJ3v1cOrXGmh5 G56YmP05i4idZz2usoI37DZv15G3jAqZotwNSO9Eem6/41f2sVSluU/3ihoYPFZe6Jzqah 0/gtfVjOSg67z1HOmnVVBowuzdKZlkLjQyrxy2y9BWCSIXG5szb4jwBYf3+OVQzx99TNlX KBcrYy81XWGFq+QmaoVLPmIY1OONJH6Iswgcinp1xnLe//yC4WApTtWoer7PumInhISxMv eQ5B5MWDPdf9GojdJkzU/gNtFAxU2vJLn2H60cAS67LCmTpD2g7yTYZRhgnD/g== 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=1717606249; 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=uq5Cs26l2EblWISgbWyUASCSKiGx3n4OYwWc2+1hDcY=; b=ufU5U4DbTkd3uE50BVpADYFTYojpf5AFHrVEEmDVGkcwwaRmP3z8aH/VyX+JjsMz7kGPcD htG64Di9l8i4bSzTemJkE3mZsg7K9yo2n4iWSX4uWz4zxkIzjUwUZOavF3H46hQicUwjdz /3yXaE75fl3yRPL6GxYeSWEbSswDnMe3e+prZT+g2MKSR0bNeXIfSMGkQNscbAMOTUgoN7 qXGzaM/qkPpJ8TiQa7LxAMtD2aUhWyigeYnVJ4pagTrvQJ6ykCHWOrJZIXcY3JDHNx6Yuh Mt5/lCmKzDa9r/dew9BqUOuTH2Ppd577OyDbt9VsonqxyRCB2gMxHFoJBiDqpw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VvYPP1kV7z18T8; Wed, 5 Jun 2024 16:50:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 455Gon4t082247; Wed, 5 Jun 2024 16:50:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 455GonBQ082244; Wed, 5 Jun 2024 16:50:49 GMT (envelope-from git) Date: Wed, 5 Jun 2024 16:50:49 GMT Message-Id: <202406051650.455GonBQ082244@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 56b822a17cde - main - pci: Only add special VF handling for direct children in bus methods 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 56b822a17cde5940909633c50623d463191a7852 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=56b822a17cde5940909633c50623d463191a7852 commit 56b822a17cde5940909633c50623d463191a7852 Author: John Baldwin AuthorDate: 2024-06-05 16:50:05 +0000 Commit: John Baldwin CommitDate: 2024-06-05 16:50:05 +0000 pci: Only add special VF handling for direct children in bus methods For activate/deactivate resource, use a more standard check at the start of the function since the addition of the PCI_IOV code made this more complex. For the three recently added methods, just add the typical check at the beginning that I missed. This wasn't always fatal as if your system only had PCI device_t's as children of PCI bus devices it would happen to work ok, but if you have a non-PCI child device (e.g. an ATA channel) then dereferencing ivars for non-direct-children could fault. Reported by: Cirrus-CI (via emaste) Reviewed by: emaste Fixes: 871b33ad65ba pci: Consistently use pci_vf_* for suballocated VF memory resources Differential Revision: https://reviews.freebsd.org/D45499 --- sys/dev/pci/pci.c | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 2093d6a8b5ef..9661cfd19db7 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -5695,6 +5695,9 @@ pci_activate_resource(device_t dev, device_t child, struct resource *r) struct pci_devinfo *dinfo; int error, rid, type; + if (device_get_parent(child) != dev) + return (bus_generic_activate_resource(dev, child, r)); + dinfo = device_get_ivars(child); #ifdef PCI_IOV if (dinfo->cfg.flags & PCICFG_VF) { @@ -5716,20 +5719,20 @@ pci_activate_resource(device_t dev, device_t child, struct resource *r) if (error) return (error); + rid = rman_get_rid(r); + type = rman_get_type(r); + + /* Device ROMs need their decoding explicitly enabled. */ + if (type == SYS_RES_MEMORY && PCIR_IS_BIOS(&dinfo->cfg, rid)) + pci_write_bar(child, pci_find_bar(child, rid), + rman_get_start(r) | PCIM_BIOS_ENABLE); + /* Enable decoding in the command register when activating BARs. */ - if (device_get_parent(child) == dev) { - /* Device ROMs need their decoding explicitly enabled. */ - rid = rman_get_rid(r); - type = rman_get_type(r); - if (type == SYS_RES_MEMORY && PCIR_IS_BIOS(&dinfo->cfg, rid)) - pci_write_bar(child, pci_find_bar(child, rid), - rman_get_start(r) | PCIM_BIOS_ENABLE); - switch (type) { - case SYS_RES_IOPORT: - case SYS_RES_MEMORY: - error = PCI_ENABLE_IO(dev, child, type); - break; - } + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + error = PCI_ENABLE_IO(dev, child, type); + break; } return (error); } @@ -5740,6 +5743,9 @@ pci_deactivate_resource(device_t dev, device_t child, struct resource *r) struct pci_devinfo *dinfo; int error, rid, type; + if (device_get_parent(child) != dev) + return (bus_generic_deactivate_resource(dev, child, r)); + dinfo = device_get_ivars(child); #ifdef PCI_IOV if (dinfo->cfg.flags & PCICFG_VF) { @@ -5762,13 +5768,11 @@ pci_deactivate_resource(device_t dev, device_t child, struct resource *r) return (error); /* Disable decoding for device ROMs. */ - if (device_get_parent(child) == dev) { - rid = rman_get_rid(r); - type = rman_get_type(r); - if (type == SYS_RES_MEMORY && PCIR_IS_BIOS(&dinfo->cfg, rid)) - pci_write_bar(child, pci_find_bar(child, rid), - rman_get_start(r)); - } + rid = rman_get_rid(r); + type = rman_get_type(r); + if (type == SYS_RES_MEMORY && PCIR_IS_BIOS(&dinfo->cfg, rid)) + pci_write_bar(child, pci_find_bar(child, rid), + rman_get_start(r)); return (0); } @@ -5779,6 +5783,10 @@ pci_adjust_resource(device_t dev, device_t child, struct resource *r, { struct pci_devinfo *dinfo; + if (device_get_parent(child) != dev) + return (bus_generic_adjust_resource(dev, child, r, start, + end)); + dinfo = device_get_ivars(child); if (dinfo->cfg.flags & PCICFG_VF) { switch (rman_get_type(r)) { @@ -5802,6 +5810,10 @@ pci_map_resource(device_t dev, device_t child, struct resource *r, { struct pci_devinfo *dinfo; + if (device_get_parent(child) != dev) + return (bus_generic_map_resource(dev, child, r, argsp, + map)); + dinfo = device_get_ivars(child); if (dinfo->cfg.flags & PCICFG_VF) { switch (rman_get_type(r)) { @@ -5825,6 +5837,9 @@ pci_unmap_resource(device_t dev, device_t child, struct resource *r, { struct pci_devinfo *dinfo; + if (device_get_parent(child) != dev) + return (bus_generic_unmap_resource(dev, child, r, map)); + dinfo = device_get_ivars(child); if (dinfo->cfg.flags & PCICFG_VF) { switch (rman_get_type(r)) {