From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Gary Guo" <gary@garyguo.net>
Cc: "Lyude Paul" <lyude@redhat.com>, <nouveau@lists.freedesktop.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
<rust-for-linux@vger.kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
<dri-devel@lists.freedesktop.org>,
"Matthew Maurer" <mmaurer@google.com>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
<christian.koenig@amd.com>, "Asahi Lina" <lina@asahilina.net>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Simona Vetter" <simona@ffwll.ch>,
"Alice Ryhl" <aliceryhl@google.com>,
"Boqun Feng" <boqun@kernel.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Krishna Ketan Rai" <prafulrai522@gmail.com>,
<linux-media@vger.kernel.org>,
"Shankari Anand" <shankari.ak0208@gmail.com>,
"David Airlie" <airlied@gmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Viresh Kumar" <viresh.kumar@linaro.org>,
<linaro-mm-sig@lists.linaro.org>,
"Asahi Lina" <lina+kernel@asahilina.net>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
<kernel@vger.kernel.org>
Subject: Re: [PATCH v12 4/5] rust: drm: gem: Introduce shmem::SGTable
Date: Fri, 24 Apr 2026 11:10:39 +0900 [thread overview]
Message-ID: <DI10QIODI69N.RKZAXK5PPLN0@nvidia.com> (raw)
In-Reply-To: <DI0O1G7AX1I3.1SCSOLCPR258X@garyguo.net>
On Fri Apr 24, 2026 at 1:13 AM JST, Gary Guo wrote:
> On Thu Apr 23, 2026 at 4:27 PM BST, Alexandre Courbot wrote:
>> On Fri Apr 24, 2026 at 12:09 AM JST, Gary Guo wrote:
>>> On Thu Apr 23, 2026 at 4:01 PM BST, Alexandre Courbot wrote:
>>>>
>>>> I didn't like this `UnsafeCell<Option>` since the last time, but only figured how to replace it now:
>>>>
>>>> sgt_res: SetOnce<Devres<SGTableMap<T>>>,
>>>>
>>>> It's actually designed for that! And lets you remove at least one unsafe
>>>> statement, while simplifying `get_sg_table` quite a bit. With the other
>>>> suggestions I have below, here is my version of `get_sg_table` for
>>>> reference:
>>>>
>>>> fn get_sg_table<'a>(
>>>> &'a self,
>>>> dev: &'a device::Device<Bound>,
>>>> ) -> Result<&'a Devres<SGTableMap<T>>> {
>>>> let _dma_resv = DmaResvGuard::new(self);
>>>>
>>>> if let Some(devres) = self.sgt_res.as_ref() {
>>>> Ok(devres)
>>>> } else {
>>>> // Only called for the side-effect of populating the GEM SG table.
>>>> // SAFETY: We grabbed the lock required for calling this function above.
>>>> from_err_ptr(unsafe {
>>>> bindings::drm_gem_shmem_get_pages_sgt_locked(self.as_raw_shmem())
>>>> })?;
>>>>
>>>> // INVARIANT:
>>>> // - We called drm_gem_shmem_get_pages_sgt_locked above and checked that it
>>>> // succeeded, fulfilling the invariant of `SGTableMap` that the object's `sgt` field
>>>> // is initialized.
>>>> // - We store this Devres in the object itself and don't move it, ensuring that the
>>>> // object it points to remains valid for the lifetime of the `SGTableMap`.
>>>> let devres =
>>>> Devres::new(dev, init!(SGTableMap { obj: self.into() })).inspect_err(|_| {
>>>> // We can't make sure that the pages for this object are unmapped on
>>>> // driver-unbind, so we need to release the sgt
>>>> // SAFETY:
>>>> // - We grabbed the lock required for calling this function above
>>>> // - We checked above that get_pages_sgt_locked() was successful
>>>> unsafe { bindings::__drm_gem_shmem_free_sgt_locked(self.as_raw_shmem()) }
>>>> })?;
>>>>
>>>> self.sgt_res.populate(devres);
>>>>
>>>> // PANIC: `populate` has just succeeded, guaranteeing that `sgt_res` is populated.
>>>> Ok(self.sgt_res.as_ref().unwrap())
>>>> }
>>>> }
>>>>
>>>> And if only we could populate the `SetOnce` with a `impl Init<T, E>`,
>>>> then we could even remove the DMA reservation acquisition on the fast
>>>> path, because `SetOnce` comes with its own locking and the DMA lock here
>>>> is used outside of its intended scope. I'll try to push the necessary
>>>> work for `SetOnce` and maybe we can do that as a follow-up patch.
>>>
>>> I have this sitting in my once_wip branch for while
>>> https://github.com/nbdd0121/linux/commits/once_wip/
>>> (the specific commit that adds init support is
>>> https://github.com/nbdd0121/linux/commit/4aabdbcf20b11626c253f203745b1d55c37ab2ee).
>>>
>>> This was implemented for lazy revocable support which Alvin has picked up, see
>>> https://lore.kernel.org/rust-for-linux/20260326-b4-tyr-debugfs-v1-1-074badd18716@linux.dev/
>>
>> Haha that's pretty close to what I wrote to test the code. Do you have
>> plans to send it soon?
>
> I mean.. Alvin has already sent it?
>
> If you (or someone else) want to carry the patch in another series, by all means.
My bad, it was late at night and my focus was a bit down.
It's perfect if Alvin keeps carrying this patch.
next prev parent reply other threads:[~2026-04-24 2:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 23:52 [PATCH v12 0/5] Rust bindings for gem shmem Lyude Paul
2026-04-21 23:52 ` [PATCH v12 1/5] rust: drm: gem: s/device::Device/Device/ for shmem.rs Lyude Paul
2026-04-21 23:52 ` [PATCH v12 2/5] drm/gem/shmem: Introduce __drm_gem_shmem_free_sgt_locked() Lyude Paul
2026-04-22 22:52 ` lyude
2026-04-21 23:52 ` [PATCH v12 3/5] drm/gem/shmem: Export drm_gem_shmem_get_pages_sgt_locked() Lyude Paul
2026-04-21 23:52 ` [PATCH v12 4/5] rust: drm: gem: Introduce shmem::SGTable Lyude Paul
2026-04-23 15:01 ` Alexandre Courbot
2026-04-23 15:09 ` Gary Guo
2026-04-23 15:27 ` Alexandre Courbot
2026-04-23 16:13 ` Gary Guo
2026-04-24 2:10 ` Alexandre Courbot [this message]
2026-04-23 15:28 ` Alexandre Courbot
2026-04-24 18:13 ` lyude
2026-04-24 23:10 ` lyude
2026-04-25 2:38 ` Alexandre Courbot
2026-04-24 11:08 ` Alexandre Courbot
2026-04-21 23:52 ` [PATCH v12 5/5] rust: drm: gem: Add vmap functions to shmem bindings Lyude Paul
2026-04-23 15:01 ` Alexandre Courbot
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=DI10QIODI69N.RKZAXK5PPLN0@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=boqun@kernel.org \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=kernel@vger.kernel.org \
--cc=lina+kernel@asahilina.net \
--cc=lina@asahilina.net \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-media@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=mmaurer@google.com \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=prafulrai522@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=shankari.ak0208@gmail.com \
--cc=simona@ffwll.ch \
--cc=sumit.semwal@linaro.org \
--cc=viresh.kumar@linaro.org \
/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