Skip to content

Commit 0983a88

Browse files
cfd-36Linus Torvalds
authored andcommitted
uml: install panic notifier earlier
It turns out that if there's a panic early enough, UML will just sit there in the LED-blinking loop because the panic notifier hadn't been installed yet. This patch installs it earlier. It also fixes the problem which exposed the hang, namely that if you give UML a zero-sized initrd, it will ask alloc_bootmem for zero bytes, and that will cause the panic. While I was in initrd.c, I gave it a style makeover. Prompted by checkpatch, I moved a couple extern declarations of uml_exitcode to kern_util.h. Signed-off-by: Jeff Dike <jdike@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8efa3c9 commit 0983a88

4 files changed

Lines changed: 42 additions & 32 deletions

File tree

‎arch/um/include/kern_util.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "sysdep/ptrace.h"
1010
#include "sysdep/faultinfo.h"
1111

12+
extern int uml_exitcode;
13+
1214
extern int ncpus;
1315
extern int kmalloc_ok;
1416
extern int nsyscalls;

‎arch/um/kernel/initrd.c‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
2+
* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
33
* Licensed under the GPL
44
*/
55

@@ -20,18 +20,27 @@ static int __init read_initrd(void)
2020
long long size;
2121
int err;
2222

23-
if(initrd == NULL)
23+
if (initrd == NULL)
2424
return 0;
2525

2626
err = os_file_size(initrd, &size);
27-
if(err)
27+
if (err)
2828
return 0;
2929

30+
/*
31+
* This is necessary because alloc_bootmem craps out if you
32+
* ask for no memory.
33+
*/
34+
if (size == 0) {
35+
printk(KERN_ERR "\"%\" is a zero-size initrd\n");
36+
return 0;
37+
}
38+
3039
area = alloc_bootmem(size);
31-
if(area == NULL)
40+
if (area == NULL)
3241
return 0;
3342

34-
if(load_initrd(initrd, area, size) == -1)
43+
if (load_initrd(initrd, area, size) == -1)
3544
return 0;
3645

3746
initrd_start = (unsigned long) area;
@@ -58,13 +67,15 @@ int load_initrd(char *filename, void *buf, int size)
5867
int fd, n;
5968

6069
fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
61-
if(fd < 0){
62-
printk("Opening '%s' failed - err = %d\n", filename, -fd);
70+
if (fd < 0) {
71+
printk(KERN_ERR "Opening '%s' failed - err = %d\n", filename,
72+
-fd);
6373
return -1;
6474
}
6575
n = os_read_file(fd, buf, size);
66-
if(n != size){
67-
printk("Read of %d bytes from '%s' failed, err = %d\n", size,
76+
if (n != size) {
77+
printk(KERN_ERR "Read of %d bytes from '%s' failed, "
78+
"err = %d\n", size,
6879
filename, -n);
6980
return -1;
7081
}

‎arch/um/kernel/um_arch.c‎

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,23 @@ static void __init uml_postsetup(void)
223223
return;
224224
}
225225

226+
static int panic_exit(struct notifier_block *self, unsigned long unused1,
227+
void *unused2)
228+
{
229+
bust_spinlocks(1);
230+
show_regs(&(current->thread.regs));
231+
bust_spinlocks(0);
232+
uml_exitcode = 1;
233+
os_dump_core();
234+
return 0;
235+
}
236+
237+
static struct notifier_block panic_exit_notifier = {
238+
.notifier_call = panic_exit,
239+
.next = NULL,
240+
.priority = 0
241+
};
242+
226243
/* Set during early boot */
227244
unsigned long brk_start;
228245
unsigned long end_iomem;
@@ -327,6 +344,9 @@ int __init linux_main(int argc, char **argv)
327344
printf("Kernel virtual memory size shrunk to %lu bytes\n",
328345
virtmem_size);
329346

347+
atomic_notifier_chain_register(&panic_notifier_list,
348+
&panic_exit_notifier);
349+
330350
uml_postsetup();
331351

332352
stack_protections((unsigned long) &init_thread_info);
@@ -335,29 +355,8 @@ int __init linux_main(int argc, char **argv)
335355
return start_uml();
336356
}
337357

338-
extern int uml_exitcode;
339-
340-
static int panic_exit(struct notifier_block *self, unsigned long unused1,
341-
void *unused2)
342-
{
343-
bust_spinlocks(1);
344-
show_regs(&(current->thread.regs));
345-
bust_spinlocks(0);
346-
uml_exitcode = 1;
347-
os_dump_core();
348-
return 0;
349-
}
350-
351-
static struct notifier_block panic_exit_notifier = {
352-
.notifier_call = panic_exit,
353-
.next = NULL,
354-
.priority = 0
355-
};
356-
357358
void __init setup_arch(char **cmdline_p)
358359
{
359-
atomic_notifier_chain_register(&panic_notifier_list,
360-
&panic_exit_notifier);
361360
paging_init();
362361
strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
363362
*cmdline_p = command_line;

‎arch/um/os-Linux/main.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ static void setup_env_path(void)
111111
}
112112
}
113113

114-
extern int uml_exitcode;
115-
116114
extern void scan_elf_aux( char **envp);
117115

118116
int __init main(int argc, char **argv, char **envp)

0 commit comments

Comments
 (0)