From nobody Wed Dec 15 10:47:38 2021 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 AA46E18E2BA3; Wed, 15 Dec 2021 10:47:38 +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 4JDX562zNPz4l5c; Wed, 15 Dec 2021 10:47:38 +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 394281AB16; Wed, 15 Dec 2021 10:47:38 +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 1BFAlcs8041080; Wed, 15 Dec 2021 10:47:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BFAlcMn041079; Wed, 15 Dec 2021 10:47:38 GMT (envelope-from git) Date: Wed, 15 Dec 2021 10:47:38 GMT Message-Id: <202112151047.1BFAlcMn041079@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Wojciech Macek Subject: git: 77b3cf989fc1 - stable/13 - pci: Don't try to read cfg registers of non-existing devices 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: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 77b3cf989fc11bcae263c8601e73daf90987ea97 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639565258; 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=j+Pqsxtq/2aL0qij2daSd53Uj6ER1iZFbgzJEXLYWp0=; b=hv2u4ULBZdX13nfU1lyoAM1pMz7w1hUbWSS20yTLpgDQyvB0YGrKBJGWsCTFMCmNcOOlKA +/u0sc7y3hIzBq0c9f2FIMT0wbCkmQBwKS/Z9yRjjNlvcuLIdbjJOxcrAKE5F9LivWYWXO wNeVw+Ao6UQ1hnDPx+PnbgbGo+X+myEorlBLy7VCfwCVNha81b4lCKTo20BXbC6HEu28GD hWcnRmAza4bnmF87XJoAOcx69vFGmuGaM73G1adbGNWL/Cq61KTufxqjNU890/KXap+O07 bbXs/vbOWrkiqaA6leEM0rc6ze8IHGKmCniF1pTLs3s3nd/4CUsaB/r0csl8gw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639565258; a=rsa-sha256; cv=none; b=g1vp8XJgiW3zuT9uP4JMBUi4kVO52e7C7KMNF10TmI8t1HFu3IHvxD8FanNNYIng5qsRJ+ uWBvWOX2i+StmMin7Gu1YbnDGm0NCj5agLXh8m2uIXydqeD+JkmuFt4dRp+a7qF+Ie2A2x +Y6NCrl++8YhRcS5GV6V0bb5kn7jP+TIaJxOM5UximDkYEazVJaJt4WW6aRwh73AFiu8zT F/JFmN38ajynsAErF3CY6/PuhL3D8jJNM8ezhjUg01HDnMQMGVPimW2N1QjDW1gTGa0utP eREMdP26uPn6NccEhIGEy4GR//rbTeXmVWnllFRwvcn2Mi32DBA/whvynW26Gg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=77b3cf989fc11bcae263c8601e73daf90987ea97 commit 77b3cf989fc11bcae263c8601e73daf90987ea97 Author: Kornel Duleba AuthorDate: 2021-11-23 08:13:56 +0000 Commit: Wojciech Macek CommitDate: 2021-12-15 10:46:46 +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 (cherry picked from commit 68cbe189fdd3c572476f8af9219a5d335f05b51a) --- 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 4c79d9260fc0..b9d908bdd822 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -682,11 +682,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 * @@ -4140,6 +4141,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; @@ -4181,7 +4186,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); @@ -4190,7 +4195,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; /*