Skip to content

Commit efc1fd6

Browse files
committed
Merge tag 'block-5.13-2021-06-12' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "A few fixes that should go into 5.13: - Fix a regression deadlock introduced in this release between open and remove of a bdev (Christoph) - Fix an async_xor md regression in this release (Xiao) - Fix bcache oversized read issue (Coly)" * tag 'block-5.13-2021-06-12' of git://git.kernel.dk/linux-block: block: loop: fix deadlock between open and remove async_xor: check src_offs is not NULL before updating it bcache: avoid oversized read request in cache missing code path bcache: remove bcache device self-defined readahead
2 parents b2568ee + 85f3f17 commit efc1fd6

File tree

8 files changed

+17
-52
lines changed

8 files changed

+17
-52
lines changed

crypto/async_tx/async_xor.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ async_xor_offs(struct page *dest, unsigned int offset,
233233
if (submit->flags & ASYNC_TX_XOR_DROP_DST) {
234234
src_cnt--;
235235
src_list++;
236-
src_offs++;
236+
if (src_offs)
237+
src_offs++;
237238
}
238239

239240
/* wait for any prerequisite operations */

drivers/block/loop.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,29 +1879,18 @@ static int lo_compat_ioctl(struct block_device *bdev, fmode_t mode,
18791879

18801880
static int lo_open(struct block_device *bdev, fmode_t mode)
18811881
{
1882-
struct loop_device *lo;
1882+
struct loop_device *lo = bdev->bd_disk->private_data;
18831883
int err;
18841884

1885-
/*
1886-
* take loop_ctl_mutex to protect lo pointer from race with
1887-
* loop_control_ioctl(LOOP_CTL_REMOVE), however, to reduce contention
1888-
* release it prior to updating lo->lo_refcnt.
1889-
*/
1890-
err = mutex_lock_killable(&loop_ctl_mutex);
1891-
if (err)
1892-
return err;
1893-
lo = bdev->bd_disk->private_data;
1894-
if (!lo) {
1895-
mutex_unlock(&loop_ctl_mutex);
1896-
return -ENXIO;
1897-
}
18981885
err = mutex_lock_killable(&lo->lo_mutex);
1899-
mutex_unlock(&loop_ctl_mutex);
19001886
if (err)
19011887
return err;
1902-
atomic_inc(&lo->lo_refcnt);
1888+
if (lo->lo_state == Lo_deleting)
1889+
err = -ENXIO;
1890+
else
1891+
atomic_inc(&lo->lo_refcnt);
19031892
mutex_unlock(&lo->lo_mutex);
1904-
return 0;
1893+
return err;
19051894
}
19061895

19071896
static void lo_release(struct gendisk *disk, fmode_t mode)
@@ -2285,7 +2274,7 @@ static long loop_control_ioctl(struct file *file, unsigned int cmd,
22852274
mutex_unlock(&lo->lo_mutex);
22862275
break;
22872276
}
2288-
lo->lo_disk->private_data = NULL;
2277+
lo->lo_state = Lo_deleting;
22892278
mutex_unlock(&lo->lo_mutex);
22902279
idr_remove(&loop_index_idr, lo->lo_number);
22912280
loop_remove(lo);

drivers/block/loop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ enum {
2222
Lo_unbound,
2323
Lo_bound,
2424
Lo_rundown,
25+
Lo_deleting,
2526
};
2627

2728
struct loop_func_table;

drivers/md/bcache/bcache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ struct cached_dev {
364364

365365
/* The rest of this all shows up in sysfs */
366366
unsigned int sequential_cutoff;
367-
unsigned int readahead;
368367

369368
unsigned int io_disable:1;
370369
unsigned int verify:1;

drivers/md/bcache/request.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,9 @@ static int cached_dev_cache_miss(struct btree *b, struct search *s,
880880
struct bio *bio, unsigned int sectors)
881881
{
882882
int ret = MAP_CONTINUE;
883-
unsigned int reada = 0;
884883
struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
885884
struct bio *miss, *cache_bio;
885+
unsigned int size_limit;
886886

887887
s->cache_missed = 1;
888888

@@ -892,14 +892,10 @@ static int cached_dev_cache_miss(struct btree *b, struct search *s,
892892
goto out_submit;
893893
}
894894

895-
if (!(bio->bi_opf & REQ_RAHEAD) &&
896-
!(bio->bi_opf & (REQ_META|REQ_PRIO)) &&
897-
s->iop.c->gc_stats.in_use < CUTOFF_CACHE_READA)
898-
reada = min_t(sector_t, dc->readahead >> 9,
899-
get_capacity(bio->bi_bdev->bd_disk) -
900-
bio_end_sector(bio));
901-
902-
s->insert_bio_sectors = min(sectors, bio_sectors(bio) + reada);
895+
/* Limitation for valid replace key size and cache_bio bvecs number */
896+
size_limit = min_t(unsigned int, BIO_MAX_VECS * PAGE_SECTORS,
897+
(1 << KEY_SIZE_BITS) - 1);
898+
s->insert_bio_sectors = min3(size_limit, sectors, bio_sectors(bio));
903899

904900
s->iop.replace_key = KEY(s->iop.inode,
905901
bio->bi_iter.bi_sector + s->insert_bio_sectors,
@@ -911,7 +907,8 @@ static int cached_dev_cache_miss(struct btree *b, struct search *s,
911907

912908
s->iop.replace = true;
913909

914-
miss = bio_next_split(bio, sectors, GFP_NOIO, &s->d->bio_split);
910+
miss = bio_next_split(bio, s->insert_bio_sectors, GFP_NOIO,
911+
&s->d->bio_split);
915912

916913
/* btree_search_recurse()'s btree iterator is no good anymore */
917914
ret = miss == bio ? MAP_DONE : -EINTR;
@@ -933,9 +930,6 @@ static int cached_dev_cache_miss(struct btree *b, struct search *s,
933930
if (bch_bio_alloc_pages(cache_bio, __GFP_NOWARN|GFP_NOIO))
934931
goto out_put;
935932

936-
if (reada)
937-
bch_mark_cache_readahead(s->iop.c, s->d);
938-
939933
s->cache_miss = miss;
940934
s->iop.bio = cache_bio;
941935
bio_get(cache_bio);

drivers/md/bcache/stats.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ read_attribute(cache_misses);
4646
read_attribute(cache_bypass_hits);
4747
read_attribute(cache_bypass_misses);
4848
read_attribute(cache_hit_ratio);
49-
read_attribute(cache_readaheads);
5049
read_attribute(cache_miss_collisions);
5150
read_attribute(bypassed);
5251

@@ -64,7 +63,6 @@ SHOW(bch_stats)
6463
DIV_SAFE(var(cache_hits) * 100,
6564
var(cache_hits) + var(cache_misses)));
6665

67-
var_print(cache_readaheads);
6866
var_print(cache_miss_collisions);
6967
sysfs_hprint(bypassed, var(sectors_bypassed) << 9);
7068
#undef var
@@ -86,7 +84,6 @@ static struct attribute *bch_stats_files[] = {
8684
&sysfs_cache_bypass_hits,
8785
&sysfs_cache_bypass_misses,
8886
&sysfs_cache_hit_ratio,
89-
&sysfs_cache_readaheads,
9087
&sysfs_cache_miss_collisions,
9188
&sysfs_bypassed,
9289
NULL
@@ -113,7 +110,6 @@ void bch_cache_accounting_clear(struct cache_accounting *acc)
113110
acc->total.cache_misses = 0;
114111
acc->total.cache_bypass_hits = 0;
115112
acc->total.cache_bypass_misses = 0;
116-
acc->total.cache_readaheads = 0;
117113
acc->total.cache_miss_collisions = 0;
118114
acc->total.sectors_bypassed = 0;
119115
}
@@ -145,7 +141,6 @@ static void scale_stats(struct cache_stats *stats, unsigned long rescale_at)
145141
scale_stat(&stats->cache_misses);
146142
scale_stat(&stats->cache_bypass_hits);
147143
scale_stat(&stats->cache_bypass_misses);
148-
scale_stat(&stats->cache_readaheads);
149144
scale_stat(&stats->cache_miss_collisions);
150145
scale_stat(&stats->sectors_bypassed);
151146
}
@@ -168,7 +163,6 @@ static void scale_accounting(struct timer_list *t)
168163
move_stat(cache_misses);
169164
move_stat(cache_bypass_hits);
170165
move_stat(cache_bypass_misses);
171-
move_stat(cache_readaheads);
172166
move_stat(cache_miss_collisions);
173167
move_stat(sectors_bypassed);
174168

@@ -209,14 +203,6 @@ void bch_mark_cache_accounting(struct cache_set *c, struct bcache_device *d,
209203
mark_cache_stats(&c->accounting.collector, hit, bypass);
210204
}
211205

212-
void bch_mark_cache_readahead(struct cache_set *c, struct bcache_device *d)
213-
{
214-
struct cached_dev *dc = container_of(d, struct cached_dev, disk);
215-
216-
atomic_inc(&dc->accounting.collector.cache_readaheads);
217-
atomic_inc(&c->accounting.collector.cache_readaheads);
218-
}
219-
220206
void bch_mark_cache_miss_collision(struct cache_set *c, struct bcache_device *d)
221207
{
222208
struct cached_dev *dc = container_of(d, struct cached_dev, disk);

drivers/md/bcache/stats.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ struct cache_stat_collector {
77
atomic_t cache_misses;
88
atomic_t cache_bypass_hits;
99
atomic_t cache_bypass_misses;
10-
atomic_t cache_readaheads;
1110
atomic_t cache_miss_collisions;
1211
atomic_t sectors_bypassed;
1312
};

drivers/md/bcache/sysfs.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ rw_attribute(io_disable);
137137
rw_attribute(discard);
138138
rw_attribute(running);
139139
rw_attribute(label);
140-
rw_attribute(readahead);
141140
rw_attribute(errors);
142141
rw_attribute(io_error_limit);
143142
rw_attribute(io_error_halflife);
@@ -260,7 +259,6 @@ SHOW(__bch_cached_dev)
260259
var_printf(partial_stripes_expensive, "%u");
261260

262261
var_hprint(sequential_cutoff);
263-
var_hprint(readahead);
264262

265263
sysfs_print(running, atomic_read(&dc->running));
266264
sysfs_print(state, states[BDEV_STATE(&dc->sb)]);
@@ -365,7 +363,6 @@ STORE(__cached_dev)
365363
sysfs_strtoul_clamp(sequential_cutoff,
366364
dc->sequential_cutoff,
367365
0, UINT_MAX);
368-
d_strtoi_h(readahead);
369366

370367
if (attr == &sysfs_clear_stats)
371368
bch_cache_accounting_clear(&dc->accounting);
@@ -538,7 +535,6 @@ static struct attribute *bch_cached_dev_files[] = {
538535
&sysfs_running,
539536
&sysfs_state,
540537
&sysfs_label,
541-
&sysfs_readahead,
542538
#ifdef CONFIG_BCACHE_DEBUG
543539
&sysfs_verify,
544540
&sysfs_bypass_torture_test,

0 commit comments

Comments
 (0)