Skip to contentSkip to conversation

Nouveau VM_BIND uAPI Fixes

PATCH In review Danilo Krummrich 2 participants 7 messages Aug 7, 2023 – Aug 8, 2023

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

cover Nouveau VM_BIND uAPI Fixes

The patch series provides a few fixes for the recently merged VM_BIND uAPI mostly addressing a couple of warnings.

It also contains one patch to slightly reduce the memory footprint of struct nouveau_uvma.

Danilo Krummrich (5):
nouveau/dmem: fix copy-paste error in nouveau_dmem_migrate_chunk() drm/nouveau: nvkm: vmm: silence warning from cast drm/nouveau: remove incorrect __user annotations drm/nouveau: uvmm: remove incorrect calls to mas_unlock() drm/nouveau: uvmm: remove dedicated VM pointer from VMAs

 drivers/gpu/drm/nouveau/nouveau_dmem.c        |  2 +-
 drivers/gpu/drm/nouveau/nouveau_exec.c        |  6 ++---
 drivers/gpu/drm/nouveau/nouveau_exec.h        |  2 +-
 drivers/gpu/drm/nouveau/nouveau_uvmm.c        | 23 ++++++++-----------
 drivers/gpu/drm/nouveau/nouveau_uvmm.h        | 14 +++++------
 .../gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c    |  5 ++--
 6 files changed, 24 insertions(+), 28 deletions(-)

base-commit: 82d750e9d2f5d0594c8f7057ce59127e701af781

Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/5 nouveau/dmem: fix copy-paste error in nouveau_dmem_migrate_chunk()

Fix call to nouveau_fence_emit() with wrong channel parameter.

Fixes 7f2a0b50b2b2 ("drm/nouveau: fence: separate fence alloc and emit")
---
 drivers/gpu/drm/nouveau/nouveau_dmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_dmem.c +1 -1
index 4ad40e42cae1..61e84562094a 100644
@@ -678,7 +678,7 @@ static void nouveau_dmem_migrate_chunk(struct nouveau_drm *drm,
 	}
 
 	if (!nouveau_fence_new(&fence))
-		nouveau_fence_emit(fence, chunk->drm->dmem->migrate.chan);
+		nouveau_fence_emit(fence, drm->dmem->migrate.chan);
 	migrate_vma_pages(args);
 	nouveau_dmem_fence_done(&fence);
 	nouveau_pfns_map(svmm, args->vma->vm_mm, args->start, pfns, i);
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/5 drm/nouveau: nvkm: vmm: silence warning from cast

In reply to Danilo Krummrich

Cast the integer to a pointer-sized type first to keep the compiler happy.

Fixes 6b252cf42281 ("drm/nouveau: nvkm/vmm: implement raw ops to manage uvmm")
---
 drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c +3 -2
index 38b7ced934b1..46cbd4cedb78 100644
@@ -399,6 +399,8 @@ nvkm_uvmm_mthd_raw_map(struct nvkm_uvmm *uvmm, struct nvif_vmm_raw_v0 *args)
 		.no_comp = true,
 	};
 	struct nvkm_memory *memory;
+	void *argv = (void *)(uintptr_t)args->argv;
+	int argc = args->argc;
 	u64 handle = args->memory;
 	u8 refd;
 	int ret;
@@ -418,8 +420,7 @@ nvkm_uvmm_mthd_raw_map(struct nvkm_uvmm *uvmm, struct nvif_vmm_raw_v0 *args)
 		return PTR_ERR(memory);
 	}
 
-	ret = nvkm_memory_map(memory, args->offset, vmm, &vma,
-			      (void *)args->argv, args->argc);
+	ret = nvkm_memory_map(memory, args->offset, vmm, &vma, argv, argc);
 
 	nvkm_memory_unref(&vma.memory);
 	nvkm_memory_unref(&memory);
Signature · 1 line
2.41.0
#3 lore raw

PATCH 3/5 drm/nouveau: remove incorrect __user annotations

In reply to Danilo Krummrich

Fix copy-paste error causing EXEC and VM_BIND syscalls data pointers to carry incorrect __user annotations.

Fixes b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI")
---
 drivers/gpu/drm/nouveau/nouveau_exec.c | 6 +++---
 drivers/gpu/drm/nouveau/nouveau_exec.h | 2 +-
 drivers/gpu/drm/nouveau/nouveau_uvmm.c | 6 +++---
 drivers/gpu/drm/nouveau/nouveau_uvmm.h | 4 ++--
 4 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/nouveau/nouveau_exec.c +3 -3
index 42d9dd43ea02..0f927adda4ed 100644
@@ -293,7 +293,7 @@ nouveau_exec(struct nouveau_exec_job_args *args)
 
 static int
 nouveau_exec_ucopy(struct nouveau_exec_job_args *args,
-		   struct drm_nouveau_exec __user *req)
+		   struct drm_nouveau_exec *req)
 {
 	struct drm_nouveau_sync **s;
 	u32 inc = req->wait_count;
@@ -352,7 +352,7 @@ nouveau_exec_ufree(struct nouveau_exec_job_args *args)
 
 int
 nouveau_exec_ioctl_exec(struct drm_device *dev,
-			void __user *data,
+			void *data,
 			struct drm_file *file_priv)
 {
 	struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
@@ -360,7 +360,7 @@ nouveau_exec_ioctl_exec(struct drm_device *dev,
 	struct nouveau_abi16_chan *chan16;
 	struct nouveau_channel *chan = NULL;
 	struct nouveau_exec_job_args args = {};
-	struct drm_nouveau_exec __user *req = data;
+	struct drm_nouveau_exec *req = data;
 	int ret = 0;
 
 	if (unlikely(!abi16))
drivers/gpu/drm/nouveau/nouveau_exec.h +1 -1
index 3032db27b8d7..778cacd90f65 100644
@@ -48,7 +48,7 @@ struct nouveau_exec_job {
 int nouveau_exec_job_init(struct nouveau_exec_job **job,
 			  struct nouveau_exec_job_args *args);
 
-int nouveau_exec_ioctl_exec(struct drm_device *dev, void __user *data,
+int nouveau_exec_ioctl_exec(struct drm_device *dev, void *data,
 			    struct drm_file *file_priv);
 
 #endif
drivers/gpu/drm/nouveau/nouveau_uvmm.c +3 -3
index b515a21aa08e..2acbac73e57a 100644
@@ -1687,7 +1687,7 @@ nouveau_uvmm_vm_bind(struct nouveau_uvmm_bind_job_args *args)
 
 static int
 nouveau_uvmm_vm_bind_ucopy(struct nouveau_uvmm_bind_job_args *args,
-			   struct drm_nouveau_vm_bind __user *req)
+			   struct drm_nouveau_vm_bind *req)
 {
 	struct drm_nouveau_sync **s;
 	u32 inc = req->wait_count;
@@ -1749,12 +1749,12 @@ nouveau_uvmm_vm_bind_ufree(struct nouveau_uvmm_bind_job_args *args)
 
 int
 nouveau_uvmm_ioctl_vm_bind(struct drm_device *dev,
-			   void __user *data,
+			   void *data,
 			   struct drm_file *file_priv)
 {
 	struct nouveau_cli *cli = nouveau_cli(file_priv);
 	struct nouveau_uvmm_bind_job_args args = {};
-	struct drm_nouveau_vm_bind __user *req = data;
+	struct drm_nouveau_vm_bind *req = data;
 	int ret = 0;
 
 	if (unlikely(!nouveau_cli_uvmm_locked(cli)))
drivers/gpu/drm/nouveau/nouveau_uvmm.h +2 -2
index 3923c03012f9..534baadc3bf7 100644
@@ -89,10 +89,10 @@ void nouveau_uvmm_fini(struct nouveau_uvmm *uvmm);
 void nouveau_uvmm_bo_map_all(struct nouveau_bo *nvbov, struct nouveau_mem *mem);
 void nouveau_uvmm_bo_unmap_all(struct nouveau_bo *nvbo);
 
-int nouveau_uvmm_ioctl_vm_init(struct drm_device *dev, void __user *data,
+int nouveau_uvmm_ioctl_vm_init(struct drm_device *dev, void *data,
 			       struct drm_file *file_priv);
 
-int nouveau_uvmm_ioctl_vm_bind(struct drm_device *dev, void __user *data,
+int nouveau_uvmm_ioctl_vm_bind(struct drm_device *dev, void *data,
 			       struct drm_file *file_priv);
 
 static inline void nouveau_uvmm_lock(struct nouveau_uvmm *uvmm)
Signature · 1 line
2.41.0
#4 lore raw

PATCH 4/5 drm/nouveau: uvmm: remove incorrect calls to mas_unlock()

In reply to Danilo Krummrich

Remove incorrect calls to mas_unlock() in the unwind path of __nouveau_uvma_region_insert(). The region maple tree uses an external lock instead, namely the global uvmm lock.

Fixes b88baab82871 ("drm/nouveau: implement new VM_BIND uAPI")
---
 drivers/gpu/drm/nouveau/nouveau_uvmm.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/nouveau/nouveau_uvmm.c +2 -6
index 2acbac73e57a..91b964ef98b1 100644
@@ -279,15 +279,11 @@ __nouveau_uvma_region_insert(struct nouveau_uvmm *uvmm,
 	u64 last = addr + range - 1;
 	MA_STATE(mas, &uvmm->region_mt, addr, addr);
 
-	if (unlikely(mas_walk(&mas))) {
-		mas_unlock(&mas);
+	if (unlikely(mas_walk(&mas)))
 		return -EEXIST;
-	}
 
-	if (unlikely(mas.last < last)) {
-		mas_unlock(&mas);
+	if (unlikely(mas.last < last))
 		return -EEXIST;
-	}
 
 	mas.index = addr;
 	mas.last = last;
Signature · 1 line
2.41.0
#5 lore raw

PATCH 5/5 drm/nouveau: uvmm: remove dedicated VM pointer from VMAs

In reply to Danilo Krummrich

VMAs can find their corresponding VM through their embedded struct drm_gpuva which already carries a pointer to a struct drm_gpuva_manager which the VM is based on. Hence, remove the struct nouveau_uvmm pointer from struct nouveau_uvma to save a couple of bytes per mapping.

---
 drivers/gpu/drm/nouveau/nouveau_uvmm.c |  9 ++++-----
 drivers/gpu/drm/nouveau/nouveau_uvmm.h | 10 +++++-----
 2 files changed, 9 insertions(+), 10 deletions(-)
drivers/gpu/drm/nouveau/nouveau_uvmm.c +4 -5
index 91b964ef98b1..3a1e8538f205 100644
@@ -181,7 +181,7 @@ nouveau_uvma_vmm_put(struct nouveau_uvma *uvma)
 	u64 addr = uvma->va.va.addr;
 	u64 range = uvma->va.va.range;
 
-	return nouveau_uvmm_vmm_put(uvma->uvmm, addr, range);
+	return nouveau_uvmm_vmm_put(to_uvmm(uvma), addr, range);
 }
 
 static int
@@ -192,7 +192,7 @@ nouveau_uvma_map(struct nouveau_uvma *uvma,
 	u64 offset = uvma->va.gem.offset;
 	u64 range = uvma->va.va.range;
 
-	return nouveau_uvmm_vmm_map(uvma->uvmm, addr, range,
+	return nouveau_uvmm_vmm_map(to_uvmm(uvma), addr, range,
 				    offset, uvma->kind, mem);
 }
 
@@ -206,7 +206,7 @@ nouveau_uvma_unmap(struct nouveau_uvma *uvma)
 	if (drm_gpuva_invalidated(&uvma->va))
 		return 0;
 
-	return nouveau_uvmm_vmm_unmap(uvma->uvmm, addr, range, sparse);
+	return nouveau_uvmm_vmm_unmap(to_uvmm(uvma), addr, range, sparse);
 }
 
 static int
@@ -586,7 +586,6 @@ op_map_prepare(struct nouveau_uvmm *uvmm,
 	if (ret)
 		return ret;
 
-	uvma->uvmm = uvmm;
 	uvma->region = args->region;
 	uvma->kind = args->kind;
 
@@ -794,7 +793,7 @@ op_unmap_range(struct drm_gpuva_op_unmap *u,
 	bool sparse = !!uvma->region;
 
 	if (!drm_gpuva_invalidated(u->va))
-		nouveau_uvmm_vmm_unmap(uvma->uvmm, addr, range, sparse);
+		nouveau_uvmm_vmm_unmap(to_uvmm(uvma), addr, range, sparse);
 }
 
 static void
drivers/gpu/drm/nouveau/nouveau_uvmm.h +5 -5
index 534baadc3bf7..fc7f6fd2a4e1 100644
@@ -37,12 +37,15 @@ struct nouveau_uvma_region {
 struct nouveau_uvma {
 	struct drm_gpuva va;
 
-	struct nouveau_uvmm *uvmm;
 	struct nouveau_uvma_region *region;
-
 	u8 kind;
 };
 
+#define uvmm_from_mgr(x) container_of((x), struct nouveau_uvmm, umgr)
+#define uvma_from_va(x) container_of((x), struct nouveau_uvma, va)
+
+#define to_uvmm(x) uvmm_from_mgr((x)->va.mgr)
+
 struct nouveau_uvmm_bind_job {
 	struct nouveau_job base;
 
@@ -79,9 +82,6 @@ struct nouveau_uvmm_bind_job_args {
 
 #define to_uvmm_bind_job(job) container_of((job), struct nouveau_uvmm_bind_job, base)
 
-#define uvmm_from_mgr(x) container_of((x), struct nouveau_uvmm, umgr)
-#define uvma_from_va(x) container_of((x), struct nouveau_uvma, va)
-
 int nouveau_uvmm_init(struct nouveau_uvmm *uvmm, struct nouveau_cli *cli,
 		      u64 kernel_managed_addr, u64 kernel_managed_size);
 void nouveau_uvmm_fini(struct nouveau_uvmm *uvmm);
Signature · 1 line
2.41.0
maintainer Reviewed-by on the v1 series
#6 lore raw
In reply to Danilo Krummrich

For the series:

Quoted 27 lines · Danilo Krummrich

The patch series provides a few fixes for the recently merged VM_BIND uAPI mostly addressing a couple of warnings.

It also contains one patch to slightly reduce the memory footprint of struct nouveau_uvma.

Danilo Krummrich (5):
nouveau/dmem: fix copy-paste error in nouveau_dmem_migrate_chunk() drm/nouveau: nvkm: vmm: silence warning from cast drm/nouveau: remove incorrect __user annotations drm/nouveau: uvmm: remove incorrect calls to mas_unlock() drm/nouveau: uvmm: remove dedicated VM pointer from VMAs

 drivers/gpu/drm/nouveau/nouveau_dmem.c        |  2 +-
 drivers/gpu/drm/nouveau/nouveau_exec.c        |  6 ++---
 drivers/gpu/drm/nouveau/nouveau_exec.h        |  2 +-
 drivers/gpu/drm/nouveau/nouveau_uvmm.c        | 23 ++++++++-----------
 drivers/gpu/drm/nouveau/nouveau_uvmm.h        | 14 +++++------
 .../gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c    |  5 ++--
 6 files changed, 24 insertions(+), 28 deletions(-)

base-commit: 82d750e9d2f5d0594c8f7057ce59127e701af781 --
2.41.0