From: Danilo Krummrich <dakr@redhat.com>
To: daniel@ffwll.ch, "Dave Airlie" <airlied@gmail.com>,
luben.tuikov@amd.com, l.stach@pengutronix.de,
"Bagas Sanjaya" <bagasdotme@gmail.com>,
andrey.grodzovsky@amd.com,
"Christian König" <christian.koenig@amd.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [Regression] drm/scheduler: track GPU active time per entity
Date: Tue, 28 Mar 2023 02:57:31 +0200 [thread overview]
Message-ID: <3e00d8a9-b6c4-8202-4f2d-5a659c61d094@redhat.com> (raw)
Hi all,
Commit df622729ddbf ("drm/scheduler: track GPU active time per entity")
tries to track the accumulated time that a job was active on the GPU
writing it to the entity through which the job was deployed to the
scheduler originally. This is done within drm_sched_get_cleanup_job()
which fetches a job from the schedulers pending_list.
Doing this can result in a race condition where the entity is already
freed, but the entity's newly added elapsed_ns field is still accessed
once the job is fetched from the pending_list.
After drm_sched_entity_destroy() being called it should be safe to free
the structure that embeds the entity. However, a job originally handed
over to the scheduler by this entity might still reside in the
schedulers pending_list for cleanup after drm_sched_entity_destroy()
already being called and the entity being freed. Hence, we can run into
a UAF.
In my case it happened that a job, as explained above, was just picked
from the schedulers pending_list after the entity was freed due to the
client application exiting. Meanwhile this freed up memory was already
allocated for a subsequent client applications job structure again.
Hence, the new jobs memory got corrupted. Luckily, I was able to
reproduce the same corruption over and over again by just using
deqp-runner to run a specific set of VK test cases in parallel.
Fixing this issue doesn't seem to be very straightforward though (unless
I miss something), which is why I'm writing this mail instead of sending
a fix directly.
Spontaneously, I see three options to fix it:
1. Rather than embedding the entity into driver specific structures
(e.g. tied to file_priv) we could allocate the entity separately and
reference count it, such that it's only freed up once all jobs that were
deployed through this entity are fetched from the schedulers pending list.
2. Somehow make sure drm_sched_entity_destroy() does block until all
jobs deployed through this entity were fetched from the schedulers
pending list. Though, I'm pretty sure that this is not really desirable.
3. Just revert the change and let drivers implement tracking of GPU
active times themselves.
In the case of just reverting the change I'd propose to also set a jobs
entity pointer to NULL once the job was taken from the entity, such
that in case of a future issue we fail where the actual issue resides
and to make it more obvious that the field shouldn't be used anymore
after the job was taken from the entity.
I'm happy to implement the solution we agree on. However, it might also
make sense to revert the change until we have a solution in place. I'm
also happy to send a revert with a proper description of the problem.
Please let me know what you think.
- Danilo
next reply other threads:[~2023-03-28 0:58 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 0:57 Danilo Krummrich [this message]
2023-03-28 8:54 ` [Regression] drm/scheduler: track GPU active time per entity Lucas Stach
2023-04-04 4:31 ` Luben Tuikov
2023-04-05 14:05 ` Danilo Krummrich
2023-04-05 14:05 ` Danilo Krummrich
2023-04-05 16:09 ` Luben Tuikov
2023-04-05 16:09 ` Luben Tuikov
2023-04-05 16:23 ` Danilo Krummrich
2023-04-05 16:23 ` Danilo Krummrich
2023-04-06 8:22 ` Christian König
2023-04-06 8:22 ` Christian König
2023-04-06 8:27 ` Daniel Vetter
2023-04-06 8:27 ` Daniel Vetter
2023-04-06 9:05 ` Asahi Lina
2023-04-06 9:05 ` Asahi Lina
2023-04-06 10:09 ` Daniel Vetter
2023-04-06 10:09 ` Daniel Vetter
2023-04-06 12:21 ` Asahi Lina
2023-04-06 12:21 ` Asahi Lina
2023-04-06 13:37 ` Daniel Vetter
2023-04-06 13:37 ` Daniel Vetter
2023-04-06 14:43 ` Asahi Lina
2023-04-06 14:43 ` Asahi Lina
2023-04-06 15:30 ` Daniel Vetter
2023-04-06 15:30 ` Daniel Vetter
2023-04-06 17:11 ` Asahi Lina
2023-04-06 17:11 ` Asahi Lina
2023-04-06 17:42 ` Daniel Vetter
2023-04-06 17:42 ` Daniel Vetter
2023-04-06 17:46 ` Daniel Vetter
2023-04-06 10:45 ` Lucas Stach
2023-04-06 10:45 ` Lucas Stach
2023-04-06 12:09 ` Daniel Vetter
2023-04-06 12:09 ` Daniel Vetter
2023-04-06 12:19 ` Lucas Stach
2023-04-06 12:19 ` Lucas Stach
2023-04-06 13:56 ` Daniel Vetter
2023-04-06 13:56 ` Daniel Vetter
2023-04-06 14:21 ` Christian König
2023-04-06 14:21 ` Christian König
2023-04-06 15:24 ` Lucas Stach
2023-04-06 15:24 ` Lucas Stach
2023-04-06 15:33 ` Christian König
2023-04-06 15:33 ` Christian König
2023-04-06 15:59 ` Daniel Vetter
2023-04-06 15:59 ` Daniel Vetter
2023-04-06 16:23 ` Daniel Vetter
2023-04-06 16:23 ` Daniel Vetter
2023-04-06 22:36 ` Luben Tuikov
2023-04-06 22:36 ` Luben Tuikov
2023-04-06 22:30 ` Luben Tuikov
2023-04-06 22:30 ` Luben Tuikov
2023-04-05 17:44 ` Lucas Stach
2023-04-05 20:44 ` Luben Tuikov
2023-04-06 15:58 ` Lucas Stach
2023-04-06 22:06 ` Luben Tuikov
[not found] <e3e07282-136f-5239-96ae-4aeb2d3c95d7.ref@yahoo.de>
2023-03-28 0:54 ` Danilo Krummrich
2023-03-28 10:29 ` Christian König
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=3e00d8a9-b6c4-8202-4f2d-5a659c61d094@redhat.com \
--to=dakr@redhat.com \
--cc=airlied@gmail.com \
--cc=andrey.grodzovsky@amd.com \
--cc=bagasdotme@gmail.com \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=l.stach@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=luben.tuikov@amd.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.