Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96170EB64D9 for ; Thu, 15 Jun 2023 11:38:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WQxaNTXTQ3IhQFkLOlRWarw51mUd3sVA+fVqyiO0nlo=; b=xHbnA0Ued+PLeIEZPMxKMyXRF4 +2XBVYUaRuK1pm8NkTXmVbhqcblOf9/ParH1vN2Pt5hGbi0s3ymuGEOInAQW9NUdDUaIHdAR1Dblr lG77bcjDsIyJJaI+3j3RZ7dqeWHunl//qeV89vM5oa8wHvW21X6fI4ZHN+PeSSFp1+/nMh1VoQs/R ao7sPioDwAyofT1hlKtXLEoS3QXZUWY1UKhPLj8cuu5dN2vC0RzOWz1fgbu6WNaLJMY3C7mHp726t n7y6yzq/kmiXn3eNKfopx0y21J+r+xyEWD0zzBECt1wNMYNBcEv/G0T9sTJkoqj1yfbjpK4sScmvg C/+t654Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q9lIx-00EitE-1D; Thu, 15 Jun 2023 11:38:19 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q9lIu-00Eiqm-16 for linux-nvme@lists.infradead.org; Thu, 15 Jun 2023 11:38:18 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C5FF063997; Thu, 15 Jun 2023 11:38:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DCCBC433CA; Thu, 15 Jun 2023 11:38:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686829095; bh=XxmzxDZqACOJxTnnJBLfFBB1rRaXqRw7sseUDDnG8SU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bj75w/ugFtV5GxEoskCDapb6zsbiqXYhPlcK7Jobk4KF6Ggciumm1TRqXL5smZGP5 OoL9yZ/BCxItkM0vekJvxQR2N9suUGvIClMYblM6peoWh+4GrAwk3wv0tE7XPAwmW6 w00zrSjYrISq6YPYVuPQsVIf5bpay7krrpQnSZtrccBCDv/u0jMk0dbLX8C+6VgieV QeZu+/Bu4lmH+SNuwVXrp3l+Hosu/qDmKMN7bgRhrVIdMIqHL71kXMr1w8emSM1tKh B9rdLm9whRDRSynO9T/cgjaoholCCMPI6f4rTaA8ZUm9NDCavLYxzexexTz0kkbaLG HHL9/OL8XYujw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Uday Shankar , Costa Sapuntzakis , Randy Jennings , Hannes Reinecke , Christoph Hellwig , Keith Busch , Sasha Levin , sagi@grimberg.me, linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 6.3 19/19] nvme: improve handling of long keep alives Date: Thu, 15 Jun 2023 07:37:19 -0400 Message-Id: <20230615113719.648862-19-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230615113719.648862-1-sashal@kernel.org> References: <20230615113719.648862-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.3.8 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230615_043816_455213_569D3456 X-CRM114-Status: GOOD ( 16.57 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org From: Uday Shankar [ Upstream commit c7275ce6a5fd32ca9f5a6294ed89cf0523181af9 ] Upon keep alive completion, nvme_keep_alive_work is scheduled with the same delay every time. If keep alive commands are completing slowly, this may cause a keep alive timeout. The following trace illustrates the issue, taking KATO = 8 and TBKAS off for simplicity: 1. t = 0: run nvme_keep_alive_work, send keep alive 2. t = ε: keep alive reaches controller, controller restarts its keep alive timer 3. t = 4: host receives keep alive completion, schedules nvme_keep_alive_work with delay 4 4. t = 8: run nvme_keep_alive_work, send keep alive Here, a keep alive having RTT of 4 causes a delay of at least 8 - ε between the controller receiving successive keep alives. With ε small, the controller is likely to detect a keep alive timeout. Fix this by calculating the RTT of the keep alive command, and adjusting the scheduling delay of the next keep alive work accordingly. Reported-by: Costa Sapuntzakis Reported-by: Randy Jennings Signed-off-by: Uday Shankar Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 1f66ba634e9c3..d3c3dbed30b37 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1199,6 +1199,20 @@ static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq, struct nvme_ctrl *ctrl = rq->end_io_data; unsigned long flags; bool startka = false; + unsigned long rtt = jiffies - (rq->deadline - rq->timeout); + unsigned long delay = nvme_keep_alive_work_period(ctrl); + + /* + * Subtract off the keepalive RTT so nvme_keep_alive_work runs + * at the desired frequency. + */ + if (rtt <= delay) { + delay -= rtt; + } else { + dev_warn(ctrl->device, "long keepalive RTT (%u ms)\n", + jiffies_to_msecs(rtt)); + delay = 0; + } blk_mq_free_request(rq); @@ -1217,7 +1231,7 @@ static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq, startka = true; spin_unlock_irqrestore(&ctrl->lock, flags); if (startka) - nvme_queue_keep_alive_work(ctrl); + queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); return RQ_END_IO_NONE; } -- 2.39.2