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 0C7C542B16; Mon, 15 May 2023 17:51:30 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E1B6D40687; Mon, 15 May 2023 17:51:29 +0200 (CEST) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mails.dpdk.org (Postfix) with ESMTP id 2F55F40395 for ; Mon, 15 May 2023 17:51:29 +0200 (CEST) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1ab1ce53ca6so92444145ad.0 for ; Mon, 15 May 2023 08:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1684165888; x=1686757888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=fJhrAL5ZWsVq97FVCU7rFChLEip0rPeOu9bTY+nZsI0=; b=PmvEM81aTMgBytIQSmy9AcpD0LOB76MDd3wOVJ3r7Rk8BQoGHuuT4xthmrup8z2+r1 nUlbCI4jKetHc0PkPo2s5wcqhsGKsdy5Ef7BbJOXXddaNCkSDmjTvK3G/RI5+xsJQN82 i06LKUuXeEV0CvJYmcnrt+vIiOTaMlisPD7Cg9F8EY03lbyHHGUn9LN6XmbwupOfBGH6 ViSUJ2+xSPdneJTjYYLAfP03FgdpU4rLAtP/cHI2KK+Uh1lLfQ0zz0ogG48+8pbElnfI RNb2gw12bHYE/QYBiyChxbRrU7ipXvDj+95gtHq5xtWOGvrVcNLljhypWybHnOLkzZhq Sk2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684165888; x=1686757888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fJhrAL5ZWsVq97FVCU7rFChLEip0rPeOu9bTY+nZsI0=; b=ZWDCUbaAUAKELPBB5ip5JCCu6T1ryXnkJC8rYrWvnIeMty/hnVWDIaQE9w7xT/GeAT JmlqGYzKGtwjVbS/RHUYf6Vx2QsJDzpp+bX3BuWd7IfYjZ6SwW8Gu6S5R+/21wHUTv/g we3q5C4zG0JCIG2TXbBDz5Aw0y6y0V3BDVkeaM426ofL++2+15rT9JPvY137EhpEc0F9 tLyQGINiFc7Sonfzm/BS8u1Cby+mCyezPAntvUh11PHiqePtCSasspo9mnnNgHM/2L7r m1z0uTJkxEi01KT9fJGPRC18/E7ZMokX3uGC/D89YC28SCJpEQ8PWbXkX+YV2Ydkcxtl X3jA== X-Gm-Message-State: AC+VfDwnY/OMVE9kVzlyVXio3o/PJSnRIP0gCOTe8/j9lR+eqm6OLZXP KzMHVgGjntb09wWjNfL0C0y8Zg== X-Google-Smtp-Source: ACHHUZ4GS7+2EDWop2Nv5evboyAwHk3f5ELyTjT/nAWpu2HgM0ip4x3hIFLvZCiiFYBv6S4Dy5jQJQ== X-Received: by 2002:a17:902:9a04:b0:1ad:bccc:af78 with SMTP id v4-20020a1709029a0400b001adbcccaf78mr18819498plp.58.1684165888205; Mon, 15 May 2023 08:51:28 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id x11-20020a170902fe8b00b001ac45598b59sm13725322plm.163.2023.05.15.08.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 08:51:27 -0700 (PDT) Date: Mon, 15 May 2023 08:51:25 -0700 From: Stephen Hemminger To: David Marchand Cc: dev@dpdk.org, stable@dpdk.org, Maxime Coquelin , Chenbo Xia , Yuanhan Liu Subject: Re: [PATCH v2] vhost: avoid sleeping under mutex Message-ID: <20230515085125.6325f6d8@hermes.local> In-Reply-To: <20230515111844.884784-1-david.marchand@redhat.com> References: <20230322170524.2314715-1-david.marchand@redhat.com> <20230515111844.884784-1-david.marchand@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Mon, 15 May 2023 13:18:44 +0200 David Marchand wrote: > Covscan reported: > > 2. dpdk-21.11/lib/vhost/socket.c:852: lock_acquire: Calling function > "pthread_mutex_lock" acquires lock "vhost_user.mutex". > 23. dpdk-21.11/lib/vhost/socket.c:955: sleep: Call to > "vhost_user_reconnect_init" might sleep while holding lock > "vhost_user.mutex". > # 953| vsocket->reconnect = > !(flags & RTE_VHOST_USER_NO_RECONNECT); > # 954| if (vsocket->reconnect && reconn_tid == 0) { > # 955|-> if (vhost_user_reconnect_init() != 0) > # 956| goto out_mutex; > # 957| } > > The reason for this warning is that vhost_user_reconnect_init() creates a > ctrl thread and calls nanosleep waiting for this thread to be ready, > while vhost_user.mutex is taken. > > Move the call to vhost_user_reconnect_init() out of this mutex. > > While at it, a pthread_t value should be considered opaque. > Instead of relying reconn_tid == 0, use an internal flag in > vhost_user_reconnect_init(). > > Coverity issue: 373686 > Bugzilla ID: 981 > Fixes: e623e0c6d8a5 ("vhost: add reconnect ability") > Cc: stable@dpdk.org > > Signed-off-by: David Marchand > --- > Changes since v1: > - moved reconn_tid in vhost_user_reconnect_init as this > variable is not used anywhere else, > > --- > lib/vhost/socket.c | 19 +++++++++++++------ > 1 file changed, 13 insertions(+), 6 deletions(-) > > diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c > index 669c322e12..00a912c59e 100644 > --- a/lib/vhost/socket.c > +++ b/lib/vhost/socket.c > @@ -427,7 +427,6 @@ struct vhost_user_reconnect_list { > }; > > static struct vhost_user_reconnect_list reconn_list; > -static pthread_t reconn_tid; > > static int > vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz) > @@ -498,8 +497,13 @@ vhost_user_client_reconnect(void *arg __rte_unused) > static int > vhost_user_reconnect_init(void) > { > + static bool reconn_init_done; > + static pthread_t reconn_tid; This would not be thread safe. Perhaps use a pthread condition variable instead of spinning here.