mbox series

[v20,00/10] Add generic DRM-shmem memory shrinker (part 1)

Message ID 20250322212608.40511-1-dmitry.osipenko@collabora.com (mailing list archive)
Headers show
Series Add generic DRM-shmem memory shrinker (part 1) | expand

Message

Dmitry Osipenko March 22, 2025, 9:25 p.m. UTC
Hi,

This a continuation of a year-old series that adds generic DRM-shmem 
shrinker [1]. The old series became too big with too many patches, more
reasonable to split it up into multiple smaller patchsets. Here is
the firtst part that makes preparatory DRM changes.

[1] https://lore.kernel.org/dri-devel/20240105184624.508603-1-dmitry.osipenko@collabora.com/

Changelog:

v20:- Rebased on recent drm-misc. Added r-bs that were given to v19.

Dmitry Osipenko (10):
  drm/gem: Change locked/unlocked postfix of drm_gem_v/unmap() function
    names
  drm/gem: Add _locked postfix to functions that have unlocked
    counterpart
  drm/gem: Document locking rule of vmap and evict callbacks
  drm/shmem-helper: Make all exported symbols GPL
  drm/shmem-helper: Refactor locked/unlocked functions
  drm/shmem-helper: Remove obsoleted is_iomem test
  drm/shmem-helper: Add and use pages_pin_count
  drm/shmem-helper: Use refcount_t for pages_use_count
  drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin
  drm/shmem-helper: Use refcount_t for vmap_use_count

 drivers/gpu/drm/drm_client.c                  |  10 +-
 drivers/gpu/drm/drm_gem.c                     |  26 ++--
 drivers/gpu/drm/drm_gem_framebuffer_helper.c  |   6 +-
 drivers/gpu/drm/drm_gem_shmem_helper.c        | 145 +++++++++---------
 drivers/gpu/drm/drm_internal.h                |   4 +-
 drivers/gpu/drm/drm_prime.c                   |   4 +-
 drivers/gpu/drm/imagination/pvr_gem.c         |   4 +-
 drivers/gpu/drm/lima/lima_gem.c               |   4 +-
 drivers/gpu/drm/lima/lima_sched.c             |   4 +-
 drivers/gpu/drm/panfrost/panfrost_drv.c       |   2 +-
 drivers/gpu/drm/panfrost/panfrost_dump.c      |   4 +-
 .../gpu/drm/panfrost/panfrost_gem_shrinker.c  |   2 +-
 drivers/gpu/drm/panfrost/panfrost_mmu.c       |   2 +-
 drivers/gpu/drm/panfrost/panfrost_perfcnt.c   |   6 +-
 drivers/gpu/drm/panthor/panthor_gem.h         |   4 +-
 drivers/gpu/drm/panthor/panthor_sched.c       |   4 +-
 drivers/gpu/drm/tests/drm_gem_shmem_test.c    |  28 ++--
 include/drm/drm_gem.h                         |  15 +-
 include/drm/drm_gem_shmem_helper.h            |  45 ++++--
 19 files changed, 167 insertions(+), 152 deletions(-)

Comments

Thomas Zimmermann March 25, 2025, 2:17 p.m. UTC | #1
I've looked through this before, so

Acked-by: Thomas Zimmermann <tzimmermann@suse.d>

for the series.

Am 22.03.25 um 22:25 schrieb Dmitry Osipenko:
> Hi,
>
> This a continuation of a year-old series that adds generic DRM-shmem
> shrinker [1]. The old series became too big with too many patches, more
> reasonable to split it up into multiple smaller patchsets. Here is
> the firtst part that makes preparatory DRM changes.
>
> [1] https://lore.kernel.org/dri-devel/20240105184624.508603-1-dmitry.osipenko@collabora.com/
>
> Changelog:
>
> v20:- Rebased on recent drm-misc. Added r-bs that were given to v19.
>
> Dmitry Osipenko (10):
>    drm/gem: Change locked/unlocked postfix of drm_gem_v/unmap() function
>      names
>    drm/gem: Add _locked postfix to functions that have unlocked
>      counterpart
>    drm/gem: Document locking rule of vmap and evict callbacks
>    drm/shmem-helper: Make all exported symbols GPL
>    drm/shmem-helper: Refactor locked/unlocked functions
>    drm/shmem-helper: Remove obsoleted is_iomem test
>    drm/shmem-helper: Add and use pages_pin_count
>    drm/shmem-helper: Use refcount_t for pages_use_count
>    drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin
>    drm/shmem-helper: Use refcount_t for vmap_use_count
>
>   drivers/gpu/drm/drm_client.c                  |  10 +-
>   drivers/gpu/drm/drm_gem.c                     |  26 ++--
>   drivers/gpu/drm/drm_gem_framebuffer_helper.c  |   6 +-
>   drivers/gpu/drm/drm_gem_shmem_helper.c        | 145 +++++++++---------
>   drivers/gpu/drm/drm_internal.h                |   4 +-
>   drivers/gpu/drm/drm_prime.c                   |   4 +-
>   drivers/gpu/drm/imagination/pvr_gem.c         |   4 +-
>   drivers/gpu/drm/lima/lima_gem.c               |   4 +-
>   drivers/gpu/drm/lima/lima_sched.c             |   4 +-
>   drivers/gpu/drm/panfrost/panfrost_drv.c       |   2 +-
>   drivers/gpu/drm/panfrost/panfrost_dump.c      |   4 +-
>   .../gpu/drm/panfrost/panfrost_gem_shrinker.c  |   2 +-
>   drivers/gpu/drm/panfrost/panfrost_mmu.c       |   2 +-
>   drivers/gpu/drm/panfrost/panfrost_perfcnt.c   |   6 +-
>   drivers/gpu/drm/panthor/panthor_gem.h         |   4 +-
>   drivers/gpu/drm/panthor/panthor_sched.c       |   4 +-
>   drivers/gpu/drm/tests/drm_gem_shmem_test.c    |  28 ++--
>   include/drm/drm_gem.h                         |  15 +-
>   include/drm/drm_gem_shmem_helper.h            |  45 ++++--
>   19 files changed, 167 insertions(+), 152 deletions(-)
>
Dmitry Osipenko March 26, 2025, 8:08 p.m. UTC | #2
On 3/25/25 17:17, Thomas Zimmermann wrote:
> I've looked through this before, so
> 
> Acked-by: Thomas Zimmermann <tzimmermann@suse.d>
> 
> for the series.

Applied to misc-next, thanks!
Boris Brezillon March 27, 2025, 10:45 a.m. UTC | #3
On Wed, 26 Mar 2025 23:08:55 +0300
Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote:

> On 3/25/25 17:17, Thomas Zimmermann wrote:
> > I've looked through this before, so
> > 
> > Acked-by: Thomas Zimmermann <tzimmermann@suse.d>
> > 
> > for the series.  
> 
> Applied to misc-next, thanks!

Looks like the accel drivers were left behind. I just sent a patch
series to address that [1].

[1]https://lore.kernel.org/r/dri-devel/20250327104300.1982058-1-boris.brezillon@collabora.com/
Dmitry Osipenko March 27, 2025, 10:47 a.m. UTC | #4
On 3/27/25 13:45, Boris Brezillon wrote:
> On Wed, 26 Mar 2025 23:08:55 +0300
> Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote:
> 
>> On 3/25/25 17:17, Thomas Zimmermann wrote:
>>> I've looked through this before, so
>>>
>>> Acked-by: Thomas Zimmermann <tzimmermann@suse.d>
>>>
>>> for the series.  
>>
>> Applied to misc-next, thanks!
> 
> Looks like the accel drivers were left behind. I just sent a patch
> series to address that [1].
> 
> [1]https://lore.kernel.org/r/dri-devel/20250327104300.1982058-1-boris.brezillon@collabora.com/

Accel drivers weren't on my radar, thanks a lot!
Lucas De Marchi April 3, 2025, 12:37 a.m. UTC | #5
On Sun, Mar 23, 2025 at 12:25:58AM +0300, Dmitry Osipenko wrote:
>Hi,
>
>This a continuation of a year-old series that adds generic DRM-shmem
>shrinker [1]. The old series became too big with too many patches, more
>reasonable to split it up into multiple smaller patchsets. Here is
>the firtst part that makes preparatory DRM changes.
>
>[1] https://lore.kernel.org/dri-devel/20240105184624.508603-1-dmitry.osipenko@collabora.com/

After these patches got merged I started seeing this on ast driver
and a similar one qemu-cirrus:

[   88.731560] fbcon: astdrmfb (fb0) is primary device
[   88.767100] Console: switching to colour frame buffer device 128x48
[   88.768982] ------------[ cut here ]------------
[   88.768989] ast 0000:02:00.0: [drm] Dirty helper failed: ret=-12
[   88.769016] WARNING: CPU: 0 PID: 10 at drivers/gpu/drm/drm_fbdev_shmem.c:118 drm_fbdev_shmem_helper_fb_dirty+0xcc/0xd0 [drm_shmem_helper]
...
[   88.769092] CPU: 0 UID: 0 PID: 10 Comm: kworker/0:1 Not tainted 6.14.0-xe+ #2
...
[   88.769095] Workqueue: events drm_fb_helper_damage_work [drm_kms_helper]
[   88.769109] RIP: 0010:drm_fbdev_shmem_helper_fb_dirty+0xcc/0xd0 [drm_shmem_helper]
[   88.769112] Code: 4d 8b 6c 24 50 4d 85 ed 75 04 4d 8b 2c 24 4c 89 e7 e8 98 36 a9 e0 89 d9 4c 89 ea 48 c7 c7 d8 65 54 a1 48 89 c6 e8 64 f4 ee df <0f> 0b eb 8b 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 0f 1f
[   88.769113] RSP: 0018:ffa00000003e7da0 EFLAGS: 00010246
[   88.769115] RAX: 0000000000000000 RBX: 00000000fffffff4 RCX: 0000000000000000
[   88.769117] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
[   88.769117] RBP: ffa00000003e7db8 R08: 0000000000000000 R09: 0000000000000000
[   88.769118] R10: 0000000000000000 R11: 0000000000000000 R12: ff11000122c190c8
[   88.769119] R13: ff11000118588a10 R14: ff1100010f4a04c0 R15: ff1100019750b588
[   88.769120] FS:  0000000000000000(0000) GS:ff11007e7d000000(0000) knlGS:0000000000000000
[   88.769121] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   88.769122] CR2: 00007e43af4056f0 CR3: 00000080c89f0003 CR4: 0000000000f73ef0
[   88.769123] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[   88.769124] DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000400
[   88.769125] PKRU: 55555554
[   88.769126] Call Trace:
[   88.769127]  <TASK>
[   88.769129]  ? show_regs.cold+0x19/0x20
[   88.769132]  ? drm_fbdev_shmem_helper_fb_dirty+0xcc/0xd0 [drm_shmem_helper]
[   88.769134]  ? __warn.cold+0xd2/0x17f
[   88.769136]  ? drm_fbdev_shmem_helper_fb_dirty+0xcc/0xd0 [drm_shmem_helper]
[   88.769139]  ? report_bug+0x114/0x160
[   88.769143]  ? handle_bug+0x6e/0xb0
[   88.769146]  ? exc_invalid_op+0x18/0x80
[   88.769147]  ? asm_exc_invalid_op+0x1b/0x20
[   88.769153]  ? drm_fbdev_shmem_helper_fb_dirty+0xcc/0xd0 [drm_shmem_helper]
[   88.769156]  drm_fb_helper_damage_work+0x8a/0x190 [drm_kms_helper]
[   88.769164]  process_one_work+0x224/0x5f0
[   88.769170]  worker_thread+0x1d4/0x3e0
[   88.769173]  ? __pfx_worker_thread+0x10/0x10
[   88.769175]  kthread+0x10b/0x260
[   88.769178]  ? __pfx_kthread+0x10/0x10
[   88.769181]  ret_from_fork+0x44/0x70
[   88.769184]  ? __pfx_kthread+0x10/0x10
[   88.769186]  ret_from_fork_asm+0x1a/0x30
[   88.769193]  </TASK>
[   88.769194] irq event stamp: 430275
[   88.769195] hardirqs last  enabled at (430281): [<ffffffff81505836>] vprintk_emit+0x416/0x470
[   88.769198] hardirqs last disabled at (430286): [<ffffffff81505868>] vprintk_emit+0x448/0x470
[   88.769200] softirqs last  enabled at (428924): [<ffffffff8143977d>] __irq_exit_rcu+0x12d/0x150
[   88.769203] softirqs last disabled at (428861): [<ffffffff8143977d>] __irq_exit_rcu+0x12d/0x150
[   88.769205] ---[ end trace 0000000000000000 ]---
[   88.769375] ast 0000:02:00.0: [drm] fb0: astdrmfb frame buffer device
[   88.802554] ast 0000:02:00.0: [drm:drm_fb_helper_hotplug_event [drm_kms_helper]] 

I confirmed that reverting the series (together with 2 patches for accel/ivpu on top)
makes the warning go away. Any idea what's going on?


Lucas De Marchi
Thomas Zimmermann April 3, 2025, 7:03 a.m. UTC | #6
Hi

Am 03.04.25 um 02:37 schrieb Lucas De Marchi:
> On Sun, Mar 23, 2025 at 12:25:58AM +0300, Dmitry Osipenko wrote:
>> Hi,
>>
>> This a continuation of a year-old series that adds generic DRM-shmem
>> shrinker [1]. The old series became too big with too many patches, more
>> reasonable to split it up into multiple smaller patchsets. Here is
>> the firtst part that makes preparatory DRM changes.
>>
>> [1] 
>> https://lore.kernel.org/dri-devel/20240105184624.508603-1-dmitry.osipenko@collabora.com/
>
> After these patches got merged I started seeing this on ast driver
> and a similar one qemu-cirrus:

Same here with simpledrm. I wanted to bisect today.

Best regards
Thomas

>
> [   88.731560] fbcon: astdrmfb (fb0) is primary device
> [   88.767100] Console: switching to colour frame buffer device 128x48
> [   88.768982] ------------[ cut here ]------------
> [   88.768989] ast 0000:02:00.0: [drm] Dirty helper failed: ret=-12
> [   88.769016] WARNING: CPU: 0 PID: 10 at 
> drivers/gpu/drm/drm_fbdev_shmem.c:118 
> drm_fbdev_shmem_helper_fb_dirty+0xcc/0xd0 [drm_shmem_helper]
> ...
> [   88.769092] CPU: 0 UID: 0 PID: 10 Comm: kworker/0:1 Not tainted 
> 6.14.0-xe+ #2
> ...
> [   88.769095] Workqueue: events drm_fb_helper_damage_work 
> [drm_kms_helper]
> [   88.769109] RIP: 0010:drm_fbdev_shmem_helper_fb_dirty+0xcc/0xd0 
> [drm_shmem_helper]
> [   88.769112] Code: 4d 8b 6c 24 50 4d 85 ed 75 04 4d 8b 2c 24 4c 89 
> e7 e8 98 36 a9 e0 89 d9 4c 89 ea 48 c7 c7 d8 65 54 a1 48 89 c6 e8 64 
> f4 ee df <0f> 0b eb 8b 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 
> 0f 1f
> [   88.769113] RSP: 0018:ffa00000003e7da0 EFLAGS: 00010246
> [   88.769115] RAX: 0000000000000000 RBX: 00000000fffffff4 RCX: 
> 0000000000000000
> [   88.769117] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 
> 0000000000000000
> [   88.769117] RBP: ffa00000003e7db8 R08: 0000000000000000 R09: 
> 0000000000000000
> [   88.769118] R10: 0000000000000000 R11: 0000000000000000 R12: 
> ff11000122c190c8
> [   88.769119] R13: ff11000118588a10 R14: ff1100010f4a04c0 R15: 
> ff1100019750b588
> [   88.769120] FS:  0000000000000000(0000) GS:ff11007e7d000000(0000) 
> knlGS:0000000000000000
> [   88.769121] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [   88.769122] CR2: 00007e43af4056f0 CR3: 00000080c89f0003 CR4: 
> 0000000000f73ef0
> [   88.769123] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 
> 0000000000000000
> [   88.769124] DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 
> 0000000000000400
> [   88.769125] PKRU: 55555554
> [   88.769126] Call Trace:
> [   88.769127]  <TASK>
> [   88.769129]  ? show_regs.cold+0x19/0x20
> [   88.769132]  ? drm_fbdev_shmem_helper_fb_dirty+0xcc/0xd0 
> [drm_shmem_helper]
> [   88.769134]  ? __warn.cold+0xd2/0x17f
> [   88.769136]  ? drm_fbdev_shmem_helper_fb_dirty+0xcc/0xd0 
> [drm_shmem_helper]
> [   88.769139]  ? report_bug+0x114/0x160
> [   88.769143]  ? handle_bug+0x6e/0xb0
> [   88.769146]  ? exc_invalid_op+0x18/0x80
> [   88.769147]  ? asm_exc_invalid_op+0x1b/0x20
> [   88.769153]  ? drm_fbdev_shmem_helper_fb_dirty+0xcc/0xd0 
> [drm_shmem_helper]
> [   88.769156]  drm_fb_helper_damage_work+0x8a/0x190 [drm_kms_helper]
> [   88.769164]  process_one_work+0x224/0x5f0
> [   88.769170]  worker_thread+0x1d4/0x3e0
> [   88.769173]  ? __pfx_worker_thread+0x10/0x10
> [   88.769175]  kthread+0x10b/0x260
> [   88.769178]  ? __pfx_kthread+0x10/0x10
> [   88.769181]  ret_from_fork+0x44/0x70
> [   88.769184]  ? __pfx_kthread+0x10/0x10
> [   88.769186]  ret_from_fork_asm+0x1a/0x30
> [   88.769193]  </TASK>
> [   88.769194] irq event stamp: 430275
> [   88.769195] hardirqs last  enabled at (430281): 
> [<ffffffff81505836>] vprintk_emit+0x416/0x470
> [   88.769198] hardirqs last disabled at (430286): 
> [<ffffffff81505868>] vprintk_emit+0x448/0x470
> [   88.769200] softirqs last  enabled at (428924): 
> [<ffffffff8143977d>] __irq_exit_rcu+0x12d/0x150
> [   88.769203] softirqs last disabled at (428861): 
> [<ffffffff8143977d>] __irq_exit_rcu+0x12d/0x150
> [   88.769205] ---[ end trace 0000000000000000 ]---
> [   88.769375] ast 0000:02:00.0: [drm] fb0: astdrmfb frame buffer device
> [   88.802554] ast 0000:02:00.0: [drm:drm_fb_helper_hotplug_event 
> [drm_kms_helper]]
> I confirmed that reverting the series (together with 2 patches for 
> accel/ivpu on top)
> makes the warning go away. Any idea what's going on?
>
>
> Lucas De Marchi
Dmitry Osipenko April 3, 2025, 2:10 p.m. UTC | #7
On 4/3/25 10:03, Thomas Zimmermann wrote:
> Hi
> 
> Am 03.04.25 um 02:37 schrieb Lucas De Marchi:
>> On Sun, Mar 23, 2025 at 12:25:58AM +0300, Dmitry Osipenko wrote:
>>> Hi,
>>>
>>> This a continuation of a year-old series that adds generic DRM-shmem
>>> shrinker [1]. The old series became too big with too many patches, more
>>> reasonable to split it up into multiple smaller patchsets. Here is
>>> the firtst part that makes preparatory DRM changes.
>>>
>>> [1] https://lore.kernel.org/dri-devel/20240105184624.508603-1-
>>> dmitry.osipenko@collabora.com/
>>
>> After these patches got merged I started seeing this on ast driver
>> and a similar one qemu-cirrus:
> 
> Same here with simpledrm. I wanted to bisect today.

I've reproduced using bochs drv, it's the last patch "drm/shmem-helper:
Use refcount_t for vmap_use_count" causing the issue. Thanks for the report!

This change fixes it, let me send a proper patch:

diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c
b/drivers/gpu/drm/drm_gem_shmem_helper.c
index 2d924d547a51..554f1d4c1a76 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -416,10 +416,10 @@ void drm_gem_shmem_vunmap_locked(struct
drm_gem_shmem_object *shmem,
                if (refcount_dec_and_test(&shmem->vmap_use_count)) {
                        vunmap(shmem->vaddr);
                        drm_gem_shmem_unpin_locked(shmem);
+
+                       shmem->vaddr = NULL;
                }
        }
-
-       shmem->vaddr = NULL;
 }
 EXPORT_SYMBOL_GPL(drm_gem_shmem_vunmap_locked);