Skip to contentSkip to conversation

drm/msm: fix msm_gem_vma_new() allocations for managed GPUVMs

PATCH Applied Dmitry Baryshkov 3 participants 7 messages Aug 23, 2025 – Aug 25, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/msm: fix msm_gem_vma_new() allocations for managed GPUVMs

Since commit 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()") MSM driver fails to init, failing with "[drm:msm_gpu_init] *ERROR* could not allocate memptrs: -22" errors. The mentioned commit reworked the function, but didn't take into account that op_map is initialized at the top of the function, while ranges might change if GPUVM is managed by the kernel.

Move op_mode initialization after finalizing all addresses and right before the drm_gpuva_init_from_op() call.

Fixes 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()")
---
 drivers/gpu/drm/msm/msm_gem_vma.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/msm/msm_gem_vma.c +7 -6
index 3f440bc1f7106f3b0091f037611d0b433e5e2c18..6df6b7c0984da57fe64de41fa54f7dea0a324c74 100644
@@ -368,12 +368,6 @@ struct drm_gpuva *
 msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj,
 		u64 offset, u64 range_start, u64 range_end)
 {
-	struct drm_gpuva_op_map op_map = {
-		.va.addr = range_start,
-		.va.range = range_end - range_start,
-		.gem.obj = obj,
-		.gem.offset = offset,
-	};
 	struct msm_gem_vm *vm = to_msm_vm(gpuvm);
 	struct drm_gpuvm_bo *vm_bo;
 	struct msm_gem_vma *vma;
@@ -402,6 +396,13 @@ msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj,
 	if (obj)
 		GEM_WARN_ON((range_end - range_start) > obj->size);
 
+	struct drm_gpuva_op_map op_map = {
+		.va.addr = range_start,
+		.va.range = range_end - range_start,
+		.gem.obj = obj,
+		.gem.offset = offset,
+	};
+
 	drm_gpuva_init_from_op(&vma->base, &op_map);
 	vma->mapped = false;
 

---
base-commit: 0f4c93f7eb861acab537dbe94441817a270537bf
change-id: 20250823-msm-fix-gpuvm-init-520d87ebcf26

Best regards,

Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v1 1/1
#1 lore raw
Quoted 37 lines · Dmitry Baryshkov

Since commit 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()") MSM driver fails to init, failing with "[drm:msm_gpu_init] *ERROR* could not allocate memptrs: -22" errors. The mentioned commit reworked the function, but didn't take into account that op_map is initialized at the top of the function, while ranges might change if GPUVM is managed by the kernel.

Move op_mode initialization after finalizing all addresses and right before the drm_gpuva_init_from_op() call.

Fixes 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()")
---
 drivers/gpu/drm/msm/msm_gem_vma.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/msm/msm_gem_vma.c +0 -6
index 3f440bc1f7106f3b0091f037611d0b433e5e2c18..6df6b7c0984da57fe64de41fa54f7dea0a324c74 100644
@@ -368,12 +368,6 @@ struct drm_gpuva *
 msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj,
                u64 offset, u64 range_start, u64 range_end)
 {
-       struct drm_gpuva_op_map op_map = {
-               .va.addr = range_start,
-               .va.range = range_end - range_start,
-               .gem.obj = obj,
-               .gem.offset = offset,
-       };
        struct msm_gem_vm *vm = to_msm_vm(gpuvm);
        struct drm_gpuvm_bo *vm_bo;
        struct msm_gem_vma *vma;

drivers/gpu/drm/msm/msm_gem_vma.c msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj, · line 404

Quoted 9 lines
drivers/gpu/drm/msm/msm_gem_vma.c +6 -0
@@ -402,6 +396,13 @@ msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj,
        if (obj)
                GEM_WARN_ON((range_end - range_start) > obj->size);
 
+       struct drm_gpuva_op_map op_map = {
+               .va.addr = range_start,
+               .va.range = range_end - range_start,
+               .gem.obj = obj,
+               .gem.offset = offset,
+       };

Thanks,

Quoted 14 lines
drivers/gpu/drm/msm/msm_gem_vma.c +1 -1
+
        drm_gpuva_init_from_op(&vma->base, &op_map);
        vma->mapped = false;
 
 
---

base-commit: 0f4c93f7eb861acab537dbe94441817a270537bf
change-id: 20250823-msm-fix-gpuvm-init-520d87ebcf26

Best regards,
--
With best wishes
Dmitry

#2 lore raw
Quoted 22 lines · Rob Clark
Quoted 11 lines · Dmitry Baryshkov

Since commit 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()") MSM driver fails to init, failing with "[drm:msm_gpu_init] *ERROR* could not allocate memptrs: -22" errors. The mentioned commit reworked the function, but didn't take into account that op_map is initialized at the top of the function, while ranges might change if GPUVM is managed by the kernel.

Move op_mode initialization after finalizing all addresses and right before the drm_gpuva_init_from_op() call.

Quoted 8 lines
Fixes 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()")
---
 drivers/gpu/drm/msm/msm_gem_vma.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Quoted 3 lines

Thanks,

I'll also need Acked-by to merge through drm-misc-next, where the offending commit is.

Signature · 2 lines
With best wishes
Dmitry
Acked-by
#3 lore raw
Quoted 24 lines · Dmitry Baryshkov
Quoted 22 lines · Rob Clark
Quoted 19 lines · Dmitry Baryshkov

Since commit 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()") MSM driver fails to init, failing with "[drm:msm_gpu_init] *ERROR* could not allocate memptrs: -22" errors. The mentioned commit reworked the function, but didn't take into account that op_map is initialized at the top of the function, while ranges might change if GPUVM is managed by the kernel.

Move op_mode initialization after finalizing all addresses and right before the drm_gpuva_init_from_op() call.

Fixes 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()")
---
 drivers/gpu/drm/msm/msm_gem_vma.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Quoted 7 lines
Quoted 3 lines

Thanks,

I'll also need Acked-by to merge through drm-misc-next, where the offending commit is.

Quoted 4 lines

--
With best wishes
Dmitry

author Applied
#4 lore raw
In reply to Dmitry Baryshkov
Quoted 8 lines · Dmitry Baryshkov

Since commit 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()") MSM driver fails to init, failing with "[drm:msm_gpu_init] *ERROR* could not allocate memptrs: -22" errors. The mentioned commit reworked the function, but didn't take into account that op_map is initialized at the top of the function, while ranges might change if GPUVM is managed by the kernel.

[...]

Applied to drm-misc-next, thanks!

[1/1] drm/msm: fix msm_gem_vma_new() allocations for managed GPUVMs

      commit: efe927b9702643a1d80472664c2642f0304cb608

Best regards,

Signature · 2 lines
With best wishes
Dmitry
#5 lore raw
In reply to Dmitry Baryshkov
Quoted 36 lines · On Sat, 23 Aug 2025 03:12:00 +0300 Dmitry Baryshkov…

Since commit 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()") MSM driver fails to init, failing with "[drm:msm_gpu_init] *ERROR* could not allocate memptrs: -22" errors. The mentioned commit reworked the function, but didn't take into account that op_map is initialized at the top of the function, while ranges might change if GPUVM is managed by the kernel.

Move op_mode initialization after finalizing all addresses and right before the drm_gpuva_init_from_op() call.

Fixes 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()")
---
 drivers/gpu/drm/msm/msm_gem_vma.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/msm/msm_gem_vma.c +0 -6
index 3f440bc1f7106f3b0091f037611d0b433e5e2c18..6df6b7c0984da57fe64de41fa54f7dea0a324c74 100644
@@ -368,12 +368,6 @@ struct drm_gpuva *
 msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj,
 		u64 offset, u64 range_start, u64 range_end)
 {
-	struct drm_gpuva_op_map op_map = {
-		.va.addr = range_start,
-		.va.range = range_end - range_start,
-		.gem.obj = obj,
-		.gem.offset = offset,
-	};
 	struct msm_gem_vm *vm = to_msm_vm(gpuvm);
 	struct drm_gpuvm_bo *vm_bo;
 	struct msm_gem_vma *vma;

drivers/gpu/drm/msm/msm_gem_vma.c msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj, · line 404

Quoted 9 lines
drivers/gpu/drm/msm/msm_gem_vma.c +6 -0
@@ -402,6 +396,13 @@ msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj,
 	if (obj)
 		GEM_WARN_ON((range_end - range_start) > obj->size);
 
+	struct drm_gpuva_op_map op_map = {
+		.va.addr = range_start,
+		.va.range = range_end - range_start,
+		.gem.obj = obj,
+		.gem.offset = offset,
+	};

OOC, are we now allowed to declare local variables in the middle of a code block in kernel code? I must admit that's not something I tried doing recently, but I've had gcc warnings in the past because of that.

Quoted 10 lines
drivers/gpu/drm/msm/msm_gem_vma.c +1 -1
+
 	drm_gpuva_init_from_op(&vma->base, &op_map);
 	vma->mapped = false;
 
 
---

base-commit: 0f4c93f7eb861acab537dbe94441817a270537bf
change-id: 20250823-msm-fix-gpuvm-init-520d87ebcf26

Best regards,

#6 lore raw
Quoted 43 lines · Boris Brezillon
Quoted 39 lines · On Sat, 23 Aug 2025 03:12:00 +0300 Dmitry Baryshkov…

Since commit 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()") MSM driver fails to init, failing with "[drm:msm_gpu_init] *ERROR* could not allocate memptrs: -22" errors. The mentioned commit reworked the function, but didn't take into account that op_map is initialized at the top of the function, while ranges might change if GPUVM is managed by the kernel.

Move op_mode initialization after finalizing all addresses and right before the drm_gpuva_init_from_op() call.

Fixes 3309323241fb ("drm/gpuvm: Kill drm_gpuva_init()")
---
 drivers/gpu/drm/msm/msm_gem_vma.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/msm/msm_gem_vma.c +0 -6
index 3f440bc1f7106f3b0091f037611d0b433e5e2c18..6df6b7c0984da57fe64de41fa54f7dea0a324c74 100644
@@ -368,12 +368,6 @@ struct drm_gpuva *
 msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj,
              u64 offset, u64 range_start, u64 range_end)
 {
-     struct drm_gpuva_op_map op_map = {
-             .va.addr = range_start,
-             .va.range = range_end - range_start,
-             .gem.obj = obj,
-             .gem.offset = offset,
-     };
      struct msm_gem_vm *vm = to_msm_vm(gpuvm);
      struct drm_gpuvm_bo *vm_bo;
      struct msm_gem_vma *vma;
@@ -402,6 +396,13 @@ msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj,
      if (obj)
              GEM_WARN_ON((range_end - range_start) > obj->size);
 
Quoted 10 lines

drivers/gpu/drm/msm/msm_gem_vma.c msm_gem_vma_new(struct drm_gpuvm *gpuvm, struct drm_gem_object *obj, · line 404

Quoted 6 lines
drivers/gpu/drm/msm/msm_gem_vma.c +6 -0
+     struct drm_gpuva_op_map op_map = {
+             .va.addr = range_start,
+             .va.range = range_end - range_start,
+             .gem.obj = obj,
+             .gem.offset = offset,
+     };

OOC, are we now allowed to declare local variables in the middle of a code block in kernel code? I must admit that's not something I tried doing recently, but I've had gcc warnings in the past because of that.

yes.. I try not to go overboard with it, but this is a case where it seems like the cleanest solution

BR,
-R

Quoted 11 lines
Quoted 10 lines
drivers/gpu/drm/msm/msm_gem_vma.c +1 -1
+
      drm_gpuva_init_from_op(&vma->base, &op_map);
      vma->mapped = false;
 
 
---

base-commit: 0f4c93f7eb861acab537dbe94441817a270537bf
change-id: 20250823-msm-fix-gpuvm-init-520d87ebcf26

Best regards,