From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4E1FCA04B1 for ; Thu, 5 Nov 2020 13:41:52 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 47826C31F; Thu, 5 Nov 2020 13:41:51 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by dpdk.org (Postfix) with ESMTP id 39CF2C31F for ; Thu, 5 Nov 2020 13:41:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604580107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z3HGusoYpYMRuG4Uuu2OgLk/Mf4W0pcaa1Q+s9g5gbY=; b=IYPiIx2Y884aIZNMWF99YyQrHXx6feWJO99akx9q1GJLvBsf0j7M06U99HRibDzECIdv4Z ocNbNE+OSeLmEmgdF2oiMKHyhuoiuTFtfIY1GitqI9DtMk7RO4CdJHnS3fTW7OXYEEpzyQ hHIyZPJQnQddgL+tGqaE87kE3mISUCo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-_K4ruiD2Pk6tBU3GmiV6NA-1; Thu, 05 Nov 2020 07:41:43 -0500 X-MC-Unique: _K4ruiD2Pk6tBU3GmiV6NA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B808D107465C; Thu, 5 Nov 2020 12:41:42 +0000 (UTC) Received: from rh.redhat.com (ovpn-113-249.ams2.redhat.com [10.36.113.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC6485C5FD; Thu, 5 Nov 2020 12:41:41 +0000 (UTC) From: Kevin Traynor To: Yunjian Wang Cc: Anatoly Burakov , dpdk stable Date: Thu, 5 Nov 2020 12:39:46 +0000 Message-Id: <20201105124015.306404-39-ktraynor@redhat.com> In-Reply-To: <20201105124015.306404-1-ktraynor@redhat.com> References: <20201105124015.306404-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ktraynor@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-stable] patch 'vfio: fix group descriptor check' has been queued to LTS release 18.11.11 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to LTS release 18.11.11 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/10/20. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable-queue This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable-queue/commit/8cba350de777b2cdf703cb742ff05afcbcc8ea88 Thanks. Kevin. --- >From 8cba350de777b2cdf703cb742ff05afcbcc8ea88 Mon Sep 17 00:00:00 2001 From: Yunjian Wang Date: Tue, 19 May 2020 11:42:00 +0800 Subject: [PATCH] vfio: fix group descriptor check [ upstream commit 1f16fa99aa36e043e395184d6ad37a348eafeba7 ] 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 mapping") Signed-off-by: Yunjian Wang Reviewed-by: Anatoly Burakov --- lib/librte_eal/linuxapp/eal/eal_vfio.c | 23 +++++++++++-------- .../linuxapp/eal/eal_vfio_mp_sync.c | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c index be969bbaac..7c4bd68732 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c @@ -293,5 +293,5 @@ vfio_open_group_fd(int iommu_group_num) return -1; } - return 0; + return -ENOENT; } /* noiommu group found */ @@ -318,10 +318,10 @@ vfio_open_group_fd(int iommu_group_num) } 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,7 +379,7 @@ 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; } @@ -705,9 +705,12 @@ 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); @@ -929,8 +932,8 @@ 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/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c index 2a47f29d5a..126b568c16 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c @@ -44,7 +44,7 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer) 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; -- 2.26.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2020-11-05 12:38:55.005221269 +0000 +++ 0039-vfio-fix-group-descriptor-check.patch 2020-11-05 12:38:54.240896020 +0000 @@ -1 +1 @@ -From 1f16fa99aa36e043e395184d6ad37a348eafeba7 Mon Sep 17 00:00:00 2001 +From 8cba350de777b2cdf703cb742ff05afcbcc8ea88 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 1f16fa99aa36e043e395184d6ad37a348eafeba7 ] + @@ -13 +14,0 @@ -Cc: stable@dpdk.org @@ -18,2 +19,2 @@ - lib/librte_eal/linux/eal_vfio.c | 23 +++++++++++++---------- - lib/librte_eal/linux/eal_vfio_mp_sync.c | 4 ++-- + lib/librte_eal/linuxapp/eal/eal_vfio.c | 23 +++++++++++-------- + .../linuxapp/eal/eal_vfio_mp_sync.c | 4 ++-- @@ -22,5 +23,5 @@ -diff --git a/lib/librte_eal/linux/eal_vfio.c b/lib/librte_eal/linux/eal_vfio.c -index e07979936e..380f2f44aa 100644 ---- a/lib/librte_eal/linux/eal_vfio.c -+++ b/lib/librte_eal/linux/eal_vfio.c -@@ -296,5 +296,5 @@ vfio_open_group_fd(int iommu_group_num) +diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c +index be969bbaac..7c4bd68732 100644 +--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c ++++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c +@@ -293,5 +293,5 @@ vfio_open_group_fd(int iommu_group_num) @@ -33 +34 @@ -@@ -321,10 +321,10 @@ vfio_open_group_fd(int iommu_group_num) +@@ -318,10 +318,10 @@ vfio_open_group_fd(int iommu_group_num) @@ -46 +47 @@ -@@ -382,7 +382,7 @@ vfio_get_group_fd(struct vfio_config *vfio_cfg, +@@ -379,7 +379,7 @@ vfio_get_group_fd(struct vfio_config *vfio_cfg, @@ -56 +57 @@ -@@ -734,9 +734,12 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, +@@ -705,9 +705,12 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, @@ -72 +73 @@ -@@ -976,8 +979,8 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, +@@ -929,8 +932,8 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, @@ -83,5 +84,5 @@ -diff --git a/lib/librte_eal/linux/eal_vfio_mp_sync.c b/lib/librte_eal/linux/eal_vfio_mp_sync.c -index 5f2a5fc1d9..6254696ae5 100644 ---- a/lib/librte_eal/linux/eal_vfio_mp_sync.c -+++ b/lib/librte_eal/linux/eal_vfio_mp_sync.c -@@ -45,7 +45,7 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer) +diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +index 2a47f29d5a..126b568c16 100644 +--- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c ++++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +@@ -44,7 +44,7 @@ vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)