DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: Wenwu Ma <wenwux.ma@intel.com>
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>,
	"Xia, Chenbo" <chenbo.xia@intel.com>, dev <dev@dpdk.org>,
	 Jiayu Hu <jiayu.hu@intel.com>,
	"Wang, Yinan" <yinan.wang@intel.com>,
	xingguang.he@intel.com
Subject: Re: [PATCH] vhost: fix deadlock when handling user messages
Date: Thu, 5 May 2022 09:21:59 +0200	[thread overview]
Message-ID: <CAJFAV8wE4UNt08QZ_OxNoy6fBYrvi1S=9O2r=svaOQL1gKJavw@mail.gmail.com> (raw)
In-Reply-To: <20220505134008.2865-1-wenwux.ma@intel.com>

Hello,

On Thu, May 5, 2022 at 7:42 AM Wenwu Ma <wenwux.ma@intel.com> wrote:
>
> In vhost_user_msg_handler(), if vhost message handling
> failed, we should check whether the queue is locked and
> release the lock before returning. Or, it will cause a
> deadlock later.

Fixes: 7f31d4ea05ca ("vhost: fix lock on device readiness notification")
Cc: stable@dpdk.org

>
> Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
> ---
>  lib/vhost/vhost_user.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
> index 1d390677fa..80a5df6e9d 100644
> --- a/lib/vhost/vhost_user.c
> +++ b/lib/vhost/vhost_user.c
> @@ -3113,6 +3113,8 @@ vhost_user_msg_handler(int vid, int fd)
>                 send_vhost_reply(dev, fd, &ctx);
>         } else if (ret == RTE_VHOST_MSG_RESULT_ERR) {
>                 VHOST_LOG_CONFIG(ERR, "(%s) vhost message handling failed.\n", dev->ifname);
> +               if (unlock_required)
> +                       vhost_user_unlock_all_queue_pairs(dev);
>                 return -1;
>         }
>

This fixes the issue, but my concern is that changes in the future
might introduce a new return statement (forgetting to unlock).
I suggest having a single return statement, like:

diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 1d390677fa..4baf969ee0 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -2976,7 +2976,6 @@ vhost_user_msg_handler(int vid, int fd)
                return -1;
        }

-       ret = 0;
        request = ctx.msg.request.master;
        if (request > VHOST_USER_NONE && request < VHOST_USER_MAX &&
                        vhost_message_str[request]) {
@@ -3113,9 +3112,11 @@ vhost_user_msg_handler(int vid, int fd)
                send_vhost_reply(dev, fd, &ctx);
        } else if (ret == RTE_VHOST_MSG_RESULT_ERR) {
                VHOST_LOG_CONFIG(ERR, "(%s) vhost message handling
failed.\n", dev->ifname);
-               return -1;
+               ret = -1;
+               goto unlock;
        }

+       ret = 0;
        for (i = 0; i < dev->nr_vring; i++) {
                struct vhost_virtqueue *vq = dev->virtqueue[i];
                bool cur_ready = vq_is_ready(dev, vq);
@@ -3126,10 +3127,11 @@ vhost_user_msg_handler(int vid, int fd)
                }
        }

+unlock:
        if (unlock_required)
                vhost_user_unlock_all_queue_pairs(dev);

-       if (!virtio_is_ready(dev))
+       if (ret != 0 || !virtio_is_ready(dev))
                goto out;

        /*
@@ -3156,7 +3158,7 @@ vhost_user_msg_handler(int vid, int fd)
        }

 out:
-       return 0;
+       return ret;
 }

 static int process_slave_message_reply(struct virtio_net *dev,


-- 
David Marchand


  reply	other threads:[~2022-05-05  7:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05 13:40 Wenwu Ma
2022-05-05  7:21 ` David Marchand [this message]
2022-05-05 16:17 ` [PATCH v2] " Wenwu Ma
2022-05-06  8:19   ` Xia, Chenbo
2022-05-07 13:27 ` [PATCH v3] vhost: fix deadlock when message handling failed Wenwu Ma
2022-05-07  6:02   ` Xia, Chenbo
2022-05-09  3:13   ` Ling, WeiX
2022-05-17 13:15   ` David Marchand
2022-05-17 13:24   ` Maxime Coquelin
2022-07-11  8:42     ` Pei, Andy
2022-07-11  8:54       ` Xia, Chenbo
2022-07-11  9:02         ` Pei, Andy
2022-07-11  9:14           ` Xia, Chenbo

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='CAJFAV8wE4UNt08QZ_OxNoy6fBYrvi1S=9O2r=svaOQL1gKJavw@mail.gmail.com' \
    --to=david.marchand@redhat.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=jiayu.hu@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=wenwux.ma@intel.com \
    --cc=xingguang.he@intel.com \
    --cc=yinan.wang@intel.com \
    /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).