From owner-dev-commits-src-all@freebsd.org Fri Dec 25 13:47:38 2020 Return-Path: Delivered-To: dev-commits-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 9F9E64C1FF4; Fri, 25 Dec 2020 13: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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D2Stf2nBqz3FHW; Fri, 25 Dec 2020 13: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 4E12C23B96; Fri, 25 Dec 2020 13: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 0BPDlcbp082271; Fri, 25 Dec 2020 13: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 0BPDlcE4082270; Fri, 25 Dec 2020 13:47:38 GMT (envelope-from git) Date: Fri, 25 Dec 2020 13:47:38 GMT Message-Id: <202012251347.0BPDlcE4082270@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 88a502a77b8f - MFC r368749: pci_iov: When pci_iov_detach(9) is called, destroy VF children instead of bailing out with EBUSY if there are any. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 88a502a77b8fb48475e02205153c15580c98fc9e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "Commit messages for all branches of the src repository." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Dec 2020 13:47:38 -0000 The branch stable/12 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=88a502a77b8fb48475e02205153c15580c98fc9e commit 88a502a77b8fb48475e02205153c15580c98fc9e Author: Konstantin Belousov AuthorDate: 2020-12-18 03:46:50 +0000 Commit: Konstantin Belousov CommitDate: 2020-12-25 13:22:37 +0000 MFC r368749: pci_iov: When pci_iov_detach(9) is called, destroy VF children instead of bailing out with EBUSY if there are any. (cherry picked from commit 94f5c1cc7186ae555b962d2450cc17e06fd4fda0) --- sys/dev/pci/pci_iov.c | 53 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/sys/dev/pci/pci_iov.c b/sys/dev/pci/pci_iov.c index db8a035f21aa..1173ed15addc 100644 --- a/sys/dev/pci/pci_iov.c +++ b/sys/dev/pci/pci_iov.c @@ -94,6 +94,7 @@ static void pci_iov_build_pf_schema(nvlist_t *schema, nvlist_t **driver_schema); static void pci_iov_build_vf_schema(nvlist_t *schema, nvlist_t **driver_schema); +static int pci_iov_delete_iov_children(struct pci_devinfo *dinfo); static nvlist_t *pci_iov_get_pf_subsystem_schema(void); static nvlist_t *pci_iov_get_vf_subsystem_schema(void); @@ -190,6 +191,7 @@ pci_iov_detach_method(device_t bus, device_t dev) { struct pci_devinfo *dinfo; struct pcicfg_iov *iov; + int error; mtx_lock(&Giant); dinfo = device_get_ivars(dev); @@ -200,11 +202,17 @@ pci_iov_detach_method(device_t bus, device_t dev) return (0); } - if (iov->iov_num_vfs != 0 || iov->iov_flags & IOV_BUSY) { + if ((iov->iov_flags & IOV_BUSY) != 0) { mtx_unlock(&Giant); return (EBUSY); } + error = pci_iov_delete_iov_children(dinfo); + if (error != 0) { + mtx_unlock(&Giant); + return (error); + } + dinfo->cfg.iov = NULL; if (iov->iov_cdev) { @@ -822,31 +830,20 @@ pci_iov_is_child_vf(struct pcicfg_iov *pf, device_t child) } static int -pci_iov_delete(struct cdev *cdev) +pci_iov_delete_iov_children(struct pci_devinfo *dinfo) { device_t bus, dev, vf, *devlist; - struct pci_devinfo *dinfo; struct pcicfg_iov *iov; int i, error, devcount; uint32_t iov_ctl; - mtx_lock(&Giant); - dinfo = cdev->si_drv1; + mtx_assert(&Giant, MA_OWNED); + iov = dinfo->cfg.iov; dev = dinfo->cfg.dev; bus = device_get_parent(dev); devlist = NULL; - if (iov->iov_flags & IOV_BUSY) { - mtx_unlock(&Giant); - return (EBUSY); - } - - if (iov->iov_num_vfs == 0) { - mtx_unlock(&Giant); - return (ECHILD); - } - iov->iov_flags |= IOV_BUSY; error = device_get_children(bus, &devlist, &devcount); @@ -904,6 +901,32 @@ pci_iov_delete(struct cdev *cdev) out: free(devlist, M_TEMP); iov->iov_flags &= ~IOV_BUSY; + return (error); +} + +static int +pci_iov_delete(struct cdev *cdev) +{ + struct pci_devinfo *dinfo; + struct pcicfg_iov *iov; + int error; + + mtx_lock(&Giant); + dinfo = cdev->si_drv1; + iov = dinfo->cfg.iov; + + if ((iov->iov_flags & IOV_BUSY) != 0) { + error = EBUSY; + goto out; + } + if (iov->iov_num_vfs == 0) { + error = ECHILD; + goto out; + } + + error = pci_iov_delete_iov_children(dinfo); + +out: mtx_unlock(&Giant); return (error); }