Message ID | 20230114-apple-nvme-suspend-fixes-v6.2-v2-1-9157bf633dba@jannau.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1949563wrn; Tue, 17 Jan 2023 11:48:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXuQZmezJdDM73nrTkyNFjprxbYJAEEBlF1xG2ZexsVAmsMJdImPrQe6vvkP9DYNcvBlEGD+ X-Received: by 2002:a05:6402:f07:b0:493:b55d:d7f2 with SMTP id i7-20020a0564020f0700b00493b55dd7f2mr5142287eda.14.1673984880582; Tue, 17 Jan 2023 11:48:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673984880; cv=none; d=google.com; s=arc-20160816; b=w9Ho0CCOJqig5fBeoUi6gBAD32sBSTR8rZ20QqsZCuPV7p+DgDA1xzKRbDXf6IVzcM VEMYAwCNmvtsnhxMMM6Q6fm3Pm9xWE0aPsDynTQuy8UNUX3P3rlRSMr/x9xj0slR/0jF r9Tp90Dn8WQSd7CHpYHTVJtguZwOTU/pgsaOliVocfHRbaxaDs8BXXvM8wcVHJXEOKsS 7b0F+8KmwBj+Fee3UA5FM1b80o1bASl+mCAuiWJkgESYRFJ8ethrFAvS59pKgCydP3dL JrmPaMNyg7neJx7w58p4G53HxCGrlfF15SV3wVi9SMirWfvsTiMHQmJZLy8xagYeUeC3 fwsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from; bh=abIp5L/7cP7iZb2NyZveklX6YFbUXJaTfBX8+huge1A=; b=0XNLGvEmAJpCbh/A9z2orKdA+oTntZ2ptlnc7c6odmhs1k42YUgsdVBr8iSjCkmdIv +4uOXAXyk8Eli2AmkV25awlsEpoQ8W+ppCAqb2YoqoZO6lrcGgS46NiVtZDzJaAyf3t0 mNu8uV2sMvLvQWS8JKvmXV7qWMOIz+krUgbmLGXI6U2J8dPeukBT33MeV0u6BO81e2ah 47HxCOmEB5tUjmC/63D3Wvkg0cbg+1ow6+IZO/cluQZV//ogR+HMyM0KObi/2fTNYMIC 1ihA+P0YuOjuceLuLvH9/BGi+N9IxtbjaCzR5TWO5wFFzLZnghvR5tc7nm7bilWHAjOu CdQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m23-20020aa7c497000000b004812e6f2d97si10145100edq.537.2023.01.17.11.47.37; Tue, 17 Jan 2023 11:48:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232528AbjAQTdV (ORCPT <rfc822;pfffrao@gmail.com> + 99 others); Tue, 17 Jan 2023 14:33:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232702AbjAQT03 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 17 Jan 2023 14:26:29 -0500 Received: from soltyk.jannau.net (soltyk.jannau.net [144.76.91.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F082047429 for <linux-kernel@vger.kernel.org>; Tue, 17 Jan 2023 10:34:18 -0800 (PST) Received: from robin.home.jannau.net (p579ad32f.dip0.t-ipconnect.de [87.154.211.47]) by soltyk.jannau.net (Postfix) with ESMTPSA id 7FEC926F670; Tue, 17 Jan 2023 19:25:02 +0100 (CET) From: Janne Grunau <j@jannau.net> Date: Tue, 17 Jan 2023 19:25:00 +0100 Subject: [PATCH v2 1/2] nvme-apple: Reset controller during shutdown MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230114-apple-nvme-suspend-fixes-v6.2-v2-1-9157bf633dba@jannau.net> References: <20230114-apple-nvme-suspend-fixes-v6.2-v2-0-9157bf633dba@jannau.net> In-Reply-To: <20230114-apple-nvme-suspend-fixes-v6.2-v2-0-9157bf633dba@jannau.net> To: Hector Martin <marcan@marcan.st>, Sven Peter <sven@svenpeter.dev>, Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@fb.com>, Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me> Cc: Alyssa Rosenzweig <alyssa@rosenzweig.io>, Eric Curtin <ecurtin@redhat.com>, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Janne Grunau <j@jannau.net> X-Mailer: b4 0.11.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1570; i=j@jannau.net; h=from:subject:message-id; bh=qtyorAlxkkMT/6LLYB1Bf2sjPkpsduWNqrw5l5ng7OU=; b=owGbwMvMwCG2UNrmdq9+ahrjabUkhuRjz//une7jdPHspxsXz4QpX9JqNW8ofLKt7PmpS3uFL4W2 pp5J6ChlYRDjYJAVU2RJ0n7ZwbC6RjGm9kEYzBxWJpAhDFycAjCRp1MZ/kd5BHDxrL5lGKkQLbzupt leg5POL7XC/xQ81XglfsEjewojw7qzBjVf5V6eXtwT5vDAJuO4wuKne1/GtrmEbnK+e63+PgcA X-Developer-Key: i=j@jannau.net; a=openpgp; fpr=8B336A6BE4E5695E89B8532B81E806F586338419 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755300369689121843?= X-GMAIL-MSGID: =?utf-8?q?1755300369689121843?= |
Series |
nvme-apple: Fix suspend-resume regression
|
|
Commit Message
Janne Grunau
Jan. 17, 2023, 6:25 p.m. UTC
This is a functional revert of c76b8308e4c9 ("nvme-apple: fix controller
shutdown in apple_nvme_disable").
The commit broke suspend/resume since apple_nvme_reset_work() tries to
disable the controller on resume. This does not work for the apple NVMe
controller since register access only works while the co-processor
firmware is running.
Disabling the NVMe controller in the shutdown path is also required
for shutting the co-processor down. The original code was appropriate
for this hardware. Add a comment to prevent a similar breaking changes
in the future.
Fixes: c76b8308e4c9 ("nvme-apple: fix controller shutdown in apple_nvme_disable")
Reported-by: Janne Grunau <j@jannau.net>
Link: https://lore.kernel.org/all/20230110174745.GA3576@jannau.net/
Signed-off-by: Janne Grunau <j@jannau.net>
---
drivers/nvme/host/apple.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
Comments
On Tue, Jan 17, 2023 at 07:25:00PM +0100, Janne Grunau wrote: > + /* > + * Always reset the NVMe controller on shutdown. The reset is > + * required to shutdown the co-processor cleanly. > + */ Hmm. This comment doesn't seem to match the discussion we had last week. Which would be: /* * NVMe requires a reset before setting up a controller to * ensure it is in a clean state. For NVMe PCIe this is * done in the setup path to be able to deal with controllers * in any kind of state. For for Apple devices, the firmware * will not be available at that time and the reset will * time out. Thus reset after shutting the NVMe controller * down and before shutting the firmware down. */
Folks, can you chime in if this comment makes sense? I'd really like to send the patches off to Jens before rc5. On Wed, Jan 18, 2023 at 06:24:50AM +0100, Christoph Hellwig wrote: > On Tue, Jan 17, 2023 at 07:25:00PM +0100, Janne Grunau wrote: > > + /* > > + * Always reset the NVMe controller on shutdown. The reset is > > + * required to shutdown the co-processor cleanly. > > + */ > > Hmm. This comment doesn't seem to match the discussion we had last > week. Which would be: > > /* > * NVMe requires a reset before setting up a controller to > * ensure it is in a clean state. For NVMe PCIe this is > * done in the setup path to be able to deal with controllers > * in any kind of state. For for Apple devices, the firmware > * will not be available at that time and the reset will > * time out. Thus reset after shutting the NVMe controller > * down and before shutting the firmware down. > */ ---end quoted text---
Hej, On 2023-01-18 06:24:50 +0100, Christoph Hellwig wrote: > On Tue, Jan 17, 2023 at 07:25:00PM +0100, Janne Grunau wrote: > > + /* > > + * Always reset the NVMe controller on shutdown. The reset is > > + * required to shutdown the co-processor cleanly. > > + */ > > Hmm. This comment doesn't seem to match the discussion we had last > week. Which would be: > > /* > * NVMe requires a reset before setting up a controller to > * ensure it is in a clean state. For NVMe PCIe this is > * done in the setup path to be able to deal with controllers > * in any kind of state. For for Apple devices, the firmware > * will not be available at that time and the reset will > * time out. Thus reset after shutting the NVMe controller > * down and before shutting the firmware down. > */ yes, it differs from the discussion last week. I tried to issue the reset later in the setup path after the firmware was brought back up. That fixes the hang but the device is still not useable. So it appears we need to reset the controller before the firmware is shutdown. Janne
(Replying from mobile, please excuse formatting) I'm actually not sure exactly how this works any more. The previous series I sent (which had slightly different logic) worked for me on a t8103 Mac Mini in smoke tests and I'd assumed fixed the issue, but it turned out to fail (in a different way) on other machines/circumstances. This one seems to work everywhere, but I can't explain exactly why. Maybe we do in fact need to issue an NVMe disable before shutting down the firmware to reliably come up properly on firmware restart. Maybe something like this? /* * Always disable the NVMe controller after shutdown. * We need to do this to bring it back up later anyway, * and we can't do it while the firmware is not running * (e.g. in the resume reset path before RTKit is * initialized), so for Apple controllers it makes sense to * unconditionally do it here. Additionally, this sequence * of events is reliable, while others (like disabling after * bringing back the firmware on resume) seem to run * into trouble under some circumstances. * * Both U-Boot and m1n1 also use this convention * (i.e. an ANS NVMe controller is handed off with * firmware shut down, in an NVMe disabled state, * after a clean shutdown). */ On 2023年1月19日 15:14:52 JST, Christoph Hellwig <hch@lst.de> wrote: >Folks, can you chime in if this comment makes sense? I'd really >like to send the patches off to Jens before rc5. > >On Wed, Jan 18, 2023 at 06:24:50AM +0100, Christoph Hellwig wrote: >> On Tue, Jan 17, 2023 at 07:25:00PM +0100, Janne Grunau wrote: >> > + /* >> > + * Always reset the NVMe controller on shutdown. The reset is >> > + * required to shutdown the co-processor cleanly. >> > + */ >> >> Hmm. This comment doesn't seem to match the discussion we had last >> week. Which would be: >> >> /* >> * NVMe requires a reset before setting up a controller to >> * ensure it is in a clean state. For NVMe PCIe this is >> * done in the setup path to be able to deal with controllers >> * in any kind of state. For for Apple devices, the firmware >> * will not be available at that time and the reset will >> * time out. Thus reset after shutting the NVMe controller >> * down and before shutting the firmware down. >> */ >---end quoted text--- >
Thanks, this looks good. Updated commit here: http://git.infradead.org/nvme.git/commitdiff/c06ba7b892a50b48522ad441a40053f483dfee9e
On 2023-01-19 09:08:39 +0100, Christoph Hellwig wrote: > Thanks, this looks good. Updated commit here: > > http://git.infradead.org/nvme.git/commitdiff/c06ba7b892a50b48522ad441a40053f483dfee9e looks good to me as well. thanks Janne
diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index bf1c60edb7f9..2a1f11b30615 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -829,7 +829,13 @@ static void apple_nvme_disable(struct apple_nvme *anv, bool shutdown) apple_nvme_remove_cq(anv); } - nvme_disable_ctrl(&anv->ctrl, shutdown); + /* + * Always reset the NVMe controller on shutdown. The reset is + * required to shutdown the co-processor cleanly. + */ + if (shutdown) + nvme_disable_ctrl(&anv->ctrl, shutdown); + nvme_disable_ctrl(&anv->ctrl, false); } WRITE_ONCE(anv->ioq.enabled, false);