From: Joel Fernandes <joelagnelf@nvidia.com>
To: Alexandre Courbot <acourbot@nvidia.com>
Cc: linux-kernel@vger.kernel.org, Danilo Krummrich <dakr@kernel.org>,
Miguel Ojeda <ojeda@kernel.org>, Boqun Feng <boqun@kernel.org>,
Gary Guo <gary@garyguo.net>,
Björn Roy Baron <bjorn3_gh@protonmail.com>,
Benno Lossin <lossin@kernel.org>,
Andreas Hindborg <a.hindborg@kernel.org>,
Alice Ryhl <aliceryhl@google.com>,
Trevor Gross <tmgross@umich.edu>,
Dave Airlie <airlied@redhat.com>,
Daniel Almeida <daniel.almeida@collabora.com>,
dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
rust-for-linux@vger.kernel.org,
Nikola Djukic <ndjukic@nvidia.com>
Subject: Re: [PATCH -next v9 1/3] rust: clist: Add support to interface with C linked lists
Date: Thu, 19 Feb 2026 10:29:21 -0500 [thread overview]
Message-ID: <ebd17ac8ab6d1e1ad6a8eb8defa49915@nvidia.com> (raw)
In-Reply-To: <DGIIMT4F1GWA.12UFBEUAC80VW@nvidia.com>
On Thu, Feb 19, 2026 at 09:35:31AM +0900, Alexandre Courbot wrote:
> I saw that v10 has been sent, but since the code is mostly identical
> this review should still apply (I was in the middle of writing it before
> going to sleep).
Thanks for the thorough review, Alex! All comments addressed below.
> > + * Helpers for C Circular doubly linked list implementation.
>
> nit: "Circular" doesn't need a capital "C".
Fixed.
> > +//! # // SAFETY: pointers are to allocated test objects with a list_head field.
> > +//! # unsafe {
> > +//! # (*ptr).value = i as i32 * 10;
> > +//! # // &raw mut computes address of link directly as link is uninitialized.
> > +//! # bindings::INIT_LIST_HEAD(&raw mut (*ptr).link);
> > +//! # bindings::list_add_tail(&mut (*ptr).link, head);
>
> Is the `INIT_LIST_HEAD` line needed? `list_add_tail` will immediately
> overwrite the initial values of `ptr.link`.
Good point - list_add_tail does overwrite the link fields. However I'm
keeping the INIT_LIST_HEAD call because the doctest is meant to show
the full pattern of working with list_head from Rust, including proper
initialization. Also, skipping it would mean calling list_add_tail on
an uninitialized list_head, which while it works in practice (since
list_add_tail overwrites both fields), feels wrong to demonstrate in
an example.
> > +//! let list = unsafe { clist_create!(head, Item, SampleItemC, link) };
>
> `head` appears in the documentation for the first time here - it would
> help to make at least its declaration visible, or add a comment
> specifying its type.
The head declaration is in the hidden doctest setup code (marked with
`# `). Since it's setup code that would be done by C in practice,
keeping it hidden seems right. The SAFETY comment on the clist_create!
call now documents what head is.
> > + pub unsafe fn from_raw<'a>(ptr: *mut bindings::list_head) -> &'a Self {
> > + // SAFETY:
> > + // - [`CList`] has same layout as [`CListHead`] due to repr(transparent).
> > + // - Caller guarantees `ptr` is a valid, sentinel `list_head` object.
> > + unsafe { &*ptr.cast() }
> > + }
>
> IIUC you can call `CListHead::from_raw` here instead of repeating its
> code.
CListHead::from_raw returns &CListHead, but we need &CList<T, OFFSET>.
Since CList is repr(transparent) over CListHead, the direct ptr.cast()
is the correct approach - we'd need an additional cast after
CListHead::from_raw anyway, which would be more code, not less.
> > + fn next(&mut self) -> Option<Self::Item> {
>
> This method is the only one not marked `#[inline]`.
Added #[inline], thanks for catching that.
> > +impl<'a> FusedIterator for CListHeadIter<'a> {}
>
> I asked this a couple of times ([1], [2]) but got no reply, so let me
> try again. :) Given that `list_head` is doubly-linked, can we also
> implement `DoubleEndedIterator`?
Apologies for the missed replies! Yes, DoubleEndedIterator makes sense
for doubly-linked lists. I'll add it as a follow-up patch since it
requires a prev() method and some additional iterator state tracking.
> > +// SAFETY: [`CListHead`] can be sent to any thread.
> > +unsafe impl Send for CListHead {}
>
> That safety comment is circular. I guess you mean to say that
> `list_head` can be sent to any thread?
Fixed. Updated to: "list_head contains no thread-bound state; it only
holds next/prev pointers."
> Since Rust macros let us be more creative, how about something like
> this:
>
> let list = unsafe { clist_create!(head => Item, SampleItemC.link) };
Interesting idea! For now I've kept the current comma-separated syntax
but with the device.rs unsafe pattern:
clist_create!(unsafe { head, Item, SampleItemC, link })
This keeps consistency with other kernel macros. The unsafe { } block
is the key improvement from Danilo's review. We can explore syntax
sugar in a follow-up if desired.
Thanks,
Joel
next prev parent reply other threads:[~2026-02-19 15:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-10 23:32 [PATCH -next v9 0/3] rust: Add CList and GPU buddy allocator bindings Joel Fernandes
2026-02-10 23:32 ` [PATCH -next v9 1/3] rust: clist: Add support to interface with C linked lists Joel Fernandes
2026-02-11 9:23 ` Danilo Krummrich
2026-02-11 17:28 ` Joel Fernandes
2026-02-19 0:35 ` Alexandre Courbot
2026-02-19 0:59 ` Joel Fernandes
2026-02-19 2:47 ` Alexandre Courbot
2026-02-19 15:29 ` Joel Fernandes [this message]
2026-02-19 16:20 ` Joel Fernandes
2026-02-20 1:57 ` Alexandre Courbot
2026-02-10 23:32 ` [PATCH -next v9 2/3] rust: gpu: Add GPU buddy allocator bindings Joel Fernandes
2026-02-10 23:32 ` [PATCH -next v9 3/3] nova-core: mm: Select GPU_BUDDY for VRAM allocation Joel Fernandes
2026-02-11 9:21 ` Danilo Krummrich
2026-02-11 9:19 ` [PATCH -next v9 0/3] rust: Add CList and GPU buddy allocator bindings Danilo Krummrich
2026-02-11 17:30 ` Joel Fernandes
[not found] <20260211-v9-nova-mm-v9-0-a8e261c2e734@nvidia.com>
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=ebd17ac8ab6d1e1ad6a8eb8defa49915@nvidia.com \
--to=joelagnelf@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@redhat.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ndjukic@nvidia.com \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--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