From: sashiko-bot@kernel.org
To: "Maíra Canal" <mcanal@igalia.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 2/6] drm: Add drm_timeout_rel_to_jiffies()
Date: Sun, 09 Aug 2026 19:33:03 +0000 [thread overview]
Message-ID: <20260809193304.4FFA91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260809-drm-timeout-helpers-v1-2-2de67405a145@igalia.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The overflow guard in `drm_timeout_rel_to_jiffies()` is ineffective on 64-bit architectures, failing to prevent internal `u64` wrap-around in `nsecs_to_jiffies64()` for specific inputs.
--
--- Patch [2]: [PATCH 2/6] drm: Add drm_timeout_rel_to_jiffies() ---
commit c015d0990b1688d1fc81fe1000d64e7430d1d234
Author: Maíra Canal <mcanal@igalia.com>
drm: Add drm_timeout_rel_to_jiffies()
This commit introduces drm_timeout_rel_to_jiffies() to convert relative
nanosecond timeouts into jiffies. It is intended for drivers whose wait UAPI
takes a duration instead of an absolute deadline, and includes an overflow
check to safely handle large values.
> diff --git a/drivers/gpu/drm/drm_timeout.c b/drivers/gpu/drm/drm_timeout.c
> index 78e9f65e54779..30ad3e8ebc92a 100644
> --- a/drivers/gpu/drm/drm_timeout.c
> +++ b/drivers/gpu/drm/drm_timeout.c
[ ... ]
> @@ -45,3 +46,31 @@ signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec)
> return timeout_jiffies64 + 1;
> }
> EXPORT_SYMBOL(drm_timeout_abs_to_jiffies);
> +
> +/**
> + * drm_timeout_rel_to_jiffies - calculate jiffies timeout from relative value
[ ... ]
> +unsigned long drm_timeout_rel_to_jiffies(u64 timeout_nsec)
> +{
> + /* make 0 timeout means poll, as for the absolute variant */
> + if (timeout_nsec == 0)
> + return 0;
> +
> + /* nsecs_to_jiffies64() does not guard against overflow */
> + if ((NSEC_PER_SEC % HZ) != 0 &&
> + div_u64(timeout_nsec, NSEC_PER_SEC) >= MAX_JIFFY_OFFSET / HZ)
> + return MAX_JIFFY_OFFSET;
[Severity: Medium]
Is this overflow guard effective on 64-bit architectures?
On 64-bit systems, MAX_JIFFY_OFFSET is around ~4.6e18, so MAX_JIFFY_OFFSET / HZ
is roughly ~4.6e16. Since timeout_nsec is a u64, div_u64(timeout_nsec, NSEC_PER_SEC)
can never exceed ~1.8e10, meaning this condition is mathematically impossible to
trigger on 64-bit platforms.
Because the guard can never be met, can highly specific inputs cause
nsecs_to_jiffies64() to silently wrap around internally?
For example, when HZ makes nsecs_to_jiffies64() use the n * 9 calculation, a
carefully chosen timeout_nsec (like ~64.9 years, or around 2049638230412172402
ns) could wrap around internally to a near-zero jiffies value, resulting in a
premature timeout.
> +
> + return min_t(u64, MAX_JIFFY_OFFSET, nsecs_to_jiffies64(timeout_nsec) + 1);
> +}
> +EXPORT_SYMBOL(drm_timeout_rel_to_jiffies);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260809-drm-timeout-helpers-v1-0-2de67405a145@igalia.com?part=2
next prev parent reply other threads:[~2026-08-09 19:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 19:23 [PATCH 0/6] drm: Consolidate the wait timeout conversion helpers Maíra Canal
2026-08-09 19:23 ` [PATCH 1/6] drm: Move drm_timeout_abs_to_jiffies() to drm_timeout.c Maíra Canal
2026-08-09 19:23 ` [PATCH 2/6] drm: Add drm_timeout_rel_to_jiffies() Maíra Canal
2026-08-09 19:33 ` sashiko-bot [this message]
2026-08-10 13:26 ` Christian König
2026-08-09 19:23 ` [PATCH 3/6] drm/amdgpu: Use drm_timeout_abs_to_jiffies() Maíra Canal
2026-08-10 13:34 ` Christian König
2026-08-10 15:32 ` Maíra Canal
2026-08-10 17:47 ` Christian König
2026-08-09 19:24 ` [PATCH 4/6] drm/v3d: Use drm_timeout_rel_to_jiffies() Maíra Canal
2026-08-09 19:24 ` [PATCH 5/6] drm/i915: " Maíra Canal
2026-08-09 19:24 ` [PATCH 6/6] drm/vc4: " Maíra Canal
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=20260809193304.4FFA91F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=mcanal@igalia.com \
--cc=sashiko-reviews@lists.linux.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