NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Gary Guo" <gary@garyguo.net>
Cc: "Alexandre Courbot" <acourbot@nvidia.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>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Onur Özkan" <work@onurozkan.dev>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	"Zhi Wang" <zhiw@nvidia.com>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/2] rust: add functions and traits for lossless integer conversions
Date: Mon, 27 Jul 2026 13:19:35 +0200	[thread overview]
Message-ID: <DK9BA0QUVUGT.2ZB6EESQOXCS3@kernel.org> (raw)
In-Reply-To: <DK9A6KGK5JQD.3U23MBEMSAXBK@garyguo.net>

On Mon Jul 27, 2026 at 12:28 PM CEST, Gary Guo wrote:
> On Mon Jul 27, 2026 at 11:15 AM BST, Alexandre Courbot wrote:
>> The core library's `From` implementations do not cover conversions that
>> are not portable or future-proof. For instance, even though it is safe
>> today, `From<usize>` is not implemented for `u64` because of the
>> possibility of supporting larger-than-64bit architectures in the future.
>>
>> However, the kernel supports a narrower set of architectures, with a
>> considerable amount of code that is architecture-specific. This makes it
>> helpful and desirable to provide more infallible conversions, lest we
>> need to rely on the `as` keyword and carry the risk of silently losing
>> data.
>>
>> Thus, introduce a new module `num::casts` that provides safe const
>> functions performing more conversions allowed by the build target, as
>> well as `FromSafeCast` and `IntoSafeCast` traits that are just
>> extensions of `From` and `Into` to conversions that are known to be
>> lossless.
>
> I'm okay with having u32 -> usize casts and usize -> u64 casts, but having
> usize -> u32 and u64 -> usize casts like this series do is worrying as it can be
> misused from drivers that are supposed to be supporting multiple platforms or
> core subsystems.
>
> Pointer-size dependent drivers that need these casts should define them locally.

I also raised this concern in the context of [1]. On the other hand, it is not
as if this can "randomly" break with exotic or niche kernel configs; 32bit vs.
64bit compile tests are well covered.

So, as long as we are explicit about it, I think it should be fine. Maybe we can
export the non-portable ones with a different name?

[1] https://lore.kernel.org/driver-core/DK0BPAHR8IS3.2KLSLH7K448RJ@kernel.org/

  parent reply	other threads:[~2026-07-27 11:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 10:15 [PATCH 0/2] rust: add functions and traits for lossless integer conversions Alexandre Courbot
2026-07-27 10:15 ` [PATCH 1/2] " Alexandre Courbot
2026-07-27 10:28   ` Gary Guo
2026-07-27 11:10     ` Miguel Ojeda
2026-07-27 11:19     ` Danilo Krummrich [this message]
2026-07-27 10:15 ` [PATCH 2/2] gpu: nova-core: use kernel lossless integer conversion module Alexandre Courbot

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=DK9BA0QUVUGT.2ZB6EESQOXCS3@kernel.org \
    --to=dakr@kernel.org \
    --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=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --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=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