From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379441; b=u+/Fy6D1TIlPxon5a0jVEuG2gAqr7pmdsg8Vb8s0woioZzJpWJ03glcDvxNG3mnlhBvV W4zZRSWMZeRnPiW9HGHmKRQ1a5K5DHqTpWBfJRT3M8t4A+gJ4S9Jy5os9KNBlkvAoCyVn ZlwmxkQcMzeVofP7/D/ty3FSQFGUcrBpvvW5SHnMcY9kFlvEHwc7rfsr29bFDq2ISzRwH PG9yaJw1eK0m0d7kT/ZQ+tergRQjnPj4c/+MbSWwN7RIgknGn2CitArYVTorqeq01+wN8 SQqswXCEOQElA381+mWNl9ZZaaxgfllGvZArVlCOFdsvS77fiV0VZzlLqRUuCwVxcTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379441; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=jl2vRrMmchoHyHFsOT/I57M5NcisXVdsGMEX4uZ2mWs=; b=WqRx9KMP7VwedY3TonDtT8EP2QOL7r0rJE0Ds4AY0rEKFRe2WXviH3008xUU8w0NbrRy PGBCKhr/Y8jtHLpcSvKWkYb9Sfhf6cL1na8E8hN0kjC70VWxat/jFlyzpEeIxVYxNtRX0 CUtBxV4tp2mEJ9dj6tKRNXWaP6pX1jHHcQKzMiKheiE5DhRTq6EnZATIhtu680xRGRJWv 0JN2iTlmmS8Y0pLR9XLKMqsrV6vG8DPPQiDsf2kR/BmDyJk/LZ6b/decrCQq9O6KV3uM6 oM8yjH3DLjmbHf7dHgKbCPu1xfz7WwpGM9zm6IvJQbce413Rnk4G7c058OvGrNVST0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=CvNWSUDG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CA90606A681; Fri, 4 Dec 2026 10:17:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=CvNWSUDG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B0C31F000C2; Fri, 4 Dec 2026 10:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379440; bh=jl2vRrMmchoHyHFsOT/I57M5NcisXVdsGMEX4uZ2mWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CvNWSUDGngJD4/9sW6xnKtPvHGXPK811ZeVQCwFsyGaB62UeljyGXJ9xG5np8nt34 p6mEDlj1azfWaZ2uYFNyuykSony/wJZqrZeMZkRLE70ZN3kPMP6nGZgTp++BfcJPSy skCG07bHOJ1lMZOPLJrsokUSZs+yVU9KysQCYqFs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mark Brown , Vishwaroop A , Sasha Levin Subject: [PATCH 6.12 030/555] spi: tegra210-quad: Track DMA mapping state Date: Fri, 4 Dec 2026 19:01:13 +0900 Message-ID: <20261204100606.214331770@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vishwaroop A [ Upstream commit 7b9e6f7bc13c0259b192d0a964e802d4ad53b8b8 ] tegra_qspi_dma_unmap_xfer() assumes a streaming mapping is always outstanding and recomputes its length from the live tqspi->curr_dma_words. Nothing records whether tegra_qspi_dma_map_xfer() mapped anything, so neither assumption holds. For a multi-chunk transfer, handle_dma_based_xfer() unmaps the chunk that just completed, recalculates the parameters for the next chunk, which overwrites curr_dma_words, and re-arms the hardware. If tegra_qspi_start_dma_based_transfer() then fails at its tegra_qspi_dma_map_xfer() call, nothing is mapped. That early return also sits above the smp_store_release() that clears tqspi->trans_status, so the previous chunk's QSPI_RDY survives, and the re-arm's return value is never checked, so handle_dma_based_xfer() returns IRQ_HANDLED without completing the transfer. The caller times out, tegra_qspi_handle_timeout() sees the stale QSPI_RDY, concludes the transfer completed and calls handle_dma_based_xfer() again. No DMA completion arrives, so num_errors is incremented and tegra_qspi_dma_unmap_xfer() runs with nothing mapped. t->tx_dma then holds either the DMA_MAPPING_ERROR sentinel or, if the RX mapping was the one that failed, the preceding chunk's address that has already been released. Behind an IOMMU the latter frees an IOVA that may since have been reallocated. Record whether a mapping is outstanding and the length that was mapped, and return early from tegra_qspi_dma_unmap_xfer() when there is nothing to release. is_dma_mapped is only updated under tqspi->lock, or on the timeout path after synchronize_irq() and cancel_work_sync() have quiesced the ISR and the bottom half. Also skip releasing the TX mapping on the RX failure path unless a TX mapping was created; t->tx_dma is uninitialised when t->tx_buf is NULL. Fixes: 921fc1838fb0 ("spi: tegra210-quad: Add support for Tegra210 QSPI controller") Suggested-by: Mark Brown Cc: stable@vger.kernel.org Signed-off-by: Vishwaroop A Link: https://patch.msgid.link/20261026111412.3843954-3-va@nvidia.com Signed-off-by: Mark Brown [ sashal: Replaced the single tqspi->dev DMA device uses for the missing tx_dma_dev/rx_dma_dev split, keeping the upstream mapping-state tracking and unmap logic unchanged. ] Signed-off-by: Sasha Levin --- drivers/spi/spi-tegra210-quad.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-tegra210-quad.c b/drivers/spi/spi-tegra210-quad.c index 14dd98b92bd93..ca91a69ea059e 100644 --- a/drivers/spi/spi-tegra210-quad.c +++ b/drivers/spi/spi-tegra210-quad.c @@ -207,6 +207,17 @@ struct tegra_qspi { bool is_packed; bool use_dma; + /* + * Set while a streaming mapping created by + * tegra_qspi_dma_map_xfer() is outstanding, together with the + * length that was handed to dma_map_single(). is_curr_dma_xfer + * only records that the last armed chunk took the DMA path, + * which is not the same thing: a chunk whose mapping failed + * leaves the DMA path flagged with nothing mapped. + */ + bool is_dma_mapped; + unsigned int dma_map_len; + u32 command1_reg; u32 dma_control_reg; u32 def_command1_reg; @@ -586,22 +597,32 @@ static int tegra_qspi_dma_map_xfer(struct tegra_qspi *tqspi, struct spi_transfer if (t->rx_buf) { t->rx_dma = dma_map_single(tqspi->dev, (void *)rx_buf, len, DMA_FROM_DEVICE); if (dma_mapping_error(tqspi->dev, t->rx_dma)) { - dma_unmap_single(tqspi->dev, t->tx_dma, len, DMA_TO_DEVICE); + if (t->tx_buf) + dma_unmap_single(tqspi->dev, t->tx_dma, + len, DMA_TO_DEVICE); return -ENOMEM; } } + tqspi->dma_map_len = len; + tqspi->is_dma_mapped = true; + return 0; } static void tegra_qspi_dma_unmap_xfer(struct tegra_qspi *tqspi, struct spi_transfer *t) { - unsigned int len; + if (!tqspi->is_dma_mapped) + return; - len = DIV_ROUND_UP(tqspi->curr_dma_words * tqspi->bytes_per_word, 4) * 4; + if (t->tx_buf) + dma_unmap_single(tqspi->dev, t->tx_dma, + tqspi->dma_map_len, DMA_TO_DEVICE); + if (t->rx_buf) + dma_unmap_single(tqspi->dev, t->rx_dma, + tqspi->dma_map_len, DMA_FROM_DEVICE); - dma_unmap_single(tqspi->dev, t->tx_dma, len, DMA_TO_DEVICE); - dma_unmap_single(tqspi->dev, t->rx_dma, len, DMA_FROM_DEVICE); + tqspi->is_dma_mapped = false; } static int tegra_qspi_start_dma_based_transfer(struct tegra_qspi *tqspi, struct spi_transfer *t) -- 2.53.0