drm/amdkfd: Fix always mapped range mapping to all ACCESS GPUs
Subsystems (3)
PATCH v2 1/1 drm/amdkfd: Fix always mapped range mapping to all ACCESS GPUs
CWSR ranges use the always mapped flag and only need a mapping on the GPU running the queue. However, svm_range_validate_and_map now updates the mapping on every GPU with the ACCESS attribute, which is all supported GPUs when XNACK is on. After the range is prefetched to VRAM, those GPUs may span different XGMI hives, so the page owner mismatches and is set to NULL. hmm_range_fault then tries to migrate the VRAM pages back to system memory, but svm_migrate_to_ram skips it because migrating pages back to system memory is not allowed while the GPU mapping is being updated, so the CPU page fault is never resolved.
Only map to the ACCESS GPUs if the range is not mapped to any GPU and is not in VRAM.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +8 -5
@@ -1757,12 +1757,15 @@ static int svm_range_validate_and_map(struct mm_struct *mm, }/* -* If prange with always mapped flag, update mapping on GPUs with -* ACCESS attribute +* If prange with always mapped flag is not mapped or migrated +* yet, update mapping on GPUs with ACCESS attribute. Don't add +* them otherwise, ACCESS GPUs may be on different XGMI hives, +* that would force hmm_range_fault to migrate VRAM back to ram. */ -if (prange->flags &KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED ) -bitmap_or (ctx->bitmap, ctx->bitmap, prange->bitmap_access, -MAX_GPU_INSTANCE ); +if (bitmap_empty (ctx->bitmap,MAX_GPU_INSTANCE ) && + prange->flags &KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED ) +bitmap_copy (ctx->bitmap, prange->bitmap_access, +MAX_GPU_INSTANCE ); }else {bitmap_or (ctx->bitmap, prange->bitmap_access, prange->bitmap_aip,MAX_GPU_INSTANCE );
Signature · 1 line
2.43.0
Quoted 10 lines · Andrew Martin
CWSR ranges use the always mapped flag and only need a mapping on the GPU running the queue. However,
svm_range_validate_and_mapnow updates the mapping on every GPU with the ACCESS attribute, which is all supported GPUs when XNACK is on. After the range is prefetched to VRAM, those GPUs may span different XGMI hives, so the page owner mismatches and is set to NULL.hmm_range_faultthen tries to migrate the VRAM pages back to system memory, butsvm_migrate_to_ramskips it because migrating pages back to system memory is not allowed while the GPU mapping is being updated, so the CPU page fault is never resolved.
Quoted 2 lines
Only map to the ACCESS GPUs if the range is not mapped to any GPU and is not in VRAM.
Quoted 33 lines
Fixes 6b2969831f7e ("drm/amdkfd: Unmap svm range from GPU set to no-access")Signed-off-by Andrew Martin<[email protected]>Assisted-by Claude:claude-opus-5--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +8
-5@@ -1757,12 +1757,15 @@ static int svm_range_validate_and_map(struct mm_struct *mm, }/* -* If prange with always mapped flag, update mapping on GPUs with -* ACCESS attribute +* If prange with always mapped flag is not mapped or migrated +* yet, update mapping on GPUs with ACCESS attribute. Don't add +* them otherwise, ACCESS GPUs may be on different XGMI hives, +* that would force hmm_range_fault to migrate VRAM back to ram. */ -if (prange->flags &KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED ) -bitmap_or (ctx->bitmap, ctx->bitmap, prange->bitmap_access, -MAX_GPU_INSTANCE ); +if (bitmap_empty (ctx->bitmap,MAX_GPU_INSTANCE ) && + prange->flags &KFD_IOCTL_SVM_FLAG_GPU_ALWAYS_MAPPED ) +bitmap_copy (ctx->bitmap, prange->bitmap_access, +MAX_GPU_INSTANCE ); }else {bitmap_or (ctx->bitmap, prange->bitmap_access, prange->bitmap_aip,MAX_GPU_INSTANCE );