All of lore.kernel.org
 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: Thu, 23 Nov 2023 10:05:57 +0100	[thread overview]
Message-ID: <20231123100557.05a49343@collabora.com> (raw)
In-Reply-To: <26890ba7-5e19-df0c-fce0-26af58e66266@collabora.com>

On Thu, 23 Nov 2023 01:04:56 +0300
Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote:

> On 11/10/23 13:53, Boris Brezillon wrote:
> > Hm, there was no drm_gem_shmem_get_pages_sgt() call here, why should we
> > add a drm_gem_shmem_get_pages()? What we should do instead is add a
> > drm_gem_shmem_get_pages() for each drm_gem_shmem_get_pages_sgt() we
> > have in the driver (in panfrost_mmu_map()), and add
> > drm_gem_shmem_put_pages() calls where they are missing
> > (panfrost_mmu_unmap()).
> >   
> >> +		if (err)
> >> +			goto err_free;
> >> +	}
> >> +
> >>  	return bo;
> >> +
> >> +err_free:
> >> +	drm_gem_shmem_free(&bo->base);
> >> +
> >> +	return ERR_PTR(err);
> >>  }
> >>  
> >>  struct drm_gem_object *
> >> diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
> >> index 770dab1942c2..ac145a98377b 100644
> >> --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
> >> +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
> >> @@ -504,7 +504,7 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
> >>  		if (IS_ERR(pages[i])) {
> >>  			ret = PTR_ERR(pages[i]);
> >>  			pages[i] = NULL;
> >> -			goto err_pages;
> >> +			goto err_unlock;
> >>  		}
> >>  	}
> >>  
> >> @@ -512,7 +512,7 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
> >>  	ret = sg_alloc_table_from_pages(sgt, pages + page_offset,
> >>  					NUM_FAULT_PAGES, 0, SZ_2M, GFP_KERNEL);
> >>  	if (ret)
> >> -		goto err_pages;
> >> +		goto err_unlock;  
> > Feels like the panfrost_gem_mapping object should hold a ref on the BO
> > pages, not the BO itself, because, ultimately, the user of the BO is
> > the GPU. This matches what I was saying about moving get/put_pages() to
> > panfrost_mmu_map/unmap(): everytime a panfrost_gem_mapping becomes
> > active, to want to take a pages ref, every time it becomes inactive,
> > you should release the pages ref.  
> 
> The panfrost_mmu_unmap() is also used by shrinker when BO is purged. I'm
> unhappy with how icky it all becomes if unmap is made to put pages.

Why, that's exactly what's supposed to happen. If you mmu_unmap(), that
means you no longer need the pages ref you got.

> 
> Previously map() was implicitly allocating pages with get_sgt() and then
> pages were implicitly released by drm_gem_shmem_free(). A non-heap BO is
> mapped when it's created by Panfrost, hence the actual lifetime of pages
> is kept unchanged by this patch.

But the whole point of making it explicit is to control when pages are
needed or not, isn't it. The fact we mmu_map() the BO at open time, and
keep it mapped until it's not longer referenced is an implementation
choice, and I don't think having pages_put() in mmu_unmap() changes
that.

> The implicit allocation is turned into
> explicit one, i.e. pages are explicitly allocated before BO is mapped.
> 


WARNING: multiple messages have this Message-ID (diff)
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: kernel@collabora.com, "Thomas Zimmermann" <tzimmermann@suse.de>,
	"Emma Anholt" <emma@anholt.net>,
	"Christian König" <christian.koenig@amd.com>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	"Maxime Ripard" <mripard@kernel.org>,
	"Gurchetan Singh" <gurchetansingh@chromium.org>,
	"Melissa Wen" <mwen@igalia.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Steven Price" <steven.price@arm.com>,
	virtualization@lists.linux-foundation.org,
	"Qiang Yu" <yuq825@gmail.com>
Subject: Re: [PATCH v18 15/26] drm/panfrost: Explicitly get and put drm-shmem pages
Date: Thu, 23 Nov 2023 10:05:57 +0100	[thread overview]
Message-ID: <20231123100557.05a49343@collabora.com> (raw)
In-Reply-To: <26890ba7-5e19-df0c-fce0-26af58e66266@collabora.com>

On Thu, 23 Nov 2023 01:04:56 +0300
Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote:

> On 11/10/23 13:53, Boris Brezillon wrote:
> > Hm, there was no drm_gem_shmem_get_pages_sgt() call here, why should we
> > add a drm_gem_shmem_get_pages()? What we should do instead is add a
> > drm_gem_shmem_get_pages() for each drm_gem_shmem_get_pages_sgt() we
> > have in the driver (in panfrost_mmu_map()), and add
> > drm_gem_shmem_put_pages() calls where they are missing
> > (panfrost_mmu_unmap()).
> >   
> >> +		if (err)
> >> +			goto err_free;
> >> +	}
> >> +
> >>  	return bo;
> >> +
> >> +err_free:
> >> +	drm_gem_shmem_free(&bo->base);
> >> +
> >> +	return ERR_PTR(err);
> >>  }
> >>  
> >>  struct drm_gem_object *
> >> diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
> >> index 770dab1942c2..ac145a98377b 100644
> >> --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
> >> +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
> >> @@ -504,7 +504,7 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
> >>  		if (IS_ERR(pages[i])) {
> >>  			ret = PTR_ERR(pages[i]);
> >>  			pages[i] = NULL;
> >> -			goto err_pages;
> >> +			goto err_unlock;
> >>  		}
> >>  	}
> >>  
> >> @@ -512,7 +512,7 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
> >>  	ret = sg_alloc_table_from_pages(sgt, pages + page_offset,
> >>  					NUM_FAULT_PAGES, 0, SZ_2M, GFP_KERNEL);
> >>  	if (ret)
> >> -		goto err_pages;
> >> +		goto err_unlock;  
> > Feels like the panfrost_gem_mapping object should hold a ref on the BO
> > pages, not the BO itself, because, ultimately, the user of the BO is
> > the GPU. This matches what I was saying about moving get/put_pages() to
> > panfrost_mmu_map/unmap(): everytime a panfrost_gem_mapping becomes
> > active, to want to take a pages ref, every time it becomes inactive,
> > you should release the pages ref.  
> 
> The panfrost_mmu_unmap() is also used by shrinker when BO is purged. I'm
> unhappy with how icky it all becomes if unmap is made to put pages.

Why, that's exactly what's supposed to happen. If you mmu_unmap(), that
means you no longer need the pages ref you got.

> 
> Previously map() was implicitly allocating pages with get_sgt() and then
> pages were implicitly released by drm_gem_shmem_free(). A non-heap BO is
> mapped when it's created by Panfrost, hence the actual lifetime of pages
> is kept unchanged by this patch.

But the whole point of making it explicit is to control when pages are
needed or not, isn't it. The fact we mmu_map() the BO at open time, and
keep it mapped until it's not longer referenced is an implementation
choice, and I don't think having pages_put() in mmu_unmap() changes
that.

> The implicit allocation is turned into
> explicit one, i.e. pages are explicitly allocated before BO is mapped.
> 


  reply	other threads:[~2023-11-23  9:06 UTC|newest]

Thread overview: 168+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-29 23:01 [PATCH v18 00/26] Add generic memory shrinker to VirtIO-GPU and Panfrost DRM drivers Dmitry Osipenko
2023-10-29 23:01 ` Dmitry Osipenko
2023-10-29 23:01 ` [PATCH v18 01/26] drm/gem: Change locked/unlocked postfix of drm_gem_v/unmap() function names Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-24 10:34   ` Maxime Ripard
2023-11-24 10:34     ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 02/26] drm/gem: Add _locked postfix to functions that have unlocked counterpart Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-24 10:35   ` Maxime Ripard
2023-11-24 10:35     ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 03/26] drm/shmem-helper: Make all exported symbols GPL Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-24 10:36   ` Maxime Ripard
2023-11-24 10:36     ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 04/26] drm/shmem-helper: Refactor locked/unlocked functions Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-24 10:40   ` Maxime Ripard
2023-11-24 10:40     ` Maxime Ripard
2023-11-24 10:44     ` Boris Brezillon
2023-11-24 10:44       ` Boris Brezillon
2023-11-24 10:59     ` Boris Brezillon
2023-11-24 10:59       ` Boris Brezillon
2023-11-28 11:14       ` Maxime Ripard
2023-11-28 11:14         ` Maxime Ripard
2023-11-28 12:37         ` Boris Brezillon
2023-11-28 12:37           ` Boris Brezillon
2023-11-28 22:05           ` Dmitry Osipenko
2023-11-28 22:05             ` Dmitry Osipenko
2023-11-29  7:53             ` Boris Brezillon
2023-11-29  7:53               ` Boris Brezillon
2023-11-29 10:47               ` Dmitry Osipenko
2023-11-29 10:47                 ` Dmitry Osipenko
2023-11-29 10:57                 ` Boris Brezillon
2023-11-29 10:57                   ` Boris Brezillon
2023-11-29 13:09               ` Maxime Ripard
2023-11-29 13:09                 ` Maxime Ripard
2023-11-29 13:46                 ` Boris Brezillon
2023-11-29 13:46                   ` Boris Brezillon
2023-11-29 15:15                   ` Maxime Ripard
2023-11-29 15:15                     ` Maxime Ripard
2023-11-29 15:47                     ` Boris Brezillon
2023-11-29 15:47                       ` Boris Brezillon
2023-12-04 12:55                       ` Maxime Ripard
2023-12-04 12:55                         ` Maxime Ripard
2023-12-05 11:43                         ` Dmitry Osipenko
2023-12-05 11:43                           ` Dmitry Osipenko
2023-12-14 18:16                           ` Maxime Ripard
2023-12-14 18:16                             ` Maxime Ripard
2023-12-15  0:42                             ` Dmitry Osipenko
2023-12-15  0:42                               ` Dmitry Osipenko
2023-10-29 23:01 ` [PATCH v18 05/26] drm/shmem-helper: Remove obsoleted is_iomem test Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-10 10:08   ` Boris Brezillon
2023-11-10 10:08     ` Boris Brezillon
2023-11-24 10:40   ` Maxime Ripard
2023-11-24 10:40     ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 06/26] drm/shmem-helper: Add and use pages_pin_count Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-24 10:41   ` Maxime Ripard
2023-11-24 10:41     ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 07/26] drm/shmem-helper: Use refcount_t for pages_use_count Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-24 10:41   ` Maxime Ripard
2023-11-24 10:41     ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 08/26] drm/shmem-helper: Add and use lockless drm_gem_shmem_get_pages() Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-24 10:47   ` Maxime Ripard
2023-11-24 10:47     ` Maxime Ripard
2023-11-24 11:20     ` Boris Brezillon
2023-11-24 11:20       ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 09/26] drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-24 10:48   ` Maxime Ripard
2023-11-24 10:48     ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 10/26] drm/shmem-helper: Use refcount_t for vmap_use_count Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-24 10:48   ` Maxime Ripard
2023-11-24 10:48     ` Maxime Ripard
2023-10-29 23:01 ` [PATCH v18 11/26] drm/shmem-helper: Prepare drm_gem_shmem_free() to shrinker addition Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-10 10:16   ` Boris Brezillon
2023-11-10 10:16     ` Boris Brezillon
2023-11-20 11:02     ` Dmitry Osipenko
2023-11-20 11:02       ` Dmitry Osipenko
2023-11-20 11:19       ` Boris Brezillon
2023-11-20 11:19         ` Boris Brezillon
2023-11-20 11:38         ` Dmitry Osipenko
2023-11-20 11:38           ` Dmitry Osipenko
2023-10-29 23:01 ` [PATCH v18 12/26] drm/shmem-helper: Make drm_gem_shmem_get_pages() public Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-10 10:17   ` Boris Brezillon
2023-11-10 10:17     ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 13/26] drm/shmem-helper: Add drm_gem_shmem_put_pages() Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-10-29 23:01 ` [PATCH v18 14/26] drm/lima: Explicitly get and put drm-shmem pages Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-10 10:30   ` Boris Brezillon
2023-11-10 10:30     ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 15/26] drm/panfrost: " Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-10 10:53   ` Boris Brezillon
2023-11-10 10:53     ` Boris Brezillon
2023-11-22 22:04     ` Dmitry Osipenko
2023-11-22 22:04       ` Dmitry Osipenko
2023-11-23  9:05       ` Boris Brezillon [this message]
2023-11-23  9:05         ` Boris Brezillon
2023-11-23 12:24         ` Dmitry Osipenko
2023-11-23 12:24           ` Dmitry Osipenko
2023-11-23 14:33           ` Boris Brezillon
2023-11-23 14:33             ` Boris Brezillon
2023-11-23 14:48   ` Boris Brezillon
2023-11-23 14:48     ` Boris Brezillon
2023-11-24  9:40     ` Boris Brezillon
2023-11-24  9:40       ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 16/26] drm/virtio: " Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-10 10:59   ` Boris Brezillon
2023-11-10 10:59     ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 17/26] drm/v3d: " Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-10 11:01   ` Boris Brezillon
2023-11-10 11:01     ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 18/26] drm/shmem-helper: Change sgt allocation policy Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-10 11:15   ` Boris Brezillon
2023-11-10 11:15     ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 19/26] drm/shmem-helper: Add common memory shrinker Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-11-10 14:58   ` Boris Brezillon
2023-11-10 14:58     ` Boris Brezillon
2023-11-13  9:35     ` Boris Brezillon
2023-11-13  9:35       ` Boris Brezillon
2023-10-29 23:01 ` [PATCH v18 20/26] drm/shmem-helper: Export drm_gem_shmem_get_pages_sgt_locked() Dmitry Osipenko
2023-10-29 23:01   ` Dmitry Osipenko
2023-10-29 23:02 ` [PATCH v18 21/26] drm/shmem-helper: Optimize unlocked get_pages_sgt() Dmitry Osipenko
2023-10-29 23:02   ` Dmitry Osipenko
2023-11-13  9:49   ` Boris Brezillon
2023-11-13  9:49     ` Boris Brezillon
2023-10-29 23:02 ` [PATCH v18 22/26] drm/shmem-helper: Don't free refcounted GEM Dmitry Osipenko
2023-10-29 23:02   ` Dmitry Osipenko
2023-11-13  9:54   ` Boris Brezillon
2023-11-13  9:54     ` Boris Brezillon
2023-11-22 22:30     ` Dmitry Osipenko
2023-11-22 22:30       ` Dmitry Osipenko
2023-11-23  9:08       ` Boris Brezillon
2023-11-23  9:08         ` Boris Brezillon
2023-11-23 12:36         ` Dmitry Osipenko
2023-11-23 12:36           ` Dmitry Osipenko
2023-10-29 23:02 ` [PATCH v18 23/26] drm/virtio: Pin display framebuffer BO Dmitry Osipenko
2023-10-29 23:02   ` Dmitry Osipenko
2023-10-29 23:02 ` [PATCH v18 24/26] drm/virtio: Attach shmem BOs dynamically Dmitry Osipenko
2023-10-29 23:02   ` Dmitry Osipenko
2023-11-13  9:57   ` Boris Brezillon
2023-11-13  9:57     ` Boris Brezillon
2023-11-22 22:37     ` Dmitry Osipenko
2023-11-22 22:37       ` Dmitry Osipenko
2023-11-22 22:41       ` Dmitry Osipenko
2023-11-22 22:41         ` Dmitry Osipenko
2023-10-29 23:02 ` [PATCH v18 25/26] drm/virtio: Support shmem shrinking Dmitry Osipenko
2023-10-29 23:02   ` Dmitry Osipenko
2023-11-03 22:55   ` Gurchetan Singh
2023-11-03 22:55     ` Gurchetan Singh
2023-11-06  2:02     ` Dmitry Osipenko
2023-11-06  2:02       ` Dmitry Osipenko
2023-10-29 23:02 ` [PATCH v18 26/26] drm/panfrost: Switch to generic memory shrinker Dmitry Osipenko
2023-10-29 23:02   ` Dmitry Osipenko
2023-11-24 10:04   ` Boris Brezillon
2023-11-24 10:04     ` 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=20231123100557.05a49343@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 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.