debuggers.hg

annotate unmodified_drivers/linux-2.6/platform-pci/machine_reboot.c @ 22855:1d1eec7e1fb4

xl: Perform minimal validation of virtual disk file while parsing config file

This patch performs some very basic validation on the virtual disk
file passed through the config file. This validation ensures that we
don't go too far with the initialization like spawn qemu and more
while there could be some potentially fundamental issues.

[ Patch fixed up to work with PHYSTYPE_EMPTY 22808:6ec61438713a -iwj ]

Signed-off-by: Kamala Narasimhan <kamala.narasimhan@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Kamala Narasimhan <kamala.narasimhan@gmail.com>
date Tue Jan 25 18:09:49 2011 +0000 (2011-01-25)
parents 0b8c6c91c5a4
children
rev   line source
kfraser@15759 1 #include <linux/cpumask.h>
kfraser@15759 2 #include <linux/preempt.h>
kfraser@14832 3 #include <xen/evtchn.h>
kfraser@14832 4 #include <xen/gnttab.h>
kfraser@14820 5 #include <xen/xenbus.h>
kfraser@14820 6 #include "platform-pci.h"
kfraser@14820 7 #include <asm/hypervisor.h>
kfraser@14820 8
kfraser@14857 9 struct ap_suspend_info {
kfraser@14857 10 int do_spin;
kfraser@14857 11 atomic_t nr_spinning;
kfraser@14857 12 };
kfraser@14857 13
kfraser@15870 14 #ifdef CONFIG_SMP
kfraser@15870 15
kfraser@15730 16 /*
kfraser@14832 17 * Spinning prevents, for example, APs touching grant table entries while
kfraser@14832 18 * the shared grant table is not mapped into the address space imemdiately
kfraser@14832 19 * after resume.
kfraser@14832 20 */
kfraser@14857 21 static void ap_suspend(void *_info)
kfraser@14832 22 {
kfraser@14857 23 struct ap_suspend_info *info = _info;
kfraser@14832 24
kfraser@14832 25 BUG_ON(!irqs_disabled());
kfraser@14832 26
kfraser@14857 27 atomic_inc(&info->nr_spinning);
kfraser@14857 28 mb();
kfraser@14857 29
keir@18707 30 while (info->do_spin)
kfraser@14832 31 cpu_relax();
kfraser@14857 32
kfraser@14857 33 mb();
kfraser@14857 34 atomic_dec(&info->nr_spinning);
kfraser@14832 35 }
kfraser@14832 36
keir@18843 37 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
kfraser@15870 38 #define initiate_ap_suspend(i) smp_call_function(ap_suspend, i, 0, 0)
keir@18843 39 #else
keir@18843 40 #define initiate_ap_suspend(i) smp_call_function(ap_suspend, i, 0)
keir@18843 41 #endif
kfraser@15870 42
kfraser@15870 43 #else /* !defined(CONFIG_SMP) */
kfraser@15870 44
kfraser@15870 45 #define initiate_ap_suspend(i) 0
kfraser@15870 46
kfraser@15870 47 #endif
kfraser@15870 48
kfraser@14832 49 static int bp_suspend(void)
kfraser@14820 50 {
kfraser@14820 51 int suspend_cancelled;
kfraser@14820 52
kfraser@14832 53 BUG_ON(!irqs_disabled());
kfraser@14820 54
keir@16900 55 suspend_cancelled = HYPERVISOR_suspend(0);
kfraser@14820 56
kfraser@14832 57 if (!suspend_cancelled) {
kfraser@14832 58 platform_pci_resume();
kfraser@14832 59 gnttab_resume();
kfraser@14832 60 irq_resume();
kfraser@14832 61 }
kfraser@14832 62
kfraser@14832 63 return suspend_cancelled;
kfraser@14832 64 }
kfraser@14832 65
keir@18237 66 int __xen_suspend(int fast_suspend, void (*resume_notifier)(int))
kfraser@14832 67 {
kfraser@14857 68 int err, suspend_cancelled, nr_cpus;
kfraser@14857 69 struct ap_suspend_info info;
kfraser@14832 70
kfraser@14832 71 xenbus_suspend();
kfraser@14832 72
kfraser@14832 73 preempt_disable();
kfraser@14832 74
kfraser@14832 75 /* Prevent any races with evtchn_interrupt() handler. */
kfraser@14832 76 disable_irq(xen_platform_pdev->irq);
kfraser@14832 77
kfraser@14857 78 info.do_spin = 1;
kfraser@14857 79 atomic_set(&info.nr_spinning, 0);
kfraser@14832 80 smp_mb();
kfraser@14832 81
kfraser@14857 82 nr_cpus = num_online_cpus() - 1;
kfraser@14857 83
kfraser@15870 84 err = initiate_ap_suspend(&info);
kfraser@14832 85 if (err < 0) {
kfraser@14832 86 preempt_enable();
kfraser@14820 87 xenbus_suspend_cancel();
kfraser@14832 88 return err;
kfraser@14832 89 }
kfraser@14832 90
kfraser@14857 91 while (atomic_read(&info.nr_spinning) != nr_cpus)
kfraser@14857 92 cpu_relax();
kfraser@14857 93
kfraser@14832 94 local_irq_disable();
kfraser@14832 95 suspend_cancelled = bp_suspend();
keir@18237 96 resume_notifier(suspend_cancelled);
kfraser@14832 97 local_irq_enable();
kfraser@14832 98
kfraser@14832 99 smp_mb();
kfraser@14857 100 info.do_spin = 0;
kfraser@14857 101 while (atomic_read(&info.nr_spinning) != 0)
kfraser@14857 102 cpu_relax();
kfraser@14832 103
kfraser@14832 104 enable_irq(xen_platform_pdev->irq);
kfraser@14832 105
kfraser@14832 106 preempt_enable();
kfraser@14832 107
kfraser@14832 108 if (!suspend_cancelled)
kfraser@14820 109 xenbus_resume();
kfraser@14832 110 else
kfraser@14832 111 xenbus_suspend_cancel();
kfraser@14820 112
kfraser@14820 113 return 0;
kfraser@14820 114 }