From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 53161137C for ; Fri, 23 Nov 2018 14:20:24 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9843C057F2A; Fri, 23 Nov 2018 13:20:23 +0000 (UTC) Received: from [10.36.112.54] (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 88CD967E72; Fri, 23 Nov 2018 13:20:22 +0000 (UTC) To: Darek Stojaczyk , dev@dpdk.org Cc: anatoly.burakov@intel.com References: <20181121184132.34039-1-dariusz.stojaczyk@intel.com> From: Maxime Coquelin Message-ID: <3dd913f5-bd7a-8a2c-3ec8-dfabb26c0584@redhat.com> Date: Fri, 23 Nov 2018 14:20:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181121184132.34039-1-dariusz.stojaczyk@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 23 Nov 2018 13:20:23 +0000 (UTC) Subject: Re: [dpdk-dev] [PATCH] vfio: don't needlessly setup devices in secondary process X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Nov 2018 13:20:24 -0000 On 11/21/18 7:41 PM, Darek Stojaczyk wrote: > Setting up a device that wasn't setup in the primary > process will possibly break the primary process. That's > because the IPC message to retrieve the group fd in the > primary will also *open* that group if it wasn't opened > before. Even though the secondary process closes that fd > soon after as a part of its error handling path, the > primary process leaks it. > > What's worse, opening that fd on the primary will > increment the process-local counter of opened groups. > If it was 0 before, then the group will never be added > to the vfio container, nor dpdk memory will be ever > mapped. > > This patch moves the proper error checks earlier in the > code to fuly prevent setting up devices in secondary s/fuly/fully/ > processes that weren't setup in the primary process. > > Fixes: 2f4adfad0a69 ("vfio: add multiprocess support") > Cc: anatoly.burakov@intel.com > > Signed-off-by: Darek Stojaczyk > --- > drivers/bus/pci/linux/pci_vfio.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c > index ffd26f195..54a4c959e 100644 > --- a/drivers/bus/pci/linux/pci_vfio.c > +++ b/drivers/bus/pci/linux/pci_vfio.c > @@ -794,11 +794,6 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev) > snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT, > loc->domain, loc->bus, loc->devid, loc->function); > > - ret = rte_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr, > - &vfio_dev_fd, &device_info); > - if (ret) > - return ret; > - > /* if we're in a secondary process, just find our tailq entry */ > TAILQ_FOREACH(vfio_res, vfio_res_list, next) { > if (rte_pci_addr_cmp(&vfio_res->pci_addr, > @@ -810,9 +805,14 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev) > if (vfio_res == NULL) { > RTE_LOG(ERR, EAL, " %s cannot find TAILQ entry for PCI device!\n", > pci_addr); > - goto err_vfio_dev_fd; > + return -1; > } > > + ret = rte_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr, > + &vfio_dev_fd, &device_info); > + if (ret) > + return ret; > + > /* map BARs */ > maps = vfio_res->maps; > > Other than commit message typo: Reviewed-by: Maxime Coquelin Thanks, Maxime