From: John Hubbard <jhubbard@nvidia.com>
To: Joel Fernandes <joelagnelf@nvidia.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
Danilo Krummrich <dakr@kernel.org>,
Dave Airlie <airlied@gmail.com>
Cc: Alexandre Courbot <acourbot@nvidia.com>,
Alistair Popple <apopple@nvidia.com>,
Miguel Ojeda <ojeda@kernel.org>,
Alex Gaynor <alex.gaynor@gmail.com>,
Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>,
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>, Simona Vetter <simona@ffwll.ch>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Timur Tabi <ttabi@nvidia.com>,
Joel Fernandes <joel@joelfernandes.org>,
Lyude Paul <elle@weathered-steel.dev>,
Daniel Almeida <daniel.almeida@collabora.com>,
Andrea Righi <arighi@nvidia.com>,
Philipp Stanner <phasta@kernel.org>
Subject: Re: [PATCH v3] rust: clist: Add support to interface with C linked lists
Date: Mon, 1 Dec 2025 14:17:17 -0800 [thread overview]
Message-ID: <497c91a2-ca6c-4e05-bc5e-7c3818302c7e@nvidia.com> (raw)
In-Reply-To: <7a88da9f-c67b-4a68-b8d6-a66f9096bab4@nvidia.com>
On 12/1/25 12:32 PM, Joel Fernandes wrote:
> On 11/30/2025 7:34 PM, John Hubbard wrote:
>> On 11/29/25 1:30 PM, Joel Fernandes wrote:
...
>> This is sufficiently tricky that I think it needs some code to exercise it.
>>
>> Lately I'm not sure what to recommend, there are several choices, each with
>> trade-offs: kunit, samples/rust, or even new DRM Rust code. Maybe the last
>> one is especially nice, because it doesn't really have many downsides.
>>
>> Rather than wait for any of that, I wrote a quick samples/rust/rust_clist.rs
>> and used it to sanity check my review findings, which are below.
>
> In v1, I had a samples/rust/ patch, but everyone's opinion almost unanimously
> was this does not belong in a sample, but rather in doctests. What in the sample
> is not supported by the current doctest? If something is missing, I think I can
> add it in. Plus yes, DRM_BUDDY is going to be a consumer shortly.
Well, I won't contest the choice of doctests, since wiser heads than mine
have already worked through the tradeoffs.
But for API developers, the problem with doctests is that no one has ever
actually *run* the code. It's just a build test. And so critical bugs, such
as the kernel crash/hang below, are missed.
I would humbly suggest that you build and *run* your own samples code, for
new code that has no users yet.
Because if you are skipping steps like this (posting the code before
there is an actual caller), then the documentation of how to use it
is not "just documentation" anymore--it really needs to run correctly.
And actually, after writing the above...I still think it would be better
to post this with its first caller (DRM_BUDDY, or BUDDY_DRM_ALUMNI, or
however it ends up), so that we can see how it looks and behaves in
practice.
What's the rush?
...
>> The fix requires two-step initialization, like this, for example:
>
> It has nothing to do with 2-step initialization. The issue is only related to
> the HEAD (and not the items) right? The issue is `assume_init()` should not be
> used on self-referential structures, the fix just one line:
>
> -//! # unsafe { init_list_head(head.as_mut_ptr()) };
> -//! # let mut head = unsafe { head.assume_init() };
>
> +//! # let head = head.as_mut_ptr();
> +//! # unsafe { init_list_head(head) };
>
> Does that fix the issue in your private sample test too?
>
> Or did I miss what you're suggesting?
>
Yes, you are correct: the main point is to avoid moving a struct
that contains self-referential fields. So your version is a more
accurate and better fix.
...
>>> +pub struct Clist<'a, T> {
>>> + head: &'a ClistHead,
>>> + offset: usize,
>>> + _phantom: PhantomData<&'a T>,
>>> +}
>>
>> This discards build-time (const generic) information, and demotes it to
>> runtime (.offset), without any real benefit. I believe it's better to keep
>> it as a const generic, like this:
>>
>> pub struct Clist<'a, T, const OFFSET: usize> {
>> head: &'a ClistHead,
>> _phantom: PhantomData<&'a T>,
>> }
>>
>>> +
>>> +impl<'a, T> Clist<'a, T> {
>>
>> And here, the above becomes:
>>
>> impl<'a, T, const OFFSET: usize> Clist<'a, T, OFFSET> {
>>
>> ...etc.
>
> It is not ignored, the const-generic part only applies to the constructor method
> in my patch. I didn't want to add another argument to the diamond brackets, the
> type name looks really ugly then.
>
The macro hides it, though. Users never have to write the full type.
Increasing const-ness is worth something. The messy syntax is unfortunate,
but I don't really know what to say there.
> The only advantage I think of doing this (inspite of the obvious aesthetic
> disadvantage) is that a mutable `Clist` cannot have its offset modified. Let me
> see if I can get Alice's suggestion to make it a const in the struct work to
> solve that.
Yes. I have it working locally, so I'm confident that you will prevail. :)
thanks,
--
John Hubbard
next prev parent reply other threads:[~2025-12-01 22:18 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-29 21:30 [PATCH v3] rust: clist: Add support to interface with C linked lists Joel Fernandes
2025-12-01 0:34 ` John Hubbard
2025-12-01 20:32 ` Joel Fernandes
2025-12-01 20:57 ` Joel Fernandes
2025-12-01 22:17 ` John Hubbard [this message]
2025-12-01 22:43 ` Joel Fernandes
2025-12-01 22:52 ` John Hubbard
2025-12-01 23:09 ` Joel Fernandes
2025-12-01 23:15 ` John Hubbard
2025-12-01 23:21 ` Joel Fernandes
2025-12-01 22:58 ` Miguel Ojeda
2025-12-01 22:50 ` Miguel Ojeda
2025-12-01 22:54 ` John Hubbard
2025-12-01 15:25 ` Alice Ryhl
2025-12-01 21:35 ` Joel Fernandes
2025-12-01 16:51 ` Daniel Almeida
2025-12-01 19:35 ` John Hubbard
2025-12-01 20:06 ` Joel Fernandes
2025-12-01 23:01 ` Daniel Almeida
2025-12-01 23:23 ` Joel Fernandes
2025-12-01 22:54 ` Daniel Almeida
2025-12-01 22:58 ` Miguel Ojeda
2025-12-01 21:46 ` Joel Fernandes
2025-12-03 13:06 ` Alexandre Courbot
2025-12-03 15:08 ` Joel Fernandes
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=497c91a2-ca6c-4e05-bc5e-7c3818302c7e@nvidia.com \
--to=jhubbard@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=arighi@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=elle@weathered-steel.dev \
--cc=gary@garyguo.net \
--cc=joel@joelfernandes.org \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=phasta@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=tzimmermann@suse.de \
/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).