Skip to content

Commit

Permalink
habanalabs: Avoid using a non-initialized MMU cache mutex
Browse files Browse the repository at this point in the history
The MMU cache mutex is used in the ASIC hw_init() functions, but it is
initialized only later in hl_mmu_init().
This patch prevents it by moving the initialization to the
device_early_init() function.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
  • Loading branch information
Tomer Tayar authored and Oded Gabbay committed May 24, 2019
1 parent 8438846 commit 8d45f1d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 2 additions & 0 deletions drivers/misc/habanalabs/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ static int device_early_init(struct hl_device *hdev)

mutex_init(&hdev->fd_open_cnt_lock);
mutex_init(&hdev->send_cpu_message_lock);
mutex_init(&hdev->mmu_cache_lock);
INIT_LIST_HEAD(&hdev->hw_queues_mirror_list);
spin_lock_init(&hdev->hw_queues_mirror_lock);
atomic_set(&hdev->in_reset, 0);
Expand Down Expand Up @@ -260,6 +261,7 @@ static int device_early_init(struct hl_device *hdev)
*/
static void device_early_fini(struct hl_device *hdev)
{
mutex_destroy(&hdev->mmu_cache_lock);
mutex_destroy(&hdev->send_cpu_message_lock);

hl_cb_mgr_fini(hdev, &hdev->kernel_cb_mgr);
Expand Down
8 changes: 1 addition & 7 deletions drivers/misc/habanalabs/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,12 @@ int hl_mmu_init(struct hl_device *hdev)

/* MMU H/W init was already done in device hw_init() */

mutex_init(&hdev->mmu_cache_lock);

hdev->mmu_pgt_pool =
gen_pool_create(__ffs(prop->mmu_hop_table_size), -1);

if (!hdev->mmu_pgt_pool) {
dev_err(hdev->dev, "Failed to create page gen pool\n");
rc = -ENOMEM;
goto err_pool_create;
return -ENOMEM;
}

rc = gen_pool_add(hdev->mmu_pgt_pool, prop->mmu_pgt_addr +
Expand All @@ -436,8 +433,6 @@ int hl_mmu_init(struct hl_device *hdev)

err_pool_add:
gen_pool_destroy(hdev->mmu_pgt_pool);
err_pool_create:
mutex_destroy(&hdev->mmu_cache_lock);

return rc;
}
Expand All @@ -459,7 +454,6 @@ void hl_mmu_fini(struct hl_device *hdev)

kvfree(hdev->mmu_shadow_hop0);
gen_pool_destroy(hdev->mmu_pgt_pool);
mutex_destroy(&hdev->mmu_cache_lock);

/* MMU H/W fini will be done in device hw_fini() */
}
Expand Down

0 comments on commit 8d45f1d

Please sign in to comment.