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: <aNa069wZv1cn8VGh@tardis.local>
Date: Fri, 26 Sep 2025 08:44:43 -0700
From: Boqun Feng <boqun.feng@...il.com>
To: phasta@...nel.org
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...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>,
	Danilo Krummrich <dakr@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>,	Ingo Molnar <mingo@...hat.com>,
 Will Deacon <will@...nel.org>,	Waiman Long <longman@...hat.com>,
	Nathan Chancellor <nathan@...nel.org>,
	Nick Desaulniers <nick.desaulniers+lkml@...il.com>,
	Bill Wendling <morbo@...gle.com>,	Justin Stitt <justinstitt@...gle.com>,
	Sumit Semwal <sumit.semwal@...aro.org>,
	Christian König <christian.koenig@....com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Viresh Kumar <viresh.kumar@...aro.org>,
	Asahi Lina <lina+kernel@...hilina.net>,
	Daniel Almeida <daniel.almeida@...labora.com>,
	Tamir Duberstein <tamird@...il.com>,
	Wedson Almeida Filho <wedsonaf@...il.com>,
	FUJITA Tomonori <fujita.tomonori@...il.com>,
	Krishna Ketan Rai <prafulrai522@...il.com>,
	Lyude Paul <lyude@...hat.com>,	Mitchell Levy <levymitchell0@...il.com>,
	linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org,
	llvm@...ts.linux.dev, dri-devel@...ts.freedesktop.org
Subject: Re: [RFC PATCH] rust: sync: Add dma_fence abstractions

On Fri, Sep 26, 2025 at 10:48:06AM +0200, Philipp Stanner wrote:
[..]
> > > 
> > > Regarding the manually created spinlock of mine: I so far never need
> > > that spinlock anywhere in Rust and wasn't sure what's then the best way
> > > to pass a "raw" spinlock to C.
> > > 
> > 
> > You can use `SpinLock<()>` for this purpose, no need to add new
> > bindings.
> 
> The dma_fence C backend needs a spinlock pointer, given to it by the
> driver (so Rust code).
> 
> How do I pass a SpinLock<()> to a C function? AFAICS SpinLock doesn't
> implement as_raw(), so I'd have to implement it, wouldn't I?
> 

Technically you can use a `&raw` to get the address of the spinlock and
just use it, since `SpinLock<()>` is `repr(C)`, so it's transparent to a 
spinlock_t. So you don't have to ;-)

However, while we are at it, it makes sense that we do it right.

> Or rather, as it looks, I'd have to implement it for SpinLockBackend?
> 

I think the below should work, we already have a special from_raw() for
Lock<()>, it makes sense to have a special as_raw() as well.

Let me know if you want me to send a proper patch, or feel free to add
one in your patchset ;-)

diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
index 27202beef90c..78f3287a1372 100644
--- a/rust/kernel/sync/lock.rs
+++ b/rust/kernel/sync/lock.rs
@@ -160,6 +160,13 @@ pub unsafe fn from_raw<'a>(ptr: *mut B::State) -> &'a Self {
         //   `B::State`.
         unsafe { &*ptr.cast() }
     }
+
+    /// Obtains the raw pointer from a [`Lock`].
+    ///
+    /// This can be useful for working with a lock user outside Rust.
+    pub fn as_raw(&self) -> *mut B::State {
+        self.state.get()
+    }
 }

 impl<T: ?Sized, B: Backend> Lock<T, B> {


Regards,
Boqun

> 
> P.
> 
> > 
> > [1]: https://lore.kernel.org/rust-for-linux/20250905044141.77868-1-boqun.feng@gmail.com/
> > 
> > Regards,
> > Boqun
> > 
> > > 
> > > So much from my side. Hope to hear from you.
> > > 
> > > (I've compiled and tested this with the unit test on the current -rc3)
> > > 
> > > Philipp
> > > ---
> > [...]
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ