Skip to content

Commit 80ef0fa

Browse files
hoshinolinajannau
authored andcommitted
drm/asahi: Fix u32 mult overflow on large tilebufs/TPCs
Signed-off-by: Asahi Lina <[email protected]>
1 parent e52df48 commit 80ef0fa

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/gpu/drm/asahi/queue/render.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ impl super::QueueInner::ver {
8888
return Err(EINVAL);
8989
}
9090

91+
// Overflow safety: all these calculations are done in u32.
92+
// At 64Kx64K max dimensions above, this is 2**32 pixels max.
93+
// In terms of tiles that are always larger than one pixel,
94+
// this can never overflow. Note that real actual dimensions
95+
// are limited to 16K * 16K below anyway.
96+
//
97+
// Once we multiply by the layer count, then we need to check
98+
// for overflow or use u64.
99+
91100
let tile_width = 32u32;
92101
let tile_height = 32u32;
93102

@@ -135,12 +144,13 @@ impl super::QueueInner::ver {
135144
let rgn_entry_size = 5;
136145
// Macrotile stride in 32-bit words
137146
let rgn_size = align(rgn_entry_size * tiles_per_mtile * utiles_per_tile, 4) / 4;
138-
let tilemap_size = (4 * rgn_size * mtiles * layers) as usize;
147+
let tilemap_size = (4 * rgn_size * mtiles) as usize * layers as usize;
139148

140149
let tpc_entry_size = 8;
141150
// TPC stride in 32-bit words
142151
let tpc_mtile_stride = tpc_entry_size * utiles_per_tile * tiles_per_mtile / 4;
143-
let tpc_size = (num_clusters * (4 * tpc_mtile_stride * mtiles) * layers) as usize;
152+
let tpc_size =
153+
(4 * tpc_mtile_stride * mtiles) as usize * layers as usize * num_clusters as usize;
144154

145155
// No idea where this comes from, but it fits what macOS does...
146156
// GUESS: Number of 32K heap blocks to fit a 5-byte region header/pointer per tile?

0 commit comments

Comments
 (0)