From patchwork Tue Sep 27 09:25:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9351627 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 0C4C1600CB for ; Tue, 27 Sep 2016 09:25:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F06B12915A for ; Tue, 27 Sep 2016 09:25:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E50872915C; Tue, 27 Sep 2016 09:25:53 +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 E77DE29172 for ; Tue, 27 Sep 2016 09:25:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933128AbcI0JZu (ORCPT ); Tue, 27 Sep 2016 05:25:50 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35643 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932192AbcI0JZt (ORCPT ); Tue, 27 Sep 2016 05:25:49 -0400 Received: by mail-pf0-f196.google.com with SMTP id 6so497112pfl.2 for ; Tue, 27 Sep 2016 02:25:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=VKLEcYtfHutq+lj5gpwtIg95nMDd+JxmSks9Nab9DGo=; b=r3qwtjoMxKwjV2ZN0wYiOl3///PGvEtnq+tJkAVzVDcH9sFOWFXZh0WGOhFP+50LLu ikzNbWpb8WS1/2b8gUQvOOMPC8aVzd+78OW4+NHdhD/UtFMhJRtQXmq/A07AgHtPD2VN bsCu3Y+v9X6SzTvyLDHUz/MEx9vI+N/ccklSjcSewl9tor9/yBFG4SIvqlinZueDDjgq tr8ZO/OVcwqv3CWgXOf7ODFipK5P5Qv+sGv6m/W0HJBvcZWcCvBBN5cQaypqmd9ITLig aMZWrnYEgessxdBJpQC4cWpx+dgVYO7zwa9jd5urf7iteKypppfZTf0zkwIVR3ijrXBp TbtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=VKLEcYtfHutq+lj5gpwtIg95nMDd+JxmSks9Nab9DGo=; b=AswGLIG618cpOxQTS/RGHAMEQngyMqdxm6ZZLHxOi4nKxbTi/RTLDJrzufSLSarRTV qb5UQpHmZ0TvFecy+FYWSfGIwQltyMk/CM5UiDiH21cxst6QmWXOlDq/7wiJ2qVyylSt bNqS343mLrL3YZKWBAZ3zlEsLxI8G/J7c7mNhvDKG7VG3kGMLFLht5c9XgJwC9SiQ+6P SbwmhyyTLKEQGJfwdnDjiOxgCyv42huidtBfwxRHhHPeKYFkOeSnCQgfjeBaNve6L2EG omqtK/L0jh/+hTk2MRtCqzwCU2zPc3eEXz99zq7gFSZvwZ9YGT7LGicSjYTrUpQSaLVD Nj5g== X-Gm-Message-State: AE9vXwPFNWi9sB1Oo5A4OQPvDlcIt9J59aEa874CwDg+Fu7MQsje5FO3JhrP3pFley8pow== X-Received: by 10.98.14.20 with SMTP id w20mr46893463pfi.9.1474968347924; Tue, 27 Sep 2016 02:25:47 -0700 (PDT) Received: from tom-ThinkPad-T450 ([45.34.23.101]) by smtp.gmail.com with ESMTPSA id s1sm3145454paz.47.2016.09.27.02.25.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Sep 2016 02:25:47 -0700 (PDT) Date: Tue, 27 Sep 2016 17:25:36 +0800 From: Ming Lei To: Keith Busch Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Ming Lei Subject: Re: [PATCH] blk-mq: Return invalid cookie if bio was split Message-ID: <20160927172536.53a1315f@tom-ThinkPad-T450> In-Reply-To: <20160926230030.GB24200@localhost.localdomain> References: <20160926230030.GB24200@localhost.localdomain> Organization: Ming X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 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 On Mon, 26 Sep 2016 19:00:30 -0400 Keith Busch wrote: > The only user of polling requires its original request be completed in > its entirety before continuing execution. If the bio needs to be split > and chained for any reason, the direct IO path would have waited for just > that split portion to complete, leading to potential data corruption if > the remaining transfer has not yet completed. The issue looks a bit tricky because there is no per-bio place for holding the cookie, and generic_make_request() only returns the cookie for the last bio in the current bio list, so maybe we need the following patch too. Also seems merge case need to take care of too. --- > > This patch has blk-mq return an invalid cookie if a bio requires splitting > so that polling does not occur. > > Signed-off-by: Keith Busch > --- > block/blk-mq.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/block/blk-mq.c b/block/blk-mq.c > index c207fa9..6385985 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -1311,6 +1311,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) > unsigned int request_count = 0; > struct blk_plug *plug; > struct request *same_queue_rq = NULL; > + struct bio *orig = bio; > blk_qc_t cookie; > > blk_queue_bounce(q, &bio); > @@ -1389,7 +1390,7 @@ run_queue: > } > blk_mq_put_ctx(data.ctx); > done: > - return cookie; > + return bio == orig ? cookie : BLK_QC_T_NONE; > } > > /* > @@ -1404,6 +1405,7 @@ static blk_qc_t blk_sq_make_request(struct request_queue *q, struct bio *bio) > unsigned int request_count = 0; > struct blk_map_ctx data; > struct request *rq; > + struct bio *orig = bio; > blk_qc_t cookie; > > blk_queue_bounce(q, &bio); > @@ -1467,7 +1469,7 @@ run_queue: > } > > blk_mq_put_ctx(data.ctx); > - return cookie; > + return bio == orig ? cookie : BLK_QC_T_NONE; > } > > /* -- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/block/blk-core.c b/block/blk-core.c index 14d7c0740dc0..f1ab547173f8 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1996,6 +1996,8 @@ blk_qc_t generic_make_request(struct bio *bio) { struct bio_list bio_list_on_stack; blk_qc_t ret = BLK_QC_T_NONE; + blk_qc_t lret; + const struct bio *orig = bio; if (!generic_make_request_checks(bio)) goto out; @@ -2036,7 +2038,9 @@ blk_qc_t generic_make_request(struct bio *bio) struct request_queue *q = bdev_get_queue(bio->bi_bdev); if (likely(blk_queue_enter(q, false) == 0)) { - ret = q->make_request_fn(q, bio); + lret = q->make_request_fn(q, bio); + if (bio == orig) + ret = lret; blk_queue_exit(q);