Skip to contentSkip to conversation

drm/amdkfd: Use huge page size to check split svm range alignment

PATCH Superseded Xiaogang.Chen 3 participants 5 messages Nov 13, 2025 – Nov 17, 2025

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/amdkfd: Use huge page size to check split svm range alignment

From: Xiaogang Chen <[email protected]>

Fixes 7ef6b2d4b7e5 (drm/amdkfd: remap unaligned svm ranges that have split)

When split svm ranges that have been mapped using huge page should use huge page size(2MB) to check split range alignment, not prange->granularity that means migration granularity.

---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +12 -4
index 521c14c7a789..c60d8134db45 100644
@@ -1146,11 +1146,14 @@ svm_range_split_tail(struct svm_range *prange, uint64_t new_last,
 {
 	struct svm_range *tail = NULL;
 	int r = svm_range_split(prange, prange->start, new_last, &tail);
+	bool huge_page_mapping = IS_ALIGNED(prange->start, 512);
 
 	if (!r) {
 		list_add(&tail->list, insert_list);
-		if (!IS_ALIGNED(new_last + 1, 1UL << prange->granularity))
-			list_add(&tail->update_list, remap_list);
+		if (huge_page_mapping) {
+			if (!IS_ALIGNED(tail->start, 512))
+				list_add(&tail->update_list, remap_list);
+		}
 	}
 	return r;
 }
@@ -1162,11 +1165,16 @@ svm_range_split_head(struct svm_range *prange, uint64_t new_start,
 	struct svm_range *head = NULL;
 	int r = svm_range_split(prange, new_start, prange->last, &head);
 
+	bool huge_page_mapping = IS_ALIGNED(prange->start, 512);
+
 	if (!r) {
 		list_add(&head->list, insert_list);
-		if (!IS_ALIGNED(new_start, 1UL << prange->granularity))
-			list_add(&head->update_list, remap_list);
+		if (huge_page_mapping) {
+			if (!IS_ALIGNED(prange->start, 512))
+				list_add(&head->update_list, remap_list);
+		}
 	}
+
 	return r;
 }
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 18 lines · Xiaogang.Chen

From: Xiaogang Chen <[email protected]>

Fixes 7ef6b2d4b7e5 (drm/amdkfd: remap unaligned svm ranges that have split)

When split svm ranges that have been mapped using huge page should use huge page size(2MB) to check split range alignment, not prange->granularity that means migration granularity.

---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 521c14c7a789..c60d8134db45 100644

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_tail(struct svm_range *prange, uint64_t new_last, · line 1149

Quoted 4 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -0
@@ -1146,11 +1146,14 @@ svm_range_split_tail(struct svm_range *prange, uint64_t new_last,
  {
  	struct svm_range *tail = NULL;
  	int r = svm_range_split(prange, prange->start, new_last, &tail);
+	bool huge_page_mapping = IS_ALIGNED(prange->start, 512);

Instead of hard-coding 512 here, it would be more future-proof to call amdgpu_vm_pt_num_entries(adev, AMDGPU_VM_PDB0). That's currently a static function in amdgpu_vm_pt.c. Christian, would you object to making that non-static?

Also, to improve the check whether the range can really use huge pages, you could add a check that it's size is at least 512 pages.

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_tail(struct svm_range *prange, uint64_t new_last, · line 1154

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -2
  	if (!r) {
  		list_add(&tail->list, insert_list);
-		if (!IS_ALIGNED(new_last + 1, 1UL << prange->granularity))
-			list_add(&tail->update_list, remap_list);
+		if (huge_page_mapping) {
+			if (!IS_ALIGNED(tail->start, 512))

Make that one condition: if (huge_page_mapping && !IS_ALIGNED...)

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_head(struct svm_range *prange, uint64_t new_start, · line 1168

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -0
+				list_add(&tail->update_list, remap_list);
+		}
  	}
  	return r;
  }
@@ -1162,11 +1165,16 @@ svm_range_split_head(struct svm_range *prange, uint64_t new_start,
  	struct svm_range *head = NULL;
  	int r = svm_range_split(prange, new_start, prange->last, &head);
 
+	bool huge_page_mapping = IS_ALIGNED(prange->start, 512);

Why the blank line before huge_page_mapping? It's part of your variable declarations.

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_head(struct svm_range *prange, uint64_t new_start, · line 1173

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -2
+
  	if (!r) {
  		list_add(&head->list, insert_list);
-		if (!IS_ALIGNED(new_start, 1UL << prange->granularity))
-			list_add(&head->update_list, remap_list);
+		if (huge_page_mapping) {
+			if (!IS_ALIGNED(prange->start, 512))

Same as above.

Regards,
  Felix

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -0
+				list_add(&head->update_list, remap_list);
+		}
  	}
+
  	return r;
  }
 
#2 lore raw
Quoted 15 lines · Felix Kuehling
Quoted 13 lines · Xiaogang.Chen

From: Xiaogang Chen <[email protected]>

Fixes 7ef6b2d4b7e5 (drm/amdkfd: remap unaligned svm ranges that have split)

When split svm ranges that have been mapped using huge page should use huge page size(2MB) to check split range alignment, not prange->granularity that means migration granularity.

---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 16 ++++++++++++----

  1 file changed, 12 insertions(+), 4 deletions(-)
Quoted 12 lines

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_tail(struct svm_range · line 1150

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -0
index 521c14c7a789..c60d8134db45 100644
@@ -1146,11 +1146,14 @@ svm_range_split_tail(struct svm_range 
 *prange, uint64_t new_last,
   {
       struct svm_range *tail = NULL;
       int r = svm_range_split(prange, prange->start, new_last, &tail);
+    bool huge_page_mapping = IS_ALIGNED(prange->start, 512);

Instead of hard-coding 512 here, it would be more future-proof to call amdgpu_vm_pt_num_entries(adev, AMDGPU_VM_PDB0). That's currently a static function in amdgpu_vm_pt.c. Christian, would you object to making that non-static?

We don't have method to know if prange has huge page mapping which depends on virtual address 2MB align and physical address contiguous, it is decided inside amdgpu_vm_ptes_update. Even prange->start is not 2MB align, prange could have huge page mapping.

Regards,

Philip

Quoted 49 lines

Also, to improve the check whether the range can really use huge pages, you could add a check that it's size is at least 512 pages.

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_tail(struct svm_range *prange, uint64_t new_last, · line 1154

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -2
         if (!r) {
           list_add(&tail->list, insert_list);
-        if (!IS_ALIGNED(new_last + 1, 1UL << prange->granularity))
-            list_add(&tail->update_list, remap_list);
+        if (huge_page_mapping) {
+            if (!IS_ALIGNED(tail->start, 512))

Make that one condition: if (huge_page_mapping && !IS_ALIGNED...)

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_head(struct svm_range · line 1168

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -0
+ list_add(&tail->update_list, remap_list);
+        }
       }
       return r;
   }
@@ -1162,11 +1165,16 @@ svm_range_split_head(struct svm_range 
 *prange, uint64_t new_start,
       struct svm_range *head = NULL;
       int r = svm_range_split(prange, new_start, prange->last, &head);
   +    bool huge_page_mapping = IS_ALIGNED(prange->start, 512);

Why the blank line before huge_page_mapping? It's part of your variable declarations.

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_head(struct svm_range *prange, uint64_t new_start, · line 1173

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -2
+
       if (!r) {
           list_add(&head->list, insert_list);
-        if (!IS_ALIGNED(new_start, 1UL << prange->granularity))
-            list_add(&head->update_list, remap_list);
+        if (huge_page_mapping) {
+            if (!IS_ALIGNED(prange->start, 512))

Same as above.

Regards,
  Felix

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -0
+ list_add(&head->update_list, remap_list);
+        }
       }
+
       return r;
   }
maintainer
#3 lore raw
Quoted 30 lines · Philip Yang
Quoted 15 lines · Felix Kuehling
Quoted 13 lines · Xiaogang.Chen

From: Xiaogang Chen <[email protected]>

Fixes 7ef6b2d4b7e5 (drm/amdkfd: remap unaligned svm ranges that have split)

When split svm ranges that have been mapped using huge page should use huge page size(2MB) to check split range alignment, not prange->granularity that means migration granularity.

---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 16 ++++++++++++----

  1 file changed, 12 insertions(+), 4 deletions(-)
Quoted 12 lines

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_tail(struct svm_range · line 1150

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -0
index 521c14c7a789..c60d8134db45 100644
@@ -1146,11 +1146,14 @@ svm_range_split_tail(struct svm_range 
 *prange, uint64_t new_last,
   {
       struct svm_range *tail = NULL;
       int r = svm_range_split(prange, prange->start, new_last, &tail);
+    bool huge_page_mapping = IS_ALIGNED(prange->start, 512);

Instead of hard-coding 512 here, it would be more future-proof to call amdgpu_vm_pt_num_entries(adev, AMDGPU_VM_PDB0). That's currently a static function in amdgpu_vm_pt.c. Christian, would you object to making that non-static?

Quoted 1 line

We don't have method to know if prange has huge page mapping which depends on virtual address 2MB align and physical address contiguous, it is decided inside amdgpu_vm_ptes_update. Even prange->start is not 2MB align, prange could have huge page mapping.

Right, I guess the correct condition would check that the range contains at least one potential huge page. I.e., the start address aligned up to 2MB is larger and the end address aligned down to 2MB. And the unaligned split is between those two aligned addresses.

Regards,
  Felix

Quoted 54 lines

Regards,

Philip

Quoted 49 lines

Also, to improve the check whether the range can really use huge pages, you could add a check that it's size is at least 512 pages.

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_tail(struct svm_range *prange, uint64_t new_last, · line 1154

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -2
         if (!r) {
           list_add(&tail->list, insert_list);
-        if (!IS_ALIGNED(new_last + 1, 1UL << prange->granularity))
-            list_add(&tail->update_list, remap_list);
+        if (huge_page_mapping) {
+            if (!IS_ALIGNED(tail->start, 512))

Make that one condition: if (huge_page_mapping && !IS_ALIGNED...)

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_head(struct svm_range · line 1168

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -0
+ list_add(&tail->update_list, remap_list);
+        }
       }
       return r;
   }
@@ -1162,11 +1165,16 @@ svm_range_split_head(struct svm_range 
 *prange, uint64_t new_start,
       struct svm_range *head = NULL;
       int r = svm_range_split(prange, new_start, prange->last, &head);
   +    bool huge_page_mapping = IS_ALIGNED(prange->start, 512);

Why the blank line before huge_page_mapping? It's part of your variable declarations.

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_head(struct svm_range *prange, uint64_t new_start, · line 1173

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -2
+
       if (!r) {
           list_add(&head->list, insert_list);
-        if (!IS_ALIGNED(new_start, 1UL << prange->granularity))
-            list_add(&head->update_list, remap_list);
+        if (huge_page_mapping) {
+            if (!IS_ALIGNED(prange->start, 512))

Same as above.

Regards,
  Felix

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -0
+ list_add(&head->update_list, remap_list);
+        }
       }
+
       return r;
   }
#4 lore raw
Quoted 31 lines · Felix
Quoted 30 lines · Philip Yang
Quoted 27 lines · Felix Kuehling
Quoted 18 lines · Xiaogang.Chen

From: Xiaogang Chen <[email protected]>

Fixes 7ef6b2d4b7e5 (drm/amdkfd: remap unaligned svm ranges that have split)

When split svm ranges that have been mapped using huge page should use huge page size(2MB) to check split range alignment, not prange->granularity that means migration granularity.

---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 16 ++++++++++++----

  1 file changed, 12 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 521c14c7a789..c60d8134db45 100644

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_tail(struct svm_range · line 1150

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -0
@@ -1146,11 +1146,14 @@ svm_range_split_tail(struct svm_range 
 *prange, uint64_t new_last,
   {
       struct svm_range *tail = NULL;
       int r = svm_range_split(prange, prange->start, new_last, &tail);
+    bool huge_page_mapping = IS_ALIGNED(prange->start, 512);

Instead of hard-coding 512 here, it would be more future-proof to call amdgpu_vm_pt_num_entries(adev, AMDGPU_VM_PDB0). That's currently a static function in amdgpu_vm_pt.c. Christian, would you object to making that non-static?

Quoted 4 lines
Quoted 1 line

We don't have method to know if prange has huge page mapping which depends on virtual address 2MB align and physical address contiguous, it is decided inside amdgpu_vm_ptes_update. Even prange->start is not 2MB align, prange could have huge page mapping.

Right, I guess the correct condition would check that the range contains at least one potential huge page. I.e., the start address aligned up to 2MB is larger and the end address aligned down to 2MB. And the unaligned split is between those two aligned addresses.

If prange->start is not 2MB aligned amdgpu_vm_ptes_update will use 2MB fragments for the aligned middle portion of the range if possible, starting sub-range and ending sub-range of prange are not 2MB huge page mapped.

I think the checking is on start address of split range that it is not aligned and whole split range is inside 2MB aligned part of prange(from down aligned of split start address to end of split range is inside prange).

Regards

Xiaogang

Quoted 57 lines

  Felix

Quoted 54 lines

Regards,

Philip

Quoted 49 lines

Also, to improve the check whether the range can really use huge pages, you could add a check that it's size is at least 512 pages.

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_tail(struct svm_range *prange, uint64_t new_last, · line 1154

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -2
         if (!r) {
           list_add(&tail->list, insert_list);
-        if (!IS_ALIGNED(new_last + 1, 1UL << prange->granularity))
-            list_add(&tail->update_list, remap_list);
+        if (huge_page_mapping) {
+            if (!IS_ALIGNED(tail->start, 512))

Make that one condition: if (huge_page_mapping && !IS_ALIGNED...)

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_head(struct svm_range · line 1168

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -0
+ list_add(&tail->update_list, remap_list);
+        }
       }
       return r;
   }
@@ -1162,11 +1165,16 @@ svm_range_split_head(struct svm_range 
 *prange, uint64_t new_start,
       struct svm_range *head = NULL;
       int r = svm_range_split(prange, new_start, prange->last, &head);
   +    bool huge_page_mapping = IS_ALIGNED(prange->start, 512);

Why the blank line before huge_page_mapping? It's part of your variable declarations.

drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_split_head(struct svm_range *prange, uint64_t new_start, · line 1173

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -2
+
       if (!r) {
           list_add(&head->list, insert_list);
-        if (!IS_ALIGNED(new_start, 1UL << prange->granularity))
-            list_add(&head->update_list, remap_list);
+        if (huge_page_mapping) {
+            if (!IS_ALIGNED(prange->start, 512))

Same as above.

Regards,
  Felix

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3 -0
+ list_add(&head->update_list, remap_list);
+        }
       }
+
       return r;
   }