Received: by 10.192.165.156 with SMTP id m28csp223117imm; Tue, 17 Apr 2018 09:04:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+3PX5Mm7gfx6YVMhZlcMDQsi2nRNlLDTB1/EYz2MSV31euQTgUsz2/TKnqnzskTAVcMRsT X-Received: by 10.101.93.7 with SMTP id e7mr2315659pgr.119.1523981094368; Tue, 17 Apr 2018 09:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523981094; cv=none; d=google.com; s=arc-20160816; b=xNkRkaZUQh+gsHJpZAfmxR08ZaaJeQcCYNXHzrtacLQCp5HZzvmukOi25Ffaw8KphD 6aDkJkNTpOPvO6BzfGvsoM/EC3AkB2cLFdWEytwk7x3s6KldxG+4Qf9xXyiC1q3jVcc8 RXwglU8ECapD28OptgI0xYkjEMIik9Q0yngIRdpIuEmxq8/9rR/gTinN5n5H9t7t4h/a boJEVipo0fwhwY4TDi75ANlM2vk+PxYqLghArxUVhzdfJaoxfRBlocdjx5uSepPJrxaq yqosrhnRAx4I1FQtoFQvEuyRPQEARlqR2q8EOluYQWMn1qilpZlmhlI2RUy7H409UU/M rPwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=uEE5SrSo9W2yAsFiT+qNw/r4Iv5UKKcylOUSga4ejhw=; b=N+FlcmnFalpLignPePP3NSBijzCW5dxildvLxRsX+iuBPZI6XY9tAgNCni20+MMxi1 GOMhUACSWKXyDsVXoHhcrkEmeJnaUpcAUqrF/sqwWPN0xPfpv7mmT8y5U7eyVJe033V7 JZKEZYPJS4ZaSKWOvbcNuExZSlVCk7ZPB1EIldRaK3eYVhifGYowUzbzyXTdhW1S+PDE DXGQshZ8K2lJZvqldk7dE8/0/oeiqW0hOrPrI0odxeaZ+dqg3C1lnZZUvCCBRa3pMkCw 2k/GyhNKC7rWqSgcJXCViLHWCXaDkbuI774HlmdVX4m8k2dHzshjda5rqbyjoJ14pHgL F+UQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j63si11869893pgc.474.2018.04.17.09.04.40; Tue, 17 Apr 2018 09:04:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753771AbeDQQBc (ORCPT + 99 others); Tue, 17 Apr 2018 12:01:32 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60472 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753596AbeDQQB3 (ORCPT ); Tue, 17 Apr 2018 12:01:29 -0400 Received: from localhost (unknown [46.44.180.42]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 725C3DF7; Tue, 17 Apr 2018 16:01:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Omar Sandoval , Ming Lei , Jens Axboe Subject: [PATCH 4.16 41/68] blk-mq: order getting budget and driver tag Date: Tue, 17 Apr 2018 17:57:54 +0200 Message-Id: <20180417155750.999593927@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180417155749.341779147@linuxfoundation.org> References: <20180417155749.341779147@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ming Lei commit 0bca799b92807ee9be0890690f5dde7d8c6a8e25 upstream. This patch orders getting budget and driver tag by making sure to acquire driver tag after budget is got, this way can help to avoid the following race: 1) before dispatch request from scheduler queue, get one budget first, then dequeue a request, call it request A. 2) in another IO path for dispatching request B which is from hctx->dispatch, driver tag is got, then try to get budget in blk_mq_dispatch_rq_list(), unfortunately the budget is held by request A. 3) meantime blk_mq_dispatch_rq_list() is called for dispatching request A, and try to get driver tag first, unfortunately no driver tag is available because the driver tag is held by request B 4) both two IO pathes can't move on, and IO stall is caused. This issue can be observed when running dbench on USB storage. This patch fixes this issue by always getting budget before getting driver tag. Cc: stable@vger.kernel.org Fixes: de1482974080ec9e ("blk-mq: introduce .get_budget and .put_budget in blk_mq_ops") Cc: Christoph Hellwig Cc: Bart Van Assche Cc: Omar Sandoval Signed-off-by: Ming Lei Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-mq.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1188,7 +1188,12 @@ bool blk_mq_dispatch_rq_list(struct requ struct blk_mq_queue_data bd; rq = list_first_entry(list, struct request, queuelist); - if (!blk_mq_get_driver_tag(rq, &hctx, false)) { + + hctx = blk_mq_map_queue(rq->q, rq->mq_ctx->cpu); + if (!got_budget && !blk_mq_get_dispatch_budget(hctx)) + break; + + if (!blk_mq_get_driver_tag(rq, NULL, false)) { /* * The initial allocation attempt failed, so we need to * rerun the hardware queue when a tag is freed. The @@ -1197,8 +1202,7 @@ bool blk_mq_dispatch_rq_list(struct requ * we'll re-run it below. */ if (!blk_mq_mark_tag_wait(&hctx, rq)) { - if (got_budget) - blk_mq_put_dispatch_budget(hctx); + blk_mq_put_dispatch_budget(hctx); /* * For non-shared tags, the RESTART check * will suffice. @@ -1209,11 +1213,6 @@ bool blk_mq_dispatch_rq_list(struct requ } } - if (!got_budget && !blk_mq_get_dispatch_budget(hctx)) { - blk_mq_put_driver_tag(rq); - break; - } - list_del_init(&rq->queuelist); bd.rq = rq; @@ -1812,11 +1811,11 @@ static blk_status_t __blk_mq_try_issue_d if (q->elevator && !bypass_insert) goto insert; - if (!blk_mq_get_driver_tag(rq, NULL, false)) + if (!blk_mq_get_dispatch_budget(hctx)) goto insert; - if (!blk_mq_get_dispatch_budget(hctx)) { - blk_mq_put_driver_tag(rq); + if (!blk_mq_get_driver_tag(rq, NULL, false)) { + blk_mq_put_dispatch_budget(hctx); goto insert; }