Skip to content

Commit aa6df65

Browse files
committed
habanalabs: fix reset process in case of failures
There are some points in the reset process where if the code fails for some reason, and the system admin tries to initiate the reset process again we will get a kernel panic. This is because there aren't any protections in different fini functions that are called during the reset process. The protections that are added in this patch make sure that if the fini functions are called multiple times, without calling init functions between them, there won't be double release of already released resources. Signed-off-by: Oded Gabbay <[email protected]>
1 parent a9d4ef6 commit aa6df65

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

drivers/misc/habanalabs/common/device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset,
10371037

10381038
if (hard_reset) {
10391039
/* Release kernel context */
1040-
if (hl_ctx_put(hdev->kernel_ctx) == 1)
1040+
if (hdev->kernel_ctx && hl_ctx_put(hdev->kernel_ctx) == 1)
10411041
hdev->kernel_ctx = NULL;
10421042
hl_vm_fini(hdev);
10431043
hl_mmu_fini(hdev);

drivers/misc/habanalabs/common/mmu_v1.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,16 @@ static void hl_mmu_v1_fini(struct hl_device *hdev)
467467
{
468468
/* MMU H/W fini was already done in device hw_fini() */
469469

470-
kvfree(hdev->mmu_priv.dr.mmu_shadow_hop0);
471-
gen_pool_destroy(hdev->mmu_priv.dr.mmu_pgt_pool);
470+
if (!ZERO_OR_NULL_PTR(hdev->mmu_priv.hr.mmu_shadow_hop0)) {
471+
kvfree(hdev->mmu_priv.dr.mmu_shadow_hop0);
472+
gen_pool_destroy(hdev->mmu_priv.dr.mmu_pgt_pool);
473+
}
474+
475+
/* Make sure that if we arrive here again without init was called we
476+
* won't cause kernel panic. This can happen for example if we fail
477+
* during hard reset code at certain points
478+
*/
479+
hdev->mmu_priv.dr.mmu_shadow_hop0 = NULL;
472480
}
473481

474482
/**

0 commit comments

Comments
 (0)