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 01E1542B16 for ; Mon, 15 May 2023 17:51:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F32C1410F9; Mon, 15 May 2023 17:51:30 +0200 (CEST) Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by mails.dpdk.org (Postfix) with ESMTP id 30B5440687 for ; Mon, 15 May 2023 17:51:29 +0200 (CEST) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1aaf21bb427so92281125ad.1 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=Ou2OUiUO5vWzGOsVmUKPPYi3gqEgrg4uwWxFvtslDnw6GVeCOj4EGlafc96tV99dL7 eMbrynAIEF6irAc2MrcLBQt/Xv83e1vX0KYO1gmMfP/ea20nowUrWmCKYQoNYuGhxQ0T +5thtCC2lnoWVnyJz7kE3ryrz178RSNPkWQzVGjMDGC8RbBkgS5FAsgmYuJgt15WGl1r kXD/bsopM9WAy/cKOgZG32xDlECE6F7iqecdEOtnMw9Wr9z66SyawWI9rt/iiHw9eK/7 t+CFss8ujFdws6Y1B5oHXdFIvrzUBws/YC4/m+o19VzE/Xe7oQ4g2ZUCqPMTV5vO4iyZ Dc6Q== X-Gm-Message-State: AC+VfDxPtp40+mUv4ampgljqcq6cflBXzuYuUaFiqt3DtDgAK+JsgQnG kO/7dcNKHTovK2ueb0zpyS679A== 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: 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 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.