Re: [PATCH v4] drm/gem: Make the GEM LRU lock part of drm_device
On Thu, May 21, 2026 at 11:07:32AM +0200, Simona Vetter wrote: > The assumption is that committers will ask maintainers for help if they're > trying to push a patch that results in tons of conflicts when applying > (since development should happen on top of linux-next or drm-tip). Could > probably improve that a bit. But also, often it's only clear after > applying that a fixup is needed, and then it's pushed already. And with > committers there's no undoing pushed patches. So it's just part of the > deal with having lots of committers imo that history is a bit more a mess > at times. What I see frequently in -next is people just cherry picking the fixes into the development branch instead of doing a merge, this leads to pointless conflicts as soon as someone adds new code on top of the fix. I gather the stable people also aren't terribly enthusiastic about this workflow. There also seem to be repeated situations where people mail me saying they're going to introduce a bunch of conflicts that are sufficiently non-obvious they're sending me fixups in whatever random form, even where people seem to think it's a big problem themselves there seems to be a helplessness about actually doing the merge. signature.asc Description: PGP signature
Re: [PATCH v4] drm/gem: Make the GEM LRU lock part of drm_device
On Tue, May 19, 2026 at 01:51:53PM +0200, Boris Brezillon wrote: > On Tue, 19 May 2026 12:37:16 +0100 > Mark Brown wrote: > > > On Mon, May 18, 2026 at 04:52:25PM +0200, Boris Brezillon wrote: > > > +Mark for the silent conflict resolution needed to reconcile > > > drm-misc-fixes and drm-next/drm-misc-next. > > > > This doesn't appear to be a drm-misc thing, I was seeing issues on the > > DRM tree. The patch does seem to ahve resolved things though. Please > > consider topic branches! > > I'm just following the dim guide for resolution of conflicts between > drm trees[1], so that's probably something to discuss with the > DRM/DRM-misc maintainers. As for the suggestion to use topic branches, > I've never heard of it being used for -fixes vs -next conflict > resolution, every time I've gone through this process it was for > xxx-next vs yyy-next conflict (xxx and yyy being different subsystem > trees). > > Maxime, Thomas, Maarteen, Sima and/or Dave, any suggestion/opinion? Yeah, in general we do substantially fewer topic branches than other subsystems. That's fallout from the committer model, which just want a branch to push their patches and be done with it all - they're not full maintainers, we don't magically have more of those. And sometimes that results in more of a mess than necessary. We try to keep the mess in check by doing backmerges as needed, ideally before applying a patch. It's not super well documented since when/how to backmerge is part of the section for maintainers: https://drm.pages.freedesktop.org/maintainer-tools/maintainer/maintainer-drm-misc.html The assumption is that committers will ask maintainers for help if they're trying to push a patch that results in tons of conflicts when applying (since development should happen on top of linux-next or drm-tip). Could probably improve that a bit. But also, often it's only clear after applying that a fixup is needed, and then it's pushed already. And with committers there's no undoing pushed patches. So it's just part of the deal with having lots of committers imo that history is a bit more a mess at times. Cheers, Sima > [1]https://drm.pages.freedesktop.org/maintainer-tools/committer/conflict-resolution.html -- Simona Vetter Software Engineer http://blog.ffwll.ch
Re: [PATCH v4] drm/gem: Make the GEM LRU lock part of drm_device
On Tue, 19 May 2026 12:37:16 +0100 Mark Brown wrote: > On Mon, May 18, 2026 at 04:52:25PM +0200, Boris Brezillon wrote: > > +Mark for the silent conflict resolution needed to reconcile > > drm-misc-fixes and drm-next/drm-misc-next. > > This doesn't appear to be a drm-misc thing, I was seeing issues on the > DRM tree. The patch does seem to ahve resolved things though. Please > consider topic branches! I'm just following the dim guide for resolution of conflicts between drm trees[1], so that's probably something to discuss with the DRM/DRM-misc maintainers. As for the suggestion to use topic branches, I've never heard of it being used for -fixes vs -next conflict resolution, every time I've gone through this process it was for xxx-next vs yyy-next conflict (xxx and yyy being different subsystem trees). Maxime, Thomas, Maarteen, Sima and/or Dave, any suggestion/opinion? [1]https://drm.pages.freedesktop.org/maintainer-tools/committer/conflict-resolution.html
Re: [PATCH v4] drm/gem: Make the GEM LRU lock part of drm_device
On Mon, May 18, 2026 at 04:52:25PM +0200, Boris Brezillon wrote: > +Mark for the silent conflict resolution needed to reconcile > drm-misc-fixes and drm-next/drm-misc-next. This doesn't appear to be a drm-misc thing, I was seeing issues on the DRM tree. The patch does seem to ahve resolved things though. Please consider topic branches! signature.asc Description: PGP signature
Re: [PATCH v4] drm/gem: Make the GEM LRU lock part of drm_device
On Mon, 18 May 2026 16:52:25 +0200
Boris Brezillon wrote:
> +Mark for the silent conflict resolution needed to reconcile
> drm-misc-fixes and drm-next/drm-misc-next.
>
> On Mon, 18 May 2026 13:41:45 +0200
> Boris Brezillon wrote:
>
> > Recently, a few races have been discovered in the GEM LRU logic, all
> > of them caused by the fact the LRU lock is accessed through
> > gem->lru->lock, and that very same lock also protects changes to
> > gem->lru, leading to situations where gem->lru needs to first be
> > accessed without the lock held, to then get the lru to access the lock
> > through and finally take the lock and do the expected operation.
> >
> > Currently, the only driver making use of this API (MSM) declares a
> > device-wide lock, and the user we're about to add (panthor) will
> > do the same. There's no evidence that we will ever have a driver
> > that wants different pools of LRUs protected by different locks under
> > the same drm_device. So we're better off moving this lock to drm_device
> > and always locking it through obj->dev->gem_lru_mutex, or directly
> > through dev->gem_lru_mutex.
> >
> > If anyone ever needs more fine-grained locking, this can be revisited
> > to pass some drm_gem_lru_pool object representing the pool of LRUs
> > under a specific lock, but for now, the per-device lock seems to be
> > enough.
> >
> > Fixes: e7c2af13f811 ("drm/gem: Add LRU/shrinker helper")
> > Reported-by: Chia-I Wu
> > Closes: https://gitlab.freedesktop.org/panfrost/linux/-/work_items/86
> > Reviewed-by: Rob Clark
> > Reviewed-by: Liviu Dudau
> > Reviewed-by: Steven Price
> > Reviewed-by: Chia-I Wu
> > Signed-off-by: Boris Brezillon
>
> Queued to drm-misc-next.
s/drm-misc-next/drm-misc-fixes/, sorry for the typo.
>
> Note for the linux-next maintainers: below is the conflict
> resolution currently stored in drm-tip.
>
> Note for the drm-misc maintainers: we'll need a backmerge of the
> next -rc into drm-misc-next so we can resolve the conflict there.
>
> --->8---
> diff --git a/drivers/gpu/drm/panthor/panthor_device.h
> b/drivers/gpu/drm/panthor/panthor_device.h
> index 4e4607bca7cc..a412a50eec76 100644
> --- a/drivers/gpu/drm/panthor/panthor_device.h
> +++ b/drivers/gpu/drm/panthor/panthor_device.h
> @@ -187,9 +187,6 @@ struct panthor_device {
> /** @reclaim.shrinker: Shrinker instance */
> struct shrinker *shrinker;
>
> - /** @reclaim.lock: Lock protecting all LRUs */
> - struct mutex lock;
> -
> /**
>* @reclaim.unused: BOs with unused pages
>*
> diff --git a/drivers/gpu/drm/panthor/panthor_gem.c
> b/drivers/gpu/drm/panthor/panthor_gem.c
> index 13295d7a593d..abe0c5bb1bca 100644
> --- a/drivers/gpu/drm/panthor/panthor_gem.c
> +++ b/drivers/gpu/drm/panthor/panthor_gem.c
> @@ -1495,13 +1495,13 @@ panthor_gem_shrinker_scan(struct shrinker *shrinker,
> struct shrink_control *sc)
> if (!can_swap())
> goto out;
>
> - freed += drm_gem_lru_scan(&ptdev->reclaim.unused,
> + freed += drm_gem_lru_scan(&ptdev->base, &ptdev->reclaim.unused,
> sc->nr_to_scan - freed, &remaining,
> panthor_gem_try_evict_no_resv_wait, NULL);
> if (freed >= sc->nr_to_scan)
> goto out;
>
> - freed += drm_gem_lru_scan(&ptdev->reclaim.mmapped,
> + freed += drm_gem_lru_scan(&ptdev->base, &ptdev->reclaim.mmapped,
> sc->nr_to_scan - freed, &remaining,
> panthor_gem_try_evict_no_resv_wait, NULL);
> if (freed >= sc->nr_to_scan)
> @@ -1515,7 +1515,7 @@ panthor_gem_shrinker_scan(struct shrinker *shrinker,
> struct shrink_control *sc)
> if (freed >= sc->nr_to_scan)
> goto out;
>
> - freed += drm_gem_lru_scan(&ptdev->reclaim.gpu_mapped_shared,
> + freed += drm_gem_lru_scan(&ptdev->base,
> &ptdev->reclaim.gpu_mapped_shared,
> sc->nr_to_scan - freed, &remaining,
> panthor_gem_try_evict, NULL);
>
> @@ -1544,21 +1544,16 @@ panthor_gem_shrinker_scan(struct shrinker *shrinker,
> struct shrink_control *sc)
> int panthor_gem_shrinker_init(struct panthor_device *ptdev)
> {
> struct shrinker *shrinker;
> - int ret;
> -
> - ret = drmm_mutex_init(&ptdev->base, &ptdev->reclaim.lock);
> - if (ret)
> - return ret;
>
> INIT_LIST_HEAD(&ptdev->reclaim.vms);
> - drm_gem_lru_init(&ptdev->reclaim.unused, &ptdev->reclaim.lock);
> - drm_gem_lru_init(&ptdev->reclaim.mmapped, &ptdev->reclaim.lock);
> - drm_gem_lru_init(&ptdev->reclaim.gpu_mapped_shared,
> &ptdev->reclaim.lock);
> + drm_gem_lru_init(&ptdev->reclaim.unused);
> + drm_gem_lru_init(&ptdev->reclaim.mmapped);
> + drm_gem_lru_init(&ptdev->reclaim.gpu_mapped_shared);
> ptdev->reclaim.gpu_mapped_count = 0;
>
> /* Teach
Re: [PATCH v4] drm/gem: Make the GEM LRU lock part of drm_device
+Mark for the silent conflict resolution needed to reconcile
drm-misc-fixes and drm-next/drm-misc-next.
On Mon, 18 May 2026 13:41:45 +0200
Boris Brezillon wrote:
> Recently, a few races have been discovered in the GEM LRU logic, all
> of them caused by the fact the LRU lock is accessed through
> gem->lru->lock, and that very same lock also protects changes to
> gem->lru, leading to situations where gem->lru needs to first be
> accessed without the lock held, to then get the lru to access the lock
> through and finally take the lock and do the expected operation.
>
> Currently, the only driver making use of this API (MSM) declares a
> device-wide lock, and the user we're about to add (panthor) will
> do the same. There's no evidence that we will ever have a driver
> that wants different pools of LRUs protected by different locks under
> the same drm_device. So we're better off moving this lock to drm_device
> and always locking it through obj->dev->gem_lru_mutex, or directly
> through dev->gem_lru_mutex.
>
> If anyone ever needs more fine-grained locking, this can be revisited
> to pass some drm_gem_lru_pool object representing the pool of LRUs
> under a specific lock, but for now, the per-device lock seems to be
> enough.
>
> Fixes: e7c2af13f811 ("drm/gem: Add LRU/shrinker helper")
> Reported-by: Chia-I Wu
> Closes: https://gitlab.freedesktop.org/panfrost/linux/-/work_items/86
> Reviewed-by: Rob Clark
> Reviewed-by: Liviu Dudau
> Reviewed-by: Steven Price
> Reviewed-by: Chia-I Wu
> Signed-off-by: Boris Brezillon
Queued to drm-misc-next.
Note for the linux-next maintainers: below is the conflict
resolution currently stored in drm-tip.
Note for the drm-misc maintainers: we'll need a backmerge of the
next -rc into drm-misc-next so we can resolve the conflict there.
--->8---
diff --git a/drivers/gpu/drm/panthor/panthor_device.h
b/drivers/gpu/drm/panthor/panthor_device.h
index 4e4607bca7cc..a412a50eec76 100644
--- a/drivers/gpu/drm/panthor/panthor_device.h
+++ b/drivers/gpu/drm/panthor/panthor_device.h
@@ -187,9 +187,6 @@ struct panthor_device {
/** @reclaim.shrinker: Shrinker instance */
struct shrinker *shrinker;
- /** @reclaim.lock: Lock protecting all LRUs */
- struct mutex lock;
-
/**
* @reclaim.unused: BOs with unused pages
*
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c
b/drivers/gpu/drm/panthor/panthor_gem.c
index 13295d7a593d..abe0c5bb1bca 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -1495,13 +1495,13 @@ panthor_gem_shrinker_scan(struct shrinker *shrinker,
struct shrink_control *sc)
if (!can_swap())
goto out;
- freed += drm_gem_lru_scan(&ptdev->reclaim.unused,
+ freed += drm_gem_lru_scan(&ptdev->base, &ptdev->reclaim.unused,
sc->nr_to_scan - freed, &remaining,
panthor_gem_try_evict_no_resv_wait, NULL);
if (freed >= sc->nr_to_scan)
goto out;
- freed += drm_gem_lru_scan(&ptdev->reclaim.mmapped,
+ freed += drm_gem_lru_scan(&ptdev->base, &ptdev->reclaim.mmapped,
sc->nr_to_scan - freed, &remaining,
panthor_gem_try_evict_no_resv_wait, NULL);
if (freed >= sc->nr_to_scan)
@@ -1515,7 +1515,7 @@ panthor_gem_shrinker_scan(struct shrinker *shrinker,
struct shrink_control *sc)
if (freed >= sc->nr_to_scan)
goto out;
- freed += drm_gem_lru_scan(&ptdev->reclaim.gpu_mapped_shared,
+ freed += drm_gem_lru_scan(&ptdev->base,
&ptdev->reclaim.gpu_mapped_shared,
sc->nr_to_scan - freed, &remaining,
panthor_gem_try_evict, NULL);
@@ -1544,21 +1544,16 @@ panthor_gem_shrinker_scan(struct shrinker *shrinker,
struct shrink_control *sc)
int panthor_gem_shrinker_init(struct panthor_device *ptdev)
{
struct shrinker *shrinker;
- int ret;
-
- ret = drmm_mutex_init(&ptdev->base, &ptdev->reclaim.lock);
- if (ret)
- return ret;
INIT_LIST_HEAD(&ptdev->reclaim.vms);
- drm_gem_lru_init(&ptdev->reclaim.unused, &ptdev->reclaim.lock);
- drm_gem_lru_init(&ptdev->reclaim.mmapped, &ptdev->reclaim.lock);
- drm_gem_lru_init(&ptdev->reclaim.gpu_mapped_shared,
&ptdev->reclaim.lock);
+ drm_gem_lru_init(&ptdev->reclaim.unused);
+ drm_gem_lru_init(&ptdev->reclaim.mmapped);
+ drm_gem_lru_init(&ptdev->reclaim.gpu_mapped_shared);
ptdev->reclaim.gpu_mapped_count = 0;
/* Teach lockdep about lock ordering wrt. shrinker: */
fs_reclaim_acquire(GFP_KERNEL);
- might_lock(&ptdev->reclaim.lock);
+ might_lock(&ptdev->base.gem_lru_mutex);
fs_reclaim_release(GFP_KERNEL);
shrinker = shrinker_alloc(0,
[PATCH v4] drm/gem: Make the GEM LRU lock part of drm_device
Recently, a few races have been discovered in the GEM LRU logic, all
of them caused by the fact the LRU lock is accessed through
gem->lru->lock, and that very same lock also protects changes to
gem->lru, leading to situations where gem->lru needs to first be
accessed without the lock held, to then get the lru to access the lock
through and finally take the lock and do the expected operation.
Currently, the only driver making use of this API (MSM) declares a
device-wide lock, and the user we're about to add (panthor) will
do the same. There's no evidence that we will ever have a driver
that wants different pools of LRUs protected by different locks under
the same drm_device. So we're better off moving this lock to drm_device
and always locking it through obj->dev->gem_lru_mutex, or directly
through dev->gem_lru_mutex.
If anyone ever needs more fine-grained locking, this can be revisited
to pass some drm_gem_lru_pool object representing the pool of LRUs
under a specific lock, but for now, the per-device lock seems to be
enough.
Fixes: e7c2af13f811 ("drm/gem: Add LRU/shrinker helper")
Reported-by: Chia-I Wu
Closes: https://gitlab.freedesktop.org/panfrost/linux/-/work_items/86
Reviewed-by: Rob Clark
Reviewed-by: Liviu Dudau
Reviewed-by: Steven Price
Reviewed-by: Chia-I Wu
Signed-off-by: Boris Brezillon
---
As reported by Chia-I [1], a race exists between drm_gem_lru_remove()
and drm_gem_lru_scan(), causing a UAF on a stack-allocated object.
This new version only keeps the last patch of the series that
addresses the problem more generically by moving the LRU lock to the
drm_device object.
[1]https://gitlab.freedesktop.org/panfrost/linux/-/work_items/86
---
Changes in v4:
- Fix kernel docs
- Drop unused var in msm_gem_purge()
- Link to v3:
https://lore.kernel.org/r/[email protected]
Changes in v3:
- Only keep patch 4 and flag it for backport
- Rebase on drm-misc-fixes
- Link to v2:
https://lore.kernel.org/r/[email protected]
Changes in v2:
- Collect R-b
- Drop a useless obj->lru != NULL check in drm_gem_lru_scan()
- Fix another race introduced in patch 2
- Document why the lru != NULL check done without the lru lock held
in drm_gem_lru_remove() is safe
- Add a patch to sanitize the GEM LRU locking: lock is now part of
drm_device, meaning we don't have this chicken/egg problem where
the lock that needs to acquired is under gem->lru->lock, and
gem->lru is also supposed to be accessed with the lru->lock held
- Fix typos in commit messages and comments
- Link to v1:
https://lore.kernel.org/r/[email protected]
---
drivers/gpu/drm/drm_drv.c | 2 ++
drivers/gpu/drm/drm_gem.c | 36 +++---
drivers/gpu/drm/msm/msm_drv.c | 11 +--
drivers/gpu/drm/msm/msm_drv.h | 7 ---
drivers/gpu/drm/msm/msm_gem.c | 33 +++
drivers/gpu/drm/msm/msm_gem_shrinker.c | 4 ++--
drivers/gpu/drm/msm/msm_gem_submit.c | 6 +++---
drivers/gpu/drm/msm/msm_gem_vma.c | 12 ++--
drivers/gpu/drm/msm/msm_ringbuffer.c | 6 +++---
include/drm/drm_device.h | 7 +++
include/drm/drm_gem.h | 20 +--
11 files changed, 69 insertions(+), 75 deletions(-)
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 985c283cf59f..675675480da4 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -697,6 +697,7 @@ static void drm_dev_init_release(struct drm_device *dev,
void *res)
mutex_destroy(&dev->master_mutex);
mutex_destroy(&dev->clientlist_mutex);
mutex_destroy(&dev->filelist_mutex);
+ mutex_destroy(&dev->gem_lru_mutex);
}
static int drm_dev_init(struct drm_device *dev,
@@ -738,6 +739,7 @@ static int drm_dev_init(struct drm_device *dev,
INIT_LIST_HEAD(&dev->vblank_event_list);
spin_lock_init(&dev->event_lock);
+ mutex_init(&dev->gem_lru_mutex);
mutex_init(&dev->filelist_mutex);
mutex_init(&dev->clientlist_mutex);
mutex_init(&dev->master_mutex);
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index d6424267260b..b95b015d2983 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -1541,12 +1541,10 @@ EXPORT_SYMBOL(drm_gem_unlock_reservations);
* drm_gem_lru_init - initialize a LRU
*
* @lru: The LRU to initialize
- * @lock: The lock protecting the LRU
*/
void
-drm_gem_lru_init(struct drm_gem_lru *lru, struct mutex *lock)
+drm_gem_lru_init(struct drm_gem_lru *lru)
{
- lru->lock = lock;
lru->count = 0;
INIT_LIST_HEAD(&lru->list);
}
@@ -1571,14 +1569,10 @@ drm_gem_lru_remove_locked(struct drm_gem_object *obj)
void
drm_gem_lru_remove(struct drm_gem_object *obj)
{
- struct drm_gem_lru *lru = obj->lru;
-
- if (!lru)
-
