From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f66.google.com (mail-lf0-f66.google.com [209.85.215.66]) by dpdk.org (Postfix) with ESMTP id 828FE1B6ED for ; Tue, 15 May 2018 19:20:21 +0200 (CEST) Received: by mail-lf0-f66.google.com with SMTP id p85-v6so1387051lfg.7 for ; Tue, 15 May 2018 10:20:21 -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; bh=ZSconzHVQKdax9SteleHz1k6HQZ+A+MoqSHA8+rw6ME=; b=P07FPshisJcH/kV5FFMXPiZFVWuO+mrj5XES6lkwnIa0Vi4//qXAOWKW+rDbVQ+4BZ 0hXn4Ki9BAEZEwobCEOQKyKrTj8VCT0ooNnixdWOSyyEGWbMy6XcrCtruVCzWBeVcXov /dBYsrOxtBf9pX5bkALD1zo3wj3OGHPVbSNm0rOsWCA6T7eOcEFq63OvjmzLsBisU2Lc tfhWRPsDqcalvF349L+ZcjQjId0uoMJ2bHTCLLpC+cePh1n04H+qnBHKYfglmmwaOe+r N6PYWPfkVJ+yLkghReoA0QD6HTmlnBFAtCUbx73yvTplWeCKrczBliL0mYir2kLNfhEv AWOA== 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; bh=ZSconzHVQKdax9SteleHz1k6HQZ+A+MoqSHA8+rw6ME=; b=mQIcEFPpIPh3lS8nze4ZkOGPVsLhRVY+VV0e/IuHs/IcuszVPuthyZlw1aTiBxsaO+ CszaUuuD25gpNzGKRUIIl4fIY0DqWR+3NFkqIKh4s1sPnu0ef2/hVs5HeIaq68dGzNb7 BiW6ezWvC6FDA3OHhH7rEZkTKjxhr7oeAHaWG+2mL7pIEkrna9GWoV96VPWFR+ANKIzL 188XsE+vtTs5jBoS6j6h0bbqMYkVTs508KECVy09t6XQyQMeFLUldrT09dIPwgHybfdB MC3zATxedsEC7skAED/rJaUtYCwfGtpZ1U/NsYcVoXIVr3ELyhiMV9T+YWXTCLdaT03+ pTLw== X-Gm-Message-State: ALKqPwfe44hI4+2tgaiZotEdSUNojqYzLWhb3XCJBnhRk/elYvl7lOe8 fNjKAVU/GTlF5XLxKwrfICk= X-Google-Smtp-Source: AB8JxZqbV6coB7R19yrutG/H15FaGrMLEWSmJDbxKa8Dkcw6UXiHW5pGBHp1FPt23MO770wxPu8DMg== X-Received: by 2002:a19:6d02:: with SMTP id i2-v6mr13032862lfc.81.1526404821116; Tue, 15 May 2018 10:20:21 -0700 (PDT) Received: from localhost ([2a00:23c5:be9a:5200:ce4c:82c0:d567:ecbb]) by smtp.gmail.com with ESMTPSA id h20-v6sm73924ljj.85.2018.05.15.10.20.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 10:20:20 -0700 (PDT) From: luca.boccassi@gmail.com To: Tonghao Zhang Cc: Maxime Coquelin , dpdk stable Date: Tue, 15 May 2018 18:19:23 +0100 Message-Id: <20180515171933.12882-22-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180515171933.12882-1-luca.boccassi@gmail.com> References: <20180501104509.17238-46-luca.boccassi@gmail.com> <20180515171933.12882-1-luca.boccassi@gmail.com> Subject: [dpdk-stable] patch 'vhost: fix dead lock on closing in server mode' has been queued to LTS release 16.11.7 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: , X-List-Received-Date: Tue, 15 May 2018 17:20:21 -0000 Hi, FYI, your patch has been queued to LTS release 16.11.7 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 05/16/18. So please shout if anyone has objections. Thanks. Luca Boccassi --- >>From a09b3760054c86faeecded8c7de5ae343d4c272f Mon Sep 17 00:00:00 2001 From: Tonghao Zhang Date: Fri, 27 Apr 2018 08:19:43 -0700 Subject: [PATCH] vhost: fix dead lock on closing in server mode [ upstream commit 8b4b949144b80cc7312bbc189d38a3feaf2c74e5 ] When qemu close the unix socket fd of the vhostuser as a server, and then immediately delete the vhostuser port on openvswitch. There will be a deadlock. A thread (fdset event thread): B thread: 1. fdset_event_dispatch rte_vhost_driver_unregister 2. set the fd busy to 1. lock vsocket->conn_mutex 3. vhost_user_read_cb fdset_del waits busy changed to 0. 4. vhost peer closed, remove the conn from vsocket->conn_list: lock vsocket->conn_mutex 5. set the fd busy to 0 Fixes: 65388b43f592 ("vhost: fix fd leaks for vhost-user server mode") Signed-off-by: Tonghao Zhang Acked-by: Maxime Coquelin --- lib/librte_vhost/fd_man.c | 32 ++++++++++++++++++++++++++++++++ lib/librte_vhost/fd_man.h | 1 + lib/librte_vhost/socket.c | 14 +++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c index 8a075da22..d4c5fba43 100644 --- a/lib/librte_vhost/fd_man.c +++ b/lib/librte_vhost/fd_man.c @@ -192,6 +192,38 @@ fdset_del(struct fdset *pfdset, int fd) return dat; } +/** + * Unregister the fd from the fdset. + * + * If parameters are invalid, return directly -2. + * And check whether fd is busy, if yes, return -1. + * Otherwise, try to delete the fd from fdset and + * return true. + */ +int +fdset_try_del(struct fdset *pfdset, int fd) +{ + int i; + + if (pfdset == NULL || fd == -1) + return -2; + + pthread_mutex_lock(&pfdset->fd_mutex); + i = fdset_find_fd(pfdset, fd); + if (i != -1 && pfdset->fd[i].busy) { + pthread_mutex_unlock(&pfdset->fd_mutex); + return -1; + } + + if (i != -1) { + pfdset->fd[i].fd = -1; + pfdset->fd[i].rcb = pfdset->fd[i].wcb = NULL; + pfdset->fd[i].dat = NULL; + } + + pthread_mutex_unlock(&pfdset->fd_mutex); + return 0; +} /** * This functions runs in infinite blocking loop until there is no fd in diff --git a/lib/librte_vhost/fd_man.h b/lib/librte_vhost/fd_man.h index d319cac6e..20781c027 100644 --- a/lib/librte_vhost/fd_man.h +++ b/lib/librte_vhost/fd_man.h @@ -63,6 +63,7 @@ int fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat); void *fdset_del(struct fdset *pfdset, int fd); +int fdset_try_del(struct fdset *pfdset, int fd); void fdset_event_dispatch(struct fdset *pfdset); diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index b9fe25be7..805b2e5b2 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -603,13 +603,25 @@ rte_vhost_driver_unregister(const char *path) vhost_user_remove_reconnect(vsocket); } +again: pthread_mutex_lock(&vsocket->conn_mutex); for (conn = TAILQ_FIRST(&vsocket->conn_list); conn != NULL; conn = next) { next = TAILQ_NEXT(conn, next); - fdset_del(&vhost_user.fdset, conn->connfd); + /* + * If r/wcb is executing, release the + * conn_mutex lock, and try again since + * the r/wcb may use the conn_mutex lock. + */ + if (fdset_try_del(&vhost_user.fdset, + conn->connfd) == -1) { + pthread_mutex_unlock( + &vsocket->conn_mutex); + goto again; + } + RTE_LOG(INFO, VHOST_CONFIG, "free connfd = %d for device '%s'\n", conn->connfd, path); -- 2.14.2