aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/kexec.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/kexec.c')
-rw-r--r--kernel/kexec.c74
1 files changed, 31 insertions, 43 deletions
diff --git a/kernel/kexec.c b/kernel/kexec.c
index c8a4370e2a34..aef265325cd3 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -12,7 +12,7 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/kexec.h> 14#include <linux/kexec.h>
15#include <linux/spinlock.h> 15#include <linux/mutex.h>
16#include <linux/list.h> 16#include <linux/list.h>
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/syscalls.h> 18#include <linux/syscalls.h>
@@ -77,7 +77,7 @@ int kexec_should_crash(struct task_struct *p)
77 * 77 *
78 * The code for the transition from the current kernel to the 78 * The code for the transition from the current kernel to the
79 * the new kernel is placed in the control_code_buffer, whose size 79 * the new kernel is placed in the control_code_buffer, whose size
80 * is given by KEXEC_CONTROL_CODE_SIZE. In the best case only a single 80 * is given by KEXEC_CONTROL_PAGE_SIZE. In the best case only a single
81 * page of memory is necessary, but some architectures require more. 81 * page of memory is necessary, but some architectures require more.
82 * Because this memory must be identity mapped in the transition from 82 * Because this memory must be identity mapped in the transition from
83 * virtual to physical addresses it must live in the range 83 * virtual to physical addresses it must live in the range
@@ -242,7 +242,7 @@ static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry,
242 */ 242 */
243 result = -ENOMEM; 243 result = -ENOMEM;
244 image->control_code_page = kimage_alloc_control_pages(image, 244 image->control_code_page = kimage_alloc_control_pages(image,
245 get_order(KEXEC_CONTROL_CODE_SIZE)); 245 get_order(KEXEC_CONTROL_PAGE_SIZE));
246 if (!image->control_code_page) { 246 if (!image->control_code_page) {
247 printk(KERN_ERR "Could not allocate control_code_buffer\n"); 247 printk(KERN_ERR "Could not allocate control_code_buffer\n");
248 goto out; 248 goto out;
@@ -317,7 +317,7 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry,
317 */ 317 */
318 result = -ENOMEM; 318 result = -ENOMEM;
319 image->control_code_page = kimage_alloc_control_pages(image, 319 image->control_code_page = kimage_alloc_control_pages(image,
320 get_order(KEXEC_CONTROL_CODE_SIZE)); 320 get_order(KEXEC_CONTROL_PAGE_SIZE));
321 if (!image->control_code_page) { 321 if (!image->control_code_page) {
322 printk(KERN_ERR "Could not allocate control_code_buffer\n"); 322 printk(KERN_ERR "Could not allocate control_code_buffer\n");
323 goto out; 323 goto out;
@@ -753,8 +753,14 @@ static struct page *kimage_alloc_page(struct kimage *image,
753 *old = addr | (*old & ~PAGE_MASK); 753 *old = addr | (*old & ~PAGE_MASK);
754 754
755 /* The old page I have found cannot be a 755 /* The old page I have found cannot be a
756 * destination page, so return it. 756 * destination page, so return it if it's
757 * gfp_flags honor the ones passed in.
757 */ 758 */
759 if (!(gfp_mask & __GFP_HIGHMEM) &&
760 PageHighMem(old_page)) {
761 kimage_free_pages(old_page);
762 continue;
763 }
758 addr = old_addr; 764 addr = old_addr;
759 page = old_page; 765 page = old_page;
760 break; 766 break;
@@ -924,19 +930,14 @@ static int kimage_load_segment(struct kimage *image,
924 */ 930 */
925struct kimage *kexec_image; 931struct kimage *kexec_image;
926struct kimage *kexec_crash_image; 932struct kimage *kexec_crash_image;
927/* 933
928 * A home grown binary mutex. 934static DEFINE_MUTEX(kexec_mutex);
929 * Nothing can wait so this mutex is safe to use
930 * in interrupt context :)
931 */
932static int kexec_lock;
933 935
934asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments, 936asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments,
935 struct kexec_segment __user *segments, 937 struct kexec_segment __user *segments,
936 unsigned long flags) 938 unsigned long flags)
937{ 939{
938 struct kimage **dest_image, *image; 940 struct kimage **dest_image, *image;
939 int locked;
940 int result; 941 int result;
941 942
942 /* We only trust the superuser with rebooting the system. */ 943 /* We only trust the superuser with rebooting the system. */
@@ -972,8 +973,7 @@ asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments,
972 * 973 *
973 * KISS: always take the mutex. 974 * KISS: always take the mutex.
974 */ 975 */
975 locked = xchg(&kexec_lock, 1); 976 if (!mutex_trylock(&kexec_mutex))
976 if (locked)
977 return -EBUSY; 977 return -EBUSY;
978 978
979 dest_image = &kexec_image; 979 dest_image = &kexec_image;
@@ -1015,8 +1015,7 @@ asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments,
1015 image = xchg(dest_image, image); 1015 image = xchg(dest_image, image);
1016 1016
1017out: 1017out:
1018 locked = xchg(&kexec_lock, 0); /* Release the mutex */ 1018 mutex_unlock(&kexec_mutex);
1019 BUG_ON(!locked);
1020 kimage_free(image); 1019 kimage_free(image);
1021 1020
1022 return result; 1021 return result;
@@ -1063,10 +1062,7 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
1063 1062
1064void crash_kexec(struct pt_regs *regs) 1063void crash_kexec(struct pt_regs *regs)
1065{ 1064{
1066 int locked; 1065 /* Take the kexec_mutex here to prevent sys_kexec_load
1067
1068
1069 /* Take the kexec_lock here to prevent sys_kexec_load
1070 * running on one cpu from replacing the crash kernel 1066 * running on one cpu from replacing the crash kernel
1071 * we are using after a panic on a different cpu. 1067 * we are using after a panic on a different cpu.
1072 * 1068 *
@@ -1074,8 +1070,7 @@ void crash_kexec(struct pt_regs *regs)
1074 * of memory the xchg(&kexec_crash_image) would be 1070 * of memory the xchg(&kexec_crash_image) would be
1075 * sufficient. But since I reuse the memory... 1071 * sufficient. But since I reuse the memory...
1076 */ 1072 */
1077 locked = xchg(&kexec_lock, 1); 1073 if (mutex_trylock(&kexec_mutex)) {
1078 if (!locked) {
1079 if (kexec_crash_image) { 1074 if (kexec_crash_image) {
1080 struct pt_regs fixed_regs; 1075 struct pt_regs fixed_regs;
1081 crash_setup_regs(&fixed_regs, regs); 1076 crash_setup_regs(&fixed_regs, regs);
@@ -1083,8 +1078,7 @@ void crash_kexec(struct pt_regs *regs)
1083 machine_crash_shutdown(&fixed_regs); 1078 machine_crash_shutdown(&fixed_regs);
1084 machine_kexec(kexec_crash_image); 1079 machine_kexec(kexec_crash_image);
1085 } 1080 }
1086 locked = xchg(&kexec_lock, 0); 1081 mutex_unlock(&kexec_mutex);
1087 BUG_ON(!locked);
1088 } 1082 }
1089} 1083}
1090 1084
@@ -1426,25 +1420,23 @@ static int __init crash_save_vmcoreinfo_init(void)
1426 1420
1427module_init(crash_save_vmcoreinfo_init) 1421module_init(crash_save_vmcoreinfo_init)
1428 1422
1429/** 1423/*
1430 * kernel_kexec - reboot the system 1424 * Move into place and start executing a preloaded standalone
1431 * 1425 * executable. If nothing was preloaded return an error.
1432 * Move into place and start executing a preloaded standalone
1433 * executable. If nothing was preloaded return an error.
1434 */ 1426 */
1435int kernel_kexec(void) 1427int kernel_kexec(void)
1436{ 1428{
1437 int error = 0; 1429 int error = 0;
1438 1430
1439 if (xchg(&kexec_lock, 1)) 1431 if (!mutex_trylock(&kexec_mutex))
1440 return -EBUSY; 1432 return -EBUSY;
1441 if (!kexec_image) { 1433 if (!kexec_image) {
1442 error = -EINVAL; 1434 error = -EINVAL;
1443 goto Unlock; 1435 goto Unlock;
1444 } 1436 }
1445 1437
1446 if (kexec_image->preserve_context) {
1447#ifdef CONFIG_KEXEC_JUMP 1438#ifdef CONFIG_KEXEC_JUMP
1439 if (kexec_image->preserve_context) {
1448 mutex_lock(&pm_mutex); 1440 mutex_lock(&pm_mutex);
1449 pm_prepare_console(); 1441 pm_prepare_console();
1450 error = freeze_processes(); 1442 error = freeze_processes();
@@ -1459,6 +1451,7 @@ int kernel_kexec(void)
1459 error = disable_nonboot_cpus(); 1451 error = disable_nonboot_cpus();
1460 if (error) 1452 if (error)
1461 goto Resume_devices; 1453 goto Resume_devices;
1454 device_pm_lock();
1462 local_irq_disable(); 1455 local_irq_disable();
1463 /* At this point, device_suspend() has been called, 1456 /* At this point, device_suspend() has been called,
1464 * but *not* device_power_down(). We *must* 1457 * but *not* device_power_down(). We *must*
@@ -1470,26 +1463,22 @@ int kernel_kexec(void)
1470 error = device_power_down(PMSG_FREEZE); 1463 error = device_power_down(PMSG_FREEZE);
1471 if (error) 1464 if (error)
1472 goto Enable_irqs; 1465 goto Enable_irqs;
1473 save_processor_state(); 1466 } else
1474#endif 1467#endif
1475 } else { 1468 {
1476 blocking_notifier_call_chain(&reboot_notifier_list, 1469 kernel_restart_prepare(NULL);
1477 SYS_RESTART, NULL);
1478 system_state = SYSTEM_RESTART;
1479 device_shutdown();
1480 sysdev_shutdown();
1481 printk(KERN_EMERG "Starting new kernel\n"); 1470 printk(KERN_EMERG "Starting new kernel\n");
1482 machine_shutdown(); 1471 machine_shutdown();
1483 } 1472 }
1484 1473
1485 machine_kexec(kexec_image); 1474 machine_kexec(kexec_image);
1486 1475
1487 if (kexec_image->preserve_context) {
1488#ifdef CONFIG_KEXEC_JUMP 1476#ifdef CONFIG_KEXEC_JUMP
1489 restore_processor_state(); 1477 if (kexec_image->preserve_context) {
1490 device_power_up(PMSG_RESTORE); 1478 device_power_up(PMSG_RESTORE);
1491 Enable_irqs: 1479 Enable_irqs:
1492 local_irq_enable(); 1480 local_irq_enable();
1481 device_pm_unlock();
1493 enable_nonboot_cpus(); 1482 enable_nonboot_cpus();
1494 Resume_devices: 1483 Resume_devices:
1495 device_resume(PMSG_RESTORE); 1484 device_resume(PMSG_RESTORE);
@@ -1499,11 +1488,10 @@ int kernel_kexec(void)
1499 Restore_console: 1488 Restore_console:
1500 pm_restore_console(); 1489 pm_restore_console();
1501 mutex_unlock(&pm_mutex); 1490 mutex_unlock(&pm_mutex);
1502#endif
1503 } 1491 }
1492#endif
1504 1493
1505 Unlock: 1494 Unlock:
1506 xchg(&kexec_lock, 0); 1495 mutex_unlock(&kexec_mutex);
1507
1508 return error; 1496 return error;
1509} 1497}