xcp-1.6-updates/xen-4.1.hg

changeset 23269:d67e4d12723f

Introduce system_state variable.

Use it to replace x86-specific early_boot boolean variable.

Also use it to detect suspend/resume case during cpu offline/online
to avoid unnecessarily breaking vcpu and cpupool affinities.

Signed-off-by: Keir Fraser <keir@xen.org>
Acked-by: Juergen Gross <juergen.gross@ts.fujitsu.com>
xen-unstable changeset: 25079:d5ccb2d1dbd1
xen-unstable date: Thu Mar 22 12:20:13 2012 +0000

Backport requested by Juergen to fix crash on poweroff when using
cpupools.
author Keir Fraser <keir@xen.org>
date Fri Mar 23 14:01:05 2012 +0000 (2012-03-23)
parents 35e2f18e04b6
children c7729c73fefc
files xen/arch/x86/acpi/power.c xen/arch/x86/mm.c xen/arch/x86/setup.c xen/arch/x86/x86_32/mm.c xen/arch/x86/x86_64/mm.c xen/common/cpupool.c xen/common/kernel.c xen/common/schedule.c xen/include/asm-x86/setup.h xen/include/xen/kernel.h
line diff
     1.1 --- a/xen/arch/x86/acpi/power.c	Fri Mar 23 13:58:22 2012 +0000
     1.2 +++ b/xen/arch/x86/acpi/power.c	Fri Mar 23 14:01:05 2012 +0000
     1.3 @@ -135,6 +135,9 @@ static int enter_state(u32 state)
     1.4      if ( !spin_trylock(&pm_lock) )
     1.5          return -EBUSY;
     1.6  
     1.7 +    BUG_ON(system_state != SYS_STATE_active);
     1.8 +    system_state = SYS_STATE_suspend;
     1.9 +
    1.10      printk(XENLOG_INFO "Preparing system for ACPI S%d state.\n", state);
    1.11  
    1.12      freeze_domains();
    1.13 @@ -142,7 +145,10 @@ static int enter_state(u32 state)
    1.14      acpi_dmar_reinstate();
    1.15  
    1.16      if ( (error = disable_nonboot_cpus()) )
    1.17 +    {
    1.18 +        system_state = SYS_STATE_resume;
    1.19          goto enable_cpu;
    1.20 +    }
    1.21  
    1.22      cpufreq_del_cpu(0);
    1.23  
    1.24 @@ -159,6 +165,7 @@ static int enter_state(u32 state)
    1.25      if ( (error = device_power_down()) )
    1.26      {
    1.27          printk(XENLOG_ERR "Some devices failed to power down.");
    1.28 +        system_state = SYS_STATE_resume;
    1.29          goto done;
    1.30      }
    1.31  
    1.32 @@ -179,6 +186,8 @@ static int enter_state(u32 state)
    1.33          break;
    1.34      }
    1.35  
    1.36 +    system_state = SYS_STATE_resume;
    1.37 +
    1.38      /* Restore CR4 and EFER from cached values. */
    1.39      cr4 = read_cr4();
    1.40      write_cr4(cr4 & ~X86_CR4_MCE);
    1.41 @@ -212,6 +221,7 @@ static int enter_state(u32 state)
    1.42      mtrr_aps_sync_end();
    1.43      acpi_dmar_zap();
    1.44      thaw_domains();
    1.45 +    system_state = SYS_STATE_active;
    1.46      spin_unlock(&pm_lock);
    1.47      return error;
    1.48  }
     2.1 --- a/xen/arch/x86/mm.c	Fri Mar 23 13:58:22 2012 +0000
     2.2 +++ b/xen/arch/x86/mm.c	Fri Mar 23 14:01:05 2012 +0000
     2.3 @@ -5123,7 +5123,7 @@ int ptwr_do_page_fault(struct vcpu *v, u
     2.4  
     2.5  void free_xen_pagetable(void *v)
     2.6  {
     2.7 -    if ( early_boot )
     2.8 +    if ( system_state == SYS_STATE_early_boot )
     2.9          return;
    2.10  
    2.11      if ( is_xen_heap_page(virt_to_page(v)) )
     3.1 --- a/xen/arch/x86/setup.c	Fri Mar 23 13:58:22 2012 +0000
     3.2 +++ b/xen/arch/x86/setup.c	Fri Mar 23 14:01:05 2012 +0000
     3.3 @@ -87,8 +87,6 @@ boolean_param("noapic", skip_ioapic_setu
     3.4  s8 __read_mostly xen_cpuidle = -1;
     3.5  boolean_param("cpuidle", xen_cpuidle);
     3.6  
     3.7 -bool_t __read_mostly early_boot = 1;
     3.8 -
     3.9  cpumask_t __read_mostly cpu_present_map;
    3.10  
    3.11  unsigned long __read_mostly xen_phys_start;
    3.12 @@ -275,7 +273,7 @@ static void *__init bootstrap_map(const 
    3.13      void *ret;
    3.14  
    3.15  #ifdef __x86_64__
    3.16 -    if ( !early_boot )
    3.17 +    if ( system_state != SYS_STATE_early_boot )
    3.18          return mod ? mfn_to_virt(mod->mod_start) : NULL;
    3.19  #endif
    3.20  
    3.21 @@ -1142,7 +1140,7 @@ void __init __start_xen(unsigned long mb
    3.22  #endif
    3.23  
    3.24      end_boot_allocator();
    3.25 -    early_boot = 0;
    3.26 +    system_state = SYS_STATE_boot;
    3.27  
    3.28  #if defined(CONFIG_X86_64)
    3.29      vesa_init();
    3.30 @@ -1341,6 +1339,8 @@ void __init __start_xen(unsigned long mb
    3.31      /* Hide UART from DOM0 if we're using it */
    3.32      serial_endboot();
    3.33  
    3.34 +    system_state = SYS_STATE_active;
    3.35 +
    3.36      domain_unpause_by_systemcontroller(dom0);
    3.37  
    3.38      reset_stack_and_jump(init_done);
     4.1 --- a/xen/arch/x86/x86_32/mm.c	Fri Mar 23 13:58:22 2012 +0000
     4.2 +++ b/xen/arch/x86/x86_32/mm.c	Fri Mar 23 14:01:05 2012 +0000
     4.3 @@ -45,7 +45,7 @@ void *alloc_xen_pagetable(void)
     4.4  {
     4.5      unsigned long mfn;
     4.6  
     4.7 -    if ( !early_boot )
     4.8 +    if ( system_state != SYS_STATE_early_boot )
     4.9      {
    4.10          void *v = alloc_xenheap_page();
    4.11  
     5.1 --- a/xen/arch/x86/x86_64/mm.c	Fri Mar 23 13:58:22 2012 +0000
     5.2 +++ b/xen/arch/x86/x86_64/mm.c	Fri Mar 23 14:01:05 2012 +0000
     5.3 @@ -81,7 +81,7 @@ void *alloc_xen_pagetable(void)
     5.4  {
     5.5      unsigned long mfn;
     5.6  
     5.7 -    if ( !early_boot )
     5.8 +    if ( system_state != SYS_STATE_early_boot )
     5.9      {
    5.10          struct page_info *pg = alloc_domheap_page(NULL, 0);
    5.11  
     6.1 --- a/xen/common/cpupool.c	Fri Mar 23 13:58:22 2012 +0000
     6.2 +++ b/xen/common/cpupool.c	Fri Mar 23 14:01:05 2012 +0000
     6.3 @@ -616,6 +616,10 @@ static int cpu_callback(
     6.4      unsigned int cpu = (unsigned long)hcpu;
     6.5      int rc = 0;
     6.6  
     6.7 +    if ( (system_state == SYS_STATE_suspend) ||
     6.8 +         (system_state == SYS_STATE_resume) )
     6.9 +        goto out;
    6.10 +
    6.11      switch ( action )
    6.12      {
    6.13      case CPU_DOWN_FAILED:
    6.14 @@ -629,6 +633,7 @@ static int cpu_callback(
    6.15          break;
    6.16      }
    6.17  
    6.18 +out:
    6.19      return !rc ? NOTIFY_DONE : notifier_from_errno(rc);
    6.20  }
    6.21  
     7.1 --- a/xen/common/kernel.c	Fri Mar 23 13:58:22 2012 +0000
     7.2 +++ b/xen/common/kernel.c	Fri Mar 23 14:01:05 2012 +0000
     7.3 @@ -22,6 +22,8 @@
     7.4  
     7.5  #ifndef COMPAT
     7.6  
     7.7 +enum system_state system_state = SYS_STATE_early_boot;
     7.8 +
     7.9  int tainted;
    7.10  
    7.11  xen_commandline_t saved_cmdline;
     8.1 --- a/xen/common/schedule.c	Fri Mar 23 13:58:22 2012 +0000
     8.2 +++ b/xen/common/schedule.c	Fri Mar 23 14:01:05 2012 +0000
     8.3 @@ -546,7 +546,7 @@ int cpu_disable_scheduler(unsigned int c
     8.4      bool_t affinity_broken;
     8.5  
     8.6      c = per_cpu(cpupool, cpu);
     8.7 -    if ( c == NULL )
     8.8 +    if ( (c == NULL) || (system_state == SYS_STATE_suspend) )
     8.9          return ret;
    8.10  
    8.11      for_each_domain ( d )
     9.1 --- a/xen/include/asm-x86/setup.h	Fri Mar 23 13:58:22 2012 +0000
     9.2 +++ b/xen/include/asm-x86/setup.h	Fri Mar 23 14:01:05 2012 +0000
     9.3 @@ -3,7 +3,6 @@
     9.4  
     9.5  #include <xen/multiboot.h>
     9.6  
     9.7 -extern bool_t early_boot;
     9.8  extern unsigned long xenheap_initial_phys_start;
     9.9  
    9.10  void init_done(void);
    10.1 --- a/xen/include/xen/kernel.h	Fri Mar 23 13:58:22 2012 +0000
    10.2 +++ b/xen/include/xen/kernel.h	Fri Mar 23 14:01:05 2012 +0000
    10.3 @@ -81,5 +81,13 @@ extern char _sinittext[], _einittext[];
    10.4      (__p >= _sinittext) && (__p <= _einittext); \
    10.5  })
    10.6  
    10.7 +extern enum system_state {
    10.8 +    SYS_STATE_early_boot,
    10.9 +    SYS_STATE_boot,
   10.10 +    SYS_STATE_active,
   10.11 +    SYS_STATE_suspend,
   10.12 +    SYS_STATE_resume
   10.13 +} system_state;
   10.14 +
   10.15  #endif /* _LINUX_KERNEL_H */
   10.16