Re: [PATCH] gpu: host1x: Cancel the fence when a syncpoint wait is interrupted
From: Mikko Perttunen
Date: Thu Nov 19 2026 - 22:17:30 EST
On Saturday, November 14, 2026 4:01 AM Patrick Fischer via B4 Relay wrote:
> From: Patrick Fischer <admin@xxxxxxxxxxxxxxxxxx>
>
> host1x_syncpt_wait() creates its fence without the internal 30 second
> timeout and cancels it only when dma_fence_wait_timeout() returns 0.
> If the wait is interrupted, dma_fence_wait_timeout() returns
> -ERESTARTSYS and the fence is left on the syncpoint's fence list,
> holding the reference that host1x_syncpt_fence_enable_signaling() took
> for the interrupt path. It is freed only once the syncpoint reaches the
> threshold, which may never happen.
>
> Callers that retry on -ERESTARTSYS allocate a new fence each time.
> tegra20_channel_capture_frame() retries in a loop without delay, and
> while the syncpoint does not move, for example with a camera that
> delivers no frames, every round leaks one fence until the system runs
> out of memory. Svyatoslav Ryhel reported this as an out-of-memory crash
> in the VI capture thread; the allocations in his report come from
> host1x_fence_create(), called by host1x_syncpt_wait() from
> tegra20_chan_capture_kthread_start(). The DRM syncpoint wait IOCTLs end
> up in host1x_syncpt_wait() as well, so a process that is signalled while
> waiting leaks a fence the same way.
>
> Cancel the fence whenever the wait did not succeed. host1x_fence_cancel()
> is safe if the interrupt path has signalled the fence in the meantime,
> as do_fence_timeout() then returns early.
>
> The leak was found with the help of an LLM assistant reading the host1x
> and dma-fence code against the call chain in the report.
>
> Fixes: d5179020f5ce ("gpu: host1x: External timeout/cancellation for fences")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
> Signed-off-by: Patrick Fischer <admin@xxxxxxxxxxxxxxxxxx>
> ---
Nice find, thank you!
One thing I'd like to add to this patch is moving the call to
INIT_LIST_HEAD from host1x_intr_add_fence_locked to host1x_fence_create.
Otherwise, theoretically, a dma_fence_wait_timeout error path that
returns before calling enable_signaling would with this patch result in
host1x_fence_cancel being called, that would go into
host1x_intr_remove_fence which assumes the list head has been
initialized.
Mikko
> Svyatoslav reported the out-of-memory crash, and he confirmed off-list
> that this patch stops the leak on his LG P895 (Tegra30). I left out a
> Tested-by so that he can give it here.
>
> I could not test this myself: the Tegra Note 7 I work on has no
> working camera path in mainline yet. Build-tested for arm and arm64.
> The DRM IOCTL case in the changelog comes from reading the code; I have
> not tried it.
>
> The retry loop in tegra20_channel_capture_frame() still spins without
> delay as long as the wait keeps returning -ERESTARTSYS. With this patch
> that costs CPU time instead of memory; how the VI driver should handle
> an interrupted wait is a separate question.
>
> Tool use (see Documentation/process/generated-content.rst): an LLM
> assistant (Claude, in a chat) found the leak by reading
> host1x_syncpt_wait() and the fence code against the call chain in the
> OOM report. Claude Code then checked the finding against the code and
> wrote the change, the changelog and this note from my notes and
> instructions. I reviewed the change.
> ---
> drivers/gpu/host1x/syncpt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/host1x/syncpt.c b/drivers/gpu/host1x/syncpt.c
> index fe74ff6fc6f2..f9c871f218f3 100644
> --- a/drivers/gpu/host1x/syncpt.c
> +++ b/drivers/gpu/host1x/syncpt.c
> @@ -247,7 +247,7 @@ int host1x_syncpt_wait(struct host1x_syncpt *sp, u32 thresh, long timeout,
> return PTR_ERR(fence);
>
> wait_err = dma_fence_wait_timeout(fence, true, timeout);
> - if (wait_err == 0)
> + if (wait_err <= 0)
> host1x_fence_cancel(fence);
> dma_fence_put(fence);
>
>
> ---
> base-commit: 9d66f26fefacebfeed15de31c1123451a17ff119
> change-id: 20261113-upstream-host1x-fence-cancel-0b32753150d6
>
> Best regards,
> --
> Patrick Fischer <admin@xxxxxxxxxxxxxxxxxx>
>
>
>