• Andrea Righi's avatar
    UBUNTU: SAUCE: bcache: fix deadlock in bcache_allocator · b8ee2db9
    Andrea Righi authored
    bcache_allocator() can call the following:
    
     bch_allocator_thread()
      -> bch_prio_write()
         -> bch_bucket_alloc()
            -> wait on &ca->set->bucket_wait
    
    But the wake up event on bucket_wait is supposed to come from
    bch_allocator_thread() itself => deadlock:
    
    [ 1158.490744] INFO: task bcache_allocato:15861 blocked for more than 10 seconds.
    [ 1158.495929]       Not tainted 5.3.0-050300rc3-generic #201908042232
    [ 1158.500653] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
    [ 1158.504413] bcache_allocato D    0 15861      2 0x80004000
    [ 1158.504419] Call Trace:
    [ 1158.504429]  __schedule+0x2a8/0x670
    [ 1158.504432]  schedule+0x2d/0x90
    [ 1158.504448]  bch_bucket_alloc+0xe5/0x370 [bcache]
    [ 1158.504453]  ? wait_woken+0x80/0x80
    [ 1158.504466]  bch_prio_write+0x1dc/0x390 [bcache]
    [ 1158.504476]  bch_allocator_thread+0x233/0x490 [bcache]
    [ 1158.504491]  kthread+0x121/0x140
    [ 1158.504503]  ? invalidate_buckets+0x890/0x890 [bcache]
    [ 1158.504506]  ? kthread_park+0xb0/0xb0
    [ 1158.504510]  ret_from_fork+0x35/0x40
    
    Fix by making the call to bch_prio_write() non-blocking, so that
    bch_allocator_thread() never waits on itself.
    
    Moreover, make sure to wake up the garbage collector thread when
    bch_prio_write() is failing to allocate buckets.
    
    BugLink: https://bugs.launchpad.net/bugs/1784665
    BugLink: https://bugs.launchpad.net/bugs/1796292Signed-off-by: default avatarAndrea Righi <andrea.righi@canonical.com>
    Acked-by: default avatarStefan Bader <stefan.bader@canonical.com>
    Acked-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
    Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
    b8ee2db9
bcache.h 28.4 KB