From patchwork Fri Jan 22 18:29:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8092291 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 88EDE9F744 for ; Fri, 22 Jan 2016 18:30:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A6E39205B1 for ; Fri, 22 Jan 2016 18:30:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A39C72058E for ; Fri, 22 Jan 2016 18:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754889AbcAVSap (ORCPT ); Fri, 22 Jan 2016 13:30:45 -0500 Received: from mail-pa0-f43.google.com ([209.85.220.43]:35604 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754879AbcAVSao (ORCPT ); Fri, 22 Jan 2016 13:30:44 -0500 Received: by mail-pa0-f43.google.com with SMTP id ho8so45419324pac.2; Fri, 22 Jan 2016 10:30:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=rWn0RFI4H+fTNZgwe4d78R7zlFghSiko69BK/6Qv4PY=; b=RKRibd5FFLMTcjVoNhWabgdHSH2oZImY8EEGEmsXVCNKOLcQw5TzbvacS4m9w5Clo4 5RXJ6WdyiD1plx4NNxrnuX9SrzlC+rkLOLNAkq3KhfdGrhc2aMyWGNJOUrmzTMq1VO/z atMPcVNrwk3qRfPPcvSrcS7q5ttaojRu8tiOdg35N+H79Ee5UGDOwWkkkbUrnDi4l+XV gEJF6bQ8e0Mp4vjTX0Mt41P1lS7JGnxEXVpvY/GqaykrnHcJDV8paeuVT/8MtFps7Aa0 H0zZHcrSRwhyJnHmT3o501qYY2GK/3Ry9RtNCsS6pz8h104TrxS6BkgZJkBoD7kKlipx r8Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rWn0RFI4H+fTNZgwe4d78R7zlFghSiko69BK/6Qv4PY=; b=CYLoD14Ja02egJKQV/8/ktPoFvWyNtVAAD+ltzVgcRvxbneSX2CfzycddDZz8F3+0G 50uwb9k6Y76fgv2HgjIvr2d0BEDXAr5hcccuCJmHTqg0EOoGa6pFlVxmHGZJubudGsJL tZpa7JFok04uXWFtl5SGQczxXOjfPr2yaIfAUiyLxuBqOgMZfV63Q06W2ovNSlClPM8s dfSfXhVN9tLEzxnQUi4AVQgI/RQMIuCu/WtrLYIqJQPWMib99ICl0HliHe9+fE9QIgTQ J7RdU8cL7hFf8ynzFxcVD8Ahwi0LpogqIqjEqXSQoaDPAQfH0QGc4G68dbanfcp1C2S3 IpjQ== X-Gm-Message-State: AG10YOTDi0wTC7ymh0xKNc+xeEsagg/0AWE8oN/63GL3hsuQ8a5O6TJW8LH4OhDaJF1usw== X-Received: by 10.66.55.39 with SMTP id o7mr6421527pap.13.1453487443782; Fri, 22 Jan 2016 10:30:43 -0800 (PST) Received: from localhost ([116.251.217.174]) by smtp.gmail.com with ESMTPSA id m75sm11291317pfj.38.2016.01.22.10.30.42 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 22 Jan 2016 10:30:43 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Linus Torvalds , Stefan Haberland , Keith Busch , Ming Lei Subject: [PATCH] block: fix bio splitting on max sectors Date: Sat, 23 Jan 2016 02:29:32 +0800 Message-Id: <1453487372-8391-1-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After commit e36f62042880(block: split bios to maxpossible length), bio can be splitted in the middle of a vector entry, then it is easy to split out one bio which size isn't aligned with block size, especially when the block size is bigger than 512. This patch fixes the issue by making the max io size aligned to logical block size. Fixes: e36f62042880(block: split bios to maxpossible length) Reported-by: Stefan Haberland Cc: Keith Busch Suggested-by: Linus Torvalds Signed-off-by: Ming Lei --- block/blk-merge.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 1699df5..ad22153 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -70,6 +70,18 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q, return bio_split(bio, q->limits.max_write_same_sectors, GFP_NOIO, bs); } +static inline unsigned get_max_io_size(struct request_queue *q, + struct bio *bio) +{ + unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector); + unsigned mask = ~(queue_logical_block_size(q) - 1); + + /* aligned to logical block size */ + sectors = ((sectors << 9) & mask) >> 9; + + return sectors; +} + static struct bio *blk_bio_segment_split(struct request_queue *q, struct bio *bio, struct bio_set *bs, @@ -81,6 +93,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, unsigned front_seg_size = bio->bi_seg_front_size; bool do_split = true; struct bio *new = NULL; + unsigned max_sectors; bio_for_each_segment(bv, bio, iter) { /* @@ -90,20 +103,20 @@ static struct bio *blk_bio_segment_split(struct request_queue *q, if (bvprvp && bvec_gap_to_prev(q, bvprvp, bv.bv_offset)) goto split; - if (sectors + (bv.bv_len >> 9) > - blk_max_size_offset(q, bio->bi_iter.bi_sector)) { + max_sectors = get_max_io_size(q, bio); + if (sectors + (bv.bv_len >> 9) > max_sectors) { /* * Consider this a new segment if we're splitting in * the middle of this vector. */ if (nsegs < queue_max_segments(q) && - sectors < blk_max_size_offset(q, - bio->bi_iter.bi_sector)) { + sectors < max_sectors) { nsegs++; - sectors = blk_max_size_offset(q, - bio->bi_iter.bi_sector); + sectors = max_sectors; } - goto split; + if (sectors) + goto split; + /* Make this single bvec as the 1st segment */ } if (bvprvp && blk_queue_cluster(q)) {