From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alice Ryhl" <aliceryhl@google.com>
Cc: <abdiel.janulgue@gmail.com>, <daniel.almeida@collabora.com>,
<robin.murphy@arm.com>, <a.hindborg@kernel.org>,
<ojeda@kernel.org>, <alex.gaynor@gmail.com>,
<boqun.feng@gmail.com>, <gary@garyguo.net>,
<bjorn3_gh@protonmail.com>, <lossin@kernel.org>,
<tmgross@umich.edu>, <linux-kernel@vger.kernel.org>,
<rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH 1/2] rust: dma: make use of start_ptr() and start_ptr_mut()
Date: Tue, 04 Nov 2025 15:55:51 +0100 [thread overview]
Message-ID: <DDZZX8AJKTP3.2OTD2L9ULVUG0@kernel.org> (raw)
In-Reply-To: <aQoOS9MQ8PDBYKtk@google.com>
On Tue Nov 4, 2025 at 3:31 PM CET, Alice Ryhl wrote:
> On Tue, Nov 04, 2025 at 10:13:08AM +0100, Danilo Krummrich wrote:
>> On 11/4/25 9:39 AM, Alice Ryhl wrote:
>> > On Mon, Nov 03, 2025 at 08:06:49PM +0100, Danilo Krummrich wrote:
>> >> Using start_ptr() and start_ptr_mut() has the advantage that we inherit
>> >> the requirements the a mutable or immutable reference from those
>> >> methods.
>> >>
>> >> Hence, use them instead of self.cpu_addr.
>> >>
>> >> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
>> >
>> >> // and we've just checked that the range and index is within bounds.
>> >> // - `offset` can't overflow since it is smaller than `self.count` and we've checked
>> >> // that `self.count` won't overflow early in the constructor.
>> >> - Ok(unsafe { self.cpu_addr.add(offset) })
>> >> + Ok(unsafe { self.start_ptr().cast_mut().add(offset) })
>> >
>> > I guess this shows that the mutable/immutable requirements we inherit
>> > aren't actually what we need?
>>
>> item_from_index() is used for the dma_read!() and dma_write!() macros, hence
>> this one is on purpose.
>
> I guess it's more that you don't really need mutable access to call
> start_ptr_mut() for this particular case?
In general I think it's good to require a mutable reference for start_ptr_mut(),
as in the absolute majority of cases we actually want to inherit exclusive
access.
As you say, in this particular case we do not want to inherit exclusive access
on purpose.
next prev parent reply other threads:[~2025-11-04 14:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 19:06 [PATCH 1/2] rust: dma: make use of start_ptr() and start_ptr_mut() Danilo Krummrich
2025-11-03 19:06 ` [PATCH 2/2] rust: dma: use NonNull<T> instead of *mut T Danilo Krummrich
2025-11-04 8:39 ` Alice Ryhl
2025-11-04 8:39 ` [PATCH 1/2] rust: dma: make use of start_ptr() and start_ptr_mut() Alice Ryhl
2025-11-04 9:13 ` Danilo Krummrich
2025-11-04 14:31 ` Alice Ryhl
2025-11-04 14:55 ` Danilo Krummrich [this message]
2025-11-04 10:44 ` Alexandre Courbot
2025-11-06 9:44 ` Danilo Krummrich
2025-11-06 11:33 ` Alice Ryhl
2025-11-11 8:51 ` Danilo Krummrich
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=DDZZX8AJKTP3.2OTD2L9ULVUG0@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=daniel.almeida@collabora.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).