From patchwork Fri Dec 1 00:08:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10085887 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 D1D03605D2 for ; Fri, 1 Dec 2017 00:08:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3B6E2A449 for ; Fri, 1 Dec 2017 00:08:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B706A2A447; Fri, 1 Dec 2017 00:08:56 +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_SIGNED, 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 5F0D62A447 for ; Fri, 1 Dec 2017 00:08:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750940AbdLAAIy (ORCPT ); Thu, 30 Nov 2017 19:08:54 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:58597 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750898AbdLAAIv (ORCPT ); Thu, 30 Nov 2017 19:08:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1512086932; x=1543622932; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=m0Gw6pK41MjEL9HPrGLomBnGlHSYp4ha2yvdi/577WY=; b=MGk/jCoqdV7GDRjshhyo19A3q7spqmAC78e7hmkudighzB4/yP+WEmej NldUCA0FErAy3HI+qDXngwE06HGznU0BihbNnte2fD1h3rJpHyZXJeQtm ry5VUs3ytJyFYD317Cr26pMkxHtr22YDUHF2r2DocbRNybiiubtmIuZv7 c84eOvqO8mDzHpHPqwRl/6yIbIsKVvAmKW5zq5CKgTNANyZOnVMK8WwJY 73RJI2x9aKOTyhXITkPuqXMqm2YmwFZkGys03qj4U1ntFf21wXVIZFZp1 03nc9x0balCluHgDwe0QwwgkfFlrXAPx4uYAwR4k5GhGEdB21OxZC9nPz w==; X-IronPort-AV: E=Sophos;i="5.45,343,1508774400"; d="scan'208";a="63876013" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 01 Dec 2017 08:08:51 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 30 Nov 2017 16:06:07 -0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.166.51]) by uls-op-cesaip02.wdc.com with ESMTP; 30 Nov 2017 16:08:51 -0800 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Ming Lei , Omar Sandoval , Hannes Reinecke , Johannes Thumshirn Subject: [PATCH 7/7] blk-mq: Fix another queue stall Date: Thu, 30 Nov 2017 16:08:48 -0800 Message-Id: <20171201000848.2656-8-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171201000848.2656-1-bart.vanassche@wdc.com> References: <20171201000848.2656-1-bart.vanassche@wdc.com> 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 The following code at the end of blk_mq_dispatch_rq_list() detects whether or not wake_up(&hctx->dispatch_wait) has been called concurrently with pushing back requests onto the dispatch list: list_empty_careful(&hctx->dispatch_wait.entry) Since blk_mq_dispatch_wake() is protected by another lock than the dispatch list and since blk_mq_run_hw_queue() does not acquire any lock if it notices that no requests are pending, blk_mq_dispatch_wake() is not ordered against the code that pushes back requests onto the dispatch list. Avoid that the dispatch_wait empty check fails due to load/store reordering by serializing it against the dispatch_wait queue wakeup. This patch fixes a queue stall I ran into while testing a SCSI initiator driver with the maximum target depth set to one. Signed-off-by: Bart Van Assche Cc: Ming Lei Cc: Omar Sandoval Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Johannes Thumshirn --- block/blk-mq.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index b4225f606737..a11767a4d95c 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1074,6 +1074,20 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx **hctx, return ret; } +static bool blk_mq_dispatch_list_empty(struct blk_mq_hw_ctx *hctx) +{ + struct sbq_wait_state *ws = bt_wait_ptr(&hctx->tags->bitmap_tags, hctx); + struct wait_queue_head *wq_head = &ws->wait; + unsigned long flags; + bool result; + + spin_lock_irqsave(&wq_head->lock, flags); + result = list_empty(&hctx->dispatch_wait.entry); + spin_unlock_irqrestore(&wq_head->lock, flags); + + return result; +} + bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, bool got_budget) { @@ -1197,7 +1211,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list, */ if (restart || !blk_mq_sched_needs_restart(hctx) || - (no_tag && list_empty_careful(&hctx->dispatch_wait.entry))) + (no_tag && blk_mq_dispatch_list_empty(hctx))) blk_mq_run_hw_queue(hctx, true); }