From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DF37D43E57 for ; Sat, 13 Apr 2024 14:51:45 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D8CB440695; Sat, 13 Apr 2024 14:51:45 +0200 (CEST) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2070.outbound.protection.outlook.com [40.107.223.70]) by mails.dpdk.org (Postfix) with ESMTP id C928840695 for ; Sat, 13 Apr 2024 14:51:43 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fnCwMei5/mYg5mGl8tVyUGuObBj2ClO+q+D8ygbFQxw6GzDYWeInY4QaUpLL2yqnib9nMm5+Enc6X0+MK6tiQyaaGbEo0TcfwcpaprrxZ2wIDNjb+CSajJ9LfUHEzswmESIAr8TPNUALFp9Cy2Q5954V4+NiVES4s362c4AFHitAzEIJW31w1Scxqj2CZQuLRTDF6teblvQp7ErEXd7/Terg3R8qSE3ebTb9LoPHwWELsrlcIcIleDlPHtviKN81/hs0UxobljOZW6IXq13vKqvFpY973sYFFgbNxbzNKbu3jZWOi/DELGQ5npF/tz4Wqh62mQM32BMCT9yiXc6dSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3xYz/0gnu0t7UT6urN1yB2UWbyzBDEDyITbhc0LE79E=; b=m+iyQbxuJ4oBLT8pSde4+B40N3/X39FTSsaSzUpkuNrLiunQTpH8Vd8T0BQfd0PMLnPNO5MVWs2YXtSn9nT/W6KBDBdoR0fe5KHrXr+8YbEDxCdzTvKxRf+1s+sRgBUlxlE6HEDAyZhzxncsP3llFzQCSCN0I58elomVLSPUdr4QKwhfqYp2YWIMIDwsufqVlxsQfd9bKaN8KE4YnvO/8PuY7EEdJZyC2Q87Ht7wc6WJVL8M646XHUqlrEKqKAgG5a8rt9EZc3ONtQlB2T1jQLK2WYB8EVgzsA2KEYOPUV1ivApoHFN1r7/DkUo+Hw5xJ+fxsi11ZTVhuaxx7THvUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3xYz/0gnu0t7UT6urN1yB2UWbyzBDEDyITbhc0LE79E=; b=g+UIoYdTxHBG2xJJaW0ftZjqgNjlXRI/GXQcsHlIsr8OrF8BBIJMZFyw1P4RkkDzkNTKFqxMI9IATLIGcQIKdnsGWzSR2UWvTorvs5eVEJxYqwIOd9RkA54i7C9YEYHt/yKtO/aoe6AJMHlCiK/uz7OhYK4xb9BRfyugpS1lGXUkPP5rSbPvuwYOOLfFDAFO3yUHjsSkRjtM6fg5t6JhBBlLfnYL82NLdqacnF3lv7g6mOyVtrmnY2ZHH92CDMlEIa44uZkVW/+kcfSIYa+tKijEnC9XHq3sWP6j51K5wOddwX0qARJ5rA3h8tFlBXjoiKAGCyspBEqrQyKIcu1kXA== Received: from MN2PR08CA0014.namprd08.prod.outlook.com (2603:10b6:208:239::19) by SA3PR12MB7783.namprd12.prod.outlook.com (2603:10b6:806:314::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Sat, 13 Apr 2024 12:51:38 +0000 Received: from BL6PEPF00020E65.namprd04.prod.outlook.com (2603:10b6:208:239:cafe::cd) by MN2PR08CA0014.outlook.office365.com (2603:10b6:208:239::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.30 via Frontend Transport; Sat, 13 Apr 2024 12:51:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL6PEPF00020E65.mail.protection.outlook.com (10.167.249.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.22 via Frontend Transport; Sat, 13 Apr 2024 12:51:37 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sat, 13 Apr 2024 05:51:25 -0700 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Sat, 13 Apr 2024 05:51:24 -0700 From: Xueming Li To: Maxime Coquelin CC: David Marchand , dpdk stable Subject: patch 'vhost: fix VDUSE device destruction failure' has been queued to stable release 23.11.1 Date: Sat, 13 Apr 2024 20:48:13 +0800 Message-ID: <20240413125005.725659-13-xuemingl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240413125005.725659-1-xuemingl@nvidia.com> References: <20240305094757.439387-1-xuemingl@nvidia.com> <20240413125005.725659-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00020E65:EE_|SA3PR12MB7783:EE_ X-MS-Office365-Filtering-Correlation-Id: 3f87cd7d-19d4-4c8e-d717-08dc5bb8755f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4JsjoemCv2k9W9IcpAEQdGIFhVguOPgWDvdj2F2AN+z19aBybW59+1HL78f/J8u4et/EAUBnEhNbYdfFU7sA2cr21g47qKGJ8WdX8ApFJH+9Jh7mP6ynpurq5X7ULws56DDCvhncKSZutVuI1aCYhX33FqgId9p9MukGCZYn15FMgSoABVUVX937b8rL37ymy9B5amdbqP7RQxSMDAXieBw1U3j9iNPvnZs7nXiwpdKcjuHxIAtZRAEn8wjUh1+tLL3yk+hsIY10DLySpLtBQoG5Sg8ruU1CZ1JZr2Ox2frgeyOzgpOLsYvpWhQX25gRVm9cljuX/CRgfTRjplyHyssfVTZ4Ziw8Dzbf3u3gP8qmk0MR1iJWhaZpZIepp3LFYGa9nuUuPNgDoI5uXl8RjtaVcmEtSHD/YiB6TRph3wuGKs9/mrHGnwdGeqbBtG5SWedFGYErIfqHTxSjo4bLM6nHjFQGHqAVlb9NFNEdFDYZQa3kQilvv4fv+m4pwVLTUZ/kC+5sgyUEsHZgE7oMkhd2BK+Y2Zzxab+arAo8TS6WbfTtif235g9AMKiY0sdMOyvonWxzY/S0++69GWdzqxSrYx+NY0cdOAvBUHmllNpJ5RjWoeRoG3Xk7uhsyRDMuE4eiIfBqG+Osd9WabDBdV3Olj3k4/q5f3l12OTQ9hviKe42isFVRvQwQsoJSrQn+uptO/JnbNhE7z35Bo+Du0gvTjlgGEFaT3AwHoYhn0BFrAon5RiTHv7CAKbY6p+p X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230031)(1800799015)(36860700004)(82310400014)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2024 12:51:37.8905 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3f87cd7d-19d4-4c8e-d717-08dc5bb8755f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00020E65.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7783 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 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 Hi, FYI, your patch has been queued to stable release 23.11.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 04/15/24. 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://git.dpdk.org/dpdk-stable/log/?h=23.11-staging This queued commit can be viewed at: https://git.dpdk.org/dpdk-stable/commit/?h=23.11-staging&id=b2dba501cf2d141ae2cb01faf58077b62ffb57d2 Thanks. Xueming Li --- >From b2dba501cf2d141ae2cb01faf58077b62ffb57d2 Mon Sep 17 00:00:00 2001 From: Maxime Coquelin Date: Thu, 29 Feb 2024 13:24:56 +0100 Subject: [PATCH] vhost: fix VDUSE device destruction failure Cc: Xueming Li [ upstream commit deedfb86a7a6e10064d3cccd593f62072de96e36 ] VDUSE_DESTROY_DEVICE ioctl can fail because the device's chardev is not released despite close syscall having been called. It happens because the events handler thread is still polling the file descriptor. fdset_pipe_notify() is not enough because it does not ensure the notification has been handled by the event thread, it just returns once the notification is sent. To fix this, this patch introduces a synchronization mechanism based on pthread's condition, so that fdset_pipe_notify_sync() only returns once the pipe's read callback has been executed. Fixes: 51d018fdac4e ("vhost: add VDUSE events handler") Signed-off-by: Maxime Coquelin Signed-off-by: David Marchand Reviewed-by: Maxime Coquelin --- lib/vhost/fd_man.c | 23 +++++++++++++++++++++-- lib/vhost/fd_man.h | 6 ++++++ lib/vhost/socket.c | 1 + lib/vhost/vduse.c | 3 ++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/vhost/fd_man.c b/lib/vhost/fd_man.c index 134414fb4b..84c5da0793 100644 --- a/lib/vhost/fd_man.c +++ b/lib/vhost/fd_man.c @@ -307,10 +307,11 @@ fdset_event_dispatch(void *arg) } static void -fdset_pipe_read_cb(int readfd, void *dat __rte_unused, +fdset_pipe_read_cb(int readfd, void *dat, int *remove __rte_unused) { char charbuf[16]; + struct fdset *fdset = dat; int r = read(readfd, charbuf, sizeof(charbuf)); /* * Just an optimization, we don't care if read() failed @@ -318,6 +319,11 @@ fdset_pipe_read_cb(int readfd, void *dat __rte_unused, * compiler happy */ RTE_SET_USED(r); + + pthread_mutex_lock(&fdset->sync_mutex); + fdset->sync = true; + pthread_cond_broadcast(&fdset->sync_cond); + pthread_mutex_unlock(&fdset->sync_mutex); } void @@ -340,7 +346,7 @@ fdset_pipe_init(struct fdset *fdset) } ret = fdset_add(fdset, fdset->u.readfd, - fdset_pipe_read_cb, NULL, NULL); + fdset_pipe_read_cb, NULL, fdset); if (ret < 0) { RTE_LOG(ERR, VHOST_FDMAN, @@ -364,5 +370,18 @@ fdset_pipe_notify(struct fdset *fdset) * compiler happy */ RTE_SET_USED(r); +} + +void +fdset_pipe_notify_sync(struct fdset *fdset) +{ + pthread_mutex_lock(&fdset->sync_mutex); + + fdset->sync = false; + fdset_pipe_notify(fdset); + + while (!fdset->sync) + pthread_cond_wait(&fdset->sync_cond, &fdset->sync_mutex); + pthread_mutex_unlock(&fdset->sync_mutex); } diff --git a/lib/vhost/fd_man.h b/lib/vhost/fd_man.h index 6315904c8e..7816fb11ac 100644 --- a/lib/vhost/fd_man.h +++ b/lib/vhost/fd_man.h @@ -6,6 +6,7 @@ #define _FD_MAN_H_ #include #include +#include #define MAX_FDS 1024 @@ -35,6 +36,10 @@ struct fdset { int writefd; }; } u; + + pthread_mutex_t sync_mutex; + pthread_cond_t sync_cond; + bool sync; }; @@ -53,5 +58,6 @@ int fdset_pipe_init(struct fdset *fdset); void fdset_pipe_uninit(struct fdset *fdset); void fdset_pipe_notify(struct fdset *fdset); +void fdset_pipe_notify_sync(struct fdset *fdset); #endif diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index 5882e44176..0b95c54c5b 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -93,6 +93,7 @@ static struct vhost_user vhost_user = { .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} }, .fd_mutex = PTHREAD_MUTEX_INITIALIZER, .fd_pooling_mutex = PTHREAD_MUTEX_INITIALIZER, + .sync_mutex = PTHREAD_MUTEX_INITIALIZER, .num = 0 }, .vsocket_cnt = 0, diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index e198eeef64..b46f0e53c7 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -36,6 +36,7 @@ static struct vduse vduse = { .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} }, .fd_mutex = PTHREAD_MUTEX_INITIALIZER, .fd_pooling_mutex = PTHREAD_MUTEX_INITIALIZER, + .sync_mutex = PTHREAD_MUTEX_INITIALIZER, .num = 0 }, }; @@ -618,7 +619,7 @@ vduse_device_destroy(const char *path) vduse_device_stop(dev); fdset_del(&vduse.fdset, dev->vduse_dev_fd); - fdset_pipe_notify(&vduse.fdset); + fdset_pipe_notify_sync(&vduse.fdset); if (dev->vduse_dev_fd >= 0) { close(dev->vduse_dev_fd); -- 2.34.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-04-13 20:43:05.548843712 +0800 +++ 0013-vhost-fix-VDUSE-device-destruction-failure.patch 2024-04-13 20:43:04.907754049 +0800 @@ -1 +1 @@ -From deedfb86a7a6e10064d3cccd593f62072de96e36 Mon Sep 17 00:00:00 2001 +From b2dba501cf2d141ae2cb01faf58077b62ffb57d2 Mon Sep 17 00:00:00 2001 @@ -4,0 +5,3 @@ +Cc: Xueming Li + +[ upstream commit deedfb86a7a6e10064d3cccd593f62072de96e36 ] @@ -21 +23,0 @@ -Cc: stable@dpdk.org @@ -34 +36 @@ -index 79a8d2c006..481e6b900a 100644 +index 134414fb4b..84c5da0793 100644 @@ -37 +39 @@ -@@ -309,10 +309,11 @@ fdset_event_dispatch(void *arg) +@@ -307,10 +307,11 @@ fdset_event_dispatch(void *arg) @@ -50 +52 @@ -@@ -320,6 +321,11 @@ fdset_pipe_read_cb(int readfd, void *dat __rte_unused, +@@ -318,6 +319,11 @@ fdset_pipe_read_cb(int readfd, void *dat __rte_unused, @@ -62 +64 @@ -@@ -342,7 +348,7 @@ fdset_pipe_init(struct fdset *fdset) +@@ -340,7 +346,7 @@ fdset_pipe_init(struct fdset *fdset) @@ -70,2 +72,2 @@ - VHOST_FDMAN_LOG(ERR, -@@ -366,5 +372,18 @@ fdset_pipe_notify(struct fdset *fdset) + RTE_LOG(ERR, VHOST_FDMAN, +@@ -364,5 +370,18 @@ fdset_pipe_notify(struct fdset *fdset) @@ -121 +123 @@ -index a2fdac30a4..96b3ab5595 100644 +index 5882e44176..0b95c54c5b 100644 @@ -133 +135 @@ -index d462428d2c..e0c6991b69 100644 +index e198eeef64..b46f0e53c7 100644