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: <aDdQmJ-pen_MQNDB@cassiopeiae>
Date: Wed, 28 May 2025 20:06:16 +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 <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>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
	Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
	Bjorn Helgaas <bhelgaas@...gle.com>,
	Mika Westerberg <mika.westerberg@...ux.intel.com>,
	Ying Huang <huang.ying.caritas@...il.com>,
	linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v8 3/3] rust: platform: allow ioremap of platform
 resources

On Wed, May 28, 2025 at 02:29:44PM -0300, Daniel Almeida wrote:
> Hi Danilo,
> 
> […]
> 
> > 
> >> +    ///     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)?.read32_relaxed(offset);
> >> +    ///
> >> +    ///     iomem.try_access().ok_or(ENODEV)?.write32_relaxed(data, offset);
> > 
> > Since this won't land for v6.16, can you please use Devres::access() [1]
> > instead? I.e.
> > 
> > let iomem = pdev.ioremap_resource_sized::<42>(&resource)?;
> > let io = Devres::access(pdev.as_ref())?;
> > 
> > let data = io.read32_relaxed(offset);
> > io.write32_relaxed(data, offset);
> > 
> > Devres::access() is in nova-next and lands in v6.16.
> > 
> > [1] https://gitlab.freedesktop.org/drm/nova/-/commit/f301cb978c068faa8fcd630be2cb317a2d0ec063
> 
> Devres:access takes &Device<Bound>, but the argument in probe() is
> &Device<Core>.
> 
> Are these two types supposed to convert between them? I see no explicit
> function to do so.

Yes, it comes from impl_device_context_deref!() [1], which, as the name implies,
implements the corresponding Deref traits.

Device dereference in the following way:

	&Device<Core> -> &Device<Bound> -> &Device (i.e. &Device<Normal>)

You can just pass in the &Device<Core>, it will work.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/tree/rust/kernel/device.rs?h=driver-core-next#n284

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ