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] [day] [month] [year] [list]
Message-Id: <FF128DEF-28D6-4302-9C53-2DD4D417053A@collabora.com>
Date: Tue, 18 Mar 2025 15:22:37 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Danilo Krummrich <dakr@...nel.org>
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 <benno.lossin@...ton.me>,
 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 v7 3/3] rust: platform: allow ioremap of platform
 resources

Hi Danilo,

> On 18 Mar 2025, at 14:43, Danilo Krummrich <dakr@...nel.org> wrote:
> 
> Hi Daniel,
> 
> On Tue, Mar 18, 2025 at 02:20:43PM -0300, Daniel Almeida wrote:
>> The preceding patches added support for resources, and for a general
>> IoMem abstraction, but thus far there is no way to access said IoMem
>> from drivers, as its creation is unsafe and depends on a resource that
>> must be acquired from some device first.
>> 
>> Now, allow the ioremap of platform resources themselves, thereby making
>> the IoMem available to platform drivers.
>> 
>> Signed-off-by: Daniel Almeida <daniel.almeida@...labora.com>
>> ---
>> rust/kernel/platform.rs | 123 +++++++++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 122 insertions(+), 1 deletion(-)
> 
> You need to rebase this onto driver-core-next.

Right, I totally forgot about this.

> 
>> 
>> diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
>> index 1297f5292ba9b7ca9784f84979efbeccb0768bd3..56f3d7c0d536d77082d7f8d2407de17ee3e95ffa 100644
>> --- a/rust/kernel/platform.rs
>> +++ b/rust/kernel/platform.rs
>> @@ -5,8 +5,14 @@
>> //! C header: [`include/linux/platform_device.h`](srctree/include/linux/platform_device.h)
>> 
>> use crate::{
>> -    bindings, container_of, device, driver,
>> +    bindings, container_of, device,
>> +    devres::Devres,
>> +    driver,
>>     error::{to_result, Result},
>> +    io::{
>> +        mem::{ExclusiveIoMem, IoMem},
>> +        resource::Resource,
>> +    },
>>     of,
>>     prelude::*,
>>     str::CStr,
>> @@ -191,6 +197,121 @@ fn as_raw(&self) -> *mut bindings::platform_device {
>>         // embedded in `struct platform_device`.
>>         unsafe { container_of!(self.0.as_raw(), bindings::platform_device, dev) }.cast_mut()
>>     }
>> +
>> +    /// Maps a platform resource through ioremap() where the size is known at
>> +    /// compile time.
>> +    ///
>> +    /// # Examples
>> +    ///
>> +    /// ```no_run
>> +    /// use kernel::{bindings, c_str, platform};
>> +    ///
>> +    /// fn probe(pdev: &mut platform::Device, /* ... */) -> Result<()> {
>> +    ///     let offset = 0; // Some offset.
>> +    ///
>> +    ///     // If the size is known at compile time, use `ioremap_resource_sized`.
>> +    ///     // No runtime checks will apply when reading and writing.
>> +    ///     let resource = pdev.resource(0).ok_or(ENODEV)?;
>> +    ///     let iomem = pdev.ioremap_resource_sized::<42>(&resource)?;
>> +    ///
>> +    ///     // Read and write a 32-bit value at `offset`. Calling `try_access()` on
>> +    ///     // the `Devres` makes sure that the resource is still valid.
>> +    ///     let data = iomem.try_access().ok_or(ENODEV)?.readl(offset);
>> +    ///
>> +    ///     iomem.try_access().ok_or(ENODEV)?.writel(data, offset);
> 
> I'd probably write this as
> 
> || -> Result {
> let iomem = iomem.try_access().ok_or(ENODEV)?;
> 
> iomem.read32(offset);
> iomem.write32(data, offset);
> 
> Ok(())
> }()?;
> 
> There's also a patch [1] in progress that makes this more convenient.
> 
> [1] https://lore.kernel.org/rust-for-linux/20250313-try_with-v1-1-adcae7ed98a9@nvidia.com/

Thanks!

— Daniel



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ