From patchwork Tue May 19 03:42:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 70408 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B4254A0093; Tue, 19 May 2020 05:42:13 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 704C01D5AF; Tue, 19 May 2020 05:42:13 +0200 (CEST) Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by dpdk.org (Postfix) with ESMTP id 622441D5AB; Tue, 19 May 2020 05:42:11 +0200 (CEST) Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 44FFF45E8ED2BEDAF7CE; Tue, 19 May 2020 11:42:10 +0800 (CST) Received: from localhost (10.173.251.152) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Tue, 19 May 2020 11:42:04 +0800 From: wangyunjian To: CC: , , , , , Yunjian Wang , Date: Tue, 19 May 2020 11:42:00 +0800 Message-ID: <1589859720-16224-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [10.173.251.152] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 1/2] vfio: fix check for vfio_group_fd 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Yunjian Wang The issue is that a file descriptor at 0 is a valid one. Currently the file not found, the return value will be set to 0. As a result, it is impossible to distinguish between a correct descriptor and a failed return value. Fix it to return -ENOENT instead of 0. Fixes: b758423bc4fe ("vfio: fix race condition with sysfs") Fixes: ff0b67d1c868 ("vfio: DMA mappinge") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang Reviewed-by: Anatoly Burakov --- lib/librte_eal/linux/eal_vfio.c | 23 +++++++++++++---------- lib/librte_eal/linux/eal_vfio_mp_sync.c | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/linux/eal_vfio.c b/lib/librte_eal/linux/eal_vfio.c index d26e1649a..8c5a13be6 100644 --- a/lib/librte_eal/linux/eal_vfio.c +++ b/lib/librte_eal/linux/eal_vfio.c @@ -293,7 +293,7 @@ vfio_open_group_fd(int iommu_group_num) strerror(errno)); return -1; } - return 0; + return -ENOENT; } /* noiommu group found */ } @@ -318,12 +318,12 @@ vfio_open_group_fd(int iommu_group_num) vfio_group_fd = mp_rep->fds[0]; } else if (p->result == SOCKET_NO_FD) { RTE_LOG(ERR, EAL, " bad VFIO group fd\n"); - vfio_group_fd = 0; + vfio_group_fd = -ENOENT; } } free(mp_reply.msgs); - if (vfio_group_fd < 0) + if (vfio_group_fd < 0 && vfio_group_fd != -ENOENT) RTE_LOG(ERR, EAL, " cannot request group fd\n"); return vfio_group_fd; } @@ -379,9 +379,9 @@ vfio_get_group_fd(struct vfio_config *vfio_cfg, } vfio_group_fd = vfio_open_group_fd(iommu_group_num); - if (vfio_group_fd <= 0) { + if (vfio_group_fd < 0) { RTE_LOG(ERR, EAL, "Failed to open group %d\n", iommu_group_num); - return -1; + return vfio_group_fd; } cur_grp->group_num = iommu_group_num; @@ -728,11 +728,14 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, /* get the actual group fd */ vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num); - if (vfio_group_fd < 0) + if (vfio_group_fd < 0 && vfio_group_fd != -ENOENT) return -1; - /* if group_fd == 0, that means the device isn't managed by VFIO */ - if (vfio_group_fd == 0) { + /* + * if vfio_group_fd == -ENOENT, that means the device + * isn't managed by VFIO + */ + if (vfio_group_fd == -ENOENT) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n", dev_addr); return 1; @@ -955,10 +958,10 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, /* get the actual group fd */ vfio_group_fd = rte_vfio_get_group_fd(iommu_group_num); - if (vfio_group_fd <= 0) { + if (vfio_group_fd < 0) { RTE_LOG(INFO, EAL, "rte_vfio_get_group_fd failed for %s\n", dev_addr); - ret = -1; + ret = vfio_group_fd; goto out; } diff --git a/lib/librte_eal/linux/eal_vfio_mp_sync.c b/lib/librte_eal/linux/eal_vfio_mp_sync.c index 5f2a5fc1d..6254696ae 100644 --- a/lib/librte_eal/linux/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linux/eal_vfio_mp_sync.c @@ -44,9 +44,9 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer) r->req = SOCKET_REQ_GROUP; r->group_num = m->group_num; fd = rte_vfio_get_group_fd(m->group_num); - if (fd < 0) + if (fd < 0 && fd != -ENOENT) r->result = SOCKET_ERR; - else if (fd == 0) + else if (fd == -ENOENT) /* if VFIO group exists but isn't bound to VFIO driver */ r->result = SOCKET_NO_FD; else { From patchwork Tue May 19 03:42:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 70409 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0C70CA0093; Tue, 19 May 2020 05:42:27 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D3F3C1D5BE; Tue, 19 May 2020 05:42:26 +0200 (CEST) Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) by dpdk.org (Postfix) with ESMTP id 2EBD71D5AC; Tue, 19 May 2020 05:42:25 +0200 (CEST) Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 3D13FC7B9C6D555106CB; Tue, 19 May 2020 11:42:24 +0800 (CST) Received: from localhost (10.173.251.152) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Tue, 19 May 2020 11:42:13 +0800 From: wangyunjian To: CC: , , , , , Yunjian Wang , Date: Tue, 19 May 2020 11:42:12 +0800 Message-ID: <1589859732-5008-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [10.173.251.152] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 2/2] bus/fslmc: fix check for vfio_group_fd 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Yunjian Wang The issue is that a file descriptor at 0 is a valid one. Currently the file not found, the return value will be set to 0. As a result, it is impossible to distinguish between a correct descriptor and a failed return value. Fix it to return -ENOENT instead of 0. Fixes: a69f79300262 ("bus/fslmc: support multi VFIO group") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang Acked-by: Anatoly Burakov Acked-by: Hemant Agrawal --- drivers/bus/fslmc/fslmc_vfio.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 970969d2b..04ccf4af6 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -448,11 +448,14 @@ fslmc_vfio_setup_device(const char *sysfs_base, const char *dev_addr, /* get the actual group fd */ vfio_group_fd = rte_vfio_get_group_fd(iommu_group_no); - if (vfio_group_fd < 0) + if (vfio_group_fd < 0 && vfio_group_fd != -ENOENT) return -1; - /* if group_fd == 0, that means the device isn't managed by VFIO */ - if (vfio_group_fd == 0) { + /* + * if vfio_group_fd == -ENOENT, that means the device + * isn't managed by VFIO + */ + if (vfio_group_fd == -ENOENT) { RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n", dev_addr); return 1;