From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: jasowang@redhat.com
Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: [BUG] vhost: two possible deadlocks involving locking and waiting
Date: Tue, 1 Feb 2022 15:27:32 +0800 [thread overview]
Message-ID: <22f57c53-1a0b-ced9-b36e-1b4de8d55572@gmail.com> (raw)
Hello,
My static analysis tool reports two possible deadlocks in the vhost
driver in Linux 5.16:
#BUG 1
vhost_net_set_backend()
mutex_lock(&n->dev.mutex); --> Line 1511(Lock A)
vhost_net_ubuf_put_wait_and_free()
vhost_net_ubuf_put_and_wait()
wait_event(ubufs->wait ...); --> Line 260 (Wait X)
vhost_net_ioctl()
mutex_lock(&n->dev.mutex); --> Line 1734 (Lock A)
vhost_net_flush()
vhost_net_ubuf_put_and_wait()
vhost_net_ubuf_put()
wake_up(&ubufs->wait); --> Line 253 (Wake X)
When vhost_net_set_backend() is executed, "Wait X" is performed by
holding "Lock A". If vhost_net_ioctl() is executed at this time, "Wake
X" cannot be performed to wake up "Wait X" in vhost_net_set_backend(),
because "Lock A" has been already hold by vhost_net_set_backend(),
causing a possible deadlock.
#BUG2
vhost_net_set_backend()
mutex_lock(&vq->mutex); --> Line 1522(Lock A)
vhost_net_ubuf_put_wait_and_free()
vhost_net_ubuf_put_and_wait()
wait_event(ubufs->wait ...); --> Line 260 (Wait X)
handle_tx()
mutex_lock_nested(&vq->mutex, ...); --> Line 966 (Lock A)
handle_tx_zerocopy()
vhost_net_ubuf_put()
wake_up(&ubufs->wait); --> Line 253 (Wake X)
When vhost_net_set_backend() is executed, "Wait X" is performed by
holding "Lock A". If handle_tx() is executed at this time, "Wake X"
cannot be performed to wake up "Wait X" in vhost_net_set_backend(),
because "Lock A" has been already hold by vhost_net_set_backend(),
causing a possible deadlock.
I am not quite sure whether these possible problems are real and how to
fix them if they are real.
Any feedback would be appreciated, thanks :)
Best wishes,
Jia-Ju Bai
reply other threads:[~2022-02-01 7:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=22f57c53-1a0b-ced9-b36e-1b4de8d55572@gmail.com \
--to=baijiaju1990@gmail.com \
--cc=jasowang@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.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
all inboxes | Powered by JetHome®