Skip to contentSkip to conversation

drm/amdgpu: Fix VM clean check method

PATCH Superseded Trigger Huang 2 participants 2 messages Apr 30, 2019 1 message not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix VM clean check method

amdgpu_vm_make_compute is used to turn a GFX VM into a compute VM, the prerequisite is this VM is clean. Let's check if some page tables are already filled , while not check if some mapping is already made.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 36 +++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +35 -1
index 56d838f..6752d4c 100644
@@ -2755,6 +2755,40 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 }
 
 /**
+ * amdgpu_vm_check_clean_reserved - check if a VM is clean
+ *
+ * @adev: amdgpu_device pointer
+ * @vm: the VM to check
+ *
+ * check all entries of the root PD, if any subsequent PDs are allocated,
+ * it means there are page table creating and filling, and is no a clean
+ * VM
+ *
+ * Returns:
+ *	0 if this VM is clean
+ */
+static int amdgpu_vm_check_clean_reserved(struct amdgpu_device *adev,
+	struct amdgpu_vm *vm)
+{
+	int ret = 0;
+
+	if (vm->root.entries) {
+		unsigned int i = 0;
+		enum amdgpu_vm_level l = adev->vm_manager.root_level;
+		unsigned int entries = amdgpu_vm_num_entries(adev, l);
+
+		for (i = 0; i < entries; i++) {
+			if (vm->root.entries[i].base.bo) {
+				ret = -EINVAL;
+				break;
+			}
+		}
+	}
+
+	return ret;
+}
+
+/**
  * amdgpu_vm_make_compute - Turn a GFX VM into a compute VM
  *
  * @adev: amdgpu_device pointer
@@ -2784,7 +2818,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, uns
 		return r;
 
 	/* Sanity checks */
-	if (!RB_EMPTY_ROOT(&vm->va.rb_root) || vm->root.entries) {
+	if (amdgpu_vm_check_clean_reserved(adev, vm)) {
 		r = -EINVAL;
 		goto unreserve_bo;
 	}
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1556633912-27698-1-git-send-email-Trigger.Huang-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Am 30.04.19 um 16:18 schrieb Trigger Huang:

Quoted 25 lines

amdgpu_vm_make_compute is used to turn a GFX VM into a compute VM, the prerequisite is this VM is clean. Let's check if some page tables are already filled , while not check if some mapping is already made.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 36 +++++++++++++++++++++++++++++++++-
  1 file changed, 35 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -0
index 56d838f..6752d4c 100644
@@ -2755,6 +2755,40 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  }
 
  /**
+ * amdgpu_vm_check_clean_reserved - check if a VM is clean
+ *
+ * @adev: amdgpu_device pointer
+ * @vm: the VM to check
+ *
+ * check all entries of the root PD, if any subsequent PDs are allocated,
+ * it means there are page table creating and filling, and is no a clean
+ * VM

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 2775

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -0
+ *
+ * Returns:
+ *	0 if this VM is clean
+ */
+static int amdgpu_vm_check_clean_reserved(struct amdgpu_device *adev,
+	struct amdgpu_vm *vm)
+{
+	int ret = 0;
+
+	if (vm->root.entries) {

Use an early return here.

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 2778

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -0
+		unsigned int i = 0;
+		enum amdgpu_vm_level l = adev->vm_manager.root_level;
+		unsigned int entries = amdgpu_vm_num_entries(adev, l);

And coding style usually uses reverse x-mas tree, e.g. stuff like "i" or "ret" last.

Christian.

Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +13 -0
+
+		for (i = 0; i < entries; i++) {
+			if (vm->root.entries[i].base.bo) {
+				ret = -EINVAL;
+				break;
+			}
+		}
+	}
+
+	return ret;
+}
+
+/**
   * amdgpu_vm_make_compute - Turn a GFX VM into a compute VM
   *
   * @adev: amdgpu_device pointer

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, uns · line 2824

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -2784,7 +2818,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, uns
  		return r;
 
  	/* Sanity checks */
-	if (!RB_EMPTY_ROOT(&vm->va.rb_root) || vm->root.entries) {
+	if (amdgpu_vm_check_clean_reserved(adev, vm)) {
  		r = -EINVAL;
  		goto unreserve_bo;
  	}

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx