All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Brajesh Gupta" <brajesh.gupta@imgtec.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 2/2] drm/imagination: Fix page count for page table for map() interface
Date: Tue, 22 Sep 2026 04:41:15 +0000	[thread overview]
Message-ID: <20260922044116.3F6AD1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260922-mmu_fix-v4-2-12f1a871456a@imgtec.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/imagination: under-allocation of page tables due to incorrect start_addr computation
--

commit 2406b8d6a0a1f7f5c8f27c8165d80a69f8753892
Author: Brajesh Gupta <brajesh.gupta@imgtec.com>

drm/imagination: Fix page count for page table for map() interface

This patch updates pvr_mmu_op_context_create() to accept a device address
and includes it in the page table count calculations for the map()
interface. This aims to fix mapping failures that occurred when the virtual
start address was omitted.

> diff --git a/drivers/gpu/drm/imagination/pvr_mmu.c b/drivers/gpu/drm/imagination/pvr_mmu.c
> --- a/drivers/gpu/drm/imagination/pvr_mmu.c
> +++ b/drivers/gpu/drm/imagination/pvr_mmu.c

[ ... ]

> @@ -2347,8 +2348,9 @@ void pvr_mmu_op_context_destroy(struct pvr_mmu_op_context *op_ctx)
>   */
>  struct pvr_mmu_op_context *
>  pvr_mmu_op_context_create(struct pvr_mmu_context *ctx, struct sg_table *sgt,
> -			  u64 sgt_offset, u64 size)
> +			  u64 device_addr, u64 sgt_offset, u64 size)
>  {
> +	u64 start_addr = device_addr + sgt_offset;

[Severity: High]
Since device_addr is the virtual address where the mapping starts, and
sgt_offset is the physical offset within the backing buffer object, does
adding the physical offset to the virtual address incorrectly shift the
preallocation start address here?

>  	int err;
>  
>  	struct pvr_mmu_op_context *op_ctx = kzalloc_obj(*op_ctx);
> @@ -2364,16 +2366,16 @@ pvr_mmu_op_context_create(struct pvr_mmu_context *ctx, struct sg_table *sgt,
>  	if (size) {
>  		/*
>  		 * The number of page table objects we need to prealloc is
> -		 * indicated by the mapping size, start offset and the sizes
> +		 * indicated by the mapping size, start address and the sizes
>  		 * of the areas mapped per PT or PD. The range calculation is
>  		 * identical to that for the index into a table for a device
>  		 * address, so we reuse those functions here.
>  		 */
> -		const u32 l1_start_idx = pvr_page_table_l2_idx(sgt_offset);
> -		const u32 l1_end_idx = pvr_page_table_l2_idx(sgt_offset + size);
> +		const u32 l1_start_idx = pvr_page_table_l2_idx(start_addr);
> +		const u32 l1_end_idx = pvr_page_table_l2_idx(start_addr + size);
>  		const u32 l1_count = l1_end_idx - l1_start_idx + 1;
> -		const u32 l0_start_idx = pvr_page_table_l1_idx(sgt_offset);
> -		const u32 l0_end_idx = pvr_page_table_l1_idx(sgt_offset + size);
> +		const u32 l0_start_idx = pvr_page_table_l1_idx(start_addr);
> +		const u32 l0_end_idx = pvr_page_table_l1_idx(start_addr + size);

[Severity: High]
By using this shifted start_addr, could we under-allocate page tables if the
actual virtual mapping from device_addr to device_addr + size crosses a page
table boundary (like a 2MB L0 block), but the incorrectly shifted start_addr
range does not?

If we preallocate fewer tables than needed, pvr_page_table_l0_get_or_insert()
might fail to pop from the empty preallocation list during pvr_mmu_map() and
return -ENOMEM, causing valid user mapping requests to unpredictably fail.

>  		const u32 l0_count = l0_end_idx - l0_start_idx + 1;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260922-mmu_fix-v4-0-12f1a871456a@imgtec.com?part=2

  reply	other threads:[~2026-09-22  4:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  4:26 [PATCH v4 0/2] Fixes for map() path Brajesh Gupta
2026-09-22  4:26 ` [PATCH v4 1/2] drm/imagination: Propagate map failures correctly from pvr_mmu_map_sgl() Brajesh Gupta
2026-09-22  4:26 ` [PATCH v4 2/2] drm/imagination: Fix page count for page table for map() interface Brajesh Gupta
2026-09-22  4:41   ` sashiko-bot [this message]
2026-09-24  9:39 ` [PATCH v4 0/2] Fixes for map() path Brajesh Gupta

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=20260922044116.3F6AD1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=brajesh.gupta@imgtec.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.