- Refactor DM core's mempool allocation so that it clearer by not
  being split acorss files.

- Improve DM core's BLK_STS_DM_REQUEUE and BLK_STS_AGAIN handling.

- Optimize DM core's more common bio splitting by eliminating the use
  of bio cloning with bio_split+bio_chain. Shift that cloning cost to
  the relatively unlikely dm_io requeue case that only occurs during
  error handling. Introduces dm_io_rewind() that will clone a bio that
  reflects the subset of the original bio that must be requeued.

- Remove DM core's dm_table_get_num_targets() wrapper and audit all
  dm_table_get_target() callers.

- Fix potential for OOM with DM writecache target by setting a default
  MAX_WRITEBACK_JOBS (set to 256MiB or 1/16 of total system memory,
  whichever is smaller).

- Fix DM writecache target's stats that are reported through
  DM-specific table info.

- Fix use-after-free crash in dm_sm_register_threshold_callback().

- Refine DM core's Persistent Reservation handling in preparation for
  broader work Mike Christie is doing to add compatibility with
  Microsoft Windows Failover Cluster.

- Fix various KASAN reported bugs in the DM raid target.

- Fix DM raid target crash due to md_handle_request() bio splitting
  that recurses to block core without properly initializing the bio's
  bi_dev.

- Fix some code comment typos and fix some Documentation formatting.
dm: fix dm-raid crash if md_handle_request() splits bio

Commit ca522482e3eaf ("dm: pass NULL bdev to bio_alloc_clone")
introduced the optimization to _not_ perform bio_associate_blkg()'s
relatively costly work when DM core clones its bio. But in doing so it
exposed the possibility for DM's cloned bio to alter DM target
behavior (e.g. crash) if a target were to issue IO without first
calling bio_set_dev().

The DM raid target can trigger an MD crash due to its need to split
the DM bio that is passed to md_handle_request(). The split will
recurse to submit_bio_noacct() using a bio with an uninitialized
->bi_blkg. This NULL bio->bi_blkg causes blk_throtl_bio() to
dereference a NULL blkg_to_tg(bio->bi_blkg).

Fix this in DM core by adding a new 'needs_bio_set_dev' target flag that
will make alloc_tio() call bio_set_dev() on behalf of the target.
dm-raid is the only target that requires this flag. bio_set_dev()
initializes the DM cloned bio's ->bi_blkg, using bio_associate_blkg,
before passing the bio to md_handle_request().

Long-term fix would be to audit and refactor MD code to rely on DM to
split its bio, using dm_accept_partial_bio(), but there are MD raid
personalities (e.g. raid1 and raid10) whose implementation are tightly
coupled to handling the bio splitting inline.

Fixes: ca522482e3eaf ("dm: pass NULL bdev to bio_alloc_clone")
Cc: stable@vger.kernel.org
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
4 files changed