Skip to contentSkip to conversation

accel/ivpu: Improve debug and warning messages

PATCH Superseded Karol Wachowski 2 participants 3 messages Oct 28, 2025 – Nov 4, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Karol Wachowski

author maintainer
#0 lore raw

PATCH 1/1 accel/ivpu: Improve debug and warning messages

Add IOCTL debug bit for logging user provided parameter validation errors.

Refactor several warning and error messages to better reflect fault reason. User generated faults should not flood kernel messages with warnings or errors, so change those to ivpu_dbg(). Add additional debug logs for parameter validation in IOCTLs.

Check size provided by in metric streamer start and return -EINVAL together with a debug message print.

Fix ivpu_warn_ratelimited() to properly use WARN logging level instead of an ERROR.

---
 drivers/accel/ivpu/ivpu_drv.h         |  3 +-
 drivers/accel/ivpu/ivpu_gem.c         | 25 ++++---
 drivers/accel/ivpu/ivpu_gem_userptr.c | 33 +++++++---
 drivers/accel/ivpu/ivpu_job.c         | 95 ++++++++++++++++++---------
 drivers/accel/ivpu/ivpu_mmu_context.c |  3 +-
 drivers/accel/ivpu/ivpu_ms.c          | 25 ++++---
 6 files changed, 124 insertions(+), 60 deletions(-)
drivers/accel/ivpu/ivpu_drv.h +2 -1
index 98b274a8567f..1b1bf0a51ccc 100644
@@ -79,6 +79,7 @@
 #define IVPU_DBG_KREF	 BIT(11)
 #define IVPU_DBG_RPM	 BIT(12)
 #define IVPU_DBG_MMU_MAP BIT(13)
+#define IVPU_DBG_IOCTL   BIT(14)
 
 #define ivpu_err(vdev, fmt, ...) \
 	drm_err(&(vdev)->drm, "%s(): " fmt, __func__, ##__VA_ARGS__)
@@ -90,7 +91,7 @@
 	drm_warn(&(vdev)->drm, "%s(): " fmt, __func__, ##__VA_ARGS__)
 
 #define ivpu_warn_ratelimited(vdev, fmt, ...) \
-	drm_err_ratelimited(&(vdev)->drm, "%s(): " fmt, __func__, ##__VA_ARGS__)
+	__drm_printk(&(vdev)->drm, warn, _ratelimited, fmt, ##__VA_ARGS__)
 
 #define ivpu_info(vdev, fmt, ...) drm_info(&(vdev)->drm, fmt, ##__VA_ARGS__)
 
drivers/accel/ivpu/ivpu_gem.c +15 -10
index b00af1ce11aa..e46a59f19475 100644
@@ -128,8 +128,6 @@ ivpu_bo_alloc_vpu_addr(struct ivpu_bo *bo, struct ivpu_mmu_context *ctx,
 		bo->ctx_id = ctx->id;
 		bo->vpu_addr = bo->mm_node.start;
 		ivpu_dbg_bo(vdev, bo, "vaddr");
-	} else {
-		ivpu_err(vdev, "Failed to add BO to context %u: %d\n", ctx->id, ret);
 	}
 
 	ivpu_bo_unlock(bo);
@@ -292,8 +290,8 @@ static int ivpu_gem_bo_open(struct drm_gem_object *obj, struct drm_file *file)
 	struct ivpu_addr_range *range;
 
 	if (bo->ctx) {
-		ivpu_warn(vdev, "Can't add BO to ctx %u: already in ctx %u\n",
-			  file_priv->ctx.id, bo->ctx->id);
+		ivpu_dbg(vdev, IOCTL, "Can't add BO %pe to ctx %u: already in ctx %u\n",
+			 bo, file_priv->ctx.id, bo->ctx->id);
 		return -EALREADY;
 	}
 
@@ -360,15 +358,19 @@ int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *fi
 	struct ivpu_bo *bo;
 	int ret;
 
-	if (args->flags & ~DRM_IVPU_BO_FLAGS)
+	if (args->flags & ~DRM_IVPU_BO_FLAGS) {
+		ivpu_dbg(vdev, IOCTL, "Invalid BO flags 0x%x\n", args->flags);
 		return -EINVAL;
+	}
 
-	if (size == 0)
+	if (size == 0) {
+		ivpu_dbg(vdev, IOCTL, "Invalid BO size %llu\n", args->size);
 		return -EINVAL;
+	}
 
 	bo = ivpu_bo_alloc(vdev, size, args->flags);
 	if (IS_ERR(bo)) {
-		ivpu_err(vdev, "Failed to allocate BO: %pe (ctx %u size %llu flags 0x%x)",
+		ivpu_dbg(vdev, IOCTL, "Failed to allocate BO: %pe ctx %u size %llu flags 0x%x\n",
 			 bo, file_priv->ctx.id, args->size, args->flags);
 		return PTR_ERR(bo);
 	}
@@ -377,7 +379,7 @@ int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *fi
 
 	ret = drm_gem_handle_create(file, &bo->base.base, &args->handle);
 	if (ret) {
-		ivpu_err(vdev, "Failed to create handle for BO: %pe (ctx %u size %llu flags 0x%x)",
+		ivpu_err(vdev, "Failed to create handle for BO: %pe ctx %u size %llu flags 0x%x\n",
 			 bo, file_priv->ctx.id, args->size, args->flags);
 	} else {
 		args->vpu_addr = bo->vpu_addr;
@@ -406,14 +408,17 @@ ivpu_bo_create(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
 
 	bo = ivpu_bo_alloc(vdev, size, flags);
 	if (IS_ERR(bo)) {
-		ivpu_err(vdev, "Failed to allocate BO: %pe (vpu_addr 0x%llx size %llu flags 0x%x)",
+		ivpu_err(vdev, "Failed to allocate BO: %pe vpu_addr 0x%llx size %llu flags 0x%x\n",
 			 bo, range->start, size, flags);
 		return NULL;
 	}
 
 	ret = ivpu_bo_alloc_vpu_addr(bo, ctx, range);
-	if (ret)
+	if (ret) {
+		ivpu_err(vdev, "Failed to allocate NPU address for BO: %pe ctx %u size %llu: %d\n",
+			 bo, ctx->id, size, ret);
 		goto err_put;
+	}
 
 	ret = ivpu_bo_bind(bo);
 	if (ret)
drivers/accel/ivpu/ivpu_gem_userptr.c +23 -10
index c5b64e0f2b13..80b316e8d685 100644
@@ -86,12 +86,12 @@ ivpu_create_userptr_dmabuf(struct ivpu_device *vdev, void __user *user_ptr,
 	pinned = pin_user_pages_fast((unsigned long)user_ptr, nr_pages, gup_flags, pages);
 	if (pinned < 0) {
 		ret = pinned;
-		ivpu_warn(vdev, "Failed to pin user pages: %d\n", ret);
+		ivpu_warn_ratelimited(vdev, "Failed to pin user pages: %d\n", ret);
 		goto free_pages_array;
 	}
 
 	if (pinned != nr_pages) {
-		ivpu_warn(vdev, "Pinned %d pages, expected %lu\n", pinned, nr_pages);
+		ivpu_warn_ratelimited(vdev, "Pinned %d pages, expected %lu\n", pinned, nr_pages);
 		ret = -EFAULT;
 		goto unpin_pages;
 	}
@@ -104,7 +104,7 @@ ivpu_create_userptr_dmabuf(struct ivpu_device *vdev, void __user *user_ptr,
 
 	ret = sg_alloc_table_from_pages(sgt, pages, nr_pages, 0, size, GFP_KERNEL);
 	if (ret) {
-		ivpu_warn(vdev, "Failed to create sg table: %d\n", ret);
+		ivpu_warn_ratelimited(vdev, "Failed to create sg table: %d\n", ret);
 		goto free_sgt;
 	}
 
@@ -118,7 +118,7 @@ ivpu_create_userptr_dmabuf(struct ivpu_device *vdev, void __user *user_ptr,
 	dma_buf = dma_buf_export(&exp_info);
 	if (IS_ERR(dma_buf)) {
 		ret = PTR_ERR(dma_buf);
-		ivpu_warn(vdev, "Failed to export userptr dma-buf: %d\n", ret);
+		ivpu_warn_ratelimited(vdev, "Failed to export userptr dma-buf: %d\n", ret);
 		goto free_sg_table;
 	}
 
@@ -172,20 +172,33 @@ int ivpu_bo_create_from_userptr_ioctl(struct drm_device *dev, void *data, struct
 	struct ivpu_bo *bo;
 	int ret;
 
-	if (args->flags & ~(DRM_IVPU_BO_HIGH_MEM | DRM_IVPU_BO_DMA_MEM | DRM_IVPU_BO_READ_ONLY))
+	if (args->flags & ~(DRM_IVPU_BO_HIGH_MEM | DRM_IVPU_BO_DMA_MEM | DRM_IVPU_BO_READ_ONLY)) {
+		ivpu_dbg(vdev, IOCTL, "Invalid BO flags: 0x%x\n", args->flags);
 		return -EINVAL;
+	}
 
-	if (!args->user_ptr || !args->size)
+	if (!args->user_ptr || !args->size) {
+		ivpu_dbg(vdev, IOCTL, "Userptr or size are zero: ptr %llx size %llu\n",
+			 args->user_ptr, args->size);
 		return -EINVAL;
+	}
 
-	if (args->size > IVPU_BO_USERPTR_MAX_SIZE)
+	if (args->size > IVPU_BO_USERPTR_MAX_SIZE) {
+		ivpu_dbg(vdev, IOCTL, "Userptr size too large: %llu\n", args->size);
 		return -EINVAL;
+	}
 
-	if (!PAGE_ALIGNED(args->user_ptr) || !PAGE_ALIGNED(args->size))
+	if (!PAGE_ALIGNED(args->user_ptr) || !PAGE_ALIGNED(args->size)) {
+		ivpu_dbg(vdev, IOCTL, "Userptr or size not page aligned: ptr %llx size %llu\n",
+			 args->user_ptr, args->size);
 		return -EINVAL;
+	}
 
-	if (!access_ok(user_ptr, args->size))
+	if (!access_ok(user_ptr, args->size)) {
+		ivpu_dbg(vdev, IOCTL, "Userptr is not accessible: ptr %llx size %llu\n",
+			 args->user_ptr, args->size);
 		return -EFAULT;
+	}
 
 	bo = ivpu_bo_create_from_userptr(vdev, user_ptr, args->size, args->flags);
 	if (IS_ERR(bo))
@@ -193,7 +206,7 @@ int ivpu_bo_create_from_userptr_ioctl(struct drm_device *dev, void *data, struct
 
 	ret = drm_gem_handle_create(file, &bo->base.base, &args->handle);
 	if (ret) {
-		ivpu_err(vdev, "Failed to create handle for BO: %pe (ctx %u size %llu flags 0x%x)",
+		ivpu_err(vdev, "Failed to create handle for BO: %pe ctx %u size %llu flags 0x%x\n",
 			 bo, file_priv->ctx.id, args->size, args->flags);
 	} else {
 		ivpu_dbg(vdev, BO, "Created userptr BO: handle=%u vpu_addr=0x%llx size=%llu flags=0x%x\n",
drivers/accel/ivpu/ivpu_job.c +65 -30

221 lines not on this page · raw message

drivers/accel/ivpu/ivpu_mmu_context.c +2 -1
index d128e8961688..87ad593ef47d 100644
@@ -529,7 +529,8 @@ ivpu_mmu_context_unmap_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ct
 
 	ret = ivpu_mmu_invalidate_tlb(vdev, ctx->id);
 	if (ret)
-		ivpu_warn(vdev, "Failed to invalidate TLB for ctx %u: %d\n", ctx->id, ret);
+		ivpu_warn_ratelimited(vdev, "Failed to invalidate TLB for ctx %u: %d\n",
+				      ctx->id, ret);
 }
 
 int
drivers/accel/ivpu/ivpu_ms.c +17 -8
index 2a043baf10ca..562820dc9b90 100644
@@ -8,6 +8,7 @@
 
 #include "ivpu_drv.h"
 #include "ivpu_gem.h"
+#include "ivpu_hw.h"
 #include "ivpu_jsm_msg.h"
 #include "ivpu_ms.h"
 #include "ivpu_pm.h"
@@ -37,8 +38,8 @@ int ivpu_ms_start_ioctl(struct drm_device *dev, void *data, struct drm_file *fil
 	struct drm_ivpu_metric_streamer_start *args = data;
 	struct ivpu_device *vdev = file_priv->vdev;
 	struct ivpu_ms_instance *ms;
-	u64 single_buff_size;
 	u32 sample_size;
+	u64 buf_size;
 	int ret;
 
 	if (!args->metric_group_mask || !args->read_period_samples ||
@@ -52,7 +53,8 @@ int ivpu_ms_start_ioctl(struct drm_device *dev, void *data, struct drm_file *fil
 	mutex_lock(&file_priv->ms_lock);
 
 	if (get_instance_by_mask(file_priv, args->metric_group_mask)) {
-		ivpu_err(vdev, "Instance already exists (mask %#llx)\n", args->metric_group_mask);
+		ivpu_dbg(vdev, IOCTL, "Instance already exists (mask %#llx)\n",
+			 args->metric_group_mask);
 		ret = -EALREADY;
 		goto unlock;
 	}
@@ -69,12 +71,18 @@ int ivpu_ms_start_ioctl(struct drm_device *dev, void *data, struct drm_file *fil
 	if (ret)
 		goto err_free_ms;
 
-	single_buff_size = sample_size *
-		((u64)args->read_period_samples * MS_READ_PERIOD_MULTIPLIER);
-	ms->bo = ivpu_bo_create_global(vdev, PAGE_ALIGN(single_buff_size * MS_NUM_BUFFERS),
-				       DRM_IVPU_BO_CACHED | DRM_IVPU_BO_MAPPABLE);
+	buf_size = PAGE_ALIGN((u64)args->read_period_samples * sample_size *
+			      MS_READ_PERIOD_MULTIPLIER * MS_NUM_BUFFERS);
+	if (buf_size > ivpu_hw_range_size(&vdev->hw->ranges.global)) {
+		ivpu_dbg(vdev, IOCTL, "Requested MS buffer size %llu exceeds range size %llu\n",
+			 buf_size, ivpu_hw_range_size(&vdev->hw->ranges.global));
+		ret = -EINVAL;
+		goto err_free_ms;
+	}
+
+	ms->bo = ivpu_bo_create_global(vdev, buf_size, DRM_IVPU_BO_CACHED | DRM_IVPU_BO_MAPPABLE);
 	if (!ms->bo) {
-		ivpu_err(vdev, "Failed to allocate MS buffer (size %llu)\n", single_buff_size);
+		ivpu_err(vdev, "Failed to allocate MS buffer (size %llu)\n", buf_size);
 		ret = -ENOMEM;
 		goto err_free_ms;
 	}
@@ -175,7 +183,8 @@ int ivpu_ms_get_data_ioctl(struct drm_device *dev, void *data, struct drm_file *
 
 	ms = get_instance_by_mask(file_priv, args->metric_group_mask);
 	if (!ms) {
-		ivpu_err(vdev, "Instance doesn't exist for mask: %#llx\n", args->metric_group_mask);
+		ivpu_dbg(vdev, IOCTL, "Instance doesn't exist for mask: %#llx\n",
+			 args->metric_group_mask);
 		ret = -EINVAL;
 		goto unlock;
 	}
Signature · 1 line
2.43.0
#1 lore raw

drivers/accel/ivpu/ivpu_gem.c int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *fi · line 383

Quoted 7 lines · Karol Wachowski
drivers/accel/ivpu/ivpu_gem.c +1 -1
@@ -377,7 +379,7 @@ int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *fi
 
  	ret = drm_gem_handle_create(file, &bo->base.base, &args->handle);
  	if (ret) {
-		ivpu_err(vdev, "Failed to create handle for BO: %pe (ctx %u size %llu flags 0x%x)",
+		ivpu_err(vdev, "Failed to create handle for BO: %pe ctx %u size %llu flags 0x%x\n",
  			 bo, file_priv->ctx.id, args->size, args->flags);

This looks like it could be triggered by a user (in an ioctl, and in this case the user could exhaust the handle space), so this should be changed to a debug message per the commit text, no?

drivers/accel/ivpu/ivpu_gem.c ivpu_bo_create(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx, · line 412

Quoted 9 lines
drivers/accel/ivpu/ivpu_gem.c +1 -1
  	} else {
  		args->vpu_addr = bo->vpu_addr;
@@ -406,14 +408,17 @@ ivpu_bo_create(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
 
  	bo = ivpu_bo_alloc(vdev, size, flags);
  	if (IS_ERR(bo)) {
-		ivpu_err(vdev, "Failed to allocate BO: %pe (vpu_addr 0x%llx size %llu flags 0x%x)",
+		ivpu_err(vdev, "Failed to allocate BO: %pe vpu_addr 0x%llx size %llu flags 0x%x\n",
  			 bo, range->start, size, flags);

Another possible debug message?

drivers/accel/ivpu/ivpu_gem.c ivpu_bo_create(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx, · line 419

Quoted 8 lines
drivers/accel/ivpu/ivpu_gem.c +3 -1
  		return NULL;
  	}
 
  	ret = ivpu_bo_alloc_vpu_addr(bo, ctx, range);
-	if (ret)
+	if (ret) {
+		ivpu_err(vdev, "Failed to allocate NPU address for BO: %pe ctx %u size %llu: %d\n",
+			 bo, ctx->id, size, ret);

Another possible debug message?

drivers/accel/ivpu/ivpu_gem.c int ivpu_bo_create_from_userptr_ioctl(struct drm_device *dev, void *data, struct · line 210

Quoted 12 lines
drivers/accel/ivpu/ivpu_gem.c +2 -1
  		goto err_put;
+	}
 
  	ret = ivpu_bo_bind(bo);
  	if (ret)
@@ -193,7 +206,7 @@ int ivpu_bo_create_from_userptr_ioctl(struct drm_device *dev, void *data, struct
 
  	ret = drm_gem_handle_create(file, &bo->base.base, &args->handle);
  	if (ret) {
-		ivpu_err(vdev, "Failed to create handle for BO: %pe (ctx %u size %llu flags 0x%x)",
+		ivpu_err(vdev, "Failed to create handle for BO: %pe ctx %u size %llu flags 0x%x\n",
  			 bo, file_priv->ctx.id, args->size, args->flags);

Another possible debug message?

Quoted 13 lines
drivers/accel/ivpu/ivpu_gem_userptr.c +3 -4
  	} else {
  		ivpu_dbg(vdev, BO, "Created userptr BO: handle=%u vpu_addr=0x%llx size=%llu flags=0x%x\n",
@@ -69,12 +71,18 @@ int ivpu_ms_start_ioctl(struct drm_device *dev, void *data, struct drm_file *fil
  	if (ret)
  		goto err_free_ms;
 
-	single_buff_size = sample_size *
-		((u64)args->read_period_samples * MS_READ_PERIOD_MULTIPLIER);
-	ms->bo = ivpu_bo_create_global(vdev, PAGE_ALIGN(single_buff_size * MS_NUM_BUFFERS),
-				       DRM_IVPU_BO_CACHED | DRM_IVPU_BO_MAPPABLE);
+	buf_size = PAGE_ALIGN((u64)args->read_period_samples * sample_size *
+			      MS_READ_PERIOD_MULTIPLIER * MS_NUM_BUFFERS);
+	if (buf_size > ivpu_hw_range_size(&vdev->hw->ranges.global)) {

drivers/accel/ivpu/ivpu_gem_userptr.c int ivpu_ms_start_ioctl(struct drm_device *dev, void *data, struct drm_file *fil · line 85

Quoted 10 lines
drivers/accel/ivpu/ivpu_gem_userptr.c +8 -1
+		ivpu_dbg(vdev, IOCTL, "Requested MS buffer size %llu exceeds range size %llu\n",
+			 buf_size, ivpu_hw_range_size(&vdev->hw->ranges.global));
+		ret = -EINVAL;
+		goto err_free_ms;
+	}
+
+	ms->bo = ivpu_bo_create_global(vdev, buf_size, DRM_IVPU_BO_CACHED | DRM_IVPU_BO_MAPPABLE);
  	if (!ms->bo) {
-		ivpu_err(vdev, "Failed to allocate MS buffer (size %llu)\n", single_buff_size);
+		ivpu_err(vdev, "Failed to allocate MS buffer (size %llu)\n", buf_size);

Another possible debug message?

Quoted 3 lines
drivers/accel/ivpu/ivpu_ms.c +0 -0
  		ret = -ENOMEM;
  		goto err_free_ms;
  	}
author maintainer
#2 lore raw
Quoted 15 lines · Jeff Hugo
Quoted 10 lines · Karol Wachowski
(quoted diff) +0 -0
@@ -377,7 +379,7 @@ int ivpu_bo_create_ioctl(struct drm_device *dev,

void *data, struct drm_file *fi
        ret = drm_gem_handle_create(file, &bo->base.base, &args->handle);
      if (ret) {
-        ivpu_err(vdev, "Failed to create handle for BO: %pe (ctx %u size %llu flags 0x%x)",
+        ivpu_err(vdev, "Failed to create handle for BO: %pe ctx %u size %llu flags 0x%x\n",
               bo, file_priv->ctx.id, args->size, args->flags);

This looks like it could be triggered by a user (in an ioctl, and in this case the user could exhaust the handle space), so this should be changed to a debug message per the commit text, no?

I agree that this one can be changed to debug. I will send new version of the patch.

Quoted 14 lines

Review ivpu_bo_create(struct ivpu_device *vdev, struct · line 414

Quoted 12 lines

      } else {
          args->vpu_addr = bo->vpu_addr;

(quoted diff) +1 -1
@@ -406,14 +408,17 @@ ivpu_bo_create(struct ivpu_device *vdev, struct
 ivpu_mmu_context *ctx,
         bo = ivpu_bo_alloc(vdev, size, flags);
       if (IS_ERR(bo)) {
-        ivpu_err(vdev, "Failed to allocate BO: %pe (vpu_addr 0x%llx
 size %llu flags 0x%x)",
+        ivpu_err(vdev, "Failed to allocate BO: %pe vpu_addr 0x%llx
 size %llu flags 0x%x\n",
                bo, range->start, size, flags);

Another possible debug message?

ivpu_bo_create() is only used by internal driver's allocations, I want those to emit error messages. User cannot trigger these. So this should stay error.

Quoted 11 lines

drivers/accel/ivpu/ivpu_gem.c ivpu_bo_create(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx, · line 419

Quoted 9 lines
drivers/accel/ivpu/ivpu_gem.c +3 -1
           return NULL;
       }
         ret = ivpu_bo_alloc_vpu_addr(bo, ctx, range);
-    if (ret)
+    if (ret) {
+        ivpu_err(vdev, "Failed to allocate NPU address for BO: %pe
 ctx %u size %llu: %d\n",
+             bo, ctx->id, size, ret);

Another possible debug message?

Same here, this one is specifically called by ivpu_bo_create(). There's another one in IOCTL and that one prints debug message only.

Quoted 17 lines
Quoted 7 lines
drivers/accel/ivpu/ivpu_gem.c +1 -0
           goto err_put;
+    }
         ret = ivpu_bo_bind(bo);

      if (ret)

(quoted diff) +0 -0
@@ -193,7 +206,7 @@ int ivpu_bo_create_from_userptr_ioctl(struct

drm_device *dev, void *data, struct

Quoted 8 lines

        ret = drm_gem_handle_create(file, &bo->base.base, &args->handle);
      if (ret) {
-        ivpu_err(vdev, "Failed to create handle for BO: %pe (ctx %u size %llu flags 0x%x)",
+        ivpu_err(vdev, "Failed to create handle for BO: %pe ctx %u size %llu flags 0x%x\n",
               bo, file_priv->ctx.id, args->size, args->flags);

Another possible debug message?

Similar to the first one, I will change this to debug.

Quoted 25 lines
Quoted 25 lines

      } else {
          ivpu_dbg(vdev, BO, "Created userptr BO: handle=%u vpu_addr=0x%llx size=%llu flags=0x%x\n",

(quoted diff) +0 -0
@@ -69,12 +71,18 @@ int ivpu_ms_start_ioctl(struct drm_device *dev,

void *data, struct drm_file *fil
      if (ret)
          goto err_free_ms;
  -    single_buff_size = sample_size *
-        ((u64)args->read_period_samples * MS_READ_PERIOD_MULTIPLIER); -    ms->bo = ivpu_bo_create_global(vdev, PAGE_ALIGN(single_buff_size
* MS_NUM_BUFFERS),
-                       DRM_IVPU_BO_CACHED | DRM_IVPU_BO_MAPPABLE); +    buf_size = PAGE_ALIGN((u64)args->read_period_samples * sample_size *
+                  MS_READ_PERIOD_MULTIPLIER * MS_NUM_BUFFERS); +    if (buf_size > ivpu_hw_range_size(&vdev->hw->ranges.global)) { +        ivpu_dbg(vdev, IOCTL, "Requested MS buffer size %llu exceeds range size %llu\n",
+             buf_size, ivpu_hw_range_size(&vdev->hw->ranges.global)); +        ret = -EINVAL;
+        goto err_free_ms;
+    }
+
+    ms->bo = ivpu_bo_create_global(vdev, buf_size,

Quoted 8 lines
Quoted 6 lines

DRM_IVPU_BO_CACHED | DRM_IVPU_BO_MAPPABLE);
      if (!ms->bo) {
-        ivpu_err(vdev, "Failed to allocate MS buffer (size %llu)\n", single_buff_size);
+        ivpu_err(vdev, "Failed to allocate MS buffer (size %llu)\n", buf_size);

Another possible debug message?

Yes, I think this one also could be debug instead. It can be triggered by user.

Quoted 4 lines
Quoted 4 lines

          ret = -ENOMEM;
          goto err_free_ms;
      }

I've sent v2 version of the patch with those concerns addressed. Thank you for your insights, as usual.
- Karol