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 C636CC83F12 for ; Mon, 28 Aug 2023 15:24:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 177CD10E2FE; Mon, 28 Aug 2023 15:24:13 +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 728ED10E2FE; Mon, 28 Aug 2023 15:24:11 +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 4A606660716E; Mon, 28 Aug 2023 16:24:08 +0100 (BST) From: "Helen Mae Koike Fornazier" In-Reply-To: <55db-64ecb100-57-403f1500@96946290> Content-Type: text/plain; charset="utf-8" X-Forward: 127.0.0.1 Date: Mon, 28 Aug 2023 16:24:08 +0100 To: "Helen Mae Koike Fornazier" MIME-Version: 1.0 Message-ID: <6d93-64ecbc00-3-3c8ca040@163557744> 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 , Boqun Feng , Maxime Ripard , Emma Anholt , =?utf-8?q?Christian_K=C3=B6nig?= , Peter Zijlstra , Thomas Zimmermann , intel-gfx@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Gurchetan Singh , Melissa Wen , Gerd Hoffmann , Dmitry Osipenko , kernel@collabora.com, Will Deacon , Steven Price , Qiang Yu Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" On Monday, August 28, 2023 11:37 -03, "Helen Mae Koike Fornazier" wrote: > On Sunday, August 27, 2023 14:54 -03, Dmitry Osipenko wrote: >=20 > > 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 >=20 > Hi Dmitry,=20 >=20 > Would you mind testing with drm-ci? We virt-io tests there and it wou= ld be > really great to get your feedback of it. >=20 > https://cgit.freedesktop.org/drm/drm/log/?h=3Dtopic/drm-ci sorry, I forgot that you also need this patchset: https://lists.freedesktop.org/archives/dri-devel/2023-August/420063= .html to enable virtio=5Fgpu test job. Thanks again. Helen >=20 > You need to merge your changes with the above tree. > To configure it, you just need to have a tree on gitlab.freedesktop.o= rg, > go to the settings and change the CI/CD configuration file from .gitl= ab-ci.yml > to drivers/gpu/drm/ci/gitlab-ci.yml, and you can start a pipeline > on your branch. >=20 > at the time of this writting, gitlab.freedesktop.org is under mainten= ance, > but it should be back soon. >=20 > Thank you! > Helen >=20 > >=20 > > Changelog: > >=20 > > v15:- Moved drm-shmem reference counters to use kref that allows to > > optimize unlocked functions, like was suggested by Boris Brez= illon. > >=20 > > - Changed drm/gem/shmem function names to use =5Flocked postfix= and > > dropped the =5Funlocked, making the naming scheme consistent = across > > DRM code, like was suggested by Boris Brezillon. > >=20 > > - Added patch that fixes UAF in drm-shmem for drivers that impo= rt > > 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=5F= pages() > > refcounting, preventing unbalanced refcounting when GEM is fr= eed. > >=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-s= hmem > > and was missed in a previous patch versions. > >=20 > > - Virtio-GPU now attaches shmem pages to host on first use and = not > > when BO is created. In older patch versions there was a poten= tial > > race condition in the BO creation code path where both > > get=5Fsgt()+object=5Fattach() should've been made under same = resv lock, > > otherwise pages could be evicted before attachment is invoked= . > >=20 > > - Virtio-GPU and drm-shmem shrinker patches are split into smal= ler > > ones. > >=20 > > v14:- All the prerequisite reservation locking patches landed upstr= eam, > > previously were a part of this series in v13 and older. > >=20 > > https://lore.kernel.org/dri-devel/20230529223935.2672495-1-= dmitry.osipenko@collabora.com/ > >=20 > > - Added patches to improve locked/unlocked function names, like= was > > 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 purge= d BO > > when userspace closes GEM. Crosvm (and not qemu) checks res=5F= id 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=5F= object=5Fpin() > > directly instead of drm=5Fgem=5Fpin() and dropped patch that = exported > > drm=5Fgem=5Fpin() functions, like was requested by Thomas Zim= mermann in > > v12. > >=20 > > v12:- Fixed the "no previous prototype for function" warning report= ed by > > kernel build bot for v11. > >=20 > > - Fixed the missing reservation lock reported by Intel CI for V= GEM > > driver. Other drivers using drm-shmem were affected similarly= to > > VGEM. The problem was in the dma-buf attachment code path tha= t led > > to drm-shmem pinning function which assumed the held reservat= ion lock > > by drm=5Fgem=5Fpin(). In the past that code path was causing = trouble for > > i915 driver and we've changed the locking scheme for the atta= chment > > 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 driv= er was > > incorrect. Now I created additional local test to exrecise th= e Panfrost > > export path. I also reproduced the issue reported by the Inte= l 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 te= sting. > >=20 > > v11:- Rebased on a recent linux-next. Added new patch as a result: > >=20 > > drm/shmem-helper: Export drm=5Fgem=5Fshmem=5Fget=5Fpages=5F= sgt=5Flocked() > >=20 > > It's needed by the virtio-gpu driver to swap-in/unevict shm= em > > 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= use pin/unpin > > drm/shmem-helper: Factor out unpinning part from drm=5Fgem=5F= shmem=5Fpurge() > >=20 > > - Addessed the v10 review comments from Thomas Zimmermann: retu= rn errno > > instead of bool, sort code alphabetically, rename function an= d etc > > minor changes. > >=20 > > - Added new patch to remove the "map->is=5Fiomem" from drm-shme= m, 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-51b= b40a8b301@collabora.com/T/ > >=20 > > Dmitry Osipenko (23): > > drm/shmem-helper: Fix UAF in error path when freeing SGT of impor= ted > > 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() = function > > 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=5Fo= bject=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=5F= pages() > > drm/shmem-helper: Switch drm=5Fgem=5Fshmem=5Fvmap/vunmap to use p= in/unpin > > drm/shmem-helper: Use kref for vmap=5Fuse=5Fcount > > drm/shmem-helper: Add and use drm=5Fgem=5Fshmem=5Fresv=5Fassert=5F= held() helper > > drm/shmem-helper: Add memory shrinker > > drm/shmem-helper: Export drm=5Fgem=5Fshmem=5Fget=5Fpages=5Fsgt=5F= 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 > >=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=5Fshrin= ker.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 1C209C83F12 for ; Mon, 28 Aug 2023 15:24:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 45CFB10E2FF; Mon, 28 Aug 2023 15:24:13 +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 728ED10E2FE; Mon, 28 Aug 2023 15:24:11 +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 4A606660716E; Mon, 28 Aug 2023 16:24:08 +0100 (BST) From: "Helen Mae Koike Fornazier" In-Reply-To: <55db-64ecb100-57-403f1500@96946290> Content-Type: text/plain; charset="utf-8" X-Forward: 127.0.0.1 Date: Mon, 28 Aug 2023 16:24:08 +0100 To: "Helen Mae Koike Fornazier" MIME-Version: 1.0 Message-ID: <6d93-64ecbc00-3-3c8ca040@163557744> 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 , Boqun Feng , Maxime Ripard , Emma Anholt , =?utf-8?q?Christian_K=C3=B6nig?= , Peter Zijlstra , Thomas Zimmermann , intel-gfx@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Gurchetan Singh , Melissa Wen , Boris Brezillon , Gerd Hoffmann , Dmitry Osipenko , kernel@collabora.com, Will Deacon , Steven Price , Qiang Yu Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Monday, August 28, 2023 11:37 -03, "Helen Mae Koike Fornazier" wrote: > On Sunday, August 27, 2023 14:54 -03, Dmitry Osipenko wrote: >=20 > > 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 >=20 > Hi Dmitry,=20 >=20 > Would you mind testing with drm-ci? We virt-io tests there and it wou= ld be > really great to get your feedback of it. >=20 > https://cgit.freedesktop.org/drm/drm/log/?h=3Dtopic/drm-ci sorry, I forgot that you also need this patchset: https://lists.freedesktop.org/archives/dri-devel/2023-August/420063= .html to enable virtio=5Fgpu test job. Thanks again. Helen >=20 > You need to merge your changes with the above tree. > To configure it, you just need to have a tree on gitlab.freedesktop.o= rg, > go to the settings and change the CI/CD configuration file from .gitl= ab-ci.yml > to drivers/gpu/drm/ci/gitlab-ci.yml, and you can start a pipeline > on your branch. >=20 > at the time of this writting, gitlab.freedesktop.org is under mainten= ance, > but it should be back soon. >=20 > Thank you! > Helen >=20 > >=20 > > Changelog: > >=20 > > v15:- Moved drm-shmem reference counters to use kref that allows to > > optimize unlocked functions, like was suggested by Boris Brez= illon. > >=20 > > - Changed drm/gem/shmem function names to use =5Flocked postfix= and > > dropped the =5Funlocked, making the naming scheme consistent = across > > DRM code, like was suggested by Boris Brezillon. > >=20 > > - Added patch that fixes UAF in drm-shmem for drivers that impo= rt > > 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=5F= pages() > > refcounting, preventing unbalanced refcounting when GEM is fr= eed. > >=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-s= hmem > > and was missed in a previous patch versions. > >=20 > > - Virtio-GPU now attaches shmem pages to host on first use and = not > > when BO is created. In older patch versions there was a poten= tial > > race condition in the BO creation code path where both > > get=5Fsgt()+object=5Fattach() should've been made under same = resv lock, > > otherwise pages could be evicted before attachment is invoked= . > >=20 > > - Virtio-GPU and drm-shmem shrinker patches are split into smal= ler > > ones. > >=20 > > v14:- All the prerequisite reservation locking patches landed upstr= eam, > > previously were a part of this series in v13 and older. > >=20 > > https://lore.kernel.org/dri-devel/20230529223935.2672495-1-= dmitry.osipenko@collabora.com/ > >=20 > > - Added patches to improve locked/unlocked function names, like= was > > 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 purge= d BO > > when userspace closes GEM. Crosvm (and not qemu) checks res=5F= id 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=5F= object=5Fpin() > > directly instead of drm=5Fgem=5Fpin() and dropped patch that = exported > > drm=5Fgem=5Fpin() functions, like was requested by Thomas Zim= mermann in > > v12. > >=20 > > v12:- Fixed the "no previous prototype for function" warning report= ed by > > kernel build bot for v11. > >=20 > > - Fixed the missing reservation lock reported by Intel CI for V= GEM > > driver. Other drivers using drm-shmem were affected similarly= to > > VGEM. The problem was in the dma-buf attachment code path tha= t led > > to drm-shmem pinning function which assumed the held reservat= ion lock > > by drm=5Fgem=5Fpin(). In the past that code path was causing = trouble for > > i915 driver and we've changed the locking scheme for the atta= chment > > 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 driv= er was > > incorrect. Now I created additional local test to exrecise th= e Panfrost > > export path. I also reproduced the issue reported by the Inte= l 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 te= sting. > >=20 > > v11:- Rebased on a recent linux-next. Added new patch as a result: > >=20 > > drm/shmem-helper: Export drm=5Fgem=5Fshmem=5Fget=5Fpages=5F= sgt=5Flocked() > >=20 > > It's needed by the virtio-gpu driver to swap-in/unevict shm= em > > 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= use pin/unpin > > drm/shmem-helper: Factor out unpinning part from drm=5Fgem=5F= shmem=5Fpurge() > >=20 > > - Addessed the v10 review comments from Thomas Zimmermann: retu= rn errno > > instead of bool, sort code alphabetically, rename function an= d etc > > minor changes. > >=20 > > - Added new patch to remove the "map->is=5Fiomem" from drm-shme= m, 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-51b= b40a8b301@collabora.com/T/ > >=20 > > Dmitry Osipenko (23): > > drm/shmem-helper: Fix UAF in error path when freeing SGT of impor= ted > > 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() = function > > 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=5Fo= bject=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=5F= pages() > > drm/shmem-helper: Switch drm=5Fgem=5Fshmem=5Fvmap/vunmap to use p= in/unpin > > drm/shmem-helper: Use kref for vmap=5Fuse=5Fcount > > drm/shmem-helper: Add and use drm=5Fgem=5Fshmem=5Fresv=5Fassert=5F= held() helper > > drm/shmem-helper: Add memory shrinker > > drm/shmem-helper: Export drm=5Fgem=5Fshmem=5Fget=5Fpages=5Fsgt=5F= 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 > >=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=5Fshrin= ker.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 8A595C83F1A for ; Mon, 28 Aug 2023 15:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231358AbjH1PYj convert rfc822-to-8bit (ORCPT ); Mon, 28 Aug 2023 11:24:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231305AbjH1PYO (ORCPT ); Mon, 28 Aug 2023 11:24:14 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31E0F124 for ; Mon, 28 Aug 2023 08:24:11 -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 4A606660716E; Mon, 28 Aug 2023 16:24:08 +0100 (BST) From: "Helen Mae Koike Fornazier" In-Reply-To: <55db-64ecb100-57-403f1500@96946290> Content-Type: text/plain; charset="utf-8" X-Forward: 127.0.0.1 Date: Mon, 28 Aug 2023 16:24:08 +0100 Cc: "Dmitry Osipenko" , "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?= To: "Helen Mae Koike Fornazier" MIME-Version: 1.0 Message-ID: <6d93-64ecbc00-3-3c8ca040@163557744> 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 Monday, August 28, 2023 11:37 -03, "Helen Mae Koike Fornazier" wrote: > 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 sorry, I forgot that you also need this patchset: https://lists.freedesktop.org/archives/dri-devel/2023-August/420063.html to enable virtio_gpu test job. Thanks again. Helen > > 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 > > >