Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63C5931E848 for ; Tue, 22 Sep 2026 15:22:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790090566; cv=none; b=AAbyHIE29gwkBDB3uk4ehHzKQGHO6Nv1XSswJEglhVGZbHwBh2RQknXTFcTrhip74yYaEudRCZLivOmrQnmRXp8J1fzDLFE8NxvuVFn2ui/wr/MD4L0BnMzoMv1Rn/13VdgiPAjI1QhO0/SDcOwzI37jnMhefmaP0McP9cnYJbQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790090566; c=relaxed/simple; bh=LgdsIUh8KGyHDYgwgiaZ+CBZ5nILAozYqparlBDFtfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lm796Vz0LkFHVDeXMp1j8JAz/fQohB/utao1TzRF9m73wrHS6++8GiNzVhbzWhmfm3k3Iv6n2/6v90kB6Lry9TEYcaGPbzMdkAu8YDFuh7y5lLEFLzFvAfiTkA2rCQAvMHNXKlVtW06WwC8iJl7J4U6+7SWJKx5pswJMvIWQ6ns= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PDNxiu8y; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PDNxiu8y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 736621F000FF; Tue, 22 Sep 2026 15:22:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790090565; bh=ZPvLFYGHGrwoVBhMhizwGtkeVmaemgBGm7SvVFClAmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PDNxiu8yowJOlKXrXpp6CuqZUb9Rq2cF1XD//W2/ngsakF20pWgVHDSm276arzL3z wIkjits8/QL6zmT/cPQ7rqzMnT1GGhphK0NLUBdtf8WM45AtrouKUDXpyzT0n28Exg Y3akroarRhGn8+9F1LTXTgS3pOn/lKVOnWWYKqJBxtEsGBP1ZVyM0OOlJhfaXgow+3 PgP8BQYqm/V4huvr35PBf1APeXL0ptVMOogZAYwk6dy4dvF9sXWtR1YXNrSrBCEcoz vyFUp/dREkNW+30GVgMZAYTI6oIPuuf8B4pzFGJ6C3gPyfGfcAMyclKl2OWJwozO8D 9RYYAToUeT8ng== From: Sasha Levin To: stable@vger.kernel.org Cc: Itai Handler , Mark Brown , Sasha Levin Subject: [PATCH 6.12.y 2/2] spi: spi-zynqmp-gqspi: stop the controller on shutdown Date: Tue, 22 Sep 2026 11:22:42 -0400 Message-ID: <20260922152242.2799625-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260922152242.2799625-1-sashal@kernel.org> References: <2026092222-marital-chasing-0267@gregkh> <20260922152242.2799625-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Itai Handler [ Upstream commit e922bad8b2d5028c51a096d083fea41cd0987154 ] The driver has no ->shutdown, and platform_drv_shutdown() has no fallback of its own. Unlike pci_device_shutdown(), which clears bus mastering when kexec_in_progress, nothing on the platform bus disarms a device that can still write to memory. The normal kexec path never calls ->suspend either, so the quiesce in zynqmp_qspi_suspend() is not reached. A controller that is still executing a DMA read may therefore keep writing to memory across a kexec. QSPIDMA_DST_ADDR still points at memory owned by the kernel that called kexec, DST_SIZE is non-zero and the flash is still clocked, so data can keep landing in RAM while the new kernel is being relocated, and after it has started executing. That destination is a physical address which means nothing to the new kernel, so the writes can corrupt whatever now occupies it: kernel text or data, page tables, or the initrd. Nothing reports an error and the resulting behaviour is undefined. This can be observed by reading GQSPI_EN (offset 0x114) and QSPIDMA_DST_ADDR/SIZE/STS/CTRL (offsets 0x800 to 0x80c) early in the new kernel, before the driver probes: without this patch GQSPI_EN reads 1 and QSPIDMA_DST_ADDR still points into the previous kernel's memory. Add a ->shutdown that stops the controller the way zynqmp_qspi_suspend() already does. spi_controller_suspend() stops the queue, waits for a message that is already executing and makes any later transfer fail with -ESHUTDOWN, so nothing can be cut short by the register write that follows. It may sleep, which is fine here: device_shutdown() runs in process context. Unlike ->suspend this cannot abort on error, because a controller left mastering the bus is worse than a truncated transfer, so a failure to drain is only logged. GQSPI_EN_OFST is then cleared, as zynqmp_qspi_remove() and zynqmp_qspi_suspend() already do. Skip that write only when pm_runtime_get_if_in_use() returns 0, i.e. runtime suspended: the clocks are gated, so the registers are unreachable and the controller cannot be mastering the bus. A negative return is not the same thing - it is what the CONFIG_PM=n stub always returns, and there probe() has enabled pclk and refclk for good, so the controller is running and must be stopped. Fixes: dfe11a11d523 ("spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller") Cc: stable@vger.kernel.org Signed-off-by: Itai Handler Link: https://patch.msgid.link/20260910174832.873352-1-itai.handler@gmail.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-zynqmp-gqspi.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index 54cea0986af09..fba30bb16eb24 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -1385,11 +1385,45 @@ static void zynqmp_qspi_remove(struct platform_device *pdev) clk_disable_unprepare(xqspi->pclk); } +static void zynqmp_qspi_shutdown(struct platform_device *pdev) +{ + struct zynqmp_qspi *xqspi = platform_get_drvdata(pdev); + int ret; + + /* + * Stop the queue and reject any later transfer first, so the write + * below cannot cut into a message that is still being executed. + * Unlike ->suspend this cannot abort on error: a controller left + * mastering the bus is worse than a truncated transfer. + */ + ret = spi_controller_suspend(xqspi->ctlr); + if (ret) + dev_warn(&pdev->dev, "could not stop the queue: %d\n", ret); + + /* + * Only a runtime suspended controller can be left alone: its clocks + * are gated, so it cannot be mastering the bus, and its registers + * must not be accessed either. Any other answer means it may be + * running and has to be stopped. In particular, on a kernel built + * without runtime PM this returns -EINVAL, and there the clocks + * enabled in probe() are never gated at all. + */ + ret = pm_runtime_get_if_in_use(&pdev->dev); + if (!ret) + return; + + zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, 0x0); + + if (ret > 0) + pm_runtime_put_noidle(&pdev->dev); +} + MODULE_DEVICE_TABLE(of, zynqmp_qspi_of_match); static struct platform_driver zynqmp_qspi_driver = { .probe = zynqmp_qspi_probe, .remove = zynqmp_qspi_remove, + .shutdown = zynqmp_qspi_shutdown, .driver = { .name = "zynqmp-qspi", .of_match_table = zynqmp_qspi_of_match, -- 2.53.0