From patchwork Wed Nov 16 10:07:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9431205 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 7294060471 for ; Wed, 16 Nov 2016 10:07:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 678D128EAC for ; Wed, 16 Nov 2016 10:07:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59F6228E9E; Wed, 16 Nov 2016 10:07:38 +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.9 required=2.0 tests=BAYES_00,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 B2F4328E9E for ; Wed, 16 Nov 2016 10:07:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934463AbcKPKHf (ORCPT ); Wed, 16 Nov 2016 05:07:35 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34437 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934108AbcKPKHT (ORCPT ); Wed, 16 Nov 2016 05:07:19 -0500 Received: by mail-pg0-f67.google.com with SMTP id e9so13974564pgc.1; Wed, 16 Nov 2016 02:07:18 -0800 (PST) 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=rLcbN7KqhczviK+7COhfqNsBRCOin1vymKyCtKz40Xg=; b=OcN/QUhWVNiG0NmTAI09WIR/8aphCta4YszKPpCGFXJ0Y0K156ImuMvN34u6xa4+86 T+4ldIfDbpoGDPn1NDfbUlTk+jGIX5bQ0E6tAL/mj8OweA5sU0XFfOKwQDJXdWJWsi5v ETaVTQO/uQ8m2Yu7YjxRyD/LH0Tvt2YVH0V3QotSQ+9T4+rrh0/2CO+7blbw0QLne+o7 oFfrZ2csAXouksriMJjHEg3rLwlkTW00bOPJrbWozp1PIphdXWZrZzqhTzZCnQTrkcdz HyPWTlXT3D0kE+J3Va9h0F+57Hn6posJgjJOlZgHSrLFhrj77Nw+s2oxKbsIZoQjGqZ7 pMWw== X-Gm-Message-State: ABUngvfIzPqm3eZe6MS33kOeNGKUIJzPWSF/zH3j+24uW+9dYulaDJX3Lu+o9AtUBAZc7Q== X-Received: by 10.99.105.70 with SMTP id e67mr6393828pgc.99.1479290838354; Wed, 16 Nov 2016 02:07:18 -0800 (PST) Received: from localhost ([45.34.23.101]) by smtp.gmail.com with ESMTPSA id u23sm51749019pfg.86.2016.11.16.02.07.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Nov 2016 02:07:17 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Ming Lei , Shaohua Li , Jens Axboe Subject: [PATCH] block: deal with stale req count of plug list Date: Wed, 16 Nov 2016 18:07:05 +0800 Message-Id: <1479290825-23201-1-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 2.7.4 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 In both legacy and mq path, req count of plug list is computed before allocating request, so the number can be stale when falling back to slept allocation, also the new introduced wbt can sleep too. This patch deals with the case by checking if plug list becomes empty, and fixes the KASAN report of 'BUG: KASAN: stack-out-of-bounds' which is introduced by Shaohua's patches of dispatching big request. Fixes: 600271d900002(blk-mq: immediately dispatch big size request) Fixes: 50d24c34403c6(block: immediately dispatch big size request) Cc: Shaohua Li Signed-off-by: Ming Lei --- block/blk-core.c | 5 ++++- block/blk-mq.c | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/block/blk-core.c b/block/blk-core.c index eea246567884..473dd698effd 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1753,8 +1753,11 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio) /* * If this is the first request added after a plug, fire * of a plug trace. + * + * @request_count may become stale because of schedule + * out, so check plug list again. */ - if (!request_count) + if (!request_count || list_empty(&plug->list)) trace_block_plug(q); else { struct request *last = list_entry_rq(plug->list.prev); diff --git a/block/blk-mq.c b/block/blk-mq.c index ae8df5ec20d3..f39e69c732cc 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1497,6 +1497,13 @@ static blk_qc_t blk_sq_make_request(struct request_queue *q, struct bio *bio) struct request *last = NULL; blk_mq_bio_to_request(rq, bio); + + /* + * @request_count may become stale because of schedule + * out, so check the list again. + */ + if (list_empty(&plug->mq_list)) + request_count = 0; if (!request_count) trace_block_plug(q); else