* [PATCH 1/3] drm/amdgpu: add user queue vm identifier
@ 2025-11-05 6:16 Prike Liang
2025-11-05 6:16 ` [PATCH 2/3] drm/amdgpu: rework the userq tlb flush Prike Liang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Prike Liang @ 2025-11-05 6:16 UTC (permalink / raw)
To: amd-gfx; +Cc: Alexander.Deucher, Christian.Koenig, Prike Liang
Add a user queue vm identifier for each userqueue
kms opt accessing.
Signed-off-by: Prike Liang <Prike.Liang@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 5 +++++
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index 8888be4e758c..a8bb3f1b8649 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -1249,10 +1249,13 @@ amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr,
int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,
struct amdgpu_device *adev)
{
+ struct amdgpu_fpriv *fpriv = uq_mgr_to_fpriv(userq_mgr);
+
mutex_init(&userq_mgr->userq_mutex);
xa_init_flags(&userq_mgr->userq_mgr_xa, XA_FLAGS_ALLOC);
userq_mgr->adev = adev;
userq_mgr->file = file_priv;
+ fpriv->vm.is_userq_context = true;
INIT_DELAYED_WORK(&userq_mgr->resume_work, amdgpu_userq_restore_worker);
return 0;
@@ -1262,6 +1265,7 @@ void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)
{
struct amdgpu_usermode_queue *queue;
unsigned long queue_id;
+ struct amdgpu_fpriv *fpriv = uq_mgr_to_fpriv(userq_mgr);
cancel_delayed_work_sync(&userq_mgr->resume_work);
@@ -1276,6 +1280,7 @@ void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)
xa_destroy(&userq_mgr->userq_mgr_xa);
mutex_unlock(&userq_mgr->userq_mutex);
mutex_destroy(&userq_mgr->userq_mutex);
+ fpriv->vm.is_userq_context = false;
}
int amdgpu_userq_suspend(struct amdgpu_device *adev)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index db66b4232de0..48a64d828eb8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2591,7 +2591,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
ttm_lru_bulk_move_init(&vm->lru_bulk_move);
vm->is_compute_context = false;
-
+ vm->is_userq_context = false;
vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
AMDGPU_VM_USE_CPU_FOR_GFX);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 77207f4e448e..cbe7dfa4ffcb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -439,7 +439,7 @@ struct amdgpu_vm {
struct ttm_lru_bulk_move lru_bulk_move;
/* Flag to indicate if VM is used for compute */
bool is_compute_context;
-
+ bool is_userq_context;
/* Memory partition number, -1 means any partition */
int8_t mem_id;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/3] drm/amdgpu: rework the userq tlb flush
2025-11-05 6:16 [PATCH 1/3] drm/amdgpu: add user queue vm identifier Prike Liang
@ 2025-11-05 6:16 ` Prike Liang
2025-11-05 8:31 ` Christian König
2025-11-05 6:16 ` [PATCH 3/3] drm/amdgpu: fix the vm update tlb sequence Prike Liang
2025-11-05 8:28 ` [PATCH 1/3] drm/amdgpu: add user queue vm identifier Christian König
2 siblings, 1 reply; 6+ messages in thread
From: Prike Liang @ 2025-11-05 6:16 UTC (permalink / raw)
To: amd-gfx; +Cc: Alexander.Deucher, Christian.Koenig, Prike Liang
The userq TLB flush should be performed after
the vm update complete and input fence signal.
Signed-off-by: Prike Liang <Prike.Liang@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 1 +
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index a8bb3f1b8649..01707d72d982 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -384,6 +384,7 @@ amdgpu_userq_wait_for_last_fence(struct amdgpu_userq_mgr *uq_mgr,
return -ETIME;
}
}
+ amdgpu_gmc_flush_gpu_tlb_pasid(uq_mgr->adev, queue->vm->pasid, 2, true, 0);
return ret;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 48a64d828eb8..1537f0b6b712 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1062,7 +1062,8 @@ amdgpu_vm_tlb_flush(struct amdgpu_vm_update_params *params,
}
/* Prepare a TLB flush fence to be attached to PTs */
- if (!params->unlocked && vm->is_compute_context) {
+ if (!params->unlocked && (vm->is_compute_context ||
+ vm->is_userq_context)) {
amdgpu_vm_tlb_fence_create(params->adev, vm, fence);
/* Makes sure no PD/PT is freed before the flush */
@@ -2792,7 +2793,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
amdgpu_bo_unreserve(root);
amdgpu_bo_unref(&root);
WARN_ON(vm->root.bo);
-
+ amdgpu_gmc_flush_gpu_tlb_pasid(adev, vm->pasid, 2, true, 0);
amdgpu_vm_fini_entities(vm);
if (!RB_EMPTY_ROOT(&vm->va.rb_root)) {
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 2/3] drm/amdgpu: rework the userq tlb flush
2025-11-05 6:16 ` [PATCH 2/3] drm/amdgpu: rework the userq tlb flush Prike Liang
@ 2025-11-05 8:31 ` Christian König
0 siblings, 0 replies; 6+ messages in thread
From: Christian König @ 2025-11-05 8:31 UTC (permalink / raw)
To: Prike Liang, amd-gfx; +Cc: Alexander.Deucher
On 11/5/25 07:16, Prike Liang wrote:
> The userq TLB flush should be performed after
> the vm update complete and input fence signal.
>
> Signed-off-by: Prike Liang <Prike.Liang@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 1 +
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++--
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index a8bb3f1b8649..01707d72d982 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> @@ -384,6 +384,7 @@ amdgpu_userq_wait_for_last_fence(struct amdgpu_userq_mgr *uq_mgr,
> return -ETIME;
> }
> }
> + amdgpu_gmc_flush_gpu_tlb_pasid(uq_mgr->adev, queue->vm->pasid, 2, true, 0);
Please drop that one, it doesn't seem to make any sense at all.
>
> return ret;
> }
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 48a64d828eb8..1537f0b6b712 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -1062,7 +1062,8 @@ amdgpu_vm_tlb_flush(struct amdgpu_vm_update_params *params,
> }
>
> /* Prepare a TLB flush fence to be attached to PTs */
> - if (!params->unlocked && vm->is_compute_context) {
> + if (!params->unlocked && (vm->is_compute_context ||
> + vm->is_userq_context)) {
Just drop the is_compute_context check here, don't add any new checks.
> amdgpu_vm_tlb_fence_create(params->adev, vm, fence);
>
> /* Makes sure no PD/PT is freed before the flush */
> @@ -2792,7 +2793,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
> amdgpu_bo_unreserve(root);
> amdgpu_bo_unref(&root);
> WARN_ON(vm->root.bo);
> -
> + amdgpu_gmc_flush_gpu_tlb_pasid(adev, vm->pasid, 2, true, 0);
Please drop that one as well, it doesn't seem to make sense.
Regards,
Christian.
> amdgpu_vm_fini_entities(vm);
>
> if (!RB_EMPTY_ROOT(&vm->va.rb_root)) {
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] drm/amdgpu: fix the vm update tlb sequence
2025-11-05 6:16 [PATCH 1/3] drm/amdgpu: add user queue vm identifier Prike Liang
2025-11-05 6:16 ` [PATCH 2/3] drm/amdgpu: rework the userq tlb flush Prike Liang
@ 2025-11-05 6:16 ` Prike Liang
2025-11-05 8:32 ` Christian König
2025-11-05 8:28 ` [PATCH 1/3] drm/amdgpu: add user queue vm identifier Christian König
2 siblings, 1 reply; 6+ messages in thread
From: Prike Liang @ 2025-11-05 6:16 UTC (permalink / raw)
To: amd-gfx; +Cc: Alexander.Deucher, Christian.Koenig, Prike Liang
The VM TLB sequence is incremented by the VM update
commit invoker, so it should not be increased again
in the commit callback.
Signed-off-by: Prike Liang <Prike.Liang@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c | 2 --
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 2 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 3 ---
3 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
index 0c1ef5850a5e..f7a5e71346df 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
@@ -106,8 +106,6 @@ static int amdgpu_vm_cpu_update(struct amdgpu_vm_update_params *p,
static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
struct dma_fence **fence)
{
- if (p->needs_flush)
- atomic64_inc(&p->vm->tlb_seq);
mb();
amdgpu_device_flush_hdp(p->adev, NULL);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
index 30022123b0bf..869f9cb28d94 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
@@ -420,6 +420,8 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
goto exit;
r = vm->update_funcs->commit(¶ms, NULL);
+ if (params.needs_flush)
+ atomic64_inc(&vm->tlb_seq);
exit:
drm_dev_exit(idx);
return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
index 46d9fb433ab2..0ceb2474a721 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
@@ -115,9 +115,6 @@ static int amdgpu_vm_sdma_commit(struct amdgpu_vm_update_params *p,
WARN_ON(ib->length_dw == 0);
amdgpu_ring_pad_ib(ring, ib);
- if (p->needs_flush)
- atomic64_inc(&p->vm->tlb_seq);
-
WARN_ON(ib->length_dw > p->num_dw_left);
f = amdgpu_job_submit(p->job);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 3/3] drm/amdgpu: fix the vm update tlb sequence
2025-11-05 6:16 ` [PATCH 3/3] drm/amdgpu: fix the vm update tlb sequence Prike Liang
@ 2025-11-05 8:32 ` Christian König
0 siblings, 0 replies; 6+ messages in thread
From: Christian König @ 2025-11-05 8:32 UTC (permalink / raw)
To: Prike Liang, amd-gfx; +Cc: Alexander.Deucher
On 11/5/25 07:16, Prike Liang wrote:
> The VM TLB sequence is incremented by the VM update
> commit invoker, so it should not be increased again
> in the commit callback.
Clear NAK to that. It must be incremented by *both*!
Regards,
Christian.
>
> Signed-off-by: Prike Liang <Prike.Liang@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c | 2 --
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 2 ++
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 3 ---
> 3 files changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
> index 0c1ef5850a5e..f7a5e71346df 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
> @@ -106,8 +106,6 @@ static int amdgpu_vm_cpu_update(struct amdgpu_vm_update_params *p,
> static int amdgpu_vm_cpu_commit(struct amdgpu_vm_update_params *p,
> struct dma_fence **fence)
> {
> - if (p->needs_flush)
> - atomic64_inc(&p->vm->tlb_seq);
>
> mb();
> amdgpu_device_flush_hdp(p->adev, NULL);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> index 30022123b0bf..869f9cb28d94 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> @@ -420,6 +420,8 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
> goto exit;
>
> r = vm->update_funcs->commit(¶ms, NULL);
> + if (params.needs_flush)
> + atomic64_inc(&vm->tlb_seq);
> exit:
> drm_dev_exit(idx);
> return r;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
> index 46d9fb433ab2..0ceb2474a721 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
> @@ -115,9 +115,6 @@ static int amdgpu_vm_sdma_commit(struct amdgpu_vm_update_params *p,
> WARN_ON(ib->length_dw == 0);
> amdgpu_ring_pad_ib(ring, ib);
>
> - if (p->needs_flush)
> - atomic64_inc(&p->vm->tlb_seq);
> -
> WARN_ON(ib->length_dw > p->num_dw_left);
> f = amdgpu_job_submit(p->job);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] drm/amdgpu: add user queue vm identifier
2025-11-05 6:16 [PATCH 1/3] drm/amdgpu: add user queue vm identifier Prike Liang
2025-11-05 6:16 ` [PATCH 2/3] drm/amdgpu: rework the userq tlb flush Prike Liang
2025-11-05 6:16 ` [PATCH 3/3] drm/amdgpu: fix the vm update tlb sequence Prike Liang
@ 2025-11-05 8:28 ` Christian König
2 siblings, 0 replies; 6+ messages in thread
From: Christian König @ 2025-11-05 8:28 UTC (permalink / raw)
To: Prike Liang, amd-gfx; +Cc: Alexander.Deucher
On 11/5/25 07:16, Prike Liang wrote:
> Add a user queue vm identifier for each userqueue
> kms opt accessing.
Clear NAK to that approach, we don't want any specialized handling in the VM if userqueues are enabled.
Christian.
>
> Signed-off-by: Prike Liang <Prike.Liang@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 5 +++++
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +-
> 3 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> index 8888be4e758c..a8bb3f1b8649 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
> @@ -1249,10 +1249,13 @@ amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr,
> int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,
> struct amdgpu_device *adev)
> {
> + struct amdgpu_fpriv *fpriv = uq_mgr_to_fpriv(userq_mgr);
> +
> mutex_init(&userq_mgr->userq_mutex);
> xa_init_flags(&userq_mgr->userq_mgr_xa, XA_FLAGS_ALLOC);
> userq_mgr->adev = adev;
> userq_mgr->file = file_priv;
> + fpriv->vm.is_userq_context = true;
>
> INIT_DELAYED_WORK(&userq_mgr->resume_work, amdgpu_userq_restore_worker);
> return 0;
> @@ -1262,6 +1265,7 @@ void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)
> {
> struct amdgpu_usermode_queue *queue;
> unsigned long queue_id;
> + struct amdgpu_fpriv *fpriv = uq_mgr_to_fpriv(userq_mgr);
>
> cancel_delayed_work_sync(&userq_mgr->resume_work);
>
> @@ -1276,6 +1280,7 @@ void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr)
> xa_destroy(&userq_mgr->userq_mgr_xa);
> mutex_unlock(&userq_mgr->userq_mutex);
> mutex_destroy(&userq_mgr->userq_mutex);
> + fpriv->vm.is_userq_context = false;
> }
>
> int amdgpu_userq_suspend(struct amdgpu_device *adev)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index db66b4232de0..48a64d828eb8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -2591,7 +2591,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
> ttm_lru_bulk_move_init(&vm->lru_bulk_move);
>
> vm->is_compute_context = false;
> -
> + vm->is_userq_context = false;
> vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
> AMDGPU_VM_USE_CPU_FOR_GFX);
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> index 77207f4e448e..cbe7dfa4ffcb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> @@ -439,7 +439,7 @@ struct amdgpu_vm {
> struct ttm_lru_bulk_move lru_bulk_move;
> /* Flag to indicate if VM is used for compute */
> bool is_compute_context;
> -
> + bool is_userq_context;
> /* Memory partition number, -1 means any partition */
> int8_t mem_id;
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-11-05 8:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-05 6:16 [PATCH 1/3] drm/amdgpu: add user queue vm identifier Prike Liang
2025-11-05 6:16 ` [PATCH 2/3] drm/amdgpu: rework the userq tlb flush Prike Liang
2025-11-05 8:31 ` Christian König
2025-11-05 6:16 ` [PATCH 3/3] drm/amdgpu: fix the vm update tlb sequence Prike Liang
2025-11-05 8:32 ` Christian König
2025-11-05 8:28 ` [PATCH 1/3] drm/amdgpu: add user queue vm identifier Christian König
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox