All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Gary Guo" <gary@garyguo.net>
Cc: <abdiel.janulgue@gmail.com>, <daniel.almeida@collabora.com>,
	<robin.murphy@arm.com>, <a.hindborg@kernel.org>,
	<ojeda@kernel.org>, <boqun@kernel.org>,
	<bjorn3_gh@protonmail.com>, <lossin@kernel.org>,
	<aliceryhl@google.com>, <tmgross@umich.edu>,
	<driver-core@lists.linux.dev>, <rust-for-linux@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] rust: dma: add CoherentHandle for DMA allocations without kernel mapping
Date: Wed, 25 Mar 2026 18:18:08 +0100	[thread overview]
Message-ID: <DHC18ZPBO3X4.1P6GJKSE0IMK8@kernel.org> (raw)
In-Reply-To: <DHBVYVW7ZTDA.23N0Z3YOC5735@garyguo.net>

On Wed Mar 25, 2026 at 2:09 PM CET, Gary Guo wrote:
> This only gives you fixed size, though. If you want the same type that supports
> both a fixed size and dynamic size, then a generic that is either array/slice is
> the way to go.

[...]

> You still can use `io_project!(handle, [start..end]?)` to do the bounds
> checking. But as you said, the benefit might be minimal.

I think we shouldn't overengineer this for now, and wait for actual use-cases
that require any of that.

The only thing we need right now in practice is an API that takes the size and
returns a handle to the buffer of this size exposing the DMA address that is
subsequently passed to the device without further modification.

So, if we want to re-use dma::Coherent<T>, we can just do this

	pub struct CoherentHandle(Coherent<[u8]>);
	
	impl CoherentHandle {
	    pub fn alloc_with_attrs(
	        dev: &device::Device<Bound>,
	        size: usize,
	        gfp_flags: kernel::alloc::Flags,
	        dma_attrs: Attrs,
	    ) -> Result<Self> {
	        let dma_attrs = dma_attrs | Attrs(bindings::DMA_ATTR_NO_KERNEL_MAPPING);
	        Coherent::<u8>::alloc_slice_with_attrs(dev, size, gfp_flags, dma_attrs).map(Self)
	    }
	
	    #[inline]
	    pub fn alloc(
	        dev: &device::Device<Bound>,
	        size: usize,
	        gfp_flags: kernel::alloc::Flags,
	    ) -> Result<Self> {
	        Self::alloc_with_attrs(dev, size, gfp_flags, Attrs(0))
	    }
	
	    #[inline]
	    pub fn dma_handle(&self) -> DmaAddress {
	        self.0.dma_handle()
	    }
	
	    #[inline]
	    pub fn size(&self) -> usize {
	        self.0.size()
	    }
	}

and add a guarantee that Coherent::alloc_with_attrs() and Coherent::drop() never
touch the cpu_ptr.

  reply	other threads:[~2026-03-25 17:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-21 17:27 [PATCH 1/2] rust: dma: remove DMA_ATTR_NO_KERNEL_MAPPING from public attrs Danilo Krummrich
2026-03-21 17:27 ` [PATCH 2/2] rust: dma: add CoherentHandle for DMA allocations without kernel mapping Danilo Krummrich
2026-03-22 14:52   ` Alexandre Courbot
2026-03-22 15:21     ` Danilo Krummrich
2026-03-24 20:10   ` Gary Guo
2026-03-24 22:20     ` Danilo Krummrich
2026-03-25 13:09       ` Gary Guo
2026-03-25 17:18         ` Danilo Krummrich [this message]
2026-03-26 13:37           ` Gary Guo
2026-03-21 18:42 ` [PATCH 1/2] rust: dma: remove DMA_ATTR_NO_KERNEL_MAPPING from public attrs Gary Guo
2026-03-22 11:07 ` Alice Ryhl
2026-03-22 14:52 ` Alexandre Courbot
2026-03-28 14:51 ` Alexandre Courbot

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=DHC18ZPBO3X4.1P6GJKSE0IMK8@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=abdiel.janulgue@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=driver-core@lists.linux.dev \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.