From nobody Thu Nov 25 09:54:23 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 A9087189FBF2 for ; Thu, 25 Nov 2021 09:54:35 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-vk1-xa2a.google.com (mail-vk1-xa2a.google.com [IPv6:2607:f8b0:4864:20::a2a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J0Cs74BlGz4ZfX for ; Thu, 25 Nov 2021 09:54:35 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-vk1-xa2a.google.com with SMTP id s17so3481432vka.5 for ; Thu, 25 Nov 2021 01:54:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wpXm1II1/CLWENn5Emh25zCoTBta8roNvZa7GDusZ6A=; b=5Wd57be7iLH0l3iFe9BMSFzhzJNCtRB9C1KzAmhmsvT9mEvfluGuUDiNDvQHoVg9sN L21A5Nv5Oz8Ir6MlqNdboeYq7H/Lh+YfDOb1FAICRnU/3IIi/ZOcKxemszT7x/9gdea0 nvTdVH4Az0Ir7i2r32lWKsxAVUg+YG7WXJuZ9nw1tWaMrPXWMeMwxy13qPkWMpBxota+ 3i5K+AqWsSZK22Cbis4CbzIB7ZC5Dk0PCc/rRY7fYPlfy/2mwKnW0J1IhG+kYWFXyDvT YtlB2b9VLR66Hxqz47/kEFRBIF+CLXmGgVXNbeiQ1abx8nLykDDpkJSxh5OVaFIVnE4s YMaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wpXm1II1/CLWENn5Emh25zCoTBta8roNvZa7GDusZ6A=; b=NByY69pkbSqHt6W/nhjQ6ZEs3s2I8Sz3SZgPp7jnqTcngZg6VugvPpM385K89ScaBn IIUEhBqqItCjaaZZlqhVHAduOL5M3qa63r4B6n7h1SCY4w9gJZFNUyXy1JxGFKSAup7i sOGzK4k1D30sYAqPd2npEiuZcu8k/pbccwJGVDjyP9UzCoivUJ0i6BQWt+eLBgAeboXM fOi4qkJLNRUR588t0L2Ek+eTDRcbfJkSBjD3tP+HitYaMC23vwstWi2TfK2AbZzsE/Xs 9F9rP66fGvInW5JaZdVVSe1uNpqmXYj0DGuNjx60LCRZdSc5Ox4ggETwf2bjEeKOBmcE eFtw== X-Gm-Message-State: AOAM532GcFLtAFfge5o0JvO4hfjL6WE3VvWqUvyE9lQRHq8P4T/Boj3z yQGQRG6Rr1pAPmdr0gaa5ZpLTC6xYi12dd7LrgjHSg== X-Google-Smtp-Source: ABdhPJxtmGIlv0Kw68m2Y9v0kQtTgI1SVTCo9cTZjhsaD+aL9DZMM15TsbHvBQaAactVElm+rT46yWmystUiWJDigUg= X-Received: by 2002:a1f:14c5:: with SMTP id 188mr692635vku.5.1637834074906; Thu, 25 Nov 2021 01:54:34 -0800 (PST) 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 References: <202111250855.1AP8t3iG042265@gitrepo.freebsd.org> In-Reply-To: <202111250855.1AP8t3iG042265@gitrepo.freebsd.org> From: Warner Losh Date: Thu, 25 Nov 2021 02:54:23 -0700 Message-ID: Subject: Re: git: 68cbe189fdd3 - main - pci: Don't try to read cfg registers of non-existing devices To: Wojciech Macek Cc: src-committers , "" , dev-commits-src-main@freebsd.org Content-Type: multipart/alternative; boundary="0000000000003c75a805d199f686" X-Rspamd-Queue-Id: 4J0Cs74BlGz4ZfX X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N --0000000000003c75a805d199f686 Content-Type: text/plain; charset="UTF-8" On Thu, Nov 25, 2021 at 1:55 AM Wojciech Macek wrote: > 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. > We didn't use to bail out if function 0 was not present due to odd balls (I think on sparc64) which have long ago since become irrelevant, so this should be OK. Warner > 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; > > /* > --0000000000003c75a805d199f686--