* [PATCH] block: don't deal with discard limit in blkdev_issue_discard()
@ 2018-10-12 7:53 Ming Lei
2018-10-17 7:06 ` Dabrowski, Mariusz
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ming Lei @ 2018-10-12 7:53 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, Ming Lei, stable, Mariusz Dabrowski, Ming Lin,
Mike Snitzer, Christoph Hellwig, Xiao Ni
blk_queue_split() does respect this limit via bio splitting, so no
need to do that in blkdev_issue_discard(), then we can align to
normal bio submit(bio_add_page() & submit_bio()).
More importantly, this patch fixes one issue introduced in a22c4d7e34402cc
("block: re-add discard_granularity and alignment checks"), in which
zero discard bio may be generated in case of zero alignment.
Fixes: a22c4d7e34402ccdf3 ("block: re-add discard_granularity and alignment checks")
Cc: stable@vger.kernel.org
Cc: Mariusz Dabrowski <mariusz.dabrowski@intel.com>
Cc: Ming Lin <ming.l@ssi.samsung.com>
Cc: Mike Snitzer <snitzer@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Xiao Ni <xni@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/blk-lib.c | 28 ++--------------------------
1 file changed, 2 insertions(+), 26 deletions(-)
diff --git a/block/blk-lib.c b/block/blk-lib.c
index d1b9dd03da25..bbd44666f2b5 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -29,9 +29,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
{
struct request_queue *q = bdev_get_queue(bdev);
struct bio *bio = *biop;
- unsigned int granularity;
unsigned int op;
- int alignment;
sector_t bs_mask;
if (!q)
@@ -54,38 +52,16 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
if ((sector | nr_sects) & bs_mask)
return -EINVAL;
- /* Zero-sector (unknown) and one-sector granularities are the same. */
- granularity = max(q->limits.discard_granularity >> 9, 1U);
- alignment = (bdev_discard_alignment(bdev) >> 9) % granularity;
-
while (nr_sects) {
- unsigned int req_sects;
- sector_t end_sect, tmp;
+ unsigned int req_sects = nr_sects;
+ sector_t end_sect;
- /*
- * Issue in chunks of the user defined max discard setting,
- * ensuring that bi_size doesn't overflow
- */
- req_sects = min_t(sector_t, nr_sects,
- q->limits.max_discard_sectors);
if (!req_sects)
goto fail;
if (req_sects > UINT_MAX >> 9)
req_sects = UINT_MAX >> 9;
- /*
- * If splitting a request, and the next starting sector would be
- * misaligned, stop the discard at the previous aligned sector.
- */
end_sect = sector + req_sects;
- tmp = end_sect;
- if (req_sects < nr_sects &&
- sector_div(tmp, granularity) != alignment) {
- end_sect = end_sect - alignment;
- sector_div(end_sect, granularity);
- end_sect = end_sect * granularity + alignment;
- req_sects = end_sect - sector;
- }
bio = next_bio(bio, 0, gfp_mask);
bio->bi_iter.bi_sector = sector;
--
2.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] block: don't deal with discard limit in blkdev_issue_discard()
2018-10-12 7:53 [PATCH] block: don't deal with discard limit in blkdev_issue_discard() Ming Lei
@ 2018-10-17 7:06 ` Dabrowski, Mariusz
2018-10-18 0:12 ` Ming Lei
2018-10-18 13:23 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Dabrowski, Mariusz @ 2018-10-17 7:06 UTC (permalink / raw)
To: Ming Lei, Jens Axboe
Cc: linux-block@vger.kernel.org, stable@vger.kernel.org, Ming Lin,
Mike Snitzer, Christoph Hellwig, Xiao Ni
On 10/12/18 9:53 AM, Ming Lei wrote:
> blk_queue_split() does respect this limit via bio splitting, so no
> need to do that in blkdev_issue_discard(), then we can align to
> normal bio submit(bio_add_page() & submit_bio()).
>
> More importantly, this patch fixes one issue introduced in a22c4d7e34402cc
> ("block: re-add discard_granularity and alignment checks"), in which
> zero discard bio may be generated in case of zero alignment.
>
> Fixes: a22c4d7e34402ccdf3 ("block: re-add discard_granularity and alignment checks")
> Cc: stable@vger.kernel.org
> Cc: Mariusz Dabrowski <mariusz.dabrowski@intel.com>
> Cc: Ming Lin <ming.l@ssi.samsung.com>
> Cc: Mike Snitzer <snitzer@redhat.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Xiao Ni <xni@redhat.com>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> block/blk-lib.c | 28 ++--------------------------
> 1 file changed, 2 insertions(+), 26 deletions(-)
>
> diff --git a/block/blk-lib.c b/block/blk-lib.c
> index d1b9dd03da25..bbd44666f2b5 100644
> --- a/block/blk-lib.c
> +++ b/block/blk-lib.c
> @@ -29,9 +29,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
> {
> struct request_queue *q = bdev_get_queue(bdev);
> struct bio *bio = *biop;
> - unsigned int granularity;
> unsigned int op;
> - int alignment;
> sector_t bs_mask;
>
> if (!q)
> @@ -54,38 +52,16 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
> if ((sector | nr_sects) & bs_mask)
> return -EINVAL;
>
> - /* Zero-sector (unknown) and one-sector granularities are the same. */
> - granularity = max(q->limits.discard_granularity >> 9, 1U);
> - alignment = (bdev_discard_alignment(bdev) >> 9) % granularity;
> -
> while (nr_sects) {
> - unsigned int req_sects;
> - sector_t end_sect, tmp;
> + unsigned int req_sects = nr_sects;
> + sector_t end_sect;
>
> - /*
> - * Issue in chunks of the user defined max discard setting,
> - * ensuring that bi_size doesn't overflow
> - */
> - req_sects = min_t(sector_t, nr_sects,
> - q->limits.max_discard_sectors);
> if (!req_sects)
> goto fail;
> if (req_sects > UINT_MAX >> 9)
> req_sects = UINT_MAX >> 9;
>
> - /*
> - * If splitting a request, and the next starting sector would be
> - * misaligned, stop the discard at the previous aligned sector.
> - */
> end_sect = sector + req_sects;
> - tmp = end_sect;
> - if (req_sects < nr_sects &&
> - sector_div(tmp, granularity) != alignment) {
> - end_sect = end_sect - alignment;
> - sector_div(end_sect, granularity);
> - end_sect = end_sect * granularity + alignment;
> - req_sects = end_sect - sector;
> - }
>
> bio = next_bio(bio, 0, gfp_mask);
> bio->bi_iter.bi_sector = sector;
>
Tested-by: Mariusz Dabrowski <mariusz.dabrowski@intel.com>
Regards,
Mariusz
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] block: don't deal with discard limit in blkdev_issue_discard()
2018-10-12 7:53 [PATCH] block: don't deal with discard limit in blkdev_issue_discard() Ming Lei
2018-10-17 7:06 ` Dabrowski, Mariusz
@ 2018-10-18 0:12 ` Ming Lei
2018-10-18 13:23 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Ming Lei @ 2018-10-18 0:12 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, stable, Mariusz Dabrowski, Ming Lin, Mike Snitzer,
Christoph Hellwig, Xiao Ni
On Fri, Oct 12, 2018 at 03:53:10PM +0800, Ming Lei wrote:
> blk_queue_split() does respect this limit via bio splitting, so no
> need to do that in blkdev_issue_discard(), then we can align to
> normal bio submit(bio_add_page() & submit_bio()).
>
> More importantly, this patch fixes one issue introduced in a22c4d7e34402cc
> ("block: re-add discard_granularity and alignment checks"), in which
> zero discard bio may be generated in case of zero alignment.
>
> Fixes: a22c4d7e34402ccdf3 ("block: re-add discard_granularity and alignment checks")
> Cc: stable@vger.kernel.org
> Cc: Mariusz Dabrowski <mariusz.dabrowski@intel.com>
> Cc: Ming Lin <ming.l@ssi.samsung.com>
> Cc: Mike Snitzer <snitzer@redhat.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Xiao Ni <xni@redhat.com>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> block/blk-lib.c | 28 ++--------------------------
> 1 file changed, 2 insertions(+), 26 deletions(-)
>
> diff --git a/block/blk-lib.c b/block/blk-lib.c
> index d1b9dd03da25..bbd44666f2b5 100644
> --- a/block/blk-lib.c
> +++ b/block/blk-lib.c
> @@ -29,9 +29,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
> {
> struct request_queue *q = bdev_get_queue(bdev);
> struct bio *bio = *biop;
> - unsigned int granularity;
> unsigned int op;
> - int alignment;
> sector_t bs_mask;
>
> if (!q)
> @@ -54,38 +52,16 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
> if ((sector | nr_sects) & bs_mask)
> return -EINVAL;
>
> - /* Zero-sector (unknown) and one-sector granularities are the same. */
> - granularity = max(q->limits.discard_granularity >> 9, 1U);
> - alignment = (bdev_discard_alignment(bdev) >> 9) % granularity;
> -
> while (nr_sects) {
> - unsigned int req_sects;
> - sector_t end_sect, tmp;
> + unsigned int req_sects = nr_sects;
> + sector_t end_sect;
>
> - /*
> - * Issue in chunks of the user defined max discard setting,
> - * ensuring that bi_size doesn't overflow
> - */
> - req_sects = min_t(sector_t, nr_sects,
> - q->limits.max_discard_sectors);
> if (!req_sects)
> goto fail;
> if (req_sects > UINT_MAX >> 9)
> req_sects = UINT_MAX >> 9;
>
> - /*
> - * If splitting a request, and the next starting sector would be
> - * misaligned, stop the discard at the previous aligned sector.
> - */
> end_sect = sector + req_sects;
> - tmp = end_sect;
> - if (req_sects < nr_sects &&
> - sector_div(tmp, granularity) != alignment) {
> - end_sect = end_sect - alignment;
> - sector_div(end_sect, granularity);
> - end_sect = end_sect * granularity + alignment;
> - req_sects = end_sect - sector;
> - }
>
> bio = next_bio(bio, 0, gfp_mask);
> bio->bi_iter.bi_sector = sector;
> --
> 2.9.5
>
Ping...
This patch fixes BUG() in blk_mq_end_request() when zero-length discard
bio is generated from __blkdev_issue_discard().
Thanks,
Ming
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] block: don't deal with discard limit in blkdev_issue_discard()
2018-10-12 7:53 [PATCH] block: don't deal with discard limit in blkdev_issue_discard() Ming Lei
2018-10-17 7:06 ` Dabrowski, Mariusz
2018-10-18 0:12 ` Ming Lei
@ 2018-10-18 13:23 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2018-10-18 13:23 UTC (permalink / raw)
To: Ming Lei
Cc: linux-block, stable, Mariusz Dabrowski, Ming Lin, Mike Snitzer,
Christoph Hellwig, Xiao Ni
On 10/12/18 1:53 AM, Ming Lei wrote:
> blk_queue_split() does respect this limit via bio splitting, so no
> need to do that in blkdev_issue_discard(), then we can align to
> normal bio submit(bio_add_page() & submit_bio()).
>
> More importantly, this patch fixes one issue introduced in a22c4d7e34402cc
> ("block: re-add discard_granularity and alignment checks"), in which
> zero discard bio may be generated in case of zero alignment.
Thanks Ming, applied.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-10-18 21:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-12 7:53 [PATCH] block: don't deal with discard limit in blkdev_issue_discard() Ming Lei
2018-10-17 7:06 ` Dabrowski, Mariusz
2018-10-18 0:12 ` Ming Lei
2018-10-18 13:23 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox