Skip to content

Commit

Permalink
xen_console: Fix deadlock in xen_stop_domain_console()
Browse files Browse the repository at this point in the history
Both xen_stop_domain_console and console thread are trying to acquire
global_console_lock and unset current_console at the same time. This can
prevent console thread from ever stopping if xen_stop_domain_console
acquires the lock first.

This patch fixes the issue by unlocking the global_console_lock before
joining the console thread, and leaving the job of unsetting the current
console to the console thread.

Signed-off-by: Mykyta Poturai <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
Reviewed-by: Dmytro Firsov <[email protected]>
  • Loading branch information
Deedone committed May 10, 2024
1 parent e62a45f commit 78ba2f5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions xen-console-srv/src/xen_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,11 @@ int xen_stop_domain_console(struct xen_domain *domain)
/* Stop attached console if any */
if (current_console == console) {
k_sem_give(&console->int_sem);
k_mutex_unlock(&global_console_lock);
k_thread_join(&console->int_thrd, K_FOREVER);
current_console = NULL;
} else {
k_mutex_unlock(&global_console_lock);
}
k_mutex_unlock(&global_console_lock);

k_free(console->int_buf);

Expand Down

0 comments on commit 78ba2f5

Please sign in to comment.