Skip to content

Commit fe35fdb

Browse files
committed
Merge tag 'for-5.18/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mike Snitzer: - Fix DM integrity shrink crash due to journal entry not being marked unused. - Fix DM bio polling to handle possibility that underlying device(s) return BLK_STS_AGAIN during submission. - Fix dm_io and dm_target_io flags race condition on Alpha. - Add some pr_err debugging to help debug cases when DM ioctl structure is corrupted. * tag 'for-5.18/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm: fix bio polling to handle possibile BLK_STS_AGAIN dm: fix dm_io and dm_target_io flags race condition on Alpha dm integrity: set journal entry unused when shrinking device dm ioctl: log an error if the ioctl structure is corrupted
2 parents 7a3ecdd + 5291984 commit fe35fdb

5 files changed

Lines changed: 33 additions & 14 deletions

File tree

drivers/md/dm-core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ struct dm_table {
210210
#define DM_TIO_MAGIC 28714
211211
struct dm_target_io {
212212
unsigned short magic;
213-
unsigned short flags;
213+
blk_short_t flags;
214214
unsigned int target_bio_nr;
215215
struct dm_io *io;
216216
struct dm_target *ti;
@@ -244,7 +244,7 @@ static inline void dm_tio_set_flag(struct dm_target_io *tio, unsigned int bit)
244244
#define DM_IO_MAGIC 19577
245245
struct dm_io {
246246
unsigned short magic;
247-
unsigned short flags;
247+
blk_short_t flags;
248248
atomic_t io_count;
249249
struct mapped_device *md;
250250
struct bio *orig_bio;

drivers/md/dm-integrity.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,9 +2472,11 @@ static void do_journal_write(struct dm_integrity_c *ic, unsigned write_start,
24722472
dm_integrity_io_error(ic, "invalid sector in journal", -EIO);
24732473
sec &= ~(sector_t)(ic->sectors_per_block - 1);
24742474
}
2475+
if (unlikely(sec >= ic->provided_data_sectors)) {
2476+
journal_entry_set_unused(je);
2477+
continue;
2478+
}
24752479
}
2476-
if (unlikely(sec >= ic->provided_data_sectors))
2477-
continue;
24782480
get_area_and_offset(ic, sec, &area, &offset);
24792481
restore_last_bytes(ic, access_journal_data(ic, i, j), je);
24802482
for (k = j + 1; k < ic->journal_section_entries; k++) {

drivers/md/dm-ioctl.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,15 +891,21 @@ static struct hash_cell *__find_device_hash_cell(struct dm_ioctl *param)
891891
struct hash_cell *hc = NULL;
892892

893893
if (*param->uuid) {
894-
if (*param->name || param->dev)
894+
if (*param->name || param->dev) {
895+
DMERR("Invalid ioctl structure: uuid %s, name %s, dev %llx",
896+
param->uuid, param->name, (unsigned long long)param->dev);
895897
return NULL;
898+
}
896899

897900
hc = __get_uuid_cell(param->uuid);
898901
if (!hc)
899902
return NULL;
900903
} else if (*param->name) {
901-
if (param->dev)
904+
if (param->dev) {
905+
DMERR("Invalid ioctl structure: name %s, dev %llx",
906+
param->name, (unsigned long long)param->dev);
902907
return NULL;
908+
}
903909

904910
hc = __get_name_cell(param->name);
905911
if (!hc)
@@ -1851,8 +1857,11 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl *param_kern
18511857
if (copy_from_user(param_kernel, user, minimum_data_size))
18521858
return -EFAULT;
18531859

1854-
if (param_kernel->data_size < minimum_data_size)
1860+
if (param_kernel->data_size < minimum_data_size) {
1861+
DMERR("Invalid data size in the ioctl structure: %u",
1862+
param_kernel->data_size);
18551863
return -EINVAL;
1864+
}
18561865

18571866
secure_data = param_kernel->flags & DM_SECURE_DATA_FLAG;
18581867

drivers/md/dm.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -892,13 +892,19 @@ static void dm_io_complete(struct dm_io *io)
892892
if (unlikely(wq_has_sleeper(&md->wait)))
893893
wake_up(&md->wait);
894894

895-
if (io_error == BLK_STS_DM_REQUEUE) {
896-
/*
897-
* Upper layer won't help us poll split bio, io->orig_bio
898-
* may only reflect a subset of the pre-split original,
899-
* so clear REQ_POLLED in case of requeue
900-
*/
901-
bio->bi_opf &= ~REQ_POLLED;
895+
if (io_error == BLK_STS_DM_REQUEUE || io_error == BLK_STS_AGAIN) {
896+
if (bio->bi_opf & REQ_POLLED) {
897+
/*
898+
* Upper layer won't help us poll split bio (io->orig_bio
899+
* may only reflect a subset of the pre-split original)
900+
* so clear REQ_POLLED in case of requeue.
901+
*/
902+
bio->bi_opf &= ~REQ_POLLED;
903+
if (io_error == BLK_STS_AGAIN) {
904+
/* io_uring doesn't handle BLK_STS_AGAIN (yet) */
905+
queue_io(md, bio);
906+
}
907+
}
902908
return;
903909
}
904910

include/linux/blk_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ struct block_device {
8585
*/
8686
#if defined(CONFIG_ALPHA) && !defined(__alpha_bwx__)
8787
typedef u32 __bitwise blk_status_t;
88+
typedef u32 blk_short_t;
8889
#else
8990
typedef u8 __bitwise blk_status_t;
91+
typedef u16 blk_short_t;
9092
#endif
9193
#define BLK_STS_OK 0
9294
#define BLK_STS_NOTSUPP ((__force blk_status_t)1)

0 commit comments

Comments
 (0)