From: "Christian König" <christian.koenig@amd.com>
To: Julian Orth <ju.orth@gmail.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Sumit Semwal <sumit.semwal@linaro.org>,
Dmitry Osipenko <dmitry.osipenko@collabora.com>,
Rob Clark <robin.clark@oss.qualcomm.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org
Subject: Re: [PATCH 2/2] drm/syncobj: flatten chains when importing sync_file into timeline point
Date: Mon, 12 Oct 2026 15:06:14 +0200 [thread overview]
Message-ID: <ce33a3ee-b3e2-434f-8a78-535a22cd9d19@amd.com> (raw)
In-Reply-To: <CAHijbEV=510kPTYit=EbXtsYosQ+WOJ58Ey1AqK1Ca7Wb77bCA@mail.gmail.com>
On 10/12/26 13:42, Julian Orth wrote:
> On Mon, Oct 12, 2026 at 9:51 AM Christian König
> <christian.koenig@amd.com> wrote:
>>
>> On 10/10/26 20:07, Julian Orth wrote:
>>> A sync_file exported from a timeline point can contain a dma_fence_chain.
>>
>> No it can't, IIRC sync files are only supposed to contain raw fences or dma_fence_array containers.
>>
>> I think we never documented that and that's why this issue here leaked in.
>
> When I reviewed this patch before sending it in, I asked the AI if it
> would not be better to do the merging at export time. It was adamant
> that it had to be at import time because of commit 519f490d by
> yourself:
>
> dma-buf/sync-file: fix warning about fence containers
>
> The dma_fence_chain containers can show up in sync_files as well
Yeah that fix was driven by the warning but it was never a complete audit.
IIRC we later found multiple other issues as well and because of that the approach of exporting dma_fence_chain in syncfiles was dropped for at least one other occasion.
I don't mind allowing a dma_fence_chain in a syncfile, but we really need to audit the code because I can't think of a way how to do this automatically.
Mixing dma_fence_chain and dma_fence_array containers into larger data structures can trivially exhaust the kernel stack on release/cleanup because of recursion.
Regards,
Christian.
>
>>
>> I'm not sure if that doesn't break anywhere else as well, so I think we should fix the exporting side instead.
>>
>> Alternatively we need to audit everywhere where fences from syncfiles can be imported somewhere else.
>>
>> Regards,
>> Christian.
>>
>>> Importing such a sync_file into a timeline point with
>>> DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE |
>>> DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_TIMELINE passes the chain directly to
>>> dma_fence_chain_init() and triggers
>>>
>>> WARNING: drivers/dma-buf/dma-fence-chain.c:286 at dma_fence_chain_init
>>>
>>> because chain fences must not be wrapped in other chain fences.
>>>
>>> Flatten the fence with dma_fence_unwrap_merge() before adding it to the
>>> timeline, as drm_syncobj_transfer_to_timeline() already does.
>>>
>>> Reproducer:
>>>
>>> 1. Export a sync_file from a point > 0 of a timeline syncobj with
>>> DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD.
>>> 2. Import it into a point > 0 of another timeline syncobj with
>>> DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE.
>>>
>>> Fixes: c2d3a7300695 ("drm/syncobj: Extend EXPORT_SYNC_FILE for timeline syncobjs")
>>> Assisted-by: Claude:claude-opus-5-5
>>> Signed-off-by: Julian Orth <ju.orth@gmail.com>
>>> ---
>>> drivers/gpu/drm/drm_syncobj.c | 12 +++++++++++-
>>> 1 file changed, 11 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
>>> index 5ca5163d0..c545af77e 100644
>>> --- a/drivers/gpu/drm/drm_syncobj.c
>>> +++ b/drivers/gpu/drm/drm_syncobj.c
>>> @@ -742,8 +742,18 @@ static int drm_syncobj_import_sync_file_fence(struct drm_file *file_private,
>>> }
>>>
>>> if (point) {
>>> - struct dma_fence_chain *chain = dma_fence_chain_alloc();
>>> + struct dma_fence_chain *chain;
>>> + struct dma_fence *tmp;
>>> +
>>> + tmp = dma_fence_unwrap_merge(fence);
>>> + dma_fence_put(fence);
>>> + fence = tmp;
>>> + if (!fence) {
>>> + drm_syncobj_put(syncobj);
>>> + return -ENOMEM;
>>> + }
>>>
>>> + chain = dma_fence_chain_alloc();
>>> if (!chain) {
>>> ret = -ENOMEM;
>>> goto out;
>>
prev parent reply other threads:[~2026-10-12 13:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 18:07 [PATCH 0/2] drm/syncobj: fix sync_file import into timeline points Julian Orth
2026-10-10 18:07 ` [PATCH 1/2] drm/syncobj: fix fence and syncobj leak in drm_syncobj_import_sync_file_fence Julian Orth
2026-10-12 7:45 ` Christian König
2026-10-12 11:38 ` Julian Orth
2026-10-12 12:56 ` Christian König
2026-10-10 18:07 ` [PATCH 2/2] drm/syncobj: flatten chains when importing sync_file into timeline point Julian Orth
2026-10-12 7:51 ` Christian König
2026-10-12 11:42 ` Julian Orth
2026-10-12 13:06 ` Christian König [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=ce33a3ee-b3e2-434f-8a78-535a22cd9d19@amd.com \
--to=christian.koenig@amd.com \
--cc=airlied@gmail.com \
--cc=dmitry.osipenko@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ju.orth@gmail.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=robin.clark@oss.qualcomm.com \
--cc=simona@ffwll.ch \
--cc=sumit.semwal@linaro.org \
--cc=tzimmermann@suse.de \
/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®