From patchwork Wed Aug 1 09:33:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Yan X-Patchwork-Id: 10551917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 032ED157D for ; Wed, 1 Aug 2018 09:21:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6B122ABF9 for ; Wed, 1 Aug 2018 09:21:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D97062AC2E; Wed, 1 Aug 2018 09:21:36 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 6C6462ABF9 for ; Wed, 1 Aug 2018 09:21:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388465AbeHALGX (ORCPT ); Wed, 1 Aug 2018 07:06:23 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:10208 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387502AbeHALGX (ORCPT ); Wed, 1 Aug 2018 07:06:23 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 9EF83CAAD5816; Wed, 1 Aug 2018 17:21:30 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.399.0; Wed, 1 Aug 2018 17:21:23 +0800 From: Jason Yan To: , CC: , , Jason Yan , Kent Overstreet , "Christoph Hellwig" , "Martin K . Petersen" Subject: [PATCH] block: only rewind to last split Date: Wed, 1 Aug 2018 17:33:57 +0800 Message-ID: <20180801093357.18417-1-yanaijie@huawei.com> X-Mailer: git-send-email 2.13.6 MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected 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 Commit 63573e359d05 ("bio-integrity: Restore original iterator on verify stage") made the bio-integrity verify function works fine when the bio is smaller than the queue limit. But since commit 54efd50bfd87 ("block: make generic_make_request handle arbitrarily sized bios") the bio will split in block layer if the size of bio is larger than the max length of the queue limit. This will make the bio-integrity verify function do not work. We will see such error log with splited bios: [69163.386065] sda: ref tag error at location 0 (rcvd 1024) Suppose we have a bio of size 1024k submitted and the driver can only accept bio of max size 512k. The original bio: bi_sector 1024k bio +-------------------------------+ After the split we have two bios: bi_sector 512k split +---------------+ bi_sector 512k bio +---------------+---------------+ The new split bio is cloned from the first 512k of the original bio. And the original bio is advanced to the next 512k(that is 512k~1024k). The we submit these two requests to the driver. After the these two bios are complete and we rewind the original bio in bio_integrity_verify_fn(), the bio restored to the beginnig, but it does not match the data we submitted to the driver: bi_sector 1024k bio +-------------------------------+ When the split bio is complete the verify works fine. But when the whole original bio is complete we just rewind the whole bio, which makes the seed does not match the ref tag at all. So we see the above error log. Fix this by clear the bi_iter.bi_done after split, so that we will only rewind to the last sector we last start to split. Fixes: 63573e359d05 ("bio-integrity: Restore original iterator on verify stage") Signed-off-by: Jason Yan Reported-by: Zhang Liao Tested-by: Li Chunjiang CC: Jens Axboe CC: Kent Overstreet CC: Christoph Hellwig CC: Martin K. Petersen CC: Miao Xie CC: Zhaohongjiang --- block/bio.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/bio.c b/block/bio.c index 67eff5eddc49..afa4f408b9dc 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1867,6 +1867,14 @@ struct bio *bio_split(struct bio *bio, int sectors, bio_advance(bio, split->bi_iter.bi_size); + /* + * Now bi_iter.bi_done is only used for bio-integrity to verify + * the data come up from the driver. If we don't clear bi_done + * here, the original bio will rewind to the beginning and the + * seed is error. Please check bio_integrity_verify_fn(). + */ + bio->bi_iter.bi_done = 0; + if (bio_flagged(bio, BIO_TRACE_COMPLETION)) bio_set_flag(split, BIO_TRACE_COMPLETION);