mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Adrián Larumbe" <adrian.larumbe@collabora.com>
To: Boris Brezillon <boris.brezillon@collabora.com>,
	 Steven Price <steven.price@arm.com>,
	Liviu Dudau <liviu.dudau@arm.com>,
	 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	 Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	 David Airlie <airlied@gmail.com>,
	Simona Vetter <simona@ffwll.ch>,
	 Heiko Stuebner <heiko@sntech.de>,
	Grant Likely <grant.likely@linaro.org>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	"Adrián Larumbe" <adrian.larumbe@collabora.com>,
	Sashiko <noreply@sashiko.dev>
Subject: [PATCH v3 4/4] drm/panthor: Check for sparse binding range overflow
Date: Mon, 29 Jun 2026 21:17:08 +0100	[thread overview]
Message-ID: <20260629-vm_bind_checks-v3-4-85e6740f6c2e@collabora.com> (raw)
In-Reply-To: <20260629-vm_bind_checks-v3-0-85e6740f6c2e@collabora.com>

This check is being already carried out further down the call stack inside
drm_gpuvm_sm_map -> drm_gpuvm_range_valid, but it's best to fail early in
the driver before GPUVM functions are invoked so that we won't waste time
allocating vm_bind context resources.

Reported-by: Sashiko <noreply@sashiko.dev>
Closes: https://sashiko.dev/#/message/20260623204220.CDB1B1F000E9%40smtp.kernel.org
Fixes: 12cf826bf1dd ("drm/panthor: Support sparse mappings")
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
---
 drivers/gpu/drm/panthor/panthor_mmu.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index 77fdad4e5166..8bd9b975e5ce 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1328,6 +1328,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 	struct drm_gpuvm_bo *preallocated_vm_bo;
 	struct sg_table *sgt = NULL;
 	int ret;
+	u64 end;
 
 	if (!bo)
 		return -EINVAL;
@@ -1353,6 +1354,10 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 	if (is_sparse && (op->bo_handle || op->bo_offset))
 		return -EINVAL;
 
+	/* Protect against sparse VA range overflow */
+	if (is_sparse && check_add_overflow(op->va, op->size, &end))
+		return -EINVAL;
+
 	/* If the BO has an exclusive VM attached, it can't be mapped to other VMs. */
 	if (bo->exclusive_vm_root_gem &&
 	    bo->exclusive_vm_root_gem != panthor_vm_root_gem(vm))
@@ -1418,7 +1423,9 @@ static int panthor_vm_prepare_unmap_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 					   struct panthor_vm *vm,
 					   const struct drm_panthor_vm_bind_op *op)
 {
+	bool is_sparse = op->flags & DRM_PANTHOR_VM_BIND_OP_MAP_SPARSE;
 	u32 pt_count = 0;
+	u64 end;
 	int ret;
 
 	memset(op_ctx, 0, sizeof(*op_ctx));
@@ -1432,6 +1439,10 @@ static int panthor_vm_prepare_unmap_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 	if (op->va != ALIGN(op->va, SZ_2M))
 		pt_count++;
 
+	/* Protect against sparse VA range overflow */
+	if (is_sparse && check_add_overflow(op->va, op->size, &end))
+		return -EINVAL;
+
 	if (op->va + op->size != ALIGN(op->va + op->size, SZ_2M) &&
 	    ALIGN(op->va + op->size, SZ_2M) != ALIGN(op->va, SZ_2M))
 		pt_count++;

-- 
2.54.0


  parent reply	other threads:[~2026-06-29 20:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 20:17 [PATCH v3 0/4] Add vm_bind param check to ensure no overlap with kbo AS carveout Adrián Larumbe
2026-06-29 20:17 ` [PATCH v3 1/4] drm/panthor: Add vm_bind region with kbo range overlap check Adrián Larumbe
2026-07-03 14:00   ` Steven Price
2026-06-29 20:17 ` [PATCH v3 2/4] drm/panthor: Fix comment to reflect actual struct field name Adrián Larumbe
2026-06-29 20:17 ` [PATCH v3 3/4] drm/panthor: Have prepare_unmap_op_ctx receive a whole vm_bind op Adrián Larumbe
2026-06-29 20:17 ` Adrián Larumbe [this message]
2026-06-30  8:23   ` [PATCH v3 4/4] drm/panthor: Check for sparse binding range overflow Boris Brezillon
2026-06-30 13:01     ` Adrián Larumbe

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=20260629-vm_bind_checks-v3-4-85e6740f6c2e@collabora.com \
    --to=adrian.larumbe@collabora.com \
    --cc=airlied@gmail.com \
    --cc=boris.brezillon@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=grant.likely@linaro.org \
    --cc=heiko@sntech.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liviu.dudau@arm.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=noreply@sashiko.dev \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.com \
    --cc=tzimmermann@suse.de \
    /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

Powered by JetHome