virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: "David Airlie" <airlied@gmail.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Gurchetan Singh" <gurchetansingh@chromium.org>,
	"Chia-I Wu" <olvaffe@gmail.com>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Christian König" <christian.koenig@amd.com>,
	"Qiang Yu" <yuq825@gmail.com>,
	"Steven Price" <steven.price@arm.com>,
	"Emma Anholt" <emma@anholt.net>, "Melissa Wen" <mwen@igalia.com>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	kernel@collabora.com, virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v18 15/26] drm/panfrost: Explicitly get and put drm-shmem pages
Date: Fri, 24 Nov 2023 10:40:53 +0100	[thread overview]
Message-ID: <20231124104053.034496fb@collabora.com> (raw)
In-Reply-To: <20231123154848.034f4710@collabora.com>

On Thu, 23 Nov 2023 15:48:48 +0100
Boris Brezillon <boris.brezillon@collabora.com> wrote:

> On Mon, 30 Oct 2023 02:01:54 +0300
> Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote:
> 
> > To simplify the drm-shmem refcnt handling, we're moving away from
> > the implicit get_pages() that is used by get_pages_sgt(). From now on
> > drivers will have to pin pages while they use sgt. Panfrost's shrinker
> > doesn't support swapping out BOs, hence pages are pinned and sgt is valid
> > as long as pages' use-count > 0.
> > 
> > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> > ---
> >  drivers/gpu/drm/panfrost/panfrost_gem.c | 17 +++++++++++++++++
> >  drivers/gpu/drm/panfrost/panfrost_mmu.c |  6 ++----
> >  2 files changed, 19 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c
> > index 6b77d8cebcb2..bb9d43cf7c3c 100644
> > --- a/drivers/gpu/drm/panfrost/panfrost_gem.c
> > +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c
> > @@ -47,8 +47,13 @@ static void panfrost_gem_free_object(struct drm_gem_object *obj)
> >  			}
> >  		}
> >  		kvfree(bo->sgts);
> > +
> > +		drm_gem_shmem_put_pages(&bo->base);
> >  	}
> >  
> > +	if (!bo->is_heap && !obj->import_attach)
> > +		drm_gem_shmem_put_pages(&bo->base);
> > +
> >  	drm_gem_shmem_free(&bo->base);
> >  }
> >  
> > @@ -269,6 +274,7 @@ panfrost_gem_create(struct drm_device *dev, size_t size, u32 flags)
> >  {
> >  	struct drm_gem_shmem_object *shmem;
> >  	struct panfrost_gem_object *bo;
> > +	int err;
> >  
> >  	/* Round up heap allocations to 2MB to keep fault handling simple */
> >  	if (flags & PANFROST_BO_HEAP)
> > @@ -282,7 +288,18 @@ panfrost_gem_create(struct drm_device *dev, size_t size, u32 flags)
> >  	bo->noexec = !!(flags & PANFROST_BO_NOEXEC);
> >  	bo->is_heap = !!(flags & PANFROST_BO_HEAP);
> >  
> > +	if (!bo->is_heap) {
> > +		err = drm_gem_shmem_get_pages(shmem);  
> 
> I really hate the fact we request pages here while we call
> panfrost_mmu_map() in panfrost_gem_open(), because ultimately, pages
> are requested for the MMU mapping. Also hate the quirk we have in shmem
> to call free_pages() instead of put_pages_locked() when the BO refcount
> dropped to zero, and I was hoping we could get rid of it at some point
> by teaching drivers to request pages when they actually need it instead
> of tying pages lifetime to the GEM object lifetime.
> 
> Maybe what we should do instead is move the get/put_pages() in
> panfrost_mmu_map/unmap() (as I suggested), but have a special mapping
> panfrost_mmu_evict/restore() helpers that kill/restore the MMU mappings
> without releasing/acquiring the pages ref.

Okay, so I played with your branch and did what I suggested here ^. The
end result is available here [1]. I also split this patch in two:

- A fix for the error path in panfrost_mmu_map_fault_addr() [2]
- The explicit get/put_pages() stuff with pages ref owned by the
  panfrost_gem_mapping object [3]

[1]https://gitlab.freedesktop.org/bbrezillon/linux/-/commits/virtio-gpu-shrinker-v18
[2]https://gitlab.freedesktop.org/bbrezillon/linux/-/commit/9d499e971fdae4d6e52f8871ca27c24b2a2c43d6
[3]https://gitlab.freedesktop.org/bbrezillon/linux/-/commit/ba3de65bf1cf0ca95710e743ec85ca67ff1aa223


  reply	other threads:[~2023-11-24  9:41 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20231029230205.93277-1-dmitry.osipenko@collabora.com>
     [not found] ` <20231029230205.93277-26-dmitry.osipenko@collabora.com>
2023-11-03 22:55   ` [PATCH v18 25/26] drm/virtio: Support shmem shrinking Gurchetan Singh
     [not found] ` <20231029230205.93277-12-dmitry.osipenko@collabora.com>
2023-11-10 10:16   ` [PATCH v18 11/26] drm/shmem-helper: Prepare drm_gem_shmem_free() to shrinker addition Boris Brezillon
2023-11-20 11:02     ` Dmitry Osipenko
2023-11-20 11:19       ` Boris Brezillon
2023-11-20 11:38         ` Dmitry Osipenko
     [not found] ` <20231029230205.93277-13-dmitry.osipenko@collabora.com>
2023-11-10 10:17   ` [PATCH v18 12/26] drm/shmem-helper: Make drm_gem_shmem_get_pages() public Boris Brezillon
     [not found] ` <20231029230205.93277-15-dmitry.osipenko@collabora.com>
2023-11-10 10:30   ` [PATCH v18 14/26] drm/lima: Explicitly get and put drm-shmem pages Boris Brezillon
     [not found] ` <20231029230205.93277-17-dmitry.osipenko@collabora.com>
2023-11-10 10:59   ` [PATCH v18 16/26] drm/virtio: " Boris Brezillon
     [not found] ` <20231029230205.93277-18-dmitry.osipenko@collabora.com>
2023-11-10 11:01   ` [PATCH v18 17/26] drm/v3d: " Boris Brezillon
     [not found] ` <20231029230205.93277-19-dmitry.osipenko@collabora.com>
2023-11-10 11:15   ` [PATCH v18 18/26] drm/shmem-helper: Change sgt allocation policy Boris Brezillon
     [not found] ` <20231029230205.93277-20-dmitry.osipenko@collabora.com>
2023-11-10 14:58   ` [PATCH v18 19/26] drm/shmem-helper: Add common memory shrinker Boris Brezillon
2023-11-13  9:35     ` Boris Brezillon
     [not found] ` <20231029230205.93277-22-dmitry.osipenko@collabora.com>
2023-11-13  9:49   ` [PATCH v18 21/26] drm/shmem-helper: Optimize unlocked get_pages_sgt() Boris Brezillon
     [not found] ` <20231029230205.93277-23-dmitry.osipenko@collabora.com>
2023-11-13  9:54   ` [PATCH v18 22/26] drm/shmem-helper: Don't free refcounted GEM Boris Brezillon
2023-11-22 22:30     ` Dmitry Osipenko
2023-11-23  9:08       ` Boris Brezillon
2023-11-23 12:36         ` Dmitry Osipenko
     [not found] ` <20231029230205.93277-25-dmitry.osipenko@collabora.com>
2023-11-13  9:57   ` [PATCH v18 24/26] drm/virtio: Attach shmem BOs dynamically Boris Brezillon
2023-11-22 22:37     ` Dmitry Osipenko
2023-11-22 22:41       ` Dmitry Osipenko
     [not found] ` <20231029230205.93277-16-dmitry.osipenko@collabora.com>
2023-11-10 10:53   ` [PATCH v18 15/26] drm/panfrost: Explicitly get and put drm-shmem pages Boris Brezillon
2023-11-22 22:04     ` Dmitry Osipenko
2023-11-23  9:05       ` Boris Brezillon
2023-11-23 12:24         ` Dmitry Osipenko
2023-11-23 14:33           ` Boris Brezillon
2023-11-23 14:48   ` Boris Brezillon
2023-11-24  9:40     ` Boris Brezillon [this message]
     [not found] ` <20231029230205.93277-27-dmitry.osipenko@collabora.com>
2023-11-24 10:04   ` [PATCH v18 26/26] drm/panfrost: Switch to generic memory shrinker Boris Brezillon
     [not found] ` <20231029230205.93277-5-dmitry.osipenko@collabora.com>
2023-11-24 10:40   ` [PATCH v18 04/26] drm/shmem-helper: Refactor locked/unlocked functions Maxime Ripard
2023-11-24 10:44     ` Boris Brezillon
2023-11-24 10:59     ` Boris Brezillon
2023-11-28 11:14       ` Maxime Ripard
2023-11-28 12:37         ` Boris Brezillon
2023-11-28 22:05           ` Dmitry Osipenko
2023-11-29  7:53             ` Boris Brezillon
2023-11-29 10:47               ` Dmitry Osipenko
2023-11-29 10:57                 ` Boris Brezillon
2023-11-29 13:09               ` Maxime Ripard
2023-11-29 13:46                 ` Boris Brezillon
2023-11-29 15:15                   ` Maxime Ripard
2023-11-29 15:47                     ` Boris Brezillon
2023-12-04 12:55                       ` Maxime Ripard
2023-12-05 11:43                         ` Dmitry Osipenko
2023-12-14 18:16                           ` Maxime Ripard
2023-12-15  0:42                             ` Dmitry Osipenko
     [not found] ` <20231029230205.93277-6-dmitry.osipenko@collabora.com>
2023-11-10 10:08   ` [PATCH v18 05/26] drm/shmem-helper: Remove obsoleted is_iomem test Boris Brezillon
2023-11-24 10:40   ` Maxime Ripard
     [not found] ` <20231029230205.93277-9-dmitry.osipenko@collabora.com>
2023-11-24 10:47   ` [PATCH v18 08/26] drm/shmem-helper: Add and use lockless drm_gem_shmem_get_pages() Maxime Ripard
2023-11-24 11:20     ` Boris Brezillon
     [not found] ` <20231029230205.93277-10-dmitry.osipenko@collabora.com>
2023-11-24 10:48   ` [PATCH v18 09/26] drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin Maxime Ripard

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=20231124104053.034496fb@collabora.com \
    --to=boris.brezillon@collabora.com \
    --cc=airlied@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dmitry.osipenko@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emma@anholt.net \
    --cc=gurchetansingh@chromium.org \
    --cc=kernel@collabora.com \
    --cc=kraxel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=mwen@igalia.com \
    --cc=olvaffe@gmail.com \
    --cc=steven.price@arm.com \
    --cc=tzimmermann@suse.de \
    --cc=virtualization@lists.linux-foundation.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).