public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: <lyude@redhat.com>
Cc: <nouveau@lists.freedesktop.org>, "Gary Guo" <gary@garyguo.net>,
	"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: Sat, 25 Apr 2026 11:38:54 +0900	[thread overview]
Message-ID: <DI1VYOJKCD2G.1RB25DXWO0OK6@nvidia.com> (raw)
In-Reply-To: <ed26658c461020547e058b237575324adcbaca59.camel@redhat.com>

On Sat Apr 25, 2026 at 8:10 AM JST, lyude wrote:
>
> On Fri, 2026-04-24 at 00:01 +0900, Alexandre Courbot wrote:
>> There are 4 sites where we acquire and release the DMA resv lock,
>> each
>> of which require unsafe blocks and carrying the risk that we forget
>> releasing the lock in the end. For this method in particular we need
>> to
>> jump through hoops a bit and store the return value into a temporary
>> variable so we can unlock the DMA reservation.
>> 
>> Let's do ourselves a favor and implement a small, private guard type:
>> 
>>     struct DmaResvGuard<'a, T: DriverObject>(&'a Object<T>);
>> 
>>     impl<'a, T: DriverObject> DmaResvGuard<'a, T> {
>>         fn new(object: &'a Object<T>) -> Self {
>>             // SAFETY: This lock is initialized throughout the
>> lifetime of `object`
>>             unsafe { bindings::dma_resv_lock(object.raw_dma_resv(),
>> ptr::null_mut()) };
>> 
>>             Self(object)
>>         }
>>     }
>> 
>>     impl<'a, T> Drop for DmaResvGuard<'a, T>
>>     where
>>         T: DriverObject,
>>     {
>>         fn drop(&mut self) {
>>             // SAFETY: We are releasing the lock grabbed during the
>> creation of this object.
>>             unsafe { bindings::dma_resv_unlock(self.0.raw_dma_resv())
>> };
>>         }
>>     }
>> 
>> There here you would just do
>> 
>>     let _dma_resv = DmaResvGuard::new(self);
>
> I thought of doing this but lost track of how many times I was actually
> grabbing this lock…
> BTW - want me to just give you authorship on the patch for adding
> DmaResvGuard? Since on my branch I've pretty much only just added two
> inline annotations, it's otherwise identical to what you wrote here.

You should remain author since I didn't formally send a patch - but if
the code remains that close, and you are comfortable with it, then a
Co-authored-by would be appreciated. Feel free to also add my

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>

  reply	other threads:[~2026-04-25  2:39 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
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 [this message]
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=DI1VYOJKCD2G.1RB25DXWO0OK6@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