Skip to content

Commit c3adefb

Browse files
committed
Merge tag 'for-6.0/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mike Snitzer: - A few fixes for the DM verity and bufio changes in this merge window - A smatch warning fix for DM writecache locking in writecache_map * tag 'for-6.0/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm bufio: fix some cases where the code sleeps with spinlock held dm writecache: fix smatch warning about invalid return from writecache_map dm verity: fix verity_parse_opt_args parsing dm verity: fix DM_VERITY_OPTS_MAX value yet again dm bufio: simplify DM_BUFIO_CLIENT_NO_SLEEP locking
2 parents 7ce2aa6 + e3a7c29 commit c3adefb

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

drivers/md/dm-bufio.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
struct dm_bufio_client {
8484
struct mutex lock;
8585
spinlock_t spinlock;
86-
unsigned long spinlock_flags;
86+
bool no_sleep;
8787

8888
struct list_head lru[LIST_SIZE];
8989
unsigned long n_buffers[LIST_SIZE];
@@ -93,8 +93,6 @@ struct dm_bufio_client {
9393
s8 sectors_per_block_bits;
9494
void (*alloc_callback)(struct dm_buffer *);
9595
void (*write_callback)(struct dm_buffer *);
96-
bool no_sleep;
97-
9896
struct kmem_cache *slab_buffer;
9997
struct kmem_cache *slab_cache;
10098
struct dm_io_client *dm_io;
@@ -174,23 +172,23 @@ static DEFINE_STATIC_KEY_FALSE(no_sleep_enabled);
174172
static void dm_bufio_lock(struct dm_bufio_client *c)
175173
{
176174
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
177-
spin_lock_irqsave_nested(&c->spinlock, c->spinlock_flags, dm_bufio_in_request());
175+
spin_lock_bh(&c->spinlock);
178176
else
179177
mutex_lock_nested(&c->lock, dm_bufio_in_request());
180178
}
181179

182180
static int dm_bufio_trylock(struct dm_bufio_client *c)
183181
{
184182
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
185-
return spin_trylock_irqsave(&c->spinlock, c->spinlock_flags);
183+
return spin_trylock_bh(&c->spinlock);
186184
else
187185
return mutex_trylock(&c->lock);
188186
}
189187

190188
static void dm_bufio_unlock(struct dm_bufio_client *c)
191189
{
192190
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
193-
spin_unlock_irqrestore(&c->spinlock, c->spinlock_flags);
191+
spin_unlock_bh(&c->spinlock);
194192
else
195193
mutex_unlock(&c->lock);
196194
}
@@ -817,6 +815,10 @@ static struct dm_buffer *__get_unclaimed_buffer(struct dm_bufio_client *c)
817815
BUG_ON(test_bit(B_WRITING, &b->state));
818816
BUG_ON(test_bit(B_DIRTY, &b->state));
819817

818+
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep &&
819+
unlikely(test_bit(B_READING, &b->state)))
820+
continue;
821+
820822
if (!b->hold_count) {
821823
__make_buffer_clean(b);
822824
__unlink_buffer(b);
@@ -825,6 +827,9 @@ static struct dm_buffer *__get_unclaimed_buffer(struct dm_bufio_client *c)
825827
cond_resched();
826828
}
827829

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

@@ -1632,7 +1637,8 @@ static void drop_buffers(struct dm_bufio_client *c)
16321637
*/
16331638
static bool __try_evict_buffer(struct dm_buffer *b, gfp_t gfp)
16341639
{
1635-
if (!(gfp & __GFP_FS)) {
1640+
if (!(gfp & __GFP_FS) ||
1641+
(static_branch_unlikely(&no_sleep_enabled) && b->c->no_sleep)) {
16361642
if (test_bit(B_READING, &b->state) ||
16371643
test_bit(B_WRITING, &b->state) ||
16381644
test_bit(B_DIRTY, &b->state))

drivers/md/dm-verity-target.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#define DM_VERITY_OPT_AT_MOST_ONCE "check_at_most_once"
3939
#define DM_VERITY_OPT_TASKLET_VERIFY "try_verify_in_tasklet"
4040

41-
#define DM_VERITY_OPTS_MAX (3 + DM_VERITY_OPTS_FEC + \
41+
#define DM_VERITY_OPTS_MAX (4 + DM_VERITY_OPTS_FEC + \
4242
DM_VERITY_ROOT_HASH_VERIFICATION_OPTS)
4343

4444
static unsigned dm_verity_prefetch_cluster = DM_VERITY_DEFAULT_PREFETCH_SIZE;
@@ -1053,7 +1053,7 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
10531053
struct dm_verity_sig_opts *verify_args,
10541054
bool only_modifier_opts)
10551055
{
1056-
int r;
1056+
int r = 0;
10571057
unsigned argc;
10581058
struct dm_target *ti = v->ti;
10591059
const char *arg_name;
@@ -1123,8 +1123,18 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v,
11231123
if (r)
11241124
return r;
11251125
continue;
1126+
1127+
} else if (only_modifier_opts) {
1128+
/*
1129+
* Ignore unrecognized opt, could easily be an extra
1130+
* argument to an option whose parsing was skipped.
1131+
* Normal parsing (@only_modifier_opts=false) will
1132+
* properly parse all options (and their extra args).
1133+
*/
1134+
continue;
11261135
}
11271136

1137+
DMERR("Unrecognized verity feature request: %s", arg_name);
11281138
ti->error = "Unrecognized verity feature request";
11291139
return -EINVAL;
11301140
} while (argc && !r);

drivers/md/dm-writecache.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,8 @@ static int writecache_map(struct dm_target *ti, struct bio *bio)
15941594

15951595
default:
15961596
BUG();
1597-
return -1;
1597+
wc_unlock(wc);
1598+
return DM_MAPIO_KILL;
15981599
}
15991600
}
16001601

0 commit comments

Comments
 (0)