From nobody Thu Nov 25 08:55:03 2021 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 4D00118A4A76; Thu, 25 Nov 2021 08:55:04 +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 4J0BXR72tXz3mny; Thu, 25 Nov 2021 08:55:03 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 C56FA1AB2C; Thu, 25 Nov 2021 08:55:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AP8t3MF042266; Thu, 25 Nov 2021 08:55:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AP8t3iG042265; Thu, 25 Nov 2021 08:55:03 GMT (envelope-from git) Date: Thu, 25 Nov 2021 08:55:03 GMT Message-Id: <202111250855.1AP8t3iG042265@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wojciech Macek Subject: git: 68cbe189fdd3 - main - pci: Don't try to read cfg registers of non-existing devices 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 68cbe189fdd3c572476f8af9219a5d335f05b51a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637830504; 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=sYHLBcpsRrU3skLqi2gFinHyaV5RaXhVly/F5GJ3yjk=; b=e+LMxA/MCyDzqdXsF+WaFOOuGRF11E62VScGZvLf5ukrOzQNC+bn6c/C+Dtb52ii/orFg9 hTIF2iPgZ0ZbKmEwC8zKpMALLdNPexrke1zZFI2I4wKnv6OulCqq9TliS5k8eGsb5/WLp3 5esMwo5auEQjak3FX5KXrxxxI66SeF+fk/T8UK3jNE1ejFrq4kWfCZ3cywpTAmTzJgeSMq RhcJs3xFvvtV6aK06ds/VLagSM8b930qlyW5NlO+7L7NE+h2rkqpoYG8lfA4JFX2wgoew8 XZyTPdFZi+xlYTAlDdr4AoQhwDFqY5qd+sp9LeTxkgxHp5uk0XVHSL2rdg4E+Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637830504; a=rsa-sha256; cv=none; b=VuA6LbIgftD/wg8Uq9hKN28sEQ7XKCUa3pAQ9a4qFrXyiImpQZ3XAOPqENnLesxycNCw+d AgKv4U7ZenFJ1+npJZV5UvzgLIMqnA1f8GMpMrgtTCRniNQZOrG33zAJ+FIjnx/BSon+FK BtIFNOAbU7gsM4gQtMCPeEZITRbja9dQcqwE8B4/2fJJd/Niuvmd80lwXgZlL4xagx0SaW RQ9krQjcmWzJ25IPkOxRaJSqJZjgf50vl+u0d8ycOm7g18eNSU7ckC2WBkwVciPVVB5cvA Ptb9CIJFVZvHz0wtGU4WlhmwMNKNG4y5rW1LlMY6Rp+EcIFpbLfeoHSCdJIWAw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=68cbe189fdd3c572476f8af9219a5d335f05b51a commit 68cbe189fdd3c572476f8af9219a5d335f05b51a Author: Kornel Duleba AuthorDate: 2021-11-23 08:13:56 +0000 Commit: Wojciech Macek CommitDate: 2021-11-25 08:53:40 +0000 pci: Don't try to read cfg registers of non-existing devices Instead of returning 0xffs some controllers, such as Layerscape generate an external exception when someone attempts to read any register of config space of a non-existing device other than PCIR_VENDOR. This causes a kernel panic. Fix it by bailing during device enumeration if a device vendor register returns invalid value. (0xffff) Use this opportunity to replace some hardcoded values with a macro. I believe that this change won't have any unintended side-effects since it is safe to assume that vendor == 0xffff -> hdr_type == 0xffff. Sponsored by: Alstom Obtained from: Semihalf Reviewed by: jhb MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D33059 --- sys/dev/pci/pci.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 7493ae1727fb..ecef65477137 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -683,11 +683,12 @@ pci_read_device(device_t pcib, device_t bus, int d, int b, int s, int f) uint16_t vid, did; vid = REG(PCIR_VENDOR, 2); + if (vid == PCIV_INVALID) + return (NULL); + did = REG(PCIR_DEVICE, 2); - if (vid != 0xffff) - return (pci_fill_devinfo(pcib, bus, d, b, s, f, vid, did)); - return (NULL); + return (pci_fill_devinfo(pcib, bus, d, b, s, f, vid, did)); } struct pci_devinfo * @@ -4141,6 +4142,10 @@ pci_add_children(device_t dev, int domain, int busno) pcifunchigh = 0; f = 0; DELAY(1); + + /* If function 0 is not present, skip to the next slot. */ + if (REG(PCIR_VENDOR, 2) == PCIV_INVALID) + continue; hdrtype = REG(PCIR_HDRTYPE, 1); if ((hdrtype & PCIM_HDRTYPE) > PCI_MAXHDRTYPE) continue; @@ -4182,7 +4187,7 @@ pci_rescan_method(device_t dev) for (s = 0; s <= maxslots; s++) { /* If function 0 is not present, skip to the next slot. */ f = 0; - if (REG(PCIR_VENDOR, 2) == 0xffff) + if (REG(PCIR_VENDOR, 2) == PCIV_INVALID) continue; pcifunchigh = 0; hdrtype = REG(PCIR_HDRTYPE, 1); @@ -4191,7 +4196,7 @@ pci_rescan_method(device_t dev) if (hdrtype & PCIM_MFDEV) pcifunchigh = PCIB_MAXFUNCS(pcib); for (f = 0; f <= pcifunchigh; f++) { - if (REG(PCIR_VENDOR, 2) == 0xffff) + if (REG(PCIR_VENDOR, 2) == PCIV_INVALID) continue; /*