From: Daniel Almeida <daniel.almeida@collabora.com>
To: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Benno Lossin" <lossin@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>
Cc: dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 01/13] drm/tyr: convert SeatInfo::slot from u8 to usize
Date: Wed, 25 Nov 2026 19:46:52 -0300 [thread overview]
Message-ID: <20261125-b4-tyr-as-casts-v1-1-2b2f53164d86@collabora.com> (raw)
In-Reply-To: <20261125-b4-tyr-as-casts-v1-0-2b2f53164d86@collabora.com>
An `as` cast silently drops the bits that do not fit the target type,
and nothing at the cast shows whether that can happen. As part of a
larger effort to reduce the number of `as` casts in Tyr, convert
`SeatInfo::slot` from `u8` to `usize`.
The slot index is stored as a `u8`, while the code that uses it takes a
`usize`. The casts follow from that choice. The index is cast with `as`
on the way into a `SeatInfo` and on the way out, and
`SlotManager::new()` rejects more than 256 slots so that the cast to
`u8` cannot truncate.
Store the index as `usize`, which removes the casts and the limit.
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
drivers/gpu/drm/tyr/mmu/address_space.rs | 15 +++------------
drivers/gpu/drm/tyr/slot.rs | 23 +++++++++--------------
2 files changed, 12 insertions(+), 26 deletions(-)
diff --git a/drivers/gpu/drm/tyr/mmu/address_space.rs b/drivers/gpu/drm/tyr/mmu/address_space.rs
index 76e3d2df6afd..dd6377bee989 100644
--- a/drivers/gpu/drm/tyr/mmu/address_space.rs
+++ b/drivers/gpu/drm/tyr/mmu/address_space.rs
@@ -467,10 +467,7 @@ pub(super) fn start_vm_update(
) -> Result {
let seat = vm_as_data.as_seat.access(self);
match seat.slot() {
- Some(slot) => {
- let as_nr = slot as usize;
- self.as_start_update(as_nr, region)
- }
+ Some(slot) => self.as_start_update(slot, region),
_ => Ok(()),
}
}
@@ -479,10 +476,7 @@ pub(super) fn start_vm_update(
pub(super) fn end_vm_update(&mut self, vm_as_data: &VmAsData<'drm>) -> Result {
let seat = vm_as_data.as_seat.access(self);
match seat.slot() {
- Some(slot) => {
- let as_nr = slot as usize;
- self.as_end_update(as_nr)
- }
+ Some(slot) => self.as_end_update(slot),
_ => Ok(()),
}
}
@@ -491,10 +485,7 @@ pub(super) fn end_vm_update(&mut self, vm_as_data: &VmAsData<'drm>) -> Result {
pub(super) fn flush_vm(&mut self, vm_as_data: &VmAsData<'drm>) -> Result {
let seat = vm_as_data.as_seat.access(self);
match seat.slot() {
- Some(slot) => {
- let as_nr = slot as usize;
- self.as_flush(as_nr)
- }
+ Some(slot) => self.as_flush(slot),
_ => Ok(()),
}
}
diff --git a/drivers/gpu/drm/tyr/slot.rs b/drivers/gpu/drm/tyr/slot.rs
index d194ead53f71..0e153dc025c5 100644
--- a/drivers/gpu/drm/tyr/slot.rs
+++ b/drivers/gpu/drm/tyr/slot.rs
@@ -47,7 +47,7 @@ pub(crate) struct SeatInfo {
/// it means the object has been evicted from the hardware slot,
/// and a new slot needs to be acquired to make this object
/// resident again.
- slot: u8,
+ slot: usize,
/// Sequence number encoding the last time this seat was active.
/// We also use it to check if a slot is still bound to a seat.
@@ -98,7 +98,7 @@ impl Seat {
/// If the seat is not `Seat::Active` we can't trust the
/// `SeatInfo`. In that case `None` is returned, otherwise
/// `Some(SeatInfo::slot)` is returned.
- pub(crate) fn slot(&self) -> Option<u8> {
+ pub(crate) fn slot(&self) -> Option<usize> {
match self {
Self::Active(info) => Some(info.slot),
_ => None,
@@ -174,10 +174,6 @@ pub(crate) fn new(manager: T, slot_count: usize) -> Result<Self> {
if slot_count > MAX_SLOTS {
return Err(EINVAL);
}
- // Since the slot index is stored in SeatInfo as a u8, the maximum number of slots is 256.
- if slot_count > u8::MAX as usize + 1 {
- return Err(EINVAL);
- }
Ok(Self {
manager,
@@ -193,7 +189,7 @@ fn record_active_slot(&mut self, slot_idx: usize, slot_data: T::SlotData) {
let cur_seqno = self.use_seqno;
*T::seat(&slot_data).access_mut(self) = Seat::Active(SeatInfo {
- slot: slot_idx as u8,
+ slot: slot_idx,
seqno: cur_seqno,
});
@@ -221,7 +217,7 @@ fn reactivate_slot(&mut self, slot_idx: usize, slot_data: &T::SlotData) -> Resul
};
*T::seat(slot_data).access_mut(self) = Seat::Active(SeatInfo {
- slot: slot_idx as u8,
+ slot: slot_idx,
seqno: cur_seqno,
});
@@ -325,8 +321,8 @@ fn evict_slot(&mut self, slot_idx: usize, locked_seat: &LockedSeat<T, MAX_SLOTS>
/// If they don't match, the seat is stale and is reset to `NoSeat`.
fn check_seat(&mut self, locked_seat: &LockedSeat<T, MAX_SLOTS>) {
let (slot_idx, seat_seqno, is_active) = match locked_seat.access(self) {
- Seat::Active(seat_info) => (seat_info.slot as usize, seat_info.seqno, true),
- Seat::Idle(seat_info) => (seat_info.slot as usize, seat_info.seqno, false),
+ Seat::Active(seat_info) => (seat_info.slot, seat_info.seqno, true),
+ Seat::Idle(seat_info) => (seat_info.slot, seat_info.seqno, false),
_ => return,
};
@@ -353,7 +349,7 @@ pub(crate) fn activate(&mut self, slot_data: T::SlotData) -> Result {
// Copy out only the slot index so the borrow of slot_data ends here.
let slot_idx = match T::seat(&slot_data).access(self) {
- Seat::Active(seat_info) | Seat::Idle(seat_info) => Some(seat_info.slot as usize),
+ Seat::Active(seat_info) | Seat::Idle(seat_info) => Some(seat_info.slot),
Seat::NoSeat => None,
};
@@ -368,7 +364,7 @@ pub(crate) fn activate(&mut self, slot_data: T::SlotData) -> Result {
pub(crate) fn idle(&mut self, locked_seat: &LockedSeat<T, MAX_SLOTS>) -> Result {
self.check_seat(locked_seat);
if let Seat::Active(seat_info) = locked_seat.access(self) {
- self.idle_slot(seat_info.slot as usize, locked_seat)?;
+ self.idle_slot(seat_info.slot, locked_seat)?;
}
Ok(())
}
@@ -379,8 +375,7 @@ pub(crate) fn evict(&mut self, locked_seat: &LockedSeat<T, MAX_SLOTS>) -> Result
match locked_seat.access(self) {
Seat::Active(seat_info) | Seat::Idle(seat_info) => {
- let slot_idx = seat_info.slot as usize;
- self.evict_slot(slot_idx, locked_seat)?;
+ self.evict_slot(seat_info.slot, locked_seat)?;
}
_ => (),
}
--
2.56.0
next prev parent reply other threads:[~2026-11-25 22:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 22:46 [PATCH 00/13] drm/tyr: reduce the number of `as` casts Daniel Almeida
2026-11-25 22:46 ` Daniel Almeida [this message]
2026-11-25 22:46 ` [PATCH 02/13] drm/tyr: convert VmAsData::va_bits from u8 to u32 Daniel Almeida
2026-11-25 22:46 ` [PATCH 03/13] drm/tyr: convert the lock region exponents " Daniel Almeida
2026-11-25 22:46 ` [PATCH 04/13] drm/tyr: convert EntryHeader to `bitfield!` Daniel Almeida
2026-11-25 22:46 ` [PATCH 05/13] drm/tyr: use SizeConstants for the u32 and u64 size constants Daniel Almeida
2026-11-25 22:46 ` [PATCH 06/13] drm/tyr: replace lossless `as` casts with From and FromSafeCast Daniel Almeida
2026-11-25 22:46 ` [PATCH 07/13] drm/tyr: use `cv!` for constant conversions Daniel Almeida
2026-11-25 22:46 ` [PATCH 08/13] drm/tyr: use VmMapFlags::all_bits() to validate map flags Daniel Almeida
2026-11-25 22:47 ` [PATCH 09/13] drm/tyr: justify the casts of enums to their integer value Daniel Almeida
2026-11-25 22:47 ` [PATCH 10/13] drm/tyr: add split_u64() for the 64-bit register values Daniel Almeida
2026-11-25 22:47 ` [PATCH 11/13] drm/tyr: return usize from get_pgsize() Daniel Almeida
2026-11-25 22:47 ` [PATCH 12/13] drm/tyr: justify the physical address cast in pt_map() Daniel Almeida
2026-11-25 22:47 ` [PATCH 13/13] drm/tyr: deny `clippy::as_conversions` Daniel Almeida
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=20261125-b4-tyr-as-casts-v1-1-2b2f53164d86@collabora.com \
--to=daniel.almeida@collabora.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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®