[PATCH] amd/amdkfd: Initialize kfd_dev::profiler lock early

Thomas Gleixner posted 1 patch 3 days, 6 hours ago
drivers/gpu/drm/amd/amdkfd/kfd_device.c |    6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] amd/amdkfd: Initialize kfd_dev::profiler lock early
Posted by Thomas Gleixner 3 days, 6 hours ago
Bert reported the following lockdep splat:

 DEBUG_LOCKS_WARN_ON(lock->magic != lock)
 WARNING: kernel/locking/mutex.c:625 at __mutex_lock+0x586/0x10c0, CPU#17: (udev-worker)/331
 RIP: 0010:__mutex_lock+0x58d/0x10c0
  init_mqd+0x122/0x190 [amdgpu]
  init_mqd_hiq+0xd/0x20 [amdgpu]
  kq_initialize.constprop.0+0x2b8/0x370 [amdgpu]
  kernel_queue_init+0x3f/0x60 [amdgpu]
  pm_init+0x6b/0x100 [amdgpu]
  start_cpsch+0x1d6/0x270 [amdgpu]
  kgd2kfd_device_init.cold+0x7b9/0xa1a [amdgpu]
  amdgpu_amdkfd_device_init+0x190/0x260 [amdgpu]
  amdgpu_device_init.cold+0x1952/0x1c79 [amdgpu]
  amdgpu_driver_load_kms+0x14/0x80 [amdgpu]

Some implementations of init_mqd() acquire kfd_dev->profile_lock, which is
initialized in kgd2kfd_device_init() after init_mqd() was invoked via the
above callchain. So init_mqd() tries to lock an uninitialized mutex.

Move the initialization to the beginning of kgd2kfd_device_init() to cure
that.

Fixes: a789761de305 ("amd/amdkfd: Add kfd_ioctl_profiler to contain profiler kernel driver changes")
Reported-by: Bert Karwatzki <spasswolf@web.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Cc: Benjamin Welton <bewelton@amd.com>
Closes: https://lore.kernel.org/lkml/4f548d61b2dd12e01f401ce4b8c865f238f7b23c.camel@web.de/
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -744,6 +744,9 @@ bool kgd2kfd_device_init(struct kfd_dev
 			KGD_ENGINE_SDMA1);
 	kfd->shared_resources = *gpu_resources;
 
+	kfd->profiler_process = NULL;
+	mutex_init(&kfd->profiler_lock);
+
 	kfd->num_nodes = amdgpu_xcp_get_num_xcp(kfd->adev->xcp_mgr);
 
 	if (kfd->num_nodes == 0) {
@@ -936,9 +939,6 @@ bool kgd2kfd_device_init(struct kfd_dev
 
 	svm_range_set_max_pages(kfd->adev);
 
-	kfd->profiler_process = NULL;
-	mutex_init(&kfd->profiler_lock);
-
 	kfd->init_complete = true;
 	dev_info(kfd_device, "added device %x:%x\n", kfd->adev->pdev->vendor,
 		 kfd->adev->pdev->device);