From patchwork Tue Jun 7 23:21:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lin X-Patchwork-Id: 9162807 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 1927260467 for ; Tue, 7 Jun 2016 23:22:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0993128360 for ; Tue, 7 Jun 2016 23:22:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1F9E2836C; Tue, 7 Jun 2016 23:21:59 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 8575D28360 for ; Tue, 7 Jun 2016 23:21:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751657AbcFGXV6 (ORCPT ); Tue, 7 Jun 2016 19:21:58 -0400 Received: from mail.kernel.org ([198.145.29.136]:49306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751433AbcFGXV6 (ORCPT ); Tue, 7 Jun 2016 19:21:58 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C45CB20256; Tue, 7 Jun 2016 23:21:56 +0000 (UTC) Received: from mail-vk0-f52.google.com (mail-vk0-f52.google.com [209.85.213.52]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 344862024F; Tue, 7 Jun 2016 23:21:55 +0000 (UTC) Received: by mail-vk0-f52.google.com with SMTP id e4so128070304vkb.1; Tue, 07 Jun 2016 16:21:55 -0700 (PDT) X-Gm-Message-State: ALyK8tLmL0wuvfndX5Lu2W1L+5IsL9PQnYqdC4ecc4vNy7swjqJvhQtenaQ7gbNRC44Tmvs/Xh9+IhJgciNJBA== X-Received: by 10.176.3.176 with SMTP id 45mr956324uau.20.1465341714424; Tue, 07 Jun 2016 16:21:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.97.131 with HTTP; Tue, 7 Jun 2016 16:21:53 -0700 (PDT) In-Reply-To: References: <1465248119-17875-1-git-send-email-hch@lst.de> <1465248119-17875-2-git-send-email-hch@lst.de> <20160607145736.GB28414@localhost.localdomain> From: Ming Lin Date: Tue, 7 Jun 2016 16:21:53 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/8] blk-mq: add blk_mq_alloc_request_hctx To: Keith Busch Cc: Christoph Hellwig , Jens Axboe , linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, lkml X-Virus-Scanned: ClamAV using ClamSMTP 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 On Tue, Jun 7, 2016 at 8:27 AM, Ming Lin wrote: > On Tue, Jun 7, 2016 at 7:57 AM, Keith Busch wrote: >> On Mon, Jun 06, 2016 at 11:21:52PM +0200, Christoph Hellwig wrote: >>> +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 request *rq; >>> + struct blk_mq_alloc_data alloc_data; >>> + int ret; >>> + >>> + ret = blk_queue_enter(q, flags & BLK_MQ_REQ_NOWAIT); >>> + if (ret) >>> + return ERR_PTR(ret); >>> + >>> + hctx = q->queue_hw_ctx[hctx_idx]; >> >> We probably want to check 'if (hctx_idx < q->nr_hw_queues)' before >> getting the hctx. Even if hctx_idx was origially valid, it's possible >> (though unlikely) blk_queue_enter waits on reallocating h/w contexts, >> which can make hctx_idx invalid. > > Yes, I'll update it. How about this? --- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/block/blk-mq.c b/block/blk-mq.c index 7bb45ed..b59d2ef 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -279,6 +279,11 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, int rw, if (ret) return ERR_PTR(ret); + if (hctx_idx >= q->nr_hw_queues) { + blk_queue_exit(q); + return ERR_PTR(-EINVAL); + } + hctx = q->queue_hw_ctx[hctx_idx]; ctx = __blk_mq_get_ctx(q, cpumask_first(hctx->cpumask));