Skip to content

Commit bd81df3

Browse files
krystian-hebelSergiiDmytruk
authored andcommitted
arch/x86/shutdown: protect against recurrent machine_restart()
If multiple CPUs called machine_restart() before actual restart took place, but after boot CPU declared itself not online, ASSERT in on_selected_cpus() will fail. Few calls later execution would end up in machine_restart() again, with another frame on call stack for new exception. To protect against running out of stack, code checks if boot CPU is still online before calling on_selected_cpus(). Signed-off-by: Krystian Hebel <[email protected]>
1 parent aacc6f2 commit bd81df3

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

xen/arch/x86/shutdown.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,23 @@ void machine_restart(unsigned int delay_millisecs)
549549
/* Ensure we are the boot CPU. */
550550
if ( get_apic_id() != boot_cpu_physical_apicid )
551551
{
552-
/* Send IPI to the boot CPU (logical cpu 0). */
553-
on_selected_cpus(cpumask_of(0), __machine_restart,
554-
&delay_millisecs, 0);
552+
/*
553+
* Send IPI to the boot CPU (logical cpu 0).
554+
*
555+
* If multiple CPUs called machine_restart() before actual restart
556+
* took place, but after boot CPU declared itself not online, ASSERT
557+
* in on_selected_cpus() will fail. Few calls later we would end up
558+
* here again, with another frame on call stack for new exception.
559+
* To protect against running out of stack, check if boot CPU is
560+
* online.
561+
*
562+
* Note this is not an atomic operation, so it is possible for
563+
* on_selected_cpus() to be called once after boot CPU is offline
564+
* before we hit halt() below.
565+
*/
566+
if ( cpu_online(0) )
567+
on_selected_cpus(cpumask_of(0), __machine_restart,
568+
&delay_millisecs, 0);
555569
for ( ; ; )
556570
halt();
557571
}

0 commit comments

Comments
 (0)