Skip to contentSkip to conversation

drm/amdkfd: only allow heavy-weight TLB flush on some ASICs for SVM too

PATCH In review Lang Yu 4 participants 10 messages Apr 14, 2022 – Apr 15, 2022

Subsystems (3)
lore
Share & tools
lore

Lang Yu

author
#0 lore raw

PATCH 1/1 drm/amdkfd: only allow heavy-weight TLB flush on some ASICs for SVM too

The idea is from commit a50fe7078035 ("drm/amdkfd: Only apply heavy-weight TLB flush on Aldebaran") and commit f61c40c0757a ("drm/amdkfd: enable heavy-weight TLB flush on Arcturus"). Otherwise, we will run into problems on some ASICs when running SVM applications.

---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 --------
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 8 ++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 4 +++-
 3 files changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -8
index 91f82a9ccdaf..459f59e3d0ed 100644
@@ -1128,14 +1128,6 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,
 	return ret;
 }
 
-static bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
-{
-	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
-		(KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
-		dev->adev->sdma.instance[0].fw_version >= 18) ||
-		KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
-}
-
 static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
 					struct kfd_process *p, void *data)
 {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -0
index 8a43def1f638..aff6f598ff2c 100644
@@ -1328,6 +1328,14 @@ void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid);
 
 void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
 
+static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
+{
+	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
+	       (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
+	       dev->adev->sdma.instance[0].fw_version >= 18) ||
+	       KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
+}
+
 bool kfd_is_locked(void);
 
 /* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -1
index 459fa07a3bcc..5afe216cf099 100644
@@ -1229,7 +1229,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
 			if (r)
 				break;
 		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+
+		if (kfd_flush_tlb_after_unmap(pdd->dev))
+			kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
 	}
 
 	return r;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 37 lines · Lang Yu

The idea is from commit a50fe7078035 ("drm/amdkfd: Only apply heavy-weight TLB flush on Aldebaran") and commit f61c40c0757a ("drm/amdkfd: enable heavy-weight TLB flush on Arcturus"). Otherwise, we will run into problems on some ASICs when running SVM applications.

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 --------
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 8 ++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 4 +++-
  3 files changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -8
index 91f82a9ccdaf..459f59e3d0ed 100644
@@ -1128,14 +1128,6 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,
  	return ret;
  }
 
-static bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
-{
-	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
-		(KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
-		dev->adev->sdma.instance[0].fw_version >= 18) ||
-		KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
-}
-
  static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
  					struct kfd_process *p, void *data)
  {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
index 8a43def1f638..aff6f598ff2c 100644
@@ -1328,6 +1328,14 @@ void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid);
 

drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid); · line 1338

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -0
  void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
 
+static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
+{
+	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
+	       (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
+	       dev->adev->sdma.instance[0].fw_version >= 18) ||
+	       KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
+}
+

It is a cosmetic change for function kfd_flush_tlb_after_unmap, and not related to the topic. You can separate that into another patch.

Regards,
Eric

Quoted 18 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
  bool kfd_is_locked(void);
 
  /* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -1
index 459fa07a3bcc..5afe216cf099 100644
@@ -1229,7 +1229,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
  			if (r)
  				break;
  		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+
+		if (kfd_flush_tlb_after_unmap(pdd->dev))
+			kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
  	}
 
  	return r;
author
#2 lore raw
Quoted 41 lines · Eric Huang
Quoted 38 lines · Lang Yu

The idea is from commit a50fe7078035 ("drm/amdkfd: Only apply heavy-weight TLB flush on Aldebaran") and commit f61c40c0757a ("drm/amdkfd: enable heavy-weight TLB flush on Arcturus"). Otherwise, we will run into problems on some ASICs when running SVM applications.

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 --------
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 8 ++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 4 +++-
  3 files changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -8
index 91f82a9ccdaf..459f59e3d0ed 100644
@@ -1128,14 +1128,6 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,
  	return ret;
  }
-static bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
-{
-	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
-		(KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
-		dev->adev->sdma.instance[0].fw_version >= 18) ||
-		KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
-}
-
  static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
  					struct kfd_process *p, void *data)
  {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +2 -0
index 8a43def1f638..aff6f598ff2c 100644
@@ -1328,6 +1328,14 @@ void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid);
  void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
+static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
+{
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid); · line 1338

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6 -0
+	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
+	       (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
+	       dev->adev->sdma.instance[0].fw_version >= 18) ||
+	       KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
+}
+

It is a cosmetic change for function kfd_flush_tlb_after_unmap, and not related to the topic. You can separate that into another patch.

Okay. Thanks.

Regards,
Lang

Quoted 19 lines

Regards,
Eric

Quoted 16 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
  bool kfd_is_locked(void);
  /* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -1
index 459fa07a3bcc..5afe216cf099 100644
@@ -1229,7 +1229,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
  			if (r)
  				break;
  		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+
+		if (kfd_flush_tlb_after_unmap(pdd->dev))
+			kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
  	}
  	return r;
maintainer
#3 lore raw
In reply to Lang Yu

Am 2022-04-14 um 04:19 schrieb Lang Yu:

Quoted 55 lines

The idea is from commit a50fe7078035 ("drm/amdkfd: Only apply heavy-weight TLB flush on Aldebaran") and commit f61c40c0757a ("drm/amdkfd: enable heavy-weight TLB flush on Arcturus"). Otherwise, we will run into problems on some ASICs when running SVM applications.

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 --------
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 8 ++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 4 +++-
  3 files changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -8
index 91f82a9ccdaf..459f59e3d0ed 100644
@@ -1128,14 +1128,6 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,
  	return ret;
  }
 
-static bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
-{
-	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
-		(KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
-		dev->adev->sdma.instance[0].fw_version >= 18) ||
-		KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
-}
-
  static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
  					struct kfd_process *p, void *data)
  {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -0
index 8a43def1f638..aff6f598ff2c 100644
@@ -1328,6 +1328,14 @@ void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid);
 
  void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
 
+static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
+{
+	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
+	       (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
+	       dev->adev->sdma.instance[0].fw_version >= 18) ||
+	       KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
+}
+
  bool kfd_is_locked(void);
 
  /* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 459fa07a3bcc..5afe216cf099 100644

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start, · line 1234

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -1
@@ -1229,7 +1229,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
  			if (r)
  				break;
  		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+
+		if (kfd_flush_tlb_after_unmap(pdd->dev))
+			kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);

Then you probably need to add another flush_tlb call in svm_range_map_to_gpus.

Regards,
  Felix

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
  	}
 
  	return r;
author
#4 lore raw
Quoted 55 lines · Felix Kuehling

Am 2022-04-14 um 04:19 schrieb Lang Yu:

Quoted 53 lines

The idea is from commit a50fe7078035 ("drm/amdkfd: Only apply heavy-weight TLB flush on Aldebaran") and commit f61c40c0757a ("drm/amdkfd: enable heavy-weight TLB flush on Arcturus"). Otherwise, we will run into problems on some ASICs when running SVM applications.

---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 --------
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 8 ++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 4 +++-
  3 files changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -8
index 91f82a9ccdaf..459f59e3d0ed 100644
@@ -1128,14 +1128,6 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,
  	return ret;
  }
-static bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
-{
-	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
-		(KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
-		dev->adev->sdma.instance[0].fw_version >= 18) ||
-		KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
-}
-
  static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
  					struct kfd_process *p, void *data)
  {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -0
index 8a43def1f638..aff6f598ff2c 100644
@@ -1328,6 +1328,14 @@ void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid);
  void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
+static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
+{
+	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
+	       (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
+	       dev->adev->sdma.instance[0].fw_version >= 18) ||
+	       KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
+}
+
  bool kfd_is_locked(void);
  /* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 459fa07a3bcc..5afe216cf099 100644
@@ -1229,7 +1229,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
  			if (r)
  				break;
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start, · line 1234

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -1
  		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+
+		if (kfd_flush_tlb_after_unmap(pdd->dev))
+			kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);

Then you probably need to add another flush_tlb call in svm_range_map_to_gpus.

There is a TLB_FLUSH_LEGACY call in svm_range_map_to_gpus same with kfd_ioctl_map_memory_to_gpu. Do we still need to add another one?

Regards,
Lang

Quoted 6 lines

Regards,
  Felix

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
  	}
  	return r;
maintainer Reviewed-by
#5 lore raw

Am 2022-04-14 um 22:47 schrieb Lang Yu:

Quoted 62 lines · Felix Kuehling
Quoted 53 lines

Am 2022-04-14 um 04:19 schrieb Lang Yu:

Quoted 52 lines

The idea is from commit a50fe7078035 ("drm/amdkfd: Only apply heavy-weight TLB flush on Aldebaran") and commit f61c40c0757a ("drm/amdkfd: enable heavy-weight TLB flush on Arcturus"). Otherwise, we will run into problems on some ASICs when running SVM applications.

---
   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 --------
   drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 8 ++++++++
   drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 4 +++-
   3 files changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -8
index 91f82a9ccdaf..459f59e3d0ed 100644
@@ -1128,14 +1128,6 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,
   	return ret;
   }
-static bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
-{
-	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
-		(KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
-		dev->adev->sdma.instance[0].fw_version >= 18) ||
-		KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
-}
-
   static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
   					struct kfd_process *p, void *data)
   {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -0
index 8a43def1f638..aff6f598ff2c 100644
@@ -1328,6 +1328,14 @@ void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid);
   void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
+static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
+{
+	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
+	       (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
+	       dev->adev->sdma.instance[0].fw_version >= 18) ||
+	       KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
+}
+
   bool kfd_is_locked(void);
   /* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 459fa07a3bcc..5afe216cf099 100644
@@ -1229,7 +1229,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
   			if (r)
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start, · line 1234

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -1
   				break;
   		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+
+		if (kfd_flush_tlb_after_unmap(pdd->dev))
+			kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);

Then you probably need to add another flush_tlb call in svm_range_map_to_gpus.

Quoted 2 lines

There is a TLB_FLUSH_LEGACY call in svm_range_map_to_gpus same with kfd_ioctl_map_memory_to_gpu. Do we still need to add another one?

Right, I missed that one. I think that should cover it and the patch looks good to me.

Quoted 10 lines

Regards,
Lang

Quoted 6 lines

Regards,
  Felix

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
   	}
   	return r;
#6 lore raw
In reply to Lang Yu

Dear Lang,

Thank you for the patch.

Am 14.04.22 um 10:19 schrieb Lang Yu:

Quoted 4 lines

The idea is from commit a50fe7078035 ("drm/amdkfd: Only apply heavy-weight TLB flush on Aldebaran") and commit f61c40c0757a ("drm/amdkfd: enable heavy-weight TLB flush on Arcturus"). Otherwise, we will run into problems on some ASICs when running SVM applications.

Please list the ASICs, you know of having problems, and even add how to reproduce this.

Kind regards,

Paul

Quoted 60 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 --------
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 8 ++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 4 +++-
  3 files changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -8
index 91f82a9ccdaf..459f59e3d0ed 100644
@@ -1128,14 +1128,6 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,
  	return ret;
  }
 
-static bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
-{
-	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
-		(KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
-		dev->adev->sdma.instance[0].fw_version >= 18) ||
-		KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
-}
-
  static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
  					struct kfd_process *p, void *data)
  {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -0
index 8a43def1f638..aff6f598ff2c 100644
@@ -1328,6 +1328,14 @@ void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid);
 
  void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
 
+static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
+{
+	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
+	       (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
+	       dev->adev->sdma.instance[0].fw_version >= 18) ||
+	       KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
+}
+
  bool kfd_is_locked(void);
 
  /* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -1
index 459fa07a3bcc..5afe216cf099 100644
@@ -1229,7 +1229,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
  			if (r)
  				break;
  		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+
+		if (kfd_flush_tlb_after_unmap(pdd->dev))
+			kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
  	}
 
  	return r;
author
#7 lore raw
Quoted 5 lines · Paul Menzel

Dear Lang,

Thank you for the patch.

Quoted 8 lines

Am 14.04.22 um 10:19 schrieb Lang Yu:

Quoted 4 lines

The idea is from commit a50fe7078035 ("drm/amdkfd: Only apply heavy-weight TLB flush on Aldebaran") and commit f61c40c0757a ("drm/amdkfd: enable heavy-weight TLB flush on Arcturus"). Otherwise, we will run into problems on some ASICs when running SVM applications.

Please list the ASICs, you know of having problems, and even add how to reproduce this.

Actually, this is ported from previous commits. You can find more details from the commits I mentioned. At the moment the ASICs except Aldebaran and Arcturus probably have the problem. And running a SVM application could reproduce the issue.

Thanks,
Lang

Quoted 61 lines

Kind regards,

Paul

Quoted 55 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 --------
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 8 ++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 4 +++-
  3 files changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -8
index 91f82a9ccdaf..459f59e3d0ed 100644
@@ -1128,14 +1128,6 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,
  	return ret;
  }
-static bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
-{
-	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
-		(KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
-		dev->adev->sdma.instance[0].fw_version >= 18) ||
-		KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
-}
-
  static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
  					struct kfd_process *p, void *data)
  {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -0
index 8a43def1f638..aff6f598ff2c 100644
@@ -1328,6 +1328,14 @@ void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid);
  void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
+static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
+{
+	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
+	       (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
+	       dev->adev->sdma.instance[0].fw_version >= 18) ||
+	       KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
+}
+
  bool kfd_is_locked(void);
  /* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -1
index 459fa07a3bcc..5afe216cf099 100644
@@ -1229,7 +1229,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
  			if (r)
  				break;
  		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+
+		if (kfd_flush_tlb_after_unmap(pdd->dev))
+			kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
  	}
  	return r;
#8 lore raw

Dear Lang,

Am 15.04.22 um 05:20 schrieb Lang Yu:

Quoted 8 lines · Paul Menzel
Quoted 7 lines

Am 14.04.22 um 10:19 schrieb Lang Yu:

Quoted 4 lines

The idea is from commit a50fe7078035 ("drm/amdkfd: Only apply heavy-weight TLB flush on Aldebaran") and commit f61c40c0757a ("drm/amdkfd: enable heavy-weight TLB flush on Arcturus"). Otherwise, we will run into problems on some ASICs when running SVM applications.

Quoted 6 lines
Quoted 2 lines

Please list the ASICs, you know of having problems, and even add how to reproduce this.

Actually, this is ported from previous commits. You can find more details from the commits I mentioned. At the moment the ASICs except Aldebaran and Arcturus probably have the problem.

I think, it’s always good to make it as easy as possible for reviewers and, later, people reading a commit, and include the necessary information directly in the commit message. It’d be great if you amended the commit message.

Quoted 1 line

And running a SVM application could reproduce the issue.

Thanks. How will it fail though?

(Also, a small implementation note would be nice to have. Maybe: Move the helper function into the header kfd_priv.h, and use in svm_range_unmap_from_gpus().)

Kind regards,

Paul

Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
---
   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 --------
   drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 8 ++++++++
   drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 4 +++-
   3 files changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -8
index 91f82a9ccdaf..459f59e3d0ed 100644
@@ -1128,14 +1128,6 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,
   	return ret;
   }
-static bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
-{
-	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
-		(KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
-		dev->adev->sdma.instance[0].fw_version >= 18) ||
-		KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
-}
-
   static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
   					struct kfd_process *p, void *data)
   {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -0
index 8a43def1f638..aff6f598ff2c 100644
@@ -1328,6 +1328,14 @@ void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid);
   void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
+static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
+{
+	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
+	       (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
+	       dev->adev->sdma.instance[0].fw_version >= 18) ||
+	       KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
+}
+
   bool kfd_is_locked(void);
   /* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -1
index 459fa07a3bcc..5afe216cf099 100644
@@ -1229,7 +1229,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
   			if (r)
   				break;
   		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+
+		if (kfd_flush_tlb_after_unmap(pdd->dev))
+			kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
   	}
   	return r;
author
#9 lore raw
Quoted 15 lines · Paul Menzel

Dear Lang,

Am 15.04.22 um 05:20 schrieb Lang Yu:

Quoted 11 lines · Paul Menzel
Quoted 9 lines

Am 14.04.22 um 10:19 schrieb Lang Yu:

Quoted 4 lines

The idea is from commit a50fe7078035 ("drm/amdkfd: Only apply heavy-weight TLB flush on Aldebaran") and commit f61c40c0757a ("drm/amdkfd: enable heavy-weight TLB flush on Arcturus"). Otherwise, we will run into problems on some ASICs when running SVM applications.

Please list the ASICs, you know of having problems, and even add how to reproduce this.

Quoted 8 lines
Quoted 3 lines

Actually, this is ported from previous commits. You can find more details from the commits I mentioned. At the moment the ASICs except Aldebaran and Arcturus probably have the problem.

I think, it’s always good to make it as easy as possible for reviewers and, later, people reading a commit, and include the necessary information directly in the commit message. It’d be great if you amended the commit message.

Yes, I agree with you. Will amended the commit message.

Quoted 3 lines
Quoted 1 line

And running a SVM application could reproduce the issue.

Thanks. How will it fail though?

Will describe more details in commit message.

Quoted 3 lines

(Also, a small implementation note would be nice to have. Maybe: Move the helper function into the header kfd_priv.h, and use in svm_range_unmap_from_gpus().)

Will separate this change into another patch suggested by Eric.

Thanks,
Lang

Quoted 60 lines

Kind regards,

Paul

Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
---
   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 8 --------
   drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 8 ++++++++
   drivers/gpu/drm/amd/amdkfd/kfd_svm.c     | 4 +++-
   3 files changed, 11 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -8
index 91f82a9ccdaf..459f59e3d0ed 100644
@@ -1128,14 +1128,6 @@ static int kfd_ioctl_free_memory_of_gpu(struct file *filep,
   	return ret;
   }
-static bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
-{
-	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
-		(KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
-		dev->adev->sdma.instance[0].fw_version >= 18) ||
-		KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
-}
-
   static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
   					struct kfd_process *p, void *data)
   {
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +8 -0
index 8a43def1f638..aff6f598ff2c 100644
@@ -1328,6 +1328,14 @@ void kfd_signal_poison_consumed_event(struct kfd_dev *dev, u32 pasid);
   void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
+static inline bool kfd_flush_tlb_after_unmap(struct kfd_dev *dev)
+{
+	return KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
+	       (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 1) &&
+	       dev->adev->sdma.instance[0].fw_version >= 18) ||
+	       KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 0);
+}
+
   bool kfd_is_locked(void);
   /* Compute profile */
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -1
index 459fa07a3bcc..5afe216cf099 100644
@@ -1229,7 +1229,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
   			if (r)
   				break;
   		}
-		kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
+
+		if (kfd_flush_tlb_after_unmap(pdd->dev))
+			kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT);
   	}
   	return r;