Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm bufio: fix some cases where the code sleeps with spinlock held

Commit b32d45824aa7 ("dm bufio: Add DM_BUFIO_CLIENT_NO_SLEEP flag")
added a "NO_SLEEP" mode, it replaces a mutex with a spinlock, and it
is only usable when the device is in read-only mode (because the write
path may be sleeping while holding the dm_bufio_client lock).

However, there are still two points where the code could sleep even in
read-only mode. One is in __get_unclaimed_buffer -> __make_buffer_clean.
The other is in __try_evict_buffer -> __make_buffer_clean. These functions
will call __make_buffer_clean which sleeps if the buffer is being read.

Fix these cases so that if c->no_sleep is set __make_buffer_clean
will not be called and the buffer will be skipped instead.

Fixes: b32d45824aa7 ("dm bufio: Add DM_BUFIO_CLIENT_NO_SLEEP flag")
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>

authored by

Mikulas Patocka and committed by
Mike Snitzer
e3a7c294 b7f362d6

+9 -1
+9 -1
drivers/md/dm-bufio.c
··· 815 815 BUG_ON(test_bit(B_WRITING, &b->state)); 816 816 BUG_ON(test_bit(B_DIRTY, &b->state)); 817 817 818 + if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep && 819 + unlikely(test_bit(B_READING, &b->state))) 820 + continue; 821 + 818 822 if (!b->hold_count) { 819 823 __make_buffer_clean(b); 820 824 __unlink_buffer(b); ··· 826 822 } 827 823 cond_resched(); 828 824 } 825 + 826 + if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep) 827 + return NULL; 829 828 830 829 list_for_each_entry_reverse(b, &c->lru[LIST_DIRTY], lru_list) { 831 830 BUG_ON(test_bit(B_READING, &b->state)); ··· 1639 1632 */ 1640 1633 static bool __try_evict_buffer(struct dm_buffer *b, gfp_t gfp) 1641 1634 { 1642 - if (!(gfp & __GFP_FS)) { 1635 + if (!(gfp & __GFP_FS) || 1636 + (static_branch_unlikely(&no_sleep_enabled) && b->c->no_sleep)) { 1643 1637 if (test_bit(B_READING, &b->state) || 1644 1638 test_bit(B_WRITING, &b->state) || 1645 1639 test_bit(B_DIRTY, &b->state))