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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251114180650.7f74ea13.zhiw@nvidia.com>
Date: Fri, 14 Nov 2025 18:06:50 +0200
From: Zhi Wang <zhiw@...dia.com>
To: Alexandre Courbot <acourbot@...dia.com>
CC: <rust-for-linux@...r.kernel.org>, <linux-pci@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>, <dakr@...nel.org>, <aliceryhl@...gle.com>,
	<bhelgaas@...gle.com>, <kwilczynski@...nel.org>, <ojeda@...nel.org>,
	<alex.gaynor@...il.com>, <boqun.feng@...il.com>, <gary@...yguo.net>,
	<bjorn3_gh@...tonmail.com>, <lossin@...nel.org>, <a.hindborg@...nel.org>,
	<tmgross@...ch.edu>, <markus.probst@...teo.de>, <helgaas@...nel.org>,
	<cjia@...dia.com>, <smitra@...dia.com>, <ankita@...dia.com>,
	<aniketa@...dia.com>, <kwankhede@...dia.com>, <targupta@...dia.com>,
	<joelagnelf@...dia.com>, <jhubbard@...dia.com>, <zhiwang@...nel.org>
Subject: Re: [PATCH v6 RESEND 5/7] rust: io: factor out MMIO read/write
 macros

On Thu, 13 Nov 2025 16:36:47 +0900
"Alexandre Courbot" <acourbot@...dia.com> wrote:


> I understand the intent from the commit message, but this is starting
> to look like an intricate maze of macro expansion and it might not be
> as easy for first-time readers - could you add an explanatory
> doccomment for these?
> 

Sure.

> > +
> >  macro_rules! define_read {
> > -    (infallible, $(#[$attr:meta])* $vis:vis $name:ident,
> > $c_fn:ident -> $type_name:ty) => {
> > +    (infallible, $(#[$attr:meta])* $vis:vis $name:ident,
> > $call_macro:ident, $c_fn:ident ->
> > +     $type_name:ty) => {
> >          /// Read IO data from a given offset known at compile time.
> >          ///
> >          /// Bound checks are performed on compile time, hence if
> > the offset is not known at compile @@ -135,12 +161,13 @@
> > macro_rules! define_read { $vis fn $name(&self, offset: usize) ->
> > $type_name { let addr = self.io_addr_assert::<$type_name>(offset);
> >  
> > -            // SAFETY: By the type invariant `addr` is a valid
> > address for MMIO operations.
> > -            unsafe { bindings::$c_fn(addr as *const c_void) }
> > +            // SAFETY: By the type invariant `addr` is a valid
> > address for IO operations.
> > +            $call_macro!(infallible, $c_fn, self, $type_name, addr)
> >          }
> >      };
> 
> To convey the fact that `$c_fn` is passed to `$call_macro`, how about
> changing the syntax to something like 
> 
>   `define_read(infallible, $vis $name $call_macro($c_fn) ->
> $type_name`
> 
> ?

Then the macros will look like:

define_read!(infallible, pub read32 call_mmio_read!(ioread32) -> u32);
define_write!(infallible, pub write32 call_mmio_write!(iowrite32) ->
u32);

The readability is indeed better - I’ll take that, thanks. :)

Z.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ