From: Boris Brezillon <boris.brezillon@collabora.com>
To: Daniel Almeida <daniel.almeida@collabora.com>
Cc: Deborah Brouwer <deborah.brouwer@collabora.com>,
dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org,
aliceryhl@google.com, beata.michalska@arm.com, lyude@redhat.com
Subject: Re: [PATCH 07/12] drm/tyr: Add generic slot manager
Date: Sun, 22 Feb 2026 18:57:43 +0100 [thread overview]
Message-ID: <20260222185743.02dabb26@fedora> (raw)
In-Reply-To: <A60BBD53-B7D3-4E85-A72E-8B914B82C977@collabora.com>
On Fri, 20 Feb 2026 13:55:31 -0300
Daniel Almeida <daniel.almeida@collabora.com> wrote:
> > On 20 Feb 2026, at 13:21, Boris Brezillon <boris.brezillon@collabora.com> wrote:
> >
> > On Fri, 20 Feb 2026 12:25:43 -0300
> > Daniel Almeida <daniel.almeida@collabora.com> wrote:
> >
> >>>> +
> >>>> + // Checks and updates the seat state based on the slot it points to
> >>>> + // (if any). Returns a Seat with a value matching the slot state.
> >>>> + fn check_seat(&mut self, locked_seat: &LockedSeat<T, MAX_SLOTS>) -> Seat {
> >>>> + let new_seat = match locked_seat.access(self) {
> >>>> + Seat::Active(seat_info) => {
> >>>> + let old_slot_idx = seat_info.slot as usize;
> >>>> + let slot = &self.slots[old_slot_idx];
> >>>> +
> >>>> + if kernel::warn_on!(
> >>>> + !matches!(slot, Slot::Active(slot_info) if slot_info.seqno == seat_info.seqno)
> >>>> + ) {
> >>>> + Seat::NoSeat
> >>>> + } else {
> >>>> + Seat::Active(SeatInfo {
> >>>> + slot: seat_info.slot,
> >>>> + seqno: seat_info.seqno,
> >>>> + })
> >>>> + }
> >>>> + }
> >>>> +
> >>>> + Seat::Idle(seat_info) => {
> >>>> + let old_slot_idx = seat_info.slot as usize;
> >>>> + let slot = &self.slots[old_slot_idx];
> >>>> +
> >>>> + if !matches!(slot, Slot::Idle(slot_info) if slot_info.seqno == seat_info.seqno) {
> >>>> + Seat::NoSeat
> >>>> + } else {
> >>>> + Seat::Idle(SeatInfo {
> >>>> + slot: seat_info.slot,
> >>>> + seqno: seat_info.seqno,
> >>>> + })
> >>>> + }
> >>>> + }
> >>>> +
> >>>> + _ => Seat::NoSeat,
> >>>> + };
> >>>> +
> >>>> + // FIXME: Annoying manual copy. The original idea was to not add Copy+Clone to SeatInfo,
> >>>> + // so that only slot.rs can change the seat state, but there might be better solutions
> >>>> + // to prevent that.
> >>>
> >>> Okay, I guess we want some inputs from Daniel and/or Alice on that one.
> >>
> >> Hm, I'd say we shouldn't implement Clone to avoid any possibility of holding on
> >> to stale state by duplicating it.
> >
> > Okay, so basically what we have now.
> >
> >>
> >> Why do we need to return Seat from this function? Can't we simply write
> >> locked_seat in place and not return anything?
> >
> > We do both actually. IIRC, the reason is that LockedBy borrows &self if
> > we want to read the locked_seat, which prevents us from calling methods
> > taking a &mut ref from a `match(locked_seat.access())`.
>
>
> I am referring to this change:
>
> --- a/drivers/gpu/drm/tyr/slot.rs
> +++ b/drivers/gpu/drm/tyr/slot.rs
> @@ -242,8 +242,8 @@ fn evict_slot(&mut self, slot_idx: usize, locked_seat: &LockedSeat<T, MAX_SLOTS>
> }
>
> // Checks and updates the seat state based on the slot it points to
> - fn check_seat(&mut self, locked_seat: &LockedSeat<T, MAX_SLOTS>) -> Seat {
> + fn check_seat(&mut self, locked_seat: &LockedSeat<T, MAX_SLOTS>) {
> let new_seat = match locked_seat.access(self) {
> Seat::Active(seat_info) => {
> let old_slot_idx = seat_info.slot as usize;
> @@ -278,26 +278,7 @@ fn check_seat(&mut self, locked_seat: &LockedSeat<T, MAX_SLOTS>) -> Seat {
> _ => Seat::NoSeat,
> };
>
> - // FIXME: Annoying manual copy. The original idea was to not add Copy+Clone to SeatInfo,
> - // so that only slot.rs can change the seat state, but there might be better solutions
> - // to prevent that.
> - match &new_seat {
> - Seat::Active(seat_info) => {
> - *locked_seat.access_mut(self) = Seat::Active(SeatInfo {
> - slot: seat_info.slot,
> - seqno: seat_info.seqno,
> - })
> - }
> - Seat::Idle(seat_info) => {
> - *locked_seat.access_mut(self) = Seat::Idle(SeatInfo {
> - slot: seat_info.slot,
> - seqno: seat_info.seqno,
> - })
> - }
> - _ => *locked_seat.access_mut(self) = Seat::NoSeat,
> - }
> -
> - new_seat
> + *locked_seat.access_mut(self) = new_seat;
That one requires Copy support, or am I missing something?
> }
>
> Or even shorter:
>
> fn check_seat(&mut self, locked_seat: &LockedSeat<T, MAX_SLOTS>) {
> let (slot_idx, seqno, is_active) = match locked_seat.access(self) {
> Seat::Active(info) => (info.slot as usize, info.seqno, true),
> Seat::Idle(info) => (info.slot as usize, info.seqno, false),
> _ => return,
> };
>
> let valid = if is_active {
> !kernel::warn_on!(!matches!(&self.slots[slot_idx], Slot::Active(s) if s.seqno == seqno))
> } else {
> matches!(&self.slots[slot_idx], Slot::Idle(s) if s.seqno == seqno)
> };
>
> if !valid {
> *locked_seat.access_mut(self) = Seat::NoSeat;
> }
> }
Did you try that? Last I tried, I was hitting a wall because the caller
of check_seat() does a match on the updated seat, and inside this
match, it calls functions that need a &mut self, and the borrow checker
rightfully points the invalid &self then &mut self borrow pattern.
>
> access vs access_mut() does not matter here: since the owner is &mut self
> anyways we know we have exclusive access to the LockedSeat throughout the whole
> function.
I agree, but LockedBy is picky, and last I tried I couldn't make it
work without the annoying update+return-copy-of-seat dance you see
here. Maybe I missed something obvious and it does indeed work with
your suggested changes, dunno.
next prev parent reply other threads:[~2026-02-22 17:57 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-12 1:37 [PATCH 0/12] drm/tyr: firmware loading and MCU boot support Deborah Brouwer
2026-02-12 1:37 ` [PATCH 01/12] drm/tyr: select DRM abstractions in Kconfig Deborah Brouwer
2026-02-12 1:37 ` [PATCH 02/12] drm/tyr: move clock cleanup into Clocks Drop impl Deborah Brouwer
2026-02-12 8:12 ` Boris Brezillon
2026-02-28 0:18 ` Deborah Brouwer
2026-02-20 14:03 ` Daniel Almeida
2026-02-21 9:01 ` Alice Ryhl
2026-02-12 1:37 ` [PATCH 03/12] drm/tyr: rename TyrObject to BoData Deborah Brouwer
2026-02-20 14:04 ` Daniel Almeida
2026-02-21 9:01 ` Alice Ryhl
2026-02-12 1:37 ` [PATCH 04/12] drm/tyr: set DMA mask using GPU physical address Deborah Brouwer
2026-02-12 10:16 ` Boris Brezillon
2026-02-20 14:19 ` Daniel Almeida
2026-02-21 9:03 ` Alice Ryhl
2026-02-12 1:37 ` [PATCH 05/12] drm/tyr: add MMU address space registers Deborah Brouwer
2026-02-12 8:16 ` Boris Brezillon
2026-02-28 0:12 ` Deborah Brouwer
2026-02-20 14:21 ` Daniel Almeida
2026-02-21 9:09 ` Alice Ryhl
2026-02-22 18:13 ` Boris Brezillon
2026-02-28 0:13 ` Deborah Brouwer
2026-02-12 1:37 ` [PATCH 06/12] drm/tyr: add shmem backing for GEM objects Deborah Brouwer
2026-02-12 8:17 ` Boris Brezillon
2026-02-28 0:15 ` Deborah Brouwer
2026-02-20 14:25 ` Daniel Almeida
2026-02-28 0:17 ` Deborah Brouwer
2026-03-02 10:17 ` Boris Brezillon
2026-03-02 17:03 ` Deborah Brouwer
2026-02-12 1:37 ` [PATCH 07/12] drm/tyr: Add generic slot manager Deborah Brouwer
2026-02-12 10:11 ` Boris Brezillon
2026-02-12 10:45 ` Miguel Ojeda
2026-02-20 15:25 ` Daniel Almeida
2026-02-20 16:21 ` Boris Brezillon
2026-02-20 16:55 ` Daniel Almeida
2026-02-22 17:57 ` Boris Brezillon [this message]
2026-02-22 18:46 ` Daniel Almeida
2026-02-28 0:28 ` Deborah Brouwer
2026-03-02 10:10 ` Boris Brezillon
2026-02-21 11:16 ` Alice Ryhl
2026-02-21 12:44 ` Daniel Almeida
2026-02-21 13:40 ` Alice Ryhl
2026-02-21 13:48 ` Daniel Almeida
2026-02-28 0:25 ` Deborah Brouwer
2026-02-12 1:37 ` [PATCH 08/12] drm/tyr: add MMU module Deborah Brouwer
2026-02-12 10:44 ` Boris Brezillon
2026-02-28 0:31 ` Deborah Brouwer
2026-02-12 11:05 ` Boris Brezillon
2026-02-20 15:41 ` Daniel Almeida
2026-02-21 11:17 ` Alice Ryhl
2026-02-20 17:11 ` Daniel Almeida
2026-02-28 0:46 ` Deborah Brouwer
2026-02-21 11:20 ` Alice Ryhl
2026-02-28 0:49 ` Deborah Brouwer
2026-02-12 1:37 ` [PATCH 09/12] drm/tyr: add GPU virtual memory module Deborah Brouwer
2026-02-12 10:54 ` Boris Brezillon
2026-02-28 0:52 ` Deborah Brouwer
2026-02-12 1:37 ` [PATCH 10/12] drm/tyr: add a kernel buffer object Deborah Brouwer
2026-02-12 11:00 ` Boris Brezillon
2026-02-28 1:01 ` Deborah Brouwer
2026-02-12 1:37 ` [PATCH 11/12] drm/tyr: add parser for firmware binary Deborah Brouwer
2026-02-12 1:37 ` [PATCH 12/12] drm/tyr: add firmware loading and MCU boot support Deborah Brouwer
2026-02-21 11:25 ` Alice Ryhl
2026-02-28 1:02 ` Deborah Brouwer
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=20260222185743.02dabb26@fedora \
--to=boris.brezillon@collabora.com \
--cc=aliceryhl@google.com \
--cc=beata.michalska@arm.com \
--cc=daniel.almeida@collabora.com \
--cc=deborah.brouwer@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=lyude@redhat.com \
--cc=rust-for-linux@vger.kernel.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