Skip to content

Commit c75981a

Browse files
committed
Merge tag 'for-6.5/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mike Snitzer: - Fix double free on memory allocation failure in DM integrity target's integrity_recalc() - Fix locking in DM raid target's raid_ctr() and around call to md_stop() - Fix DM cache target's cleaner policy to always allow work to be queued for writeback; even if cache isn't idle. * tag 'for-6.5/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm cache policy smq: ensure IO doesn't prevent cleaner policy progress dm raid: protect md_stop() with 'reconfig_mutex' dm raid: clean up four equivalent goto tags in raid_ctr() dm raid: fix missing reconfig_mutex unlock in raid_ctr() error paths dm integrity: fix double free on memory allocation failure
2 parents 6fb9f7f + 1e4ab7b commit c75981a

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

drivers/md/dm-cache-policy-smq.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,13 @@ struct smq_policy {
857857

858858
struct background_tracker *bg_work;
859859

860-
bool migrations_allowed;
860+
bool migrations_allowed:1;
861+
862+
/*
863+
* If this is set the policy will try and clean the whole cache
864+
* even if the device is not idle.
865+
*/
866+
bool cleaner:1;
861867
};
862868

863869
/*----------------------------------------------------------------*/
@@ -1138,7 +1144,7 @@ static bool clean_target_met(struct smq_policy *mq, bool idle)
11381144
* Cache entries may not be populated. So we cannot rely on the
11391145
* size of the clean queue.
11401146
*/
1141-
if (idle) {
1147+
if (idle || mq->cleaner) {
11421148
/*
11431149
* We'd like to clean everything.
11441150
*/
@@ -1722,11 +1728,9 @@ static void calc_hotspot_params(sector_t origin_size,
17221728
*hotspot_block_size /= 2u;
17231729
}
17241730

1725-
static struct dm_cache_policy *__smq_create(dm_cblock_t cache_size,
1726-
sector_t origin_size,
1727-
sector_t cache_block_size,
1728-
bool mimic_mq,
1729-
bool migrations_allowed)
1731+
static struct dm_cache_policy *
1732+
__smq_create(dm_cblock_t cache_size, sector_t origin_size, sector_t cache_block_size,
1733+
bool mimic_mq, bool migrations_allowed, bool cleaner)
17301734
{
17311735
unsigned int i;
17321736
unsigned int nr_sentinels_per_queue = 2u * NR_CACHE_LEVELS;
@@ -1813,6 +1817,7 @@ static struct dm_cache_policy *__smq_create(dm_cblock_t cache_size,
18131817
goto bad_btracker;
18141818

18151819
mq->migrations_allowed = migrations_allowed;
1820+
mq->cleaner = cleaner;
18161821

18171822
return &mq->policy;
18181823

@@ -1836,21 +1841,24 @@ static struct dm_cache_policy *smq_create(dm_cblock_t cache_size,
18361841
sector_t origin_size,
18371842
sector_t cache_block_size)
18381843
{
1839-
return __smq_create(cache_size, origin_size, cache_block_size, false, true);
1844+
return __smq_create(cache_size, origin_size, cache_block_size,
1845+
false, true, false);
18401846
}
18411847

18421848
static struct dm_cache_policy *mq_create(dm_cblock_t cache_size,
18431849
sector_t origin_size,
18441850
sector_t cache_block_size)
18451851
{
1846-
return __smq_create(cache_size, origin_size, cache_block_size, true, true);
1852+
return __smq_create(cache_size, origin_size, cache_block_size,
1853+
true, true, false);
18471854
}
18481855

18491856
static struct dm_cache_policy *cleaner_create(dm_cblock_t cache_size,
18501857
sector_t origin_size,
18511858
sector_t cache_block_size)
18521859
{
1853-
return __smq_create(cache_size, origin_size, cache_block_size, false, false);
1860+
return __smq_create(cache_size, origin_size, cache_block_size,
1861+
false, false, true);
18541862
}
18551863

18561864
/*----------------------------------------------------------------*/

drivers/md/dm-integrity.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,6 +2676,7 @@ static void integrity_recalc(struct work_struct *w)
26762676
recalc_tags = kvmalloc(recalc_tags_size, GFP_NOIO);
26772677
if (!recalc_tags) {
26782678
vfree(recalc_buffer);
2679+
recalc_buffer = NULL;
26792680
goto oom;
26802681
}
26812682

drivers/md/dm-raid.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,17 +3251,15 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
32513251
r = md_start(&rs->md);
32523252
if (r) {
32533253
ti->error = "Failed to start raid array";
3254-
mddev_unlock(&rs->md);
3255-
goto bad_md_start;
3254+
goto bad_unlock;
32563255
}
32573256

32583257
/* If raid4/5/6 journal mode explicitly requested (only possible with journal dev) -> set it */
32593258
if (test_bit(__CTR_FLAG_JOURNAL_MODE, &rs->ctr_flags)) {
32603259
r = r5c_journal_mode_set(&rs->md, rs->journal_dev.mode);
32613260
if (r) {
32623261
ti->error = "Failed to set raid4/5/6 journal mode";
3263-
mddev_unlock(&rs->md);
3264-
goto bad_journal_mode_set;
3262+
goto bad_unlock;
32653263
}
32663264
}
32673265

@@ -3272,14 +3270,14 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
32723270
if (rs_is_raid456(rs)) {
32733271
r = rs_set_raid456_stripe_cache(rs);
32743272
if (r)
3275-
goto bad_stripe_cache;
3273+
goto bad_unlock;
32763274
}
32773275

32783276
/* Now do an early reshape check */
32793277
if (test_bit(RT_FLAG_RESHAPE_RS, &rs->runtime_flags)) {
32803278
r = rs_check_reshape(rs);
32813279
if (r)
3282-
goto bad_check_reshape;
3280+
goto bad_unlock;
32833281

32843282
/* Restore new, ctr requested layout to perform check */
32853283
rs_config_restore(rs, &rs_layout);
@@ -3288,7 +3286,7 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
32883286
r = rs->md.pers->check_reshape(&rs->md);
32893287
if (r) {
32903288
ti->error = "Reshape check failed";
3291-
goto bad_check_reshape;
3289+
goto bad_unlock;
32923290
}
32933291
}
32943292
}
@@ -3299,11 +3297,9 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
32993297
mddev_unlock(&rs->md);
33003298
return 0;
33013299

3302-
bad_md_start:
3303-
bad_journal_mode_set:
3304-
bad_stripe_cache:
3305-
bad_check_reshape:
3300+
bad_unlock:
33063301
md_stop(&rs->md);
3302+
mddev_unlock(&rs->md);
33073303
bad:
33083304
raid_set_free(rs);
33093305

@@ -3314,7 +3310,9 @@ static void raid_dtr(struct dm_target *ti)
33143310
{
33153311
struct raid_set *rs = ti->private;
33163312

3313+
mddev_lock_nointr(&rs->md);
33173314
md_stop(&rs->md);
3315+
mddev_unlock(&rs->md);
33183316
raid_set_free(rs);
33193317
}
33203318

drivers/md/md.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6247,6 +6247,8 @@ static void __md_stop(struct mddev *mddev)
62476247

62486248
void md_stop(struct mddev *mddev)
62496249
{
6250+
lockdep_assert_held(&mddev->reconfig_mutex);
6251+
62506252
/* stop the array and free an attached data structures.
62516253
* This is called from dm-raid
62526254
*/

0 commit comments

Comments
 (0)