Skip to contentSkip to conversation

drm/amdkfd: Add TLB flush after MES queue eviction/suspension

PATCH Superseded Priya Hosur 7 participants 12 messages Aug 14 – Aug 25

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover drm/amdkfd: Add TLB flush after MES queue eviction/suspension

This patch series adds heavy-weight TLB flush after MES queue eviction/suspension to fix SVM page migration hangs on gfx1151 with XNACK mode enabled.

v3:
- Split into 2 patches per Alex's review
- Added userq TLB flush in amdgpu_userq_unmap_helper() (amdgpu_userq.c)

v2:
- Removed "SDMA" from comment as this affects all in-flight memory accesses, not just SDMA (Felix Kuehling)
- Added Reviewed-by tag

Priya Hosur (2):
drm/amdkfd: Add TLB flush after MES queue eviction/suspension drm/amdgpu: Add TLB flush after MES user queue unmap

 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c           |  6 ++++++
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c   | 13 ++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/2 drm/amdkfd: Add TLB flush after MES queue eviction/suspension

MES (Micro Engine Scheduler) does not perform heavy-weight TLB invalidation after unmapping queues, unlike HWS which does this automatically. This causes a race condition where in-flight DMA descriptors can access memory that has been unmapped, leading to page faults and GPU queue hangs during SVM page migration.

The issue manifests as KFDSVMRangeTest.MultiThreadMigrationTest failures on gfx1151 (Strix Point) with XNACK mode 1 enabled - the GPU compute queue hangs with packets submitted but never consumed.

Add kfd_flush_tlb() calls after MES queue removal in two locations:
- evict_process_queues_cpsch(): after all queues removed during eviction
- suspend_queues(): after debug/criu queue suspension (with mem_fence barrier)

This ensures all in-flight memory accesses from unmapped queues are flushed before memory is freed or migrated.

Change-Id Iaa884d4a7ad1199446bc45f4ad8a9a179ab386e6
---
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c   | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +12 -1
index a23384571193..6002c8a65fbe 100644
@@ -1450,6 +1450,14 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm,
 		dqm_evict_mqd_bo(dqm, q);
 	}
 
+	/*
+	 * Heavy-weight TLB flush after MES removes queues to ensure
+	 * in-flight memory accesses complete before memory is freed/migrated.
+	 * HWS does this automatically, MES does not.
+	 */
+	if (dqm->dev->kfd->shared_resources.enable_mes)
+		kfd_flush_tlb(pdd);
+
 	if (!dqm->dev->kfd->shared_resources.enable_mes) {
 		pdd->last_evict_timestamp = get_jiffies_64();
 		retval = execute_queues_cpsch(dqm,
@@ -3736,8 +3744,11 @@ int suspend_queues(struct kfd_process *p,
 		if (!per_device_suspended) {
 			dqm_unlock(dqm);
 			mutex_unlock(&p->event_mutex);
-			if (total_suspended)
+			if (total_suspended) {
 				amdgpu_amdkfd_debug_mem_fence(dqm->dev->adev);
+				/* Heavy-weight TLB flush after MES suspends queues */
+				kfd_flush_tlb(pdd);
+			}
 			continue;
 		}
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/2 drm/amdgpu: Add TLB flush after MES user queue unmap

In reply to Priya Hosur

Similar to the KFD fix, MES does not perform heavy-weight TLB invalidation after unmapping user queues. Add amdgpu_gmc_flush_gpu_tlb_pasid() after MES unmap succeeds in amdgpu_userq_unmap_helper() to ensure in-flight memory accesses complete before memory is freed or migrated.

Change-Id I94fe2c84547723b6b73816ce8d727a54bd773a6a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -0
index 6d3ed55e9ab4..9fcf15d69b7b 100644
@@ -375,6 +375,12 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
 		} else {
 			trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
 			queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+			/*
+			 * Heavy-weight TLB flush after MES unmaps queue to ensure
+			 * in-flight memory accesses complete before memory is freed/migrated.
+			 * MES does not do this automatically unlike HWS.
+			 */
+			amdgpu_gmc_flush_gpu_tlb_pasid(adev, queue->vm->pasid, 2, true, 0);
 		}
 	}
 
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Hi,

Shouldn't this be a FW fix?

Thanks,
Lijo
________________________________
From: Priya Hosur <[email protected]>
Sent: Friday, 14 August 2026 21:48:40
To: [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Lazar, Lijo <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

Similar to the KFD fix, MES does not perform heavy-weight TLB invalidation after unmapping user queues. Add amdgpu_gmc_flush_gpu_tlb_pasid() after MES unmap succeeds in amdgpu_userq_unmap_helper() to ensure in-flight memory accesses complete before memory is freed or migrated.

Change-Id I94fe2c84547723b6b73816ce8d727a54bd773a6a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -0
index 6d3ed55e9ab4..9fcf15d69b7b 100644
@@ -375,6 +375,12 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
                 } else {
                         trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
                         queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+                       /*
+                        * Heavy-weight TLB flush after MES unmaps queue to ensure
+                        * in-flight memory accesses complete before memory is freed/migrated.
+                        * MES does not do this automatically unlike HWS.
+                        */
+                       amdgpu_gmc_flush_gpu_tlb_pasid(adev, queue->vm->pasid, 2, true, 0);
                 }
         }
 

--
2.43.0

maintainer
#4 lore raw

Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

We don't need to flush TLBs after every queue unmap. We only need to do it if there is an expectation that memory access is quiesced after unmapping. In the case of KFD, we are doing it when we're unmapping all queues, e.g. in MMU notifiers, evictions or when the debugger needs to stop the queues and look at memory contents. We only need one TLB flush after unmapping many queues.

Therefore, MES should flush TLBs after every queue unmap. OTOH, MES must flush TLBs by itself when it switches VMIDs. This is not under driver control.

I don't know what the requirements are for quiescing memory access after unmapping amdgpu user mode queues.

Regards,
Felix
________________________________
From: Lazar, Lijo <[email protected]>
Sent: Friday, August 14, 2026 12:29
To: Hosur, Priya <[email protected]>; [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Hi,

Shouldn't this be a FW fix?

Thanks,
Lijo
________________________________
From: Priya Hosur <[email protected]>
Sent: Friday, 14 August 2026 21:48:40
To: [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Lazar, Lijo <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

Similar to the KFD fix, MES does not perform heavy-weight TLB invalidation after unmapping user queues. Add amdgpu_gmc_flush_gpu_tlb_pasid() after MES unmap succeeds in amdgpu_userq_unmap_helper() to ensure in-flight memory accesses complete before memory is freed or migrated.

Change-Id I94fe2c84547723b6b73816ce8d727a54bd773a6a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -0
index 6d3ed55e9ab4..9fcf15d69b7b 100644
@@ -375,6 +375,12 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
                 } else {
                         trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
                         queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+                       /*
+                        * Heavy-weight TLB flush after MES unmaps queue to ensure
+                        * in-flight memory accesses complete before memory is freed/migrated.
+                        * MES does not do this automatically unlike HWS.
+                        */
+                       amdgpu_gmc_flush_gpu_tlb_pasid(adev, queue->vm->pasid, 2, true, 0);
                 }
         }
 

--
2.43.0

#5 lore raw

Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Thanks for the details. Didn't realise that it is one by one removal. I thought it was something like unmap-all for a PAS id.

Thanks,
Lijo
________________________________
From: Kuehling, Felix <[email protected]>
Sent: Friday, 14 August 2026 22:17:50
To: Lazar, Lijo <[email protected]>; Hosur, Priya <[email protected]>; [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

We don't need to flush TLBs after every queue unmap. We only need to do it if there is an expectation that memory access is quiesced after unmapping. In the case of KFD, we are doing it when we're unmapping all queues, e.g. in MMU notifiers, evictions or when the debugger needs to stop the queues and look at memory contents. We only need one TLB flush after unmapping many queues.

Therefore, MES should flush TLBs after every queue unmap. OTOH, MES must flush TLBs by itself when it switches VMIDs. This is not under driver control.

I don't know what the requirements are for quiescing memory access after unmapping amdgpu user mode queues.

Regards,
Felix
________________________________
From: Lazar, Lijo <[email protected]>
Sent: Friday, August 14, 2026 12:29
To: Hosur, Priya <[email protected]>; [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Hi,

Shouldn't this be a FW fix?

Thanks,
Lijo
________________________________
From: Priya Hosur <[email protected]>
Sent: Friday, 14 August 2026 21:48:40
To: [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Lazar, Lijo <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

Similar to the KFD fix, MES does not perform heavy-weight TLB invalidation after unmapping user queues. Add amdgpu_gmc_flush_gpu_tlb_pasid() after MES unmap succeeds in amdgpu_userq_unmap_helper() to ensure in-flight memory accesses complete before memory is freed or migrated.

Change-Id I94fe2c84547723b6b73816ce8d727a54bd773a6a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -0
index 6d3ed55e9ab4..9fcf15d69b7b 100644
@@ -375,6 +375,12 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
                 } else {
                         trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
                         queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+                       /*
+                        * Heavy-weight TLB flush after MES unmaps queue to ensure
+                        * in-flight memory accesses complete before memory is freed/migrated.
+                        * MES does not do this automatically unlike HWS.
+                        */
+                       amdgpu_gmc_flush_gpu_tlb_pasid(adev, queue->vm->pasid, 2, true, 0);
                 }
         }
 

--
2.43.0

#6 lore raw

RE: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Hi Felix, Lijo,

Thanks for the clarification. I understand now - TLB flush is only needed after batch queue unmapping (eviction/suspension), not after each individual queue unmap.

Alex - based on Felix's feedback, the userq unmap path doesn't need the same fix since it's per-queue unmap rather than batch unmap.

I'll drop patch 2/2 (userq fix) and send v4 with only the KFD fix.

Thanks and Regards,
Priya Hosur

From: Lazar, Lijo <[email protected]>
Sent: Friday, August 14, 2026 10:56 PM
To: Kuehling, Felix <[email protected]>; Hosur, Priya <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Thanks for the details. Didn't realise that it is one by one removal. I thought it was something like unmap-all for a PAS id.

Thanks,
Lijo
________________________________
From: Kuehling, Felix <[email protected]>
Sent: Friday, 14 August 2026 22:17:50
To: Lazar, Lijo <[email protected]>; Hosur, Priya <[email protected]>; [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

We don't need to flush TLBs after every queue unmap. We only need to do it if there is an expectation that memory access is quiesced after unmapping. In the case of KFD, we are doing it when we're unmapping all queues, e.g. in MMU notifiers, evictions or when the debugger needs to stop the queues and look at memory contents. We only need one TLB flush after unmapping many queues.

Therefore, MES should flush TLBs after every queue unmap. OTOH, MES must flush TLBs by itself when it switches VMIDs. This is not under driver control.

I don't know what the requirements are for quiescing memory access after unmapping amdgpu user mode queues.

Regards,
Felix
________________________________
From: Lazar, Lijo <[email protected]>
Sent: Friday, August 14, 2026 12:29
To: Hosur, Priya <[email protected]>; [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Hi,

Shouldn't this be a FW fix?

Thanks,
Lijo
________________________________
From: Priya Hosur <[email protected]>
Sent: Friday, 14 August 2026 21:48:40
To: [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Lazar, Lijo <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

Similar to the KFD fix, MES does not perform heavy-weight TLB invalidation after unmapping user queues. Add amdgpu_gmc_flush_gpu_tlb_pasid() after MES unmap succeeds in amdgpu_userq_unmap_helper() to ensure in-flight memory accesses complete before memory is freed or migrated.

Change-Id I94fe2c84547723b6b73816ce8d727a54bd773a6a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -0
index 6d3ed55e9ab4..9fcf15d69b7b 100644
@@ -375,6 +375,12 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
                 } else {
                         trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
                         queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+                       /*
+                        * Heavy-weight TLB flush after MES unmaps queue to ensure
+                        * in-flight memory accesses complete before memory is freed/migrated.
+                        * MES does not do this automatically unlike HWS.
+                        */
+                       amdgpu_gmc_flush_gpu_tlb_pasid(adev, queue->vm->pasid, 2, true, 0);
                 }
         }
 

--
2.43.0

#7 lore raw

Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

Quoted 8 lines · Priya

AMD General

Hi Felix, Lijo,

Quoted 6 lines

Thanks for the clarification. I understand now - TLB flush is only needed after batch queue unmapping (eviction/suspension), not after each individual queue unmap.

Alex - based on Felix's feedback, the userq unmap path doesn't need the same fix since it's per-queue unmap rather than batch unmap.

I think it's still needed when we evict all KGD userqs for a process (technically per GPU VM instance). E.g., the eviction fence case.

Alex

Quoted 128 lines

I'll drop patch 2/2 (userq fix) and send v4 with only the KFD fix.

Thanks and Regards,
Priya Hosur

From: Lazar, Lijo <[email protected]>
Sent: Friday, August 14, 2026 10:56 PM
To: Kuehling, Felix <[email protected]>; Hosur, Priya <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Thanks for the details. Didn't realise that it is one by one removal. I thought it was something like unmap-all for a PAS id.

Thanks,

Lijo

________________________________

From: Kuehling, Felix <[email protected]>
Sent: Friday, 14 August 2026 22:17:50
To: Lazar, Lijo <[email protected]>; Hosur, Priya <[email protected]>; [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

We don't need to flush TLBs after every queue unmap. We only need to do it if there is an expectation that memory access is quiesced after unmapping. In the case of KFD, we are doing it when we're unmapping all queues, e.g. in MMU notifiers, evictions or when the debugger needs to stop the queues and look at memory contents. We only need one TLB flush after unmapping many queues.

Therefore, MES should flush TLBs after every queue unmap. OTOH, MES must flush TLBs by itself when it switches VMIDs. This is not under driver control.

I don't know what the requirements are for quiescing memory access after unmapping amdgpu user mode queues.

Regards,

Felix

________________________________

From: Lazar, Lijo <[email protected]>
Sent: Friday, August 14, 2026 12:29
To: Hosur, Priya <[email protected]>; [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Hi,

Shouldn't this be a FW fix?

Thanks,

Lijo

________________________________

From: Priya Hosur <[email protected]>
Sent: Friday, 14 August 2026 21:48:40
To: [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Lazar, Lijo <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

Similar to the KFD fix, MES does not perform heavy-weight TLB invalidation after unmapping user queues. Add amdgpu_gmc_flush_gpu_tlb_pasid() after MES unmap succeeds in amdgpu_userq_unmap_helper() to ensure in-flight memory accesses complete before memory is freed or migrated.

Change-Id I94fe2c84547723b6b73816ce8d727a54bd773a6a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -1
index 6d3ed55e9ab4..9fcf15d69b7b 100644
@@ -375,6 +375,12 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
                 } else {
                         trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
                         queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+                       /*
+                        * Heavy-weight TLB flush after MES unmaps queue to ensure
+                        * in-flight memory accesses complete before memory is freed/migrated.
+                        * MES does not do this automatically unlike HWS.
+                        */
+                       amdgpu_gmc_flush_gpu_tlb_pasid(adev, queue->vm->pasid, 2, true, 0);
                 }
         }
 
--

2.43.0

#8 lore raw

Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

Quoted 8 lines · Alex Deucher
Quoted 7 lines · Priya

AMD General

Hi Felix, Lijo,

Quoted 8 lines
Quoted 6 lines

Thanks for the clarification. I understand now - TLB flush is only needed after batch queue unmapping (eviction/suspension), not after each individual queue unmap.

Alex - based on Felix's feedback, the userq unmap path doesn't need the same fix since it's per-queue unmap rather than batch unmap.

I think it's still needed when we evict all KGD userqs for a process (technically per GPU VM instance). E.g., the eviction fence case.

@priya, i am looking into this in the KGD userqueues. It's ok if you drop that as it need some more insight to understand how well it fits the KGD queues..

Regards
Sunil Khatri

Quoted 130 lines

Alex

Quoted 127 lines

I'll drop patch 2/2 (userq fix) and send v4 with only the KFD fix.

Thanks and Regards,
Priya Hosur

From: Lazar, Lijo <[email protected]>
Sent: Friday, August 14, 2026 10:56 PM
To: Kuehling, Felix <[email protected]>; Hosur, Priya <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Thanks for the details. Didn't realise that it is one by one removal. I thought it was something like unmap-all for a PAS id.

Thanks,

Lijo

________________________________

From: Kuehling, Felix <[email protected]>
Sent: Friday, 14 August 2026 22:17:50
To: Lazar, Lijo <[email protected]>; Hosur, Priya <[email protected]>; [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

We don't need to flush TLBs after every queue unmap. We only need to do it if there is an expectation that memory access is quiesced after unmapping. In the case of KFD, we are doing it when we're unmapping all queues, e.g. in MMU notifiers, evictions or when the debugger needs to stop the queues and look at memory contents. We only need one TLB flush after unmapping many queues.

Therefore, MES should flush TLBs after every queue unmap. OTOH, MES must flush TLBs by itself when it switches VMIDs. This is not under driver control.

I don't know what the requirements are for quiescing memory access after unmapping amdgpu user mode queues.

Regards,

Felix

________________________________

From: Lazar, Lijo <[email protected]>
Sent: Friday, August 14, 2026 12:29
To: Hosur, Priya <[email protected]>; [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Hi,

Shouldn't this be a FW fix?

Thanks,

Lijo

________________________________

From: Priya Hosur <[email protected]>
Sent: Friday, 14 August 2026 21:48:40
To: [email protected] <[email protected]>; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Lazar, Lijo <[email protected]>; Limonciello, Mario <[email protected]>; Koenig, Christian <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>; Hosur, Priya <[email protected]>
Subject: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

Similar to the KFD fix, MES does not perform heavy-weight TLB invalidation after unmapping user queues. Add amdgpu_gmc_flush_gpu_tlb_pasid() after MES unmap succeeds in amdgpu_userq_unmap_helper() to ensure in-flight memory accesses complete before memory is freed or migrated.

Change-Id I94fe2c84547723b6b73816ce8d727a54bd773a6a
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -1
index 6d3ed55e9ab4..9fcf15d69b7b 100644
@@ -375,6 +375,12 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
                  } else {
                          trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
                          queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+                       /*
+                        * Heavy-weight TLB flush after MES unmaps queue to ensure
+                        * in-flight memory accesses complete before memory is freed/migrated.
+                        * MES does not do this automatically unlike HWS.
+                        */
+                       amdgpu_gmc_flush_gpu_tlb_pasid(adev, queue->vm->pasid, 2, true, 0);
                  }
          }
 
--

2.43.0

maintainer
#9 lore raw

Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

In reply to Priya Hosur
Quoted 17 lines · Priya Hosur

Similar to the KFD fix, MES does not perform heavy-weight TLB invalidation after unmapping user queues. Add amdgpu_gmc_flush_gpu_tlb_pasid() after MES unmap succeeds in amdgpu_userq_unmap_helper() to ensure in-flight memory accesses complete before memory is freed or migrated.

Change-Id I94fe2c84547723b6b73816ce8d727a54bd773a6a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0 -0
index 6d3ed55e9ab4..9fcf15d69b7b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue) · line 383

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -0
@@ -375,6 +375,12 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
 		} else {
 			trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
 			queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+			/*
+			 * Heavy-weight TLB flush after MES unmaps queue to ensure
+			 * in-flight memory accesses complete before memory is freed/migrated.
+			 * MES does not do this automatically unlike HWS.
+			 */
+			amdgpu_gmc_flush_gpu_tlb_pasid(adev, queue->vm->pasid, 2, true, 0);

Absolutely clear NAK to this.

The MES *must* guarantee that in flight memory accesses are completed before it unmaps the queue or otherwise we run into massive problems.

Flushing out any VM changes by invalidating the TLB doesn't change anything on that.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0 -0
 		}
 	}
 
#10 lore raw

RE: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, August 24, 2026 1:09 PM
To: Hosur, Priya <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Lazar, Lijo <[email protected]>; Limonciello, Mario <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

Quoted 18 lines · Priya Hosur

Similar to the KFD fix, MES does not perform heavy-weight TLB invalidation after unmapping user queues. Add amdgpu_gmc_flush_gpu_tlb_pasid() after MES unmap succeeds in amdgpu_userq_unmap_helper() to ensure in-flight memory accesses complete before memory is freed or migrated.

Change-Id I94fe2c84547723b6b73816ce8d727a54bd773a6a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0 -0
index 6d3ed55e9ab4..9fcf15d69b7b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue) · line 384

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +7 -0
@@ -375,6 +375,12 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
              } else {
                      trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
                      queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+                     /*
+                      * Heavy-weight TLB flush after MES unmaps queue to ensure
+                      * in-flight memory accesses complete before memory is freed/migrated.
+                      * MES does not do this automatically unlike HWS.
+                      */
+                     amdgpu_gmc_flush_gpu_tlb_pasid(adev, queue->vm->pasid, 2, true,
+0);

Absolutely clear NAK to this.

The MES *must* guarantee that in flight memory accesses are completed before it unmaps the queue or otherwise we run into massive problems.

Flushing out any VM changes by invalidating the TLB doesn't change anything on that.

I tried this change during suspend but it dint help the case of tlb invalidation issues that we are facing.

regards
Sunil Khatri

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0 -0
              }
      }
#11 lore raw

RE: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

Hi all,

Thanks for the feedback and for testing this during suspend — since it doesn't resolve the TLB invalidation issue there either, this clearly needs deeper analysis. For now, I'll pick patch 1 (the KFD-related fix) only and drop patch 2 (this amdgpu_userq.c TLB flush).

Thanks,
Priya

-----Original Message-----
From: Khatri, Sunil <[email protected]>
Sent: Tuesday, August 25, 2026 12:17 PM
To: Koenig, Christian <[email protected]>; Hosur, Priya <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Lazar, Lijo <[email protected]>; Limonciello, Mario <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>
Subject: RE: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

AMD General

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, August 24, 2026 1:09 PM
To: Hosur, Priya <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Khatri, Sunil <[email protected]>; Kuehling, Felix <[email protected]>; Liu, Shaoyun <[email protected]>; Lazar, Lijo <[email protected]>; Limonciello, Mario <[email protected]>
Cc: Vishwakarma, Pratik <[email protected]>; Gopalakrishnan, Veerabadhran (Veera) <[email protected]>
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Add TLB flush after MES user queue unmap

Quoted 18 lines · Priya Hosur

Similar to the KFD fix, MES does not perform heavy-weight TLB invalidation after unmapping user queues. Add amdgpu_gmc_flush_gpu_tlb_pasid() after MES unmap succeeds in amdgpu_userq_unmap_helper() to ensure in-flight memory accesses complete before memory is freed or migrated.

Change-Id I94fe2c84547723b6b73816ce8d727a54bd773a6a
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0 -0
index 6d3ed55e9ab4..9fcf15d69b7b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue) · line 384

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +7 -0
@@ -375,6 +375,12 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue)
              } else {
                      trace_amdgpu_userq_state_changed(queue, AMDGPU_USERQ_STATE_UNMAPPED);
                      queue->state = AMDGPU_USERQ_STATE_UNMAPPED;
+                     /*
+                      * Heavy-weight TLB flush after MES unmaps queue to ensure
+                      * in-flight memory accesses complete before memory is freed/migrated.
+                      * MES does not do this automatically unlike HWS.
+                      */
+                     amdgpu_gmc_flush_gpu_tlb_pasid(adev,
+queue->vm->pasid, 2, true, 0);

Absolutely clear NAK to this.

The MES *must* guarantee that in flight memory accesses are completed before it unmaps the queue or otherwise we run into massive problems.

Flushing out any VM changes by invalidating the TLB doesn't change anything on that.

I tried this change during suspend but it dint help the case of tlb invalidation issues that we are facing.

regards
Sunil Khatri

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0 -0
              }
      }