drm/amdkfd: Use last + 1 of vm range to check 2MB huge page alignment
Subsystems (3)
PATCH 1/1 drm/amdkfd: Use last + 1 of vm range to check 2MB huge page alignment
From: Xiaogang Chen <[email protected]>
The last byte of svm range is included. Should use last + 1 to check 2MB alignment for possible huge page mapping.
range alignment")
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +4 -4
@@ -1144,7 +1144,7 @@ static int svm_range_split_tail(struct svm_range *prange, uint64_t new_last, struct list_head *insert_list, struct list_head *remap_list) { - unsigned long last_align_down = ALIGN_DOWN(prange->last, 512); + unsigned long last_align_down = ALIGN_DOWN(prange->last + 1, 512);unsigned long start_align =ALIGN (prange->start,512 );bool huge_page_mapping = last_align_down > start_align;struct svm_range *tail =NULL ;
@@ -1168,7 +1168,7 @@ static int svm_range_split_head(struct svm_range *prange, uint64_t new_start, struct list_head *insert_list, struct list_head *remap_list) { - unsigned long last_align_down = ALIGN_DOWN(prange->last, 512); + unsigned long last_align_down = ALIGN_DOWN(prange->last + 1, 512);unsigned long start_align =ALIGN (prange->start,512 );bool huge_page_mapping = last_align_down > start_align;struct svm_range *head =NULL ;
@@ -1181,8 +1181,8 @@ svm_range_split_head(struct svm_range *prange, uint64_t new_start,list_add (&head->list, insert_list); -if (huge_page_mapping && head->last +1 > start_align && - head->last +1 < last_align_down && (!IS_ALIGNED (head->last,512 ))) +if (huge_page_mapping && head->last > start_align && + head->last < last_align_down && (!IS_ALIGNED (head->last,512 )))list_add (&head->update_list, remap_list);return 0 ;
Signature · 1 line
2.34.1
Hi Xiaogang,
thanks for sending this.
The last + 1 change to last_align_down matches the reproduced split-tail failure and fixes the inclusive-last issue there. I think the head-side condition still uses the inclusive end of the generated head range in places where the exclusive split boundary is needed.
In svm_range_split_head() the call is:
r = svm_range_split(prange, new_start, prange->last, &head);
This is case 2 in svm_range_split(): the generated range is [old_start, new_start - 1], where old_start is the original prange start. So for the head range:
head->last + 1 == new_start
and new_start is the split boundary that should be checked for 2MB alignment. That would make the head-side condition:
if (huge_page_mapping && new_start > start_align && new_start < last_align_down && !IS_ALIGNED(new_start, 512)) list_add(&head->update_list, remap_list);
With an original page range [0, 1023], start_align is 0 and last_align_down is 1024 after the last + 1 change.
For new_start = 512, the generated head is [0, 511]. The split boundary is 512-page aligned, so this condition should not add the head to remap_list, but checking !IS_ALIGNED(head->last, 512) checks 511 and evaluates true.
For new_start = 513, the generated head is [0, 512]. The split boundary is not 512-page aligned, so this condition should add the head to remap_list, but checking !IS_ALIGNED(head->last, 512) checks 512 and evaluates false.
This is the head-side issue Philip pointed out in the review of the original change:
https://lore.kernel.org/all/[email protected]/
I posted a v2 that keeps your tail-side last + 1 fix and uses new_start for the head-side split-boundary checks:
https://lore.kernel.org/all/[email protected]/
Thanks,
Gerhard