From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Vinod Koul <vkoul@kernel.org>, Sasha Levin <sashal@kernel.org>,
samuel@sholland.org, dmaengine@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 6.19-6.1] dmaengine: sun6i: Choose appropriate burst length under maxburst
Date: Wed, 18 Feb 2026 21:03:52 -0500 [thread overview]
Message-ID: <20260219020422.1539798-16-sashal@kernel.org> (raw)
In-Reply-To: <20260219020422.1539798-1-sashal@kernel.org>
From: Chen-Yu Tsai <wens@kernel.org>
[ Upstream commit 7178c3586ab42693b28bb81014320a7783e5c435 ]
maxburst, as provided by the client, specifies the largest amount of
data that is allowed to be transferred in one burst. This limit is
normally provided to avoid a data burst overflowing the target FIFO.
It does not mean that the DMA engine can only do bursts in that size.
Let the driver pick the largest supported burst length within the
given limit. This lets the driver work correctly with some clients that
give a large maxburst value. In particular, the 8250_dw driver will give
a quarter of the UART's FIFO size as maxburst. On some systems the FIFO
size is 256 bytes, giving a maxburst of 64 bytes, while the hardware
only supports bursts of up to 16 bytes.
Signed-off-by: Chen-Yu Tsai <wens@kernel.org>
Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Link: https://patch.msgid.link/20251221080450.1813479-1-wens@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
## Analysis Summary
### What the commit fixes
This commit fixes a real bug where the sun6i DMA engine driver
incorrectly rejects valid DMA slave configurations. The DMA API's
`maxburst` field specifies the **maximum** burst size, not an exact
value. When a DMA client (like 8250_dw UART) provides a maxburst value
(e.g., 64) that isn't directly supported by the hardware (which only
supports 1, 4, 8, 16), the old code returned `-EINVAL`, causing DMA
transfers to fail completely.
The fix adds a `find_burst_size()` helper that selects the largest
supported burst length that doesn't exceed `maxburst`, which is the
correct DMA API semantics. This makes DMA work on real systems where
8250_dw UART gives maxburst=64 (quarter of a 256-byte FIFO) but the DMA
hardware supports bursts of at most 16.
### Stable kernel criteria assessment
1. **Obviously correct and tested**: Yes. The logic is simple - find
largest power-of-two burst in the supported bitmask that fits within
maxburst. Reviewed by Jernej Skrabec, applied by Vinod Koul.
2. **Fixes a real bug**: Yes. DMA transactions fail with `-EINVAL` on
specific hardware combinations. This causes UART (and potentially
other peripherals) to not work via DMA.
3. **Important issue**: Yes - this causes peripheral communication
failure (UART DMA doesn't work on some Allwinner SoCs). Users with
256-byte UART FIFOs and DMA-capable 8250_dw cannot use DMA at all.
4. **Small and contained**: Yes. Adds a ~14-line helper function,
removes 4 lines of strict checks, and reorders 4 lines of existing
code to call the new function first. Total change is well under 50
lines in a single file.
5. **No new features**: Correct - this makes the driver handle the
existing DMA API correctly. It's a bug fix to match the documented
DMA maxburst semantics.
### Risk assessment
- **Low risk**: Changes are confined to one driver file
(`drivers/dma/sun6i-dma.c`)
- **No regressions for existing users**: If maxburst was previously an
exact match for hardware-supported values (1, 4, 8, or 16),
`find_burst_size()` returns the same value as before. The behavior
only changes for values that previously failed.
- **Well-tested helper**: `rounddown_pow_of_two` is a standard kernel
utility available in all stable trees.
- **No dependency issues**: The `burst_lengths` infrastructure was
introduced in 2017, present in all current stable kernels.
### User impact
Moderate-to-high for Allwinner ARM SoC users (embedded/IoT). These SoCs
are common in single-board computers (Orange Pi, Pine64, etc.) and
various embedded devices. The fix enables DMA-based UART operation where
it was previously broken.
## Verification
- **Verified** `burst_lengths` was introduced by commit d5f6d8cf31a89
(2017-09-28), present in all stable trees.
- **Verified** `convert_burst()` only handles values 1, 4, 8, 16 (lines
283-297), so the old code that directly passed unsupported values
would return -EINVAL from both the explicit check AND from
convert_burst.
- **Verified** the hardware configs show burst_lengths support
BIT(1)|BIT(8) (A31/A23/A83t/D1) or BIT(1)|BIT(4)|BIT(8)|BIT(16)
(H3/H6/V3s/A100), meaning a maxburst of 64 would fail on ALL variants.
- **Verified** `rounddown_pow_of_two` is available in
`include/linux/log2.h` and is a long-standing kernel utility.
- **Verified** via git log that no other recent commits to this file are
needed as dependencies.
- **Verified** via lore.kernel.org that the patch was reviewed by Jernej
Skrabec and applied by maintainer Vinod Koul.
- **Could not verify** the exact 8250_dw maxburst=64 scenario from the
8250_dw driver source (unverified, but the commit message describes a
real hardware scenario credibly).
**YES**
drivers/dma/sun6i-dma.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index 2215ff877bf7d..f9d876deb1f05 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -583,6 +583,22 @@ static irqreturn_t sun6i_dma_interrupt(int irq, void *dev_id)
return ret;
}
+static u32 find_burst_size(const u32 burst_lengths, u32 maxburst)
+{
+ if (!maxburst)
+ return 1;
+
+ if (BIT(maxburst) & burst_lengths)
+ return maxburst;
+
+ /* Hardware only does power-of-two bursts. */
+ for (u32 burst = rounddown_pow_of_two(maxburst); burst > 0; burst /= 2)
+ if (BIT(burst) & burst_lengths)
+ return burst;
+
+ return 1;
+}
+
static int set_config(struct sun6i_dma_dev *sdev,
struct dma_slave_config *sconfig,
enum dma_transfer_direction direction,
@@ -616,15 +632,13 @@ static int set_config(struct sun6i_dma_dev *sdev,
return -EINVAL;
if (!(BIT(dst_addr_width) & sdev->slave.dst_addr_widths))
return -EINVAL;
- if (!(BIT(src_maxburst) & sdev->cfg->src_burst_lengths))
- return -EINVAL;
- if (!(BIT(dst_maxburst) & sdev->cfg->dst_burst_lengths))
- return -EINVAL;
src_width = convert_buswidth(src_addr_width);
dst_width = convert_buswidth(dst_addr_width);
- dst_burst = convert_burst(dst_maxburst);
- src_burst = convert_burst(src_maxburst);
+ src_burst = find_burst_size(sdev->cfg->src_burst_lengths, src_maxburst);
+ dst_burst = find_burst_size(sdev->cfg->dst_burst_lengths, dst_maxburst);
+ dst_burst = convert_burst(dst_burst);
+ src_burst = convert_burst(src_burst);
*p_cfg = DMA_CHAN_CFG_SRC_WIDTH(src_width) |
DMA_CHAN_CFG_DST_WIDTH(dst_width);
--
2.51.0
next prev parent reply other threads:[~2026-02-19 2:04 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-19 2:03 [PATCH AUTOSEL 6.19] rust_binder: Fix build failure if !CONFIG_COMPAT Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.12] usb: chipidea: udc: fix DMA and SG cleanup in _ep_nuke() Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-5.15] staging: rtl8723bs: fix memory leak on failure path Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19] tty: vt/keyboard: Split apart vt_do_diacrit() Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-5.10] fix it87_wdt early reboot by reporting running timer Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-5.15] misc: eeprom: Fix EWEN/EWDS/ERAL commands for 93xx56 and 93xx66 Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-5.15] mmc: rtsx_pci: add quirk to disable MMC_CAP_AGGRESSIVE_PM for RTS525A Sasha Levin
2026-02-19 10:29 ` Ulf Hansson
2026-02-26 13:23 ` Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.1] fpga: of-fpga-region: Fail if any bridge is missing Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.12] soundwire: intel_auxdevice: add cs42l45 codec to wake_capable_list Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-5.10] iio: magnetometer: Remove IRQF_ONESHOT Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.1] watchdog: imx7ulp_wdt: handle the nowayout option Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-5.10] serial: 8250_dw: handle clock enable errors in runtime_resume Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.12] most: core: fix resource leak in most_register_interface error paths Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19] block: fix partial IOVA mapping cleanup in blk_rq_dma_map_iova Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.1] misc: bcm_vk: Fix possible null-pointer dereferences in bcm_vk_read() Sasha Levin
2026-02-19 2:03 ` Sasha Levin [this message]
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.1] mmc: rtsx: reset power state on suspend Sasha Levin
2026-02-19 10:27 ` Ulf Hansson
2026-02-26 13:24 ` Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19] serial: rsci: Add set_rtrg() callback Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-5.10] Revert "mfd: da9052-spi: Change read-mask to write-mask" Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.18] pinctrl: mediatek: make devm allocations safer and clearer in mtk_eint_do_init() Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.12] serial: 8250: 8250_omap.c: Add support for handling UART error conditions Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.12] usb: gadget: f_fs: Fix ioctl error handling Sasha Levin
2026-02-19 2:03 ` [PATCH AUTOSEL 6.19-6.12] phy: cadence-torrent: restore parent clock for refclk during resume Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-5.10] binder: don't use %pK through printk Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.18] iio: bmi270_i2c: Add MODULE_DEVICE_TABLE for BMI260/270 Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-5.15] iio: Use IRQF_NO_THREAD Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.12] mfd: intel-lpss: Add Intel Nova Lake-S PCI IDs Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.12] phy: ti: phy-j721e-wiz: restore mux selection during resume Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-5.10] MIPS: Loongson: Make cpumask_of_node() robust against NUMA_NO_NODE Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.12] usb: gadget: f_fs: fix DMA-BUF OUT queues Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-5.10] phy: fsl-imx8mq-usb: disable bind/unbind platform driver feature Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.18] watchdog: rzv2h_wdt: Discard pm_runtime_put() return value Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.1] soundwire: dmi-quirks: add mapping for Avell B.ON (OEM rebranded of NUC15) Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.18] pinctrl: renesas: rzt2h: Allow .get_direction() for IRQ function GPIOs Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.12] dmaengine: stm32-dma3: use module_platform_driver Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-5.15] staging: rtl8723bs: fix missing status update on sdio_alloc_irq() failure Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-5.15] phy: mvebu-cp110-utmi: fix dr_mode property read from dts Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.1] usb: typec: ucsi: psy: Fix voltage and current max for non-Fixed PDOs Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-5.10] serial: 8250: 8250_omap.c: Clear DMA RX running status only after DMA termination is done Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.1] dmaengine: stm32-mdma: initialize m2m_hw_period and ccr to fix warnings Sasha Levin
2026-02-19 2:04 ` [PATCH AUTOSEL 6.19-6.18] misc: ti_fpc202: fix a potential memory leak in probe function Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260219020422.1539798-16-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=jernej.skrabec@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=patches@lists.linux.dev \
--cc=samuel@sholland.org \
--cc=stable@vger.kernel.org \
--cc=vkoul@kernel.org \
--cc=wens@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox