From: "Benno Lossin" <lossin@kernel.org>
To: "Gary Guo" <gary@garyguo.net>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Alexandre Courbot" <acourbot@nvidia.com>,
rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] rust: dma: generalize `dma_{read,write}` macro
Date: Sat, 14 Feb 2026 15:53:21 +0100 [thread overview]
Message-ID: <DGERQW278SQX.3GIPMUSC46PQ6@kernel.org> (raw)
In-Reply-To: <84ef050ac2c2cf858ec766f23d1fb90e@garyguo.net>
On Sat Feb 14, 2026 at 11:46 AM CET, Gary Guo wrote:
> On 2026-02-14 10:04, Benno Lossin wrote:
>> On Sat Feb 14, 2026 at 6:33 AM CET, Gary Guo wrote:
>>> + (@parse [$dma:expr] [$($proj:tt)*] [.$field:tt $($rest:tt)*]) => {
>>> + $crate::dma_write!(@parse [$dma] [$($proj)* .$field] [$($rest)*])
>>> + };
>>> + (@parse [$dma:expr] [$($proj:tt)*] [[$index:expr]? $($rest:tt)*]) => {
>>> + $crate::dma_write!(@parse [$dma] [$($proj)* [$index]?] [$($rest)*])
>>> + };
>>> + (@parse [$dma:expr] [$($proj:tt)*] [[$index:expr] $($rest:tt)*]) => {
>>> + $crate::dma_write!(@parse [$dma] [$($proj)* [$index]] [$($rest)*])
>>> + };
>>> + ($dma:expr, $($rest:tt)*) => {
>>> + $crate::dma_write!(@parse [$dma] [] [$($rest)*])
>>> };
>>
>> I'm wondering if this also works:
>>
>> ($dma:expr, $($(.$field:ident)? $([$index:expr])?)*, $val:expr) => {{
>> let dma = &$dma;
>> let ptr = $crate::project_pointer!(
>> mut $crate::dma::CoherentAllocation::as_mut_ptr(dma),
>> $($(.$field)? $([$index])?)*,
>> );
>> let val = $val;
>> // SAFETY: pointer created by projection is within DMA region.
>> unsafe { $crate::dma::CoherentAllocation::field_write(dma, ptr, val) }
>> }}
>
> Rust would complain that the outer repetition can match empty token tree.
Ah right.
>>> @@ -91,17 +91,17 @@ fn drop(self: Pin<&mut Self>) {
>>> dev_info!(self.pdev, "Unload DMA test driver.\n");
>>>
>>> for (i, value) in TEST_VALUES.into_iter().enumerate() {
>>> - let val0 = kernel::dma_read!(self.ca[i].h);
>>> - let val1 = kernel::dma_read!(self.ca[i].b);
>>> - assert!(val0.is_ok());
>>> - assert!(val1.is_ok());
>>> + let result = (|| -> Result<_> {
>>> + let val0 = kernel::dma_read!(self.ca, [i]?.h);
>>> + let val1 = kernel::dma_read!(self.ca, [i]?.b);
>>>
>>> - if let Ok(val0) = val0 {
>>> assert_eq!(val0, value.0);
>>> - }
>>> - if let Ok(val1) = val1 {
>>> assert_eq!(val1, value.1);
>>> - }
>>> +
>>> + Ok(())
>>> + })();
>>
>> I dislike that we have to reintroduce the budget-try block here. Ideally
>> we could add something like `try` at the beginning of the macro and then
>> automatically add the try block. Feel free to make that a future series.
>
> I don't think this is an issue. It's visible inside the samples because
> we are testing the values, but in practice most users would propagate the
> errors out.
Maybe we should just have a function that returns a Result in this test
that's called from drop.
> I also dislike that the budget-try block that we have inside `dma_read!`
> currently hard-codes the error type.
Yeah me too.
Cheers,
Benno
next prev parent reply other threads:[~2026-02-14 14:53 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-14 5:33 [PATCH 0/4] rust: add pointer projection infrastructure and convert DMA Gary Guo
2026-02-14 5:33 ` [PATCH 1/4] rust: add projection infrastructure Gary Guo
2026-02-14 9:53 ` Benno Lossin
2026-02-14 10:36 ` Gary Guo
2026-02-14 14:48 ` Benno Lossin
2026-02-14 10:27 ` Danilo Krummrich
2026-02-22 0:57 ` Benno Lossin
2026-02-22 10:52 ` Gary Guo
2026-02-14 5:33 ` [PATCH 2/4] rust: dma: generalize `dma_{read,write}` macro Gary Guo
2026-02-14 10:04 ` Benno Lossin
2026-02-14 10:46 ` Gary Guo
2026-02-14 14:53 ` Benno Lossin [this message]
2026-02-14 5:33 ` [PATCH 3/4] gpu: nova-core: convert to use new `dma_write!` syntax Gary Guo
2026-02-14 10:06 ` Benno Lossin
2026-02-14 10:06 ` Benno Lossin
2026-02-14 5:33 ` [PATCH 4/4] rust: dma: remove old dma_{read,write} macro compatibility syntax Gary Guo
2026-02-14 10:05 ` Benno Lossin
2026-02-14 10:33 ` [PATCH 0/4] rust: add pointer projection infrastructure and convert DMA Danilo Krummrich
2026-02-14 10:50 ` Gary Guo
2026-02-14 11:00 ` Danilo Krummrich
2026-02-15 0:47 ` Miguel Ojeda
2026-02-15 11:06 ` Danilo Krummrich
2026-02-15 12:06 ` Miguel Ojeda
2026-02-15 12:56 ` Danilo Krummrich
2026-02-15 15:16 ` Miguel Ojeda
2026-02-15 17:02 ` Danilo Krummrich
2026-02-18 10:49 ` Miguel Ojeda
2026-02-18 18:25 ` Danilo Krummrich
2026-02-15 14:39 ` Benno Lossin
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=DGERQW278SQX.3GIPMUSC46PQ6@kernel.org \
--to=lossin@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.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.