Skip to content

Commit 2a89b99

Browse files
committed
Merge tag 'for-5.8/dm-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mike Snitzer: - A request-based DM fix to not use a waitqueue to wait for blk-mq IO completion because doing so is racey. - A couple more DM zoned target fixes to address issues introduced during the 5.8 cycle. - A DM core fix to use proper interface to cleanup DM's static flush bio. - A DM core fix to prevent mm recursion during memory allocation needed by dm_kobject_uevent. * tag 'for-5.8/dm-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm: use noio when sending kobject event dm zoned: Fix zone reclaim trigger dm zoned: fix unused but set variable warnings dm writecache: reject asynchronous pmem devices dm: use bio_uninit instead of bio_disassociate_blkg dm: do not use waitqueue for request-based DM
2 parents ce69fb3 + 6958c1c commit 2a89b99

File tree

6 files changed

+71
-49
lines changed

6 files changed

+71
-49
lines changed

drivers/md/dm-rq.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ static void rq_end_stats(struct mapped_device *md, struct request *orig)
146146
*/
147147
static void rq_completed(struct mapped_device *md)
148148
{
149-
/* nudge anyone waiting on suspend queue */
150-
if (unlikely(wq_has_sleeper(&md->wait)))
151-
wake_up(&md->wait);
152-
153149
/*
154150
* dm_put() must be at the end of this function. See the comment above
155151
*/

drivers/md/dm-writecache.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,12 @@ static int writecache_ctr(struct dm_target *ti, unsigned argc, char **argv)
22662266
}
22672267

22682268
if (WC_MODE_PMEM(wc)) {
2269+
if (!dax_synchronous(wc->ssd_dev->dax_dev)) {
2270+
r = -EOPNOTSUPP;
2271+
ti->error = "Asynchronous persistent memory not supported as pmem cache";
2272+
goto bad;
2273+
}
2274+
22692275
r = persistent_memory_claim(wc);
22702276
if (r) {
22712277
ti->error = "Unable to map persistent memory for cache";

drivers/md/dm-zoned-metadata.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,8 +2217,15 @@ struct dm_zone *dmz_alloc_zone(struct dmz_metadata *zmd, unsigned int dev_idx,
22172217
{
22182218
struct list_head *list;
22192219
struct dm_zone *zone;
2220-
int i = 0;
2220+
int i;
2221+
2222+
/* Schedule reclaim to ensure free zones are available */
2223+
if (!(flags & DMZ_ALLOC_RECLAIM)) {
2224+
for (i = 0; i < zmd->nr_devs; i++)
2225+
dmz_schedule_reclaim(zmd->dev[i].reclaim);
2226+
}
22212227

2228+
i = 0;
22222229
again:
22232230
if (flags & DMZ_ALLOC_CACHE)
22242231
list = &zmd->unmap_cache_list;

drivers/md/dm-zoned-reclaim.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ static unsigned int dmz_reclaim_percentage(struct dmz_reclaim *zrc)
456456
nr_zones = dmz_nr_rnd_zones(zmd, zrc->dev_idx);
457457
nr_unmap = dmz_nr_unmap_rnd_zones(zmd, zrc->dev_idx);
458458
}
459+
if (nr_unmap <= 1)
460+
return 0;
459461
return nr_unmap * 100 / nr_zones;
460462
}
461463

@@ -501,7 +503,7 @@ static void dmz_reclaim_work(struct work_struct *work)
501503
{
502504
struct dmz_reclaim *zrc = container_of(work, struct dmz_reclaim, work.work);
503505
struct dmz_metadata *zmd = zrc->metadata;
504-
unsigned int p_unmap, nr_unmap_rnd = 0, nr_rnd = 0;
506+
unsigned int p_unmap;
505507
int ret;
506508

507509
if (dmz_dev_is_dying(zmd))
@@ -527,9 +529,6 @@ static void dmz_reclaim_work(struct work_struct *work)
527529
zrc->kc_throttle.throttle = min(75U, 100U - p_unmap / 2);
528530
}
529531

530-
nr_unmap_rnd = dmz_nr_unmap_rnd_zones(zmd, zrc->dev_idx);
531-
nr_rnd = dmz_nr_rnd_zones(zmd, zrc->dev_idx);
532-
533532
DMDEBUG("(%s/%u): Reclaim (%u): %s, %u%% free zones (%u/%u cache %u/%u random)",
534533
dmz_metadata_label(zmd), zrc->dev_idx,
535534
zrc->kc_throttle.throttle,

drivers/md/dm-zoned-target.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,7 @@ static void dmz_handle_bio(struct dmz_target *dmz, struct dm_chunk_work *cw,
400400
dm_per_bio_data(bio, sizeof(struct dmz_bioctx));
401401
struct dmz_metadata *zmd = dmz->metadata;
402402
struct dm_zone *zone;
403-
int i, ret;
404-
405-
/*
406-
* Write may trigger a zone allocation. So make sure the
407-
* allocation can succeed.
408-
*/
409-
if (bio_op(bio) == REQ_OP_WRITE)
410-
for (i = 0; i < dmz->nr_ddevs; i++)
411-
dmz_schedule_reclaim(dmz->dev[i].reclaim);
403+
int ret;
412404

413405
dmz_lock_metadata(zmd);
414406

drivers/md/dm.c

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/init.h>
1313
#include <linux/module.h>
1414
#include <linux/mutex.h>
15+
#include <linux/sched/mm.h>
1516
#include <linux/sched/signal.h>
1617
#include <linux/blkpg.h>
1718
#include <linux/bio.h>
@@ -654,28 +655,6 @@ static void free_tio(struct dm_target_io *tio)
654655
bio_put(&tio->clone);
655656
}
656657

657-
static bool md_in_flight_bios(struct mapped_device *md)
658-
{
659-
int cpu;
660-
struct hd_struct *part = &dm_disk(md)->part0;
661-
long sum = 0;
662-
663-
for_each_possible_cpu(cpu) {
664-
sum += part_stat_local_read_cpu(part, in_flight[0], cpu);
665-
sum += part_stat_local_read_cpu(part, in_flight[1], cpu);
666-
}
667-
668-
return sum != 0;
669-
}
670-
671-
static bool md_in_flight(struct mapped_device *md)
672-
{
673-
if (queue_is_mq(md->queue))
674-
return blk_mq_queue_inflight(md->queue);
675-
else
676-
return md_in_flight_bios(md);
677-
}
678-
679658
u64 dm_start_time_ns_from_clone(struct bio *bio)
680659
{
681660
struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
@@ -1465,9 +1444,6 @@ static int __send_empty_flush(struct clone_info *ci)
14651444
BUG_ON(bio_has_data(ci->bio));
14661445
while ((ti = dm_table_get_target(ci->map, target_nr++)))
14671446
__send_duplicate_bios(ci, ti, ti->num_flush_bios, NULL);
1468-
1469-
bio_disassociate_blkg(ci->bio);
1470-
14711447
return 0;
14721448
}
14731449

@@ -1655,6 +1631,7 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md,
16551631
ci.bio = &flush_bio;
16561632
ci.sector_count = 0;
16571633
error = __send_empty_flush(&ci);
1634+
bio_uninit(ci.bio);
16581635
/* dec_pending submits any data associated with flush */
16591636
} else if (op_is_zone_mgmt(bio_op(bio))) {
16601637
ci.bio = bio;
@@ -1729,6 +1706,7 @@ static blk_qc_t __process_bio(struct mapped_device *md, struct dm_table *map,
17291706
ci.bio = &flush_bio;
17301707
ci.sector_count = 0;
17311708
error = __send_empty_flush(&ci);
1709+
bio_uninit(ci.bio);
17321710
/* dec_pending submits any data associated with flush */
17331711
} else {
17341712
struct dm_target_io *tio;
@@ -2470,15 +2448,29 @@ void dm_put(struct mapped_device *md)
24702448
}
24712449
EXPORT_SYMBOL_GPL(dm_put);
24722450

2473-
static int dm_wait_for_completion(struct mapped_device *md, long task_state)
2451+
static bool md_in_flight_bios(struct mapped_device *md)
2452+
{
2453+
int cpu;
2454+
struct hd_struct *part = &dm_disk(md)->part0;
2455+
long sum = 0;
2456+
2457+
for_each_possible_cpu(cpu) {
2458+
sum += part_stat_local_read_cpu(part, in_flight[0], cpu);
2459+
sum += part_stat_local_read_cpu(part, in_flight[1], cpu);
2460+
}
2461+
2462+
return sum != 0;
2463+
}
2464+
2465+
static int dm_wait_for_bios_completion(struct mapped_device *md, long task_state)
24742466
{
24752467
int r = 0;
24762468
DEFINE_WAIT(wait);
24772469

2478-
while (1) {
2470+
while (true) {
24792471
prepare_to_wait(&md->wait, &wait, task_state);
24802472

2481-
if (!md_in_flight(md))
2473+
if (!md_in_flight_bios(md))
24822474
break;
24832475

24842476
if (signal_pending_state(task_state, current)) {
@@ -2493,6 +2485,28 @@ static int dm_wait_for_completion(struct mapped_device *md, long task_state)
24932485
return r;
24942486
}
24952487

2488+
static int dm_wait_for_completion(struct mapped_device *md, long task_state)
2489+
{
2490+
int r = 0;
2491+
2492+
if (!queue_is_mq(md->queue))
2493+
return dm_wait_for_bios_completion(md, task_state);
2494+
2495+
while (true) {
2496+
if (!blk_mq_queue_inflight(md->queue))
2497+
break;
2498+
2499+
if (signal_pending_state(task_state, current)) {
2500+
r = -EINTR;
2501+
break;
2502+
}
2503+
2504+
msleep(5);
2505+
}
2506+
2507+
return r;
2508+
}
2509+
24962510
/*
24972511
* Process the deferred bios
24982512
*/
@@ -2926,17 +2940,25 @@ EXPORT_SYMBOL_GPL(dm_internal_resume_fast);
29262940
int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
29272941
unsigned cookie)
29282942
{
2943+
int r;
2944+
unsigned noio_flag;
29292945
char udev_cookie[DM_COOKIE_LENGTH];
29302946
char *envp[] = { udev_cookie, NULL };
29312947

2948+
noio_flag = memalloc_noio_save();
2949+
29322950
if (!cookie)
2933-
return kobject_uevent(&disk_to_dev(md->disk)->kobj, action);
2951+
r = kobject_uevent(&disk_to_dev(md->disk)->kobj, action);
29342952
else {
29352953
snprintf(udev_cookie, DM_COOKIE_LENGTH, "%s=%u",
29362954
DM_COOKIE_ENV_VAR_NAME, cookie);
2937-
return kobject_uevent_env(&disk_to_dev(md->disk)->kobj,
2938-
action, envp);
2955+
r = kobject_uevent_env(&disk_to_dev(md->disk)->kobj,
2956+
action, envp);
29392957
}
2958+
2959+
memalloc_noio_restore(noio_flag);
2960+
2961+
return r;
29402962
}
29412963

29422964
uint32_t dm_next_uevent_seq(struct mapped_device *md)

0 commit comments

Comments
 (0)