From: Matthew Brost <matthew.brost@intel.com>
To: <phasta@kernel.org>
Cc: "qianyi liu" <liuqianyi125@gmail.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Christian König" <ckoenig.leichtzumerken@gmail.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/scheduler: Fix mem leak when last_scheduled signaled
Date: Mon, 24 Feb 2025 21:46:27 -0800 [thread overview]
Message-ID: <Z71ZM9Cs1Wb4mhD3@lstrano-desk.jf.intel.com> (raw)
In-Reply-To: <3b369e1a49b354852f361b103999673e4f7906a9.camel@mailbox.org>
On Mon, Feb 24, 2025 at 10:52:56AM +0100, Philipp Stanner wrote:
> Hello,
>
> subject line: please write "drm/sched" instead of "drm/scheduler". It
> has become the norm
>
> On Fri, 2025-02-21 at 14:27 +0800, qianyi liu wrote:
> > Problem: If prev(last_scheduled) was already signaled I encountred a
>
> prev(last_scheduled) almost reads like a function call. Maybe write
> "prev / last_scheduled"?
>
> > memory leak in drm_sched_entity_fini. This is because the
> > prev(last_scheduled) fence is not free properly.
>
> s/free/freed
>
> >
> > Fix: Balance the prev(last_scheduled) fence refcnt when
> > dma_fence_add_callback failed.
> >
> > Signed-off-by: qianyi liu <liuqianyi125@gmail.com>
> > ---
> > drivers/gpu/drm/scheduler/sched_entity.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/scheduler/sched_entity.c
> > b/drivers/gpu/drm/scheduler/sched_entity.c
> > index 69bcf0e99d57..1c0c14bcf726 100644
> > --- a/drivers/gpu/drm/scheduler/sched_entity.c
> > +++ b/drivers/gpu/drm/scheduler/sched_entity.c
> > @@ -259,9 +259,12 @@ static void drm_sched_entity_kill(struct
> > drm_sched_entity *entity)
> > struct drm_sched_fence *s_fence = job->s_fence;
> >
> > dma_fence_get(&s_fence->finished);
> > - if (!prev || dma_fence_add_callback(prev, &job-
> > >finish_cb,
> > -
> > drm_sched_entity_kill_jobs_cb))
> > + if (!prev ||
> > + dma_fence_add_callback(prev, &job->finish_cb,
> > +
> > drm_sched_entity_kill_jobs_cb)) {
> > + dma_fence_put(prev);
>
> But now the fence will also be put when prev == NULL. Is that
dma_fence_put(NULL) is a NOP [1].
[1] https://elixir.bootlin.com/linux/v6.13.4/source/include/linux/dma-fence.h#L290
> intentional? It doesn't seem correct to me from looking at the commit
> message, which states "Balance […] refcnt when dma_fence_add_callback
> failed"
>
> It didn't get clear to me immediately which dma_fence_get() your new
> dma_fence_put() balances. Can you ellaborate on that or maybe write a
> comment?
drm_sched_entity_kill_jobs_cb(prev, ...) - Calls put 'prev'
drm_sched_entity_kill_jobs_cb(NULL, ...) - Does not.
>
> But also be handy of could share the kmemleak trace.
>
Agree kmemleak trace would good, include in commit message, but the
patch looks correct to me.
I also think the commit message need a bit of work as Phillip suggests.
Matt
>
> Thanks
> P.
>
> > drm_sched_entity_kill_jobs_cb(NULL, &job-
> > >finish_cb);
> > + }
> >
> > prev = &s_fence->finished;
> > }
>
next prev parent reply other threads:[~2025-02-25 5:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-21 6:27 qianyi liu
2025-02-24 9:52 ` Philipp Stanner
2025-02-24 9:57 ` Philipp Stanner
2025-02-25 2:58 ` Qianyi Liu
2025-02-25 3:12 ` Qianyi Liu
2025-02-25 7:23 ` Philipp Stanner
2025-02-25 5:46 ` Matthew Brost [this message]
2025-02-25 8:19 ` Qianyi Liu
2025-02-25 7:18 ` Philipp Stanner
2025-02-25 13:09 ` Qianyi Liu
2025-02-25 14:00 ` Markus Elfring
2025-02-25 14:05 ` Philipp Stanner
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=Z71ZM9Cs1Wb4mhD3@lstrano-desk.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=airlied@gmail.com \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuqianyi125@gmail.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=phasta@kernel.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®