]> git.ipfire.org Git - thirdparty/libvirt.git/commit
nwfilter: fix lock order deadlock
authorMaxim Nestratov <mnestratov@virtuozzo.com>
Sat, 9 Apr 2016 16:14:30 +0000 (19:14 +0300)
committerMaxim Nestratov <mnestratov@virtuozzo.com>
Tue, 24 May 2016 12:24:37 +0000 (15:24 +0300)
commit2f5e24ba00d93c25b87561cb1f5259de175d70f9
tree06243e1c931bb8dd020d4219243c39c33b307221
parenta94efa50e253cb59a2925dca2705bce801f46fb1
nwfilter: fix lock order deadlock

Below is backtraces of two deadlocked threads:

thread #1:
 virDomainConfVMNWFilterTeardown
   virNWFilterTeardownFilter
       lock updateMutex <------------
       _virNWFilterTeardownFilter
            try to lock interface <----------

thread #2:
 learnIPAddressThread
    lock interface <-------
    virNWFilterInstantiateFilterLate
        try to lock updateMutex <----------

The problem is fixed by unlocking interface before calling
virNWFilterInstantiateFilterLate to avoid updateMutex and interface ordering
deadlocks. Otherwise we are going to instantiate the filter while holding
interface lock, which will try to lock updateMutex, and if some other thread
instantiating a filter in parallel is holding updateMutex and is trying to
lock interface, both will deadlock.
Also it is safe to unlock interface before virNWFilterInstantiateFilterLate
because learnIPAddressThread stopped capturing packets and applied necessary
rules on the interface, while instantiating a new filter doesn't require a
locked interface.

Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
src/nwfilter/nwfilter_learnipaddr.c