Skip to content

Commit 7981ec6

Browse files
alexsierragalexdeucher
authored andcommitted
drm/amdkfd: Maintain svm_bo reference in page->zone_device_data
Each zone-device page holds a reference to the SVM BO that manages its backing storage. This is necessary to correctly hold on to the BO in case zone_device pages are shared with a child-process. Signed-off-by: Alex Sierra <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 3bf8282 commit 7981ec6

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

drivers/gpu/drm/amd/amdkfd/kfd_migrate.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ svm_migrate_get_vram_page(struct svm_range *prange, unsigned long pfn)
218218
struct page *page;
219219

220220
page = pfn_to_page(pfn);
221-
page->zone_device_data = prange;
221+
svm_range_bo_ref(prange->svm_bo);
222+
page->zone_device_data = prange->svm_bo;
222223
get_page(page);
223224
lock_page(page);
224225
}
@@ -502,7 +503,12 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc,
502503

503504
static void svm_migrate_page_free(struct page *page)
504505
{
505-
/* Keep this function to avoid warning */
506+
struct svm_range_bo *svm_bo = page->zone_device_data;
507+
508+
if (svm_bo) {
509+
pr_debug("svm_bo ref left: %d\n", kref_read(&svm_bo->kref));
510+
svm_range_bo_unref(svm_bo);
511+
}
506512
}
507513

508514
static int

drivers/gpu/drm/amd/amdkfd/kfd_svm.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,6 @@ static bool svm_bo_ref_unless_zero(struct svm_range_bo *svm_bo)
312312
return true;
313313
}
314314

315-
static struct svm_range_bo *svm_range_bo_ref(struct svm_range_bo *svm_bo)
316-
{
317-
if (svm_bo)
318-
kref_get(&svm_bo->kref);
319-
320-
return svm_bo;
321-
}
322-
323315
static void svm_range_bo_release(struct kref *kref)
324316
{
325317
struct svm_range_bo *svm_bo;
@@ -358,7 +350,7 @@ static void svm_range_bo_release(struct kref *kref)
358350
kfree(svm_bo);
359351
}
360352

361-
static void svm_range_bo_unref(struct svm_range_bo *svm_bo)
353+
void svm_range_bo_unref(struct svm_range_bo *svm_bo)
362354
{
363355
if (!svm_bo)
364356
return;

drivers/gpu/drm/amd/amdkfd/kfd_svm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ static inline void svm_range_unlock(struct svm_range *prange)
150150
mutex_unlock(&prange->lock);
151151
}
152152

153+
static inline struct svm_range_bo *svm_range_bo_ref(struct svm_range_bo *svm_bo)
154+
{
155+
if (svm_bo)
156+
kref_get(&svm_bo->kref);
157+
158+
return svm_bo;
159+
}
160+
153161
int svm_range_list_init(struct kfd_process *p);
154162
void svm_range_list_fini(struct kfd_process *p);
155163
int svm_ioctl(struct kfd_process *p, enum kfd_ioctl_svm_op op, uint64_t start,
@@ -186,6 +194,7 @@ svm_range_get_pdd_by_adev(struct svm_range *prange, struct amdgpu_device *adev);
186194
*/
187195
#define KFD_IS_SVM_API_SUPPORTED(dev) ((dev)->pgmap.type != 0)
188196

197+
void svm_range_bo_unref(struct svm_range_bo *svm_bo);
189198
#else
190199

191200
struct kfd_process;

0 commit comments

Comments
 (0)