From: Thomas Zimmermann <tzimmermann@suse.de>
To: "Maíra Canal" <mcanal@igalia.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"Melissa Wen" <mwen@igalia.com>, "Iago Toral" <itoral@igalia.com>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
"Dave Stevenson" <dave.stevenson@raspberrypi.com>,
"Raspberry Pi Kernel Maintenance" <kernel-list@raspberrypi.com>
Cc: kernel-dev@igalia.com, dri-devel@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v3 2/7] drm: Add drm_timeout_rel_to_jiffies()
Date: Tue, 29 Sep 2026 10:07:18 +0200 [thread overview]
Message-ID: <1a4e787f-c61f-4892-ae7e-344880f5c7bf@suse.de> (raw)
In-Reply-To: <7dda1960-9e73-43af-bbb8-e6e7ba32a8f3@igalia.com>
Hi
Am 28.09.26 um 20:09 schrieb Maíra Canal:
> Hi Thomas,
>
> Thank you for your review!
>
> On 28/09/26 13:37, Thomas Zimmermann wrote:
>
> [...]
>
>>> +unsigned long drm_timeout_rel_to_jiffies(u64 timeout_nsec)
>>> +{
>>> + u64 secs;
>>> + u32 rem;
>>> +
>>> + /* Make 0 timeout means poll, as for the absolute variant. */
>>> + if (timeout_nsec == 0)
>>> + return 0;
>>> +
>>> + /*
>>> + * As nsecs_to_jiffies64() does not guard against overflow, split
>>> + * the timeout into whole seconds and nanoseconds. This way
>>> + * nsecs_to_jiffies64() is always handed a value below a second.
>>> + */
>>> + secs = div_u64_rem(timeout_nsec, NSEC_PER_SEC, &rem);
>>> + if (secs >= MAX_JIFFY_OFFSET / HZ)
>>> + return MAX_JIFFY_OFFSET;
>>> +
>>> + return min_t(u64, MAX_JIFFY_OFFSET,
>>> + secs_to_jiffies(secs) + nsecs_to_jiffies64(rem) + 1);
>>
>> The timeout is controled by user space, right? Can these additions
>> overflow? I see that secs is tested against MAX_JIFFY_OFFSET, but is
>> that sufficient?
>
> Although the timeout is controlled by user-space, the additions cannot
> overflow here. The secs test bounds the multiplication, which is why it
> is written as secs >= MAX_JIFFY_OFFSET / HZ rather than secs * HZ >=
> MAX_JIFFY_OFFSET (which could overflow).
>
> Past that check, we know that the remaining is smaller than one second
> and therefore, nsecs_to_jiffies64(rem) <= HZ - 1. So, the sum + 1 is at
> most MAX_JIFFY_OFFSET.
>
>>
>> BTW there was this NSEC % HZ test in the original code? What was it
>> good for? It is no longer useful?
>>
>
> I believe that NSEC_PER_SEC % HZ was only useful to check if it was a
> plain division, which wouldn't overflow. With the current approach, I
> believe it's no longer needed.
Thanks for answering my questions.
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Best regards
Thomas
>
> Best regards,
> - Maíra
>> Best regards
>> Thomas
>>
>>
>>> +}
>>> +EXPORT_SYMBOL(drm_timeout_rel_to_jiffies);
>>> diff --git a/include/drm/drm_timeout.h b/include/drm/drm_timeout.h
>>> index cd9621c52062..6ee222a3e97c 100644
>>> --- a/include/drm/drm_timeout.h
>>> +++ b/include/drm/drm_timeout.h
>>> @@ -12,5 +12,6 @@
>>> #include <linux/types.h>
>>> signed long drm_timeout_abs_to_jiffies(s64 timeout_nsec);
>>> +unsigned long drm_timeout_rel_to_jiffies(u64 timeout_nsec);
>>> #endif
>>>
>>
>
--
--
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)
next prev parent reply other threads:[~2026-09-29 8:07 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 19:42 [PATCH v3 0/7] drm: Consolidate the wait timeout conversion helpers Maíra Canal
2026-09-15 19:42 ` [PATCH v3 1/7] drm: Move drm_timeout_abs_to_jiffies() to drm_timeout.c Maíra Canal
2026-09-16 10:33 ` Jani Nikula
2026-09-28 16:03 ` Thomas Zimmermann
2026-09-28 16:12 ` Thomas Zimmermann
2026-09-28 16:23 ` Thomas Zimmermann
2026-09-15 19:42 ` [PATCH v3 2/7] drm: Add drm_timeout_rel_to_jiffies() Maíra Canal
2026-09-16 10:38 ` Jani Nikula
2026-09-16 10:38 ` Jani Nikula
2026-09-16 13:08 ` Maíra Canal
2026-09-16 16:06 ` Jani Nikula
2026-09-28 16:37 ` Thomas Zimmermann
2026-09-28 18:09 ` Maíra Canal
2026-09-29 8:07 ` Thomas Zimmermann [this message]
2026-09-15 19:42 ` [PATCH v3 3/7] drm/amdgpu: Use drm_timeout_abs_to_jiffies() Maíra Canal
2026-09-15 19:42 ` [PATCH v3 4/7] drm/v3d: Use drm_timeout_rel_to_jiffies() Maíra Canal
2026-09-29 8:22 ` Thomas Zimmermann
2026-09-15 19:42 ` [PATCH v3 5/7] drm/i915: " Maíra Canal
2026-09-16 10:42 ` Jani Nikula
2026-09-29 8:20 ` Thomas Zimmermann
2026-09-30 17:12 ` Andi Shyti
2026-09-15 19:42 ` [PATCH v3 6/7] drm/vc4: " Maíra Canal
2026-09-15 19:42 ` [PATCH v3 7/7] drm: Rename drm_utils.h to drm_panel_quirks.h Maíra Canal
2026-09-22 12:00 ` Maíra Canal
2026-09-29 8:17 ` Thomas Zimmermann
2026-09-15 21:21 ` ✓ i915.CI.BAT: success for drm: Consolidate the wait timeout conversion helpers (rev3) Patchwork
2026-09-16 9:14 ` ✓ i915.CI.Full: " Patchwork
2026-09-16 12:22 ` [PATCH v3 0/7] drm: Consolidate the wait timeout conversion helpers Christian König
2026-09-30 22:51 ` 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=1a4e787f-c61f-4892-ae7e-344880f5c7bf@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=itoral@igalia.com \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kernel-dev@igalia.com \
--cc=kernel-list@raspberrypi.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mcanal@igalia.com \
--cc=mripard@kernel.org \
--cc=mwen@igalia.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=tvrtko.ursulin@igalia.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.