From: Daniel Almeida <daniel.almeida@collabora.com>
To: phasta@kernel.org
Cc: "Alice Ryhl" <aliceryhl@google.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Christian König" <ckoenig.leichtzumerken@gmail.com>,
"Tvrtko Ursulin" <tursulin@ursulin.net>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Boris Brezillon" <boris.brezillon@collabora.com>,
"Dave Airlie" <airlied@redhat.com>,
"Lyude Paul" <lyude@redhat.com>,
"Peter Colberg" <pcolberg@redhat.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
rust-for-linux@vger.kernel.org
Subject: Re: [RFC WIP 2/3] rust: sync: Add dma_fence abstractions
Date: Thu, 27 Nov 2025 10:48:10 -0300 [thread overview]
Message-ID: <8F85F97A-F411-48E1-9942-64B692E8CD79@collabora.com> (raw)
In-Reply-To: <bc4f01ec5172d29abd64429e3017cc53c0522e01.camel@mailbox.org>
Hi Phillipp,
[…]
>
>>
>>> + // among all the fences. This can't become a UAF because each fence takes a
>>> + // reference of the fence context.
>>> + unsafe { bindings::dma_fence_init(slot, &Self::OPS, Opaque::cast_into(lock_ptr), context, seqno) };
>>> + }),
>>> + data <- data,
>>> + signalling: false,
>>> + signalling_cookie: false,
>>> + fctx: fctx,
>>> + });
>>> +
>>> + let b = KBox::pin_init(fence, GFP_KERNEL)?;
>>> +
>>> + // SAFETY: We don't move the contents of `b` anywhere here. After unwrapping it, ARef will
>>> + // take care of preventing memory moves.
>>> + let rawptr = KBox::into_raw(unsafe { Pin::into_inner_unchecked(b) });
>>> +
>>> + // SAFETY: `rawptr` was created validly above.
>>> + let aref = unsafe { ARef::from_raw(NonNull::new_unchecked(rawptr)) };
>>> +
>>> + Ok(aref)
>>> + }
>>> +
>>> + /// Mark the beginning of a DmaFence signalling critical section. Should be called once a fence
>>> + /// gets published.
>>> + ///
>>> + /// The signalling critical section is marked as finished automatically once the fence signals.
>>> + pub fn begin_signalling(&mut self) {
>>> + // FIXME: this needs to be mutable, obviously, but we can't borrow mutably. *sigh*
>>
>> Is AtomicBool going away? Otherwise can you expand?
>
> The AtomicBool is just used in the example demo code.
>
> The issue here is that begin_signalling() should set a "this fence is
> currently in the signalling section"-flag. So the fence needs to be
> mutable. Then, however, Rust complains because self.signalling is not
> protected by any lock.
>
> So one needs some sort of synchronization. Stuffing a DmaFence into a
> SpinLock would be overkill, however, considering that the C code
> already takes care of properly taking all locks.
>
> I've asked about that problem on Zulip once:
> https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/.E2.9C.94.20ARef.20without.20locking/near/539747635
>
> Haven't looked deeper into solving it since, because those lockdep
> guards are kind of nice-to-have at the moment.
>
> I think the solution will be to make self.signalling an AtomicBool (I
> think you meant that above?)
Yes, that’s what I meant, i.e.: making self.signalling an AtomicBool.
next prev parent reply other threads:[~2025-11-27 13:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-18 13:25 [RFC WIP 0/3] DRM Jobqueue Philipp Stanner
2025-11-18 13:25 ` [RFC WIP 1/3] rust: list: Add unsafe for container_of Philipp Stanner
2025-11-18 13:25 ` [RFC WIP 2/3] rust: sync: Add dma_fence abstractions Philipp Stanner
2025-11-21 23:03 ` Lyude Paul
2025-11-24 9:31 ` Alice Ryhl
2025-11-27 13:45 ` Philipp Stanner
2025-11-24 12:49 ` Daniel Almeida
2025-11-25 9:48 ` Philipp Stanner
2025-11-25 10:58 ` Boris Brezillon
2025-11-25 12:20 ` Philipp Stanner
2025-11-25 13:50 ` Boris Brezillon
2025-11-26 13:42 ` Philipp Stanner
2025-11-26 14:55 ` Boris Brezillon
2025-11-27 13:48 ` Daniel Almeida [this message]
2025-11-28 11:08 ` Philipp Stanner
2025-11-28 12:21 ` Daniel Almeida
2025-11-18 13:25 ` [RFC WIP 3/3] rust/drm: Add initial jobqueue sceleton Philipp Stanner
2025-11-24 13:58 ` Daniel Almeida
2025-11-25 13:20 ` Philipp Stanner
2025-11-27 14:13 ` Daniel Almeida
2025-11-28 10:07 ` Philipp Stanner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8F85F97A-F411-48E1-9942-64B692E8CD79@collabora.com \
--to=daniel.almeida@collabora.com \
--cc=acourbot@nvidia.com \
--cc=airlied@redhat.com \
--cc=aliceryhl@google.com \
--cc=boris.brezillon@collabora.com \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lyude@redhat.com \
--cc=pcolberg@redhat.com \
--cc=phasta@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tursulin@ursulin.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®