From patchwork Thu Apr 20 21:13:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9691345 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 13E236037F for ; Thu, 20 Apr 2017 21:13:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 015EC28477 for ; Thu, 20 Apr 2017 21:13:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8BB82848E; Thu, 20 Apr 2017 21:13:49 +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.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 BBA4528477 for ; Thu, 20 Apr 2017 21:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032268AbdDTVNr (ORCPT ); Thu, 20 Apr 2017 17:13:47 -0400 Received: from mail-io0-f169.google.com ([209.85.223.169]:36610 "EHLO mail-io0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032147AbdDTVNp (ORCPT ); Thu, 20 Apr 2017 17:13:45 -0400 Received: by mail-io0-f169.google.com with SMTP id o22so95906962iod.3 for ; Thu, 20 Apr 2017 14:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=utQXrm+I+wpfOijxgxig21n4dvJxyQ8K8+u5bX10m6s=; b=fa/bX+xQmRZN8G9fGjXw85C8r3JjIbaJYkfShhTBtyVcLm5BM/PiYs9l7IVYz47PEh qSKxZBGpRhniaQAxXfSWPlU1hluKTzWyTe//bigFu+N+xTh+QP4bIV3pJnrc7dLVvUcM +K36e0emOHRkHsnI3T3wO1zLCcOr9Ivgrhvu0HnIZHe94ff8VtVYSIjMHUHtKoNKW8Ql zN7mT3YAzxST54tIjBdTlkIVxYd8zLKMBbgK3SF0gmhPJiQbr8H4tSTkMDD7qfmOYoix 94xNB1AaoyNm9RHt2QuxiAz+N56KIr91tfH/NkrM3x4hgC/09BGbP8L85Hc+wCv9/b59 QNXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=utQXrm+I+wpfOijxgxig21n4dvJxyQ8K8+u5bX10m6s=; b=bx/L1wAWa2qQiF4XKMYWeMucWG6TEscrRYxNsBkE6CmlX6ACyw80nQgG5cCXuLjQE6 fiTkUntHRmIPB7Iwv2a5aXwbprRK9yOWD8CoYhdvxiMUCY0yVmXMdl64J47EB4vlPdPX EgEL5DgDQiqSkC8kaLzWLIidyDYSswzCPqvFJy6hfsHXfMLIhiEas9KEpV94egfvRu5V f7HggGtB0I/b3KrB3561Mb10RuPbBvyQb5g/YHdbxmVIrSIHBBxTJ9zF5UKCUGHPDrfA N8jkgvHOrDEc5zA6tlCnkOPd/9fvGG54BxDfNZDFI/x/EyHFBDUb9YJf2g19p+0jvWpX jttw== X-Gm-Message-State: AN3rC/47nUp4NRgoM++gNrb9jSpZb0S3S4F7XwOo3xmiKzWScggQ0F2R lqGH5SuhSm7QKreWRb0= X-Received: by 10.107.33.135 with SMTP id h129mr12512932ioh.57.1492722824652; Thu, 20 Apr 2017 14:13:44 -0700 (PDT) Received: from [192.168.1.154] ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id s40sm194846ite.18.2017.04.20.14.13.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Apr 2017 14:13:43 -0700 (PDT) To: "linux-block@vger.kernel.org" Cc: Christoph Hellwig , Omar Sandoval From: Jens Axboe Subject: [PATCH] blk-mq: fix schedule-while-atomic with scheduler attached Message-ID: Date: Thu, 20 Apr 2017 15:13:43 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 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 We must have dropped the ctx before we call blk_mq_sched_insert_request() with can_block=true, otherwise we risk that a flush request can block on insertion if we are currently out of tags. [ 47.667190] BUG: scheduling while atomic: jbd2/sda2-8/2089/0x00000002 [ 47.674493] Modules linked in: x86_pkg_temp_thermal btrfs xor zlib_deflate raid6_pq sr_mod cdre [ 47.690572] Preemption disabled at: [ 47.690584] [] blk_mq_sched_get_request+0x6c/0x280 [ 47.701764] CPU: 1 PID: 2089 Comm: jbd2/sda2-8 Not tainted 4.11.0-rc7+ #271 [ 47.709630] Hardware name: Dell Inc. PowerEdge T630/0NT78X, BIOS 2.3.4 11/09/2016 [ 47.718081] Call Trace: [ 47.720903] dump_stack+0x4f/0x73 [ 47.724694] ? blk_mq_sched_get_request+0x6c/0x280 [ 47.730137] __schedule_bug+0x6c/0xc0 [ 47.734314] __schedule+0x559/0x780 [ 47.738302] schedule+0x3b/0x90 [ 47.741899] io_schedule+0x11/0x40 [ 47.745788] blk_mq_get_tag+0x167/0x2a0 [ 47.750162] ? remove_wait_queue+0x70/0x70 [ 47.754901] blk_mq_get_driver_tag+0x92/0xf0 [ 47.759758] blk_mq_sched_insert_request+0x134/0x170 [ 47.765398] ? blk_account_io_start+0xd0/0x270 [ 47.770679] blk_mq_make_request+0x1b2/0x850 [ 47.775766] generic_make_request+0xf7/0x2d0 [ 47.780860] submit_bio+0x5f/0x120 [ 47.784979] ? submit_bio+0x5f/0x120 [ 47.789631] submit_bh_wbc.isra.46+0x10d/0x130 [ 47.794902] submit_bh+0xb/0x10 [ 47.798719] journal_submit_commit_record+0x190/0x210 [ 47.804686] ? _raw_spin_unlock+0x13/0x30 [ 47.809480] jbd2_journal_commit_transaction+0x180a/0x1d00 [ 47.815925] kjournald2+0xb6/0x250 [ 47.820022] ? kjournald2+0xb6/0x250 [ 47.824328] ? remove_wait_queue+0x70/0x70 [ 47.829223] kthread+0x10e/0x140 [ 47.833147] ? commit_timeout+0x10/0x10 [ 47.837742] ? kthread_create_on_node+0x40/0x40 [ 47.843122] ret_from_fork+0x29/0x40 Fixes: a4d907b6a33b ("blk-mq: streamline blk_mq_make_request") Signed-off-by: Jens Axboe Reviewed-by: Omar Sandoval diff --git a/block/blk-mq.c b/block/blk-mq.c index 9d7645f24b05..323eed50d615 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1634,8 +1634,10 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) blk_mq_try_issue_directly(data.hctx, rq, &cookie); return cookie; } else if (q->elevator) { + blk_mq_put_ctx(data.ctx); blk_mq_bio_to_request(rq, bio); blk_mq_sched_insert_request(rq, false, true, true, true); + return cookie; } else if (!blk_mq_merge_queue_io(data.hctx, data.ctx, rq, bio)) blk_mq_run_hw_queue(data.hctx, true);