From owner-svn-src-all@freebsd.org Sun Nov 24 15:37:15 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0C5641B2434; Sun, 24 Nov 2019 15:37:15 +0000 (UTC) (envelope-from imp@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47LZ6L6c6Vz487m; Sun, 24 Nov 2019 15:37:14 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C629D26416; Sun, 24 Nov 2019 15:37:14 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xAOFbENw060101; Sun, 24 Nov 2019 15:37:14 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xAOFbEVF060099; Sun, 24 Nov 2019 15:37:14 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201911241537.xAOFbEVF060099@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Sun, 24 Nov 2019 15:37:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r355057 - head/sys/dev/pci X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sys/dev/pci X-SVN-Commit-Revision: 355057 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Nov 2019 15:37:15 -0000 Author: imp Date: Sun Nov 24 15:37:14 2019 New Revision: 355057 URL: https://svnweb.freebsd.org/changeset/base/355057 Log: Hoist locking giant back up into the ioctl handler Move the locking back into the ioctl handler. This "fixes" the race where we hve a hot plug event just after the dropping of Giant in pci_find_dbsf, assuming the driver doesn't then call anything that drops and picks up Giant again... It's a little safer since don't think it doesn't, but we lack the tools to know for sure. Modified: head/sys/dev/pci/pci.c head/sys/dev/pci/pci_user.c Modified: head/sys/dev/pci/pci.c ============================================================================== --- head/sys/dev/pci/pci.c Sun Nov 24 15:24:05 2019 (r355056) +++ head/sys/dev/pci/pci.c Sun Nov 24 15:37:14 2019 (r355057) @@ -447,8 +447,6 @@ pci_find_dbsf(uint32_t domain, uint8_t bus, uint8_t sl { struct pci_devinfo *dinfo = NULL; - /* Giant because newbus is Giant locked revisit with newbus locking */ - mtx_lock(&Giant); STAILQ_FOREACH(dinfo, &pci_devq, pci_links) { if ((dinfo->cfg.domain == domain) && (dinfo->cfg.bus == bus) && @@ -457,7 +455,6 @@ pci_find_dbsf(uint32_t domain, uint8_t bus, uint8_t sl break; } } - mtx_unlock(&Giant); return (dinfo != NULL ? dinfo->cfg.dev : NULL); } Modified: head/sys/dev/pci/pci_user.c ============================================================================== --- head/sys/dev/pci/pci_user.c Sun Nov 24 15:24:05 2019 (r355056) +++ head/sys/dev/pci/pci_user.c Sun Nov 24 15:37:14 2019 (r355057) @@ -965,6 +965,9 @@ pci_ioctl(struct cdev *dev, u_long cmd, caddr_t data, } + /* Giant because newbus is Giant locked revisit with newbus locking */ + mtx_lock(&Giant); + switch (cmd) { case PCIOCGETCONF: #ifdef COMPAT_FREEBSD32 @@ -1288,8 +1291,10 @@ getconfexit: case PCIOCBARMMAP: pbm = (struct pci_bar_mmap *)data; if ((flag & FWRITE) == 0 && - (pbm->pbm_flags & PCIIO_BAR_MMAP_RW) != 0) - return (EPERM); + (pbm->pbm_flags & PCIIO_BAR_MMAP_RW) != 0) { + error = EPERM; + break; + } pcidev = pci_find_dbsf(pbm->pbm_sel.pc_domain, pbm->pbm_sel.pc_bus, pbm->pbm_sel.pc_dev, pbm->pbm_sel.pc_func); @@ -1300,6 +1305,8 @@ getconfexit: error = ENOTTY; break; } + + mtx_unlock(&Giant); return (error); }