aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/xen/balloon.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 37d06ea624aa..dd7954922942 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -592,19 +592,29 @@ static void __init balloon_add_region(unsigned long start_pfn,
592 } 592 }
593} 593}
594 594
595static int alloc_balloon_scratch_page(int cpu)
596{
597 if (per_cpu(balloon_scratch_page, cpu) != NULL)
598 return 0;
599
600 per_cpu(balloon_scratch_page, cpu) = alloc_page(GFP_KERNEL);
601 if (per_cpu(balloon_scratch_page, cpu) == NULL) {
602 pr_warn("Failed to allocate balloon_scratch_page for cpu %d\n", cpu);
603 return -ENOMEM;
604 }
605
606 return 0;
607}
608
609
595static int balloon_cpu_notify(struct notifier_block *self, 610static int balloon_cpu_notify(struct notifier_block *self,
596 unsigned long action, void *hcpu) 611 unsigned long action, void *hcpu)
597{ 612{
598 int cpu = (long)hcpu; 613 int cpu = (long)hcpu;
599 switch (action) { 614 switch (action) {
600 case CPU_UP_PREPARE: 615 case CPU_UP_PREPARE:
601 if (per_cpu(balloon_scratch_page, cpu) != NULL) 616 if (alloc_balloon_scratch_page(cpu))
602 break;
603 per_cpu(balloon_scratch_page, cpu) = alloc_page(GFP_KERNEL);
604 if (per_cpu(balloon_scratch_page, cpu) == NULL) {
605 pr_warn("Failed to allocate balloon_scratch_page for cpu %d\n", cpu);
606 return NOTIFY_BAD; 617 return NOTIFY_BAD;
607 }
608 break; 618 break;
609 default: 619 default:
610 break; 620 break;
@@ -624,15 +634,17 @@ static int __init balloon_init(void)
624 return -ENODEV; 634 return -ENODEV;
625 635
626 if (!xen_feature(XENFEAT_auto_translated_physmap)) { 636 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
627 for_each_online_cpu(cpu) 637 register_cpu_notifier(&balloon_cpu_notifier);
628 { 638
629 per_cpu(balloon_scratch_page, cpu) = alloc_page(GFP_KERNEL); 639 get_online_cpus();
630 if (per_cpu(balloon_scratch_page, cpu) == NULL) { 640 for_each_online_cpu(cpu) {
631 pr_warn("Failed to allocate balloon_scratch_page for cpu %d\n", cpu); 641 if (alloc_balloon_scratch_page(cpu)) {
642 put_online_cpus();
643 unregister_cpu_notifier(&balloon_cpu_notifier);
632 return -ENOMEM; 644 return -ENOMEM;
633 } 645 }
634 } 646 }
635 register_cpu_notifier(&balloon_cpu_notifier); 647 put_online_cpus();
636 } 648 }
637 649
638 pr_info("Initialising balloon driver\n"); 650 pr_info("Initialising balloon driver\n");