All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: "Boris Brezillon" <boris.brezillon@collabora.com>,
	"Steven Price" <steven.price@arm.com>,
	"Liviu Dudau" <liviu.dudau@arm.com>,
	"Adrián Larumbe" <adrian.larumbe@collabora.com>,
	lima@lists.freedesktop.org, "Qiang Yu" <yuq825@gmail.com>
Cc: "David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	dri-devel@lists.freedesktop.org,
	"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
	kernel@collabora.com,
	"Christian König" <christian.koenig@amd.com>,
	"Alyssa Rosenzweig" <alyssa@rosenzweig.io>,
	"Faith Ekstrand" <faith.ekstrand@collabora.com>
Subject: Re: [PATCH v3 0/8] drm: Introduce sparse GEM shmem
Date: Thu, 10 Apr 2025 16:48:09 +0200	[thread overview]
Message-ID: <20250410164809.21109cbc@collabora.com> (raw)
In-Reply-To: <20250404092634.2968115-1-boris.brezillon@collabora.com>

+Christian, Alyssa and Faith, as suggested by Sima. I'll make sure to
Cc you on v4, but before that, I'd like to get your opinion on the
drm-gem/drm-gem-shmem changes to see if sending a v4 is actually
desirable or if I should go back to the drawing board.

On Fri,  4 Apr 2025 11:26:26 +0200
Boris Brezillon <boris.brezillon@collabora.com> wrote:

> This patch series is a proposal for implementing sparse page allocations
> for shmem objects. It was initially motivated by a kind of BO managed by
> the Panfrost/Panthor and Lima drivers, the tiler heap, which grows on
> demand every time the GPU faults on a virtual address within the heap BO
> range.
> 
> Because keeping a struct page pointer array that can describe the entire
> virtual range is wasteful when only a few backing pages have been
> allocated, we thought a sparse allocation approach with xarrays was a
> more efficient choice.
> 
> This sparse GEM shmem features takes the form of a new optional
> drm_gem_shmem_sparse_backing object that can be attached to a
> drm_gem_shmem_object at creation time if the driver wants. When this
> sparse GEM shmem backing mode is enabled, the driver is allow to
> partially populate the GEM pages, either at use time, or at fault
> time. The page population can be done progressively as the need for
> more memory arises. The new APIs takes explicit gfp_t flags to solve
> a long standing issue reported by Sima a while ago: all allocations
> happening in the fault handler path shouldn't block.
> 
> We also introduce two new helpers at the drm_gem.{c,h} level to
> automate the partial xarray population which the GEM-SHMEM logic
> relies on to populate its sparse page array.
> 
> A few details about the implementation now:
> 
> - Sparse GEM backing locking is deferred to the driver, because
>   we can't take the resv locks in the GPU fault handler path, and
>   since the page population can come from there, we have to let
>   the driver decide how to lock.
> - The pin/get semantics for sparse GEM shmem objects is different,
>   in that it doesn't populate the pages, but just flag them as
>   being used/required by some GPU component. The page population
>   will happen explicitly at GEM creation time or when a GPU fault
>   happens. Once pages have been populated, they won't disappear
>   until the GEM object is destroyed, purged or evicted. This means
>   you can grow, but not shrink. If we ever need to discard
>   BO ranges, the API can be extended to allow it, but it's not
>   something we needed for the Lima/Panthor/Panfrost case.
> - Panthor and Panfrost changes have been tested, but not extensively.
>   Lima changes have only been compile-tested.
> 
> Changes from v2:
> - We decided to focus more on the DRM aspects and forget about the
>   sgt building optimizations (sgt helpers taking an xarray instead of
>   a plain array). If the xarray -> array copies happening in that
>   path ever become the bottleneck, we can resurrect those changes.
> - We decided to make the sparse GEM changes less invasive by making
>   them an extra layer on top of drm_gem_shmem_object. What this means
>   is that sparse GEM shmem can now be used as regular GEM shmem
>   objects (vmap, pin, export, ... all work as they would on a regular
>   GEM). When that happens, we just force all pages to be populated,
>   so we kinda lose the benefit of sparse GEMs, but that's fine, because
>   in practice, such objects shouldn't be manipulated as regular GEMs.
>   It just serves as a safety guard to limit the risk of regressions
>   introduced by these sparse GEM shmem changes.
> 
> Discussion of previus revision can be found here[2][3].
> 
> For those used to review gitlab MRs, here's a link [1] to a Draft
> MR grouping those changes, but I'm in no way asking that the review
> happens on gitlab.
> 
> Regards,
> 
> Boris
> 
> [1]https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/16
> [2]https://lore.kernel.org/lkml/20250326021433.772196-1-adrian.larumbe@collabora.com/T/
> [3]https://lore.kernel.org/dri-devel/20250218232552.3450939-1-adrian.larumbe@collabora.com/
> 
> Adrián Larumbe (1):
>   drm/gem: Add helpers to request a range of pages on a GEM
> 
> Boris Brezillon (7):
>   drm/gem-shmem: Support sparse backing
>   drm/panfrost: Switch to sparse gem shmem to implement our
>     alloc-on-fault
>   drm/panthor: Add support for alloc-on-fault buffers
>   drm/panthor: Allow kernel BOs to pass DRM_PANTHOR_BO_ALLOC_ON_FAULT
>   drm/panthor: Add a panthor_vm_pre_fault_range() helper
>   drm/panthor: Make heap chunk allocation non-blocking
>   drm/lima: Use drm_gem_shmem_sparse_backing for heap buffers
> 
>  drivers/gpu/drm/drm_gem.c               | 134 +++++++
>  drivers/gpu/drm/drm_gem_shmem_helper.c  | 404 +++++++++++++++++++-
>  drivers/gpu/drm/lima/lima_gem.c         |  89 ++---
>  drivers/gpu/drm/lima/lima_gem.h         |   1 +
>  drivers/gpu/drm/lima/lima_vm.c          |  48 ++-
>  drivers/gpu/drm/panfrost/panfrost_drv.c |   2 +-
>  drivers/gpu/drm/panfrost/panfrost_gem.c |  37 +-
>  drivers/gpu/drm/panfrost/panfrost_gem.h |   8 +-
>  drivers/gpu/drm/panfrost/panfrost_mmu.c |  98 ++---
>  drivers/gpu/drm/panfrost/panfrost_mmu.h |   2 +
>  drivers/gpu/drm/panthor/panthor_drv.c   |  20 +-
>  drivers/gpu/drm/panthor/panthor_fw.c    |   6 +-
>  drivers/gpu/drm/panthor/panthor_gem.c   |  18 +-
>  drivers/gpu/drm/panthor/panthor_gem.h   |  12 +-
>  drivers/gpu/drm/panthor/panthor_heap.c  | 222 ++++++-----
>  drivers/gpu/drm/panthor/panthor_mmu.c   | 481 ++++++++++++++++++------
>  drivers/gpu/drm/panthor/panthor_mmu.h   |   2 +
>  drivers/gpu/drm/panthor/panthor_sched.c |   6 +-
>  include/drm/drm_gem.h                   |  14 +
>  include/drm/drm_gem_shmem_helper.h      | 285 +++++++++++++-
>  include/uapi/drm/panthor_drm.h          |  19 +-
>  21 files changed, 1492 insertions(+), 416 deletions(-)
> 


  parent reply	other threads:[~2025-04-10 14:48 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-04  9:26 [PATCH v3 0/8] drm: Introduce sparse GEM shmem Boris Brezillon
2025-04-04  9:26 ` [PATCH v3 1/8] drm/gem: Add helpers to request a range of pages on a GEM Boris Brezillon
2025-04-04  9:26 ` [PATCH v3 2/8] drm/gem-shmem: Support sparse backing Boris Brezillon
2025-04-04  9:26 ` [PATCH v3 3/8] drm/panfrost: Switch to sparse gem shmem to implement our alloc-on-fault Boris Brezillon
2025-04-04  9:26 ` [PATCH v3 4/8] drm/panthor: Add support for alloc-on-fault buffers Boris Brezillon
2025-04-04 12:17   ` Boris Brezillon
2025-04-04  9:26 ` [PATCH v3 5/8] drm/panthor: Allow kernel BOs to pass DRM_PANTHOR_BO_ALLOC_ON_FAULT Boris Brezillon
2025-04-04  9:26 ` [PATCH v3 6/8] drm/panthor: Add a panthor_vm_pre_fault_range() helper Boris Brezillon
2025-04-04  9:26 ` [PATCH v3 7/8] drm/panthor: Make heap chunk allocation non-blocking Boris Brezillon
2025-04-04  9:26 ` [PATCH v3 8/8] drm/lima: Use drm_gem_shmem_sparse_backing for heap buffers Boris Brezillon
2025-04-10 14:48 ` Boris Brezillon [this message]
2025-04-10 15:05   ` [PATCH v3 0/8] drm: Introduce sparse GEM shmem Christian König
2025-04-10 15:53     ` Boris Brezillon
2025-04-10 16:43       ` Christian König
2025-04-10 17:20         ` Boris Brezillon
2025-04-10 18:01           ` Alyssa Rosenzweig
2025-04-10 18:41             ` Boris Brezillon
2025-04-11  8:04               ` Christian König
2025-04-11  8:38                 ` Boris Brezillon
2025-04-11 10:55                   ` Christian König
2025-04-11 12:02                     ` Boris Brezillon
2025-04-11 12:45                       ` Christian König
2025-04-11 13:00                         ` Boris Brezillon
2025-04-11 13:13                           ` Christian König
2025-04-11 14:39                             ` Boris Brezillon
2025-04-14 12:47                               ` Boris Brezillon
2025-04-14 15:34                                 ` Steven Price
2025-04-15  9:47                                   ` Boris Brezillon
2025-04-16 15:16                                     ` Steven Price
2025-04-16 15:53                                       ` Boris Brezillon
2025-04-15 12:39                                   ` Daniel Stone
2025-04-11 18:24                     ` Simona Vetter
2025-04-11 12:01               ` Simona Vetter
2025-04-11 12:50                 ` Christian König
2025-04-11 18:18                   ` Simona Vetter
2025-04-11 13:52                 ` Alyssa Rosenzweig
2025-04-11 18:16                   ` Simona Vetter
2025-04-14 11:22                 ` Boris Brezillon
2025-04-14 13:03                   ` Alyssa Rosenzweig
2025-04-14 13:31                     ` Boris Brezillon
2025-04-14 13:42                       ` Alyssa Rosenzweig
2025-04-14 13:08                   ` Liviu Dudau
2025-04-14 14:34                     ` Simona Vetter
2025-04-14 15:15                       ` Boris Brezillon
2025-04-14 14:46                   ` Simona Vetter
2025-04-10 18:52           ` Christian König
2025-04-11  8:08             ` Boris Brezillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250410164809.21109cbc@collabora.com \
    --to=boris.brezillon@collabora.com \
    --cc=adrian.larumbe@collabora.com \
    --cc=airlied@gmail.com \
    --cc=alyssa@rosenzweig.io \
    --cc=christian.koenig@amd.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=faith.ekstrand@collabora.com \
    --cc=kernel@collabora.com \
    --cc=lima@lists.freedesktop.org \
    --cc=liviu.dudau@arm.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.com \
    --cc=tzimmermann@suse.de \
    --cc=yuq825@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.