DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: David Marchand <david.marchand@redhat.com>
Cc: dev@dpdk.org, stable@dpdk.org,
	Maxime Coquelin <maxime.coquelin@redhat.com>,
	Chenbo Xia <chenbo.xia@intel.com>,
	Yuanhan Liu <yliu@fridaylinux.org>
Subject: Re: [PATCH v2] vhost: avoid sleeping under mutex
Date: Mon, 15 May 2023 08:51:25 -0700	[thread overview]
Message-ID: <20230515085125.6325f6d8@hermes.local> (raw)
In-Reply-To: <20230515111844.884784-1-david.marchand@redhat.com>

On Mon, 15 May 2023 13:18:44 +0200
David Marchand <david.marchand@redhat.com> 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 <david.marchand@redhat.com>
> ---
> 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.

      reply	other threads:[~2023-05-15 15:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22 17:05 [PATCH] " David Marchand
2023-05-11  8:10 ` Xia, Chenbo
2023-05-15 11:22   ` David Marchand
2023-05-15 11:18 ` [PATCH v2] " David Marchand
2023-05-15 15:51   ` Stephen Hemminger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230515085125.6325f6d8@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=chenbo.xia@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=stable@dpdk.org \
    --cc=yliu@fridaylinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).