mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/panthor: Fix overflow in fdinfo engine time conversion
@ 2026-11-21 15:27 Haoming Gao
  2026-11-24  8:32 ` Boris Brezillon
  2026-11-24 12:19 ` Liviu Dudau
  0 siblings, 2 replies; 3+ messages in thread
From: Haoming Gao @ 2026-11-21 15:27 UTC (permalink / raw)
  To: boris.brezillon
  Cc: adrian.larumbe, Haoming Gao, Steven Price, Liviu Dudau,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, dri-devel, linux-kernel

The timestamp counter accumulates GPU ticks per DRM client. Multiplying
that counter by NSEC_PER_SEC in u64 can overflow before the division by
the timer frequency, even when the result in nanoseconds fits in u64.

On an RK3588 with a 24 MHz timer, drm-engine-panthor dropped from
768569012750 ns to 422647638 ns between two reads of the same client's
fdinfo. The GPU cycle counter continued to advance.

Use mul_u64_u64_div_u64_roundup() to preserve the full product and keep
the existing rounding. The helper was checked against a 128-bit
reference on the board, including at the first wrap boundary.

Fixes: e16635d88fa0 ("drm/panthor: add DRM fdinfo support")
Signed-off-by: Haoming Gao <Naixumogu@whut.edu.cn>
---
 drivers/gpu/drm/panthor/panthor_drv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index dc8d0191aef4..39b827a9b9cc 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -8,6 +8,7 @@
 #endif
 
 #include <linux/list.h>
+#include <linux/math64.h>
 #include <linux/module.h>
 #include <linux/of_platform.h>
 #include <linux/pagemap.h>
@@ -1708,8 +1709,8 @@ static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev,
 	if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP) {
 #ifdef CONFIG_ARM_ARCH_TIMER
 		drm_printf(p, "drm-engine-panthor:\t%llu ns\n",
-			   DIV_ROUND_UP_ULL((pfile->stats.time * NSEC_PER_SEC),
-					    arch_timer_get_cntfrq()));
+			   mul_u64_u64_div_u64_roundup(pfile->stats.time, NSEC_PER_SEC,
+						       arch_timer_get_cntfrq()));
 #endif
 	}
 	if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_CYCLES)

base-commit: 878c885830ef004a32e8974c4d1ae14e2ea30c5a
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/panthor: Fix overflow in fdinfo engine time conversion
  2026-11-21 15:27 [PATCH] drm/panthor: Fix overflow in fdinfo engine time conversion Haoming Gao
@ 2026-11-24  8:32 ` Boris Brezillon
  2026-11-24 12:19 ` Liviu Dudau
  1 sibling, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2026-11-24  8:32 UTC (permalink / raw)
  To: Haoming Gao
  Cc: adrian.larumbe, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	dri-devel, linux-kernel

On Sat, 21 Nov 2026 23:27:28 +0800
Haoming Gao <Naixumogu@whut.edu.cn> wrote:

> The timestamp counter accumulates GPU ticks per DRM client. Multiplying
> that counter by NSEC_PER_SEC in u64 can overflow before the division by
> the timer frequency, even when the result in nanoseconds fits in u64.
> 
> On an RK3588 with a 24 MHz timer, drm-engine-panthor dropped from
> 768569012750 ns to 422647638 ns between two reads of the same client's
> fdinfo. The GPU cycle counter continued to advance.
> 
> Use mul_u64_u64_div_u64_roundup() to preserve the full product and keep
> the existing rounding. The helper was checked against a 128-bit
> reference on the board, including at the first wrap boundary.
> 
> Fixes: e16635d88fa0 ("drm/panthor: add DRM fdinfo support")
> Signed-off-by: Haoming Gao <Naixumogu@whut.edu.cn>

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>

> ---
>  drivers/gpu/drm/panthor/panthor_drv.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
> index dc8d0191aef4..39b827a9b9cc 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -8,6 +8,7 @@
>  #endif
>  
>  #include <linux/list.h>
> +#include <linux/math64.h>
>  #include <linux/module.h>
>  #include <linux/of_platform.h>
>  #include <linux/pagemap.h>
> @@ -1708,8 +1709,8 @@ static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev,
>  	if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP) {
>  #ifdef CONFIG_ARM_ARCH_TIMER
>  		drm_printf(p, "drm-engine-panthor:\t%llu ns\n",
> -			   DIV_ROUND_UP_ULL((pfile->stats.time * NSEC_PER_SEC),
> -					    arch_timer_get_cntfrq()));
> +			   mul_u64_u64_div_u64_roundup(pfile->stats.time, NSEC_PER_SEC,
> +						       arch_timer_get_cntfrq()));
>  #endif
>  	}
>  	if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_CYCLES)
> 
> base-commit: 878c885830ef004a32e8974c4d1ae14e2ea30c5a


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/panthor: Fix overflow in fdinfo engine time conversion
  2026-11-21 15:27 [PATCH] drm/panthor: Fix overflow in fdinfo engine time conversion Haoming Gao
  2026-11-24  8:32 ` Boris Brezillon
@ 2026-11-24 12:19 ` Liviu Dudau
  1 sibling, 0 replies; 3+ messages in thread
From: Liviu Dudau @ 2026-11-24 12:19 UTC (permalink / raw)
  To: Haoming Gao
  Cc: boris.brezillon, adrian.larumbe, Steven Price, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	dri-devel, linux-kernel

On Sat, Nov 21, 2026 at 11:27:28PM +0800, Haoming Gao wrote:
> The timestamp counter accumulates GPU ticks per DRM client. Multiplying
> that counter by NSEC_PER_SEC in u64 can overflow before the division by
> the timer frequency, even when the result in nanoseconds fits in u64.
> 
> On an RK3588 with a 24 MHz timer, drm-engine-panthor dropped from
> 768569012750 ns to 422647638 ns between two reads of the same client's
> fdinfo. The GPU cycle counter continued to advance.
> 
> Use mul_u64_u64_div_u64_roundup() to preserve the full product and keep
> the existing rounding. The helper was checked against a 128-bit
> reference on the board, including at the first wrap boundary.
> 
> Fixes: e16635d88fa0 ("drm/panthor: add DRM fdinfo support")
> Signed-off-by: Haoming Gao <Naixumogu@whut.edu.cn>

Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>

Best regards,
Liviu

> ---
>  drivers/gpu/drm/panthor/panthor_drv.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
> index dc8d0191aef4..39b827a9b9cc 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -8,6 +8,7 @@
>  #endif
>  
>  #include <linux/list.h>
> +#include <linux/math64.h>
>  #include <linux/module.h>
>  #include <linux/of_platform.h>
>  #include <linux/pagemap.h>
> @@ -1708,8 +1709,8 @@ static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev,
>  	if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP) {
>  #ifdef CONFIG_ARM_ARCH_TIMER
>  		drm_printf(p, "drm-engine-panthor:\t%llu ns\n",
> -			   DIV_ROUND_UP_ULL((pfile->stats.time * NSEC_PER_SEC),
> -					    arch_timer_get_cntfrq()));
> +			   mul_u64_u64_div_u64_roundup(pfile->stats.time, NSEC_PER_SEC,
> +						       arch_timer_get_cntfrq()));
>  #endif
>  	}
>  	if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_CYCLES)
> 
> base-commit: 878c885830ef004a32e8974c4d1ae14e2ea30c5a
> -- 
> 2.43.0
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-24 12:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-21 15:27 [PATCH] drm/panthor: Fix overflow in fdinfo engine time conversion Haoming Gao
2026-11-24  8:32 ` Boris Brezillon
2026-11-24 12:19 ` Liviu Dudau

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®