From patchwork Thu Mar 30 18:00:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9654909 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 7976960113 for ; Thu, 30 Mar 2017 18:00:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D2A0285AE for ; Thu, 30 Mar 2017 18:00:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62052285B8; Thu, 30 Mar 2017 18:00:58 +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 CEA8C285BE for ; Thu, 30 Mar 2017 18:00:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934427AbdC3SA6 (ORCPT ); Thu, 30 Mar 2017 14:00:58 -0400 Received: from mail-it0-f46.google.com ([209.85.214.46]:38411 "EHLO mail-it0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934007AbdC3SA5 (ORCPT ); Thu, 30 Mar 2017 14:00:57 -0400 Received: by mail-it0-f46.google.com with SMTP id y18so81202448itc.1 for ; Thu, 30 Mar 2017 11:00:56 -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=LzgXmpCc0n1ZTDOpa08X11yTUFfDnvmurlz+F/f3Rg0=; b=WyCrlfTjKqOL8lLBPRc+mWvWmzzfCeS2p6HTgVTaiD0K06lQHYDtLYDqiROsaiaq4F qnJylUhIO2moMrcten3QQ5+vYg0080YD15l4OvQpq7syVNQ8HoCZdFhWylFDW1ihPW9A yjJDkPd7UyGez7Rb4YuC8OMa8Li4NasxidCGxTbekdU6a9UM26YVr49E7p/1prE8voGy 3TE1qRLfVbhR3IAbyBi0/+NkNj9kcw9WzLaX37JhEyAeQluNq26tOQp4/r5qZ2Dfpj4Q UnKJMkefI24MBhAwgWilpHNShkRG5/q46EGjNlC3msAMwmqzRQXPug8IdqFRJAgG/Qct UDig== 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=LzgXmpCc0n1ZTDOpa08X11yTUFfDnvmurlz+F/f3Rg0=; b=JO350zYVxxjxSI53pAhrbth6vrjlWGe/cMDjfYSLsCo43LSft9IIFP+1pRpUEeflAR h83QQj8NayIrV+qG/boJLmWFjycmTMnVYKQybayuUI60IMDYUGHpsbZmLJkrK0X997KL qzeGc1q+EXny2zQl6AriTE2YRiAXsiu0t0VL9Nopj6XjR1GYynAZ4EY5dYrhT9Rt3TXv Mm3dutdoNU0lGdTAhfRXc4lQDLBBKCPtTTIk1evz8sjrbAxTa4MFIGl8c7U2w1/IXsCu dy9j3cyS1sZPNpXY2o4Q+1ch5hLL2farkujfqwLKMhlr2TN43uXTyG7K2LwR25tRgpSi GGZA== X-Gm-Message-State: AFeK/H1VrPEfo69OqTDdXwqX4v7Z9u6T+Rs81HtelD+vqj39haBxkru/R0CqI046SVkQIA== X-Received: by 10.36.77.139 with SMTP id l133mr5712443itb.5.1490896855764; Thu, 30 Mar 2017 11:00:55 -0700 (PDT) Received: from [192.168.1.154] ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id l129sm1636578ite.1.2017.03.30.11.00.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 11:00:55 -0700 (PDT) To: "linux-block@vger.kernel.org" Cc: Christoph Hellwig , Josef Bacik From: Jens Axboe Subject: [PATCH] blk-mq: fix schedule-under-preempt for blocking drivers Message-ID: Date: Thu, 30 Mar 2017 12:00:54 -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 Commit a4d907b6a33b unified the single and multi queue request handlers, but in the process, it also screwed up the locking balance and calls blk_mq_try_issue_directly() with the ctx preempt lock held. This is a problem for drivers that have set BLK_MQ_F_BLOCKING, since now they can't reliably sleep. While in there, protect against similar issues in the future, by adding a might_sleep() trigger in the BLOCKING path for direct issue or queue run. Reported-by: Josef Bacik Tested-by: Josef Bacik Fixes: a4d907b6a33b ("blk-mq: streamline blk_mq_make_request") Signed-off-by: Jens Axboe Reviewed-by: Christoph Hellwig diff --git a/block/blk-mq.c b/block/blk-mq.c index e6ac774b0e41..d4d6ed4e7250 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1122,6 +1122,8 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx) blk_mq_sched_dispatch_requests(hctx); rcu_read_unlock(); } else { + might_sleep(); + srcu_idx = srcu_read_lock(&hctx->queue_rq_srcu); blk_mq_sched_dispatch_requests(hctx); srcu_read_unlock(&hctx->queue_rq_srcu, srcu_idx); @@ -1496,7 +1498,11 @@ static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx, __blk_mq_try_issue_directly(rq, cookie, false); rcu_read_unlock(); } else { - unsigned int srcu_idx = srcu_read_lock(&hctx->queue_rq_srcu); + unsigned int srcu_idx; + + might_sleep(); + + srcu_idx = srcu_read_lock(&hctx->queue_rq_srcu); __blk_mq_try_issue_directly(rq, cookie, true); srcu_read_unlock(&hctx->queue_rq_srcu, srcu_idx); } @@ -1596,18 +1602,23 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) list_del_init(&same_queue_rq->queuelist); list_add_tail(&rq->queuelist, &plug->mq_list); + blk_mq_put_ctx(data.ctx); + if (same_queue_rq) blk_mq_try_issue_directly(data.hctx, same_queue_rq, &cookie); + + return cookie; } else if (q->nr_hw_queues > 1 && is_sync) { + blk_mq_put_ctx(data.ctx); blk_mq_bio_to_request(rq, bio); blk_mq_try_issue_directly(data.hctx, rq, &cookie); + return cookie; } else if (q->elevator) { blk_mq_bio_to_request(rq, bio); blk_mq_sched_insert_request(rq, false, true, true, true); - } else if (!blk_mq_merge_queue_io(data.hctx, data.ctx, rq, bio)) { + } else if (!blk_mq_merge_queue_io(data.hctx, data.ctx, rq, bio)) blk_mq_run_hw_queue(data.hctx, true); - } blk_mq_put_ctx(data.ctx); return cookie;