[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z4_7-jbmeQ62hMb0@tardis.local>
Date: Tue, 21 Jan 2025 11:56:42 -0800
From: Boqun Feng <boqun.feng@...il.com>
To: Abdiel Janulgue <abdiel.janulgue@...il.com>
Cc: rust-for-linux@...r.kernel.org, daniel.almeida@...labora.com,
dakr@...nel.org, robin.murphy@....com, daniel@...lak.dev,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Valentin Obst <kernel@...entinobst.de>,
open list <linux-kernel@...r.kernel.org>,
Christoph Hellwig <hch@....de>,
Marek Szyprowski <m.szyprowski@...sung.com>, airlied@...hat.com,
"open list:DMA MAPPING HELPERS" <iommu@...ts.linux.dev>
Subject: Re: [PATCH v9 2/3] rust: add dma coherent allocator abstraction.
On Tue, Jan 21, 2025 at 10:47:46AM +0200, Abdiel Janulgue wrote:
[...]
> +
> + /// Reads data from the region starting from `offset` as a slice.
> + /// `offset` and `count` are in units of `T`, not the number of bytes.
> + ///
> + /// Due to the safety requirements of slice, the data returned should be regarded by the
> + /// caller as a snapshot of the region when this function is called, as the region could
> + /// be modified by the device at anytime. For ringbuffer type of r/w access or use-cases
> + /// where the pointer to the live data is needed, `start_ptr()` or `start_ptr_mut()`
> + /// could be used instead.
> + ///
> + /// # Safety
> + ///
> + /// Callers must ensure that no hardware operations that involve the buffer are currently
> + /// taking place while the returned slice is live.
> + pub unsafe fn read(&self, offset: usize, count: usize) -> Result<&[T]> {
I don't think `read()` is a proper name here since this function only
provides a slice for the caller to read. How about `as_slice()`? Or you
can change the function signature to:
read(&self, offset, usize, count: usize, dst: &mut [T]) -> Result
Regards,
Boqun
> + if offset + count >= self.count {
> + return Err(EINVAL);
> + }
> + // SAFETY: The pointer is valid due to type invariant on `CoherentAllocation`,
> + // we've just checked that the range and index is within bounds. The immutability of the
> + // of data is also guaranteed by the safety requirements of the function.
> + Ok(unsafe { core::slice::from_raw_parts(self.cpu_addr.wrapping_add(offset), count) })
> + }
> +
[...]
Powered by blists - more mailing lists