Files
android_kernel_xiaomi_sm8450/drivers/gpu/drm
Desmond Cheong Zhi Xi 06a553a99b drm: serialize drm_file.master with a new spinlock
[ Upstream commit 0b0860a3cf5eccf183760b1177a1dcdb821b0b66 ]

Currently, drm_file.master pointers should be protected by
drm_device.master_mutex when being dereferenced. This is because
drm_file.master is not invariant for the lifetime of drm_file. If
drm_file is not the creator of master, then drm_file.is_master is
false, and a call to drm_setmaster_ioctl will invoke
drm_new_set_master, which then allocates a new master for drm_file and
puts the old master.

Thus, without holding drm_device.master_mutex, the old value of
drm_file.master could be freed while it is being used by another
concurrent process.

However, it is not always possible to lock drm_device.master_mutex to
dereference drm_file.master. Through the fbdev emulation code, this
might occur in a deep nest of other locks. But drm_device.master_mutex
is also the outermost lock in the nesting hierarchy, so this leads to
potential deadlocks.

To address this, we introduce a new spin lock at the bottom of the
lock hierarchy that only serializes drm_file.master. With this change,
the value of drm_file.master changes only when both
drm_device.master_mutex and drm_file.master_lookup_lock are
held. Hence, any process holding either of those locks can ensure that
the value of drm_file.master will not change concurrently.

Since no lock depends on the new drm_file.master_lookup_lock, when
drm_file.master is dereferenced, but drm_device.master_mutex cannot be
held, we can safely protect the master pointer with
drm_file.master_lookup_lock.

Reported-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Desmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210712043508.11584-5-desmondcheongzx@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-09-18 13:40:19 +02:00
..
2021-07-19 09:44:58 +02:00
2020-08-11 11:58:31 +10:00
2021-09-03 10:09:26 +02:00
2021-09-15 09:50:35 +02:00
2020-04-03 17:11:41 +02:00
2020-09-08 14:41:40 +10:00
2021-05-14 09:50:22 +02:00
2020-09-11 10:47:19 +02:00
2021-05-11 14:47:26 +02:00
2020-05-27 14:31:42 +03:00
2020-04-03 17:11:41 +02:00
2020-09-21 10:45:08 +02:00
2020-09-21 10:45:08 +02:00
2020-05-29 12:58:11 +02:00
2020-09-21 10:45:08 +02:00
2020-08-11 11:58:31 +10:00
2021-01-27 11:54:55 +01:00
2021-03-30 14:31:51 +02:00