From owner-freebsd-net@freebsd.org Wed Jan 25 11:41:29 2017 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 11338CC0EF6 for ; Wed, 25 Jan 2017 11:41:29 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 01806BF6 for ; Wed, 25 Jan 2017 11:41:29 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id v0PBfSTq014767 for ; Wed, 25 Jan 2017 11:41:28 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-net@FreeBSD.org Subject: [Bug 216456] iflib error checking for MSIX Date: Wed, 25 Jan 2017 11:41:28 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: bz@FreeBSD.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-net@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter cc Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Jan 2017 11:41:29 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D216456 Bug ID: 216456 Summary: iflib error checking for MSIX Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: kern Assignee: freebsd-net@FreeBSD.org Reporter: bz@FreeBSD.org CC: sbruno@FreeBSD.org Structurally this seems entirely backwards that drivers do supply a isc_msix_bar value without checking if MSIX is available. Writing code bas= ed on assumptions is not stable but iflib should guard against this. Add error checking to the pci_find_cap(, PCIY_MSIX,) call that is returns success and a good value. Only then try to use it and set the MSIX_ENABLE = bit. With the current em(4) driver we have observed failures in this case in a specific environment when pci_find_cap() would not return the assumed value, which meant we ended up writing to PCI register 2 (PCI_DEVICE_ID) which is read-only. It seems that a lot more safeguarding and perhaps better structuring between drivers and iflib is needed to avoid these kinds of errors. This patch just adds the safeguard in a single place in iflib, em(4) should ideally be improved to not signal an msix bar value anymore if MSIX is not avail. Index: head-r312664.svn/sys/net/iflib.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- head-r312664.svn/sys/net/iflib.c (revision 312664) +++ head-r312664.svn/sys/net/iflib.c (working copy) @@ -3710,6 +3710,10 @@ iflib_device_register(device_t dev, void *sc, if_s if (sctx->isc_flags & IFLIB_SKIP_MSIX) { msix =3D scctx->isc_vectors; } else if (scctx->isc_msix_bar !=3D 0) + /* + * The simple fact that isc_msix_bar is not 0 does not mean= we + * we have a good value there that is known to work. + */ msix =3D iflib_msix_init(ctx); else { scctx->isc_vectors =3D 1; @@ -4754,15 +4758,21 @@ iflib_msix_init(if_ctx_t ctx) uint16_t pci_cmd_word; int msix_ctrl, rid; - rid =3D 0; pci_cmd_word =3D pci_read_config(dev, PCIR_COMMAND, 2); pci_cmd_word |=3D PCIM_CMD_BUSMASTEREN; pci_write_config(dev, PCIR_COMMAND, pci_cmd_word, 2); - pci_find_cap(dev, PCIY_MSIX, &rid); - rid +=3D PCIR_MSIX_CTRL; - msix_ctrl =3D pci_read_config(dev, rid, 2); - msix_ctrl |=3D PCIM_MSIXCTRL_MSIX_ENABLE; - pci_write_config(dev, rid, msix_ctrl, 2); + + rid =3D 0; + if (pci_find_cap(dev, PCIY_MSIX, &rid) =3D=3D 0 && rid !=3D= 0) { + rid +=3D PCIR_MSIX_CTRL; + msix_ctrl =3D pci_read_config(dev, rid, 2); + msix_ctrl |=3D PCIM_MSIXCTRL_MSIX_ENABLE; + pci_write_config(dev, rid, msix_ctrl, 2); + } else { + device_printf(dev, "PCIY_MSIX capability not found;= " + "or rid %d =3D=3D 0.\n", rid); + goto msi; + } } /* --=20 You are receiving this mail because: You are the assignee for the bug.=