Skip to contentSkip to conversation

drm/gud: fix potential divide error due to optimisation

PATCH In review Ruben Wauters 2 participants 2 messages Nov 17

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/gud: fix potential divide error due to optimisation

Compilers can potentially optmise the read of gdrm->stats_actual_length to two separate reads. As flagged by sashiko, when the rect is flushed the stats_actual_length can reset to zero. If this was to occur between the two reads, the divide error can still be triggered (albeit rarely).

Fix this by adding a READ_ONCE around the gdrm->stats_actual_length

Fixes 431c2dffd2b7 ("drm/gud: avoid divide error in gud_stats_debugfs")
---
 drivers/gpu/drm/gud/gud_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/gud/gud_drv.c +1 -1
index cec5d64e152b..4854b30ea5ba 100644
@@ -329,7 +329,7 @@ static int gud_stats_debugfs(struct seq_file *m, void *data)
 	seq_puts(m, "\n");
 
 	if (gdrm->compression) {
-		u64 actual_length = gdrm->stats_actual_length;
+		u64 actual_length = READ_ONCE(gdrm->stats_actual_length);
 		u64 remainder;
 		u64 ratio, ratio_frac;
 
Signature · 1 line
2.56.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 17.11.26 um 15:17 schrieb Ruben Wauters:

Quoted 9 lines

Compilers can potentially optmise the read of gdrm->stats_actual_length to two separate reads. As flagged by sashiko, when the rect is flushed the stats_actual_length can reset to zero. If this was to occur between the two reads, the divide error can still be triggered (albeit rarely).

Fix this by adding a READ_ONCE around the gdrm->stats_actual_length

Fixes 431c2dffd2b7 ("drm/gud: avoid divide error in gud_stats_debugfs")
Quoted 17 lines
---
  drivers/gpu/drm/gud/gud_drv.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/gud/gud_drv.c +1 -1
index cec5d64e152b..4854b30ea5ba 100644
@@ -329,7 +329,7 @@ static int gud_stats_debugfs(struct seq_file *m, void *data)
  	seq_puts(m, "\n");
 
  	if (gdrm->compression) {
-		u64 actual_length = gdrm->stats_actual_length;
+		u64 actual_length = READ_ONCE(gdrm->stats_actual_length);
  		u64 remainder;
  		u64 ratio, ratio_frac;
 
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)