From patchwork Tue Feb 11 18:25:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alyssa Rosenzweig X-Patchwork-Id: 13970471 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 16F3FC0219B for ; Tue, 11 Feb 2025 18:39:35 +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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Nh4p/vkoe1IUhU0kNW+lsCY3zF9KIL8HN2NY6NLEHFk=; b=KtPj/7u8B+IqyX+2IqLrR50qd6 e0A/+2oYeC93p9ANpFz0NfTS6BPUxVwhbxErL/s7kKlUN/B6wu8gcbhUm3XIW233UgC8zc+bk4MyT pCYaK0Ei5fB/fKe2EUgg8u2HIC+/uDvboSDjx7mfzrwbAmj5oMEVsgbJYJPy2INOdLimhYHW1c7KH TdOinF/oFJ9KxMsBWNtNhdpYzMzs/De7E9Vw1B13EY3AXlN+5xSWofGhxqJMu6itJGQsmJ0kWzSiU KZMtOjzP6dtVq6J5xAMvkfmCPY4WRsc9p9QYRHB2DZ8Wkt37afQNaDnEo8kdJSQxgcQAg4JtC6Ld8 eMmJYorg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1thvAJ-00000004sCx-404v; Tue, 11 Feb 2025 18:39:23 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1thuxe-00000004q5p-136Q for linux-arm-kernel@bombadil.infradead.org; Tue, 11 Feb 2025 18:26:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=Nh4p/vkoe1IUhU0kNW+lsCY3zF9KIL8HN2NY6NLEHFk=; b=PY5XYaHZWDFRpVdhwY21ky/FKx lsFAnkQLDlN91pP6KCRi3GbYsZM4DpP9wvn9BkSNokZkIHjcUag6LZToyz5P1ufSxP071PhTf/v1q C8t3ncNCR8FxotMFq5TtuGqDBNxQXAuEMC4kIuLyeAfiWPuQAOL6irs6rvdzHRJP0CYNE/Y6/XMJa rzrQVC0AiMsga/rIMubxgByHRsi8pW46XGaZpF8jXUV5E50NQ75jA9etXKxGftPI4C0yCbTP6SsrL 6gTo/KNPrnzq26OAOGqdAEOqN9itho0vjhWm512Wmwvs28iIes5WWKrRseE0LqdZcE0CTsz2OPDMb hSBQ8nyw==; Received: from out-185.mta0.migadu.com ([2001:41d0:1004:224b::b9]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1thuxb-00000000g0K-13DP for linux-arm-kernel@lists.infradead.org; Tue, 11 Feb 2025 18:26:17 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rosenzweig.io; s=key1; t=1739298363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nh4p/vkoe1IUhU0kNW+lsCY3zF9KIL8HN2NY6NLEHFk=; b=vDjaf+wWvTT2dtZEaGODEDZJsVIgTvnYQtaKIxJn4GbTbjrBijwoB5qQfbUhf2sPI1tUY5 GEKhxSP7SKvU8XEhHO8eXPdBYHmh+mZ2UYkRBUuSavkNdWWt1xIveiqsX7sv/qpMFJ9kxm CRuH/IsOXeRGw+YbDpCKPqI7I0SAOFAQX67nmtjaS8xN2mFdNquWtS7/fTyfSa53OYdBB/ /+pM+JIhiFlMxrKTWKHesQprp2ubjhUSymlIoQd/8XaMo4bujL6POhG5d82uhMbYwLHt8M X4WrEt7365IO9iz9GRRuEXx24PDVtKP4fnSq+XJjb7Sm3BxrX7gjsjdSEUclNA== From: Alyssa Rosenzweig Date: Tue, 11 Feb 2025 13:25:57 -0500 Subject: [PATCH 1/3] apple-nvme: Support coprocessors left idle MIME-Version: 1.0 Message-Id: <20250211-nvme-fixes-v1-1-6958b3aa49fe@rosenzweig.io> References: <20250211-nvme-fixes-v1-0-6958b3aa49fe@rosenzweig.io> In-Reply-To: <20250211-nvme-fixes-v1-0-6958b3aa49fe@rosenzweig.io> To: Hector Martin , Sven Peter , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Philipp Zabel Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Alyssa Rosenzweig X-Developer-Signature: v=1; a=openpgp-sha256; l=3914; i=alyssa@rosenzweig.io; h=from:subject:message-id; bh=mqPCDjV0fSRn/nhoe3qxtBUGiudls3umAeMV7A1xI+w=; b=owEBbQKS/ZANAwAIAf7+UFoK9VgNAcsmYgBnq5Y3MY4msd3EKNRZnQIhChthfJmteSkdbuijp khUKHo+m8qJAjMEAAEIAB0WIQRDXuCbsK8A0B2q9jj+/lBaCvVYDQUCZ6uWNwAKCRD+/lBaCvVY DUj8EACAF38TFG6b+7PMcQoaejAgCZiZcTG/DnrV7ydUZ4i8628bjueZahLtieUOM8b3U/lYgek DChUb++lo0EhEuTx0jTFATxLtg4dGT7ibBZRNwwZIvLC+BXKxRPaCUqhKTO7eA5YGPVUUAf8ORO ErcnDdc8WsFluYzoB1vUbaf0YRywB7qOlV/f8iIgZdcWEH5uUuh2I8qNi3adfo7igJMjXr5CMNl fhf858j5VdOD0Up3KtXYOwqfQRWUNK1vQGv0gc+ipp933FCKbEG65w5A5MeUp+q96xsTkw8FEqf DIhWnCzjPlA/tJDEvTd9wF4tCywFN7Q6HijhzgOhZAnFExhH/dJmqREB/sTWdgdnHnE0QIf0lpW ULgeAbozpB/+1vHHmzQQxUkbxByFPvKg40Jp1LwyZ2qSayHTOXjCInICSfIWSnJNrNF6eKJyqka oIVTS0MhQPi4UQfl7v3gAqcU1U3kG/qag1QQL65G97aVK5J/Cx25WNkXICzjd1plk2WO5fP6IFX roHzxcZPgODAMJ1GjYaHF+dz9rGgLx8tVfN6sT8PjlahEHQIIIu1eM/BwIJiwAKEqP6EL3BgMy8 y2sPU/g+iUEizOIK97GrcwqBFyZxwsrnVsqb0ydOUC2JlF96pq1LU/rEyn6z2ebx5n3F5Bf/KVq 2ukcrsMB8YB8L4Q== X-Developer-Key: i=alyssa@rosenzweig.io; a=openpgp; fpr=435EE09BB0AF00D01DAAF638FEFE505A0AF5580D X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250211_182615_512787_D1BEEBB0 X-CRM114-Status: GOOD ( 16.83 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Hector Martin iBoot on at least some firmwares/machines leaves ANS2 running, requiring a wake command instead of a CPU boot (and if we reset ANS2 in that state, everything breaks). Only stop the CPU if RTKit was running, and only do the reset dance if the CPU is stopped. Normal shutdown handoff: - RTKit not yet running - CPU detected not running - Reset - CPU powerup - RTKit boot wait ANS2 left running/idle: - RTKit not yet running - CPU detected running - RTKit wake message Sleep/resume cycle: - RTKit shutdown - CPU stopped - (sleep here) - CPU detected not running - Reset - CPU powerup - RTKit boot wait Shutdown or device removal: - RTKit shutdown - CPU stopped Therefore, the CPU running bit serves as a consistent flag of whether the coprocessor is fully stopped or just idle. Signed-off-by: Hector Martin Signed-off-by: Alyssa Rosenzweig --- drivers/nvme/host/apple.c | 53 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index 1de11b722f049abbc96a6bb62b072ac973b8c4aa..5e1c01a67ee81a36faa3da2f86a3a24fefcdfd6f 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -1011,25 +1011,37 @@ static void apple_nvme_reset_work(struct work_struct *work) ret = apple_rtkit_shutdown(anv->rtk); if (ret) goto out; + + writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL); } - writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL); + /* + * Only do the soft-reset if the CPU is not running, which means either we + * or the previous stage shut it down cleanly. + */ + if (!(readl(anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL) & + APPLE_ANS_COPROC_CPU_CONTROL_RUN)) { - ret = reset_control_assert(anv->reset); - if (ret) - goto out; + ret = reset_control_assert(anv->reset); + if (ret) + goto out; - ret = apple_rtkit_reinit(anv->rtk); - if (ret) - goto out; + ret = apple_rtkit_reinit(anv->rtk); + if (ret) + goto out; - ret = reset_control_deassert(anv->reset); - if (ret) - goto out; + ret = reset_control_deassert(anv->reset); + if (ret) + goto out; + + writel(APPLE_ANS_COPROC_CPU_CONTROL_RUN, + anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL); + + ret = apple_rtkit_boot(anv->rtk); + } else { + ret = apple_rtkit_wake(anv->rtk); + } - writel(APPLE_ANS_COPROC_CPU_CONTROL_RUN, - anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL); - ret = apple_rtkit_boot(anv->rtk); if (ret) { dev_err(anv->dev, "ANS did not boot"); goto out; @@ -1563,9 +1575,12 @@ static void apple_nvme_remove(struct platform_device *pdev) apple_nvme_disable(anv, true); nvme_uninit_ctrl(&anv->ctrl); - if (apple_rtkit_is_running(anv->rtk)) + if (apple_rtkit_is_running(anv->rtk)) { apple_rtkit_shutdown(anv->rtk); + writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL); + } + apple_nvme_detach_genpd(anv); } @@ -1574,8 +1589,11 @@ static void apple_nvme_shutdown(struct platform_device *pdev) struct apple_nvme *anv = platform_get_drvdata(pdev); apple_nvme_disable(anv, true); - if (apple_rtkit_is_running(anv->rtk)) + if (apple_rtkit_is_running(anv->rtk)) { apple_rtkit_shutdown(anv->rtk); + + writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL); + } } static int apple_nvme_resume(struct device *dev) @@ -1592,10 +1610,11 @@ static int apple_nvme_suspend(struct device *dev) apple_nvme_disable(anv, true); - if (apple_rtkit_is_running(anv->rtk)) + if (apple_rtkit_is_running(anv->rtk)) { ret = apple_rtkit_shutdown(anv->rtk); - writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL); + writel(0, anv->mmio_coproc + APPLE_ANS_COPROC_CPU_CONTROL); + } return ret; } From patchwork Tue Feb 11 18:25:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alyssa Rosenzweig X-Patchwork-Id: 13970472 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 0EB23C0219B for ; Tue, 11 Feb 2025 18:40:59 +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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=idU4M1eBTyORkzLLKsL5gMIZbBkj9wGw9TueyObtiRQ=; b=WrI+V/Bxnt8Z2s/T1VzAb4K2xc VLyKfVrClW/AwqAyHmfyk+fM0v4iG7VSXyvZ4CarloAhGcAX9gMNm6uMbhJQ5upkK+kPVgqvOtiZA idZvt3dLtp+ahHLTa2ujlH3lWXU8cG4MLPMkELkYxdGuQmEmkfOoOw9/6YsQjOv+r/WW+YCQlT44Q 3ZNy12knd23JJidUB87EN2leHURk3MRgTDXwxU2U50jRQx6Aj0ZHyvtBzscy0A+pbN6q22fmDmjvO nU9A5lKxx0mBjZwi4vI7OR1PBEO1Xm+yhPRE3qJLQWEOS5ce0iCHWoDq3sEzjOF5L92cQbGoYkzFb End/soDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1thvBi-00000004sZT-2yLf; Tue, 11 Feb 2025 18:40:50 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1thuxe-00000004q5q-1nIh; Tue, 11 Feb 2025 18:26:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=idU4M1eBTyORkzLLKsL5gMIZbBkj9wGw9TueyObtiRQ=; b=hfQgGmMp+udMpnacQklpUs0/9S JUh0Ltxu8jZXsr/lla04/YR5J07fd3jK3IATe5ZhyW4JWUh4djgBP9RN9un+jw0UQkiS5EdwjendU BOki+zXOjQhT2FvFep1fdRUz5zN8qDzC+qo8O6D1qClBVECIyqAchdR3PmjX3+T2pxiM8A2hhNUBW FsUZiDZEvJfQaldlTAL6dgMDGChArA7jR1os3asM+p3/aRcwgPwMNltUUJp77Kx64S+LL7vBl75BP eUPjPx7z4io91rZcNWzaGuQL06ehmzUAy+SUZoMcE65O1ALL1LgIYwS+E6yB63VbkKTuNwUfLejLT 7V11U2aw==; Received: from out-175.mta0.migadu.com ([91.218.175.175]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1thuxb-00000000g0L-2OPI; Tue, 11 Feb 2025 18:26:17 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rosenzweig.io; s=key1; t=1739298365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=idU4M1eBTyORkzLLKsL5gMIZbBkj9wGw9TueyObtiRQ=; b=q+ID/jn3SpGNrR3SUWLvrQ/iBKesO0BAR+scpPxJHyo9U/bLZNkvoR2wiqgrU+mdMJ59Na ZUmbuwm6PpcvJpQiobs9PpT+ICpa/ekPnGCRK4cZR1ZTM/cAWkGJtZM5/XDrY+xTv7067X p394CHAcjdF+ANORjQqm2ezYVyDNpDFeWjcdAB222DbzxUURiXEfNTN1R0wKqkK6Thitz0 eAlSRpJgJFmlXOFLhIq1rdOE/ePv0ASsLZQJ0cQ/JkqXWXoB4BlH3HmbLgFYNw/BXiD9g1 MIFYBBCpKuXtXfOxGpSpuEIocoAUvjIpgFZWaGHuaWleU7pCkeinxcGtGmmNxA== From: Alyssa Rosenzweig Date: Tue, 11 Feb 2025 13:25:58 -0500 Subject: [PATCH 2/3] apple-nvme: Release power domains when probe fails MIME-Version: 1.0 Message-Id: <20250211-nvme-fixes-v1-2-6958b3aa49fe@rosenzweig.io> References: <20250211-nvme-fixes-v1-0-6958b3aa49fe@rosenzweig.io> In-Reply-To: <20250211-nvme-fixes-v1-0-6958b3aa49fe@rosenzweig.io> To: Hector Martin , Sven Peter , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Philipp Zabel Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Alyssa Rosenzweig X-Developer-Signature: v=1; a=openpgp-sha256; l=854; i=alyssa@rosenzweig.io; h=from:subject:message-id; bh=8vBQ/v44cM9RurlOEJqS9G0+SOpYh3VTVvP62muKOs8=; b=owEBbQKS/ZANAwAIAf7+UFoK9VgNAcsmYgBnq5Y3JoRTpZggfiWVdYcP0iyVHDJ//MLZ5GLPN 83hIsPuBMeJAjMEAAEIAB0WIQRDXuCbsK8A0B2q9jj+/lBaCvVYDQUCZ6uWNwAKCRD+/lBaCvVY DUD4D/0Sx7sJnd8ickbkui6NuiZpuL2EOI7nalgwVj2PqptKMNPmymjt6QlI0ip1HudADNTfCHW dIyn21enlKeH2lViS94Gb+1EjYNnPGJp96OUvz7ub2LIeNG/SMwfbTSd9Gt1hBXI4CvRk36xk3g FQemoR5vedw+A4sgDRv1Q5j0x397vsGBcHvJcU/jRD6In3AUXAP7buEaUFYQ9ZB69JILR2oUk1/ rc7vMmQLascmkAXlMR7OhCGbpLpR2o3F9FnUf6H6nJ7oi8QaGWe1o8LEd3m4qP5yEoOGzGEq4oK W6b02fzoeE793G73RvH07TZJpAzMxYCJO923p1hD3RSjmsdTmyjtubBKi5eYWPZRGezx+tm7nhm 0ULV7N7OZPrk20ZkiFktC8QPl5Lwz/Jwm0qoYSW7XY9OXiWkprnvcinsP122X9KTXmsEaqOpoG2 vxYCzsr5FK08P97nSpdRIX0vvPTSCrETIOmV7YH6VyCp/5atF80JB2ioeRLDOHLrJyJRqc0RkFi 1J5237GfZdT1fZgLx5dQi+eha80Tqw9lm5P9ctCyfLA8ERvz/Yhh2Qct6wc2rqrTl5pIKt0oo/E Z68lO22qqvvp94ftRBHIIcbMMVj03htBaRcJnRFMYeAGlX3/Z9pmWQM5EYRG2H2BvP04jy1afFa sMW2SrdBa7ltplA== X-Developer-Key: i=alyssa@rosenzweig.io; a=openpgp; fpr=435EE09BB0AF00D01DAAF638FEFE505A0AF5580D X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250211_182615_760834_BA91EB37 X-CRM114-Status: UNSURE ( 8.80 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Hector Martin Signed-off-by: Hector Martin Signed-off-by: Alyssa Rosenzweig --- drivers/nvme/host/apple.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index 5e1c01a67ee81a36faa3da2f86a3a24fefcdfd6f..a060f69558e76970bfba046cca5127243e8a51b7 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -1528,6 +1528,7 @@ static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev) return anv; put_dev: + apple_nvme_detach_genpd(anv); put_device(anv->dev); return ERR_PTR(ret); } @@ -1561,6 +1562,7 @@ static int apple_nvme_probe(struct platform_device *pdev) nvme_uninit_ctrl(&anv->ctrl); out_put_ctrl: nvme_put_ctrl(&anv->ctrl); + apple_nvme_detach_genpd(anv); return ret; } From patchwork Tue Feb 11 18:25:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alyssa Rosenzweig X-Patchwork-Id: 13970470 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 E5D61C0219B for ; Tue, 11 Feb 2025 18:38:06 +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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ge0IZaVhj6bYPb7IYImWFci1To9h0GU7LfN7WXAzDQg=; b=phJlWPcO077tREMmbsAKKr+IgQ kO9AbXCQPPEDraQzIvq6C1dygNSRxGhyCZXm9HupT1nbsyiGbQhU/8AN3wiLiIHEf1Tw4ALDyfIbJ MTCFr+Q2hn+dpZVQBtVLkokJ25fgN42uBZ5H5qBnVqi9mPgPXyfqvzgG1R0kqTPDzk+4kYSByGdwq BbMngXGFSkoQ7nqu/jhFtbKfkkkE7rhZwTx8U/0ObaZtRZZiaVx1e/qUwPLEKRh+qA+CrVN7gFKUc J7pb0FOwUc9zL0Yt4SL3/e4SMDGaxGsN/dFhCdWHMUzN4o3Fs3IuBU99gE8d06+v9ndADupiQni4e QVJ4Ym8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1thv8w-00000004rqz-2pit; Tue, 11 Feb 2025 18:37:58 +0000 Received: from out-175.mta0.migadu.com ([91.218.175.175]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1thuxV-00000004q4A-3oSs for linux-arm-kernel@lists.infradead.org; Tue, 11 Feb 2025 18:26:11 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rosenzweig.io; s=key1; t=1739298367; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ge0IZaVhj6bYPb7IYImWFci1To9h0GU7LfN7WXAzDQg=; b=Ybmo94hD5UHHt5O9IVJN0SV8pvCtcE0ivNp3/n1zhklYBqNjltkMOMPFHyeJx5KMlCElq6 E4kQU2TxImK8S2dl/koS4OlfG2yvr1MNzTylIpBcfIFx87VuQ6QfngqCUqtA5SuYb5drXi cQjoZWnVadk4ndtTaQ5eJ61exw5vEA2w2+aOjegisGHupEq8T+UvqjexQgfXfvN//uguy9 8fIzc7A66BIF2Mk8NeqrPmY0tx+V4v+iObyK9n4CawAT2TIvCHD3kekscg7lHo6IumTVLy 6Tww43KxYN1itL4og2plMDX+2NldcDAY4Ezcqmur0VZJ2bor+yqtupo0aZaQYQ== From: Alyssa Rosenzweig Date: Tue, 11 Feb 2025 13:25:59 -0500 Subject: [PATCH 3/3] apple-nvme: defer cache flushes by a specified amount MIME-Version: 1.0 Message-Id: <20250211-nvme-fixes-v1-3-6958b3aa49fe@rosenzweig.io> References: <20250211-nvme-fixes-v1-0-6958b3aa49fe@rosenzweig.io> In-Reply-To: <20250211-nvme-fixes-v1-0-6958b3aa49fe@rosenzweig.io> To: Hector Martin , Sven Peter , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Philipp Zabel Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Alyssa Rosenzweig X-Developer-Signature: v=1; a=openpgp-sha256; l=4209; i=alyssa@rosenzweig.io; h=from:subject:message-id; bh=XdAPgabJp3Th1VF3dW5IHPK3KhszAX1ZDwJh3vdU+rs=; b=owEBbQKS/ZANAwAIAf7+UFoK9VgNAcsmYgBnq5Y3LVwFvjEt/Oee7LPZ30kNPyq8CqXKwpOxw cgxkAAh8ICJAjMEAAEIAB0WIQRDXuCbsK8A0B2q9jj+/lBaCvVYDQUCZ6uWNwAKCRD+/lBaCvVY Df8pD/41JdixnbjBPDORaqiQEXeFWOiGuKrkuQnkmT4IDcLlme7arNTYhFy4qlp1QSVcgeWHLsI Hed2NG2jpq0DD5uWlXx5fe1asg4+KvdwJ9EBGBHz29MLxM/PMBSa2k9RYvGfQlcFvAfdRUHQE5T d/PnE+t0vHutgLo5Ba9/rNuyvIaq+qkle/OwXSsjeq0q/L8vOtlJBvoYWuod0C1G2+EV21KkGhq XL98CYSgN5uPiA4WBt3x3NoWRFzXUK23fXQ/jE2EkxAFHX9k1VUUJC1OV4DwOaCCHLSCywLq/qX 4aYYECjAAQlgjq/oBH3vyTc05BaWoQceQzceLVYR+U+vtH0iC6354OdeeEz6lld9JzMnkSZaKQI qAuxX07xFR8osmSkWSFb8+/IzmO9mHjuqS0+/qXZ6hJ1C3wGlpWYjx3xSsBkJiKFbSnV6zRyfFy e+owMrQ27m4YV4NoqcE6rSR/aqrQAEBh9meE0O0aWOwM8ShJolQPM+WerbUN63G0XwWNIrP0X/Z 4hZKEfqnhDbS3yuhr7bIzEc4ZZDCBUvBIeIPr2YsyMjRfhWinT0hiw4KVOT580lPyknu3zeFod9 4+v0hP4Tuj42OaPcMc/HtBdLHL7jUOfb/ZzLVy/fMFZS0WECDRCJJ3NuddFW4G7WeKyOO+87dC7 WFM2C460AzrUvLw== X-Developer-Key: i=alyssa@rosenzweig.io; a=openpgp; fpr=435EE09BB0AF00D01DAAF638FEFE505A0AF5580D X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250211_102610_241761_4B736FD5 X-CRM114-Status: GOOD ( 16.01 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jens Axboe Cache flushes on the M1 nvme are really slow, taking 17-18 msec to complete. This can slow down workloads considerably, pure random writes end up being bound by the flush latency and hence run at 55-60 IOPS. Add a deferred flush work around to provide better performance, at a minimal risk. By default, flushes are delayed at most 1 second, but this is configurable. With this work-around, a pure random write workload runs at ~12K IOPS rather than 56 IOPS. Signed-off-by: Jens Axboe Signed-off-by: Alyssa Rosenzweig --- drivers/nvme/host/apple.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index a060f69558e76970bfba046cca5127243e8a51b7..2dfb0442d56195756df91e0fbc913b751c74d0ea 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -195,8 +195,20 @@ struct apple_nvme { int irq; spinlock_t lock; + + /* + * Delayed cache flush handling state + */ + struct nvme_ns *flush_ns; + unsigned long flush_interval; + unsigned long last_flush; + struct delayed_work flush_dwork; }; +unsigned int flush_interval = 1000; +module_param(flush_interval, uint, 0644); +MODULE_PARM_DESC(flush_interval, "Grace period in msecs between flushes"); + static_assert(sizeof(struct nvme_command) == 64); static_assert(sizeof(struct apple_nvmmu_tcb) == 128); @@ -729,6 +741,26 @@ static int apple_nvme_remove_sq(struct apple_nvme *anv) return nvme_submit_sync_cmd(anv->ctrl.admin_q, &c, NULL, 0); } +static bool apple_nvme_delayed_flush(struct apple_nvme *anv, struct nvme_ns *ns, + struct request *req) +{ + if (!anv->flush_interval || req_op(req) != REQ_OP_FLUSH) + return false; + if (delayed_work_pending(&anv->flush_dwork)) + return true; + if (time_before(jiffies, anv->last_flush + anv->flush_interval)) { + kblockd_mod_delayed_work_on(WORK_CPU_UNBOUND, &anv->flush_dwork, + anv->flush_interval); + if (WARN_ON_ONCE(anv->flush_ns && anv->flush_ns != ns)) + goto out; + anv->flush_ns = ns; + return true; + } +out: + anv->last_flush = jiffies; + return false; +} + static blk_status_t apple_nvme_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { @@ -764,6 +796,12 @@ static blk_status_t apple_nvme_queue_rq(struct blk_mq_hw_ctx *hctx, } nvme_start_request(req); + + if (apple_nvme_delayed_flush(anv, ns, req)) { + blk_mq_complete_request(req); + return BLK_STS_OK; + } + apple_nvme_submit_cmd(q, cmnd); return BLK_STS_OK; @@ -1398,6 +1436,28 @@ static void devm_apple_nvme_mempool_destroy(void *data) mempool_destroy(data); } +static void apple_nvme_flush_work(struct work_struct *work) +{ + struct nvme_command c = { }; + struct apple_nvme *anv; + struct nvme_ns *ns; + int err; + + anv = container_of(work, struct apple_nvme, flush_dwork.work); + ns = anv->flush_ns; + if (WARN_ON_ONCE(!ns)) + return; + + c.common.opcode = nvme_cmd_flush; + c.common.nsid = cpu_to_le32(anv->flush_ns->head->ns_id); + err = nvme_submit_sync_cmd(ns->queue, &c, NULL, 0); + if (err) { + dev_err(anv->dev, "Deferred flush failed: %d\n", err); + } else { + anv->last_flush = jiffies; + } +} + static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1553,6 +1613,14 @@ static int apple_nvme_probe(struct platform_device *pdev) goto out_uninit_ctrl; } + if (flush_interval) { + anv->flush_interval = msecs_to_jiffies(flush_interval); + anv->flush_ns = NULL; + anv->last_flush = jiffies - anv->flush_interval; + } + + INIT_DELAYED_WORK(&anv->flush_dwork, apple_nvme_flush_work); + nvme_reset_ctrl(&anv->ctrl); async_schedule(apple_nvme_async_probe, anv); @@ -1590,6 +1658,7 @@ static void apple_nvme_shutdown(struct platform_device *pdev) { struct apple_nvme *anv = platform_get_drvdata(pdev); + flush_delayed_work(&anv->flush_dwork); apple_nvme_disable(anv, true); if (apple_rtkit_is_running(anv->rtk)) { apple_rtkit_shutdown(anv->rtk);