drm/amdkfd: Fix GPU mappings for APU after prefetch
Subsystems (3)
PATCH v2 1/1 drm/amdkfd: Fix GPU mappings for APU after prefetch
Fix the following corner case:-
Consider a 2M huge page SVM allocation, followed by prefetch call for
the first 4K page. The whole range is initially mapped with single PTE. After the prefetch, this range gets split to first page + rest of the pages. Currently, the first page mapping is not updated on MI300A (APU) since page hasn't migrated. However, after range split PTE mapping it not valid.
Fix this by forcing page table update for the whole range when prefetch is called. Calling prefetch on APU doesn't improve performance. If all it deteriotes. However, functionality has to be supported.
v2: Use apu_prefer_gtt as this issue doesn't apply to APUs with carveout VRAM
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +7 -0
@@ -766,14 +766,21 @@ svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange, {uint32_t i;int gpuidx; +struct kfd_node *node;for (i =0 ; i < nattr; i++) {switch (attrs[i].type) {case KFD_IOCTL_SVM_ATTR_PREFERRED_LOC : prange->preferred_loc = attrs[i].value; + node =svm_range_get_node_by_id (prange, attrs[i].value); +if (node && node->adev->apu_prefer_gtt && !p->xnack_enabled) + *update_mapping = true;break ;case KFD_IOCTL_SVM_ATTR_PREFETCH_LOC : prange->prefetch_loc = attrs[i].value; + node =svm_range_get_node_by_id (prange, attrs[i].value); +if (node && node->adev->apu_prefer_gtt && !p->xnack_enabled) + *update_mapping = true;break ;case KFD_IOCTL_SVM_ATTR_ACCESS :case KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE :
Signature · 1 line
2.34.1
Quoted 9 lines · Harish Kasiviswanathan
Fix the following corner case:-
Consider a 2M huge page SVM allocation, followed by prefetch call for
the first 4K page. The whole range is initially mapped with single PTE. After the prefetch, this range gets split to first page + rest of the pages. Currently, the first page mapping is not updated on MI300A (APU) since page hasn't migrated. However, after range split PTE mapping it not valid.
Quoted 6 lines
Fix this by forcing page table update for the whole range when prefetch is called. Calling prefetch on APU doesn't improve performance. If all it deteriotes. However, functionality has to be supported.
v2: Use
apu_prefer_gttas this issue doesn't apply to APUs with carveout VRAM
apu_prefer_gtt is used by small APUs as well. It depends on how much VRAM vs GTT is available on the system.
if (adev->flags & AMD_IS_APU) {
if (adev->gmc.real_vram_size < gtt_size)
adev->apu_prefer_gtt = true;
}Alex
Quoted 36 lines
Suggested-by Philip Yang <[email protected]>Signed-off-by Harish Kasiviswanathan <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +7
-1@@ -766,14 +766,21 @@ svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange, {uint32_t i;int gpuidx; +struct kfd_node *node;for (i =0 ; i < nattr; i++) {switch (attrs[i].type) {case KFD_IOCTL_SVM_ATTR_PREFERRED_LOC : prange->preferred_loc = attrs[i].value; + node =svm_range_get_node_by_id (prange, attrs[i].value); +if (node && node->adev->apu_prefer_gtt && !p->xnack_enabled) + *update_mapping = true;break ;case KFD_IOCTL_SVM_ATTR_PREFETCH_LOC : prange->prefetch_loc = attrs[i].value; + node =svm_range_get_node_by_id (prange, attrs[i].value); +if (node && node->adev->apu_prefer_gtt && !p->xnack_enabled) + *update_mapping = true;break ;case KFD_IOCTL_SVM_ATTR_ACCESS :case KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE : --2.34.1
Philip Yang
Reviewed-byQuoted 16 lines · Alex Deucher
Quoted 8 lines · Harish Kasiviswanathan
Fix the following corner case:-
Consider a 2M huge page SVM allocation, followed by prefetch call for
the first 4K page. The whole range is initially mapped with single PTE. After the prefetch, this range gets split to first page + rest of the pages. Currently, the first page mapping is not updated on MI300A (APU) since page hasn't migrated. However, after range split PTE mapping it not valid.Quoted 6 lines
Fix this by forcing page table update for the whole range when prefetch is called. Calling prefetch on APU doesn't improve performance. If all it deteriotes. However, functionality has to be supported.
v2: Use
apu_prefer_gttas this issue doesn't apply to APUs with carveout VRAM
Quoted 7 lines
apu_prefer_gttis used by small APUs as well. It depends on how much VRAM vs GTT is available on the system.if (adev->flags & AMD_IS_APU) { if (adev->gmc.real_vram_size < gtt_size) adev->apu_prefer_gtt = true; }
yes, if apu_perfer_gtt is true, then no page migration because best_prefetch_location is always CPU. For small APU, it will have same issue if KFD is used, prefetch split range page table not updated because no migration. This patch can fix the issue on both small APU and APP APU.
Quoted 37 lines
Alex
Quoted 35 lines
Suggested-by Philip Yang <[email protected]>Signed-off-by Harish Kasiviswanathan <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +7
-1@@ -766,14 +766,21 @@ svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange, {uint32_t i;int gpuidx; +struct kfd_node *node;for (i =0 ; i < nattr; i++) {switch (attrs[i].type) {case KFD_IOCTL_SVM_ATTR_PREFERRED_LOC : prange->preferred_loc = attrs[i].value; + node =svm_range_get_node_by_id (prange, attrs[i].value); +if (node && node->adev->apu_prefer_gtt && !p->xnack_enabled) + *update_mapping = true;break ;case KFD_IOCTL_SVM_ATTR_PREFETCH_LOC : prange->prefetch_loc = attrs[i].value; + node =svm_range_get_node_by_id (prange, attrs[i].value); +if (node && node->adev->apu_prefer_gtt && !p->xnack_enabled) + *update_mapping = true;break ;case KFD_IOCTL_SVM_ATTR_ACCESS :case KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE : --2.34.1
Quoted 21 lines · Philip Yang
Quoted 19 lines · Alex Deucher
Quoted 8 lines · Harish Kasiviswanathan
Fix the following corner case:-
Consider a 2M huge page SVM allocation, followed by prefetch call for the first 4K page. The whole range is initially mapped with single PTE. After the prefetch, this range gets split to first page + rest of the pages. Currently, the first page mapping is not updated on MI300A (APU) since page hasn't migrated. However, after range split PTE mapping it not valid.Quoted 6 lines
Fix this by forcing page table update for the whole range when prefetch is called. Calling prefetch on APU doesn't improve performance. If all it deteriotes. However, functionality has to be supported.
v2: Use
apu_prefer_gttas this issue doesn't apply to APUs with carveout VRAM
apu_prefer_gttis used by small APUs as well. It depends on how much VRAM vs GTT is available on the system.
Quoted 8 lines
Quoted 4 lines
if (
adev->flags&AMD_IS_APU) {
if (adev->gmc.real_vram_size<gtt_size)adev->apu_prefer_gtt= true; }yes, if
apu_perfer_gttis true, then no page migration becausebest_prefetch_locationis always CPU. For small APU, it will have same issue if KFD is used, prefetch split range page table not updated because no migration. This patch can fix the issue on both small APU and APP APU.Reviewed-by Philip Yang<[email protected]>
Is the case like that: the svm range got split; the pages are not migrated and attributes for the pages are not changed. Then why need update pte as page physical locations and attributes are not changed? Basically it used huge page pte, now you split the pte into smaller ranges. Or I misunderstood the scenario?
Regards
Xiaogang
Quoted 43 lines
Quoted 43 lines
Alex
Quoted 40 lines
Suggested-by Philip Yang <[email protected]>Signed-off-by Harish Kasiviswanathan <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c| 7 +++++++1 file changed, 7 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1
-0@@ -766,14 +766,21 @@ svm_range_apply_attrs(struct kfd_process *p,struct svm_range *prange, { uint32_t i; int gpuidx; + struct kfd_node *node; for (i = 0; i < nattr; i++) { switch (attrs[i].type) {case
KFD_IOCTL_SVM_ATTR_PREFERRED_LOC:
prange->preferred_loc= attrs[i].value; + node =svm_range_get_node_by_id(prange, attrs[i].value);
+ if (node &&node->adev->apu_prefer_gtt&& !p->xnack_enabled)
+*update_mapping= true; break;
caseKFD_IOCTL_SVM_ATTR_PREFETCH_LOC:
prange->prefetch_loc= attrs[i].value; + node =svm_range_get_node_by_id(prange, attrs[i].value);
+ if (node &&node->adev->apu_prefer_gtt&& !p->xnack_enabled)
+*update_mapping= true; break;
caseKFD_IOCTL_SVM_ATTR_ACCESS:
caseKFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE:Signature · 1 line
2.34.1
Quoted 28 lines · Xiaogang
Quoted 26 lines · Philip Yang
Quoted 23 lines · Alex Deucher
Quoted 8 lines · Harish Kasiviswanathan
Fix the following corner case:-
Consider a 2M huge page SVM allocation, followed by prefetch call for the first 4K page. The whole range is initially mapped with single PTE. After the prefetch, this range gets split to first page + rest of the pages. Currently, the first page mapping is not updated on MI300A (APU) since page hasn't migrated. However, after range split PTE mapping it not valid.Quoted 6 lines
Fix this by forcing page table update for the whole range when prefetch is called. Calling prefetch on APU doesn't improve performance. If all it deteriotes. However, functionality has to be supported.
v2: Use
apu_prefer_gttas this issue doesn't apply to APUs with carveout VRAM
apu_prefer_gttis used by small APUs as well. It depends on how much VRAM vs GTT is available on the system.if (
adev->flags&AMD_IS_APU) {
if (adev->gmc.real_vram_size<gtt_size)adev->apu_prefer_gtt= true; }
Quoted 5 lines
Quoted 3 lines
yes, if
apu_perfer_gttis true, then no page migration becausebest_prefetch_locationis always CPU. For small APU, it will have same issue if KFD is used, prefetch split range page table not updated because no migration. This patch can fix the issue on both small APU and APP APU.Reviewed-by Philip Yang<[email protected]>Is the case like that: the svm range got split; the pages are not migrated and attributes for the pages are not changed. Then why need update pte as page physical locations and attributes are not changed? Basically it used huge page pte, now you split the pte into smaller ranges. Or I misunderstood the scenario?
yes, the range mapped as huge page, use 2MB PDE entry as PTE, after spliting, the tail range mapping update, not 2MB alignment huge page, alloc pt bo for PDE entry, then tail PTEs updated, the head PTEs is invalid entry.
Regards,
Philip
Quoted 48 lines
Regards
Xiaogang
Quoted 43 lines
Quoted 43 lines
Alex
Quoted 40 lines
Suggested-by Philip Yang <[email protected]>Signed-off-by Harish Kasiviswanathan <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c| 7 +++++++1 file changed, 7 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1
-0@@ -766,14 +766,21 @@ svm_range_apply_attrs(struct kfd_process *p,struct svm_range *prange, { uint32_t i; int gpuidx; + struct kfd_node *node; for (i = 0; i < nattr; i++) { switch (attrs[i].type) {case
KFD_IOCTL_SVM_ATTR_PREFERRED_LOC:
prange->preferred_loc= attrs[i].value; + node =svm_range_get_node_by_id(prange, attrs[i].value);
+ if (node &&node->adev->apu_prefer_gtt&& !p->xnack_enabled)
+*update_mapping= true; break;
caseKFD_IOCTL_SVM_ATTR_PREFETCH_LOC:
prange->prefetch_loc= attrs[i].value; + node =svm_range_get_node_by_id(prange, attrs[i].value);
+ if (node &&node->adev->apu_prefer_gtt&& !p->xnack_enabled)
+*update_mapping= true; break;
caseKFD_IOCTL_SVM_ATTR_ACCESS:
caseKFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE:Signature · 1 line
2.34.1
Quoted 30 lines · Philip Yang
Quoted 28 lines · Xiaogang
Quoted 26 lines · Philip Yang
Quoted 23 lines · Alex Deucher
Quoted 8 lines · Harish Kasiviswanathan
Fix the following corner case:-
Consider a 2M huge page SVM allocation, followed by prefetch call for the first 4K page. The whole range is initially mapped with single PTE. After the prefetch, this range gets split to first page + rest of the pages. Currently, the first page mapping is not updated on MI300A (APU) since page hasn't migrated. However, after range split PTE mapping it not valid.Quoted 6 lines
Fix this by forcing page table update for the whole range when prefetch is called. Calling prefetch on APU doesn't improve performance. If all it deteriotes. However, functionality has to be supported.
v2: Use
apu_prefer_gttas this issue doesn't apply to APUs with carveout VRAM
apu_prefer_gttis used by small APUs as well. It depends on how much VRAM vs GTT is available on the system.if (
adev->flags&AMD_IS_APU) {
if (adev->gmc.real_vram_size<gtt_size)adev->apu_prefer_gtt= true; }
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
yes, if
apu_perfer_gttis true, then no page migration becausebest_prefetch_locationis always CPU. For small APU, it will have same issue if KFD is used, prefetch split range page table not updated because no migration. This patch can fix the issue on both small APU and APP APU.Reviewed-by Philip Yang<[email protected]>Is the case like that: the svm range got split; the pages are not migrated and attributes for the pages are not changed. Then why need update pte as page physical locations and attributes are not changed? Basically it used huge page pte, now you split the pte into smaller ranges. Or I misunderstood the scenario?
yes, the range mapped as huge page, use 2MB PDE entry as PTE, after spliting, the tail range mapping update, not 2MB alignment huge page, alloc pt bo for PDE entry, then tail PTEs updated, the head PTEs is invalid entry.
My concern is that since it is APU no page got migrated and access attributes are not changes, just svm range got split. Then neither tail or head sub-range would get mapping updated: the original 2MB PTE mapping can still be used for both sub-ranges that gives better performance. This patch spoil 2MB PTE vm mapping that is not necessary for APU.
Regards
Xiaogang
Quoted 52 lines
Regards,
Philip
Quoted 48 lines
Regards
Xiaogang
Quoted 43 lines
Quoted 43 lines
Alex
Quoted 40 lines
Suggested-by Philip Yang <[email protected]>Signed-off-by Harish Kasiviswanathan <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c| 7 +++++++1 file changed, 7 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1
-0@@ -766,14 +766,21 @@ svm_range_apply_attrs(struct kfd_process *p,struct svm_range *prange, { uint32_t i; int gpuidx; + struct kfd_node *node; for (i = 0; i < nattr; i++) { switch (attrs[i].type) {case
KFD_IOCTL_SVM_ATTR_PREFERRED_LOC:
prange->preferred_loc= attrs[i].value; + node =svm_range_get_node_by_id(prange, attrs[i].value);
+ if (node &&node->adev->apu_prefer_gtt&& !p->xnack_enabled)
+*update_mapping= true; break;
caseKFD_IOCTL_SVM_ATTR_PREFETCH_LOC:
prange->prefetch_loc= attrs[i].value; + node =svm_range_get_node_by_id(prange, attrs[i].value);
+ if (node &&node->adev->apu_prefer_gtt&& !p->xnack_enabled)
+*update_mapping= true; break;
caseKFD_IOCTL_SVM_ATTR_ACCESS:
caseKFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE:Signature · 1 line
2.34.1
Felix Kuehling
maintainerQuoted 27 lines · Harish Kasiviswanathan
Fix the following corner case:-
Consider a 2M huge page SVM allocation, followed by prefetch call for
the first 4K page. The whole range is initially mapped with single PTE. After the prefetch, this range gets split to first page + rest of the pages. Currently, the first page mapping is not updated on MI300A (APU) since page hasn't migrated. However, after range split PTE mapping it not valid.Fix this by forcing page table update for the whole range when prefetch is called. Calling prefetch on APU doesn't improve performance. If all it deteriotes. However, functionality has to be supported.
v2: Use
apu_prefer_gttas this issue doesn't apply to APUs with carveout VRAMSuggested-by Philip Yang<[email protected]>Signed-off-by Harish Kasiviswanathan<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0@@ -766,14 +766,21 @@ svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange, {
drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange, · line 776
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +3
-0uint32_t i;int gpuidx; +struct kfd_node *node;for (i =0 ; i < nattr; i++) {switch (attrs[i].type) {case KFD_IOCTL_SVM_ATTR_PREFERRED_LOC : prange->preferred_loc = attrs[i].value; + node =svm_range_get_node_by_id (prange, attrs[i].value); +if (node && node->adev->apu_prefer_gtt && !p->xnack_enabled)
I don't think you even need the condition based on apu_prefer_gtt. You can always set update_mapping. If you are migrating, it would update the mapping anyway, so it shouldn't make a difference on dGPUs.
More importantly, I think this may apply to other attributes as well that result in splitting of a range without causing a migration. So this condition could be moved outside the switch-case block and the loop:
if (!p->xnack_enabled) *update_mapping = true;
I see we already do the same for the access attributes. Just generalize it.
Regards,
Felix
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +4
-0+ *update_mapping = true;break ;case KFD_IOCTL_SVM_ATTR_PREFETCH_LOC : prange->prefetch_loc = attrs[i].value; + node =svm_range_get_node_by_id (prange, attrs[i].value); +if (node && node->adev->apu_prefer_gtt && !p->xnack_enabled) + *update_mapping = true;break ;case KFD_IOCTL_SVM_ATTR_ACCESS :case KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE :
Quoted 32 lines · Felix Kuehling
Quoted 31 lines · Harish Kasiviswanathan
Fix the following corner case:-
Consider a 2M huge page SVM allocation, followed by prefetch call for
the first 4K page. The whole range is initially mapped with single PTE. After the prefetch, this range gets split to first page + rest of the pages. Currently, the first page mapping is not updated on MI300A (APU) since page hasn't migrated. However, after range split PTE mapping it not valid.Fix this by forcing page table update for the whole range when prefetch is called. Calling prefetch on APU doesn't improve performance. If all it deteriotes. However, functionality has to be supported.
v2: Use
apu_prefer_gttas this issue doesn't apply to APUs with carveout VRAMSuggested-by Philip Yang<[email protected]>Signed-off-by Harish Kasiviswanathan<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1
-0@@ -766,14 +766,21 @@ svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange, {uint32_t i;int gpuidx; +struct kfd_node *node;
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_apply_attrs(struct kfd_process *p, struct svm_range *prange, · line 776
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-0for (i =0 ; i < nattr; i++) {switch (attrs[i].type) {case KFD_IOCTL_SVM_ATTR_PREFERRED_LOC : prange->preferred_loc = attrs[i].value; + node =svm_range_get_node_by_id (prange, attrs[i].value); +if (node && node->adev->apu_prefer_gtt && !p->xnack_enabled)I don't think you even need the condition based on
apu_prefer_gtt. You can always setupdate_mapping. If you are migrating, it would update the mapping anyway, so it shouldn't make a difference on dGPUs.
For dGPU xnack off case, prefetch range migrated, we should use restore worker to update mapping, yes, you are right, if migrated and xnack off, set_attr will skip update mapping regardless update_mapping true or false.
Thanks,
Philip
Quoted 21 lines
More importantly, I think this may apply to other attributes as well that result in splitting of a range without causing a migration. So this condition could be moved outside the switch-case block and the loop:
if (!p->xnack_enabled) *update_mapping = true;I see we already do the same for the access attributes. Just generalize it.
Regards,
FelixQuoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +4
-0+ *update_mapping = true;break ;case KFD_IOCTL_SVM_ATTR_PREFETCH_LOC : prange->prefetch_loc = attrs[i].value; + node =svm_range_get_node_by_id (prange, attrs[i].value); +if (node && node->adev->apu_prefer_gtt && !p->xnack_enabled) + *update_mapping = true;break ;case KFD_IOCTL_SVM_ATTR_ACCESS :case KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE :