Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3860375pxb; Tue, 17 Nov 2020 05:36:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8YRNDCGMr/IxNRSsJVESp/Q0T4nTY1A+onclyTqW+TuTrl7I8ZECxSMI80plsJ9PeUBZ0 X-Received: by 2002:a17:906:4104:: with SMTP id j4mr20053682ejk.439.1605620198292; Tue, 17 Nov 2020 05:36:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605620198; cv=none; d=google.com; s=arc-20160816; b=v2JNnIzGiojeKcbOlPizA0At8/98Gjf38ojUdlN2bBev0oS1mUmXWZrP1pzhoqz40G +mIFDFgPzHHdnV1VmxFxtFjfshM7q9SaePsyFhaMY9NxHmjhhkdBN50Ml1mOMecxajQR bG35oQewRk8/ZWARXVSoJC3TVgdsN0vL+EZSy0kNX+55wK6oTsxsDWr6OVLjCKI85BOz bm1B8+IbktwR8yvz8C4YKZrTEzIKFJPTnaHUf1wb4PSui6NQEoGtfP2Sn0UxvZEGOnFc udDCQ6AeyVG8CfxB7V/xb7OkEwooy46gGkFcmX6wMFoJZpl99yjZze69NRgefmR/S91D 1u/w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TRFQiodDV1Bt+kAtPJqRg7MOYSYmGqmBZsF0fl/DDp4=; b=uSzVU7FhISeGcDn0TEZ98KEanJPVBZkNaJr+1I3dvfWkjuXcrqEPle/jDVYfrXnzYH aNyCvZaT94eV3CRSFFkuHJzn5SG7Ae3hlicvc1ErqPQbI995o+3k6rszTDUpoMLmAZvJ QRmNMI/FJ1NXS6AUrRfBjBR5d+LFAsoMMxwp9LDIoh58mxqZaCWfNgoH3/+dGZZJwVnG wS+tbT5rjnEdLtHzohm0hGPWEo1L7Vp/BeIXViq2EcmZnU85yLkMOCbwXXtaEkfyVIul YGHX6ghJaIWuDIrvLcEJHAcU2gjL74uJvjWLSU2c3ibnW+SCCo86AMkkwbg4uBMt60Hg ZwdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CZ8b1ODl; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b13si952393edt.209.2020.11.17.05.36.15; Tue, 17 Nov 2020 05:36:38 -0800 (PST) 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=CZ8b1ODl; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732266AbgKQNew (ORCPT + 99 others); Tue, 17 Nov 2020 08:34:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:45294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731584AbgKQNep (ORCPT ); Tue, 17 Nov 2020 08:34:45 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5CE8C246A5; Tue, 17 Nov 2020 13:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620086; bh=6IoiOFJUKOcUhztuRrXe9uOyWyzAOJU/nq/G7DDNUvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZ8b1ODlCHswM3ZpSdSe2geZYr/Ge8rI+6m8vhutbPIh6LLgFegLrEGaZGfdcj0wA kQlU1sKoSGINa6pVV3MQdQEmK2A32nQj5dfgdVL4aKewqDoRMEmflFEkKVy3W1H3El 7QDDCaXZwEW/kNEfIK4v/g5VeLOQSxXiSn660XLA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "B.L. Jones" , Keith Busch , Sasha Levin Subject: [PATCH 5.9 103/255] Revert "nvme-pci: remove last_sq_tail" Date: Tue, 17 Nov 2020 14:04:03 +0100 Message-Id: <20201117122143.971355832@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Keith Busch [ Upstream commit 38210800bf66d7302da1bb5b624ad68638da1562 ] Multiple CPUs may be mapped to the same hctx, allowing mulitple submission contexts to attempt commit_rqs(). We need to verify we're not writing the same doorbell value multiple times since that's a spec violation. Revert commit 54b2fcee1db041a83b52b51752dade6090cf952f. Link: https://bugzilla.redhat.com/show_bug.cgi?id=1878596 Reported-by: "B.L. Jones" Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/pci.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 8984796db0c80..a6af96aaa0eb7 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -198,6 +198,7 @@ struct nvme_queue { u32 q_depth; u16 cq_vector; u16 sq_tail; + u16 last_sq_tail; u16 cq_head; u16 qid; u8 cq_phase; @@ -455,11 +456,24 @@ static int nvme_pci_map_queues(struct blk_mq_tag_set *set) return 0; } -static inline void nvme_write_sq_db(struct nvme_queue *nvmeq) +/* + * Write sq tail if we are asked to, or if the next command would wrap. + */ +static inline void nvme_write_sq_db(struct nvme_queue *nvmeq, bool write_sq) { + if (!write_sq) { + u16 next_tail = nvmeq->sq_tail + 1; + + if (next_tail == nvmeq->q_depth) + next_tail = 0; + if (next_tail != nvmeq->last_sq_tail) + return; + } + if (nvme_dbbuf_update_and_check_event(nvmeq->sq_tail, nvmeq->dbbuf_sq_db, nvmeq->dbbuf_sq_ei)) writel(nvmeq->sq_tail, nvmeq->q_db); + nvmeq->last_sq_tail = nvmeq->sq_tail; } /** @@ -476,8 +490,7 @@ static void nvme_submit_cmd(struct nvme_queue *nvmeq, struct nvme_command *cmd, cmd, sizeof(*cmd)); if (++nvmeq->sq_tail == nvmeq->q_depth) nvmeq->sq_tail = 0; - if (write_sq) - nvme_write_sq_db(nvmeq); + nvme_write_sq_db(nvmeq, write_sq); spin_unlock(&nvmeq->sq_lock); } @@ -486,7 +499,8 @@ static void nvme_commit_rqs(struct blk_mq_hw_ctx *hctx) struct nvme_queue *nvmeq = hctx->driver_data; spin_lock(&nvmeq->sq_lock); - nvme_write_sq_db(nvmeq); + if (nvmeq->sq_tail != nvmeq->last_sq_tail) + nvme_write_sq_db(nvmeq, true); spin_unlock(&nvmeq->sq_lock); } @@ -1496,6 +1510,7 @@ static void nvme_init_queue(struct nvme_queue *nvmeq, u16 qid) struct nvme_dev *dev = nvmeq->dev; nvmeq->sq_tail = 0; + nvmeq->last_sq_tail = 0; nvmeq->cq_head = 0; nvmeq->cq_phase = 1; nvmeq->q_db = &dev->dbs[qid * 2 * dev->db_stride]; -- 2.27.0