Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3440919pxk; Mon, 28 Sep 2020 18:33:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypqIQOM7R157Op8Mkp2WkSZ4Ydkb6oinH1VY+HAou1l8BDUtJb4mKzxl5kpG8rztstEL/r X-Received: by 2002:a17:906:3c47:: with SMTP id i7mr1472480ejg.554.1601343216967; Mon, 28 Sep 2020 18:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601343216; cv=none; d=google.com; s=arc-20160816; b=JWdFYkzjP+8XkjyJIIS3JAoYmTRitg5CzgENUbKRUp0KdkvozKyXe+OIcn/8MKkTAs kwhEKSASBsP0YgxoAz+PSm/N2yz9jsdWunOBRpucI1WsMFAozKKsufyMsq8rwCcIBJX3 D67YhDl99zv23UclNI+dIhk3WIdaU3FrP9TYgy5SFWkSX1TWCbgwY5TxuGZhPWdksdli /e/KzTqAVx0elWADstJKrvuuS+W1Oq604tyx2ZGBuy4CwK91GNhGZnh302WnIFw5xSF7 iGFR4SmBlCBxcBXs+6CgtAvNg/e5rZ9svW2BMH3y2zbgzCkS2kO655YpAyaQwlobnPqj WJkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lkhIsC6zn+Dn2WgtBfmdv0kj5kcf0+GQPXrnDOFx7Sc=; b=Nt9Ty0pw6filLKgRDZ8AfZJacRkm33VKAoWvI5h47aYruzmAhZJy4GSiqr1ygk2WR5 Vo6IHfb02MoRX43hVmWUUdT3HUJwpkI6Q0qz/7PsCqCjqtM/cwWveYVmlSHqUzjCqG1o 3NimXJE/amBWCPG2EqSBgw2ttkQXgaPwgMIB+qqtiklb6jTYHWR8TGCmzgS/2d+asmx3 TNfn9Y85RR6P1u9amPSqQslrwRXAu+7VDIz506UXTrAnhpxZoup2lvbCB0tOsgR9wX1g vjk+5HD8HcQjhrhysVYYVBOBxn2/XEYwWfxaOv/fHhkw7b6urKqOW37jdcXz5VIcpI60 e5qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WYkzoyBc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n15si1759158edy.300.2020.09.28.18.33.08; Mon, 28 Sep 2020 18:33:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WYkzoyBc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727591AbgI2BbV (ORCPT + 99 others); Mon, 28 Sep 2020 21:31:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:40114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727410AbgI2BbB (ORCPT ); Mon, 28 Sep 2020 21:31:01 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DF2EE216C4; Tue, 29 Sep 2020 01:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601343060; bh=m8yyWdT17sxwA4pTD6kXD50OTjR8orcJ4BiXJpbqZAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WYkzoyBcyzw7/oUVGksf/HHaiD73FNOvm3M4iMhq3Jvj93XtB1v78jO9Hv5WTQMwL gxBQsgK2i5I/dzc/UorKlYJw8BBXMZ/1lzDeKPlXztD8LemyvW7866ZQDm9jTiYlvV IL5bvwzhdwhPZNrTMu7xQIocPmd6Eoc69hQrn2oA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xianting Tian , Keith Busch , Christoph Hellwig , Sasha Levin , linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 5.8 26/29] nvme-pci: fix NULL req in completion handler Date: Mon, 28 Sep 2020 21:30:23 -0400 Message-Id: <20200929013027.2406344-26-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200929013027.2406344-1-sashal@kernel.org> References: <20200929013027.2406344-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xianting Tian [ Upstream commit 50b7c24390a53c78de546215282fb52980f1d7b7 ] Currently, we use nvmeq->q_depth as the upper limit for a valid tag in nvme_handle_cqe(), it is not correct. Because the available tag number is recorded in tagset, which is not equal to nvmeq->q_depth. The nvme driver registers interrupts for queues before initializing the tagset, because it uses the number of successful request_irq() calls to configure the tagset parameters. This allows a race condition with the current tag validity check if the controller happens to produce an interrupt with a corrupted CQE before the tagset is initialized. Replace the driver's indirect tag check with the one already provided by the block layer. Signed-off-by: Xianting Tian Reviewed-by: Keith Busch Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/pci.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 90346cba87d1e..cc3ae9c63a01b 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -942,13 +942,6 @@ static inline void nvme_handle_cqe(struct nvme_queue *nvmeq, u16 idx) struct nvme_completion *cqe = &nvmeq->cqes[idx]; struct request *req; - if (unlikely(cqe->command_id >= nvmeq->q_depth)) { - dev_warn(nvmeq->dev->ctrl.device, - "invalid id %d completed on queue %d\n", - cqe->command_id, le16_to_cpu(cqe->sq_id)); - return; - } - /* * AEN requests are special as they don't time out and can * survive any kind of queue freeze and often don't respond to @@ -962,6 +955,13 @@ static inline void nvme_handle_cqe(struct nvme_queue *nvmeq, u16 idx) } req = blk_mq_tag_to_rq(nvme_queue_tagset(nvmeq), cqe->command_id); + if (unlikely(!req)) { + dev_warn(nvmeq->dev->ctrl.device, + "invalid id %d completed on queue %d\n", + cqe->command_id, le16_to_cpu(cqe->sq_id)); + return; + } + trace_nvme_sq(req, cqe->sq_head, nvmeq->sq_tail); nvme_end_request(req, cqe->status, cqe->result); } -- 2.25.1