Received: by 10.192.165.156 with SMTP id m28csp269005imm; Tue, 17 Apr 2018 09:51:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/CAcsJ51waxpmIjwX9HioOSRJmgt2em4ETZQmQpZHeuk3/7/d4BKhif6nQA0lcQaONIuHm X-Received: by 2002:a17:902:b60f:: with SMTP id b15-v6mr2807215pls.12.1523983868572; Tue, 17 Apr 2018 09:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523983868; cv=none; d=google.com; s=arc-20160816; b=ELGU8aDf2N36DDAhSF6BXtrMIeaqS3Sia8IFUCrmb9+mEjAxKep9qXIhbWhJUMl29q E25u/lYZ80NMVSHUV0QFCi3kxGlWoPoocONeyHtX4yUgK8zIEZQbmv776AmEp+WMg83I gHpYGL3Ujb0peXsc4ghGH12xGXmd3zlaECukyIdHBrxHMdbd/bNldyEpqK5bZNPFGGT1 XxD2v4o8ypl9/X9+7zhVmIN96cZUp6g4bNdrcurICiN0m2e/s6nnodlgyUiyM3IbYg24 lzbOwY0tehjgwtnCI98ILg8EQHKUFqPOWlj98Q2x4vaoIhQFCok0bu5sEIgi8vO0DYIu PPmQ== 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=LnHgsKMUu1QiCx7jtZ1Stoo2ww33oNuCF1yMijxQUi4=; b=uNVeOshS21z+DlRMknTCyWRzbCEleRWh3V6rUrjS6S8kEWgfvUaNEOb+/MrmgJRR10 fwlwdxWc6uA2D98B9eMGjFDsU6vEZIcTPo9g2Smv+Z0UCt3liIaIG490pQq8xp0LJPV8 koS4rkgdOX77SjQAuDVR9TwCHVK3mD2dAT2gH4oFDfrPyygBw8nDmsO7vb7mij6JT+He frm/si5hBZIuy4chRhPGJP6TRafyVO8RPnCONgePVVjF2pgxaK8I3cX8EKug4/0D1a1Q OpWWj+zLnjmjIoyx5H/WjYr41XTS+ZJSHt3EG8DphMkbSU/yOThjjtgAACfqK0RKWl9g FD2Q== 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 a1si4963347pgq.594.2018.04.17.09.50.53; Tue, 17 Apr 2018 09:51:08 -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 S1754582AbeDQQEp (ORCPT + 99 others); Tue, 17 Apr 2018 12:04:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34178 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752695AbeDQQEg (ORCPT ); Tue, 17 Apr 2018 12:04:36 -0400 Received: from localhost (unknown [46.44.180.42]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 403FE8E3; Tue, 17 Apr 2018 16:04:14 +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.15 31/53] blk-mq: order getting budget and driver tag Date: Tue, 17 Apr 2018 17:58:56 +0200 Message-Id: <20180417155724.667039673@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180417155723.091120060@linuxfoundation.org> References: <20180417155723.091120060@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.15-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 @@ -1096,7 +1096,12 @@ bool blk_mq_dispatch_rq_list(struct requ blk_status_t ret; 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 @@ -1105,8 +1110,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. @@ -1117,11 +1121,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; @@ -1619,11 +1618,11 @@ static void __blk_mq_try_issue_directly( if (q->elevator) 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; }