dri-devel Archive on 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 v3 2/2] drm/imagination: Fix page count for page table for map() interface
Date: Fri, 18 Sep 2026 11:14:24 +0000	[thread overview]
Message-ID: <20260918111425.3F2FD1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260918-mmu_fix-v3-2-7b3d73aef041@imgtec.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/imagination: map failure due to incorrect page table preallocation
--

commit 745ba10b948681b4d3d12138bed64dc2fbad043c
Author: Brajesh Gupta <brajesh.gupta@imgtec.com>

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

This commit aims to fix the page count calculation for mapping a buffer object
by including the GPU virtual start address. It updates the
pvr_mmu_op_context_create function to accept the device address and uses it
to compute the required page table memory.

> diff --git a/drivers/gpu/drm/imagination/pvr_mmu.c b/drivers/gpu/drm/imagination/pvr_mmu.c
> index 23261d9ad3fdd..62eae7fcd5a26 100644
> --- 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]
Does this computation incorrectly add the physical buffer offset (sgt_offset)
to the virtual device address (device_addr)?

It appears that shifting the address window this way can lead to
under-allocation of page tables. For instance, if a user-space application
maps a memory region where the true virtual address range from device_addr
to device_addr + size crosses more page directory boundaries than the
shifted range (start_addr to start_addr + size), the preallocation will
fall short.

As an example, if L0 tables cover 2MB (0x200000), and we have
device_addr = 0x1FF000, size = 0x2000, and sgt_offset = 0x1000: the actual
mapping touches both 0x1FF000 and 0x200000, requiring two L0 tables. However,
start_addr becomes 0x200000, causing the logic to preallocate only one
L0 table. Later, when pvr_mmu_map executes, it could fail to retrieve the
second table from the preallocated list and return -ENOMEM.

Could this result in unprivileged user-space clients experiencing random map
failures depending on the buffer offset?

>  	int err;
>  
>  	struct pvr_mmu_op_context *op_ctx = kzalloc_obj(*op_ctx);
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260918-mmu_fix-v3-0-7b3d73aef041@imgtec.com?part=2

  reply	other threads:[~2026-09-18 11:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 10:41 [PATCH v3 0/2] Fixes for map() path Brajesh Gupta
2026-09-18 10:41 ` [PATCH v3 1/2] drm/imagination: Propagate map failures correctly from pvr_mmu_map_sgl() Brajesh Gupta
2026-09-18 10:41 ` [PATCH v3 2/2] drm/imagination: Fix page count for page table for map() interface Brajesh Gupta
2026-09-18 11:14   ` sashiko-bot [this message]
2026-09-21 16:57   ` Alessio Belle

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=20260918111425.3F2FD1F000FF@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox