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 9287BA04DD for ; Wed, 28 Oct 2020 11:51:27 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 87AB4CA12; Wed, 28 Oct 2020 11:51:26 +0100 (CET) Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by dpdk.org (Postfix) with ESMTP id 837E2CA06 for ; Wed, 28 Oct 2020 11:51:23 +0100 (CET) Received: by mail-wm1-f43.google.com with SMTP id k18so4302029wmj.5 for ; Wed, 28 Oct 2020 03:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ood3JZ1idv3n3aBEKwFa/AXr37Epp9F3/hsov7ABv+E=; b=h4b5AM61WTEXma+n6VC4g3RjRtHyauf0GgbQzMXemz9H2J0ZsxT0UZurBijNdfki0K qLQVu4yag3BkanNVUFqYEIosW/vfWlTM0C8ojLUqEJWMPi9f1f42IFE70TKIElOXGS+l q8QHUNXgkOoVw2B0Qm5llUU8JhyAriNuI/b4cQiIEEvFIaUxjSU14+E3fE0uLyVzTH75 9EEExixyLRB2/7C4ouEijZEp1Mv8CVp+ceB55/u2e9ppZuy6eAW2oPm61sIPn6OskYcv fGjeulvUCtGRCNPJXH/M2FeLIWZU5BnMMxM3xuBBYbz3oKKXfECFfZXYQYIdlOnS1AXM 2irA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ood3JZ1idv3n3aBEKwFa/AXr37Epp9F3/hsov7ABv+E=; b=sGYCVBMeVnTPyNxUeTAXAzgq1SJekOTKO8krfBuq8VN1PquOyp8x/jOjbdbsYKe930 cH1Lno3X3YFTbqwsmbIXBHv5K/LekVPAasmQK/PHzLgx76dYUDzSNfBoquBiwE5SY6d1 BHOxKf6lQVHALIkmjjMALG7/flNr/Qsmz8UjxgHajH5hNLtwlgYYUmBGTZvCBwKxsRZt AwOultw73SN01E/w8BNmTeXWvhEg2ewAhcUCxQmlEJVuY1/IdxUM53q1ZzHcNkx8d6AC 636yS0pt6oCaqiVh+oVylFxrV+Xjo+1ZeY/zs4kGN/26K8SU2cqRz3U7Qhxo+4WP/8VM Kxkg== X-Gm-Message-State: AOAM533SO1jnH2vX0wf83o4OaCBRf/cLBK2sZ7VBLbX+EkWmDwTiKwGE TwpoF6c9SbZ15I3zC3mNzfs= X-Google-Smtp-Source: ABdhPJyiU8HLSlEL/CUTyj+PgMFLJagPh5rjVJAYMbseCslMYu/McGwF6nl0ObOJmhQDIsaxbJ7D8g== X-Received: by 2002:a1c:9e0e:: with SMTP id h14mr7313979wme.18.1603882283245; Wed, 28 Oct 2020 03:51:23 -0700 (PDT) Received: from localhost ([88.98.246.218]) by smtp.gmail.com with ESMTPSA id y4sm6217763wrp.74.2020.10.28.03.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 03:51:22 -0700 (PDT) From: luca.boccassi@gmail.com To: Yunjian Wang Cc: Anatoly Burakov , dpdk stable Date: Wed, 28 Oct 2020 10:44:19 +0000 Message-Id: <20201028104606.3504127-100-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201028104606.3504127-1-luca.boccassi@gmail.com> References: <20201028104606.3504127-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'vfio: fix group descriptor check' has been queued to stable release 19.11.6 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 stable release 19.11.6 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 10/30/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. Thanks. Luca Boccassi --- >From 06077f1238d574eb85e8b9430af82afc42768817 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/linux/eal/eal_vfio.c | 23 ++++++++++++--------- lib/librte_eal/linux/eal/eal_vfio_mp_sync.c | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/linux/eal/eal_vfio.c b/lib/librte_eal/linux/eal/eal_vfio.c index 289f066508..1be02e7f13 100644 --- a/lib/librte_eal/linux/eal/eal_vfio.c +++ b/lib/librte_eal/linux/eal/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; @@ -952,10 +955,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/eal_vfio_mp_sync.c b/lib/librte_eal/linux/eal/eal_vfio_mp_sync.c index 5f2a5fc1d9..6254696ae5 100644 --- a/lib/librte_eal/linux/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linux/eal/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 { -- 2.20.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2020-10-28 10:35:14.887278703 +0000 +++ 0100-vfio-fix-group-descriptor-check.patch 2020-10-28 10:35:11.652832202 +0000 @@ -1,8 +1,10 @@ -From 1f16fa99aa36e043e395184d6ad37a348eafeba7 Mon Sep 17 00:00:00 2001 +From 06077f1238d574eb85e8b9430af82afc42768817 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 @@ -10,20 +12,19 @@ Fixes: b758423bc4fe ("vfio: fix race condition with sysfs") Fixes: ff0b67d1c868 ("vfio: DMA mapping") -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 ++-- + lib/librte_eal/linux/eal/eal_vfio.c | 23 ++++++++++++--------- + lib/librte_eal/linux/eal/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 e07979936e..380f2f44aa 100644 ---- a/lib/librte_eal/linux/eal_vfio.c -+++ b/lib/librte_eal/linux/eal_vfio.c -@@ -295,7 +295,7 @@ vfio_open_group_fd(int iommu_group_num) +diff --git a/lib/librte_eal/linux/eal/eal_vfio.c b/lib/librte_eal/linux/eal/eal_vfio.c +index 289f066508..1be02e7f13 100644 +--- a/lib/librte_eal/linux/eal/eal_vfio.c ++++ b/lib/librte_eal/linux/eal/eal_vfio.c +@@ -293,7 +293,7 @@ vfio_open_group_fd(int iommu_group_num) strerror(errno)); return -1; } @@ -32,7 +33,7 @@ } /* noiommu group found */ } -@@ -320,12 +320,12 @@ vfio_open_group_fd(int iommu_group_num) +@@ -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"); @@ -47,7 +48,7 @@ RTE_LOG(ERR, EAL, " cannot request group fd\n"); return vfio_group_fd; } -@@ -381,9 +381,9 @@ vfio_get_group_fd(struct vfio_config *vfio_cfg, +@@ -379,9 +379,9 @@ vfio_get_group_fd(struct vfio_config *vfio_cfg, } vfio_group_fd = vfio_open_group_fd(iommu_group_num); @@ -59,7 +60,7 @@ } cur_grp->group_num = iommu_group_num; -@@ -733,11 +733,14 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, +@@ -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); @@ -77,7 +78,7 @@ RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n", dev_addr); return 1; -@@ -975,10 +978,10 @@ rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, +@@ -952,10 +955,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); @@ -90,10 +91,10 @@ goto out; } -diff --git a/lib/librte_eal/linux/eal_vfio_mp_sync.c b/lib/librte_eal/linux/eal_vfio_mp_sync.c +diff --git a/lib/librte_eal/linux/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linux/eal/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 +--- a/lib/librte_eal/linux/eal/eal_vfio_mp_sync.c ++++ b/lib/librte_eal/linux/eal/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;