From patchwork Sat Nov 6 12:10:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 1551661 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=AJabNxfF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hmbnk4dF6z9t0G for ; Sat, 6 Nov 2021 23:11:21 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mjKXR-0005df-Fe; Sat, 06 Nov 2021 12:11:13 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mjKXN-0005be-1V for kernel-team@lists.ubuntu.com; Sat, 06 Nov 2021 12:11:09 +0000 Received: from HP-EliteBook-840-G7.. (1-171-213-210.dynamic-ip.hinet.net [1.171.213.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id BF9AB3F1B4 for ; Sat, 6 Nov 2021 12:11:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1636200668; bh=MZ0/EqPdZExXKdCUs+Myu1RKpK0wzmwWxTHVZt6+5fM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AJabNxfFSdbgROzmBhpAq2PiTILx3ENLyo6snJIKSiH+/8g9/Wr9TdxpvJb93vdDk DIKEp0PPgpTpzqveb/zhG696h4QX5TuOrwk6e67QRZ7Bh3NOU/itEAkfUY4cbO9zRG TPWsmkN92QSx4Blhvv0UXCAboQBV8yhfa0LL/zsGFMXGQhyELnE8nk1hgu8eN0hWLC Sk8WhJ7QyNyPC9d9m9E71RLkaYVdrouw3sUe07Wb94OURAlzQb6KaB6kLC51JD7tBP o0gbioR5LB7dr+q6GxxMBaH6bp8DIJi7Iq1e/B088vzLxXgBc/uhnjPGyHdJY7V5gR Hx+9xBYwi0R3g== From: Kai-Heng Feng To: kernel-team@lists.ubuntu.com Subject: [H/I/OEM-5.10/OEM-5.13/OEM-5.14] [PATCH 3/4] nvme-pci: disable hmb on idle suspend Date: Sat, 6 Nov 2021 20:10:57 +0800 Message-Id: <20211106121058.1843173-4-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211106121058.1843173-1-kai.heng.feng@canonical.com> References: <20211106121058.1843173-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Keith Busch BugLink: https://bugs.launchpad.net/bugs/1950042 An idle suspend may or may not disable host memory access from devices placed in low power mode. Either way, it should always be safe to disable the host memory buffer prior to entering the low power mode, and this should also always be faster than a full device shutdown. Signed-off-by: Keith Busch Reviewed-by: Sagi Grimberg Signed-off-by: Christoph Hellwig (cherry picked from commit e5ad96f388b765fe6b52f64f37e910c0ba4f3de7) Signed-off-by: Kai-Heng Feng --- drivers/nvme/host/pci.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 3d734e60f2146..ee7ef813fb18a 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -3091,8 +3091,13 @@ static int nvme_resume(struct device *dev) if (ndev->last_ps == U32_MAX || nvme_set_power_state(ctrl, ndev->last_ps) != 0) - return nvme_try_sched_reset(&ndev->ctrl); + goto reset; + if (ctrl->hmpre && nvme_setup_host_mem(ndev)) + goto reset; + return 0; +reset: + return nvme_try_sched_reset(ctrl); } static int nvme_suspend(struct device *dev) @@ -3116,15 +3121,9 @@ static int nvme_suspend(struct device *dev) * the PCI bus layer to put it into D3 in order to take the PCIe link * down, so as to allow the platform to achieve its minimum low-power * state (which may not be possible if the link is up). - * - * If a host memory buffer is enabled, shut down the device as the NVMe - * specification allows the device to access the host memory buffer in - * host DRAM from all power states, but hosts will fail access to DRAM - * during S3. */ if (pm_suspend_via_firmware() || !ctrl->npss || !pcie_aspm_enabled(pdev) || - ndev->nr_host_mem_descs || (ndev->ctrl.quirks & NVME_QUIRK_SIMPLE_SUSPEND)) return nvme_disable_prepare_reset(ndev, true); @@ -3135,6 +3134,17 @@ static int nvme_suspend(struct device *dev) if (ctrl->state != NVME_CTRL_LIVE) goto unfreeze; + /* + * Host memory access may not be successful in a system suspend state, + * but the specification allows the controller to access memory in a + * non-operational power state. + */ + if (ndev->hmb) { + ret = nvme_set_host_mem(ndev, 0); + if (ret < 0) + goto unfreeze; + } + ret = nvme_get_power_state(ctrl, &ndev->last_ps); if (ret < 0) goto unfreeze;