lkml.org 
[lkml]   [2021]   [Jul]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.13 261/800] block: fix discard request merge
    Date
    From: Ming Lei <ming.lei@redhat.com>

    [ Upstream commit 2705dfb2094777e405e065105e307074af8965c1 ]

    ll_new_hw_segment() is reached only in case of single range discard
    merge, and we don't have max discard segment size limit actually, so
    it is wrong to run the following check:

    if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req))

    it may be always false since req->nr_phys_segments is initialized as
    one, and bio's segment count is still 1, blk_rq_get_max_segments(reg)
    is 1 too.

    Fix the issue by not doing the check and bypassing the calculation of
    discard request's nr_phys_segments.

    Based on analysis from Wang Shanker.

    Cc: Christoph Hellwig <hch@lst.de>
    Reported-by: Wang Shanker <shankerwangmiao@gmail.com>
    Signed-off-by: Ming Lei <ming.lei@redhat.com>
    Link: https://lore.kernel.org/r/20210628023312.1903255-1-ming.lei@redhat.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    block/blk-merge.c | 8 ++++++--
    1 file changed, 6 insertions(+), 2 deletions(-)

    diff --git a/block/blk-merge.c b/block/blk-merge.c
    index 4d97fb6dd226..bcdff1879c34 100644
    --- a/block/blk-merge.c
    +++ b/block/blk-merge.c
    @@ -559,10 +559,14 @@ static inline unsigned int blk_rq_get_max_segments(struct request *rq)
    static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
    unsigned int nr_phys_segs)
    {
    - if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req))
    + if (blk_integrity_merge_bio(req->q, req, bio) == false)
    goto no_merge;

    - if (blk_integrity_merge_bio(req->q, req, bio) == false)
    + /* discard request merge won't add new segment */
    + if (req_op(req) == REQ_OP_DISCARD)
    + return 1;
    +
    + if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req))
    goto no_merge;

    /*
    --
    2.30.2


    \
     
     \ /
      Last update: 2021-07-12 10:41    [W:2.243 / U:0.024 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site