mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 02:21:39 -04:00
md/raid5: fix lockless max_nr_stripes reads
max_nr_stripes is updated under cache_size_mutex in the stripe cache grow/shrink paths, while is_inactive_blocked() and raid5_end_read_request() read it without that lock. Use READ_ONCE() for those reads in lockless path to match the WRITE_ONCE() updates and avoid KCSAN data race reports. A similar issue was previously fixed in commit-id:dfd2bf4367. Fixes:0009fad033("raid5 improve too many read errors msg by adding limits") Fixes:3514da58be("md/raid5: Make is_inactive_blocked() helper") KCSAN report: ================= BUG: KCSAN: data-race in grow_one_stripe / is_inactive_blocked write (marked) to 0xffff8f01f0b5a268 of 4 bytes by task 12616 on cpu 9: grow_one_stripe+0x2d8/0x320 raid5d+0xb57/0xba0 md_thread+0x15a/0x2d0 [..........] read to 0xffff8f01f0b5a268 of 4 bytes by task 12670 on cpu 11: is_inactive_blocked+0x97/0xc0 raid5_get_active_stripe+0x2fd/0xa70 raid5_make_request+0x4aa/0x2940 [..........] value changed: 0x000003b9 -> 0x000003ba Signed-off-by: Chen Cheng <chencheng@fnnas.com> Reviewed-by: Yu Kuai <yukuai@fygo.io> Link: https://patch.msgid.link/20260624024042.2561803-1-chencheng@fnnas.com Signed-off-by: Yu Kuai <yukuai@fygo.io>
This commit is contained in:
@@ -801,7 +801,7 @@ static bool is_inactive_blocked(struct r5conf *conf, int hash)
|
||||
return true;
|
||||
|
||||
return (atomic_read(&conf->active_stripes) <
|
||||
(conf->max_nr_stripes * 3 / 4));
|
||||
(READ_ONCE(conf->max_nr_stripes) * 3 / 4));
|
||||
}
|
||||
|
||||
struct stripe_head *raid5_get_active_stripe(struct r5conf *conf,
|
||||
@@ -2785,6 +2785,7 @@ static void raid5_end_read_request(struct bio * bi)
|
||||
} else {
|
||||
int retry = 0;
|
||||
int set_bad = 0;
|
||||
int max_nr_stripes = READ_ONCE(conf->max_nr_stripes);
|
||||
|
||||
clear_bit(R5_UPTODATE, &sh->dev[i].flags);
|
||||
if (!(bi->bi_status == BLK_STS_PROTECTION))
|
||||
@@ -2810,13 +2811,12 @@ static void raid5_end_read_request(struct bio * bi)
|
||||
mdname(conf->mddev),
|
||||
(unsigned long long)s,
|
||||
rdev->bdev);
|
||||
} else if (atomic_read(&rdev->read_errors)
|
||||
> conf->max_nr_stripes) {
|
||||
} else if (atomic_read(&rdev->read_errors) > max_nr_stripes) {
|
||||
if (!test_bit(Faulty, &rdev->flags)) {
|
||||
pr_warn("md/raid:%s: %d read_errors > %d stripes\n",
|
||||
mdname(conf->mddev),
|
||||
atomic_read(&rdev->read_errors),
|
||||
conf->max_nr_stripes);
|
||||
max_nr_stripes);
|
||||
pr_warn("md/raid:%s: Too many read errors, failing device %pg.\n",
|
||||
mdname(conf->mddev), rdev->bdev);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user