dri-devel Archive mirror
 help / color / mirror / Atom feed
From: Liviu Dudau <liviu.dudau@arm.com>
To: Boris Brezillon <boris.brezillon@collabora.com>
Cc: "Steven Price" <steven.price@arm.com>,
	"Adrián Larumbe" <adrian.larumbe@collabora.com>,
	dri-devel@lists.freedesktop.org, kernel@collabora.com,
	"Eric Smith" <eric.smith@collabora.com>
Subject: Re: [PATCH v4 4/5] drm/panthor: Fix an off-by-one in the heap context retrieval logic
Date: Fri, 3 May 2024 11:22:03 +0100	[thread overview]
Message-ID: <ZjS6y54E8YF1lW1r@e110455-lin.cambridge.arm.com> (raw)
In-Reply-To: <20240502165158.1458959-5-boris.brezillon@collabora.com>

On Thu, May 02, 2024 at 06:51:57PM +0200, Boris Brezillon wrote:
> The heap ID is used to index the heap context pool, and allocating
> in the [1:MAX_HEAPS_PER_POOL] leads to an off-by-one. This was
> originally to avoid returning a zero heap handle, but given the handle
> is formed with (vm_id << 16) | heap_id, with vm_id > 0, we already can't
> end up with a valid heap handle that's zero.
> 
> v4:
> - s/XA_FLAGS_ALLOC1/XA_FLAGS_ALLOC/
> 
> v3:
> - Allocate in the [0:MAX_HEAPS_PER_POOL-1] range
> 
> v2:
> - New patch
> 
> Fixes: 9cca48fa4f89 ("drm/panthor: Add the heap logical block")
> Reported-by: Eric Smith <eric.smith@collabora.com>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> Tested-by: Eric Smith <eric.smith@collabora.com>

Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>

Best regards,
Liviu

> ---
>  drivers/gpu/drm/panthor/panthor_heap.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_heap.c b/drivers/gpu/drm/panthor/panthor_heap.c
> index b0fc5b9ee847..95a1c6c9f35e 100644
> --- a/drivers/gpu/drm/panthor/panthor_heap.c
> +++ b/drivers/gpu/drm/panthor/panthor_heap.c
> @@ -323,7 +323,8 @@ int panthor_heap_create(struct panthor_heap_pool *pool,
>  	if (!pool->vm) {
>  		ret = -EINVAL;
>  	} else {
> -		ret = xa_alloc(&pool->xa, &id, heap, XA_LIMIT(1, MAX_HEAPS_PER_POOL), GFP_KERNEL);
> +		ret = xa_alloc(&pool->xa, &id, heap,
> +			       XA_LIMIT(0, MAX_HEAPS_PER_POOL - 1), GFP_KERNEL);
>  		if (!ret) {
>  			void *gpu_ctx = panthor_get_heap_ctx(pool, id);
>  
> @@ -543,7 +544,7 @@ panthor_heap_pool_create(struct panthor_device *ptdev, struct panthor_vm *vm)
>  	pool->vm = vm;
>  	pool->ptdev = ptdev;
>  	init_rwsem(&pool->lock);
> -	xa_init_flags(&pool->xa, XA_FLAGS_ALLOC1);
> +	xa_init_flags(&pool->xa, XA_FLAGS_ALLOC);
>  	kref_init(&pool->refcount);
>  
>  	pool->gpu_contexts = panthor_kernel_bo_create(ptdev, vm, bosize,
> -- 
> 2.44.0
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

  parent reply	other threads:[~2024-05-03 10:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02 16:51 [PATCH v4 0/5] drm/panthor: Collection of tiler heap related fixes Boris Brezillon
2024-05-02 16:51 ` [PATCH v4 1/5] drm/panthor: Fix tiler OOM handling to allow incremental rendering Boris Brezillon
2024-05-02 16:51 ` [PATCH v4 2/5] drm/panthor: Make sure the tiler initial/max chunks are consistent Boris Brezillon
2024-05-02 16:51 ` [PATCH v4 3/5] drm/panthor: Relax the constraints on the tiler chunk size Boris Brezillon
2024-05-02 16:51 ` [PATCH v4 4/5] drm/panthor: Fix an off-by-one in the heap context retrieval logic Boris Brezillon
2024-05-03  8:26   ` Steven Price
2024-05-03 10:22   ` Liviu Dudau [this message]
2024-05-02 16:51 ` [PATCH v4 5/5] drm/panthor: Document drm_panthor_tiler_heap_destroy::handle validity constraints Boris Brezillon
2024-05-03 10:22   ` Liviu Dudau
2024-05-13 11:41 ` [PATCH v4 0/5] drm/panthor: Collection of tiler heap related fixes 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=ZjS6y54E8YF1lW1r@e110455-lin.cambridge.arm.com \
    --to=liviu.dudau@arm.com \
    --cc=adrian.larumbe@collabora.com \
    --cc=boris.brezillon@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eric.smith@collabora.com \
    --cc=kernel@collabora.com \
    --cc=steven.price@arm.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 read-only IMAP folder(s) and NNTP newsgroup(s).