xref: /linux-6.15/arch/um/kernel/reboot.c (revision 137d1a26)
1 /*
2  * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3  * Licensed under the GPL
4  */
5 
6 #include "linux/sched.h"
7 #include "linux/spinlock.h"
8 #include "linux/slab.h"
9 #include "kern_util.h"
10 #include "os.h"
11 #include "skas.h"
12 
13 void (*pm_power_off)(void);
14 
15 static void kill_off_processes(void)
16 {
17 	if (proc_mm)
18 		/*
19 		 * FIXME: need to loop over userspace_pids
20 		 */
21 		os_kill_ptraced_process(userspace_pid[0], 1);
22 	else {
23 		struct task_struct *p;
24 		int pid;
25 
26 		read_lock(&tasklist_lock);
27 		for_each_process(p) {
28 			task_lock(p);
29 			if (!p->mm) {
30 				task_unlock(p);
31 				continue;
32 			}
33 			pid = p->mm->context.id.u.pid;
34 			task_unlock(p);
35 			os_kill_ptraced_process(pid, 1);
36 		}
37 		read_unlock(&tasklist_lock);
38 	}
39 }
40 
41 void uml_cleanup(void)
42 {
43 	kmalloc_ok = 0;
44 	do_uml_exitcalls();
45 	kill_off_processes();
46 }
47 
48 void machine_restart(char * __unused)
49 {
50 	uml_cleanup();
51 	reboot_skas();
52 }
53 
54 void machine_power_off(void)
55 {
56 	uml_cleanup();
57 	halt_skas();
58 }
59 
60 void machine_halt(void)
61 {
62 	machine_power_off();
63 }
64