Skip to contentSkip to conversation

accel/ivpu: Add support for userptr buffer objects

PATCH In review Karol Wachowski 2 participants 3 messages Oct 29, 2025 – Oct 30, 2025

Subsystems (4)
lore
Share & tools
lore

Karol Wachowski

author maintainer
#0 lore raw

PATCH v2 1/1 accel/ivpu: Add support for userptr buffer objects

From: Jacek Lawrynowicz <[email protected]>

Introduce a new ioctl drm_ivpu_bo_create_from_userptr that allows users to create GEM buffer objects from user pointers to memory regions. The user pointer must be page-aligned and the memory region must remain valid for the buffer object's lifetime.

Userptr buffers enable direct use of mmapped files (e.g. inference weights) in NPU workloads without copying data to NPU buffer objects. This reduces memory usage and provides better flexibility for NPU applications.

---
Changes in v2:
- Remove unnecessary paragraph duplicating subject in commit message
- Add paragraph explaining benefits of userptr buffers in commit message
- Remove 4GB limiation for userptr size

---
 drivers/accel/ivpu/Makefile           |   1 +
 drivers/accel/ivpu/ivpu_drv.c         |   3 +
 drivers/accel/ivpu/ivpu_gem.c         |   2 +-
 drivers/accel/ivpu/ivpu_gem.h         |   7 +
 drivers/accel/ivpu/ivpu_gem_userptr.c | 202 ++++++++++++++++++++++++++
 drivers/accel/ivpu/ivpu_mmu_context.c |   4 +-
 drivers/accel/ivpu/ivpu_mmu_context.h |   2 +-
 include/uapi/drm/ivpu_accel.h         |  52 +++++++
 8 files changed, 270 insertions(+), 3 deletions(-)
 create mode 100644 drivers/accel/ivpu/ivpu_gem_userptr.c
drivers/accel/ivpu/Makefile +1 -0
index 1029e0bab061..dbf76b8a5b4c 100644
@@ -6,6 +6,7 @@ intel_vpu-y := \
 	ivpu_fw.o \
 	ivpu_fw_log.o \
 	ivpu_gem.o \
+	ivpu_gem_userptr.o \
 	ivpu_hw.o \
 	ivpu_hw_btrs.o \
 	ivpu_hw_ip.o \
drivers/accel/ivpu/ivpu_drv.c +3 -0
index c6fe7a408912..ca68730dee88 100644
@@ -134,6 +134,8 @@ bool ivpu_is_capable(struct ivpu_device *vdev, u32 capability)
 		return true;
 	case DRM_IVPU_CAP_DMA_MEMORY_RANGE:
 		return true;
+	case DRM_IVPU_CAP_BO_CREATE_FROM_USERPTR:
+		return true;
 	case DRM_IVPU_CAP_MANAGE_CMDQ:
 		return vdev->fw->sched_mode == VPU_SCHEDULING_MODE_HW;
 	default:
@@ -313,6 +315,7 @@ static const struct drm_ioctl_desc ivpu_drm_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(IVPU_CMDQ_CREATE, ivpu_cmdq_create_ioctl, 0),
 	DRM_IOCTL_DEF_DRV(IVPU_CMDQ_DESTROY, ivpu_cmdq_destroy_ioctl, 0),
 	DRM_IOCTL_DEF_DRV(IVPU_CMDQ_SUBMIT, ivpu_cmdq_submit_ioctl, 0),
+	DRM_IOCTL_DEF_DRV(IVPU_BO_CREATE_FROM_USERPTR, ivpu_bo_create_from_userptr_ioctl, 0),
 };
 
 static int ivpu_wait_for_ready(struct ivpu_device *vdev)
drivers/accel/ivpu/ivpu_gem.c +1 -1
index e7277e02840a..9e58522840ae 100644
@@ -96,7 +96,7 @@ int __must_check ivpu_bo_bind(struct ivpu_bo *bo)
 	if (!bo->mmu_mapped) {
 		drm_WARN_ON(&vdev->drm, !bo->ctx);
 		ret = ivpu_mmu_context_map_sgt(vdev, bo->ctx, bo->vpu_addr, sgt,
-					       ivpu_bo_is_snooped(bo));
+					       ivpu_bo_is_snooped(bo), ivpu_bo_is_read_only(bo));
 		if (ret) {
 			ivpu_err(vdev, "Failed to map BO in MMU: %d\n", ret);
 			goto unlock;
drivers/accel/ivpu/ivpu_gem.h +7 -0
index 54452eb8a41f..2dcd7eba9cb7 100644
@@ -38,6 +38,8 @@ void ivpu_bo_free(struct ivpu_bo *bo);
 int ivpu_bo_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
 int ivpu_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
 int ivpu_bo_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
+int ivpu_bo_create_from_userptr_ioctl(struct drm_device *dev, void *data,
+				      struct drm_file *file);
 
 void ivpu_bo_list(struct drm_device *dev, struct drm_printer *p);
 void ivpu_bo_list_print(struct drm_device *dev);
@@ -75,6 +77,11 @@ static inline bool ivpu_bo_is_snooped(struct ivpu_bo *bo)
 	return ivpu_bo_cache_mode(bo) == DRM_IVPU_BO_CACHED;
 }
 
+static inline bool ivpu_bo_is_read_only(struct ivpu_bo *bo)
+{
+	return bo->flags & DRM_IVPU_BO_READ_ONLY;
+}
+
 static inline void *ivpu_to_cpu_addr(struct ivpu_bo *bo, u32 vpu_addr)
 {
 	if (vpu_addr < bo->vpu_addr)
drivers/accel/ivpu/ivpu_gem_userptr.c new file +202 -0

202 lines not on this page · raw message

drivers/accel/ivpu/ivpu_mmu_context.c +3 -1
index 4ffc783426be..d128e8961688 100644
@@ -430,7 +430,7 @@ static void ivpu_mmu_context_unmap_pages(struct ivpu_mmu_context *ctx, u64 vpu_a
 
 int
 ivpu_mmu_context_map_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
-			 u64 vpu_addr, struct sg_table *sgt,  bool llc_coherent)
+			 u64 vpu_addr, struct sg_table *sgt, bool llc_coherent, bool read_only)
 {
 	size_t start_vpu_addr = vpu_addr;
 	struct scatterlist *sg;
@@ -450,6 +450,8 @@ ivpu_mmu_context_map_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
 	prot = IVPU_MMU_ENTRY_MAPPED;
 	if (llc_coherent)
 		prot |= IVPU_MMU_ENTRY_FLAG_LLC_COHERENT;
+	if (read_only)
+		prot |= IVPU_MMU_ENTRY_FLAG_RO;
 
 	mutex_lock(&ctx->lock);
 
drivers/accel/ivpu/ivpu_mmu_context.h +1 -1
index f255310968cf..663a11a9db11 100644
@@ -42,7 +42,7 @@ int ivpu_mmu_context_insert_node(struct ivpu_mmu_context *ctx, const struct ivpu
 void ivpu_mmu_context_remove_node(struct ivpu_mmu_context *ctx, struct drm_mm_node *node);
 
 int ivpu_mmu_context_map_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
-			     u64 vpu_addr, struct sg_table *sgt, bool llc_coherent);
+			     u64 vpu_addr, struct sg_table *sgt, bool llc_coherent, bool read_only);
 void ivpu_mmu_context_unmap_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
 				u64 vpu_addr, struct sg_table *sgt);
 int ivpu_mmu_context_set_pages_ro(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
include/uapi/drm/ivpu_accel.h +52 -0

88 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Karol Wachowski

From: Jacek Lawrynowicz <[email protected]>

Introduce a new ioctl drm_ivpu_bo_create_from_userptr that allows users to create GEM buffer objects from user pointers to memory regions. The user pointer must be page-aligned and the memory region must remain valid for the buffer object's lifetime.

Quoted 8 lines

Userptr buffers enable direct use of mmapped files (e.g. inference weights) in NPU workloads without copying data to NPU buffer objects. This reduces memory usage and provides better flexibility for NPU applications.

author maintainer Applied
#2 lore raw
Quoted 13 lines · Jeff Hugo
Quoted 12 lines · Karol Wachowski

From: Jacek Lawrynowicz <[email protected]>

Introduce a new ioctl drm_ivpu_bo_create_from_userptr that allows users to create GEM buffer objects from user pointers to memory regions. The user pointer must be page-aligned and the memory region must remain valid for the buffer object's lifetime.

Userptr buffers enable direct use of mmapped files (e.g. inference weights) in NPU workloads without copying data to NPU buffer objects. This reduces memory usage and provides better flexibility for NPU applications.

Quoted 5 lines
Quoted 3 lines

Pushed to drm-misc-next.
-Karol