Commit 274295c6 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for-5.19/dm-fixes-3' of...

Merge tag 'for-5.19/dm-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm

Pull device mapper fixes from Mike Snitzer:

 - Fix a race in DM core's dm_start_io_acct that could result in double
   accounting for abnormal IO (e.g. discards, write zeroes, etc).

 - Fix a use-after-free in DM core's dm_put_live_table_bio.

 - Fix a race for REQ_NOWAIT bios being issued despite no support from
   underlying DM targets (due to DM table reload at an "unlucky" time)

 - Fix access beyond allocated bitmap in DM mirror's log.

* tag 'for-5.19/dm-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm:
  dm mirror log: round up region bitmap size to BITS_PER_LONG
  dm: fix narrow race for REQ_NOWAIT bios being issued despite no support
  dm: fix use-after-free in dm_put_live_table_bio
  dm: fix race in dm_start_io_acct
parents a96e902b 85e123c2
...@@ -415,8 +415,7 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti, ...@@ -415,8 +415,7 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
/* /*
* Work out how many "unsigned long"s we need to hold the bitset. * Work out how many "unsigned long"s we need to hold the bitset.
*/ */
bitset_size = dm_round_up(region_count, bitset_size = dm_round_up(region_count, BITS_PER_LONG);
sizeof(*lc->clean_bits) << BYTE_SHIFT);
bitset_size >>= BYTE_SHIFT; bitset_size >>= BYTE_SHIFT;
lc->bitset_uint32_count = bitset_size / sizeof(*lc->clean_bits); lc->bitset_uint32_count = bitset_size / sizeof(*lc->clean_bits);
......
...@@ -555,6 +555,10 @@ static void dm_start_io_acct(struct dm_io *io, struct bio *clone) ...@@ -555,6 +555,10 @@ static void dm_start_io_acct(struct dm_io *io, struct bio *clone)
unsigned long flags; unsigned long flags;
/* Can afford locking given DM_TIO_IS_DUPLICATE_BIO */ /* Can afford locking given DM_TIO_IS_DUPLICATE_BIO */
spin_lock_irqsave(&io->lock, flags); spin_lock_irqsave(&io->lock, flags);
if (dm_io_flagged(io, DM_IO_ACCOUNTED)) {
spin_unlock_irqrestore(&io->lock, flags);
return;
}
dm_io_set_flag(io, DM_IO_ACCOUNTED); dm_io_set_flag(io, DM_IO_ACCOUNTED);
spin_unlock_irqrestore(&io->lock, flags); spin_unlock_irqrestore(&io->lock, flags);
} }
...@@ -711,18 +715,18 @@ static void dm_put_live_table_fast(struct mapped_device *md) __releases(RCU) ...@@ -711,18 +715,18 @@ static void dm_put_live_table_fast(struct mapped_device *md) __releases(RCU)
} }
static inline struct dm_table *dm_get_live_table_bio(struct mapped_device *md, static inline struct dm_table *dm_get_live_table_bio(struct mapped_device *md,
int *srcu_idx, struct bio *bio) int *srcu_idx, unsigned bio_opf)
{ {
if (bio->bi_opf & REQ_NOWAIT) if (bio_opf & REQ_NOWAIT)
return dm_get_live_table_fast(md); return dm_get_live_table_fast(md);
else else
return dm_get_live_table(md, srcu_idx); return dm_get_live_table(md, srcu_idx);
} }
static inline void dm_put_live_table_bio(struct mapped_device *md, int srcu_idx, static inline void dm_put_live_table_bio(struct mapped_device *md, int srcu_idx,
struct bio *bio) unsigned bio_opf)
{ {
if (bio->bi_opf & REQ_NOWAIT) if (bio_opf & REQ_NOWAIT)
dm_put_live_table_fast(md); dm_put_live_table_fast(md);
else else
dm_put_live_table(md, srcu_idx); dm_put_live_table(md, srcu_idx);
...@@ -1609,7 +1613,12 @@ static blk_status_t __split_and_process_bio(struct clone_info *ci) ...@@ -1609,7 +1613,12 @@ static blk_status_t __split_and_process_bio(struct clone_info *ci)
ti = dm_table_find_target(ci->map, ci->sector); ti = dm_table_find_target(ci->map, ci->sector);
if (unlikely(!ti)) if (unlikely(!ti))
return BLK_STS_IOERR; return BLK_STS_IOERR;
else if (unlikely(ci->is_abnormal_io))
if (unlikely((ci->bio->bi_opf & REQ_NOWAIT) != 0) &&
unlikely(!dm_target_supports_nowait(ti->type)))
return BLK_STS_NOTSUPP;
if (unlikely(ci->is_abnormal_io))
return __process_abnormal_io(ci, ti); return __process_abnormal_io(ci, ti);
/* /*
...@@ -1711,8 +1720,9 @@ static void dm_submit_bio(struct bio *bio) ...@@ -1711,8 +1720,9 @@ static void dm_submit_bio(struct bio *bio)
struct mapped_device *md = bio->bi_bdev->bd_disk->private_data; struct mapped_device *md = bio->bi_bdev->bd_disk->private_data;
int srcu_idx; int srcu_idx;
struct dm_table *map; struct dm_table *map;
unsigned bio_opf = bio->bi_opf;
map = dm_get_live_table_bio(md, &srcu_idx, bio); map = dm_get_live_table_bio(md, &srcu_idx, bio_opf);
/* If suspended, or map not yet available, queue this IO for later */ /* If suspended, or map not yet available, queue this IO for later */
if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) || if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) ||
...@@ -1728,7 +1738,7 @@ static void dm_submit_bio(struct bio *bio) ...@@ -1728,7 +1738,7 @@ static void dm_submit_bio(struct bio *bio)
dm_split_and_process_bio(md, map, bio); dm_split_and_process_bio(md, map, bio);
out: out:
dm_put_live_table_bio(md, srcu_idx, bio); dm_put_live_table_bio(md, srcu_idx, bio_opf);
} }
static bool dm_poll_dm_io(struct dm_io *io, struct io_comp_batch *iob, static bool dm_poll_dm_io(struct dm_io *io, struct io_comp_batch *iob,
......
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