mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mikko Perttunen <mperttunen@nvidia.com>
To: Thierry Reding <thierry.reding@kernel.org>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	stable@vger.kernel.org
Cc: Svyatoslav Ryhel <clamor95@gmail.com>,
	dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Patrick Fischer <admin@tsv-stahl-riesa.de>,
	admin@tsv-stahl-riesa.de
Subject: Re: [PATCH] gpu: host1x: Cancel the fence when a syncpoint wait is interrupted
Date: Fri, 20 Nov 2026 12:16:15 +0900	[thread overview]
Message-ID: <xW4QZMkHQ7ahYXD5Tq5ciA@nvidia.com> (raw)
In-Reply-To: <20261113-upstream-host1x-fence-cancel-v1-1-89f453504222@tsv-stahl-riesa.de>

On Saturday, November 14, 2026 4:01 AM Patrick Fischer via B4 Relay wrote:
> From: Patrick Fischer <admin@tsv-stahl-riesa.de>
> 
> 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@vger.kernel.org
> Reported-by: Svyatoslav Ryhel <clamor95@gmail.com>
> Signed-off-by: Patrick Fischer <admin@tsv-stahl-riesa.de>
> ---

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@tsv-stahl-riesa.de>
> 
> 
> 





      reply	other threads:[~2026-11-20  3:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 19:01 Patrick Fischer via B4 Relay
2026-11-20  3:16 ` Mikko Perttunen [this message]

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=xW4QZMkHQ7ahYXD5Tq5ciA@nvidia.com \
    --to=mperttunen@nvidia.com \
    --cc=admin@tsv-stahl-riesa.de \
    --cc=airlied@gmail.com \
    --cc=clamor95@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jonathanh@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    --cc=thierry.reding@kernel.org \
    /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

all inboxes | Powered by JetHome®