All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Fix VM clean check method
@ 2019-04-30 14:18 Trigger Huang
       [not found] ` <1556633912-27698-1-git-send-email-Trigger.Huang-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Trigger Huang @ 2019-04-30 14:18 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Trigger.Huang-5C7GfCeVMHo

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.

Signed-off-by: Trigger Huang <Trigger.Huang@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 36 +++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 56d838f..6752d4c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -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;
 	}
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amdgpu: Fix VM clean check method
       [not found] ` <1556633912-27698-1-git-send-email-Trigger.Huang-5C7GfCeVMHo@public.gmane.org>
@ 2019-04-30 14:29   ` Christian König
  0 siblings, 0 replies; 2+ messages in thread
From: Christian König @ 2019-04-30 14:29 UTC (permalink / raw)
  To: Trigger Huang, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 30.04.19 um 16:18 schrieb Trigger Huang:
> 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.
>
> Signed-off-by: Trigger Huang <Trigger.Huang@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 36 +++++++++++++++++++++++++++++++++-
>   1 file changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 56d838f..6752d4c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -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) {

Use an early return here.

> +		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.

> +
> +		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;
>   	}

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-30 14:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-30 14:18 [PATCH] drm/amdgpu: Fix VM clean check method Trigger Huang
     [not found] ` <1556633912-27698-1-git-send-email-Trigger.Huang-5C7GfCeVMHo@public.gmane.org>
2019-04-30 14:29   ` Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.