From e550a3cab0473bbcebe5ba8ebd2537addf2f6bb7 Mon Sep 17 00:00:00 2001 From: "Eric R. Smith" Date: Thu, 6 Feb 2025 17:21:36 -0400 Subject: [PATCH] panfrost: avoid potential divide by 0 calculating timer_resolution On armhf integer divide by 0 can raise SIGFPE, whereas on aarch64 it just returns 0. This has become an issue because the recently added panfrost_init_screen_caps always calls pan_gpu_time_to_ns to calculate caps->timer_resolution, whereas before we only called it when PIPE_CAP_TIMER_RESOLUTION was queried, and only OpenCL does that (and not always). Fixes: 205669e3a9 ("panfrost: add panfrost_init_screen_caps") Reviewed-by: Erik Faye-Lund Part-of: --- src/gallium/drivers/panfrost/pan_device.h | 1 + src/gallium/drivers/panfrost/pan_screen.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/panfrost/pan_device.h b/src/gallium/drivers/panfrost/pan_device.h index 2478ead9e06..ad629f15f06 100644 --- a/src/gallium/drivers/panfrost/pan_device.h +++ b/src/gallium/drivers/panfrost/pan_device.h @@ -229,6 +229,7 @@ pan_is_bifrost(const struct panfrost_device *dev) static inline uint64_t pan_gpu_time_to_ns(struct panfrost_device *dev, uint64_t gpu_time) { + assert(dev->kmod.props.timestamp_frequency > 0); return (gpu_time * NSEC_PER_SEC) / dev->kmod.props.timestamp_frequency; } diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index 01a5a04dee7..af6c935ea6a 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -576,7 +576,8 @@ panfrost_init_screen_caps(struct panfrost_screen *screen) dev->kmod.props.gpu_can_query_timestamp && dev->kmod.props.timestamp_frequency != 0; - caps->timer_resolution = pan_gpu_time_to_ns(dev, 1); + if (caps->query_timestamp) + caps->timer_resolution = pan_gpu_time_to_ns(dev, 1); /* The hardware requires element alignment for data conversion to work * as expected. If data conversion is not required, this restriction is