lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DG22Q420ISG8.169OONC5IKK7I@kernel.org>
Date: Fri, 30 Jan 2026 17:44:53 +0100
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Gary Guo" <gary@...yguo.net>
Cc: "Alexandre Courbot" <acourbot@...dia.com>, "Alice Ryhl"
 <aliceryhl@...gle.com>, "Daniel Almeida" <daniel.almeida@...labora.com>,
 "Miguel Ojeda" <ojeda@...nel.org>, "Boqun Feng" <boqun.feng@...il.com>,
 Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
 <lossin@...nel.org>, "Andreas Hindborg" <a.hindborg@...nel.org>, "Trevor
 Gross" <tmgross@...ch.edu>, "Yury Norov" <yury.norov@...il.com>, "John
 Hubbard" <jhubbard@...dia.com>, "Alistair Popple" <apopple@...dia.com>,
 "Joel Fernandes" <joelagnelf@...dia.com>, "Timur Tabi" <ttabi@...dia.com>,
 "Edwin Peer" <epeer@...dia.com>, "Eliot Courtney" <ecourtney@...dia.com>,
 "Dirk Behme" <dirk.behme@...bosch.com>, "Steven Price"
 <steven.price@....com>, <rust-for-linux@...r.kernel.org>,
 <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 5/7] rust: io: add `register!` macro

On Fri Jan 30, 2026 at 5:14 PM CET, Gary Guo wrote:
> On Fri Jan 30, 2026 at 6:55 AM GMT, Alexandre Courbot wrote:
>> No, I'm starting to believe that the fundamental issue is that the
>> register interface does its I/O backwards, and that design issue is only
>> exacerbated by the recent I/O redesign. I.e. instead of doing
>>
>>   regs::NV_PMC_BOOT_0::read(bar);
>>
>> We should really do
>>
>>   bar.read_reg::<regs::NV_PMC_BOOT_0>();
>>
>> Because that way we can use deref coercion.
>>
>> That's quite a big redesign though, which means I don't believe
>> `register!` can make it this cycle... I'll give it a try though.
>
> Hmm, that's unfortunate, but I think this is indeed a big design change that we
> should iron out before merging...
>
> I think you're right that if we put the methods on `Io` then all of the deref
> issue would just went away.

I already discussed this with Alex offline and I think we should not take this
direction just because of the Deref issue, as we can easily overcome this with
using AsRef (or a custom trait).

Whereas the downside of bar.read_reg() is that you end up with a more
inconsistent and complicated API for drivers.

For instance, with the API as is you can do things like:

	register!(NV_PFALCON_FALCON_ENGINE @ PFalconBase[0x000003c0] {
	    0:0     reset as bool;
	});
	
	impl NV_PFALCON_FALCON_ENGINE {
	    pub(crate) fn reset_engine<E: FalconEngine>(bar: &Bar0) {
	        Self::update(bar, &E::ID, |r| r.set_reset(true));
	
	        // TIMEOUT: falcon engine should not take more than 10us to reset.
	        time::delay::fsleep(time::Delta::from_micros(10));
	
	        Self::update(bar, &E::ID, |r| r.set_reset(false));
	    }
	}

and then use this from the driver code like this:

	impl<E: FalconEngine> FalconHal<E> for Tu102<E> {
	    fn do_stuff(&self, bar: &Bar0) {
	        //...
	
	        regs::NV_PFALCON_FALCON_ENGINE::reset_engine::<E>(bar);

	        //...
	    }
	}

Having to implement AsRef (or a custom trait) for the corresponding I/O backend
implementations is a pretty minor inconvinience compared to the simplicity the
current API provides to drivers.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ