]> git.baikalelectronics.ru Git - kernel.git/commit
vhost: fix ref cnt checking deadlock
authorMichael S. Tsirkin <mst@redhat.com>
Thu, 13 Feb 2014 09:42:05 +0000 (11:42 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 13 Feb 2014 23:47:30 +0000 (18:47 -0500)
commit54494f6488bf2837f190d2190324e6e8a0c987b5
tree0822d50ade14f1ab57ec2cd4fa878611f3ba752f
parentb3b9973441182bf2005ffead50e32c3cfd8d2fbb
vhost: fix ref cnt checking deadlock

vhost checked the counter within the refcnt before decrementing.  It
really wanted to know that it is the one that has the last reference, as
a way to batch freeing resources a bit more efficiently.

Note: we only let refcount go to 0 on device release.

This works well but we now access the ref counter twice so there's a
race: all users might see a high count and decide to defer freeing
resources.
In the end no one initiates freeing resources until the last reference
is gone (which is on VM shotdown so might happen after a looooong time).

Let's do what we probably should have done straight away:
switch from kref to plain atomic, documenting the
semantics, return the refcount value atomically after decrement,
then use that to avoid the deadlock.

Reported-by: Qin Chuanyu <qinchuanyu@huawei.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/vhost/net.c