Skip to content

Commit e3a7c29

Browse files
Mikulas PatockaMike Snitzer
authored andcommitted
dm bufio: fix some cases where the code sleeps with spinlock held
Commit b32d458 ("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: b32d458 ("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>
1 parent b7f362d commit e3a7c29

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

drivers/md/dm-bufio.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,10 @@ static struct dm_buffer *__get_unclaimed_buffer(struct dm_bufio_client *c)
815815
BUG_ON(test_bit(B_WRITING, &b->state));
816816
BUG_ON(test_bit(B_DIRTY, &b->state));
817817

818+
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep &&
819+
unlikely(test_bit(B_READING, &b->state)))
820+
continue;
821+
818822
if (!b->hold_count) {
819823
__make_buffer_clean(b);
820824
__unlink_buffer(b);
@@ -823,6 +827,9 @@ static struct dm_buffer *__get_unclaimed_buffer(struct dm_bufio_client *c)
823827
cond_resched();
824828
}
825829

830+
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
831+
return NULL;
832+
826833
list_for_each_entry_reverse(b, &c->lru[LIST_DIRTY], lru_list) {
827834
BUG_ON(test_bit(B_READING, &b->state));
828835

@@ -1632,7 +1639,8 @@ static void drop_buffers(struct dm_bufio_client *c)
16321639
*/
16331640
static bool __try_evict_buffer(struct dm_buffer *b, gfp_t gfp)
16341641
{
1635-
if (!(gfp & __GFP_FS)) {
1642+
if (!(gfp & __GFP_FS) ||
1643+
(static_branch_unlikely(&no_sleep_enabled) && b->c->no_sleep)) {
16361644
if (test_bit(B_READING, &b->state) ||
16371645
test_bit(B_WRITING, &b->state) ||
16381646
test_bit(B_DIRTY, &b->state))

0 commit comments

Comments
 (0)