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: <DBG2XI0UZ3B5.I9KLFJUYQUMC@kernel.org>
Date: Sat, 19 Jul 2025 15:51:59 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Daniel Almeida" <daniel.almeida@...labora.com>
Cc: "Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor"
 <alex.gaynor@...il.com>, "Boqun Feng" <boqun.feng@...il.com>, "Gary Guo"
 <gary@...yguo.net>, Björn Roy Baron
 <bjorn3_gh@...tonmail.com>, "Benno Lossin" <lossin@...nel.org>, "Andreas
 Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
 "Trevor Gross" <tmgross@...ch.edu>, "Greg Kroah-Hartman"
 <gregkh@...uxfoundation.org>, "Rafael J. Wysocki" <rafael@...nel.org>,
 <linux-kernel@...r.kernel.org>, <rust-for-linux@...r.kernel.org>
Subject: Re: [PATCH v15 2/3] rust: io: mem: add a generic iomem abstraction

On Thu Jul 17, 2025 at 5:55 PM CEST, Daniel Almeida wrote:
> +    /// Maps an [`IoRequest`] where the size is known at compile time.
> +    ///
> +    /// This uses the [`ioremap()`] C API.
> +    ///
> +    /// [`ioremap()`]: https://docs.kernel.org/driver-api/device-io.html#getting-access-to-the-device
> +    ///
> +    /// # Examples
> +    ///
> +    /// The following example uses a [`platform::Device`] for illustration
> +    /// purposes.
> +    ///
> +    /// ```no_run
> +    /// use kernel::{bindings, c_str, platform, of, device::Core};
> +    /// struct SampleDriver;
> +    ///
> +    /// impl platform::Driver for SampleDriver {
> +    ///    # type IdInfo = ();
> +    ///    # const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
> +    ///
> +    ///    fn probe(
> +    ///       pdev: &platform::Device<Core>,
> +    ///       info: Option<&Self::IdInfo>,
> +    ///    ) -> Result<Pin<KBox<Self>>> {
> +    ///       let offset = 0; // Some offset.
> +    ///
> +    ///       // If the size is known at compile time, use [`Self::iomap_sized`].
> +    ///       //
> +    ///       // No runtime checks will apply when reading and writing.
> +    ///       let request = pdev.io_request_by_index(0).ok_or(ENODEV)?;
> +    ///       let iomem = request.iomap_sized::<42>();
> +    ///       let iomem = KBox::pin_init(iomem, GFP_KERNEL)?;
> +    ///
> +    ///       let io = iomem.access(pdev.as_ref())?;
> +    ///
> +    ///       // Read and write a 32-bit value at `offset`.
> +    ///       let data = io.read32_relaxed(offset);
> +    ///
> +    ///       io.write32_relaxed(data, offset);
> +    ///
> +    ///       # Ok(KBox::new(SampleDriver, GFP_KERNEL)?.into())
> +    ///     }
> +    /// }
> +    /// ```
> +    pub fn iomap_sized<const SIZE: usize>(self) -> impl PinInit<Devres<IoMem<SIZE>>, Error> + 'a {
> +        IoMem::new(self)
> +    }

This doc-test and the one below break the build, since the used platform device
infrastructure is introduced with the next patch.

I can set them to `ignore` and we turn them into `no_run` with a subsequent
patch.

> +    /// Maps an [`IoRequest`] where the size is not known at compile time,
> +    ///
> +    /// This uses the [`ioremap()`] C API.
> +    ///
> +    /// [`ioremap()`]: https://docs.kernel.org/driver-api/device-io.html#getting-access-to-the-device
> +    ///
> +    /// # Examples
> +    ///
> +    /// The following example uses a [`platform::Device`] for illustration
> +    /// purposes.
> +    ///
> +    /// ```no_run
> +    /// use kernel::{bindings, c_str, platform, of, device::Core};
> +    /// struct SampleDriver;
> +    ///
> +    /// impl platform::Driver for SampleDriver {
> +    ///    # type IdInfo = ();
> +    ///    # const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
> +    ///
> +    ///    fn probe(
> +    ///       pdev: &platform::Device<Core>,
> +    ///       info: Option<&Self::IdInfo>,
> +    ///    ) -> Result<Pin<KBox<Self>>> {
> +    ///       let offset = 0; // Some offset.
> +    ///
> +    ///       // Unlike [`Self::iomap_sized`], here the size of the memory region
> +    ///       // is not known at compile time, so only the `try_read*` and `try_write*`
> +    ///       // family of functions should be used, leading to runtime checks on every
> +    ///       // access.
> +    ///       let request = pdev.io_request_by_index(0).ok_or(ENODEV)?;
> +    ///       let iomem = request.iomap();
> +    ///       let iomem = KBox::pin_init(iomem, GFP_KERNEL)?;
> +    ///
> +    ///       let io = iomem.access(pdev.as_ref())?;
> +    ///
> +    ///       let data = io.try_read32_relaxed(offset)?;
> +    ///
> +    ///       io.try_write32_relaxed(data, offset)?;
> +    ///
> +    ///       # Ok(KBox::new(SampleDriver, GFP_KERNEL)?.into())
> +    ///     }
> +    /// }
> +    /// ```
> +    pub fn iomap(self) -> impl PinInit<Devres<IoMem<0>>, Error> + 'a {
> +        Self::iomap_sized::<0>(self)
> +    }
> +
> +    /// Same as [`Self::iomap`] but with exclusive access to the underlying
> +    /// region.
> +    pub fn iomap_exclusive(self) -> impl PinInit<Devres<ExclusiveIoMem<0>>, Error> + 'a {
> +        Self::iomap_exclusive_sized::<0>(self)
> +    }
> +}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ