Commit 176d23a7 authored by Oded Gabbay's avatar Oded Gabbay

habanalabs: disable IRQ in user interrupts spinlock

Because this spinlock is taken in an interrupt handler, we must use
the spin_lock_irqsave/irqrestore version to disable the interrupts
on the local CPU. Otherwise, we can have a potential deadlock (if
the interrupt handler is scheduled to run on the same cpu that the
code who took the lock was running on).
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
parent 71731090
...@@ -923,13 +923,14 @@ static void ...@@ -923,13 +923,14 @@ static void
wake_pending_user_interrupt_threads(struct hl_user_interrupt *interrupt) wake_pending_user_interrupt_threads(struct hl_user_interrupt *interrupt)
{ {
struct hl_user_pending_interrupt *pend; struct hl_user_pending_interrupt *pend;
unsigned long flags;
spin_lock(&interrupt->wait_list_lock); spin_lock_irqsave(&interrupt->wait_list_lock, flags);
list_for_each_entry(pend, &interrupt->wait_list_head, wait_list_node) { list_for_each_entry(pend, &interrupt->wait_list_head, wait_list_node) {
pend->fence.error = -EIO; pend->fence.error = -EIO;
complete_all(&pend->fence.completion); complete_all(&pend->fence.completion);
} }
spin_unlock(&interrupt->wait_list_lock); spin_unlock_irqrestore(&interrupt->wait_list_lock, flags);
} }
void hl_release_pending_user_interrupts(struct hl_device *hdev) void hl_release_pending_user_interrupts(struct hl_device *hdev)
...@@ -2714,9 +2715,9 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx, ...@@ -2714,9 +2715,9 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx,
{ {
struct hl_user_pending_interrupt *pend; struct hl_user_pending_interrupt *pend;
struct hl_user_interrupt *interrupt; struct hl_user_interrupt *interrupt;
unsigned long timeout; unsigned long timeout, flags;
long completion_rc;
u32 completion_value; u32 completion_value;
long completion_rc;
int rc = 0; int rc = 0;
if (timeout_us == U32_MAX) if (timeout_us == U32_MAX)
...@@ -2739,7 +2740,7 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx, ...@@ -2739,7 +2740,7 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx,
else else
interrupt = &hdev->user_interrupt[interrupt_offset]; interrupt = &hdev->user_interrupt[interrupt_offset];
spin_lock(&interrupt->wait_list_lock); spin_lock_irqsave(&interrupt->wait_list_lock, flags);
if (!hl_device_operational(hdev, NULL)) { if (!hl_device_operational(hdev, NULL)) {
rc = -EPERM; rc = -EPERM;
goto unlock_and_free_fence; goto unlock_and_free_fence;
...@@ -2765,7 +2766,7 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx, ...@@ -2765,7 +2766,7 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx,
* handler to monitor * handler to monitor
*/ */
list_add_tail(&pend->wait_list_node, &interrupt->wait_list_head); list_add_tail(&pend->wait_list_node, &interrupt->wait_list_head);
spin_unlock(&interrupt->wait_list_lock); spin_unlock_irqrestore(&interrupt->wait_list_lock, flags);
wait_again: wait_again:
/* Wait for interrupt handler to signal completion */ /* Wait for interrupt handler to signal completion */
...@@ -2777,12 +2778,12 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx, ...@@ -2777,12 +2778,12 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx,
* If comparison fails, keep waiting until timeout expires * If comparison fails, keep waiting until timeout expires
*/ */
if (completion_rc > 0) { if (completion_rc > 0) {
spin_lock(&interrupt->wait_list_lock); spin_lock_irqsave(&interrupt->wait_list_lock, flags);
if (copy_from_user(&completion_value, if (copy_from_user(&completion_value,
u64_to_user_ptr(user_address), 4)) { u64_to_user_ptr(user_address), 4)) {
spin_unlock(&interrupt->wait_list_lock); spin_unlock_irqrestore(&interrupt->wait_list_lock, flags);
dev_err(hdev->dev, dev_err(hdev->dev,
"Failed to copy completion value from user\n"); "Failed to copy completion value from user\n");
...@@ -2792,13 +2793,13 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx, ...@@ -2792,13 +2793,13 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx,
} }
if (completion_value >= target_value) { if (completion_value >= target_value) {
spin_unlock(&interrupt->wait_list_lock); spin_unlock_irqrestore(&interrupt->wait_list_lock, flags);
*status = CS_WAIT_STATUS_COMPLETED; *status = CS_WAIT_STATUS_COMPLETED;
} else { } else {
reinit_completion(&pend->fence.completion); reinit_completion(&pend->fence.completion);
timeout = completion_rc; timeout = completion_rc;
spin_unlock(&interrupt->wait_list_lock); spin_unlock_irqrestore(&interrupt->wait_list_lock, flags);
goto wait_again; goto wait_again;
} }
} else if (completion_rc == -ERESTARTSYS) { } else if (completion_rc == -ERESTARTSYS) {
...@@ -2812,11 +2813,11 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx, ...@@ -2812,11 +2813,11 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx,
} }
remove_pending_user_interrupt: remove_pending_user_interrupt:
spin_lock(&interrupt->wait_list_lock); spin_lock_irqsave(&interrupt->wait_list_lock, flags);
list_del(&pend->wait_list_node); list_del(&pend->wait_list_node);
unlock_and_free_fence: unlock_and_free_fence:
spin_unlock(&interrupt->wait_list_lock); spin_unlock_irqrestore(&interrupt->wait_list_lock, flags);
kfree(pend); kfree(pend);
hl_ctx_put(ctx); hl_ctx_put(ctx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment