Commit ee1aa06b authored by Logan Gunthorpe's avatar Logan Gunthorpe Committed by Jens Axboe

md/raid5: Convert prepare_to_wait() to wait_woken() api

raid5_get_active_stripe() can sleep in various situations and it
is called by make_stripe_request() while inside the
prepare_to_wait()/finish_wait() section. Nested waits like this are
not supported.

This was noticed while making other changes that add different sleeps
to raid5_get_active_stripe() that caused a WARNING with
CONFIG_DEBUG_ATOMIC_SLEEP.

No ill effects have been noticed with the code as is, but theoretically
a nested and here could cause a dead lock so it should be fixed.

To fix this, convert the prepare_to_wait() call to use wake_woken()
which supports nested sleeps.

Link: https://lwn.net/Articles/628628/Signed-off-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Signed-off-by: default avatarSong Liu <song@kernel.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent b9f91d80
...@@ -6044,12 +6044,12 @@ static enum stripe_result make_stripe_request(struct mddev *mddev, ...@@ -6044,12 +6044,12 @@ static enum stripe_result make_stripe_request(struct mddev *mddev,
static bool raid5_make_request(struct mddev *mddev, struct bio * bi) static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
{ {
DEFINE_WAIT_FUNC(wait, woken_wake_function);
struct r5conf *conf = mddev->private; struct r5conf *conf = mddev->private;
sector_t logical_sector; sector_t logical_sector;
struct stripe_request_ctx ctx = {}; struct stripe_request_ctx ctx = {};
const int rw = bio_data_dir(bi); const int rw = bio_data_dir(bi);
enum stripe_result res; enum stripe_result res;
DEFINE_WAIT(w);
int s, stripe_cnt; int s, stripe_cnt;
if (unlikely(bi->bi_opf & REQ_PREFLUSH)) { if (unlikely(bi->bi_opf & REQ_PREFLUSH)) {
...@@ -6112,7 +6112,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) ...@@ -6112,7 +6112,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
return true; return true;
} }
md_account_bio(mddev, &bi); md_account_bio(mddev, &bi);
prepare_to_wait(&conf->wait_for_overlap, &w, TASK_UNINTERRUPTIBLE);
add_wait_queue(&conf->wait_for_overlap, &wait);
while (1) { while (1) {
res = make_stripe_request(mddev, conf, &ctx, logical_sector, res = make_stripe_request(mddev, conf, &ctx, logical_sector,
bi); bi);
...@@ -6135,9 +6136,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) ...@@ -6135,9 +6136,8 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
ctx.batch_last = NULL; ctx.batch_last = NULL;
} }
schedule(); wait_woken(&wait, TASK_UNINTERRUPTIBLE,
prepare_to_wait(&conf->wait_for_overlap, &w, MAX_SCHEDULE_TIMEOUT);
TASK_UNINTERRUPTIBLE);
continue; continue;
} }
...@@ -6148,8 +6148,7 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi) ...@@ -6148,8 +6148,7 @@ static bool raid5_make_request(struct mddev *mddev, struct bio * bi)
logical_sector = ctx.first_sector + logical_sector = ctx.first_sector +
(s << RAID5_STRIPE_SHIFT(conf)); (s << RAID5_STRIPE_SHIFT(conf));
} }
remove_wait_queue(&conf->wait_for_overlap, &wait);
finish_wait(&conf->wait_for_overlap, &w);
if (ctx.batch_last) if (ctx.batch_last)
raid5_release_stripe(ctx.batch_last); raid5_release_stripe(ctx.batch_last);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment