[SRU][E][PATCH v2 0/1] bcache: fix hung task timeout in bch_bucket_alloc()

Andrea Righi andrea.righi at canonical.com
Wed Aug 7 12:58:46 UTC 2019


BugLink: https://bugs.launchpad.net/bugs/1784665

[Impact]

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 causing a deadlock.

[Test Case]

This is a simple script that can easily trigger the deadlock condition:
https://launchpadlibrarian.net/381282009/bcache-basic-repro.sh

A better test case has been also provided in LP: #1796292:
https://bugs.launchpad.net/curtin/+bug/1796292/+attachment/5280353/+files/curtin-nvme.sh

[Fix]

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 to increase the chance of freeing up more buckets.

[Regression Potential]

Even if this patch is not yet applied upstream (posted to the LKML), it
seems to reliably fix/prevent the specific deadlock problem reported in
this bug, so it should be considered safe to apply it as it is for now,
to prevent potential hung task timeout conditions.

Changes in v2:
 - fix potential buckets leak

----------------------------------------------------------------
Andrea Righi (1):
      UBUNTU: SAUCE: bcache: fix deadlock in bcache_allocator

 drivers/md/bcache/alloc.c  |  5 ++++-
 drivers/md/bcache/bcache.h |  2 +-
 drivers/md/bcache/super.c  | 27 +++++++++++++++++++++------
 3 files changed, 26 insertions(+), 8 deletions(-)




More information about the kernel-team mailing list