[RFC PATCH 1/3] drm/amdgpu: Add vm->notifier_lock

Felix Kuehling Felix.Kuehling at amd.com
Tue Dec 20 23:27:02 UTC 2022


This points to a mutex to serialize with MMU notifiers during page table
updates. For graphics contexts, the notifier lock is per adev. For compute
contexts the lock is per process.

Signed-off-by: Felix Kuehling <Felix.Kuehling at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c           | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h           | 3 +++
 3 files changed, 7 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index b15091d8310d..7aaa844a8284 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1325,9 +1325,12 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
 
 		*process_info = info;
 		*ef = dma_fence_get(&info->eviction_fence->base);
+	} else {
+		info = *process_info;
 	}
 
 	vm->process_info = *process_info;
+	vm->notifier_lock = &info->notifier_lock;
 
 	/* Validate page directory and attach eviction fence */
 	ret = amdgpu_bo_reserve(vm->root.bo, true);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index dc379dc22c77..a04f7aef4ca9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2075,6 +2075,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm)
 
 	mutex_init(&vm->eviction_lock);
 	vm->evicting = false;
+	vm->notifier_lock = &adev->notifier_lock;
 
 	r = amdgpu_vm_pt_create(adev, vm, adev->vm_manager.root_level,
 				false, &root);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 094bb4807303..07af80df812b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -251,6 +251,9 @@ struct amdgpu_vm {
 	bool			evicting;
 	unsigned int		saved_flags;
 
+	/* Pointer to notifier lock used when updating PTEs */
+	struct mutex		*notifier_lock;
+
 	/* Lock to protect vm_bo add/del/move on all lists of vm */
 	spinlock_t		status_lock;
 
-- 
2.32.0



More information about the amd-gfx mailing list