From: "Gary Guo" <gary@garyguo.net>
To: "Danilo Krummrich" <dakr@kernel.org>,
"Eliot Courtney" <ecourtney@nvidia.com>
Cc: "Gary Guo" <gary@garyguo.net>, "Yury Norov" <ynorov@nvidia.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Burak Emir" <burak.emir@gmail.com>,
"Yury Norov" <yury.norov@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"John Hubbard" <jhubbard@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Timur Tabi" <ttabi@nvidia.com>, "Zhi Wang" <zhiw@nvidia.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
dri-devel <dri-devel-bounces@lists.freedesktop.org>
Subject: Re: [PATCH v5 5/5] gpu: nova-core: add ChannelIdPool
Date: Mon, 17 Aug 2026 14:02:38 +0100 [thread overview]
Message-ID: <DKR8MCRB76L2.1TV4D7261PVTH@garyguo.net> (raw)
In-Reply-To: <DKR7N2LLIQZH.25F7VF4CET6PO@kernel.org>
On Mon Aug 17, 2026 at 1:16 PM BST, Danilo Krummrich wrote:
> On Mon Aug 17, 2026 at 1:49 PM CEST, Eliot Courtney wrote:
>> On Mon Aug 17, 2026 at 8:18 PM JST, Danilo Krummrich wrote:
>>> On Mon Aug 17, 2026 at 12:54 PM CEST, Gary Guo wrote:
>>>> IMO we can just support zero-sized allocation by always succeeding, similar to
>>>> how ZST allocation is handled in memory allocation.
>>>
>>> Probably, but in contrast to ZST allocations it wouldn't be very useful, so we'd
>>> silently succeed on something that never was a reasonable argument in the first
>>> palce.
>>
>> Yeah I agree that supporting a generalised zero sized alloc is in some
>> ways conceptually nicer, but I also can't see any good reason why you
>> would want to do it, it sounds like a bug. That's also why in the latest
>> version I made IdPool also not allow a zero capacity [1] (incidentally
>> required to not have to change the grow code to avoid trying to double a
>> zero capacity thing every time).
>
> (I assume this is more a reply to Gary?)
>
>> Tbh, I feel that NonZero (and Alignment) is hard to use currently
>> because of these ergonomics issues. But I reckon they're useful, so I
>> like the idea of trying to making them easier to use. Maybe you can make
>> an argument to not use NonZero here, but what about all the other times
>> we will want to use it?
>
> Personally, I don't see the argument for not using NonZero (or Alignment); the
> invariants required by the API are expressed very well by those types.
>
> I also don't see a reason to step back from using those types for this API. If
> we'd do so it would question all the other new types we have over primitives
> carrying certain invariants to a certain extend as well.
I think there is an distinction between semantic differences vs just range
restrictions. Consider the other cases where we use new types:
* flags: very natural as you don't even need to mention raw literals.
* units: for things that semantically carry a unit, writing things like
`Delta::new_jiffies(...)` is quite natural, just like writing "2 seconds"
* addresses: things like dma addresses naturally fit in new types because you
don't need to write literals for them.
Now, with `NonZero` or `Bounded`, we are doing none of that. The only thing here
is that there is a range restriction. Other than the value restriction
themselves, they carry no other semantic meanings. How you interpret these types
still fully depend on the API that accepts them. Therefore, it is very common
that you'd be using these with literals, and it becomes an ergnomic pain.
If Rust pattern types become available in the future and you can write
fn alloc_area(&self, count: usize is 1..)
then I'd fully support adding that annotation to functions. Personally I value
ergnomics higher than possibility of misuse if latter can be easily mitigated
otherwise (in this case, by WARN_ON or just support zero-sized alloc).
Best,
Gary
>
> I understand the ergonomics concern, and I also see that for compile time
> evaluation turbofish syntax is not that popular, but this can be improved.
>
> The fundamental value remains that it nicely separates the invariants callers
> need to uphold about certain arguments from the API itself. It makes the code
> more maintainable (e.g. we don't need 10 different variants of a function
> depending on whether the value is a compile time, build time or run time value)
> and it makes the code more readable and robust (e.g. the semantic meaning of
> arguments is very obvious and confusing arguments becomes almost impossible).
next prev parent reply other threads:[~2026-08-17 13:02 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 8:51 [PATCH v5 0/5] rust: Add support for reserving of ranges of IDs Eliot Courtney
2026-08-12 8:51 ` [PATCH v5 1/5] rust: bitmap: use function-level cfg on kunit test Eliot Courtney
2026-08-12 22:23 ` Yury Norov
2026-08-12 8:51 ` [PATCH v5 2/5] rust: bitmap: restrict bitmap length to at most i32::MAX Eliot Courtney
2026-08-12 19:44 ` Yury Norov
2026-08-12 8:51 ` [PATCH v5 3/5] rust: bitmap: add contiguous area operations Eliot Courtney
2026-08-12 20:31 ` Yury Norov
2026-08-13 7:27 ` Eliot Courtney
2026-08-12 8:51 ` [PATCH v5 4/5] rust: id_pool: add contiguous area allocation Eliot Courtney
2026-08-12 21:16 ` Yury Norov
2026-08-13 7:29 ` Eliot Courtney
2026-08-12 8:51 ` [PATCH v5 5/5] gpu: nova-core: add ChannelIdPool Eliot Courtney
2026-08-12 22:18 ` Yury Norov
2026-08-13 7:31 ` Eliot Courtney
2026-08-13 18:32 ` Yury Norov
2026-08-13 20:20 ` Miguel Ojeda
2026-08-13 20:48 ` Danilo Krummrich
2026-08-13 20:58 ` Gary Guo
2026-08-13 21:38 ` John Hubbard
2026-08-13 21:44 ` Yury Norov
2026-08-13 21:53 ` John Hubbard
2026-08-13 21:03 ` Yury Norov
2026-08-14 2:14 ` Eliot Courtney
2026-08-14 4:54 ` Eliot Courtney
2026-08-14 9:08 ` Yury Norov
2026-08-14 14:53 ` Yury Norov
2026-08-17 7:03 ` Eliot Courtney
2026-08-17 10:54 ` Gary Guo
2026-08-17 11:18 ` Danilo Krummrich
2026-08-17 11:49 ` Eliot Courtney
2026-08-17 12:16 ` Danilo Krummrich
2026-08-17 12:37 ` Eliot Courtney
2026-08-17 13:02 ` Gary Guo [this message]
2026-08-17 14:08 ` Danilo Krummrich
2026-08-17 21:36 ` Burak Emir
2026-08-18 7:18 ` Miguel Ojeda
2026-08-17 22:40 ` Yury Norov
2026-08-18 6:41 ` Miguel Ojeda
2026-08-18 13:55 ` Danilo Krummrich
2026-08-17 20:20 ` Yury Norov
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=DKR8MCRB76L2.1TV4D7261PVTH@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=burak.emir@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel-bounces@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=gregkh@linuxfoundation.org \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=work@onurozkan.dev \
--cc=ynorov@nvidia.com \
--cc=yury.norov@gmail.com \
--cc=zhiw@nvidia.com \
/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