mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joel Fernandes <joelagnelf@nvidia.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"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>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"nouveau@lists.freedesktop.org" <nouveau@lists.freedesktop.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"rust-for-linux@vger.kernel.org" <rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH 1/2] nova-core: Add a library for bitfields in Rust structs
Date: Thu, 4 Sep 2025 11:33:53 +0000	[thread overview]
Message-ID: <DEC556AB-8E6F-475B-AF9F-11973F7A92B1@nvidia.com> (raw)
In-Reply-To: <DCJTY0OQFG83.1AX49CQARXCEX@kernel.org>



> On Sep 4, 2025, at 3:16 AM, Danilo Krummrich <dakr@kernel.org> wrote:
> 
> On Thu Sep 4, 2025 at 5:16 AM CEST, Alexandre Courbot wrote:
>> On Thu Sep 4, 2025 at 12:15 AM JST, Joel Fernandes wrote:
>> <snip>
>>>>> +use kernel::prelude::*;
>>>>> +
>>>>> +/// Macro for defining bitfield-packed structures in Rust.
>>>>> +/// The size of the underlying storage type is specified with #[repr(TYPE)].
>>>>> +///
>>>>> +/// # Example (just for illustration)
>>>>> +/// ```rust
>>>>> +/// bitstruct! {
>>>>> +///     #[repr(u64)]
>>>>> +///     pub struct PageTableEntry {
>>>>> +///         0:0       present     as bool,
>>>>> +///         1:1       writable    as bool,
>>>>> +///         11:9      available   as u8,
>>>>> +///         51:12     pfn         as u64,
>>>>> +///         62:52     available2  as u16,
>>>>> +///         63:63     nx          as bool,
>>>> 
>>>> A note on syntax: for nova-core, we may want to use the `H:L` notation,
>>>> as this is what OpenRM uses, but in the larger kernel we might want to
>>>> use inclusive ranges (`L..=H`) as it will look more natural in Rust
>>>> code (and is the notation the `bits` module already uses).
>>> 
>>> Perhaps future add-on enhancement to have both syntax? I'd like to initially
>>> keep H:L and stabilize the code first, what do you think?
>> 
>> Let's have the discussion with the other stakeholders (Daniel?). I think
>> in Nova we want to keep the `H:L` syntax, as it matches what the OpenRM
>> headers do (so Nova would have its own `register` macro that calls into
>> the common one, tweaking things as it needs). But in the kernel crate we
>> should use something intuitive for everyone.
> 
> I don't care too much about whether it's gonna be H:L or L:H [1], but I do care
> about being consistent throughout the kernel. Let's not start the practice of
> twisting kernel APIs to NV_* specific APIs that differ from what people are used
> to work with in the kernel.
> 
> [1] If it's gonna be H:L, I think we should also list things in reverse order,
>    i.e.:
> 
>    pub struct PageTableEntry {
>        63:63     nx          as bool,
>        62:52     available2  as u16,
>        51:12     pfn         as u64,
>        11:9      available   as u8,
>        1:1       writable    as bool,
>        0:0       present     as bool,
>    }
> 
> This is also what would be my preferred style for the kernel in general.

Sure, that only means I have to change the example code since the
macro itself already supports that. I can do that.

Thanks.





> 
> - Danilo

  parent reply	other threads:[~2025-09-04 11:33 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-24 13:59 Joel Fernandes
2025-08-24 13:59 ` [PATCH 2/2] nova-core: Add KUNIT tests for bitstruct Joel Fernandes
2025-08-24 17:37 ` [PATCH 1/2] nova-core: Add a library for bitfields in Rust structs John Hubbard
2025-08-25  4:14 ` Boqun Feng
2025-08-25  4:16   ` Joel Fernandes
2025-08-25 10:42     ` Alexandre Courbot
2025-08-25 10:46 ` Danilo Krummrich
2025-09-09 19:07   ` Joel Fernandes
2025-08-25 11:07 ` Alexandre Courbot
2025-09-03 15:15   ` Joel Fernandes
2025-09-04  3:16     ` Alexandre Courbot
2025-09-04  7:16       ` Danilo Krummrich
2025-09-04 11:06         ` Alexandre Courbot
2025-09-05 21:29           ` John Hubbard
2025-09-06  1:58             ` Alexandre Courbot
2025-09-04 11:33         ` Joel Fernandes [this message]
2025-09-04 11:02       ` Daniel Almeida
2025-09-04 11:32       ` Joel Fernandes
2025-08-25 23:20 ` Elle Rhumsaa
2025-09-03 21:52   ` Joel Fernandes
2025-09-03 13:29 ` Daniel Almeida
2025-09-03 17:54   ` Joel Fernandes
2025-09-04 21:35 ` Yury Norov
2025-09-05 18:45   ` 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=DEC556AB-8E6F-475B-AF9F-11973F7A92B1@nvidia.com \
    --to=joelagnelf@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=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --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

all inboxes | Powered by JetHome®