Skip to contentSkip to conversation

drm/amdkfd: Make all TLB-flushes heavy-weight

PATCH In review Felix Kuehling 2 participants 4 messages Apr 20 – Apr 27

Subsystems (3)
lore
Share & tools
lore

Felix Kuehling

author maintainer
#0 lore raw

PATCH 1/1 drm/amdkfd: Make all TLB-flushes heavy-weight

With only one sequence number we cannot track the need for legacy vs heavy-weight flushes reliably. Always use heavy-weight.

---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c              | 4 ++--
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 6 +++---
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h                 | 6 +++---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c                  | 4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -2
index 16fb39259911..0625104a7693 100644
@@ -1358,7 +1358,7 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
 		peer_pdd = kfd_process_device_data_by_id(p, devices_arr[i]);
 		if (WARN_ON_ONCE(!peer_pdd))
 			continue;
-		kfd_flush_tlb(peer_pdd, TLB_FLUSH_LEGACY);
+		kfd_flush_tlb(peer_pdd);
 	}
 	kfree(devices_arr);
 
@@ -1453,7 +1453,7 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep,
 		if (WARN_ON_ONCE(!peer_pdd))
 			continue;
 		if (flush_tlb)
-			kfd_flush_tlb(peer_pdd, TLB_FLUSH_HEAVYWEIGHT);
+			kfd_flush_tlb(peer_pdd);
 
 		/* Remove dma mapping after tlb flush to avoid IO_PAGE_FAULT */
 		err = amdgpu_amdkfd_gpuvm_dmaunmap_mem(mem, peer_pdd->drm_priv);
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +3 -3
index c1f668f12732..8d9bf4334090 100644
@@ -595,7 +595,7 @@ static int allocate_vmid(struct device_queue_manager *dqm,
 			qpd->vmid,
 			qpd->page_table_base);
 	/* invalidate the VM context after pasid and vmid mapping is set up */
-	kfd_flush_tlb(qpd_to_pdd(qpd), TLB_FLUSH_LEGACY);
+	kfd_flush_tlb(qpd_to_pdd(qpd));
 
 	if (dqm->dev->kfd2kgd->set_scratch_backing_va)
 		dqm->dev->kfd2kgd->set_scratch_backing_va(dqm->dev->adev,
@@ -633,7 +633,7 @@ static void deallocate_vmid(struct device_queue_manager *dqm,
 		if (flush_texture_cache_nocpsch(q->device, qpd))
 			dev_err(dev, "Failed to flush TC\n");
 
-	kfd_flush_tlb(qpd_to_pdd(qpd), TLB_FLUSH_LEGACY);
+	kfd_flush_tlb(qpd_to_pdd(qpd));
 
 	/* Release the vmid mapping */
 	set_pasid_vmid_mapping(dqm, 0, qpd->vmid);
@@ -1307,7 +1307,7 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm,
 				dqm->dev->adev,
 				qpd->vmid,
 				qpd->page_table_base);
-		kfd_flush_tlb(pdd, TLB_FLUSH_LEGACY);
+		kfd_flush_tlb(pdd);
 	}
 
 	/* Take a safe reference to the mm_struct, which may otherwise
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -3
index 53c26b1a25ca..dc8787dc399b 100644
@@ -1559,13 +1559,13 @@ void kfd_signal_reset_event(struct kfd_node *dev);
 void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid);
 void kfd_signal_process_terminate_event(struct kfd_process *p);
 
-static inline void kfd_flush_tlb(struct kfd_process_device *pdd,
-				 enum TLB_FLUSH_TYPE type)
+static inline void kfd_flush_tlb(struct kfd_process_device *pdd)
 {
 	struct amdgpu_device *adev = pdd->dev->adev;
 	struct amdgpu_vm *vm = drm_priv_to_vm(pdd->drm_priv);
 
-	amdgpu_vm_flush_compute_tlb(adev, vm, type, pdd->dev->xcc_mask);
+	amdgpu_vm_flush_compute_tlb(adev, vm, TLB_FLUSH_HEAVYWEIGHT,
+				    pdd->dev->xcc_mask);
 }
 
 static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -2
index 015eb61f3440..5090f8c15428 100644
@@ -1418,7 +1418,7 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
 			if (r)
 				break;
 		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+		kfd_flush_tlb(pdd);
 	}
 
 	return r;
@@ -1560,7 +1560,7 @@ svm_range_map_to_gpus(struct svm_range *prange, unsigned long offset,
 			}
 		}
 
-		kfd_flush_tlb(pdd, TLB_FLUSH_LEGACY);
+		kfd_flush_tlb(pdd);
 	}
 
 	return r;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 10 lines · Felix Kuehling

With only one sequence number we cannot track the need for legacy vs heavy-weight flushes reliably. Always use heavy-weight.

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c              | 4 ++--
  drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 6 +++---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h                 | 6 +++---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c                  | 4 ++--
  4 files changed, 10 insertions(+), 10 deletions(-)

Probably change to heavy-weight flush in this path, other changes look good to me.

amdgpu_gem_va_update_vm()
 {
  ....
          if (vm->is_compute_context) {
            .....
                               r = amdgpu_vm_flush_compute_tlb(adev, vm, TLB_FLUSH_LEGACY,
                            xcc_mask);
}

Regards,
Philip

Quoted 96 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -2
index 16fb39259911..0625104a7693 100644
@@ -1358,7 +1358,7 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
  		peer_pdd = kfd_process_device_data_by_id(p, devices_arr[i]);
  		if (WARN_ON_ONCE(!peer_pdd))
  			continue;
-		kfd_flush_tlb(peer_pdd, TLB_FLUSH_LEGACY);
+		kfd_flush_tlb(peer_pdd);
  	}
  	kfree(devices_arr);
 
@@ -1453,7 +1453,7 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep,
  		if (WARN_ON_ONCE(!peer_pdd))
  			continue;
  		if (flush_tlb)
-			kfd_flush_tlb(peer_pdd, TLB_FLUSH_HEAVYWEIGHT);
+			kfd_flush_tlb(peer_pdd);
 
  		/* Remove dma mapping after tlb flush to avoid IO_PAGE_FAULT */
  		err = amdgpu_amdkfd_gpuvm_dmaunmap_mem(mem, peer_pdd->drm_priv);
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +3 -3
index c1f668f12732..8d9bf4334090 100644
@@ -595,7 +595,7 @@ static int allocate_vmid(struct device_queue_manager *dqm,
  			qpd->vmid,
  			qpd->page_table_base);
  	/* invalidate the VM context after pasid and vmid mapping is set up */
-	kfd_flush_tlb(qpd_to_pdd(qpd), TLB_FLUSH_LEGACY);
+	kfd_flush_tlb(qpd_to_pdd(qpd));
 
  	if (dqm->dev->kfd2kgd->set_scratch_backing_va)
  		dqm->dev->kfd2kgd->set_scratch_backing_va(dqm->dev->adev,
@@ -633,7 +633,7 @@ static void deallocate_vmid(struct device_queue_manager *dqm,
  		if (flush_texture_cache_nocpsch(q->device, qpd))
  			dev_err(dev, "Failed to flush TC\n");
 
-	kfd_flush_tlb(qpd_to_pdd(qpd), TLB_FLUSH_LEGACY);
+	kfd_flush_tlb(qpd_to_pdd(qpd));
 
  	/* Release the vmid mapping */
  	set_pasid_vmid_mapping(dqm, 0, qpd->vmid);
@@ -1307,7 +1307,7 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm,
  				dqm->dev->adev,
  				qpd->vmid,
  				qpd->page_table_base);
-		kfd_flush_tlb(pdd, TLB_FLUSH_LEGACY);
+		kfd_flush_tlb(pdd);
  	}
 
  	/* Take a safe reference to the mm_struct, which may otherwise
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -3
index 53c26b1a25ca..dc8787dc399b 100644
@@ -1559,13 +1559,13 @@ void kfd_signal_reset_event(struct kfd_node *dev);
  void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid);
  void kfd_signal_process_terminate_event(struct kfd_process *p);
 
-static inline void kfd_flush_tlb(struct kfd_process_device *pdd,
-				 enum TLB_FLUSH_TYPE type)
+static inline void kfd_flush_tlb(struct kfd_process_device *pdd)
  {
  	struct amdgpu_device *adev = pdd->dev->adev;
  	struct amdgpu_vm *vm = drm_priv_to_vm(pdd->drm_priv);
 
-	amdgpu_vm_flush_compute_tlb(adev, vm, type, pdd->dev->xcc_mask);
+	amdgpu_vm_flush_compute_tlb(adev, vm, TLB_FLUSH_HEAVYWEIGHT,
+				    pdd->dev->xcc_mask);
  }
 
  static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -2
index 015eb61f3440..5090f8c15428 100644
@@ -1418,7 +1418,7 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
  			if (r)
  				break;
  		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+		kfd_flush_tlb(pdd);
  	}
 
  	return r;
@@ -1560,7 +1560,7 @@ svm_range_map_to_gpus(struct svm_range *prange, unsigned long offset,
  			}
  		}
 
-		kfd_flush_tlb(pdd, TLB_FLUSH_LEGACY);
+		kfd_flush_tlb(pdd);
  	}
 
  	return r;
author maintainer
#2 lore raw
Quoted 15 lines · Philip Yang
Quoted 10 lines · Felix Kuehling

With only one sequence number we cannot track the need for legacy vs heavy-weight flushes reliably. Always use heavy-weight.

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c              | 4 ++--
  drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 6 +++---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h                 | 6 +++---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c                  | 4 ++--
  4 files changed, 10 insertions(+), 10 deletions(-)

Probably change to heavy-weight flush in this path, other changes look good to me.

Quoted 8 lines

amdgpu_gem_va_update_vm()
 {
  ....
          if (vm->is_compute_context) {
            .....
                               r = amdgpu_vm_flush_compute_tlb(adev, vm, TLB_FLUSH_LEGACY,
                            xcc_mask);

This code doesn't exist on the amd-staging-drm-next branch that this patch is intended for. I'll need to make a separate patch for the DKMS branch that includes this one.

Can I get your R-b for this patch?

Thanks,
  Felix

Quoted 101 lines

}

Regards,
Philip

Quoted 96 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +2 -2
index 16fb39259911..0625104a7693 100644
@@ -1358,7 +1358,7 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
  		peer_pdd = kfd_process_device_data_by_id(p, devices_arr[i]);
  		if (WARN_ON_ONCE(!peer_pdd))
  			continue;
-		kfd_flush_tlb(peer_pdd, TLB_FLUSH_LEGACY);
+		kfd_flush_tlb(peer_pdd);
  	}
  	kfree(devices_arr);
 
@@ -1453,7 +1453,7 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep,
  		if (WARN_ON_ONCE(!peer_pdd))
  			continue;
  		if (flush_tlb)
-			kfd_flush_tlb(peer_pdd, TLB_FLUSH_HEAVYWEIGHT);
+			kfd_flush_tlb(peer_pdd);
 
  		/* Remove dma mapping after tlb flush to avoid IO_PAGE_FAULT */
  		err = amdgpu_amdkfd_gpuvm_dmaunmap_mem(mem, peer_pdd->drm_priv);
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +3 -3
index c1f668f12732..8d9bf4334090 100644
@@ -595,7 +595,7 @@ static int allocate_vmid(struct device_queue_manager *dqm,
  			qpd->vmid,
  			qpd->page_table_base);
  	/* invalidate the VM context after pasid and vmid mapping is set up */
-	kfd_flush_tlb(qpd_to_pdd(qpd), TLB_FLUSH_LEGACY);
+	kfd_flush_tlb(qpd_to_pdd(qpd));
 
  	if (dqm->dev->kfd2kgd->set_scratch_backing_va)
  		dqm->dev->kfd2kgd->set_scratch_backing_va(dqm->dev->adev,
@@ -633,7 +633,7 @@ static void deallocate_vmid(struct device_queue_manager *dqm,
  		if (flush_texture_cache_nocpsch(q->device, qpd))
  			dev_err(dev, "Failed to flush TC\n");
 
-	kfd_flush_tlb(qpd_to_pdd(qpd), TLB_FLUSH_LEGACY);
+	kfd_flush_tlb(qpd_to_pdd(qpd));
 
  	/* Release the vmid mapping */
  	set_pasid_vmid_mapping(dqm, 0, qpd->vmid);
@@ -1307,7 +1307,7 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm,
  				dqm->dev->adev,
  				qpd->vmid,
  				qpd->page_table_base);
-		kfd_flush_tlb(pdd, TLB_FLUSH_LEGACY);
+		kfd_flush_tlb(pdd);
  	}
 
  	/* Take a safe reference to the mm_struct, which may otherwise
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -3
index 53c26b1a25ca..dc8787dc399b 100644
@@ -1559,13 +1559,13 @@ void kfd_signal_reset_event(struct kfd_node *dev);
  void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid);
  void kfd_signal_process_terminate_event(struct kfd_process *p);
 
-static inline void kfd_flush_tlb(struct kfd_process_device *pdd,
-				 enum TLB_FLUSH_TYPE type)
+static inline void kfd_flush_tlb(struct kfd_process_device *pdd)
  {
  	struct amdgpu_device *adev = pdd->dev->adev;
  	struct amdgpu_vm *vm = drm_priv_to_vm(pdd->drm_priv);
 
-	amdgpu_vm_flush_compute_tlb(adev, vm, type, pdd->dev->xcc_mask);
+	amdgpu_vm_flush_compute_tlb(adev, vm, TLB_FLUSH_HEAVYWEIGHT,
+				    pdd->dev->xcc_mask);
  }
 
  static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -2
index 015eb61f3440..5090f8c15428 100644
@@ -1418,7 +1418,7 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
  			if (r)
  				break;
  		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+		kfd_flush_tlb(pdd);
  	}
 
  	return r;
@@ -1560,7 +1560,7 @@ svm_range_map_to_gpus(struct svm_range *prange, unsigned long offset,
  			}
  		}
 
-		kfd_flush_tlb(pdd, TLB_FLUSH_LEGACY);
+		kfd_flush_tlb(pdd);
  	}
 
  	return r;
Reviewed-by
#3 lore raw
Quoted 25 lines · Felix Kuehling
Quoted 15 lines · Philip Yang
Quoted 10 lines · Felix Kuehling

With only one sequence number we cannot track the need for legacy vs heavy-weight flushes reliably. Always use heavy-weight.

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c              | 4 ++-- drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 6 +++--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h                 | 6 +++--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c                  | 4 ++--

  4 files changed, 10 insertions(+), 10 deletions(-)

Probably change to heavy-weight flush in this path, other changes look good to me.

Quoted 8 lines

amdgpu_gem_va_update_vm()
 {
  ....
          if (vm->is_compute_context) {
            .....
                               r = amdgpu_vm_flush_compute_tlb(adev, vm, TLB_FLUSH_LEGACY,
                            xcc_mask);

Quoted 3 lines

This code doesn't exist on the amd-staging-drm-next branch that this patch is intended for. I'll need to make a separate patch for the DKMS branch that includes this one.

Can I get your R-b for this patch?

ohh, I checked the DKMS branch as I am working on it. For amd-staging-drm-next branch, this patch is

Quoted 101 lines

Thanks,
  Felix

Quoted 96 lines

}

Regards,
Philip

Quoted 91 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -1
index 16fb39259911..0625104a7693 100644
@@ -1358,7 +1358,7 @@ static int kfd_ioctl_map_memory_to_gpu(struct 
 file *filep,
           peer_pdd = kfd_process_device_data_by_id(p, devices_arr[i]);
           if (WARN_ON_ONCE(!peer_pdd))
               continue;
-        kfd_flush_tlb(peer_pdd, TLB_FLUSH_LEGACY);
+        kfd_flush_tlb(peer_pdd);
       }
       kfree(devices_arr);

  @@ -1453,7 +1453,7 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep, if (WARN_ON_ONCE(!peer_pdd))
              continue;
          if (flush_tlb)
-            kfd_flush_tlb(peer_pdd, TLB_FLUSH_HEAVYWEIGHT);
+            kfd_flush_tlb(peer_pdd);
            /* Remove dma mapping after tlb flush to avoid IO_PAGE_FAULT */ err = amdgpu_amdkfd_gpuvm_dmaunmap_mem(mem, peer_pdd->drm_priv);

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +3 -2
index c1f668f12732..8d9bf4334090 100644
@@ -595,7 +595,7 @@ static int allocate_vmid(struct 
 device_queue_manager *dqm,
               qpd->vmid,
               qpd->page_table_base);
       /* invalidate the VM context after pasid and vmid mapping is set up */
-    kfd_flush_tlb(qpd_to_pdd(qpd), TLB_FLUSH_LEGACY);
+    kfd_flush_tlb(qpd_to_pdd(qpd));
         if (dqm->dev->kfd2kgd->set_scratch_backing_va)
 dqm->dev->kfd2kgd->set_scratch_backing_va(dqm->dev->adev,
@@ -633,7 +633,7 @@ static void deallocate_vmid(struct 
 device_queue_manager *dqm,
           if (flush_texture_cache_nocpsch(q->device, qpd))
               dev_err(dev, "Failed to flush TC\n");
   -    kfd_flush_tlb(qpd_to_pdd(qpd), TLB_FLUSH_LEGACY);
+    kfd_flush_tlb(qpd_to_pdd(qpd));
         /* Release the vmid mapping */
       set_pasid_vmid_mapping(dqm, 0, qpd->vmid);
@@ -1307,7 +1307,7 @@ static int 
 restore_process_queues_nocpsch(struct device_queue_manager *dqm,
                   dqm->dev->adev,
                   qpd->vmid,
                   qpd->page_table_base);
-        kfd_flush_tlb(pdd, TLB_FLUSH_LEGACY);
+        kfd_flush_tlb(pdd);
       }
         /* Take a safe reference to the mm_struct, which may otherwise
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -1
index 53c26b1a25ca..dc8787dc399b 100644
@@ -1559,13 +1559,13 @@ void kfd_signal_reset_event(struct kfd_node 
 *dev);
   void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid);
   void kfd_signal_process_terminate_event(struct kfd_process *p);
   -static inline void kfd_flush_tlb(struct kfd_process_device *pdd,
-                 enum TLB_FLUSH_TYPE type)
+static inline void kfd_flush_tlb(struct kfd_process_device *pdd)
   {
       struct amdgpu_device *adev = pdd->dev->adev;
       struct amdgpu_vm *vm = drm_priv_to_vm(pdd->drm_priv);
   -    amdgpu_vm_flush_compute_tlb(adev, vm, type, pdd->dev->xcc_mask);
+    amdgpu_vm_flush_compute_tlb(adev, vm, TLB_FLUSH_HEAVYWEIGHT,
+                    pdd->dev->xcc_mask);
   }
     static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -1
index 015eb61f3440..5090f8c15428 100644
@@ -1418,7 +1418,7 @@ svm_range_unmap_from_gpus(struct svm_range 
 *prange, unsigned long start,
               if (r)
                   break;
           }
-        kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+        kfd_flush_tlb(pdd);
       }
         return r;
@@ -1560,7 +1560,7 @@ svm_range_map_to_gpus(struct svm_range 
 *prange, unsigned long offset,
               }
           }
   -        kfd_flush_tlb(pdd, TLB_FLUSH_LEGACY);
+        kfd_flush_tlb(pdd);
       }
         return r;