From patchwork Mon Oct 16 23:32:26 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: 10010219 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 D64C6601D5 for ; Mon, 16 Oct 2017 23:33:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C837228408 for ; Mon, 16 Oct 2017 23:33:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC309286FD; Mon, 16 Oct 2017 23:33:22 +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 375BD28408 for ; Mon, 16 Oct 2017 23:33:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932697AbdJPXdV (ORCPT ); Mon, 16 Oct 2017 19:33:21 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:20239 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932638AbdJPXdV (ORCPT ); Mon, 16 Oct 2017 19:33:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1508196801; x=1539732801; h=from:to:cc:subject:date:message-id; bh=b5q1H6oI2WbImGQWoDadg9VIuVWmvpjIS66zefZprQU=; b=lk6IJROO/Z7pmuh97ZVA46n0z6GwOdLwtmh+o78oeSL0/hWJbjjCnOpE vxC1m1ih2OjndKAuROOJtc6YMKuvnbJal29l/Y+WQv2vS294Ki7rosTVb 9MI+phQi91HZ/EFYqJvt4/8bruFIcMBPYdUySvDI/qWzo7X0B0tngU8hC qLyqQL4f+TZDuJbW0UgF5MacnwlNDtF2tZb6Js+7+RCFrMYzwOJK9++ax E+AVI1ZlD8FS4KM+o78JpPIwKJNYAfTvQ39X4NH4dlqZ1KzNLv4xkJKPz hn1/VTsSURyJRM/D43HXWHhBfHzu9fOW+1HR5/3Ez7aRqvQRtn7GVdH5a Q==; X-IronPort-AV: E=Sophos;i="5.43,388,1503331200"; d="scan'208";a="160781962" Received: from sjappemgw12.hgst.com (HELO sjappemgw11.hgst.com) ([199.255.44.66]) by ob1.hgst.iphmx.com with ESMTP; 17 Oct 2017 07:33:20 +0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.172.152]) by sjappemgw11.hgst.com with ESMTP; 16 Oct 2017 16:32:27 -0700 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Ming Lei Subject: [PATCH v2] blk-mq: Make blk_mq_get_request() error path less confusing Date: Mon, 16 Oct 2017 16:32:26 -0700 Message-Id: <20171016233226.5488-1-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.14.2 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 blk_mq_get_tag() can modify data->ctx. This means that in the error path of blk_mq_get_request() data->ctx should be passed to blk_mq_put_ctx() instead of local_ctx. Note: since blk_mq_put_ctx() ignores its argument, this patch does not change any functionality. References: commit 1ad43c0078b7 ("blk-mq: don't leak preempt counter/q_usage_counter when allocating rq failed") Signed-off-by: Bart Van Assche Cc: Ming Lei Reviewed-by: Ming Lei Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- Changes compared to v1: - Removed "Cc: " - Removed "bug fix" from the description. block/blk-mq.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 097ca3ece716..d9b3b5dc66ab 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -336,12 +336,14 @@ static struct request *blk_mq_get_request(struct request_queue *q, struct elevator_queue *e = q->elevator; struct request *rq; unsigned int tag; - struct blk_mq_ctx *local_ctx = NULL; + bool put_ctx_on_error = false; blk_queue_enter_live(q); data->q = q; - if (likely(!data->ctx)) - data->ctx = local_ctx = blk_mq_get_ctx(q); + if (likely(!data->ctx)) { + data->ctx = blk_mq_get_ctx(q); + put_ctx_on_error = true; + } if (likely(!data->hctx)) data->hctx = blk_mq_map_queue(q, data->ctx->cpu); if (op & REQ_NOWAIT) @@ -360,8 +362,8 @@ static struct request *blk_mq_get_request(struct request_queue *q, tag = blk_mq_get_tag(data); if (tag == BLK_MQ_TAG_FAIL) { - if (local_ctx) { - blk_mq_put_ctx(local_ctx); + if (put_ctx_on_error) { + blk_mq_put_ctx(data->ctx); data->ctx = NULL; } blk_queue_exit(q);