From patchwork Mon Feb 27 18:28:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9594403 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 CCEBD60453 for ; Mon, 27 Feb 2017 22:52:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE756205F7 for ; Mon, 27 Feb 2017 22:52:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2B8528498; Mon, 27 Feb 2017 22:52:25 +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 30FD3205F7 for ; Mon, 27 Feb 2017 22:52:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750971AbdB0WwY (ORCPT ); Mon, 27 Feb 2017 17:52:24 -0500 Received: from mail-pg0-f46.google.com ([74.125.83.46]:36509 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751291AbdB0WwX (ORCPT ); Mon, 27 Feb 2017 17:52:23 -0500 Received: by mail-pg0-f46.google.com with SMTP id s67so49405272pgb.3 for ; Mon, 27 Feb 2017 14:50:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eZzduwOukPqHxpYLeSCgDcBAA0Zw5Cc6frUpbRfBfyU=; b=ycjtS7KHsirmBBLIEWrxIBmy8NxL3LL9G2zlZhAu6nh24D6S6sE9PZQdsem9OJEJkM I+5h2Zz9xI5e7ksdHrMWa+xqx7/yI4Z4bHNwD7+VJlKOmHGNOXRJURk6hi+iAoS3Hyu8 YX/FOgUEi45PQP8hICyeOnLDbjzjvTMOFzgC6bbaF6iBjv8l9rX6E0csp77neVH8NGY+ SubZArwoODxHLESPBVvxfTS4PSULONsZtDc+vc034zWABUoDKAAvJdjOc/A8831At/+u gRoJiYn3znlANvYv97W29tkyN2zD4ZHroZmiesH7QHJdQWVBh4ZnJtemCVJNh8tCnvEf x3+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eZzduwOukPqHxpYLeSCgDcBAA0Zw5Cc6frUpbRfBfyU=; b=eyGZzwutwMrSJN0yyVO5f5jO+YS6Ywres8NBAe0sbRhH0EqD+JAza4VHKo014EzS3X 10hzNJxsTYERMASuuhkF/JTdLcdMpBI49Zg+puKbucwJ8ldc4Px0goh1YcfDR0jI7M+i R8bSPaqZE+ozZHVYcrMKa0VH2m5egDh5rbBSvpPcaPm3Vk7NF1UaacYQNTSXoCpTG3fC jxbvEXm3JbKXt89TZfK41Qa8At2bPUckJOk4rOSTEI+eymUdtUA5xd4g70f5f54DjJYn 1UME+iAF/pqUKEOCGGERGWJp0qA7Xvagzb7zMbuFdEwVIFyyXxPuJWyc6cbMTDK8YfPm Qg+g== X-Gm-Message-State: AMke39lZv0sTmqmAeETk0MbjK3LsvqhdKiDi77Eiu/wS8jrVi2cAL3nt6IfSA6ihUv30BQG8 X-Received: by 10.98.62.219 with SMTP id y88mr22407463pfj.62.1488220154162; Mon, 27 Feb 2017 10:29:14 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::93d5]) by smtp.gmail.com with ESMTPSA id l188sm31967615pfl.28.2017.02.27.10.29.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Feb 2017 10:29:13 -0800 (PST) From: Omar Sandoval To: Jens Axboe , linux-block@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH v2] blk-mq: make blk_mq_alloc_request_hctx() allocate a scheduler request Date: Mon, 27 Feb 2017 10:28:27 -0800 Message-Id: X-Mailer: git-send-email 2.12.0 In-Reply-To: References: 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 From: Omar Sandoval blk_mq_alloc_request_hctx() allocates a driver request directly, unlike its blk_mq_alloc_request() counterpart. It also crashes because it doesn't update the tags->rqs map. Fix it by making it allocate a scheduler request. Reported-by: Sagi Grimberg Signed-off-by: Omar Sandoval --- block/blk-mq-sched.c | 11 +++++------ block/blk-mq.c | 33 +++++++++++++++------------------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c index 46ca965fff5c..5697b23412a1 100644 --- a/block/blk-mq-sched.c +++ b/block/blk-mq-sched.c @@ -110,15 +110,14 @@ struct request *blk_mq_sched_get_request(struct request_queue *q, struct blk_mq_alloc_data *data) { struct elevator_queue *e = q->elevator; - struct blk_mq_hw_ctx *hctx; - struct blk_mq_ctx *ctx; struct request *rq; blk_queue_enter_live(q); - ctx = blk_mq_get_ctx(q); - hctx = blk_mq_map_queue(q, ctx->cpu); - - blk_mq_set_alloc_data(data, q, data->flags, ctx, hctx); + data->q = q; + if (likely(!data->ctx)) + data->ctx = blk_mq_get_ctx(q); + if (likely(!data->hctx)) + data->hctx = blk_mq_map_queue(q, data->ctx->cpu); if (e) { data->flags |= BLK_MQ_REQ_INTERNAL; diff --git a/block/blk-mq.c b/block/blk-mq.c index 4df5fb42c74f..85a7047d8b03 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -273,10 +273,9 @@ EXPORT_SYMBOL(blk_mq_alloc_request); struct request *blk_mq_alloc_request_hctx(struct request_queue *q, int rw, unsigned int flags, unsigned int hctx_idx) { - struct blk_mq_hw_ctx *hctx; - struct blk_mq_ctx *ctx; + struct blk_mq_alloc_data alloc_data = { .flags = flags }; struct request *rq; - struct blk_mq_alloc_data alloc_data; + unsigned int cpu; int ret; /* @@ -299,25 +298,23 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, int rw, * Check if the hardware context is actually mapped to anything. * If not tell the caller that it should skip this queue. */ - hctx = q->queue_hw_ctx[hctx_idx]; - if (!blk_mq_hw_queue_mapped(hctx)) { - ret = -EXDEV; - goto out_queue_exit; + alloc_data.hctx = q->queue_hw_ctx[hctx_idx]; + if (!blk_mq_hw_queue_mapped(alloc_data.hctx)) { + blk_queue_exit(q); + return ERR_PTR(-EXDEV); } - ctx = __blk_mq_get_ctx(q, cpumask_first(hctx->cpumask)); + cpu = cpumask_first(alloc_data.hctx->cpumask); + alloc_data.ctx = __blk_mq_get_ctx(q, cpu); - blk_mq_set_alloc_data(&alloc_data, q, flags, ctx, hctx); - rq = __blk_mq_alloc_request(&alloc_data, rw); - if (!rq) { - ret = -EWOULDBLOCK; - goto out_queue_exit; - } - - return rq; + rq = blk_mq_sched_get_request(q, NULL, rw, &alloc_data); -out_queue_exit: + blk_mq_put_ctx(alloc_data.ctx); blk_queue_exit(q); - return ERR_PTR(ret); + + if (!rq) + return ERR_PTR(-EWOULDBLOCK); + + return rq; } EXPORT_SYMBOL_GPL(blk_mq_alloc_request_hctx);