From patchwork Thu Jul 28 10:19:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minfei Huang X-Patchwork-Id: 9251065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7FDBC6077C for ; Thu, 28 Jul 2016 10:19:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7118E26785 for ; Thu, 28 Jul 2016 10:19:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65BFF26D08; Thu, 28 Jul 2016 10:19:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADBA526785 for ; Thu, 28 Jul 2016 10:19:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755756AbcG1KTv (ORCPT ); Thu, 28 Jul 2016 06:19:51 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36525 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755015AbcG1KTu (ORCPT ); Thu, 28 Jul 2016 06:19:50 -0400 Received: by mail-pf0-f193.google.com with SMTP id y134so3469623pfg.3; Thu, 28 Jul 2016 03:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=duLYGN2VEKHa39xbRXEmJBuoDMKjW1R0mDHBBEnxgXo=; b=V3W6IoSz7h2FQKNXXB88ORUR6xeTXF8JbfU9HT1qJpg0Qe3szMWwSmMP+D/gi3/ofK kndPBuIoCfMtGqjFNSSQzCh7zLmLQRr3TxPiz1kEA5fXLNBGucvirF47L9d8m1BEYQmd nYdJSLhijsDmRPRiXSAjpD1JSm/+M6wnp5vzNdntoP/zoWUmjrHifcqHcPOjS1PygS09 WKgWA0NejdDTzl/ABplKMyKzZ61CgwukWUe7wjNk15CcVNcAVcT0Dv2D3GjjBjbxGn74 yqLA1jlppc5DH802vBsZSFbqfhRoAlfwwTdr4Sl+DC6gGRnqfCJyW0Y4/AMseLG/tGD/ OJDQ== 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=duLYGN2VEKHa39xbRXEmJBuoDMKjW1R0mDHBBEnxgXo=; b=LCWdGlCMiWlrNRJhINXWRWIZ+PGIFQeHb24sMd4B7yOlZF8sRnzCStFE5ozru/RxQ1 bWogXh010KVZtSeuaqv3b8efEDxf3YMkAy2VKk5CVkboVVlQVMAK2UQyh7wzkq/N3Nam v6Mqf4yEw3FXDhSSU5KhUWRzzMIWO+rWnLbZFdWxPzZioREQP5mTiC0hLX/NsfZpvVfn qTf+Pte/HtykbLfwnNovF+zt4NRAAV/5hD/lNvsTy1phJPopMQ4a3B12mHsDAKx3x9b3 WOqj/OEcepOBpUiGAGAUJyXPCEgawFM4MY+vKxWDkT6rwOT0KO8E0tM6q/LUFiHEeVTd Nrzg== X-Gm-Message-State: AEkoout+hdaXKdJ+VuJQuMVJGESWKUJgHOrjRzJNbtEDQLh4o/9qMVErjM7yzXcuSLdfqQ== X-Received: by 10.98.201.138 with SMTP id l10mr57651718pfk.77.1469701189615; Thu, 28 Jul 2016 03:19:49 -0700 (PDT) Received: from localhost ([205.204.104.65]) by smtp.gmail.com with ESMTPSA id 191sm15768649pfx.68.2016.07.28.03.19.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jul 2016 03:19:49 -0700 (PDT) From: Minfei Huang To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Minfei Huang , Minfei Huang Subject: [PATCH] blk-core: Fix the bad IO during checking bio Date: Thu, 28 Jul 2016 18:19:44 +0800 Message-Id: <1469701184-50412-1-git-send-email-mnghuan@gmail.com> X-Mailer: git-send-email 2.7.4 (Apple Git-66) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We will handle IO as a bad IO, if its range exceeds the disk's capacity in function bio_check_eod. Also we should catch the corner case if inode->i_size is set to 0 during disabling disk. Fix the coming IO as a bad IO as well, if inode->i_size is set to 0. Signed-off-by: Minfei Huang Signed-off-by: Minfei Huang --- block/blk-core.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 2475b1c7..765dfc4 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1896,25 +1896,23 @@ static inline bool should_fail_request(struct hd_struct *part, */ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors) { - sector_t maxsector; + sector_t maxsector, sector; if (!nr_sectors) return 0; /* Test device or partition size, when known. */ maxsector = i_size_read(bio->bi_bdev->bd_inode) >> 9; - if (maxsector) { - sector_t sector = bio->bi_iter.bi_sector; + sector = bio->bi_iter.bi_sector; - if (maxsector < nr_sectors || maxsector - nr_sectors < sector) { - /* - * This may well happen - the kernel calls bread() - * without checking the size of the device, e.g., when - * mounting a device. - */ - handle_bad_sector(bio); - return 1; - } + if (maxsector < nr_sectors || maxsector - nr_sectors < sector) { + /* + * This may well happen - the kernel calls bread() + * without checking the size of the device, e.g., when + * mounting a device. + */ + handle_bad_sector(bio); + return 1; } return 0;