* [PATCH v3] rust: dma: allow drivers to tune max segment size
@ 2026-01-28 13:53 Beata Michalska
2026-01-28 14:11 ` Alice Ryhl
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Beata Michalska @ 2026-01-28 13:53 UTC (permalink / raw)
To: dakr, ojeda, gary, rust-for-linux, dirk.behme
Cc: abdiel.janulgue, daniel.almeida, aliceryhl, robin.murphy,
a.hindborg, boqun.feng, bjorn3_gh, lossin, tmgross, linux-kernel
Make dma_set_max_seg_size() available to Rust so drivers can perform
standard DMA setup steps.
Signed-off-by: Beata Michalska <beata.michalska@arm.com>
---
Apologies for delay.
v3:
- Added __rust_helper
v2:
- Aligned safety requirements
rust/helpers/dma.c | 6 ++++++
rust/kernel/dma.rs | 17 +++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/rust/helpers/dma.c b/rust/helpers/dma.c
index e7defeecda71..20232ac64850 100644
--- a/rust/helpers/dma.c
+++ b/rust/helpers/dma.c
@@ -43,3 +43,9 @@ size_t rust_helper_dma_max_mapping_size(struct device *dev)
{
return dma_max_mapping_size(dev);
}
+
+__rust_helper void rust_helper_dma_set_max_seg_size(struct device *dev,
+ unsigned int size)
+{
+ dma_set_max_seg_size(dev, size);
+}
diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
index acc65b1e0f24..909d56fd5118 100644
--- a/rust/kernel/dma.rs
+++ b/rust/kernel/dma.rs
@@ -85,6 +85,23 @@ unsafe fn dma_set_mask_and_coherent(&self, mask: DmaMask) -> Result {
bindings::dma_set_mask_and_coherent(self.as_ref().as_raw(), mask.value())
})
}
+
+ /// Set the maximum size of a single DMA segment the device may request.
+ ///
+ /// This method is usually called once from `probe()` as soon as the device capabilities are
+ /// known.
+ ///
+ /// # Safety
+ ///
+ /// This method must not be called concurrently with any DMA allocation or mapping primitives,
+ /// such as [`CoherentAllocation::alloc_attrs`].
+ unsafe fn dma_set_max_seg_size(&self, size: u32) {
+ // SAFETY:
+ // - By the type invariant of `device::Device`, `self.as_ref().as_raw()` is valid.
+ // - The safety requirement of this function guarantees that there are no concurrent calls
+ // to DMA allocation and mapping primitives using this parameter.
+ unsafe { bindings::dma_set_max_seg_size(self.as_ref().as_raw(), size) }
+ }
}
/// A DMA mask that holds a bitmask with the lowest `n` bits set.
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] rust: dma: allow drivers to tune max segment size
2026-01-28 13:53 [PATCH v3] rust: dma: allow drivers to tune max segment size Beata Michalska
@ 2026-01-28 14:11 ` Alice Ryhl
2026-01-28 14:39 ` Robin Murphy
2026-01-28 17:17 ` Danilo Krummrich
2 siblings, 0 replies; 4+ messages in thread
From: Alice Ryhl @ 2026-01-28 14:11 UTC (permalink / raw)
To: Beata Michalska
Cc: dakr, ojeda, gary, rust-for-linux, dirk.behme, abdiel.janulgue,
daniel.almeida, robin.murphy, a.hindborg, boqun.feng, bjorn3_gh,
lossin, tmgross, linux-kernel
On Wed, Jan 28, 2026 at 02:53:20PM +0100, Beata Michalska wrote:
> Make dma_set_max_seg_size() available to Rust so drivers can perform
> standard DMA setup steps.
>
> Signed-off-by: Beata Michalska <beata.michalska@arm.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] rust: dma: allow drivers to tune max segment size
2026-01-28 13:53 [PATCH v3] rust: dma: allow drivers to tune max segment size Beata Michalska
2026-01-28 14:11 ` Alice Ryhl
@ 2026-01-28 14:39 ` Robin Murphy
2026-01-28 17:17 ` Danilo Krummrich
2 siblings, 0 replies; 4+ messages in thread
From: Robin Murphy @ 2026-01-28 14:39 UTC (permalink / raw)
To: Beata Michalska, dakr, ojeda, gary, rust-for-linux, dirk.behme
Cc: abdiel.janulgue, daniel.almeida, aliceryhl, a.hindborg,
boqun.feng, bjorn3_gh, lossin, tmgross, linux-kernel
On 2026-01-28 1:53 pm, Beata Michalska wrote:
> Make dma_set_max_seg_size() available to Rust so drivers can perform
> standard DMA setup steps.
Yup, API-wise this goes hand-in-hand with dma_set_mask calls, so keeping
all the requirements in sync is the right thing to do. FWIW,
Acked-by: Robin Murphy <robvin.murphy@arm.com>
> Signed-off-by: Beata Michalska <beata.michalska@arm.com>
> ---
> Apologies for delay.
>
> v3:
> - Added __rust_helper
>
> v2:
> - Aligned safety requirements
>
> rust/helpers/dma.c | 6 ++++++
> rust/kernel/dma.rs | 17 +++++++++++++++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/rust/helpers/dma.c b/rust/helpers/dma.c
> index e7defeecda71..20232ac64850 100644
> --- a/rust/helpers/dma.c
> +++ b/rust/helpers/dma.c
> @@ -43,3 +43,9 @@ size_t rust_helper_dma_max_mapping_size(struct device *dev)
> {
> return dma_max_mapping_size(dev);
> }
> +
> +__rust_helper void rust_helper_dma_set_max_seg_size(struct device *dev,
> + unsigned int size)
> +{
> + dma_set_max_seg_size(dev, size);
> +}
> diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
> index acc65b1e0f24..909d56fd5118 100644
> --- a/rust/kernel/dma.rs
> +++ b/rust/kernel/dma.rs
> @@ -85,6 +85,23 @@ unsafe fn dma_set_mask_and_coherent(&self, mask: DmaMask) -> Result {
> bindings::dma_set_mask_and_coherent(self.as_ref().as_raw(), mask.value())
> })
> }
> +
> + /// Set the maximum size of a single DMA segment the device may request.
> + ///
> + /// This method is usually called once from `probe()` as soon as the device capabilities are
> + /// known.
> + ///
> + /// # Safety
> + ///
> + /// This method must not be called concurrently with any DMA allocation or mapping primitives,
> + /// such as [`CoherentAllocation::alloc_attrs`].
> + unsafe fn dma_set_max_seg_size(&self, size: u32) {
> + // SAFETY:
> + // - By the type invariant of `device::Device`, `self.as_ref().as_raw()` is valid.
> + // - The safety requirement of this function guarantees that there are no concurrent calls
> + // to DMA allocation and mapping primitives using this parameter.
> + unsafe { bindings::dma_set_max_seg_size(self.as_ref().as_raw(), size) }
> + }
> }
>
> /// A DMA mask that holds a bitmask with the lowest `n` bits set.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] rust: dma: allow drivers to tune max segment size
2026-01-28 13:53 [PATCH v3] rust: dma: allow drivers to tune max segment size Beata Michalska
2026-01-28 14:11 ` Alice Ryhl
2026-01-28 14:39 ` Robin Murphy
@ 2026-01-28 17:17 ` Danilo Krummrich
2 siblings, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-01-28 17:17 UTC (permalink / raw)
To: Beata Michalska
Cc: ojeda, gary, rust-for-linux, dirk.behme, abdiel.janulgue,
daniel.almeida, aliceryhl, robin.murphy, a.hindborg, boqun.feng,
bjorn3_gh, lossin, tmgross, linux-kernel
On Wed Jan 28, 2026 at 2:53 PM CET, Beata Michalska wrote:
> Make dma_set_max_seg_size() available to Rust so drivers can perform
> standard DMA setup steps.
>
> Signed-off-by: Beata Michalska <beata.michalska@arm.com>
Applied to driver-core-testing, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-28 17:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-28 13:53 [PATCH v3] rust: dma: allow drivers to tune max segment size Beata Michalska
2026-01-28 14:11 ` Alice Ryhl
2026-01-28 14:39 ` Robin Murphy
2026-01-28 17:17 ` Danilo Krummrich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox