From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23562C71153 for ; Mon, 28 Aug 2023 14:37:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4D8FD10E04E; Mon, 28 Aug 2023 14:37:18 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7C0C210E04E; Mon, 28 Aug 2023 14:37:16 +0000 (UTC) Received: from hamburger.collabora.co.uk (hamburger.collabora.co.uk [IPv6:2a01:4f8:1c1c:f269::1]) by madras.collabora.co.uk (Postfix) with ESMTP id 2B6C966003AC; Mon, 28 Aug 2023 15:37:13 +0100 (BST) From: "Helen Mae Koike Fornazier" In-Reply-To: <20230827175449.1766701-1-dmitry.osipenko@collabora.com> Content-Type: text/plain; charset="utf-8" X-Forward: 127.0.0.1 Date: Mon, 28 Aug 2023 15:37:12 +0100 To: "Dmitry Osipenko" MIME-Version: 1.0 Message-ID: <55db-64ecb100-57-403f1500@96946290> User-Agent: SOGoMail 5.8.4 Content-Transfer-Encoding: quoted-printable Subject: Re: [Intel-gfx] =?utf-8?q?=5BPATCH_v15_00/23=5D_Add_generic_memory_s?= =?utf-8?q?hrinker_to_VirtIO-GPU_and_Panfrost_DRM_drivers?= X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Emma Anholt , Peter Zijlstra , dri-devel@lists.freedesktop.org, Gurchetan Singh , Gerd Hoffmann , kernel@collabora.com, Will Deacon , David Airlie , Steven Price , intel-gfx@lists.freedesktop.org, Daniel Vetter , Boqun Feng , Maxime Ripard , Melissa Wen , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Chia-I Wu , Qiang Yu , Thomas Zimmermann , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Sunday, August 27, 2023 14:54 -03, Dmitry Osipenko wrote: > This series: >=20 > 1. Adds common drm-shmem memory shrinker > 2. Enables shrinker for VirtIO-GPU driver > 3. Switches Panfrost driver to the common shrinker Hi Dmitry,=20 Would you mind testing with drm-ci? We virt-io tests there and it would= be really great to get your feedback of it. https://cgit.freedesktop.org/drm/drm/log/?h=3Dtopic/drm-ci You need to merge your changes with the above tree. To configure it, you just need to have a tree on gitlab.freedesktop.org= , go to the settings and change the CI/CD configuration file from .gitlab= -ci.yml to drivers/gpu/drm/ci/gitlab-ci.yml, and you can start a pipeline on your branch. at the time of this writting, gitlab.freedesktop.org is under maintenan= ce, but it should be back soon. Thank you! Helen >=20 > Changelog: >=20 > v15:- Moved drm-shmem reference counters to use kref that allows to > optimize unlocked functions, like was suggested by Boris Brezil= lon. >=20 > - Changed drm/gem/shmem function names to use =5Flocked postfix a= nd > dropped the =5Funlocked, making the naming scheme consistent ac= ross > DRM code, like was suggested by Boris Brezillon. >=20 > - Added patch that fixes UAF in drm-shmem for drivers that import > dma-buf and then release buffer in the import error code path. >=20 > - Added patch that makes drm-shmem use new flag for SGT's get=5Fp= ages() > refcounting, preventing unbalanced refcounting when GEM is free= d. >=20 > - Fixed guest blob pinning in virtio-gpu driver that was missed > previously in the shrinker patch. >=20 > - Moved VC4 and virtio-gpu drivers to use drm=5Fgem=5Fput() in > GEM-creation error code paths, which is now required by drm-shm= em > and was missed in a previous patch versions. >=20 > - Virtio-GPU now attaches shmem pages to host on first use and no= t > when BO is created. In older patch versions there was a potenti= al > race condition in the BO creation code path where both > get=5Fsgt()+object=5Fattach() should've been made under same re= sv lock, > otherwise pages could be evicted before attachment is invoked. >=20 > - Virtio-GPU and drm-shmem shrinker patches are split into smalle= r > ones. >=20 > v14:- All the prerequisite reservation locking patches landed upstrea= m, > previously were a part of this series in v13 and older. >=20 > https://lore.kernel.org/dri-devel/20230529223935.2672495-1-dm= itry.osipenko@collabora.com/ >=20 > - Added patches to improve locked/unlocked function names, like w= as > suggested by Boris Brezillon for v13. >=20 > - Made all exported drm-shmem symbols GPL, like was previously > discussed with Thomas Zimmermann on this series. >=20 > - Improved virtio-gpu shrinker patch. Now it won't detach purged = BO > when userspace closes GEM. Crosvm (and not qemu) checks res=5Fi= d on > CMD=5FCTX=5FDETACH=5FRESOURCE and prints noisy error message if= ID is > invalid, which wasn't noticed before. >=20 > v13:- Updated virtio-gpu shrinker patch to use drm=5Fgem=5Fshmem=5Fob= ject=5Fpin() > directly instead of drm=5Fgem=5Fpin() and dropped patch that ex= ported > drm=5Fgem=5Fpin() functions, like was requested by Thomas Zimme= rmann in > v12. >=20 > v12:- Fixed the "no previous prototype for function" warning reported= by > kernel build bot for v11. >=20 > - Fixed the missing reservation lock reported by Intel CI for VGE= M > driver. Other drivers using drm-shmem were affected similarly t= o > VGEM. The problem was in the dma-buf attachment code path that = led > to drm-shmem pinning function which assumed the held reservatio= n lock > by drm=5Fgem=5Fpin(). In the past that code path was causing tr= ouble for > i915 driver and we've changed the locking scheme for the attach= ment > code path in the dma-buf core to let exporters to handle the lo= cking > themselves. After a closer investigation, I realized that my as= sumption > about testing of dma-buf export code path using Panfrost driver= was > incorrect. Now I created additional local test to exrecise the = Panfrost > export path. I also reproduced the issue reported by the Intel = CI for > v10. It's all fixed now by making the drm=5Fgem=5Fshmem=5Fpin()= to take the > resv lock by itself. >=20 > - Patches are based on top of drm-tip, CC'd intel-gfx CI for test= ing. >=20 > v11:- Rebased on a recent linux-next. Added new patch as a result: >=20 > drm/shmem-helper: Export drm=5Fgem=5Fshmem=5Fget=5Fpages=5Fsg= t=5Flocked() >=20 > It's needed by the virtio-gpu driver to swap-in/unevict shmem > object, previously get=5Fpages=5Fsgt() didn't use locking. >=20 > - Separated the "Add memory shrinker" patch into smaller parts to= ease > the reviewing, as was requested by Thomas Zimmermann: >=20 > drm/shmem-helper: Factor out pages alloc/release from > drm=5Fgem=5Fshmem=5Fget/put=5Fpages() > drm/shmem-helper: Add pages=5Fpin=5Fcount field > drm/shmem-helper: Switch drm=5Fgem=5Fshmem=5Fvmap/vunmap to u= se pin/unpin > drm/shmem-helper: Factor out unpinning part from drm=5Fgem=5F= shmem=5Fpurge() >=20 > - Addessed the v10 review comments from Thomas Zimmermann: return= errno > instead of bool, sort code alphabetically, rename function and = etc > minor changes. >=20 > - Added new patch to remove the "map->is=5Fiomem" from drm-shmem,= as > was suggested by Thomas Zimmermann. >=20 > - Added acks and r-b's that were given to v10. >=20 > v10:- Was partially applied to misc-fixes/next. >=20 > https://lore.kernel.org/dri-devel/6c16f303-81df-7ebe-85e9-51bb4= 0a8b301@collabora.com/T/ >=20 > Dmitry Osipenko (23): > drm/shmem-helper: Fix UAF in error path when freeing SGT of importe= d > GEM > drm/shmem-helper: Use flag for tracking page count bumped by > get=5Fpages=5Fsgt() > drm/gem: Change locked/unlocked postfix of drm=5Fgem=5Fv/unmap() fu= nction > names > drm/gem: Add =5Flocked postfix to functions that have unlocked > counterpart > drm/v3d: Replace open-coded drm=5Fgem=5Fshmem=5Ffree() with > drm=5Fgem=5Fobject=5Fput() > drm/virtio: Replace drm=5Fgem=5Fshmem=5Ffree() with drm=5Fgem=5Fobj= ect=5Fput() > drm/shmem-helper: Make all exported symbols GPL > drm/shmem-helper: Refactor locked/unlocked functions > drm/shmem-helper: Remove obsoleted is=5Fiomem test > locking/refcount, kref: Add kref=5Fput=5Fww=5Fmutex() > dma-resv: Add kref=5Fput=5Fdma=5Fresv() > drm/shmem-helper: Add and use pages=5Fpin=5Fcount > drm/shmem-helper: Use kref for pages=5Fuse=5Fcount > drm/shmem-helper: Add and use lockless drm=5Fgem=5Fshmem=5Fget=5Fpa= ges() > drm/shmem-helper: Switch drm=5Fgem=5Fshmem=5Fvmap/vunmap to use pin= /unpin > drm/shmem-helper: Use kref for vmap=5Fuse=5Fcount > drm/shmem-helper: Add and use drm=5Fgem=5Fshmem=5Fresv=5Fassert=5Fh= eld() helper > drm/shmem-helper: Add memory shrinker > drm/shmem-helper: Export drm=5Fgem=5Fshmem=5Fget=5Fpages=5Fsgt=5Flo= cked() > drm/virtio: Pin display framebuffer BO > drm/virtio: Attach shmem BOs dynamically > drm/virtio: Support memory shrinking > drm/panfrost: Switch to generic memory shrinker >=20 > drivers/gpu/drm/drm=5Fclient.c | 6 +- > drivers/gpu/drm/drm=5Fgem.c | 26 +- > drivers/gpu/drm/drm=5Fgem=5Fframebuffer=5Fhelper.c | 6 +- > drivers/gpu/drm/drm=5Fgem=5Fshmem=5Fhelper.c | 616 ++++++++++= +++++--- > drivers/gpu/drm/drm=5Finternal.h | 4 +- > drivers/gpu/drm/drm=5Fprime.c | 4 +- > drivers/gpu/drm/lima/lima=5Fgem.c | 11 +- > drivers/gpu/drm/lima/lima=5Fsched.c | 4 +- > drivers/gpu/drm/panfrost/Makefile | 1 - > drivers/gpu/drm/panfrost/panfrost=5Fdevice.h | 4 - > drivers/gpu/drm/panfrost/panfrost=5Fdrv.c | 29 +- > drivers/gpu/drm/panfrost/panfrost=5Fdump.c | 4 +- > drivers/gpu/drm/panfrost/panfrost=5Fgem.c | 36 +- > drivers/gpu/drm/panfrost/panfrost=5Fgem.h | 9 - > .../gpu/drm/panfrost/panfrost=5Fgem=5Fshrinker.c | 122 ---- > drivers/gpu/drm/panfrost/panfrost=5Fjob.c | 18 +- > drivers/gpu/drm/panfrost/panfrost=5Fmmu.c | 4 +- > drivers/gpu/drm/panfrost/panfrost=5Fperfcnt.c | 6 +- > drivers/gpu/drm/v3d/v3d=5Fbo.c | 26 +- > drivers/gpu/drm/virtio/virtgpu=5Fdrv.h | 22 +- > drivers/gpu/drm/virtio/virtgpu=5Fgem.c | 80 +++ > drivers/gpu/drm/virtio/virtgpu=5Fioctl.c | 57 +- > drivers/gpu/drm/virtio/virtgpu=5Fkms.c | 8 + > drivers/gpu/drm/virtio/virtgpu=5Fobject.c | 147 ++++- > drivers/gpu/drm/virtio/virtgpu=5Fplane.c | 17 +- > drivers/gpu/drm/virtio/virtgpu=5Fsubmit.c | 15 +- > drivers/gpu/drm/virtio/virtgpu=5Fvq.c | 40 ++ > include/drm/drm=5Fdevice.h | 10 +- > include/drm/drm=5Fgem.h | 6 +- > include/drm/drm=5Fgem=5Fshmem=5Fhelper.h | 141 +++- > include/linux/dma-resv.h | 9 + > include/linux/kref.h | 12 + > include/linux/refcount.h | 5 + > include/uapi/drm/virtgpu=5Fdrm.h | 14 + > lib/refcount.c | 34 + > 35 files changed, 1167 insertions(+), 386 deletions(-) > delete mode 100644 drivers/gpu/drm/panfrost/panfrost=5Fgem=5Fshrinke= r.c >=20 > --=20 > 2.41.0 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F06FC71153 for ; Mon, 28 Aug 2023 14:37:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4ED0710E2F0; Mon, 28 Aug 2023 14:37:19 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7C0C210E04E; Mon, 28 Aug 2023 14:37:16 +0000 (UTC) Received: from hamburger.collabora.co.uk (hamburger.collabora.co.uk [IPv6:2a01:4f8:1c1c:f269::1]) by madras.collabora.co.uk (Postfix) with ESMTP id 2B6C966003AC; Mon, 28 Aug 2023 15:37:13 +0100 (BST) From: "Helen Mae Koike Fornazier" In-Reply-To: <20230827175449.1766701-1-dmitry.osipenko@collabora.com> Content-Type: text/plain; charset="utf-8" X-Forward: 127.0.0.1 Date: Mon, 28 Aug 2023 15:37:12 +0100 To: "Dmitry Osipenko" MIME-Version: 1.0 Message-ID: <55db-64ecb100-57-403f1500@96946290> Subject: =?utf-8?q?Re=3A?= [PATCH v15 00/23] Add generic memory shrinker to VirtIO-GPU and Panfrost DRM drivers User-Agent: SOGoMail 5.8.4 Content-Transfer-Encoding: quoted-printable X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Emma Anholt , Peter Zijlstra , dri-devel@lists.freedesktop.org, Gurchetan Singh , Gerd Hoffmann , kernel@collabora.com, Will Deacon , Steven Price , intel-gfx@lists.freedesktop.org, Boqun Feng , Maxime Ripard , Melissa Wen , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Boris Brezillon , Qiang Yu , Thomas Zimmermann , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Sunday, August 27, 2023 14:54 -03, Dmitry Osipenko wrote: > This series: >=20 > 1. Adds common drm-shmem memory shrinker > 2. Enables shrinker for VirtIO-GPU driver > 3. Switches Panfrost driver to the common shrinker Hi Dmitry,=20 Would you mind testing with drm-ci? We virt-io tests there and it would= be really great to get your feedback of it. https://cgit.freedesktop.org/drm/drm/log/?h=3Dtopic/drm-ci You need to merge your changes with the above tree. To configure it, you just need to have a tree on gitlab.freedesktop.org= , go to the settings and change the CI/CD configuration file from .gitlab= -ci.yml to drivers/gpu/drm/ci/gitlab-ci.yml, and you can start a pipeline on your branch. at the time of this writting, gitlab.freedesktop.org is under maintenan= ce, but it should be back soon. Thank you! Helen >=20 > Changelog: >=20 > v15:- Moved drm-shmem reference counters to use kref that allows to > optimize unlocked functions, like was suggested by Boris Brezil= lon. >=20 > - Changed drm/gem/shmem function names to use =5Flocked postfix a= nd > dropped the =5Funlocked, making the naming scheme consistent ac= ross > DRM code, like was suggested by Boris Brezillon. >=20 > - Added patch that fixes UAF in drm-shmem for drivers that import > dma-buf and then release buffer in the import error code path. >=20 > - Added patch that makes drm-shmem use new flag for SGT's get=5Fp= ages() > refcounting, preventing unbalanced refcounting when GEM is free= d. >=20 > - Fixed guest blob pinning in virtio-gpu driver that was missed > previously in the shrinker patch. >=20 > - Moved VC4 and virtio-gpu drivers to use drm=5Fgem=5Fput() in > GEM-creation error code paths, which is now required by drm-shm= em > and was missed in a previous patch versions. >=20 > - Virtio-GPU now attaches shmem pages to host on first use and no= t > when BO is created. In older patch versions there was a potenti= al > race condition in the BO creation code path where both > get=5Fsgt()+object=5Fattach() should've been made under same re= sv lock, > otherwise pages could be evicted before attachment is invoked. >=20 > - Virtio-GPU and drm-shmem shrinker patches are split into smalle= r > ones. >=20 > v14:- All the prerequisite reservation locking patches landed upstrea= m, > previously were a part of this series in v13 and older. >=20 > https://lore.kernel.org/dri-devel/20230529223935.2672495-1-dm= itry.osipenko@collabora.com/ >=20 > - Added patches to improve locked/unlocked function names, like w= as > suggested by Boris Brezillon for v13. >=20 > - Made all exported drm-shmem symbols GPL, like was previously > discussed with Thomas Zimmermann on this series. >=20 > - Improved virtio-gpu shrinker patch. Now it won't detach purged = BO > when userspace closes GEM. Crosvm (and not qemu) checks res=5Fi= d on > CMD=5FCTX=5FDETACH=5FRESOURCE and prints noisy error message if= ID is > invalid, which wasn't noticed before. >=20 > v13:- Updated virtio-gpu shrinker patch to use drm=5Fgem=5Fshmem=5Fob= ject=5Fpin() > directly instead of drm=5Fgem=5Fpin() and dropped patch that ex= ported > drm=5Fgem=5Fpin() functions, like was requested by Thomas Zimme= rmann in > v12. >=20 > v12:- Fixed the "no previous prototype for function" warning reported= by > kernel build bot for v11. >=20 > - Fixed the missing reservation lock reported by Intel CI for VGE= M > driver. Other drivers using drm-shmem were affected similarly t= o > VGEM. The problem was in the dma-buf attachment code path that = led > to drm-shmem pinning function which assumed the held reservatio= n lock > by drm=5Fgem=5Fpin(). In the past that code path was causing tr= ouble for > i915 driver and we've changed the locking scheme for the attach= ment > code path in the dma-buf core to let exporters to handle the lo= cking > themselves. After a closer investigation, I realized that my as= sumption > about testing of dma-buf export code path using Panfrost driver= was > incorrect. Now I created additional local test to exrecise the = Panfrost > export path. I also reproduced the issue reported by the Intel = CI for > v10. It's all fixed now by making the drm=5Fgem=5Fshmem=5Fpin()= to take the > resv lock by itself. >=20 > - Patches are based on top of drm-tip, CC'd intel-gfx CI for test= ing. >=20 > v11:- Rebased on a recent linux-next. Added new patch as a result: >=20 > drm/shmem-helper: Export drm=5Fgem=5Fshmem=5Fget=5Fpages=5Fsg= t=5Flocked() >=20 > It's needed by the virtio-gpu driver to swap-in/unevict shmem > object, previously get=5Fpages=5Fsgt() didn't use locking. >=20 > - Separated the "Add memory shrinker" patch into smaller parts to= ease > the reviewing, as was requested by Thomas Zimmermann: >=20 > drm/shmem-helper: Factor out pages alloc/release from > drm=5Fgem=5Fshmem=5Fget/put=5Fpages() > drm/shmem-helper: Add pages=5Fpin=5Fcount field > drm/shmem-helper: Switch drm=5Fgem=5Fshmem=5Fvmap/vunmap to u= se pin/unpin > drm/shmem-helper: Factor out unpinning part from drm=5Fgem=5F= shmem=5Fpurge() >=20 > - Addessed the v10 review comments from Thomas Zimmermann: return= errno > instead of bool, sort code alphabetically, rename function and = etc > minor changes. >=20 > - Added new patch to remove the "map->is=5Fiomem" from drm-shmem,= as > was suggested by Thomas Zimmermann. >=20 > - Added acks and r-b's that were given to v10. >=20 > v10:- Was partially applied to misc-fixes/next. >=20 > https://lore.kernel.org/dri-devel/6c16f303-81df-7ebe-85e9-51bb4= 0a8b301@collabora.com/T/ >=20 > Dmitry Osipenko (23): > drm/shmem-helper: Fix UAF in error path when freeing SGT of importe= d > GEM > drm/shmem-helper: Use flag for tracking page count bumped by > get=5Fpages=5Fsgt() > drm/gem: Change locked/unlocked postfix of drm=5Fgem=5Fv/unmap() fu= nction > names > drm/gem: Add =5Flocked postfix to functions that have unlocked > counterpart > drm/v3d: Replace open-coded drm=5Fgem=5Fshmem=5Ffree() with > drm=5Fgem=5Fobject=5Fput() > drm/virtio: Replace drm=5Fgem=5Fshmem=5Ffree() with drm=5Fgem=5Fobj= ect=5Fput() > drm/shmem-helper: Make all exported symbols GPL > drm/shmem-helper: Refactor locked/unlocked functions > drm/shmem-helper: Remove obsoleted is=5Fiomem test > locking/refcount, kref: Add kref=5Fput=5Fww=5Fmutex() > dma-resv: Add kref=5Fput=5Fdma=5Fresv() > drm/shmem-helper: Add and use pages=5Fpin=5Fcount > drm/shmem-helper: Use kref for pages=5Fuse=5Fcount > drm/shmem-helper: Add and use lockless drm=5Fgem=5Fshmem=5Fget=5Fpa= ges() > drm/shmem-helper: Switch drm=5Fgem=5Fshmem=5Fvmap/vunmap to use pin= /unpin > drm/shmem-helper: Use kref for vmap=5Fuse=5Fcount > drm/shmem-helper: Add and use drm=5Fgem=5Fshmem=5Fresv=5Fassert=5Fh= eld() helper > drm/shmem-helper: Add memory shrinker > drm/shmem-helper: Export drm=5Fgem=5Fshmem=5Fget=5Fpages=5Fsgt=5Flo= cked() > drm/virtio: Pin display framebuffer BO > drm/virtio: Attach shmem BOs dynamically > drm/virtio: Support memory shrinking > drm/panfrost: Switch to generic memory shrinker >=20 > drivers/gpu/drm/drm=5Fclient.c | 6 +- > drivers/gpu/drm/drm=5Fgem.c | 26 +- > drivers/gpu/drm/drm=5Fgem=5Fframebuffer=5Fhelper.c | 6 +- > drivers/gpu/drm/drm=5Fgem=5Fshmem=5Fhelper.c | 616 ++++++++++= +++++--- > drivers/gpu/drm/drm=5Finternal.h | 4 +- > drivers/gpu/drm/drm=5Fprime.c | 4 +- > drivers/gpu/drm/lima/lima=5Fgem.c | 11 +- > drivers/gpu/drm/lima/lima=5Fsched.c | 4 +- > drivers/gpu/drm/panfrost/Makefile | 1 - > drivers/gpu/drm/panfrost/panfrost=5Fdevice.h | 4 - > drivers/gpu/drm/panfrost/panfrost=5Fdrv.c | 29 +- > drivers/gpu/drm/panfrost/panfrost=5Fdump.c | 4 +- > drivers/gpu/drm/panfrost/panfrost=5Fgem.c | 36 +- > drivers/gpu/drm/panfrost/panfrost=5Fgem.h | 9 - > .../gpu/drm/panfrost/panfrost=5Fgem=5Fshrinker.c | 122 ---- > drivers/gpu/drm/panfrost/panfrost=5Fjob.c | 18 +- > drivers/gpu/drm/panfrost/panfrost=5Fmmu.c | 4 +- > drivers/gpu/drm/panfrost/panfrost=5Fperfcnt.c | 6 +- > drivers/gpu/drm/v3d/v3d=5Fbo.c | 26 +- > drivers/gpu/drm/virtio/virtgpu=5Fdrv.h | 22 +- > drivers/gpu/drm/virtio/virtgpu=5Fgem.c | 80 +++ > drivers/gpu/drm/virtio/virtgpu=5Fioctl.c | 57 +- > drivers/gpu/drm/virtio/virtgpu=5Fkms.c | 8 + > drivers/gpu/drm/virtio/virtgpu=5Fobject.c | 147 ++++- > drivers/gpu/drm/virtio/virtgpu=5Fplane.c | 17 +- > drivers/gpu/drm/virtio/virtgpu=5Fsubmit.c | 15 +- > drivers/gpu/drm/virtio/virtgpu=5Fvq.c | 40 ++ > include/drm/drm=5Fdevice.h | 10 +- > include/drm/drm=5Fgem.h | 6 +- > include/drm/drm=5Fgem=5Fshmem=5Fhelper.h | 141 +++- > include/linux/dma-resv.h | 9 + > include/linux/kref.h | 12 + > include/linux/refcount.h | 5 + > include/uapi/drm/virtgpu=5Fdrm.h | 14 + > lib/refcount.c | 34 + > 35 files changed, 1167 insertions(+), 386 deletions(-) > delete mode 100644 drivers/gpu/drm/panfrost/panfrost=5Fgem=5Fshrinke= r.c >=20 > --=20 > 2.41.0 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08D85C71153 for ; Mon, 28 Aug 2023 14:38:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231543AbjH1Oht convert rfc822-to-8bit (ORCPT ); Mon, 28 Aug 2023 10:37:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230102AbjH1OhU (ORCPT ); Mon, 28 Aug 2023 10:37:20 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E4BFC9 for ; Mon, 28 Aug 2023 07:37:16 -0700 (PDT) Received: from hamburger.collabora.co.uk (hamburger.collabora.co.uk [IPv6:2a01:4f8:1c1c:f269::1]) by madras.collabora.co.uk (Postfix) with ESMTP id 2B6C966003AC; Mon, 28 Aug 2023 15:37:13 +0100 (BST) From: "Helen Mae Koike Fornazier" In-Reply-To: <20230827175449.1766701-1-dmitry.osipenko@collabora.com> Content-Type: text/plain; charset="utf-8" X-Forward: 127.0.0.1 Date: Mon, 28 Aug 2023 15:37:12 +0100 Cc: "David Airlie" , "Gerd Hoffmann" , "Gurchetan Singh" , "Chia-I Wu" , "Daniel Vetter" , "Maarten Lankhorst" , "Maxime Ripard" , "Thomas Zimmermann" , =?utf-8?q?Christian_K=C3=B6nig?= , "Qiang Yu" , "Steven Price" , "Boris Brezillon" , "Emma Anholt" , "Melissa Wen" , "Will Deacon" , "Peter Zijlstra" , "Boqun Feng" , "Mark Rutland" , intel-gfx@lists.freedesktop.org, kernel@collabora.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org To: "Dmitry Osipenko" MIME-Version: 1.0 Message-ID: <55db-64ecb100-57-403f1500@96946290> Subject: =?utf-8?q?Re=3A?= [PATCH v15 00/23] Add generic memory shrinker to VirtIO-GPU and Panfrost DRM drivers User-Agent: SOGoMail 5.8.4 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sunday, August 27, 2023 14:54 -03, Dmitry Osipenko wrote: > This series: > > 1. Adds common drm-shmem memory shrinker > 2. Enables shrinker for VirtIO-GPU driver > 3. Switches Panfrost driver to the common shrinker Hi Dmitry, Would you mind testing with drm-ci? We virt-io tests there and it would be really great to get your feedback of it. https://cgit.freedesktop.org/drm/drm/log/?h=topic/drm-ci You need to merge your changes with the above tree. To configure it, you just need to have a tree on gitlab.freedesktop.org, go to the settings and change the CI/CD configuration file from .gitlab-ci.yml to drivers/gpu/drm/ci/gitlab-ci.yml, and you can start a pipeline on your branch. at the time of this writting, gitlab.freedesktop.org is under maintenance, but it should be back soon. Thank you! Helen > > Changelog: > > v15:- Moved drm-shmem reference counters to use kref that allows to > optimize unlocked functions, like was suggested by Boris Brezillon. > > - Changed drm/gem/shmem function names to use _locked postfix and > dropped the _unlocked, making the naming scheme consistent across > DRM code, like was suggested by Boris Brezillon. > > - Added patch that fixes UAF in drm-shmem for drivers that import > dma-buf and then release buffer in the import error code path. > > - Added patch that makes drm-shmem use new flag for SGT's get_pages() > refcounting, preventing unbalanced refcounting when GEM is freed. > > - Fixed guest blob pinning in virtio-gpu driver that was missed > previously in the shrinker patch. > > - Moved VC4 and virtio-gpu drivers to use drm_gem_put() in > GEM-creation error code paths, which is now required by drm-shmem > and was missed in a previous patch versions. > > - Virtio-GPU now attaches shmem pages to host on first use and not > when BO is created. In older patch versions there was a potential > race condition in the BO creation code path where both > get_sgt()+object_attach() should've been made under same resv lock, > otherwise pages could be evicted before attachment is invoked. > > - Virtio-GPU and drm-shmem shrinker patches are split into smaller > ones. > > v14:- All the prerequisite reservation locking patches landed upstream, > previously were a part of this series in v13 and older. > > https://lore.kernel.org/dri-devel/20230529223935.2672495-1-dmitry.osipenko@collabora.com/ > > - Added patches to improve locked/unlocked function names, like was > suggested by Boris Brezillon for v13. > > - Made all exported drm-shmem symbols GPL, like was previously > discussed with Thomas Zimmermann on this series. > > - Improved virtio-gpu shrinker patch. Now it won't detach purged BO > when userspace closes GEM. Crosvm (and not qemu) checks res_id on > CMD_CTX_DETACH_RESOURCE and prints noisy error message if ID is > invalid, which wasn't noticed before. > > v13:- Updated virtio-gpu shrinker patch to use drm_gem_shmem_object_pin() > directly instead of drm_gem_pin() and dropped patch that exported > drm_gem_pin() functions, like was requested by Thomas Zimmermann in > v12. > > v12:- Fixed the "no previous prototype for function" warning reported by > kernel build bot for v11. > > - Fixed the missing reservation lock reported by Intel CI for VGEM > driver. Other drivers using drm-shmem were affected similarly to > VGEM. The problem was in the dma-buf attachment code path that led > to drm-shmem pinning function which assumed the held reservation lock > by drm_gem_pin(). In the past that code path was causing trouble for > i915 driver and we've changed the locking scheme for the attachment > code path in the dma-buf core to let exporters to handle the locking > themselves. After a closer investigation, I realized that my assumption > about testing of dma-buf export code path using Panfrost driver was > incorrect. Now I created additional local test to exrecise the Panfrost > export path. I also reproduced the issue reported by the Intel CI for > v10. It's all fixed now by making the drm_gem_shmem_pin() to take the > resv lock by itself. > > - Patches are based on top of drm-tip, CC'd intel-gfx CI for testing. > > v11:- Rebased on a recent linux-next. Added new patch as a result: > > drm/shmem-helper: Export drm_gem_shmem_get_pages_sgt_locked() > > It's needed by the virtio-gpu driver to swap-in/unevict shmem > object, previously get_pages_sgt() didn't use locking. > > - Separated the "Add memory shrinker" patch into smaller parts to ease > the reviewing, as was requested by Thomas Zimmermann: > > drm/shmem-helper: Factor out pages alloc/release from > drm_gem_shmem_get/put_pages() > drm/shmem-helper: Add pages_pin_count field > drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin > drm/shmem-helper: Factor out unpinning part from drm_gem_shmem_purge() > > - Addessed the v10 review comments from Thomas Zimmermann: return errno > instead of bool, sort code alphabetically, rename function and etc > minor changes. > > - Added new patch to remove the "map->is_iomem" from drm-shmem, as > was suggested by Thomas Zimmermann. > > - Added acks and r-b's that were given to v10. > > v10:- Was partially applied to misc-fixes/next. > > https://lore.kernel.org/dri-devel/6c16f303-81df-7ebe-85e9-51bb40a8b301@collabora.com/T/ > > Dmitry Osipenko (23): > drm/shmem-helper: Fix UAF in error path when freeing SGT of imported > GEM > drm/shmem-helper: Use flag for tracking page count bumped by > get_pages_sgt() > 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/v3d: Replace open-coded drm_gem_shmem_free() with > drm_gem_object_put() > drm/virtio: Replace drm_gem_shmem_free() with drm_gem_object_put() > drm/shmem-helper: Make all exported symbols GPL > drm/shmem-helper: Refactor locked/unlocked functions > drm/shmem-helper: Remove obsoleted is_iomem test > locking/refcount, kref: Add kref_put_ww_mutex() > dma-resv: Add kref_put_dma_resv() > drm/shmem-helper: Add and use pages_pin_count > drm/shmem-helper: Use kref for pages_use_count > drm/shmem-helper: Add and use lockless drm_gem_shmem_get_pages() > drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin > drm/shmem-helper: Use kref for vmap_use_count > drm/shmem-helper: Add and use drm_gem_shmem_resv_assert_held() helper > drm/shmem-helper: Add memory shrinker > drm/shmem-helper: Export drm_gem_shmem_get_pages_sgt_locked() > drm/virtio: Pin display framebuffer BO > drm/virtio: Attach shmem BOs dynamically > drm/virtio: Support memory shrinking > drm/panfrost: Switch to generic memory shrinker > > drivers/gpu/drm/drm_client.c | 6 +- > drivers/gpu/drm/drm_gem.c | 26 +- > drivers/gpu/drm/drm_gem_framebuffer_helper.c | 6 +- > drivers/gpu/drm/drm_gem_shmem_helper.c | 616 +++++++++++++++--- > drivers/gpu/drm/drm_internal.h | 4 +- > drivers/gpu/drm/drm_prime.c | 4 +- > drivers/gpu/drm/lima/lima_gem.c | 11 +- > drivers/gpu/drm/lima/lima_sched.c | 4 +- > drivers/gpu/drm/panfrost/Makefile | 1 - > drivers/gpu/drm/panfrost/panfrost_device.h | 4 - > drivers/gpu/drm/panfrost/panfrost_drv.c | 29 +- > drivers/gpu/drm/panfrost/panfrost_dump.c | 4 +- > drivers/gpu/drm/panfrost/panfrost_gem.c | 36 +- > drivers/gpu/drm/panfrost/panfrost_gem.h | 9 - > .../gpu/drm/panfrost/panfrost_gem_shrinker.c | 122 ---- > drivers/gpu/drm/panfrost/panfrost_job.c | 18 +- > drivers/gpu/drm/panfrost/panfrost_mmu.c | 4 +- > drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 6 +- > drivers/gpu/drm/v3d/v3d_bo.c | 26 +- > drivers/gpu/drm/virtio/virtgpu_drv.h | 22 +- > drivers/gpu/drm/virtio/virtgpu_gem.c | 80 +++ > drivers/gpu/drm/virtio/virtgpu_ioctl.c | 57 +- > drivers/gpu/drm/virtio/virtgpu_kms.c | 8 + > drivers/gpu/drm/virtio/virtgpu_object.c | 147 ++++- > drivers/gpu/drm/virtio/virtgpu_plane.c | 17 +- > drivers/gpu/drm/virtio/virtgpu_submit.c | 15 +- > drivers/gpu/drm/virtio/virtgpu_vq.c | 40 ++ > include/drm/drm_device.h | 10 +- > include/drm/drm_gem.h | 6 +- > include/drm/drm_gem_shmem_helper.h | 141 +++- > include/linux/dma-resv.h | 9 + > include/linux/kref.h | 12 + > include/linux/refcount.h | 5 + > include/uapi/drm/virtgpu_drm.h | 14 + > lib/refcount.c | 34 + > 35 files changed, 1167 insertions(+), 386 deletions(-) > delete mode 100644 drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c > > -- > 2.41.0 >