Netdev Archive on
help / color / mirror / Atom feed
* [PATCH] vsock/virtio: avoid potential deadlock when vsock device remove
@ 2021-08-12  1:09 Longpeng(Mike)
  0 siblings, 0 replies; only message in thread
From: Longpeng(Mike) @ 2021-08-12  1:09 UTC (permalink / raw)
  To: sgarzare
  Cc: kvm, virtualization, netdev, arei.gonglei, Longpeng(Mike),
	Stefan Hajnoczi, David S. Miller, Jakub Kicinski

There's a potential deadlock case when remove the vsock device or
process the RESET event:

      spin_lock_bh(&vsock_table_lock) ----------- (1)
              lock_sock(sk) --------------------- (2)

lock_sock() may do initiative schedule when the 'sk' is owned by
other thread at the same time, we would receivce a warning message
that "scheduling while atomic".

Even worse, if the next task (selected by the scheduler) try to
release a 'sk', it need to request vsock_table_lock and the deadlock
occur, cause the system into softlockup state.
  Call trace:

So we should not require sk_lock in this case, just like the behavior
in vhost_vsock or vmci.

Cc: Stefan Hajnoczi <>
Cc: Stefano Garzarella <>
Cc: "David S. Miller" <>
Cc: Jakub Kicinski <>
Signed-off-by: Longpeng(Mike) <>
 net/vmw_vsock/virtio_transport.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index e0c2c99..4f7c99d 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -357,11 +357,14 @@ static void virtio_vsock_event_fill(struct virtio_vsock *vsock)
 static void virtio_vsock_reset_sock(struct sock *sk)
-	lock_sock(sk);
+	/* vmci_transport.c doesn't take sk_lock here either.  At least we're
+	 * under vsock_table_lock so the sock cannot disappear while we're
+	 * executing.
+	 */
 	sk->sk_state = TCP_CLOSE;
 	sk->sk_err = ECONNRESET;
-	release_sock(sk);
 static void virtio_vsock_update_guest_cid(struct virtio_vsock *vsock)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-12  1:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12  1:09 [PATCH] vsock/virtio: avoid potential deadlock when vsock device remove Longpeng(Mike)

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).