Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dm.c: Fix coercion bug in dm_merge_bvec()
dm_merge_bvec was originally added in f6fccb.  In this patch a value
in sectors is converted to bytes via a << 9, and then assigned to an
int.  This code made assumptions about the value of BIO_MAX_SECTORS.

A later patch, 148e51, removed the use of BIO_MAX_SECTORS.  At this
point the coercion resulted in a zero value.  The upshot being
dm_merge_bvec would only allow a single page to be added to a bio.

This patch is an interim patch.  The full solution needs to change
the max_size parameter in the dm_target merge methods to take a
sector_t (containing sectors, not bytes).
  • Loading branch information
jthornber committed May 29, 2015
1 parent a9f0959 commit 56db3d2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions drivers/md/dm.c
Expand Up @@ -1664,8 +1664,7 @@ static int dm_merge_bvec(struct request_queue *q,
struct mapped_device *md = q->queuedata;
struct dm_table *map = dm_get_live_table_fast(md);
struct dm_target *ti;
sector_t max_sectors;
int max_size = 0;
sector_t max_sectors, max_size = 0;

if (unlikely(!map))
goto out;
Expand All @@ -1680,16 +1679,22 @@ static int dm_merge_bvec(struct request_queue *q,
max_sectors = min(max_io_len(bvm->bi_sector, ti),
(sector_t) queue_max_sectors(q));
max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size;
if (unlikely(max_size < 0)) /* this shouldn't _ever_ happen */
max_size = 0;

/*
* FIXME: This is horrible. We should really be passing a sector_t
* to the target merge functions (holding sectors not bytes). Just
* doing this as an interim fix.
*/
if (max_size > INT_MAX)
max_size = INT_MAX;

/*
* merge_bvec_fn() returns number of bytes
* it can accept at this offset
* max is precomputed maximal io size
*/
if (max_size && ti->type->merge)
max_size = ti->type->merge(ti, bvm, biovec, max_size);
max_size = ti->type->merge(ti, bvm, biovec, (int) max_size);
/*
* If the target doesn't support merge method and some of the devices
* provided their merge_bvec method (we know this by looking for the
Expand Down

0 comments on commit 56db3d2

Please sign in to comment.