Merge branch 'linus' into stackprotector
authorIngo Molnar <mingo@elte.hu>
Wed, 15 Oct 2008 11:46:29 +0000 (13:46 +0200)
committerIngo Molnar <mingo@elte.hu>
Wed, 15 Oct 2008 11:46:29 +0000 (13:46 +0200)
Conflicts:
arch/x86/kernel/Makefile
include/asm-x86/pda.h

15 files changed:
1  2 
arch/x86/Kconfig
arch/x86/Kconfig.debug
arch/x86/Makefile
arch/x86/kernel/Makefile
arch/x86/kernel/process_64.c
arch/x86/mm/fault.c
include/asm-x86/pda.h
include/asm-x86/system.h
include/linux/magic.h
include/linux/sched.h
init/main.c
kernel/exit.c
kernel/fork.c
kernel/panic.c
kernel/sched.c

diff --combined arch/x86/Kconfig
@@@ -18,13 -18,21 +18,21 @@@ config X86_6
  ### Arch settings
  config X86
        def_bool y
+       select HAVE_AOUT if X86_32
        select HAVE_UNSTABLE_SCHED_CLOCK
        select HAVE_IDE
        select HAVE_OPROFILE
+       select HAVE_IOREMAP_PROT
        select HAVE_KPROBES
+       select ARCH_WANT_OPTIONAL_GPIOLIB
        select HAVE_KRETPROBES
+       select HAVE_DYNAMIC_FTRACE
+       select HAVE_FTRACE
        select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64)
        select HAVE_ARCH_KGDB if !X86_VOYAGER
+       select HAVE_ARCH_TRACEHOOK
+       select HAVE_GENERIC_DMA_COHERENT if X86_32
+       select HAVE_EFFICIENT_UNALIGNED_ACCESS
  
  config ARCH_DEFCONFIG
        string
@@@ -121,7 -129,7 +129,7 @@@ config ARCH_HAS_CACHE_LINE_SIZ
        def_bool y
  
  config HAVE_SETUP_PER_CPU_AREA
-       def_bool X86_64 || (X86_SMP && !X86_VOYAGER)
+       def_bool X86_64_SMP || (X86_SMP && !X86_VOYAGER)
  
  config HAVE_CPUMASK_OF_CPU_MAP
        def_bool X86_64_SMP
@@@ -145,9 -153,6 +153,6 @@@ config AUDIT_ARC
        bool
        default X86_64
  
- config ARCH_SUPPORTS_AOUT
-       def_bool y
  config ARCH_SUPPORTS_OPTIMIZED_INLINING
        def_bool y
  
@@@ -168,6 -173,7 +173,7 @@@ config GENERIC_PENDING_IR
  config X86_SMP
        bool
        depends on SMP && ((X86_32 && !X86_VOYAGER) || X86_64)
+       select USE_GENERIC_SMP_HELPERS
        default y
  
  config X86_32_SMP
@@@ -181,12 -187,12 +187,12 @@@ config X86_64_SM
  config X86_HT
        bool
        depends on SMP
-       depends on (X86_32 && !(X86_VISWS || X86_VOYAGER)) || X86_64
+       depends on (X86_32 && !X86_VOYAGER) || X86_64
        default y
  
  config X86_BIOS_REBOOT
        bool
-       depends on !X86_VISWS && !X86_VOYAGER
+       depends on !X86_VOYAGER
        default y
  
  config X86_TRAMPOLINE
@@@ -230,6 -236,26 +236,26 @@@ config SM
  
          If you don't know what to do here, say N.
  
+ config X86_FIND_SMP_CONFIG
+       def_bool y
+       depends on X86_MPPARSE || X86_VOYAGER
+ if ACPI
+ config X86_MPPARSE
+       def_bool y
+       bool "Enable MPS table"
+       depends on X86_LOCAL_APIC
+       help
+         For old smp systems that do not have proper acpi support. Newer systems
+         (esp with 64bit cpus) with acpi support, MADT and DSDT will override it
+ endif
+ if !ACPI
+ config X86_MPPARSE
+       def_bool y
+       depends on X86_LOCAL_APIC
+ endif
  choice
        prompt "Subarchitecture Type"
        default X86_PC
@@@ -251,7 -277,7 +277,7 @@@ config X86_ELA
  
  config X86_VOYAGER
        bool "Voyager (NCR)"
-       depends on X86_32 && (SMP || BROKEN)
+       depends on X86_32 && (SMP || BROKEN) && !PCI
        help
          Voyager is an MCA-based 32-way capable SMP architecture proprietary
          to NCR Corp.  Machine classes 345x/35xx/4100/51xx are Voyager-based.
          If you do not specifically know you have a Voyager based machine,
          say N here, otherwise the kernel you build will not be bootable.
  
+ config X86_GENERICARCH
+        bool "Generic architecture"
+       depends on X86_32
+        help
+           This option compiles in the NUMAQ, Summit, bigsmp, ES7000, default
+         subarchitectures.  It is intended for a generic binary kernel.
+         if you select them all, kernel will probe it one by one. and will
+         fallback to default.
+ if X86_GENERICARCH
  config X86_NUMAQ
        bool "NUMAQ (IBM/Sequent)"
-       depends on SMP && X86_32
+       depends on SMP && X86_32 && PCI && X86_MPPARSE
        select NUMA
        help
-         This option is used for getting Linux to run on a (IBM/Sequent) NUMA
-         multiquad box. This changes the way that processors are bootstrapped,
-         and uses Clustered Logical APIC addressing mode instead of Flat Logical.
-         You will need a new lynxer.elf file to flash your firmware with - send
-         email to <Martin.Bligh@us.ibm.com>.
+         This option is used for getting Linux to run on a NUMAQ (IBM/Sequent)
+         NUMA multiquad box. This changes the way that processors are
+         bootstrapped, and uses Clustered Logical APIC addressing mode instead
+         of Flat Logical.  You will need a new lynxer.elf file to flash your
+         firmware with - send email to <Martin.Bligh@us.ibm.com>.
  
  config X86_SUMMIT
        bool "Summit/EXA (IBM x440)"
          This option is needed for IBM systems that use the Summit/EXA chipset.
          In particular, it is needed for the x440.
  
-         If you don't have one of these computers, you should say N here.
-         If you want to build a NUMA kernel, you must select ACPI.
+ config X86_ES7000
+       bool "Support for Unisys ES7000 IA32 series"
+       depends on X86_32 && SMP
+       help
+         Support for Unisys ES7000 systems.  Say 'Y' here if this kernel is
+         supposed to run on an IA32-based Unisys ES7000 system.
  
  config X86_BIGSMP
-       bool "Support for other sub-arch SMP systems with more than 8 CPUs"
+       bool "Support for big SMP systems with more than 8 CPUs"
        depends on X86_32 && SMP
        help
          This option is needed for the systems that have more than 8 CPUs
          and if the system is not of any sub-arch type above.
  
-         If you don't have such a system, you should say N here.
+ endif
+ config X86_VSMP
+       bool "Support for ScaleMP vSMP"
+       select PARAVIRT
+       depends on X86_64 && PCI
+       help
+         Support for ScaleMP vSMP systems.  Say 'Y' here if this kernel is
+         supposed to run on these EM64T-based machines.  Only choose this option
+         if you have one of these machines.
+ endchoice
  
  config X86_VISWS
        bool "SGI 320/540 (Visual Workstation)"
-       depends on X86_32
+       depends on X86_32 && PCI && !X86_VOYAGER && X86_MPPARSE && PCI_GODIRECT
        help
          The SGI Visual Workstation series is an IA32-based workstation
          based on SGI systems chips with some legacy PC hardware attached.
  
          Say Y here to create a kernel to run on the SGI 320 or 540.
  
-         A kernel compiled for the Visual Workstation will not run on PCs
-         and vice versa. See <file:Documentation/sgi-visws.txt> for details.
- config X86_GENERICARCH
-        bool "Generic architecture (Summit, bigsmp, ES7000, default)"
-       depends on X86_32
-        help
-           This option compiles in the Summit, bigsmp, ES7000, default subarchitectures.
-         It is intended for a generic binary kernel.
-         If you want a NUMA kernel, select ACPI.   We need SRAT for NUMA.
- config X86_ES7000
-       bool "Support for Unisys ES7000 IA32 series"
-       depends on X86_32 && SMP
-       help
-         Support for Unisys ES7000 systems.  Say 'Y' here if this kernel is
-         supposed to run on an IA32-based Unisys ES7000 system.
-         Only choose this option if you have such a system, otherwise you
-         should say N here.
+         A kernel compiled for the Visual Workstation will run on general
+         PCs as well. See <file:Documentation/sgi-visws.txt> for details.
  
  config X86_RDC321X
        bool "RDC R-321x SoC"
        depends on X86_32
        select M486
        select X86_REBOOTFIXUPS
-       select GENERIC_GPIO
-       select LEDS_CLASS
-       select LEDS_GPIO
-       select NEW_LEDS
        help
          This option is needed for RDC R-321x system-on-chip, also known
          as R-8610-(G).
          If you don't have one of these chips, you should say N here.
  
- config X86_VSMP
-       bool "Support for ScaleMP vSMP"
-       select PARAVIRT
-       depends on X86_64
-       help
-         Support for ScaleMP vSMP systems.  Say 'Y' here if this kernel is
-         supposed to run on these EM64T-based machines.  Only choose this option
-         if you have one of these machines.
- endchoice
  config SCHED_NO_NO_OMIT_FRAME_POINTER
        def_bool y
        prompt "Single-depth WCHAN output"
@@@ -373,7 -393,7 +393,7 @@@ config VM
        bool "VMI Guest support"
        select PARAVIRT
        depends on X86_32
-       depends on !(X86_VISWS || X86_VOYAGER)
+       depends on !X86_VOYAGER
        help
          VMI provides a paravirtualized interface to the VMware ESX server
          (it could be used by other hypervisors in theory too, but is not
@@@ -384,7 -404,7 +404,7 @@@ config KVM_CLOC
        bool "KVM paravirtualized clock"
        select PARAVIRT
        select PARAVIRT_CLOCK
-       depends on !(X86_VISWS || X86_VOYAGER)
+       depends on !X86_VOYAGER
        help
          Turning on this option will allow you to run a paravirtualized clock
          when running over the KVM hypervisor. Instead of relying on a PIT
  config KVM_GUEST
        bool "KVM Guest support"
        select PARAVIRT
-       depends on !(X86_VISWS || X86_VOYAGER)
+       depends on !X86_VOYAGER
        help
         This option enables various optimizations for running under the KVM
         hypervisor.
@@@ -404,7 -424,7 +424,7 @@@ source "arch/x86/lguest/Kconfig
  
  config PARAVIRT
        bool "Enable paravirtualization code"
-       depends on !(X86_VISWS || X86_VOYAGER)
+       depends on !X86_VOYAGER
        help
          This changes the kernel so it can modify itself when it is run
          under a hypervisor, potentially improving performance significantly
@@@ -417,51 -437,31 +437,31 @@@ config PARAVIRT_CLOC
  
  endif
  
- config MEMTEST_BOOTPARAM
-       bool "Memtest boot parameter"
-       depends on X86_64
-       default y
-       help
-         This option adds a kernel parameter 'memtest', which allows memtest
-         to be disabled at boot.  If this option is selected, memtest
-         functionality can be disabled with memtest=0 on the kernel
-         command line.  The purpose of this option is to allow a single
-         kernel image to be distributed with memtest built in, but not
-         necessarily enabled.
-         If you are unsure how to answer this question, answer Y.
+ config PARAVIRT_DEBUG
+        bool "paravirt-ops debugging"
+        depends on PARAVIRT && DEBUG_KERNEL
+        help
+          Enable to debug paravirt_ops internals.  Specifically, BUG if
+        a paravirt_op is missing when it is called.
  
- config MEMTEST_BOOTPARAM_VALUE
-       int "Memtest boot parameter default value (0-4)"
-       depends on MEMTEST_BOOTPARAM
-       range 0 4
-       default 0
+ config MEMTEST
+       bool "Memtest"
        help
-         This option sets the default value for the kernel parameter
-         'memtest', which allows memtest to be disabled at boot.  If this
-         option is set to 0 (zero), the memtest kernel parameter will
-         default to 0, disabling memtest at bootup.  If this option is
-         set to 4, the memtest kernel parameter will default to 4,
-         enabling memtest at bootup, and use that as pattern number.
-         If you are unsure how to answer this question, answer 0.
- config ACPI_SRAT
-       def_bool y
-       depends on X86_32 && ACPI && NUMA && (X86_SUMMIT || X86_GENERICARCH)
-       select ACPI_NUMA
- config HAVE_ARCH_PARSE_SRAT
-       def_bool y
-       depends on ACPI_SRAT
+         This option adds a kernel parameter 'memtest', which allows memtest
+         to be set.
+               memtest=0, mean disabled; -- default
+               memtest=1, mean do 1 test pattern;
+               ...
+               memtest=4, mean do 4 test patterns.
+         If you are unsure how to answer this question, answer N.
  
  config X86_SUMMIT_NUMA
        def_bool y
-       depends on X86_32 && NUMA && (X86_SUMMIT || X86_GENERICARCH)
+       depends on X86_32 && NUMA && X86_GENERICARCH
  
  config X86_CYCLONE_TIMER
        def_bool y
-       depends on X86_32 && X86_SUMMIT || X86_GENERICARCH
+       depends on X86_GENERICARCH
  
  config ES7000_CLUSTERED_APIC
        def_bool y
@@@ -549,6 -549,22 +549,22 @@@ config CALGARY_IOMMU_ENABLED_BY_DEFAUL
          Calgary anyway, pass 'iommu=calgary' on the kernel command line.
          If unsure, say Y.
  
+ config AMD_IOMMU
+       bool "AMD IOMMU support"
+       select SWIOTLB
+       select PCI_MSI
+       depends on X86_64 && PCI && ACPI
+       help
+         With this option you can enable support for AMD IOMMU hardware in
+         your system. An IOMMU is a hardware component which provides
+         remapping of DMA memory accesses from devices. With an AMD IOMMU you
+         can isolate the the DMA memory of different devices and protect the
+         system from misbehaving device drivers or hardware.
+         You can find out if your system has an AMD IOMMU if you look into
+         your BIOS for an option to enable it or if you have an IVRS ACPI
+         table.
  # need this always selected by IOMMU for the VIA workaround
  config SWIOTLB
        bool
          3 GB of memory. If unsure, say Y.
  
  config IOMMU_HELPER
-       def_bool (CALGARY_IOMMU || GART_IOMMU || SWIOTLB)
+       def_bool (CALGARY_IOMMU || GART_IOMMU || SWIOTLB || AMD_IOMMU)
+ config MAXSMP
+       bool "Configure Maximum number of SMP Processors and NUMA Nodes"
+       depends on X86_64 && SMP && BROKEN
+       default n
+       help
+         Configure maximum number of CPUS and NUMA Nodes for this architecture.
+         If unsure, say N.
  
  config NR_CPUS
-       int "Maximum number of CPUs (2-255)"
-       range 2 255
+       int "Maximum number of CPUs (2-512)" if !MAXSMP
+       range 2 512
        depends on SMP
+       default "4096" if MAXSMP
        default "32" if X86_NUMAQ || X86_SUMMIT || X86_BIGSMP || X86_ES7000
        default "8"
        help
          This allows you to specify the maximum number of CPUs which this
-         kernel will support.  The maximum supported value is 255 and the
+         kernel will support.  The maximum supported value is 512 and the
          minimum value which makes sense is 2.
  
          This is purely to save memory - each supported CPU adds
@@@ -598,7 -623,7 +623,7 @@@ source "kernel/Kconfig.preempt
  
  config X86_UP_APIC
        bool "Local APIC support on uniprocessors"
-       depends on X86_32 && !SMP && !(X86_VISWS || X86_VOYAGER || X86_GENERICARCH)
+       depends on X86_32 && !SMP && !(X86_VOYAGER || X86_GENERICARCH)
        help
          A local APIC (Advanced Programmable Interrupt Controller) is an
          integrated interrupt controller in the CPU. If you have a single-CPU
@@@ -623,11 -648,11 +648,11 @@@ config X86_UP_IOAPI
  
  config X86_LOCAL_APIC
        def_bool y
-       depends on X86_64 || (X86_32 && (X86_UP_APIC || ((X86_VISWS || SMP) && !X86_VOYAGER) || X86_GENERICARCH))
+       depends on X86_64 || (X86_32 && (X86_UP_APIC || (SMP && !X86_VOYAGER) || X86_GENERICARCH))
  
  config X86_IO_APIC
        def_bool y
-       depends on X86_64 || (X86_32 && (X86_UP_IOAPIC || (SMP && !(X86_VISWS || X86_VOYAGER)) || X86_GENERICARCH))
+       depends on X86_64 || (X86_32 && (X86_UP_IOAPIC || (SMP && !X86_VOYAGER) || X86_GENERICARCH))
  
  config X86_VISWS_APIC
        def_bool y
@@@ -681,7 -706,7 +706,7 @@@ config X86_MCE_NONFATA
  
  config X86_MCE_P4THERMAL
        bool "check for P4 thermal throttling interrupt."
-       depends on X86_32 && X86_MCE && (X86_UP_APIC || SMP) && !X86_VISWS
+       depends on X86_32 && X86_MCE && (X86_UP_APIC || SMP)
        help
          Enabling this feature will cause a message to be printed when the P4
          enters thermal throttling.
@@@ -751,23 -776,45 +776,45 @@@ config X86_REBOOTFIXUP
          Say N otherwise.
  
  config MICROCODE
-       tristate "/dev/cpu/microcode - Intel IA32 CPU microcode support"
+       tristate "/dev/cpu/microcode - microcode support"
        select FW_LOADER
        ---help---
          If you say Y here, you will be able to update the microcode on
-         Intel processors in the IA32 family, e.g. Pentium Pro, Pentium II,
-         Pentium III, Pentium 4, Xeon etc.  You will obviously need the
-         actual microcode binary data itself which is not shipped with the
-         Linux kernel.
+         certain Intel and AMD processors. The Intel support is for the
+         IA32 family, e.g. Pentium Pro, Pentium II, Pentium III,
+         Pentium 4, Xeon etc. The AMD support is for family 0x10 and
+         0x11 processors, e.g. Opteron, Phenom and Turion 64 Ultra.
+         You will obviously need the actual microcode binary data itself
+         which is not shipped with the Linux kernel.
  
-         For latest news and information on obtaining all the required
-         ingredients for this driver, check:
-         <http://www.urbanmyth.org/microcode/>.
+         This option selects the general module only, you need to select
+         at least one vendor specific module as well.
  
          To compile this driver as a module, choose M here: the
          module will be called microcode.
  
- config MICROCODE_OLD_INTERFACE
+ config MICROCODE_INTEL
+        bool "Intel microcode patch loading support"
+        depends on MICROCODE
+        default MICROCODE
+        select FW_LOADER
+        --help---
+          This options enables microcode patch loading support for Intel
+          processors.
+          For latest news and information on obtaining all the required
+          Intel ingredients for this driver, check:
+          <http://www.urbanmyth.org/microcode/>.
+ config MICROCODE_AMD
+        bool "AMD microcode patch loading support"
+        depends on MICROCODE
+        select FW_LOADER
+        --help---
+          If you select this option, microcode patch loading support for AMD
+        processors will be enabled.
+    config MICROCODE_OLD_INTERFACE
        def_bool y
        depends on MICROCODE
  
@@@ -911,18 -958,18 +958,18 @@@ config X86_PA
  config NUMA
        bool "Numa Memory Allocation and Scheduler Support (EXPERIMENTAL)"
        depends on SMP
-       depends on X86_64 || (X86_32 && HIGHMEM64G && (X86_NUMAQ || (X86_SUMMIT || X86_GENERICARCH) && ACPI) && EXPERIMENTAL)
+       depends on X86_64 || (X86_32 && HIGHMEM64G && (X86_NUMAQ || X86_BIGSMP || X86_SUMMIT && ACPI) && EXPERIMENTAL)
        default n if X86_PC
-       default y if (X86_NUMAQ || X86_SUMMIT)
+       default y if (X86_NUMAQ || X86_SUMMIT || X86_BIGSMP)
        help
          Enable NUMA (Non Uniform Memory Access) support.
          The kernel will try to allocate memory used by a CPU on the
          local memory controller of the CPU and add some more
          NUMA awareness to the kernel.
  
-         For i386 this is currently highly experimental and should be only
+         For 32-bit this is currently highly experimental and should be only
          used for kernel development. It might also cause boot failures.
-         For x86_64 this is recommended on all multiprocessor Opteron systems.
+         For 64-bit this is recommended on all multiprocessor Opteron systems.
          If the system is EM64T, you should say N unless your system is
          EM64T NUMA.
  
@@@ -966,12 -1013,16 +1013,16 @@@ config NUMA_EM
          number of nodes. This is only useful for debugging.
  
  config NODES_SHIFT
-       int "Max num nodes shift(1-15)"
-       range 1 15  if X86_64
+       int "Maximum NUMA Nodes (as a power of 2)" if !MAXSMP
+       range 1 9   if X86_64
+       default "9" if MAXSMP
        default "6" if X86_64
        default "4" if X86_NUMAQ
        default "3"
        depends on NEED_MULTIPLE_NODES
+       help
+         Specify the maximum number of NUMA Nodes available on the target
+         system.  Increases memory reserved to accomodate various tables.
  
  config HAVE_ARCH_BOOTMEM_NODE
        def_bool y
@@@ -991,7 -1042,7 +1042,7 @@@ config HAVE_ARCH_ALLOC_REMA
  
  config ARCH_FLATMEM_ENABLE
        def_bool y
-       depends on X86_32 && ARCH_SELECT_MEMORY_MODEL && X86_PC && !NUMA
+       depends on X86_32 && ARCH_SELECT_MEMORY_MODEL && !NUMA
  
  config ARCH_DISCONTIGMEM_ENABLE
        def_bool y
@@@ -1007,7 -1058,7 +1058,7 @@@ config ARCH_SPARSEMEM_DEFAUL
  
  config ARCH_SPARSEMEM_ENABLE
        def_bool y
-       depends on X86_64 || NUMA || (EXPERIMENTAL && X86_PC)
+       depends on X86_64 || NUMA || (EXPERIMENTAL && X86_PC) || X86_GENERICARCH
        select SPARSEMEM_STATIC if X86_32
        select SPARSEMEM_VMEMMAP_ENABLE if X86_64
  
@@@ -1030,6 -1081,56 +1081,56 @@@ config HIGHPT
          low memory.  Setting this option will put user-space page table
          entries in high memory.
  
+ config X86_CHECK_BIOS_CORRUPTION
+         bool "Check for low memory corruption"
+       help
+        Periodically check for memory corruption in low memory, which
+        is suspected to be caused by BIOS.  Even when enabled in the
+        configuration, it is disabled at runtime.  Enable it by
+        setting "memory_corruption_check=1" on the kernel command
+        line.  By default it scans the low 64k of memory every 60
+        seconds; see the memory_corruption_check_size and
+        memory_corruption_check_period parameters in
+        Documentation/kernel-parameters.txt to adjust this.
+        When enabled with the default parameters, this option has
+        almost no overhead, as it reserves a relatively small amount
+        of memory and scans it infrequently.  It both detects corruption
+        and prevents it from affecting the running system.
+        It is, however, intended as a diagnostic tool; if repeatable
+        BIOS-originated corruption always affects the same memory,
+        you can use memmap= to prevent the kernel from using that
+        memory.
+ config X86_BOOTPARAM_MEMORY_CORRUPTION_CHECK
+         bool "Set the default setting of memory_corruption_check"
+       depends on X86_CHECK_BIOS_CORRUPTION
+       default y
+       help
+        Set whether the default state of memory_corruption_check is
+        on or off.
+ config X86_RESERVE_LOW_64K
+         bool "Reserve low 64K of RAM on AMI/Phoenix BIOSen"
+       default y
+       help
+        Reserve the first 64K of physical RAM on BIOSes that are known
+        to potentially corrupt that memory range. A numbers of BIOSes are
+        known to utilize this area during suspend/resume, so it must not
+        be used by the kernel.
+        Set this to N if you are absolutely sure that you trust the BIOS
+        to get all its memory reservations and usages right.
+        If you have doubts about the BIOS (e.g. suspend/resume does not
+        work or there's kernel crashes after certain hardware hotplug
+        events) and it's not AMI or Phoenix, then you might want to enable
+        X86_CHECK_BIOS_CORRUPTION=y to allow the kernel to check typical
+        corruption patterns.
+        Say Y if unsure.
  config MATH_EMULATION
        bool
        prompt "Math emulation" if X86_32
@@@ -1088,7 -1189,38 +1189,38 @@@ config MTR
          You can safely say Y even if your machine doesn't have MTRRs, you'll
          just add about 9 KB to your kernel.
  
-         See <file:Documentation/mtrr.txt> for more information.
+         See <file:Documentation/x86/mtrr.txt> for more information.
+ config MTRR_SANITIZER
+       def_bool y
+       prompt "MTRR cleanup support"
+       depends on MTRR
+       help
+         Convert MTRR layout from continuous to discrete, so X drivers can
+         add writeback entries.
+         Can be disabled with disable_mtrr_cleanup on the kernel command line.
+         The largest mtrr entry size for a continous block can be set with
+         mtrr_chunk_size.
+         If unsure, say Y.
+ config MTRR_SANITIZER_ENABLE_DEFAULT
+       int "MTRR cleanup enable value (0-1)"
+       range 0 1
+       default "0"
+       depends on MTRR_SANITIZER
+       help
+         Enable mtrr cleanup default value
+ config MTRR_SANITIZER_SPARE_REG_NR_DEFAULT
+       int "MTRR cleanup spare reg num (0-7)"
+       range 0 7
+       default "1"
+       depends on MTRR_SANITIZER
+       help
+         mtrr cleanup spare entries default, it can be changed via
+         mtrr_spare_reg_nr=N on the kernel command line.
  
  config X86_PAT
        bool
@@@ -1131,7 -1263,6 +1263,6 @@@ config IRQBALANC
  config SECCOMP
        def_bool y
        prompt "Enable seccomp to safely compute untrusted bytecode"
-       depends on PROC_FS
        help
          This kernel feature is useful for number crunching applications
          that may need to compute untrusted bytecode during their
          the process as file descriptors supporting the read/write
          syscalls, it's possible to isolate those applications in
          their own address space using seccomp. Once seccomp is
-         enabled via /proc/<pid>/seccomp, it cannot be disabled
+         enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
          and the task is only allowed to execute a few safe syscalls
          defined by each seccomp mode.
  
          If unsure, say Y. Only embedded should say N here.
  
 +config CC_STACKPROTECTOR_ALL
 +      bool
 +
  config CC_STACKPROTECTOR
        bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
 -      depends on X86_64 && EXPERIMENTAL && BROKEN
 +      depends on X86_64
 +      select CC_STACKPROTECTOR_ALL
        help
 -         This option turns on the -fstack-protector GCC feature. This
 -        feature puts, at the beginning of critical functions, a canary
 -        value on the stack just before the return address, and validates
 +          This option turns on the -fstack-protector GCC feature. This
 +        feature puts, at the beginning of functions, a canary value on
 +        the stack just before the return address, and validates
          the value just before actually returning.  Stack based buffer
          overflows (that need to overwrite this return address) now also
          overwrite the canary, which gets detected and the attack is then
  
          This feature requires gcc version 4.2 or above, or a distribution
          gcc with the feature backported. Older versions are automatically
 -        detected and for those versions, this configuration option is ignored.
 -
 -config CC_STACKPROTECTOR_ALL
 -      bool "Use stack-protector for all functions"
 -      depends on CC_STACKPROTECTOR
 -      help
 -        Normally, GCC only inserts the canary value protection for
 -        functions that use large-ish on-stack buffers. By enabling
 -        this option, GCC will be asked to do this for ALL functions.
 +        detected and for those versions, this configuration option is
 +        ignored. (and a warning is printed during bootup)
  
  source kernel/Kconfig.hz
  
@@@ -1186,8 -1320,7 +1317,7 @@@ config KEXE
          strongly in flux, so no good recommendation can be made.
  
  config CRASH_DUMP
-       bool "kernel crash dumps (EXPERIMENTAL)"
-       depends on EXPERIMENTAL
+       bool "kernel crash dumps"
        depends on X86_64 || (X86_32 && HIGHMEM)
        help
          Generate crash dump after being started by kexec.
          (CONFIG_RELOCATABLE=y).
          For more details see Documentation/kdump/kdump.txt
  
+ config KEXEC_JUMP
+       bool "kexec jump (EXPERIMENTAL)"
+       depends on EXPERIMENTAL
+       depends on KEXEC && HIBERNATION && X86_32
+       help
+         Jump between original kernel and kexeced kernel and invoke
+         code in physical address mode via KEXEC
  config PHYSICAL_START
        hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
        default "0x1000000" if X86_NUMAQ
@@@ -1286,14 -1427,14 +1424,14 @@@ config PHYSICAL_ALIG
          Don't change this unless you know what you are doing.
  
  config HOTPLUG_CPU
-       bool "Support for suspend on SMP and hot-pluggable CPUs (EXPERIMENTAL)"
-       depends on SMP && HOTPLUG && EXPERIMENTAL && !X86_VOYAGER
+       bool "Support for hot-pluggable CPUs"
+       depends on SMP && HOTPLUG && !X86_VOYAGER
        ---help---
-         Say Y here to experiment with turning CPUs off and on, and to
-         enable suspend on SMP systems. CPUs can be controlled through
-         /sys/devices/system/cpu.
-         Say N if you want to disable CPU hotplug and don't need to
-         suspend.
+         Say Y here to allow turning CPUs off and on. CPUs can be
+         controlled through /sys/devices/system/cpu.
+         ( Note: power management support will enable this option
+           automatically on SMP systems. )
+         Say N if you want to disable CPU hotplug.
  
  config COMPAT_VDSO
        def_bool y
  
          If unsure, say Y.
  
+ config CMDLINE_BOOL
+       bool "Built-in kernel command line"
+       default n
+       help
+         Allow for specifying boot arguments to the kernel at
+         build time.  On some systems (e.g. embedded ones), it is
+         necessary or convenient to provide some or all of the
+         kernel boot arguments with the kernel itself (that is,
+         to not rely on the boot loader to provide them.)
+         To compile command line arguments into the kernel,
+         set this option to 'Y', then fill in the
+         the boot arguments in CONFIG_CMDLINE.
+         Systems with fully functional boot loaders (i.e. non-embedded)
+         should leave this option set to 'N'.
+ config CMDLINE
+       string "Built-in kernel command string"
+       depends on CMDLINE_BOOL
+       default ""
+       help
+         Enter arguments here that should be compiled into the kernel
+         image and used at boot time.  If the boot loader provides a
+         command line at boot time, it is appended to this string to
+         form the full kernel command line, when the system boots.
+         However, you can use the CONFIG_CMDLINE_OVERRIDE option to
+         change this behavior.
+         In most cases, the command line (whether built-in or provided
+         by the boot loader) should specify the device for the root
+         file system.
+ config CMDLINE_OVERRIDE
+       bool "Built-in command line overrides boot loader arguments"
+       default n
+       depends on CMDLINE_BOOL
+       help
+         Set this option to 'Y' to have the kernel ignore the boot loader
+         command line, and use ONLY the built-in command line.
+         This is used to work around broken boot loaders.  This should
+         be set to 'N' under normal conditions.
  endmenu
  
  config ARCH_ENABLE_MEMORY_HOTPLUG
@@@ -1336,7 -1522,7 +1519,7 @@@ config X86_APM_BOO
  
  menuconfig APM
        tristate "APM (Advanced Power Management) BIOS support"
-       depends on X86_32 && PM_SLEEP && !X86_VISWS
+       depends on X86_32 && PM_SLEEP
        ---help---
          APM is a BIOS specification for saving power using several different
          techniques. This is mostly useful for battery powered laptops with
@@@ -1472,8 -1658,7 +1655,7 @@@ endmen
  menu "Bus options (PCI etc.)"
  
  config PCI
-       bool "PCI support" if !X86_VISWS && !X86_VSMP
-       depends on !X86_VOYAGER
+       bool "PCI support"
        default y
        select ARCH_SUPPORTS_MSI if (X86_LOCAL_APIC && X86_IO_APIC)
        help
  
  choice
        prompt "PCI access mode"
-       depends on X86_32 && PCI && !X86_VISWS
+       depends on X86_32 && PCI
        default PCI_GOANY
        ---help---
          On PCI systems, the BIOS can be used to detect the PCI devices and
@@@ -1521,12 -1706,12 +1703,12 @@@ endchoic
  
  config PCI_BIOS
        def_bool y
-       depends on X86_32 && !X86_VISWS && PCI && (PCI_GOBIOS || PCI_GOANY)
+       depends on X86_32 && PCI && (PCI_GOBIOS || PCI_GOANY)
  
  # x86-64 doesn't support PCI BIOS access from long mode so always go direct.
  config PCI_DIRECT
        def_bool y
-       depends on PCI && (X86_64 || (PCI_GODIRECT || PCI_GOANY || PCI_GOOLPC) || X86_VISWS)
+       depends on PCI && (X86_64 || (PCI_GODIRECT || PCI_GOANY || PCI_GOOLPC))
  
  config PCI_MMCONFIG
        def_bool y
@@@ -1574,6 -1759,14 +1756,14 @@@ config DMAR_FLOPPY_W
         workaround will setup a 1:1 mapping for the first
         16M to make floppy (an ISA device) work.
  
+ config INTR_REMAP
+       bool "Support for Interrupt Remapping (EXPERIMENTAL)"
+       depends on X86_64 && X86_IO_APIC && PCI_MSI && ACPI && EXPERIMENTAL
+       help
+        Supports Interrupt remapping for IO-APIC and MSI devices.
+        To use x2apic mode in the CPU's which support x2APIC enhancements or
+        to support platforms with CPU's having > 8 bit APIC ID, say Y.
  source "drivers/pci/pcie/Kconfig"
  
  source "drivers/pci/Kconfig"
@@@ -1586,7 -1779,7 +1776,7 @@@ if X86_3
  
  config ISA
        bool "ISA support"
-       depends on !(X86_VOYAGER || X86_VISWS)
+       depends on !X86_VOYAGER
        help
          Find out whether you have ISA slots on your motherboard.  ISA is the
          name of a bus system, i.e. the way the CPU talks to the other stuff
@@@ -1613,7 -1806,7 +1803,7 @@@ config EIS
  source "drivers/eisa/Kconfig"
  
  config MCA
-       bool "MCA support" if !(X86_VISWS || X86_VOYAGER)
+       bool "MCA support" if !X86_VOYAGER
        default y if X86_VOYAGER
        help
          MicroChannel Architecture is found in some IBM PS/2 machines and
@@@ -1690,7 -1883,7 +1880,7 @@@ config IA32_EMULATIO
  
  config IA32_AOUT
         tristate "IA32 a.out support"
-        depends on IA32_EMULATION && ARCH_SUPPORTS_AOUT
+        depends on IA32_EMULATION
         help
           Support old a.out binaries in the 32bit emulation.
  
@@@ -1704,7 -1897,7 +1894,7 @@@ config COMPAT_FOR_U64_ALIGNMEN
  
  config SYSVIPC_COMPAT
        def_bool y
-       depends on X86_64 && COMPAT && SYSVIPC
+       depends on COMPAT && SYSVIPC
  
  endmenu
  
diff --combined arch/x86/Kconfig.debug
@@@ -5,13 -5,15 +5,15 @@@ config TRACE_IRQFLAGS_SUPPOR
  
  source "lib/Kconfig.debug"
  
- config NONPROMISC_DEVMEM
+ config STRICT_DEVMEM
        bool "Filter access to /dev/mem"
        help
-         If this option is left off, you allow userspace access to all
+         If this option is disabled, you allow userspace (root) access to all
          of memory, including kernel and userspace memory. Accidental
          access to this is obviously disastrous, but specific access can
-         be used by people debugging the kernel.
+         be used by people debugging the kernel. Note that with PAT support
+         enabled, even in this case there are restrictions on /dev/mem
+         use due to the cache aliasing requirements.
  
          If this option is switched on, the /dev/mem file only allows
          userspace access to PCI space and the BIOS code and data regions.
  
          If in doubt, say Y.
  
+ config X86_VERBOSE_BOOTUP
+       bool "Enable verbose x86 bootup info messages"
+       default y
+       help
+         Enables the informational output from the decompression stage
+         (e.g. bzImage) of the boot. If you disable this you will still
+         see errors. Disable this if you want silent bootup.
  config EARLY_PRINTK
        bool "Early printk" if EMBEDDED
        default y
          with klogd/syslogd or the X server. You should normally N here,
          unless you want to debug such a crash.
  
+ config EARLY_PRINTK_DBGP
+       bool "Early printk via EHCI debug port"
+       default n
+       depends on EARLY_PRINTK && PCI
+       help
+         Write kernel log output directly into the EHCI debug port.
+         This is useful for kernel debugging when your machine crashes very
+         early before the console code is initialized. For normal operation
+         it is not recommended because it looks ugly and doesn't cooperate
+         with klogd/syslogd or the X server. You should normally N here,
+         unless you want to debug such a crash. You need usb debug device.
  config DEBUG_STACKOVERFLOW
        bool "Check for stack overflows"
        depends on DEBUG_KERNEL
@@@ -60,7 -83,7 +83,7 @@@ config DEBUG_PAGEALLO
  config DEBUG_PER_CPU_MAPS
        bool "Debug access to per_cpu maps"
        depends on DEBUG_KERNEL
-       depends on X86_64_SMP
+       depends on X86_SMP
        default n
        help
          Say Y to verify that the per_cpu map being accessed has
@@@ -106,7 -129,6 +129,7 @@@ config DIRECT_GBPAGE
  config DEBUG_RODATA_TEST
        bool "Testcase for the DEBUG_RODATA feature"
        depends on DEBUG_RODATA
 +      default y
        help
          This option enables a testcase for the DEBUG_RODATA
          feature as well as for the change_page_attr() infrastructure.
@@@ -130,15 -152,6 +153,6 @@@ config 4KSTACK
          on the VM subsystem for higher order allocations. This option
          will also use IRQ stacks to compensate for the reduced stackspace.
  
- config X86_FIND_SMP_CONFIG
-       def_bool y
-       depends on X86_LOCAL_APIC || X86_VOYAGER
-       depends on X86_32
- config X86_MPPARSE
-       def_bool y
-       depends on (X86_32 && (X86_LOCAL_APIC && !X86_VISWS)) || X86_64
  config DOUBLEFAULT
        default y
        bool "Enable doublefault exception handler" if EMBEDDED
@@@ -173,6 -186,33 +187,33 @@@ config IOMMU_LEA
          Add a simple leak tracer to the IOMMU code. This is useful when you
          are debugging a buggy device driver that leaks IOMMU mappings.
  
+ config MMIOTRACE_HOOKS
+       bool
+ config MMIOTRACE
+       bool "Memory mapped IO tracing"
+       depends on DEBUG_KERNEL && PCI
+       select TRACING
+       select MMIOTRACE_HOOKS
+       help
+         Mmiotrace traces Memory Mapped I/O access and is meant for
+         debugging and reverse engineering. It is called from the ioremap
+         implementation and works via page faults. Tracing is disabled by
+         default and can be enabled at run-time.
+         See Documentation/tracers/mmiotrace.txt.
+         If you are not helping to develop drivers, say N.
+ config MMIOTRACE_TEST
+       tristate "Test module for mmiotrace"
+       depends on MMIOTRACE && m
+       help
+         This is a dumb module for testing mmiotrace. It is very dangerous
+         as it will write garbage to IO memory starting at a given address.
+         However, it should be safe to use on e.g. unused portion of VRAM.
+         Say N, unless you absolutely know what you are doing.
  #
  # IO delay types:
  #
@@@ -262,7 -302,6 +303,6 @@@ config CPA_DEBU
  
  config OPTIMIZE_INLINING
        bool "Allow gcc to uninline functions marked 'inline'"
-       depends on BROKEN
        help
          This option determines if the kernel forces gcc to inline the functions
          developers have marked 'inline'. Doing so takes away freedom from gcc to
          become the default in the future, until then this option is there to
          test gcc for this.
  
+         If unsure, say N.
  endmenu
  
diff --combined arch/x86/Makefile
@@@ -73,7 -73,7 +73,7 @@@ els
  
          stackp := $(CONFIG_SHELL) $(srctree)/scripts/gcc-x86_64-has-stack-protector.sh
          stackp-$(CONFIG_CC_STACKPROTECTOR) := $(shell $(stackp) \
 -                "$(CC)" -fstack-protector )
 +                "$(CC)" "-fstack-protector -DGCC_HAS_SP" )
          stackp-$(CONFIG_CC_STACKPROTECTOR_ALL) += $(shell $(stackp) \
                  "$(CC)" -fstack-protector-all )
  
@@@ -113,38 -113,11 +113,11 @@@ mcore-y  := arch/x86/mach-default
  mflags-$(CONFIG_X86_VOYAGER)  := -Iinclude/asm-x86/mach-voyager
  mcore-$(CONFIG_X86_VOYAGER)   := arch/x86/mach-voyager/
  
- # VISWS subarch support
- mflags-$(CONFIG_X86_VISWS)    := -Iinclude/asm-x86/mach-visws
- mcore-$(CONFIG_X86_VISWS)     := arch/x86/mach-visws/
- # NUMAQ subarch support
- mflags-$(CONFIG_X86_NUMAQ)    := -Iinclude/asm-x86/mach-numaq
- mcore-$(CONFIG_X86_NUMAQ)     := arch/x86/mach-default/
- # BIGSMP subarch support
- mflags-$(CONFIG_X86_BIGSMP)   := -Iinclude/asm-x86/mach-bigsmp
- mcore-$(CONFIG_X86_BIGSMP)    := arch/x86/mach-default/
- #Summit subarch support
- mflags-$(CONFIG_X86_SUMMIT)   := -Iinclude/asm-x86/mach-summit
- mcore-$(CONFIG_X86_SUMMIT)    := arch/x86/mach-default/
  # generic subarchitecture
  mflags-$(CONFIG_X86_GENERICARCH):= -Iinclude/asm-x86/mach-generic
  fcore-$(CONFIG_X86_GENERICARCH)       += arch/x86/mach-generic/
  mcore-$(CONFIG_X86_GENERICARCH)       := arch/x86/mach-default/
  
- # ES7000 subarch support
- mflags-$(CONFIG_X86_ES7000)   := -Iinclude/asm-x86/mach-es7000
- fcore-$(CONFIG_X86_ES7000)    := arch/x86/mach-es7000/
- mcore-$(CONFIG_X86_ES7000)    := arch/x86/mach-default/
- # RDC R-321x subarch support
- mflags-$(CONFIG_X86_RDC321X)  := -Iinclude/asm-x86/mach-rdc321x
- mcore-$(CONFIG_X86_RDC321X)   := arch/x86/mach-default/
- core-$(CONFIG_X86_RDC321X)    += arch/x86/mach-rdc321x/
  # default subarch .h files
  mflags-y += -Iinclude/asm-x86/mach-default
  
@@@ -160,6 -133,7 +133,7 @@@ KBUILD_AFLAGS += $(mflags-y
  
  head-y := arch/x86/kernel/head_$(BITS).o
  head-y += arch/x86/kernel/head$(BITS).o
+ head-y += arch/x86/kernel/head.o
  head-y += arch/x86/kernel/init_task.o
  
  libs-y  += arch/x86/lib/
@@@ -210,12 -184,12 +184,12 @@@ all: bzImag
  
  # KBUILD_IMAGE specify target image being built
                      KBUILD_IMAGE := $(boot)/bzImage
- zImage zlilo zdisk: KBUILD_IMAGE := arch/x86/boot/zImage
+ zImage zlilo zdisk: KBUILD_IMAGE := $(boot)/zImage
  
  zImage bzImage: vmlinux
        $(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE)
        $(Q)mkdir -p $(objtree)/arch/$(UTS_MACHINE)/boot
-       $(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/bzImage
+       $(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/$@
  
  compressed: zImage
  
diff --combined arch/x86/kernel/Makefile
@@@ -2,10 -2,17 +2,17 @@@
  # Makefile for the linux kernel.
  #
  
- extra-y                := head_$(BITS).o head$(BITS).o init_task.o vmlinux.lds
+ extra-y                := head_$(BITS).o head$(BITS).o head.o init_task.o vmlinux.lds
  
  CPPFLAGS_vmlinux.lds += -U$(UTS_MACHINE)
  
+ ifdef CONFIG_FTRACE
+ # Do not profile debug and lowlevel utilities
+ CFLAGS_REMOVE_tsc.o = -pg
+ CFLAGS_REMOVE_rtc.o = -pg
+ CFLAGS_REMOVE_paravirt-spinlocks.o = -pg
+ endif
  #
  # vsyscalls (which work on the user stack) should have
  # no stack-protector checks:
  nostackp := $(call cc-option, -fno-stack-protector)
  CFLAGS_vsyscall_64.o  := $(PROFILING) -g0 $(nostackp)
  CFLAGS_hpet.o         := $(nostackp)
- CFLAGS_tsc_64.o               := $(nostackp)
+ CFLAGS_tsc.o          := $(nostackp)
 +CFLAGS_paravirt.o     := $(nostackp)
  
  obj-y                 := process_$(BITS).o signal_$(BITS).o entry_$(BITS).o
- obj-y                 += traps_$(BITS).o irq_$(BITS).o
+ obj-y                 += traps.o irq_$(BITS).o dumpstack_$(BITS).o
  obj-y                 += time_$(BITS).o ioport.o ldt.o
- obj-y                 += setup_$(BITS).o i8259_$(BITS).o setup.o
+ obj-y                 += setup.o i8259.o irqinit_$(BITS).o setup_percpu.o
+ obj-$(CONFIG_X86_VISWS)       += visws_quirks.o
+ obj-$(CONFIG_X86_32)  += probe_roms_32.o
  obj-$(CONFIG_X86_32)  += sys_i386_32.o i386_ksyms_32.o
  obj-$(CONFIG_X86_64)  += sys_x86_64.o x8664_ksyms_64.o
- obj-$(CONFIG_X86_64)  += syscall_64.o vsyscall_64.o setup64.o
- obj-y                 += bootflag.o e820_$(BITS).o
+ obj-$(CONFIG_X86_64)  += syscall_64.o vsyscall_64.o
+ obj-y                 += bootflag.o e820.o
  obj-y                 += pci-dma.o quirks.o i8237.o topology.o kdebugfs.o
  obj-y                 += alternative.o i8253.o pci-nommu.o
- obj-$(CONFIG_X86_64)  += bugs_64.o
- obj-y                 += tsc_$(BITS).o io_delay.o rtc.o
+ obj-y                 += tsc.o io_delay.o rtc.o
  
  obj-$(CONFIG_X86_TRAMPOLINE)  += trampoline.o
  obj-y                         += process.o
- obj-y                         += i387.o
+ obj-y                         += i387.o xsave.o
  obj-y                         += ptrace.o
  obj-y                         += ds.o
  obj-$(CONFIG_X86_32)          += tls.o
@@@ -44,7 -51,6 +52,6 @@@ obj-$(CONFIG_X86_BIOS_REBOOT) += reboot
  obj-$(CONFIG_MCA)             += mca_32.o
  obj-$(CONFIG_X86_MSR)         += msr.o
  obj-$(CONFIG_X86_CPUID)               += cpuid.o
- obj-$(CONFIG_MICROCODE)               += microcode.o
  obj-$(CONFIG_PCI)             += early-quirks.o
  apm-y                         := apm_32.o
  obj-$(CONFIG_APM)             += apm.o
@@@ -54,18 -60,19 +61,19 @@@ obj-$(CONFIG_X86_32_SMP)   += smpcommon.
  obj-$(CONFIG_X86_64_SMP)      += tsc_sync.o smpcommon.o
  obj-$(CONFIG_X86_TRAMPOLINE)  += trampoline_$(BITS).o
  obj-$(CONFIG_X86_MPPARSE)     += mpparse.o
- obj-$(CONFIG_X86_LOCAL_APIC)  += apic_$(BITS).o nmi_$(BITS).o
+ obj-$(CONFIG_X86_LOCAL_APIC)  += apic_$(BITS).o nmi.o
  obj-$(CONFIG_X86_IO_APIC)     += io_apic_$(BITS).o
  obj-$(CONFIG_X86_REBOOTFIXUPS)        += reboot_fixups_32.o
+ obj-$(CONFIG_DYNAMIC_FTRACE)  += ftrace.o
  obj-$(CONFIG_KEXEC)           += machine_kexec_$(BITS).o
  obj-$(CONFIG_KEXEC)           += relocate_kernel_$(BITS).o crash.o
  obj-$(CONFIG_CRASH_DUMP)      += crash_dump_$(BITS).o
  obj-$(CONFIG_X86_NUMAQ)               += numaq_32.o
+ obj-$(CONFIG_X86_ES7000)      += es7000_32.o
  obj-$(CONFIG_X86_SUMMIT_NUMA) += summit_32.o
  obj-y                         += vsmp_64.o
  obj-$(CONFIG_KPROBES)         += kprobes.o
  obj-$(CONFIG_MODULES)         += module_$(BITS).o
- obj-$(CONFIG_ACPI_SRAT)       += srat_32.o
  obj-$(CONFIG_EFI)             += efi.o efi_$(BITS).o efi_stub_$(BITS).o
  obj-$(CONFIG_DOUBLEFAULT)     += doublefault_32.o
  obj-$(CONFIG_KGDB)            += kgdb.o
@@@ -82,7 -89,7 +90,7 @@@ obj-$(CONFIG_DEBUG_NX_TEST)   += test_nx.
  obj-$(CONFIG_VMI)             += vmi_32.o vmiclock_32.o
  obj-$(CONFIG_KVM_GUEST)               += kvm.o
  obj-$(CONFIG_KVM_CLOCK)               += kvmclock.o
- obj-$(CONFIG_PARAVIRT)                += paravirt.o paravirt_patch_$(BITS).o
+ obj-$(CONFIG_PARAVIRT)                += paravirt.o paravirt_patch_$(BITS).o paravirt-spinlocks.o
  obj-$(CONFIG_PARAVIRT_CLOCK)  += pvclock.o
  
  obj-$(CONFIG_PCSPKR_PLATFORM) += pcspeaker.o
@@@ -92,15 -99,24 +100,24 @@@ scx200-y                  += scx200_32.
  
  obj-$(CONFIG_OLPC)            += olpc.o
  
+ microcode-y                           := microcode_core.o
+ microcode-$(CONFIG_MICROCODE_INTEL)   += microcode_intel.o
+ microcode-$(CONFIG_MICROCODE_AMD)     += microcode_amd.o
+ obj-$(CONFIG_MICROCODE)                       += microcode.o
  ###
  # 64 bit specific files
  ifeq ($(CONFIG_X86_64),y)
-         obj-y                         += genapic_64.o genapic_flat_64.o genx2apic_uv_x.o
+         obj-y                         += genapic_64.o genapic_flat_64.o genx2apic_uv_x.o tlb_uv.o
+       obj-y                           += bios_uv.o
+         obj-y                         += genx2apic_cluster.o
+         obj-y                         += genx2apic_phys.o
          obj-$(CONFIG_X86_PM_TIMER)    += pmtimer_64.o
          obj-$(CONFIG_AUDIT)           += audit_64.o
  
          obj-$(CONFIG_GART_IOMMU)      += pci-gart_64.o aperture_64.o
          obj-$(CONFIG_CALGARY_IOMMU)   += pci-calgary_64.o tce_64.o
+         obj-$(CONFIG_AMD_IOMMU)               += amd_iommu_init.o amd_iommu.o
          obj-$(CONFIG_SWIOTLB)         += pci-swiotlb_64.o
  
          obj-$(CONFIG_PCI_MMCONFIG)    += mmconf-fam10h_64.o
@@@ -16,7 -16,6 +16,7 @@@
  
  #include <stdarg.h>
  
 +#include <linux/stackprotector.h>
  #include <linux/cpu.h>
  #include <linux/errno.h>
  #include <linux/sched.h>
  #include <linux/kdebug.h>
  #include <linux/tick.h>
  #include <linux/prctl.h>
+ #include <linux/uaccess.h>
+ #include <linux/io.h>
  
- #include <asm/uaccess.h>
  #include <asm/pgtable.h>
  #include <asm/system.h>
- #include <asm/io.h>
  #include <asm/processor.h>
  #include <asm/i387.h>
  #include <asm/mmu_context.h>
  #include <asm/proto.h>
  #include <asm/ia32.h>
  #include <asm/idle.h>
+ #include <asm/syscalls.h>
  
  asmlinkage extern void ret_from_fork(void);
  
  unsigned long kernel_thread_flags = CLONE_VM | CLONE_UNTRACED;
  
- unsigned long boot_option_idle_override = 0;
- EXPORT_SYMBOL(boot_option_idle_override);
- /*
-  * Powermanagement idle function, if any..
-  */
- void (*pm_idle)(void);
- EXPORT_SYMBOL(pm_idle);
  static ATOMIC_NOTIFIER_HEAD(idle_notifier);
  
  void idle_notifier_register(struct notifier_block *n)
@@@ -95,48 -86,12 +87,12 @@@ void exit_idle(void
        __exit_idle();
  }
  
- /*
-  * We use this if we don't have any better
-  * idle routine..
-  */
- void default_idle(void)
- {
-       current_thread_info()->status &= ~TS_POLLING;
-       /*
-        * TS_POLLING-cleared state must be visible before we
-        * test NEED_RESCHED:
-        */
-       smp_mb();
-       if (!need_resched())
-               safe_halt();    /* enables interrupts racelessly */
-       else
-               local_irq_enable();
-       current_thread_info()->status |= TS_POLLING;
- }
- #ifdef CONFIG_HOTPLUG_CPU
- DECLARE_PER_CPU(int, cpu_state);
- #include <asm/nmi.h>
- /* We halt the CPU with physical CPU hotplug */
- static inline void play_dead(void)
- {
-       idle_task_exit();
-       wbinvd();
-       mb();
-       /* Ack it */
-       __get_cpu_var(cpu_state) = CPU_DEAD;
-       local_irq_disable();
-       while (1)
-               halt();
- }
- #else
+ #ifndef CONFIG_SMP
  static inline void play_dead(void)
  {
        BUG();
  }
- #endif /* CONFIG_HOTPLUG_CPU */
+ #endif
  
  /*
   * The idle thread. There's no useful work to be
  void cpu_idle(void)
  {
        current_thread_info()->status |= TS_POLLING;
 +
 +      /*
 +       * If we're the non-boot CPU, nothing set the PDA stack
 +       * canary up for us - and if we are the boot CPU we have
 +       * a 0 stack canary. This is a good place for updating
 +       * it, as we wont ever return from this function (so the
 +       * invalid canaries already on the stack wont ever
 +       * trigger):
 +       */
 +      boot_init_stack_canary();
 +
        /* endless idle loop with no priority at all */
        while (1) {
-               tick_nohz_stop_sched_tick();
+               tick_nohz_stop_sched_tick(1);
                while (!need_resched()) {
-                       void (*idle)(void);
  
                        rmb();
-                       idle = pm_idle;
-                       if (!idle)
-                               idle = default_idle;
                        if (cpu_is_offline(smp_processor_id()))
                                play_dead();
                        /*
                         */
                        local_irq_disable();
                        enter_idle();
-                       idle();
+                       /* Don't trace irqs off for idle */
+                       stop_critical_timings();
+                       pm_idle();
+                       start_critical_timings();
                        /* In many cases the interrupt that ended idle
                           has already called exit_idle. But some idle
                           loops can be woken up without interrupt. */
  }
  
  /* Prints also some state that isn't saved in the pt_regs */
- void __show_regs(struct pt_regs * regs)
+ void __show_regs(struct pt_regs *regs, int all)
  {
        unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
        unsigned long d0, d1, d2, d3, d6, d7;
  
        printk("\n");
        print_modules();
-       printk("Pid: %d, comm: %.20s %s %s %.*s\n",
+       printk(KERN_INFO "Pid: %d, comm: %.20s %s %s %.*s\n",
                current->pid, current->comm, print_tainted(),
                init_utsname()->release,
                (int)strcspn(init_utsname()->version, " "),
                init_utsname()->version);
-       printk("RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip);
+       printk(KERN_INFO "RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->ip);
        printk_address(regs->ip, 1);
-       printk("RSP: %04lx:%016lx  EFLAGS: %08lx\n", regs->ss, regs->sp,
-               regs->flags);
-       printk("RAX: %016lx RBX: %016lx RCX: %016lx\n",
+       printk(KERN_INFO "RSP: %04lx:%016lx  EFLAGS: %08lx\n", regs->ss,
+                       regs->sp, regs->flags);
+       printk(KERN_INFO "RAX: %016lx RBX: %016lx RCX: %016lx\n",
               regs->ax, regs->bx, regs->cx);
-       printk("RDX: %016lx RSI: %016lx RDI: %016lx\n",
+       printk(KERN_INFO "RDX: %016lx RSI: %016lx RDI: %016lx\n",
               regs->dx, regs->si, regs->di);
-       printk("RBP: %016lx R08: %016lx R09: %016lx\n",
+       printk(KERN_INFO "RBP: %016lx R08: %016lx R09: %016lx\n",
               regs->bp, regs->r8, regs->r9);
-       printk("R10: %016lx R11: %016lx R12: %016lx\n",
-              regs->r10, regs->r11, regs->r12); 
-       printk("R13: %016lx R14: %016lx R15: %016lx\n",
-              regs->r13, regs->r14, regs->r15); 
-       asm("movl %%ds,%0" : "=r" (ds)); 
-       asm("movl %%cs,%0" : "=r" (cs)); 
-       asm("movl %%es,%0" : "=r" (es)); 
+       printk(KERN_INFO "R10: %016lx R11: %016lx R12: %016lx\n",
+              regs->r10, regs->r11, regs->r12);
+       printk(KERN_INFO "R13: %016lx R14: %016lx R15: %016lx\n",
+              regs->r13, regs->r14, regs->r15);
+       asm("movl %%ds,%0" : "=r" (ds));
+       asm("movl %%cs,%0" : "=r" (cs));
+       asm("movl %%es,%0" : "=r" (es));
        asm("movl %%fs,%0" : "=r" (fsindex));
        asm("movl %%gs,%0" : "=r" (gsindex));
  
        rdmsrl(MSR_FS_BASE, fs);
-       rdmsrl(MSR_GS_BASE, gs); 
-       rdmsrl(MSR_KERNEL_GS_BASE, shadowgs); 
+       rdmsrl(MSR_GS_BASE, gs);
+       rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
+       if (!all)
+               return;
  
        cr0 = read_cr0();
        cr2 = read_cr2();
        cr3 = read_cr3();
        cr4 = read_cr4();
  
-       printk("FS:  %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n", 
-              fs,fsindex,gs,gsindex,shadowgs); 
-       printk("CS:  %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds, es, cr0); 
-       printk("CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3, cr4);
+       printk(KERN_INFO "FS:  %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
+              fs, fsindex, gs, gsindex, shadowgs);
+       printk(KERN_INFO "CS:  %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds,
+                       es, cr0);
+       printk(KERN_INFO "CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3,
+                       cr4);
  
        get_debugreg(d0, 0);
        get_debugreg(d1, 1);
        get_debugreg(d2, 2);
-       printk("DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2);
+       printk(KERN_INFO "DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2);
        get_debugreg(d3, 3);
        get_debugreg(d6, 6);
        get_debugreg(d7, 7);
-       printk("DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
+       printk(KERN_INFO "DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
  }
  
  void show_regs(struct pt_regs *regs)
  {
-       printk("CPU %d:", smp_processor_id());
-       __show_regs(regs);
+       printk(KERN_INFO "CPU %d:", smp_processor_id());
+       __show_regs(regs, 1);
        show_trace(NULL, regs, (void *)(regs + 1), regs->bp);
  }
  
@@@ -279,6 -228,14 +240,14 @@@ void exit_thread(void
                t->io_bitmap_max = 0;
                put_cpu();
        }
+ #ifdef CONFIG_X86_DS
+       /* Free any DS contexts that have not been properly released. */
+       if (unlikely(t->ds_ctx)) {
+               /* we clear debugctl to make sure DS is not used. */
+               update_debugctlmsr(0);
+               ds_free(t->ds_ctx);
+       }
+ #endif /* CONFIG_X86_DS */
  }
  
  void flush_thread(void)
@@@ -354,10 -311,10 +323,10 @@@ void prepare_to_copy(struct task_struc
  
  int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
                unsigned long unused,
-       struct task_struct * p, struct pt_regs * regs)
+       struct task_struct *p, struct pt_regs *regs)
  {
        int err;
-       struct pt_regs * childregs;
+       struct pt_regs *childregs;
        struct task_struct *me = current;
  
        childregs = ((struct pt_regs *)
        p->thread.fs = me->thread.fs;
        p->thread.gs = me->thread.gs;
  
-       asm("mov %%gs,%0" : "=m" (p->thread.gsindex));
-       asm("mov %%fs,%0" : "=m" (p->thread.fsindex));
-       asm("mov %%es,%0" : "=m" (p->thread.es));
-       asm("mov %%ds,%0" : "=m" (p->thread.ds));
+       savesegment(gs, p->thread.gsindex);
+       savesegment(fs, p->thread.fsindex);
+       savesegment(es, p->thread.es);
+       savesegment(ds, p->thread.ds);
  
        if (unlikely(test_tsk_thread_flag(me, TIF_IO_BITMAP))) {
                p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
                if (test_thread_flag(TIF_IA32))
                        err = do_set_thread_area(p, -1,
                                (struct user_desc __user *)childregs->si, 0);
-               else                    
- #endif         
-                       err = do_arch_prctl(p, ARCH_SET_FS, childregs->r8); 
-               if (err) 
+               else
+ #endif
+                       err = do_arch_prctl(p, ARCH_SET_FS, childregs->r8);
+               if (err)
                        goto out;
        }
        err = 0;
@@@ -420,7 -377,9 +389,9 @@@ out
  void
  start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
  {
-       asm volatile("movl %0, %%fs; movl %0, %%es; movl %0, %%ds" :: "r"(0));
+       loadsegment(fs, 0);
+       loadsegment(es, 0);
+       loadsegment(ds, 0);
        load_gs_index(0);
        regs->ip                = new_ip;
        regs->sp                = new_sp;
@@@ -510,13 -469,27 +481,27 @@@ static inline void __switch_to_xtra(str
        next = &next_p->thread;
  
        debugctl = prev->debugctlmsr;
-       if (next->ds_area_msr != prev->ds_area_msr) {
-               /* we clear debugctl to make sure DS
-                * is not in use when we change it */
-               debugctl = 0;
-               update_debugctlmsr(0);
-               wrmsrl(MSR_IA32_DS_AREA, next->ds_area_msr);
+ #ifdef CONFIG_X86_DS
+       {
+               unsigned long ds_prev = 0, ds_next = 0;
+               if (prev->ds_ctx)
+                       ds_prev = (unsigned long)prev->ds_ctx->ds;
+               if (next->ds_ctx)
+                       ds_next = (unsigned long)next->ds_ctx->ds;
+               if (ds_next != ds_prev) {
+                       /*
+                        * We clear debugctl to make sure DS
+                        * is not in use when we change it:
+                        */
+                       debugctl = 0;
+                       update_debugctlmsr(0);
+                       wrmsrl(MSR_IA32_DS_AREA, ds_next);
+               }
        }
+ #endif /* CONFIG_X86_DS */
  
        if (next->debugctlmsr != debugctl)
                update_debugctlmsr(next->debugctlmsr);
                memset(tss->io_bitmap, 0xff, prev->io_bitmap_max);
        }
  
- #ifdef X86_BTS
+ #ifdef CONFIG_X86_PTRACE_BTS
        if (test_tsk_thread_flag(prev_p, TIF_BTS_TRACE_TS))
                ptrace_bts_take_timestamp(prev_p, BTS_TASK_DEPARTS);
  
        if (test_tsk_thread_flag(next_p, TIF_BTS_TRACE_TS))
                ptrace_bts_take_timestamp(next_p, BTS_TASK_ARRIVES);
- #endif
+ #endif /* CONFIG_X86_PTRACE_BTS */
  }
  
  /*
  struct task_struct *
  __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
  {
-       struct thread_struct *prev = &prev_p->thread,
-                                *next = &next_p->thread;
+       struct thread_struct *prev = &prev_p->thread;
+       struct thread_struct *next = &next_p->thread;
        int cpu = smp_processor_id();
        struct tss_struct *tss = &per_cpu(init_tss, cpu);
+       unsigned fsindex, gsindex;
  
        /* we're going to use this soon, after a few expensive things */
-       if (next_p->fpu_counter>5)
+       if (next_p->fpu_counter > 5)
                prefetch(next->xstate);
  
        /*
         */
        load_sp0(tss, next);
  
-       /* 
+       /*
         * Switch DS and ES.
         * This won't pick up thread selector changes, but I guess that is ok.
         */
-       asm volatile("mov %%es,%0" : "=m" (prev->es));
+       savesegment(es, prev->es);
        if (unlikely(next->es | prev->es))
-               loadsegment(es, next->es); 
-       
-       asm volatile ("mov %%ds,%0" : "=m" (prev->ds));
+               loadsegment(es, next->es);
+       savesegment(ds, prev->ds);
        if (unlikely(next->ds | prev->ds))
                loadsegment(ds, next->ds);
  
+       /* We must save %fs and %gs before load_TLS() because
+        * %fs and %gs may be cleared by load_TLS().
+        *
+        * (e.g. xen_load_tls())
+        */
+       savesegment(fs, fsindex);
+       savesegment(gs, gsindex);
        load_TLS(next, cpu);
  
-       /* 
+       /*
+        * Leave lazy mode, flushing any hypercalls made here.
+        * This must be done before restoring TLS segments so
+        * the GDT and LDT are properly updated, and must be
+        * done before math_state_restore, so the TS bit is up
+        * to date.
+        */
+       arch_leave_lazy_cpu_mode();
+       /*
         * Switch FS and GS.
+        *
+        * Segment register != 0 always requires a reload.  Also
+        * reload when it has changed.  When prev process used 64bit
+        * base always reload to avoid an information leak.
         */
-       { 
-               unsigned fsindex;
-               asm volatile("movl %%fs,%0" : "=r" (fsindex)); 
-               /* segment register != 0 always requires a reload. 
-                  also reload when it has changed. 
-                  when prev process used 64bit base always reload
-                  to avoid an information leak. */
-               if (unlikely(fsindex | next->fsindex | prev->fs)) {
-                       loadsegment(fs, next->fsindex);
-                       /* check if the user used a selector != 0
-                        * if yes clear 64bit base, since overloaded base
-                          * is always mapped to the Null selector
-                          */
-                       if (fsindex)
-                       prev->fs = 0;                           
-               }
-               /* when next process has a 64bit base use it */
-               if (next->fs) 
-                       wrmsrl(MSR_FS_BASE, next->fs); 
-               prev->fsindex = fsindex;
+       if (unlikely(fsindex | next->fsindex | prev->fs)) {
+               loadsegment(fs, next->fsindex);
+               /*
+                * Check if the user used a selector != 0; if yes
+                *  clear 64bit base, since overloaded base is always
+                *  mapped to the Null selector
+                */
+               if (fsindex)
+                       prev->fs = 0;
        }
-       { 
-               unsigned gsindex;
-               asm volatile("movl %%gs,%0" : "=r" (gsindex)); 
-               if (unlikely(gsindex | next->gsindex | prev->gs)) {
-                       load_gs_index(next->gsindex);
-                       if (gsindex)
-                       prev->gs = 0;                           
-               }
-               if (next->gs)
-                       wrmsrl(MSR_KERNEL_GS_BASE, next->gs); 
-               prev->gsindex = gsindex;
+       /* when next process has a 64bit base use it */
+       if (next->fs)
+               wrmsrl(MSR_FS_BASE, next->fs);
+       prev->fsindex = fsindex;
+       if (unlikely(gsindex | next->gsindex | prev->gs)) {
+               load_gs_index(next->gsindex);
+               if (gsindex)
+                       prev->gs = 0;
        }
+       if (next->gs)
+               wrmsrl(MSR_KERNEL_GS_BASE, next->gs);
+       prev->gsindex = gsindex;
  
        /* Must be after DS reload */
        unlazy_fpu(prev_p);
  
-       /* 
+       /*
         * Switch the PDA and FPU contexts.
         */
        prev->usersp = read_pda(oldrsp);
        write_pda(oldrsp, next->usersp);
-       write_pda(pcurrent, next_p); 
+       write_pda(pcurrent, next_p);
  
        write_pda(kernelstack,
-       (unsigned long)task_stack_page(next_p) + THREAD_SIZE - PDA_STACKOFFSET);
+                 (unsigned long)task_stack_page(next_p) +
+                 THREAD_SIZE - PDA_STACKOFFSET);
  #ifdef CONFIG_CC_STACKPROTECTOR
 -      write_pda(stack_canary, next_p->stack_canary);
        /*
         * Build time only check to make sure the stack_canary is at
         * offset 40 in the pda; this is a gcc ABI requirement
@@@ -687,7 -675,7 +686,7 @@@ long sys_execve(char __user *name, cha
                char __user * __user *envp, struct pt_regs *regs)
  {
        long error;
-       char * filename;
+       char *filename;
  
        filename = getname(name);
        error = PTR_ERR(filename);
@@@ -745,55 -733,55 +744,55 @@@ asmlinkage long sys_vfork(struct pt_reg
  unsigned long get_wchan(struct task_struct *p)
  {
        unsigned long stack;
-       u64 fp,ip;
+       u64 fp, ip;
        int count = 0;
  
-       if (!p || p == current || p->state==TASK_RUNNING)
-               return 0; 
+       if (!p || p == current || p->state == TASK_RUNNING)
+               return 0;
        stack = (unsigned long)task_stack_page(p);
-       if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE)
+       if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
                return 0;
        fp = *(u64 *)(p->thread.sp);
-       do { 
+       do {
                if (fp < (unsigned long)stack ||
-                   fp > (unsigned long)stack+THREAD_SIZE)
-                       return 0; 
+                   fp >= (unsigned long)stack+THREAD_SIZE)
+                       return 0;
                ip = *(u64 *)(fp+8);
                if (!in_sched_functions(ip))
                        return ip;
-               fp = *(u64 *)fp; 
-       } while (count++ < 16); 
+               fp = *(u64 *)fp;
+       } while (count++ < 16);
        return 0;
  }
  
  long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
- { 
-       int ret = 0; 
+ {
+       int ret = 0;
        int doit = task == current;
        int cpu;
  
-       switch (code) { 
+       switch (code) {
        case ARCH_SET_GS:
                if (addr >= TASK_SIZE_OF(task))
-                       return -EPERM; 
+                       return -EPERM;
                cpu = get_cpu();
-               /* handle small bases via the GDT because that's faster to 
+               /* handle small bases via the GDT because that's faster to
                   switch. */
-               if (addr <= 0xffffffff) {  
-                       set_32bit_tls(task, GS_TLS, addr); 
-                       if (doit) { 
+               if (addr <= 0xffffffff) {
+                       set_32bit_tls(task, GS_TLS, addr);
+                       if (doit) {
                                load_TLS(&task->thread, cpu);
-                               load_gs_index(GS_TLS_SEL); 
+                               load_gs_index(GS_TLS_SEL);
                        }
-                       task->thread.gsindex = GS_TLS_SEL; 
+                       task->thread.gsindex = GS_TLS_SEL;
                        task->thread.gs = 0;
-               } else { 
+               } else {
                        task->thread.gsindex = 0;
                        task->thread.gs = addr;
                        if (doit) {
                                load_gs_index(0);
                                ret = checking_wrmsrl(MSR_KERNEL_GS_BASE, addr);
-                       } 
+                       }
                }
                put_cpu();
                break;
                        set_32bit_tls(task, FS_TLS, addr);
                        if (doit) {
                                load_TLS(&task->thread, cpu);
-                               asm volatile("movl %0,%%fs" :: "r"(FS_TLS_SEL));
+                               loadsegment(fs, FS_TLS_SEL);
                        }
                        task->thread.fsindex = FS_TLS_SEL;
                        task->thread.fs = 0;
                        if (doit) {
                                /* set the selector to 0 to not confuse
                                   __switch_to */
-                               asm volatile("movl %0,%%fs" :: "r" (0));
+                               loadsegment(fs, 0);
                                ret = checking_wrmsrl(MSR_FS_BASE, addr);
                        }
                }
                if (task->thread.gsindex == GS_TLS_SEL)
                        base = read_32bit_tls(task, GS_TLS);
                else if (doit) {
-                       asm("movl %%gs,%0" : "=r" (gsindex));
+                       savesegment(gs, gsindex);
                        if (gsindex)
                                rdmsrl(MSR_KERNEL_GS_BASE, base);
                        else
                                base = task->thread.gs;
-               }
-               else
+               } else
                        base = task->thread.gs;
                ret = put_user(base, (unsigned long __user *)addr);
                break;
diff --combined arch/x86/mm/fault.c
@@@ -10,6 -10,7 +10,7 @@@
  #include <linux/string.h>
  #include <linux/types.h>
  #include <linux/ptrace.h>
+ #include <linux/mmiotrace.h>
  #include <linux/mman.h>
  #include <linux/mm.h>
  #include <linux/smp.h>
@@@ -25,7 -26,6 +26,7 @@@
  #include <linux/kprobes.h>
  #include <linux/uaccess.h>
  #include <linux/kdebug.h>
 +#include <linux/magic.h>
  
  #include <asm/system.h>
  #include <asm/desc.h>
@@@ -35,6 -35,7 +36,7 @@@
  #include <asm/tlbflush.h>
  #include <asm/proto.h>
  #include <asm-generic/sections.h>
+ #include <asm/traps.h>
  
  /*
   * Page fault error code bits
  #define PF_RSVD               (1<<3)
  #define PF_INSTR      (1<<4)
  
+ static inline int kmmio_fault(struct pt_regs *regs, unsigned long addr)
+ {
+ #ifdef CONFIG_MMIOTRACE_HOOKS
+       if (unlikely(is_kmmio_active()))
+               if (kmmio_handler(regs, addr) == 1)
+                       return -1;
+ #endif
+       return 0;
+ }
  static inline int notify_page_fault(struct pt_regs *regs)
  {
  #ifdef CONFIG_KPROBES
        int ret = 0;
  
        /* kprobe_running() needs smp_processor_id() */
- #ifdef CONFIG_X86_32
        if (!user_mode_vm(regs)) {
- #else
-       if (!user_mode(regs)) {
- #endif
                preempt_disable();
                if (kprobe_running() && kprobe_fault_handler(regs, 14))
                        ret = 1;
@@@ -351,8 -358,6 +359,6 @@@ static int is_errata100(struct pt_regs 
        return 0;
  }
  
- void do_invalid_op(struct pt_regs *, unsigned long);
  static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
  {
  #ifdef CONFIG_X86_F00F_BUG
@@@ -397,11 -402,7 +403,7 @@@ static void show_fault_oops(struct pt_r
                printk(KERN_CONT "NULL pointer dereference");
        else
                printk(KERN_CONT "paging request");
- #ifdef CONFIG_X86_32
-       printk(KERN_CONT " at %08lx\n", address);
- #else
-       printk(KERN_CONT " at %016lx\n", address);
- #endif
+       printk(KERN_CONT " at %p\n", (void *) address);
        printk(KERN_ALERT "IP:");
        printk_address(regs->ip, 1);
        dump_pagetable(address);
@@@ -587,17 -588,10 +589,12 @@@ void __kprobes do_page_fault(struct pt_
        unsigned long address;
        int write, si_code;
        int fault;
 +      unsigned long *stackend;
 +
  #ifdef CONFIG_X86_64
        unsigned long flags;
  #endif
  
-       /*
-        * We can fault from pretty much anywhere, with unknown IRQ state.
-        */
-       trace_hardirqs_fixup();
        tsk = current;
        mm = tsk->mm;
        prefetchw(&mm->mmap_sem);
  
        if (notify_page_fault(regs))
                return;
+       if (unlikely(kmmio_fault(regs, address)))
+               return;
  
        /*
         * We fault-in kernel-space virtual memory on-demand. The
@@@ -803,14 -799,10 +802,10 @@@ bad_area_nosemaphore
                if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) &&
                    printk_ratelimit()) {
                        printk(
- #ifdef CONFIG_X86_32
-                       "%s%s[%d]: segfault at %lx ip %08lx sp %08lx error %lx",
- #else
-                       "%s%s[%d]: segfault at %lx ip %lx sp %lx error %lx",
- #endif
+                       "%s%s[%d]: segfault at %lx ip %p sp %p error %lx",
                        task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
-                       tsk->comm, task_pid_nr(tsk), address, regs->ip,
-                       regs->sp, error_code);
+                       tsk->comm, task_pid_nr(tsk), address,
+                       (void *) regs->ip, (void *) regs->sp, error_code);
                        print_vma_addr(" in ", regs->ip);
                        printk("\n");
                }
@@@ -858,10 -850,6 +853,10 @@@ no_context
  
        show_fault_oops(regs, error_code, address);
  
 +      stackend = end_of_stack(tsk);
 +      if (*stackend != STACK_END_MAGIC)
 +              printk(KERN_ALERT "Thread overran stack, or stack corrupted\n");
 +
        tsk->thread.cr2 = address;
        tsk->thread.trap_no = 14;
        tsk->thread.error_code = error_code;
@@@ -921,72 -909,45 +916,45 @@@ LIST_HEAD(pgd_list)
  
  void vmalloc_sync_all(void)
  {
- #ifdef CONFIG_X86_32
-       /*
-        * Note that races in the updates of insync and start aren't
-        * problematic: insync can only get set bits added, and updates to
-        * start are only improving performance (without affecting correctness
-        * if undone).
-        */
-       static DECLARE_BITMAP(insync, PTRS_PER_PGD);
-       static unsigned long start = TASK_SIZE;
        unsigned long address;
  
+ #ifdef CONFIG_X86_32
        if (SHARED_KERNEL_PMD)
                return;
  
-       BUILD_BUG_ON(TASK_SIZE & ~PGDIR_MASK);
-       for (address = start; address >= TASK_SIZE; address += PGDIR_SIZE) {
-               if (!test_bit(pgd_index(address), insync)) {
-                       unsigned long flags;
-                       struct page *page;
-                       spin_lock_irqsave(&pgd_lock, flags);
-                       list_for_each_entry(page, &pgd_list, lru) {
-                               if (!vmalloc_sync_one(page_address(page),
-                                                     address))
-                                       break;
-                       }
-                       spin_unlock_irqrestore(&pgd_lock, flags);
-                       if (!page)
-                               set_bit(pgd_index(address), insync);
+       for (address = VMALLOC_START & PMD_MASK;
+            address >= TASK_SIZE && address < FIXADDR_TOP;
+            address += PMD_SIZE) {
+               unsigned long flags;
+               struct page *page;
+               spin_lock_irqsave(&pgd_lock, flags);
+               list_for_each_entry(page, &pgd_list, lru) {
+                       if (!vmalloc_sync_one(page_address(page),
+                                             address))
+                               break;
                }
-               if (address == start && test_bit(pgd_index(address), insync))
-                       start = address + PGDIR_SIZE;
+               spin_unlock_irqrestore(&pgd_lock, flags);
        }
  #else /* CONFIG_X86_64 */
-       /*
-        * Note that races in the updates of insync and start aren't
-        * problematic: insync can only get set bits added, and updates to
-        * start are only improving performance (without affecting correctness
-        * if undone).
-        */
-       static DECLARE_BITMAP(insync, PTRS_PER_PGD);
-       static unsigned long start = VMALLOC_START & PGDIR_MASK;
-       unsigned long address;
-       for (address = start; address <= VMALLOC_END; address += PGDIR_SIZE) {
-               if (!test_bit(pgd_index(address), insync)) {
-                       const pgd_t *pgd_ref = pgd_offset_k(address);
-                       unsigned long flags;
-                       struct page *page;
-                       if (pgd_none(*pgd_ref))
-                               continue;
-                       spin_lock_irqsave(&pgd_lock, flags);
-                       list_for_each_entry(page, &pgd_list, lru) {
-                               pgd_t *pgd;
-                               pgd = (pgd_t *)page_address(page) + pgd_index(address);
-                               if (pgd_none(*pgd))
-                                       set_pgd(pgd, *pgd_ref);
-                               else
-                                       BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
-                       }
-                       spin_unlock_irqrestore(&pgd_lock, flags);
-                       set_bit(pgd_index(address), insync);
+       for (address = VMALLOC_START & PGDIR_MASK; address <= VMALLOC_END;
+            address += PGDIR_SIZE) {
+               const pgd_t *pgd_ref = pgd_offset_k(address);
+               unsigned long flags;
+               struct page *page;
+               if (pgd_none(*pgd_ref))
+                       continue;
+               spin_lock_irqsave(&pgd_lock, flags);
+               list_for_each_entry(page, &pgd_list, lru) {
+                       pgd_t *pgd;
+                       pgd = (pgd_t *)page_address(page) + pgd_index(address);
+                       if (pgd_none(*pgd))
+                               set_pgd(pgd, *pgd_ref);
+                       else
+                               BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
                }
-               if (address == start)
-                       start = address + PGDIR_SIZE;
+               spin_unlock_irqrestore(&pgd_lock, flags);
        }
  #endif
  }
diff --combined include/asm-x86/pda.h
@@@ -1,5 -1,5 +1,5 @@@
- #ifndef X86_64_PDA_H
- #define X86_64_PDA_H
+ #ifndef ASM_X86__PDA_H
+ #define ASM_X86__PDA_H
  
  #ifndef __ASSEMBLY__
  #include <linux/stddef.h>
@@@ -16,10 -16,14 +16,12 @@@ struct x8664_pda 
        unsigned long oldrsp;           /* 24 user rsp for system call */
        int irqcount;                   /* 32 Irq nesting counter. Starts -1 */
        unsigned int cpunumber;         /* 36 Logical CPU number */
 -#ifdef CONFIG_CC_STACKPROTECTOR
        unsigned long stack_canary;     /* 40 stack canary value */
                                        /* gcc-ABI: this canary MUST be at
                                           offset 40!!! */
 -#endif
        char *irqstackptr;
+       short nodenumber;               /* number of current node (32k max) */
+       short in_bootmem;               /* pda lives in bootmem */
        unsigned int __softirq_pending;
        unsigned int __nmi_count;       /* number of NMI on this CPUs */
        short mmu_state;
@@@ -35,8 -39,7 +37,7 @@@
        unsigned irq_spurious_count;
  } ____cacheline_aligned_in_smp;
  
- extern struct x8664_pda *_cpu_pda[];
- extern struct x8664_pda boot_cpu_pda[];
+ extern struct x8664_pda **_cpu_pda;
  extern void pda_init(int);
  
  #define cpu_pda(i) (_cpu_pda[i])
@@@ -131,5 -134,4 +132,6 @@@ do {                                                                       
  
  #define PDA_STACKOFFSET (5*8)
  
- #endif
 +#define refresh_stack_canary() write_pda(stack_canary, current->stack_canary)
++
+ #endif /* ASM_X86__PDA_H */
diff --combined include/asm-x86/system.h
@@@ -1,5 -1,5 +1,5 @@@
- #ifndef _ASM_X86_SYSTEM_H_
- #define _ASM_X86_SYSTEM_H_
+ #ifndef ASM_X86__SYSTEM_H
+ #define ASM_X86__SYSTEM_H
  
  #include <asm/asm.h>
  #include <asm/segment.h>
@@@ -64,7 -64,10 +64,10 @@@ do {                                                                        
                                                                        \
                       /* regparm parameters for __switch_to(): */      \
                       [prev]     "a" (prev),                           \
-                      [next]     "d" (next));                          \
+                      [next]     "d" (next)                            \
+                                                                       \
+                    : /* reloaded segment registers */                 \
+                       "memory");                                      \
  } while (0)
  
  /*
@@@ -92,8 -95,6 +95,8 @@@
             ".globl thread_return\n"                                     \
             "thread_return:\n\t"                                         \
             "movq %%gs:%P[pda_pcurrent],%%rsi\n\t"                       \
 +           "movq %P[task_canary](%%rsi),%%r8\n\t"                       \
 +           "movq %%r8,%%gs:%P[pda_canary]\n\t"                          \
             "movq %P[thread_info](%%rsi),%%r8\n\t"                       \
             LOCK_PREFIX "btr  %[tif_fork],%P[ti_flags](%%r8)\n\t"        \
             "movq %%rax,%%rdi\n\t"                                       \
               [ti_flags] "i" (offsetof(struct thread_info, flags)),      \
               [tif_fork] "i" (TIF_FORK),                                 \
               [thread_info] "i" (offsetof(struct task_struct, stack)),   \
 -             [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent))  \
 +             [task_canary] "i" (offsetof(struct task_struct, stack_canary)),\
 +             [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)), \
 +             [pda_canary] "i" (offsetof(struct x8664_pda, stack_canary))\
             : "memory", "cc" __EXTRA_CLOBBER)
  #endif
  
@@@ -140,7 -139,7 +143,7 @@@ __asm__ __volatile__ ("movw %%dx,%1\n\t
  #define set_base(ldt, base) _set_base(((char *)&(ldt)) , (base))
  #define set_limit(ldt, limit) _set_limit(((char *)&(ldt)) , ((limit)-1))
  
- extern void load_gs_index(unsigned);
+ extern void native_load_gs_index(unsigned);
  
  /*
   * Load a segment. Fall back on loading the zero
                     "jmp 2b\n"                 \
                     ".previous\n"              \
                     _ASM_EXTABLE(1b,3b)        \
-                    : :"r" (value), "r" (0))
+                    : :"r" (value), "r" (0) : "memory")
  
  
  /*
   * Save a segment register away
   */
  #define savesegment(seg, value)                               \
-       asm volatile("mov %%" #seg ",%0":"=rm" (value))
+       asm("mov %%" #seg ",%0":"=r" (value) : : "memory")
  
  static inline unsigned long get_limit(unsigned long segment)
  {
@@@ -286,6 -285,7 +289,7 @@@ static inline void native_wbinvd(void
  #ifdef CONFIG_X86_64
  #define read_cr8()    (native_read_cr8())
  #define write_cr8(x)  (native_write_cr8(x))
+ #define load_gs_index   native_load_gs_index
  #endif
  
  /* Clear the 'TS' bit */
  
  #endif/* CONFIG_PARAVIRT */
  
- #define stts() write_cr0(8 | read_cr0())
+ #define stts() write_cr0(read_cr0() | X86_CR0_TS)
  
  #endif /* __KERNEL__ */
  
@@@ -307,7 -307,6 +311,6 @@@ static inline void clflush(volatile voi
  void disable_hlt(void);
  void enable_hlt(void);
  
- extern int es7000_plat;
  void cpu_idle_wait(void);
  
  extern unsigned long arch_align_stack(unsigned long sp);
@@@ -423,4 -422,4 +426,4 @@@ static inline void rdtsc_barrier(void
        alternative(ASM_NOP3, "lfence", X86_FEATURE_LFENCE_RDTSC);
  }
  
- #endif
+ #endif /* ASM_X86__SYSTEM_H */
diff --combined include/linux/magic.h
@@@ -6,6 -6,10 +6,10 @@@
  #define AFS_SUPER_MAGIC                0x5346414F
  #define AUTOFS_SUPER_MAGIC    0x0187
  #define CODA_SUPER_MAGIC      0x73757245
+ #define DEBUGFS_MAGIC          0x64626720
+ #define SYSFS_MAGIC           0x62656572
+ #define SECURITYFS_MAGIC      0x73636673
+ #define TMPFS_MAGIC           0x01021994
  #define EFS_SUPER_MAGIC               0x414A53
  #define EXT2_SUPER_MAGIC      0xEF53
  #define EXT3_SUPER_MAGIC      0xEF53
@@@ -42,5 -46,4 +46,5 @@@
  #define FUTEXFS_SUPER_MAGIC   0xBAD1DEA
  #define INOTIFYFS_SUPER_MAGIC 0x2BAD1DEA
  
 +#define STACK_END_MAGIC               0x57AC6E9D
  #endif /* __LINUX_MAGIC_H__ */
diff --combined include/linux/sched.h
@@@ -87,6 -87,7 +87,7 @@@ struct sched_param 
  #include <linux/task_io_accounting.h>
  #include <linux/kobject.h>
  #include <linux/latencytop.h>
+ #include <linux/cred.h>
  
  #include <asm/processor.h>
  
@@@ -134,7 -135,6 +135,6 @@@ extern unsigned long nr_running(void)
  extern unsigned long nr_uninterruptible(void);
  extern unsigned long nr_active(void);
  extern unsigned long nr_iowait(void);
- extern unsigned long weighted_cpuload(const int cpu);
  
  struct seq_file;
  struct cfs_rq;
@@@ -246,6 -246,8 +246,8 @@@ extern asmlinkage void schedule_tail(st
  extern void init_idle(struct task_struct *idle, int cpu);
  extern void init_idle_bootup_task(struct task_struct *idle);
  
+ extern int runqueue_is_locked(void);
  extern cpumask_t nohz_cpu_mask;
  #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
  extern int select_nohz_load_balancer(int cpu);
@@@ -291,13 -293,13 +293,13 @@@ extern void sched_show_task(struct task
  
  #ifdef CONFIG_DETECT_SOFTLOCKUP
  extern void softlockup_tick(void);
- extern void spawn_softlockup_task(void);
  extern void touch_softlockup_watchdog(void);
  extern void touch_all_softlockup_watchdogs(void);
- extern unsigned long  softlockup_thresh;
+ extern unsigned int  softlockup_panic;
  extern unsigned long sysctl_hung_task_check_count;
  extern unsigned long sysctl_hung_task_timeout_secs;
  extern unsigned long sysctl_hung_task_warnings;
+ extern int softlockup_thresh;
  #else
  static inline void softlockup_tick(void)
  {
@@@ -350,7 -352,7 +352,7 @@@ arch_get_unmapped_area_topdown(struct f
  extern void arch_unmap_area(struct mm_struct *, unsigned long);
  extern void arch_unmap_area_topdown(struct mm_struct *, unsigned long);
  
- #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
+ #if USE_SPLIT_PTLOCKS
  /*
   * The mm counters are not protected by its page_table_lock,
   * so must be incremented atomically.
  #define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
  #define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
  
- #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
+ #else  /* !USE_SPLIT_PTLOCKS */
  /*
   * The mm counters are protected by its page_table_lock,
   * so can be incremented directly.
  #define inc_mm_counter(mm, member) (mm)->_##member++
  #define dec_mm_counter(mm, member) (mm)->_##member--
  
- #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
+ #endif /* !USE_SPLIT_PTLOCKS */
  
  #define get_mm_rss(mm)                                        \
        (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
@@@ -449,8 -451,8 +451,8 @@@ struct signal_struct 
         * - everyone except group_exit_task is stopped during signal delivery
         *   of fatal signals, group_exit_task processes the signal.
         */
-       struct task_struct      *group_exit_task;
        int                     notify_count;
+       struct task_struct      *group_exit_task;
  
        /* thread group stop support, overloads group_exit_code too */
        int                     group_stop_count;
        unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
        unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
        unsigned long inblock, oublock, cinblock, coublock;
+       struct task_io_accounting ioac;
  
        /*
         * Cumulative ns of scheduled CPU time for dead threads in the
@@@ -666,6 -669,10 +669,10 @@@ struct task_delay_info 
                                /* io operations performed */
        u32 swapin_count;       /* total count of the number of swapin block */
                                /* io operations performed */
+       struct timespec freepages_start, freepages_end;
+       u64 freepages_delay;    /* wait for memory reclaim */
+       u32 freepages_count;    /* total count of memory reclaim */
  };
  #endif        /* CONFIG_TASK_DELAY_ACCT */
  
@@@ -784,6 -791,8 +791,8 @@@ struct sched_domain 
        unsigned int balance_interval;  /* initialise to 1. units in ms. */
        unsigned int nr_balance_failed; /* initialise to 0 */
  
+       u64 last_update;
  #ifdef CONFIG_SCHEDSTATS
        /* load_balance() stats */
        unsigned int lb_count[CPU_MAX_IDLE_TYPES];
        unsigned int ttwu_move_affine;
        unsigned int ttwu_move_balance;
  #endif
+ #ifdef CONFIG_SCHED_DEBUG
+       char *name;
+ #endif
  };
  
  extern void partition_sched_domains(int ndoms_new, cpumask_t *doms_new,
                                    struct sched_domain_attr *dattr_new);
  extern int arch_reinit_sched_domains(void);
  
- #endif        /* CONFIG_SMP */
+ #else /* CONFIG_SMP */
  
- /*
-  * A runqueue laden with a single nice 0 task scores a weighted_cpuload of
-  * SCHED_LOAD_SCALE. This function returns 1 if any cpu is laden with a
-  * task of nice 0 or enough lower priority tasks to bring up the
-  * weighted_cpuload
-  */
- static inline int above_background_load(void)
- {
-       unsigned long cpu;
+ struct sched_domain_attr;
  
-       for_each_online_cpu(cpu) {
-               if (weighted_cpuload(cpu) >= SCHED_LOAD_SCALE)
-                       return 1;
-       }
-       return 0;
+ static inline void
+ partition_sched_domains(int ndoms_new, cpumask_t *doms_new,
+                       struct sched_domain_attr *dattr_new)
+ {
  }
+ #endif        /* !CONFIG_SMP */
  
  struct io_context;                    /* See blkdev.h */
  #define NGROUPS_SMALL         32
@@@ -896,7 -900,7 +900,7 @@@ struct sched_class 
        void (*yield_task) (struct rq *rq);
        int  (*select_task_rq)(struct task_struct *p, int sync);
  
-       void (*check_preempt_curr) (struct rq *rq, struct task_struct *p);
+       void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int sync);
  
        struct task_struct * (*pick_next_task) (struct rq *rq);
        void (*put_prev_task) (struct rq *rq, struct task_struct *p);
        void (*set_cpus_allowed)(struct task_struct *p,
                                 const cpumask_t *newmask);
  
-       void (*join_domain)(struct rq *rq);
-       void (*leave_domain)(struct rq *rq);
+       void (*rq_online)(struct rq *rq);
+       void (*rq_offline)(struct rq *rq);
  
        void (*switched_from) (struct rq *this_rq, struct task_struct *task,
                               int running);
@@@ -1009,8 -1013,8 +1013,8 @@@ struct sched_entity 
  
  struct sched_rt_entity {
        struct list_head run_list;
-       unsigned int time_slice;
        unsigned long timeout;
+       unsigned int time_slice;
        int nr_cpus_allowed;
  
        struct sched_rt_entity *back;
@@@ -1039,6 -1043,7 +1043,7 @@@ struct task_struct 
  #endif
  
        int prio, static_prio, normal_prio;
+       unsigned int rt_priority;
        const struct sched_class *sched_class;
        struct sched_entity se;
        struct sched_rt_entity rt;
  #endif
  
        struct list_head tasks;
-       /*
-        * ptrace_list/ptrace_children forms the list of my children
-        * that were stolen by a ptracer.
-        */
-       struct list_head ptrace_children;
-       struct list_head ptrace_list;
  
        struct mm_struct *mm, *active_mm;
  
        pid_t pid;
        pid_t tgid;
  
 -#ifdef CONFIG_CC_STACKPROTECTOR
        /* Canary value for the -fstack-protector gcc feature */
        unsigned long stack_canary;
 -#endif
 +
        /* 
         * pointers to (original) parent process, youngest child, younger sibling,
         * older sibling, respectively.  (p->father can be replaced with 
-        * p->parent->pid)
+        * p->real_parent->pid)
         */
-       struct task_struct *real_parent; /* real parent process (when being debugged) */
-       struct task_struct *parent;     /* parent process */
+       struct task_struct *real_parent; /* real parent process */
+       struct task_struct *parent; /* recipient of SIGCHLD, wait4() reports */
        /*
-        * children/sibling forms the list of my children plus the
-        * tasks I'm ptracing.
+        * children/sibling forms the list of my natural children
         */
        struct list_head children;      /* list of my children */
        struct list_head sibling;       /* linkage in my parent's children list */
        struct task_struct *group_leader;       /* threadgroup leader */
  
+       /*
+        * ptraced is the list of tasks this task is using ptrace on.
+        * This includes both natural children and PTRACE_ATTACH targets.
+        * p->ptrace_entry is p's link on the p->parent->ptraced list.
+        */
+       struct list_head ptraced;
+       struct list_head ptrace_entry;
        /* PID/PID hash table linkage. */
        struct pid_link pids[PIDTYPE_MAX];
        struct list_head thread_group;
        int __user *set_child_tid;              /* CLONE_CHILD_SETTID */
        int __user *clear_child_tid;            /* CLONE_CHILD_CLEARTID */
  
-       unsigned int rt_priority;
        cputime_t utime, stime, utimescaled, stimescaled;
        cputime_t gtime;
        cputime_t prev_utime, prev_stime;
        gid_t gid,egid,sgid,fsgid;
        struct group_info *group_info;
        kernel_cap_t   cap_effective, cap_inheritable, cap_permitted, cap_bset;
-       unsigned securebits;
        struct user_struct *user;
+       unsigned securebits;
  #ifdef CONFIG_KEYS
+       unsigned char jit_keyring;      /* default keyring to attach requested keys to */
        struct key *request_key_auth;   /* assumed request_key authority */
        struct key *thread_keyring;     /* keyring private to this thread */
-       unsigned char jit_keyring;      /* default keyring to attach requested keys to */
  #endif
        char comm[TASK_COMM_LEN]; /* executable name excluding path
                                     - access with [gs]et_task_comm (which lock
  # define MAX_LOCK_DEPTH 48UL
        u64 curr_chain_key;
        int lockdep_depth;
-       struct held_lock held_locks[MAX_LOCK_DEPTH];
        unsigned int lockdep_recursion;
+       struct held_lock held_locks[MAX_LOCK_DEPTH];
  #endif
  
  /* journalling filesystem info */
  
        unsigned long ptrace_message;
        siginfo_t *last_siginfo; /* For ptrace use.  */
- #ifdef CONFIG_TASK_XACCT
- /* i/o counters(bytes read/written, #syscalls */
-       u64 rchar, wchar, syscr, syscw;
- #endif
        struct task_io_accounting ioac;
  #if defined(CONFIG_TASK_XACCT)
        u64 acct_rss_mem1;      /* accumulated rss usage */
        u64 acct_vm_mem1;       /* accumulated virtual memory usage */
-       cputime_t acct_stimexpd;/* stime since last update */
- #endif
- #ifdef CONFIG_NUMA
-       struct mempolicy *mempolicy;
-       short il_next;
+       cputime_t acct_timexpd; /* stime + utime since last update */
  #endif
  #ifdef CONFIG_CPUSETS
        nodemask_t mems_allowed;
  #endif
        struct list_head pi_state_list;
        struct futex_pi_state *pi_state_cache;
+ #endif
+ #ifdef CONFIG_NUMA
+       struct mempolicy *mempolicy;
+       short il_next;
  #endif
        atomic_t fs_excl;       /* holding fs exclusive resources */
        struct rcu_head rcu;
@@@ -1476,6 -1478,10 +1477,10 @@@ static inline void put_task_struct(stru
                __put_task_struct(t);
  }
  
+ extern cputime_t task_utime(struct task_struct *p);
+ extern cputime_t task_stime(struct task_struct *p);
+ extern cputime_t task_gtime(struct task_struct *p);
  /*
   * Per process flags
   */
  #define PF_KSWAPD     0x00040000      /* I am kswapd */
  #define PF_SWAPOFF    0x00080000      /* I am in swapoff */
  #define PF_LESS_THROTTLE 0x00100000   /* Throttle me less: I clean memory */
- #define PF_BORROWED_MM        0x00200000      /* I am a kthread doing use_mm */
+ #define PF_KTHREAD    0x00200000      /* I am a kernel thread */
  #define PF_RANDOMIZE  0x00400000      /* randomize virtual address space */
  #define PF_SWAPWRITE  0x00800000      /* Allowed to write to swap */
  #define PF_SPREAD_PAGE        0x01000000      /* Spread page cache over cpuset */
  #define PF_SPREAD_SLAB        0x02000000      /* Spread some slab caches over cpuset */
+ #define PF_THREAD_BOUND       0x04000000      /* Thread bound to specific cpu */
  #define PF_MEMPOLICY  0x10000000      /* Non-default NUMA mempolicy */
  #define PF_MUTEX_TESTER       0x20000000      /* Thread belongs to the rt mutex tester */
  #define PF_FREEZER_SKIP       0x40000000      /* Freezer should not count it as freezeable */
+ #define PF_FREEZER_NOSIG 0x80000000   /* Freezer won't send signals to it */
  
  /*
   * Only the _current_ task can read/write to tsk->flags, but other
@@@ -1551,16 -1559,10 +1558,10 @@@ static inline int set_cpus_allowed(stru
  
  extern unsigned long long sched_clock(void);
  
- #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
- static inline void sched_clock_init(void)
- {
- }
- static inline u64 sched_clock_cpu(int cpu)
- {
-       return sched_clock();
- }
+ extern void sched_clock_init(void);
+ extern u64 sched_clock_cpu(int cpu);
  
+ #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
  static inline void sched_clock_tick(void)
  {
  }
@@@ -1573,8 -1575,6 +1574,6 @@@ static inline void sched_clock_idle_wak
  {
  }
  #else
- extern void sched_clock_init(void);
- extern u64 sched_clock_cpu(int cpu);
  extern void sched_clock_tick(void);
  extern void sched_clock_idle_sleep_event(void);
  extern void sched_clock_idle_wakeup_event(u64 delta_ns);
@@@ -1621,6 -1621,7 +1620,7 @@@ extern unsigned int sysctl_sched_child_
  extern unsigned int sysctl_sched_features;
  extern unsigned int sysctl_sched_migration_cost;
  extern unsigned int sysctl_sched_nr_migrate;
+ extern unsigned int sysctl_sched_shares_ratelimit;
  
  int sched_nr_latency_handler(struct ctl_table *table, int write,
                struct file *file, void __user *buffer, size_t *length,
@@@ -1654,6 -1655,8 +1654,8 @@@ extern int can_nice(const struct task_s
  extern int task_curr(const struct task_struct *p);
  extern int idle_cpu(int cpu);
  extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
+ extern int sched_setscheduler_nocheck(struct task_struct *, int,
+                                     struct sched_param *);
  extern struct task_struct *idle_task(int cpu);
  extern struct task_struct *curr_task(int cpu);
  extern void set_curr_task(int cpu, struct task_struct *p);
@@@ -1697,19 -1700,13 +1699,13 @@@ extern struct pid_namespace init_pid_ns
   *      finds a task by its pid in the specified namespace
   * find_task_by_vpid():
   *      finds a task by its virtual pid
-  * find_task_by_pid():
-  *      finds a task by its global pid
   *
-  * see also find_pid() etc in include/linux/pid.h
+  * see also find_vpid() etc in include/linux/pid.h
   */
  
  extern struct task_struct *find_task_by_pid_type_ns(int type, int pid,
                struct pid_namespace *ns);
  
- static inline struct task_struct *__deprecated find_task_by_pid(pid_t nr)
- {
-       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, &init_pid_ns);
- }
  extern struct task_struct *find_task_by_vpid(pid_t nr);
  extern struct task_struct *find_task_by_pid_ns(pid_t nr,
                struct pid_namespace *ns);
@@@ -1777,12 -1774,11 +1773,11 @@@ extern int kill_pid_info_as_uid(int, st
  extern int kill_pgrp(struct pid *pid, int sig, int priv);
  extern int kill_pid(struct pid *pid, int sig, int priv);
  extern int kill_proc_info(int, struct siginfo *, pid_t);
- extern void do_notify_parent(struct task_struct *, int);
+ extern int do_notify_parent(struct task_struct *, int);
  extern void force_sig(int, struct task_struct *);
  extern void force_sig_specific(int, struct task_struct *);
  extern int send_sig(int, struct task_struct *, int);
  extern void zap_other_threads(struct task_struct *p);
- extern int kill_proc(pid_t, int, int);
  extern struct sigqueue *sigqueue_alloc(void);
  extern void sigqueue_free(struct sigqueue *);
  extern int send_sigqueue(struct sigqueue *,  struct task_struct *, int group);
@@@ -1864,14 -1860,15 +1859,15 @@@ extern void set_task_comm(struct task_s
  extern char *get_task_comm(char *to, struct task_struct *tsk);
  
  #ifdef CONFIG_SMP
- extern void wait_task_inactive(struct task_struct * p);
+ extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
  #else
- #define wait_task_inactive(p) do { } while (0)
+ static inline unsigned long wait_task_inactive(struct task_struct *p,
+                                              long match_state)
+ {
+       return 1;
+ }
  #endif
  
- #define remove_parent(p)      list_del_init(&(p)->sibling)
- #define add_parent(p)         list_add_tail(&(p)->sibling,&(p)->parent->children)
  #define next_task(p)  list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks)
  
  #define for_each_process(p) \
@@@ -1968,21 -1965,15 +1964,28 @@@ static inline unsigned long *end_of_sta
  
  #endif
  
+ static inline int object_is_on_stack(void *obj)
+ {
+       void *stack = task_stack_page(current);
+       return (obj >= stack) && (obj < (stack + THREAD_SIZE));
+ }
  extern void thread_info_cache_init(void);
  
 +#ifdef CONFIG_DEBUG_STACK_USAGE
 +static inline unsigned long stack_not_used(struct task_struct *p)
 +{
 +      unsigned long *n = end_of_stack(p);
 +
 +      do {    /* Skip over canary */
 +              n++;
 +      } while (!*n);
 +
 +      return (unsigned long)n - (unsigned long)end_of_stack(p);
 +}
 +#endif
 +
  /* set thread flags in other task's structures
   * - see asm/thread_info.h for TIF_xxxx flags available
   */
@@@ -2045,9 -2036,6 +2048,6 @@@ static inline int signal_pending_state(
        if (!signal_pending(p))
                return 0;
  
-       if (state & (__TASK_STOPPED | __TASK_TRACED))
-               return 0;
        return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
  }
  
@@@ -2132,14 -2120,17 +2132,17 @@@ static inline void set_task_cpu(struct 
  
  #endif /* CONFIG_SMP */
  
- #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  extern void arch_pick_mmap_layout(struct mm_struct *mm);
+ #ifdef CONFIG_TRACING
+ extern void
+ __trace_special(void *__tr, void *__data,
+               unsigned long arg1, unsigned long arg2, unsigned long arg3);
  #else
- static inline void arch_pick_mmap_layout(struct mm_struct *mm)
+ static inline void
+ __trace_special(void *__tr, void *__data,
+               unsigned long arg1, unsigned long arg2, unsigned long arg3)
  {
-       mm->mmap_base = TASK_UNMAPPED_BASE;
-       mm->get_unmapped_area = arch_get_unmapped_area;
-       mm->unmap_area = arch_unmap_area;
  }
  #endif
  
@@@ -2177,22 -2168,22 +2180,22 @@@ extern long sched_group_rt_period(struc
  #ifdef CONFIG_TASK_XACCT
  static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
  {
-       tsk->rchar += amt;
+       tsk->ioac.rchar += amt;
  }
  
  static inline void add_wchar(struct task_struct *tsk, ssize_t amt)
  {
-       tsk->wchar += amt;
+       tsk->ioac.wchar += amt;
  }
  
  static inline void inc_syscr(struct task_struct *tsk)
  {
-       tsk->syscr++;
+       tsk->ioac.syscr++;
  }
  
  static inline void inc_syscw(struct task_struct *tsk)
  {
-       tsk->syscw++;
+       tsk->ioac.syscw++;
  }
  #else
  static inline void add_rchar(struct task_struct *tsk, ssize_t amt)
@@@ -2212,14 -2203,6 +2215,6 @@@ static inline void inc_syscw(struct tas
  }
  #endif
  
- #ifdef CONFIG_SMP
- void migration_init(void);
- #else
- static inline void migration_init(void)
- {
- }
- #endif
  #ifndef TASK_SIZE_OF
  #define TASK_SIZE_OF(tsk)     TASK_SIZE
  #endif
@@@ -2237,6 -2220,8 +2232,8 @@@ static inline void mm_init_owner(struc
  }
  #endif /* CONFIG_MM_OWNER */
  
+ #define TASK_STATE_TO_CHAR_STR "RSDTtZX"
  #endif /* __KERNEL__ */
  
  #endif
diff --combined init/main.c
@@@ -14,7 -14,6 +14,7 @@@
  #include <linux/proc_fs.h>
  #include <linux/kernel.h>
  #include <linux/syscalls.h>
 +#include <linux/stackprotector.h>
  #include <linux/string.h>
  #include <linux/ctype.h>
  #include <linux/delay.h>
@@@ -23,7 -22,6 +23,6 @@@
  #include <linux/init.h>
  #include <linux/smp_lock.h>
  #include <linux/initrd.h>
- #include <linux/hdreg.h>
  #include <linux/bootmem.h>
  #include <linux/tty.h>
  #include <linux/gfp.h>
@@@ -32,6 -30,7 +31,7 @@@
  #include <linux/kernel_stat.h>
  #include <linux/start_kernel.h>
  #include <linux/security.h>
+ #include <linux/smp.h>
  #include <linux/workqueue.h>
  #include <linux/profile.h>
  #include <linux/rcupdate.h>
@@@ -87,8 -86,6 +87,6 @@@ extern void init_IRQ(void)
  extern void fork_init(unsigned long);
  extern void mca_init(void);
  extern void sbus_init(void);
- extern void pidhash_init(void);
- extern void pidmap_init(void);
  extern void prio_tree_init(void);
  extern void radix_tree_init(void);
  extern void free_initmem(void);
@@@ -415,6 -412,13 +413,13 @@@ static void __init smp_init(void
  {
        unsigned int cpu;
  
+       /*
+        * Set up the current CPU as possible to migrate to.
+        * The other ones will be done by cpu_up/cpu_down()
+        */
+       cpu = smp_processor_id();
+       cpu_set(cpu, cpu_active_map);
        /* FIXME: This should be done in userspace --RR */
        for_each_present_cpu(cpu) {
                if (num_online_cpus() >= setup_max_cpus)
@@@ -546,12 -550,6 +551,12 @@@ asmlinkage void __init start_kernel(voi
        unwind_init();
        lockdep_init();
        debug_objects_early_init();
 +
 +      /*
 +       * Set up the the initial canary ASAP:
 +       */
 +      boot_init_stack_canary();
 +
        cgroup_init_early();
  
        local_irq_disable();
  
  #ifdef CONFIG_BLK_DEV_INITRD
        if (initrd_start && !initrd_below_start_ok &&
-                       initrd_start < min_low_pfn << PAGE_SHIFT) {
+           page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {
                printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
-                   "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT);
+                   "disabling it.\n",
+                   page_to_pfn(virt_to_page((void *)initrd_start)),
+                   min_low_pfn);
                initrd_start = 0;
        }
  #endif
        rest_init();
  }
  
- static int __initdata initcall_debug;
+ static int initcall_debug;
  
  static int __init initcall_debug_setup(char *str)
  {
  }
  __setup("initcall_debug", initcall_debug_setup);
  
static void __init do_one_initcall(initcall_t fn)
int do_one_initcall(initcall_t fn)
  {
        int count = preempt_count();
        ktime_t t0, t1, delta;
        int result;
  
        if (initcall_debug) {
-               print_fn_descriptor_symbol("calling  %s\n", fn);
+               printk("calling  %pF @ %i\n", fn, task_pid_nr(current));
                t0 = ktime_get();
        }
  
                t1 = ktime_get();
                delta = ktime_sub(t1, t0);
  
-               print_fn_descriptor_symbol("initcall %s", fn);
-               printk(" returned %d after %Ld msecs\n", result,
+               printk("initcall %pF returned %d after %Ld msecs\n",
+                       fn, result,
                        (unsigned long long) delta.tv64 >> 20);
        }
  
                local_irq_enable();
        }
        if (msgbuf[0]) {
-               print_fn_descriptor_symbol(KERN_WARNING "initcall %s", fn);
-               printk(" returned with %s\n", msgbuf);
+               printk("initcall %pF returned with %s\n", fn, msgbuf);
        }
+       return result;
  }
  
  
- extern initcall_t __initcall_start[], __initcall_end[];
+ extern initcall_t __initcall_start[], __initcall_end[], __early_initcall_end[];
  
  static void __init do_initcalls(void)
  {
        initcall_t *call;
  
-       for (call = __initcall_start; call < __initcall_end; call++)
+       for (call = __early_initcall_end; call < __initcall_end; call++)
                do_one_initcall(*call);
  
        /* Make sure there is no pending stuff from the initcall sequence */
   */
  static void __init do_basic_setup(void)
  {
+       rcu_init_sched(); /* needed by module_init stage. */
        /* drivers will send hotplug events */
        init_workqueues();
        usermodehelper_init();
        do_initcalls();
  }
  
- static int __initdata nosoftlockup;
- static int __init nosoftlockup_setup(char *str)
- {
-       nosoftlockup = 1;
-       return 1;
- }
- __setup("nosoftlockup", nosoftlockup_setup);
  static void __init do_pre_smp_initcalls(void)
  {
-       extern int spawn_ksoftirqd(void);
+       initcall_t *call;
  
-       migration_init();
-       spawn_ksoftirqd();
-       if (!nosoftlockup)
-               spawn_softlockup_task();
+       for (call = __initcall_start; call < __early_initcall_end; call++)
+               do_one_initcall(*call);
  }
  
  static void run_init_process(char *init_filename)
diff --combined kernel/exit.c
@@@ -13,6 -13,7 +13,7 @@@
  #include <linux/personality.h>
  #include <linux/tty.h>
  #include <linux/mnt_namespace.h>
+ #include <linux/iocontext.h>
  #include <linux/key.h>
  #include <linux/security.h>
  #include <linux/cpu.h>
@@@ -45,6 -46,7 +46,7 @@@
  #include <linux/resource.h>
  #include <linux/blkdev.h>
  #include <linux/task_io_accounting_ops.h>
+ #include <linux/tracehook.h>
  
  #include <asm/uaccess.h>
  #include <asm/unistd.h>
@@@ -70,7 -72,7 +72,7 @@@ static void __unhash_process(struct tas
                __get_cpu_var(process_counts)--;
        }
        list_del_rcu(&p->thread_group);
-       remove_parent(p);
+       list_del_init(&p->sibling);
  }
  
  /*
@@@ -84,7 -86,6 +86,6 @@@ static void __exit_signal(struct task_s
        BUG_ON(!sig);
        BUG_ON(!atomic_read(&sig->count));
  
-       rcu_read_lock();
        sighand = rcu_dereference(tsk->sighand);
        spin_lock(&sighand->siglock);
  
                 * We won't ever get here for the group leader, since it
                 * will have been the last reference on the signal_struct.
                 */
-               sig->utime = cputime_add(sig->utime, tsk->utime);
-               sig->stime = cputime_add(sig->stime, tsk->stime);
-               sig->gtime = cputime_add(sig->gtime, tsk->gtime);
+               sig->utime = cputime_add(sig->utime, task_utime(tsk));
+               sig->stime = cputime_add(sig->stime, task_stime(tsk));
+               sig->gtime = cputime_add(sig->gtime, task_gtime(tsk));
                sig->min_flt += tsk->min_flt;
                sig->maj_flt += tsk->maj_flt;
                sig->nvcsw += tsk->nvcsw;
                sig->nivcsw += tsk->nivcsw;
                sig->inblock += task_io_get_inblock(tsk);
                sig->oublock += task_io_get_oublock(tsk);
+               task_io_accounting_add(&sig->ioac, &tsk->ioac);
                sig->sum_sched_runtime += tsk->se.sum_exec_runtime;
                sig = NULL; /* Marker for below. */
        }
        tsk->signal = NULL;
        tsk->sighand = NULL;
        spin_unlock(&sighand->siglock);
-       rcu_read_unlock();
  
        __cleanup_sighand(sighand);
        clear_tsk_thread_flag(tsk,TIF_SIGPENDING);
@@@ -151,16 -152,17 +152,17 @@@ static void delayed_put_task_struct(str
        put_task_struct(container_of(rhp, struct task_struct, rcu));
  }
  
  void release_task(struct task_struct * p)
  {
        struct task_struct *leader;
        int zap_leader;
  repeat:
+       tracehook_prepare_release_task(p);
        atomic_dec(&p->user->processes);
        proc_flush_task(p);
        write_lock_irq(&tasklist_lock);
-       ptrace_unlink(p);
-       BUG_ON(!list_empty(&p->ptrace_list) || !list_empty(&p->ptrace_children));
+       tracehook_finish_release_task(p);
        __exit_signal(p);
  
        /*
                 * that case.
                 */
                zap_leader = task_detached(leader);
+               /*
+                * This maintains the invariant that release_task()
+                * only runs on a task in EXIT_DEAD, just for sanity.
+                */
+               if (zap_leader)
+                       leader->exit_state = EXIT_DEAD;
        }
  
        write_unlock_irq(&tasklist_lock);
@@@ -314,9 -323,8 +323,8 @@@ static void reparent_to_kthreadd(void
  
        ptrace_unlink(current);
        /* Reparent to init */
-       remove_parent(current);
        current->real_parent = current->parent = kthreadd_task;
-       add_parent(current);
+       list_move_tail(&current->sibling, &current->real_parent->children);
  
        /* Set the exit signal to SIGCHLD so we signal init on exit */
        current->exit_signal = SIGCHLD;
@@@ -421,7 -429,7 +429,7 @@@ void daemonize(const char *name, ...
         * We don't want to have TIF_FREEZE set if the system-wide hibernation
         * or suspend transition begins right now.
         */
-       current->flags |= PF_NOFREEZE;
+       current->flags |= (PF_NOFREEZE | PF_KTHREAD);
  
        if (current->nsproxy != &init_nsproxy) {
                get_nsproxy(&init_nsproxy);
@@@ -546,8 -554,6 +554,6 @@@ void put_fs_struct(struct fs_struct *fs
        if (atomic_dec_and_test(&fs->count)) {
                path_put(&fs->root);
                path_put(&fs->pwd);
-               if (fs->altroot.dentry)
-                       path_put(&fs->altroot);
                kmem_cache_free(fs_cachep, fs);
        }
  }
@@@ -577,8 -583,6 +583,6 @@@ mm_need_new_owner(struct mm_struct *mm
         * If there are other users of the mm and the owner (us) is exiting
         * we need to find a new owner to take on the responsibility.
         */
-       if (!mm)
-               return 0;
        if (atomic_read(&mm->mm_users) <= 1)
                return 0;
        if (mm->owner != p)
@@@ -621,6 -625,16 +625,16 @@@ retry
        } while_each_thread(g, c);
  
        read_unlock(&tasklist_lock);
+       /*
+        * We found no owner yet mm_users > 1: this implies that we are
+        * most likely racing with swapoff (try_to_unuse()) or /proc or
+        * ptrace or page migration (get_task_mm()).  Mark owner as NULL,
+        * so that subsystems can understand the callback and take action.
+        */
+       down_write(&mm->mmap_sem);
+       cgroup_mm_owner_callbacks(mm->owner, NULL);
+       mm->owner = NULL;
+       up_write(&mm->mmap_sem);
        return;
  
  assign_new_owner:
  static void exit_mm(struct task_struct * tsk)
  {
        struct mm_struct *mm = tsk->mm;
+       struct core_state *core_state;
  
        mm_release(tsk, mm);
        if (!mm)
                return;
        /*
         * Serialize with any possible pending coredump.
-        * We must hold mmap_sem around checking core_waiters
+        * We must hold mmap_sem around checking core_state
         * and clearing tsk->mm.  The core-inducing thread
-        * will increment core_waiters for each thread in the
+        * will increment ->nr_threads for each thread in the
         * group with ->mm != NULL.
         */
        down_read(&mm->mmap_sem);
-       if (mm->core_waiters) {
+       core_state = mm->core_state;
+       if (core_state) {
+               struct core_thread self;
                up_read(&mm->mmap_sem);
-               down_write(&mm->mmap_sem);
-               if (!--mm->core_waiters)
-                       complete(mm->core_startup_done);
-               up_write(&mm->mmap_sem);
  
-               wait_for_completion(&mm->core_done);
+               self.task = tsk;
+               self.next = xchg(&core_state->dumper.next, &self);
+               /*
+                * Implies mb(), the result of xchg() must be visible
+                * to core_state->dumper.
+                */
+               if (atomic_dec_and_test(&core_state->nr_threads))
+                       complete(&core_state->startup);
+               for (;;) {
+                       set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+                       if (!self.task) /* see coredump_finish() */
+                               break;
+                       schedule();
+               }
+               __set_task_state(tsk, TASK_RUNNING);
                down_read(&mm->mmap_sem);
        }
        atomic_inc(&mm->mm_count);
        mmput(mm);
  }
  
- static void
- reparent_thread(struct task_struct *p, struct task_struct *father, int traced)
+ /*
+  * Return nonzero if @parent's children should reap themselves.
+  *
+  * Called with write_lock_irq(&tasklist_lock) held.
+  */
+ static int ignoring_children(struct task_struct *parent)
  {
-       if (p->pdeath_signal)
-               /* We already hold the tasklist_lock here.  */
-               group_send_sig_info(p->pdeath_signal, SEND_SIG_NOINFO, p);
+       int ret;
+       struct sighand_struct *psig = parent->sighand;
+       unsigned long flags;
+       spin_lock_irqsave(&psig->siglock, flags);
+       ret = (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN ||
+              (psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT));
+       spin_unlock_irqrestore(&psig->siglock, flags);
+       return ret;
+ }
  
-       /* Move the child from its dying parent to the new one.  */
-       if (unlikely(traced)) {
-               /* Preserve ptrace links if someone else is tracing this child.  */
-               list_del_init(&p->ptrace_list);
-               if (ptrace_reparented(p))
-                       list_add(&p->ptrace_list, &p->real_parent->ptrace_children);
-       } else {
-               /* If this child is being traced, then we're the one tracing it
-                * anyway, so let go of it.
+ /*
+  * Detach all tasks we were using ptrace on.
+  * Any that need to be release_task'd are put on the @dead list.
+  *
+  * Called with write_lock(&tasklist_lock) held.
+  */
+ static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
+ {
+       struct task_struct *p, *n;
+       int ign = -1;
+       list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
+               __ptrace_unlink(p);
+               if (p->exit_state != EXIT_ZOMBIE)
+                       continue;
+               /*
+                * If it's a zombie, our attachedness prevented normal
+                * parent notification or self-reaping.  Do notification
+                * now if it would have happened earlier.  If it should
+                * reap itself, add it to the @dead list.  We can't call
+                * release_task() here because we already hold tasklist_lock.
+                *
+                * If it's our own child, there is no notification to do.
+                * But if our normal children self-reap, then this child
+                * was prevented by ptrace and we must reap it now.
                 */
-               p->ptrace = 0;
-               remove_parent(p);
-               p->parent = p->real_parent;
-               add_parent(p);
+               if (!task_detached(p) && thread_group_empty(p)) {
+                       if (!same_thread_group(p->real_parent, parent))
+                               do_notify_parent(p, p->exit_signal);
+                       else {
+                               if (ign < 0)
+                                       ign = ignoring_children(parent);
+                               if (ign)
+                                       p->exit_signal = -1;
+                       }
+               }
  
-               if (task_is_traced(p)) {
+               if (task_detached(p)) {
                        /*
-                        * If it was at a trace stop, turn it into
-                        * a normal stop since it's no longer being
-                        * traced.
+                        * Mark it as in the process of being reaped.
                         */
-                       ptrace_untrace(p);
+                       p->exit_state = EXIT_DEAD;
+                       list_add(&p->ptrace_entry, dead);
                }
        }
+ }
+ /*
+  * Finish up exit-time ptrace cleanup.
+  *
+  * Called without locks.
+  */
+ static void ptrace_exit_finish(struct task_struct *parent,
+                              struct list_head *dead)
+ {
+       struct task_struct *p, *n;
+       BUG_ON(!list_empty(&parent->ptraced));
+       list_for_each_entry_safe(p, n, dead, ptrace_entry) {
+               list_del_init(&p->ptrace_entry);
+               release_task(p);
+       }
+ }
+ static void reparent_thread(struct task_struct *p, struct task_struct *father)
+ {
+       if (p->pdeath_signal)
+               /* We already hold the tasklist_lock here.  */
+               group_send_sig_info(p->pdeath_signal, SEND_SIG_NOINFO, p);
+       list_move_tail(&p->sibling, &p->real_parent->children);
  
        /* If this is a threaded reparent there is no need to
         * notify anyone anything has happened.
        /* If we'd notified the old parent about this child's death,
         * also notify the new parent.
         */
-       if (!traced && p->exit_state == EXIT_ZOMBIE &&
+       if (!ptrace_reparented(p) &&
+           p->exit_state == EXIT_ZOMBIE &&
            !task_detached(p) && thread_group_empty(p))
                do_notify_parent(p, p->exit_signal);
  
   * the child reaper process (ie "init") in our pid
   * space.
   */
- static void forget_original_parent(struct task_struct *father)
+ static struct task_struct *find_new_reaper(struct task_struct *father)
  {
-       struct task_struct *p, *n, *reaper = father;
-       struct list_head ptrace_dead;
-       INIT_LIST_HEAD(&ptrace_dead);
-       write_lock_irq(&tasklist_lock);
-       do {
-               reaper = next_thread(reaper);
-               if (reaper == father) {
-                       reaper = task_child_reaper(father);
-                       break;
-               }
-       } while (reaper->flags & PF_EXITING);
+       struct pid_namespace *pid_ns = task_active_pid_ns(father);
+       struct task_struct *thread;
  
-       /*
-        * There are only two places where our children can be:
-        *
-        * - in our child list
-        * - in our ptraced child list
-        *
-        * Search them and reparent children.
-        */
-       list_for_each_entry_safe(p, n, &father->children, sibling) {
-               int ptrace;
-               ptrace = p->ptrace;
-               /* if father isn't the real parent, then ptrace must be enabled */
-               BUG_ON(father != p->real_parent && !ptrace);
+       thread = father;
+       while_each_thread(father, thread) {
+               if (thread->flags & PF_EXITING)
+                       continue;
+               if (unlikely(pid_ns->child_reaper == father))
+                       pid_ns->child_reaper = thread;
+               return thread;
+       }
  
-               if (father == p->real_parent) {
-                       /* reparent with a reaper, real father it's us */
-                       p->real_parent = reaper;
-                       reparent_thread(p, father, 0);
-               } else {
-                       /* reparent ptraced task to its real parent */
-                       __ptrace_unlink (p);
-                       if (p->exit_state == EXIT_ZOMBIE && !task_detached(p) &&
-                           thread_group_empty(p))
-                               do_notify_parent(p, p->exit_signal);
-               }
+       if (unlikely(pid_ns->child_reaper == father)) {
+               write_unlock_irq(&tasklist_lock);
+               if (unlikely(pid_ns == &init_pid_ns))
+                       panic("Attempted to kill init!");
  
+               zap_pid_ns_processes(pid_ns);
+               write_lock_irq(&tasklist_lock);
                /*
-                * if the ptraced child is a detached zombie we must collect
-                * it before we exit, or it will remain zombie forever since
-                * we prevented it from self-reap itself while it was being
-                * traced by us, to be able to see it in wait4.
+                * We can not clear ->child_reaper or leave it alone.
+                * There may by stealth EXIT_DEAD tasks on ->children,
+                * forget_original_parent() must move them somewhere.
                 */
-               if (unlikely(ptrace && p->exit_state == EXIT_ZOMBIE && task_detached(p)))
-                       list_add(&p->ptrace_list, &ptrace_dead);
+               pid_ns->child_reaper = init_pid_ns.child_reaper;
        }
  
-       list_for_each_entry_safe(p, n, &father->ptrace_children, ptrace_list) {
+       return pid_ns->child_reaper;
+ }
+ static void forget_original_parent(struct task_struct *father)
+ {
+       struct task_struct *p, *n, *reaper;
+       LIST_HEAD(ptrace_dead);
+       write_lock_irq(&tasklist_lock);
+       reaper = find_new_reaper(father);
+       /*
+        * First clean up ptrace if we were using it.
+        */
+       ptrace_exit(father, &ptrace_dead);
+       list_for_each_entry_safe(p, n, &father->children, sibling) {
                p->real_parent = reaper;
-               reparent_thread(p, father, 1);
+               if (p->parent == father) {
+                       BUG_ON(p->ptrace);
+                       p->parent = p->real_parent;
+               }
+               reparent_thread(p, father);
        }
  
        write_unlock_irq(&tasklist_lock);
        BUG_ON(!list_empty(&father->children));
-       BUG_ON(!list_empty(&father->ptrace_children));
-       list_for_each_entry_safe(p, n, &ptrace_dead, ptrace_list) {
-               list_del_init(&p->ptrace_list);
-               release_task(p);
-       }
  
+       ptrace_exit_finish(father, &ptrace_dead);
  }
  
  /*
   */
  static void exit_notify(struct task_struct *tsk, int group_dead)
  {
-       int state;
+       int signal;
+       void *cookie;
  
        /*
         * This does two things:
            !capable(CAP_KILL))
                tsk->exit_signal = SIGCHLD;
  
-       /* If something other than our normal parent is ptracing us, then
-        * send it a SIGCHLD instead of honoring exit_signal.  exit_signal
-        * only has special meaning to our real parent.
-        */
-       if (!task_detached(tsk) && thread_group_empty(tsk)) {
-               int signal = ptrace_reparented(tsk) ?
-                               SIGCHLD : tsk->exit_signal;
-               do_notify_parent(tsk, signal);
-       } else if (tsk->ptrace) {
-               do_notify_parent(tsk, SIGCHLD);
-       }
+       signal = tracehook_notify_death(tsk, &cookie, group_dead);
+       if (signal >= 0)
+               signal = do_notify_parent(tsk, signal);
  
-       state = EXIT_ZOMBIE;
-       if (task_detached(tsk) && likely(!tsk->ptrace))
-               state = EXIT_DEAD;
-       tsk->exit_state = state;
+       tsk->exit_state = signal == DEATH_REAP ? EXIT_DEAD : EXIT_ZOMBIE;
  
        /* mt-exec, de_thread() is waiting for us */
        if (thread_group_leader(tsk) &&
-           tsk->signal->notify_count < 0 &&
-           tsk->signal->group_exit_task)
+           tsk->signal->group_exit_task &&
+           tsk->signal->notify_count < 0)
                wake_up_process(tsk->signal->group_exit_task);
  
        write_unlock_irq(&tasklist_lock);
  
+       tracehook_report_death(tsk, signal, cookie, group_dead);
        /* If the process is dead, release it - nobody will wait for it */
-       if (state == EXIT_DEAD)
+       if (signal == DEATH_REAP)
                release_task(tsk);
  }
  
@@@ -899,9 -968,12 +968,9 @@@ static void check_stack_usage(void
  {
        static DEFINE_SPINLOCK(low_water_lock);
        static int lowest_to_date = THREAD_SIZE;
 -      unsigned long *n = end_of_stack(current);
        unsigned long free;
  
 -      while (*n == 0)
 -              n++;
 -      free = (unsigned long)n - (unsigned long)end_of_stack(current);
 +      free = stack_not_used(current);
  
        if (free >= lowest_to_date)
                return;
  static inline void check_stack_usage(void) {}
  #endif
  
- static inline void exit_child_reaper(struct task_struct *tsk)
- {
-       if (likely(tsk->group_leader != task_child_reaper(tsk)))
-               return;
-       if (tsk->nsproxy->pid_ns == &init_pid_ns)
-               panic("Attempted to kill init!");
-       /*
-        * @tsk is the last thread in the 'cgroup-init' and is exiting.
-        * Terminate all remaining processes in the namespace and reap them
-        * before exiting @tsk.
-        *
-        * Note that @tsk (last thread of cgroup-init) may not necessarily
-        * be the child-reaper (i.e main thread of cgroup-init) of the
-        * namespace i.e the child_reaper may have already exited.
-        *
-        * Even after a child_reaper exits, we let it inherit orphaned children,
-        * because, pid_ns->child_reaper remains valid as long as there is
-        * at least one living sub-thread in the cgroup init.
-        * This living sub-thread of the cgroup-init will be notified when
-        * a child inherited by the 'child-reaper' exits (do_notify_parent()
-        * uses __group_send_sig_info()). Further, when reaping child processes,
-        * do_wait() iterates over children of all living sub threads.
-        * i.e even though 'child_reaper' thread is listed as the parent of the
-        * orphaned children, any living sub-thread in the cgroup-init can
-        * perform the role of the child_reaper.
-        */
-       zap_pid_ns_processes(tsk->nsproxy->pid_ns);
- }
  NORET_TYPE void do_exit(long code)
  {
        struct task_struct *tsk = current;
        if (unlikely(!tsk->pid))
                panic("Attempted to kill the idle task!");
  
-       if (unlikely(current->ptrace & PT_TRACE_EXIT)) {
-               current->ptrace_message = code;
-               ptrace_notify((PTRACE_EVENT_EXIT << 8) | SIGTRAP);
-       }
+       tracehook_report_exit(&code);
  
        /*
         * We're taking recursive faults here in do_exit. Safest is to just
        }
        group_dead = atomic_dec_and_test(&tsk->signal->live);
        if (group_dead) {
-               exit_child_reaper(tsk);
                hrtimer_cancel(&tsk->signal->real_timer);
                exit_itimers(tsk->signal);
        }
@@@ -1176,13 -1211,6 +1208,6 @@@ static int eligible_child(enum pid_typ
                        return 0;
        }
  
-       /*
-        * Do not consider detached threads that are
-        * not ptraced:
-        */
-       if (task_detached(p) && !p->ptrace)
-               return 0;
        /* Wait for all children (clone and not) if __WALL is set;
         * otherwise, wait for clone children *only* if __WCLONE is
         * set; otherwise, wait for non-clone children *only*.  (Note:
                return 0;
  
        err = security_task_wait(p);
-       if (likely(!err))
-               return 1;
+       if (err)
+               return err;
  
-       if (type != PIDTYPE_PID)
-               return 0;
-       /* This child was explicitly requested, abort */
-       read_unlock(&tasklist_lock);
-       return err;
+       return 1;
  }
  
  static int wait_noreap_copyout(struct task_struct *p, pid_t pid, uid_t uid,
   * the lock and this task is uninteresting.  If we return nonzero, we have
   * released the lock and the system call should return.
   */
- static int wait_task_zombie(struct task_struct *p, int noreap,
+ static int wait_task_zombie(struct task_struct *p, int options,
                            struct siginfo __user *infop,
                            int __user *stat_addr, struct rusage __user *ru)
  {
        int retval, status, traced;
        pid_t pid = task_pid_vnr(p);
  
-       if (unlikely(noreap)) {
+       if (!likely(options & WEXITED))
+               return 0;
+       if (unlikely(options & WNOWAIT)) {
                uid_t uid = p->uid;
                int exit_code = p->exit_code;
                int why, status;
                psig->coublock +=
                        task_io_get_oublock(p) +
                        sig->oublock + sig->coublock;
+               task_io_accounting_add(&psig->ioac, &p->ioac);
+               task_io_accounting_add(&psig->ioac, &sig->ioac);
                spin_unlock_irq(&p->parent->sighand->siglock);
        }
  
   * the lock and this task is uninteresting.  If we return nonzero, we have
   * released the lock and the system call should return.
   */
- static int wait_task_stopped(struct task_struct *p,
-                            int noreap, struct siginfo __user *infop,
+ static int wait_task_stopped(int ptrace, struct task_struct *p,
+                            int options, struct siginfo __user *infop,
                             int __user *stat_addr, struct rusage __user *ru)
  {
        int retval, exit_code, why;
        uid_t uid = 0; /* unneeded, required by compiler */
        pid_t pid;
  
+       if (!(options & WUNTRACED))
+               return 0;
        exit_code = 0;
        spin_lock_irq(&p->sighand->siglock);
  
        if (unlikely(!task_is_stopped_or_traced(p)))
                goto unlock_sig;
  
-       if (!(p->ptrace & PT_PTRACED) && p->signal->group_stop_count > 0)
+       if (!ptrace && p->signal->group_stop_count > 0)
                /*
                 * A group stop is in progress and this is the group leader.
                 * We won't report until all threads have stopped.
        if (!exit_code)
                goto unlock_sig;
  
-       if (!noreap)
+       if (!unlikely(options & WNOWAIT))
                p->exit_code = 0;
  
        uid = p->uid;
@@@ -1435,10 -1467,10 +1464,10 @@@ unlock_sig
         */
        get_task_struct(p);
        pid = task_pid_vnr(p);
-       why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED;
+       why = ptrace ? CLD_TRAPPED : CLD_STOPPED;
        read_unlock(&tasklist_lock);
  
-       if (unlikely(noreap))
+       if (unlikely(options & WNOWAIT))
                return wait_noreap_copyout(p, pid, uid,
                                           why, exit_code,
                                           infop, ru);
   * the lock and this task is uninteresting.  If we return nonzero, we have
   * released the lock and the system call should return.
   */
- static int wait_task_continued(struct task_struct *p, int noreap,
+ static int wait_task_continued(struct task_struct *p, int options,
                               struct siginfo __user *infop,
                               int __user *stat_addr, struct rusage __user *ru)
  {
        pid_t pid;
        uid_t uid;
  
+       if (!unlikely(options & WCONTINUED))
+               return 0;
        if (!(p->signal->flags & SIGNAL_STOP_CONTINUED))
                return 0;
  
                spin_unlock_irq(&p->sighand->siglock);
                return 0;
        }
-       if (!noreap)
+       if (!unlikely(options & WNOWAIT))
                p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
        spin_unlock_irq(&p->sighand->siglock);
  
        return retval;
  }
  
+ /*
+  * Consider @p for a wait by @parent.
+  *
+  * -ECHILD should be in *@notask_error before the first call.
+  * Returns nonzero for a final return, when we have unlocked tasklist_lock.
+  * Returns zero if the search for a child should continue;
+  * then *@notask_error is 0 if @p is an eligible child,
+  * or another error from security_task_wait(), or still -ECHILD.
+  */
+ static int wait_consider_task(struct task_struct *parent, int ptrace,
+                             struct task_struct *p, int *notask_error,
+                             enum pid_type type, struct pid *pid, int options,
+                             struct siginfo __user *infop,
+                             int __user *stat_addr, struct rusage __user *ru)
+ {
+       int ret = eligible_child(type, pid, options, p);
+       if (!ret)
+               return ret;
+       if (unlikely(ret < 0)) {
+               /*
+                * If we have not yet seen any eligible child,
+                * then let this error code replace -ECHILD.
+                * A permission error will give the user a clue
+                * to look for security policy problems, rather
+                * than for mysterious wait bugs.
+                */
+               if (*notask_error)
+                       *notask_error = ret;
+       }
+       if (likely(!ptrace) && unlikely(p->ptrace)) {
+               /*
+                * This child is hidden by ptrace.
+                * We aren't allowed to see it now, but eventually we will.
+                */
+               *notask_error = 0;
+               return 0;
+       }
+       if (p->exit_state == EXIT_DEAD)
+               return 0;
+       /*
+        * We don't reap group leaders with subthreads.
+        */
+       if (p->exit_state == EXIT_ZOMBIE && !delay_group_leader(p))
+               return wait_task_zombie(p, options, infop, stat_addr, ru);
+       /*
+        * It's stopped or running now, so it might
+        * later continue, exit, or stop again.
+        */
+       *notask_error = 0;
+       if (task_is_stopped_or_traced(p))
+               return wait_task_stopped(ptrace, p, options,
+                                        infop, stat_addr, ru);
+       return wait_task_continued(p, options, infop, stat_addr, ru);
+ }
+ /*
+  * Do the work of do_wait() for one thread in the group, @tsk.
+  *
+  * -ECHILD should be in *@notask_error before the first call.
+  * Returns nonzero for a final return, when we have unlocked tasklist_lock.
+  * Returns zero if the search for a child should continue; then
+  * *@notask_error is 0 if there were any eligible children,
+  * or another error from security_task_wait(), or still -ECHILD.
+  */
+ static int do_wait_thread(struct task_struct *tsk, int *notask_error,
+                         enum pid_type type, struct pid *pid, int options,
+                         struct siginfo __user *infop, int __user *stat_addr,
+                         struct rusage __user *ru)
+ {
+       struct task_struct *p;
+       list_for_each_entry(p, &tsk->children, sibling) {
+               /*
+                * Do not consider detached threads.
+                */
+               if (!task_detached(p)) {
+                       int ret = wait_consider_task(tsk, 0, p, notask_error,
+                                                    type, pid, options,
+                                                    infop, stat_addr, ru);
+                       if (ret)
+                               return ret;
+               }
+       }
+       return 0;
+ }
+ static int ptrace_do_wait(struct task_struct *tsk, int *notask_error,
+                         enum pid_type type, struct pid *pid, int options,
+                         struct siginfo __user *infop, int __user *stat_addr,
+                         struct rusage __user *ru)
+ {
+       struct task_struct *p;
+       /*
+        * Traditionally we see ptrace'd stopped tasks regardless of options.
+        */
+       options |= WUNTRACED;
+       list_for_each_entry(p, &tsk->ptraced, ptrace_entry) {
+               int ret = wait_consider_task(tsk, 1, p, notask_error,
+                                            type, pid, options,
+                                            infop, stat_addr, ru);
+               if (ret)
+                       return ret;
+       }
+       return 0;
+ }
  static long do_wait(enum pid_type type, struct pid *pid, int options,
                    struct siginfo __user *infop, int __user *stat_addr,
                    struct rusage __user *ru)
  {
        DECLARE_WAITQUEUE(wait, current);
        struct task_struct *tsk;
-       int flag, retval;
+       int retval;
  
        add_wait_queue(&current->signal->wait_chldexit,&wait);
  repeat:
-       /* If there is nothing that can match our critier just get out */
+       /*
+        * If there is nothing that can match our critiera just get out.
+        * We will clear @retval to zero if we see any child that might later
+        * match our criteria, even if we are not able to reap it yet.
+        */
        retval = -ECHILD;
        if ((type < PIDTYPE_MAX) && (!pid || hlist_empty(&pid->tasks[type])))
                goto end;
  
-       /*
-        * We will set this flag if we see any child that might later
-        * match our criteria, even if we are not able to reap it yet.
-        */
-       flag = retval = 0;
        current->state = TASK_INTERRUPTIBLE;
        read_lock(&tasklist_lock);
        tsk = current;
        do {
-               struct task_struct *p;
-               list_for_each_entry(p, &tsk->children, sibling) {
-                       int ret = eligible_child(type, pid, options, p);
-                       if (!ret)
-                               continue;
-                       if (unlikely(ret < 0)) {
-                               retval = ret;
-                       } else if (task_is_stopped_or_traced(p)) {
-                               /*
-                                * It's stopped now, so it might later
-                                * continue, exit, or stop again.
-                                */
-                               flag = 1;
-                               if (!(p->ptrace & PT_PTRACED) &&
-                                   !(options & WUNTRACED))
-                                       continue;
-                               retval = wait_task_stopped(p,
-                                               (options & WNOWAIT), infop,
-                                               stat_addr, ru);
-                       } else if (p->exit_state == EXIT_ZOMBIE &&
-                                       !delay_group_leader(p)) {
-                               /*
-                                * We don't reap group leaders with subthreads.
-                                */
-                               if (!likely(options & WEXITED))
-                                       continue;
-                               retval = wait_task_zombie(p,
-                                               (options & WNOWAIT), infop,
-                                               stat_addr, ru);
-                       } else if (p->exit_state != EXIT_DEAD) {
-                               /*
-                                * It's running now, so it might later
-                                * exit, stop, or stop and then continue.
-                                */
-                               flag = 1;
-                               if (!unlikely(options & WCONTINUED))
-                                       continue;
-                               retval = wait_task_continued(p,
-                                               (options & WNOWAIT), infop,
-                                               stat_addr, ru);
-                       }
-                       if (retval != 0) /* tasklist_lock released */
-                               goto end;
-               }
-               if (!flag) {
-                       list_for_each_entry(p, &tsk->ptrace_children,
-                                                               ptrace_list) {
-                               flag = eligible_child(type, pid, options, p);
-                               if (!flag)
-                                       continue;
-                               if (likely(flag > 0))
-                                       break;
-                               retval = flag;
-                               goto end;
-                       }
+               int tsk_result = do_wait_thread(tsk, &retval,
+                                               type, pid, options,
+                                               infop, stat_addr, ru);
+               if (!tsk_result)
+                       tsk_result = ptrace_do_wait(tsk, &retval,
+                                                   type, pid, options,
+                                                   infop, stat_addr, ru);
+               if (tsk_result) {
+                       /*
+                        * tasklist_lock is unlocked and we have a final result.
+                        */
+                       retval = tsk_result;
+                       goto end;
                }
                if (options & __WNOTHREAD)
                        break;
                tsk = next_thread(tsk);
        } while (tsk != current);
        read_unlock(&tasklist_lock);
  
-       if (flag) {
-               if (options & WNOHANG)
-                       goto end;
+       if (!retval && !(options & WNOHANG)) {
                retval = -ERESTARTSYS;
-               if (signal_pending(current))
-                       goto end;
-               schedule();
-               goto repeat;
+               if (!signal_pending(current)) {
+                       schedule();
+                       goto repeat;
+               }
        }
-       retval = -ECHILD;
  end:
        current->state = TASK_RUNNING;
        remove_wait_queue(&current->signal->wait_chldexit,&wait);
diff --combined kernel/fork.c
  #include <linux/sem.h>
  #include <linux/file.h>
  #include <linux/fdtable.h>
+ #include <linux/iocontext.h>
  #include <linux/key.h>
  #include <linux/binfmts.h>
  #include <linux/mman.h>
+ #include <linux/mmu_notifier.h>
  #include <linux/fs.h>
  #include <linux/nsproxy.h>
  #include <linux/capability.h>
  #include <linux/cpu.h>
  #include <linux/cgroup.h>
  #include <linux/security.h>
+ #include <linux/hugetlb.h>
  #include <linux/swap.h>
  #include <linux/syscalls.h>
  #include <linux/jiffies.h>
+ #include <linux/tracehook.h>
  #include <linux/futex.h>
  #include <linux/task_io_accounting_ops.h>
  #include <linux/rcupdate.h>
@@@ -54,7 -58,6 +58,7 @@@
  #include <linux/tty.h>
  #include <linux/proc_fs.h>
  #include <linux/blkdev.h>
 +#include <linux/magic.h>
  
  #include <asm/pgtable.h>
  #include <asm/pgalloc.h>
@@@ -92,6 -95,23 +96,23 @@@ int nr_processes(void
  static struct kmem_cache *task_struct_cachep;
  #endif
  
+ #ifndef __HAVE_ARCH_THREAD_INFO_ALLOCATOR
+ static inline struct thread_info *alloc_thread_info(struct task_struct *tsk)
+ {
+ #ifdef CONFIG_DEBUG_STACK_USAGE
+       gfp_t mask = GFP_KERNEL | __GFP_ZERO;
+ #else
+       gfp_t mask = GFP_KERNEL;
+ #endif
+       return (struct thread_info *)__get_free_pages(mask, THREAD_SIZE_ORDER);
+ }
+ static inline void free_thread_info(struct thread_info *ti)
+ {
+       free_pages((unsigned long)ti, THREAD_SIZE_ORDER);
+ }
+ #endif
  /* SLAB cache for signal_struct structures (tsk->signal) */
  static struct kmem_cache *signal_cachep;
  
@@@ -187,8 -207,6 +208,8 @@@ static struct task_struct *dup_task_str
  {
        struct task_struct *tsk;
        struct thread_info *ti;
 +      unsigned long *stackend;
 +
        int err;
  
        prepare_to_copy(orig);
                goto out;
  
        setup_thread_stack(tsk, orig);
 +      stackend = end_of_stack(tsk);
 +      *stackend = STACK_END_MAGIC;    /* for overflow detection */
  
  #ifdef CONFIG_CC_STACKPROTECTOR
        tsk->stack_canary = get_random_int();
@@@ -310,6 -326,14 +331,14 @@@ static int dup_mmap(struct mm_struct *m
                        spin_unlock(&file->f_mapping->i_mmap_lock);
                }
  
+               /*
+                * Clear hugetlb-related page reserves for children. This only
+                * affects MAP_PRIVATE mappings. Faults generated by the child
+                * are not guaranteed to succeed, even if read-only
+                */
+               if (is_vm_hugetlb_page(tmp))
+                       reset_vma_resv_huge_pages(tmp);
                /*
                 * Link in the new vma and copy the page table entries.
                 */
@@@ -378,7 -402,7 +407,7 @@@ static struct mm_struct * mm_init(struc
        INIT_LIST_HEAD(&mm->mmlist);
        mm->flags = (current->mm) ? current->mm->flags
                                  : MMF_DUMP_FILTER_DEFAULT;
-       mm->core_waiters = 0;
+       mm->core_state = NULL;
        mm->nr_ptes = 0;
        set_mm_counter(mm, file_rss, 0);
        set_mm_counter(mm, anon_rss, 0);
  
        if (likely(!mm_alloc_pgd(mm))) {
                mm->def_flags = 0;
+               mmu_notifier_mm_init(mm);
                return mm;
        }
  
@@@ -423,6 -448,7 +453,7 @@@ void __mmdrop(struct mm_struct *mm
        BUG_ON(mm == &init_mm);
        mm_free_pgd(mm);
        destroy_context(mm);
+       mmu_notifier_mm_destroy(mm);
        free_mm(mm);
  }
  EXPORT_SYMBOL_GPL(__mmdrop);
@@@ -452,7 -478,7 +483,7 @@@ EXPORT_SYMBOL_GPL(mmput)
  /**
   * get_task_mm - acquire a reference to the task's mm
   *
-  * Returns %NULL if the task has no mm.  Checks PF_BORROWED_MM (meaning
+  * Returns %NULL if the task has no mm.  Checks PF_KTHREAD (meaning
   * this kernel workthread has transiently adopted a user mm with use_mm,
   * to do its AIO) is not set and if so returns a reference to it, after
   * bumping up the use count.  User must release the mm via mmput()
@@@ -465,7 -491,7 +496,7 @@@ struct mm_struct *get_task_mm(struct ta
        task_lock(task);
        mm = task->mm;
        if (mm) {
-               if (task->flags & PF_BORROWED_MM)
+               if (task->flags & PF_KTHREAD)
                        mm = NULL;
                else
                        atomic_inc(&mm->mm_users);
@@@ -634,13 -660,6 +665,6 @@@ static struct fs_struct *__copy_fs_stru
                path_get(&old->root);
                fs->pwd = old->pwd;
                path_get(&old->pwd);
-               if (old->altroot.dentry) {
-                       fs->altroot = old->altroot;
-                       path_get(&old->altroot);
-               } else {
-                       fs->altroot.mnt = NULL;
-                       fs->altroot.dentry = NULL;
-               }
                read_unlock(&old->lock);
        }
        return fs;
@@@ -783,6 -802,7 +807,7 @@@ static int copy_signal(unsigned long cl
  
        sig->leader = 0;        /* session leadership doesn't inherit */
        sig->tty_old_pgrp = NULL;
+       sig->tty = NULL;
  
        sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero;
        sig->gtime = cputime_zero;
        sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0;
        sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0;
        sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0;
+       task_io_accounting_init(&sig->ioac);
        sig->sum_sched_runtime = 0;
        INIT_LIST_HEAD(&sig->cpu_timers[0]);
        INIT_LIST_HEAD(&sig->cpu_timers[1]);
  void __cleanup_signal(struct signal_struct *sig)
  {
        exit_thread_group_keys(sig);
+       tty_kref_put(sig->tty);
        kmem_cache_free(signal_cachep, sig);
  }
  
@@@ -837,8 -859,7 +864,7 @@@ static void copy_flags(unsigned long cl
  
        new_flags &= ~PF_SUPERPRIV;
        new_flags |= PF_FORKNOEXEC;
-       if (!(clone_flags & CLONE_PTRACE))
-               p->ptrace = 0;
+       new_flags |= PF_STARTING;
        p->flags = new_flags;
        clear_freeze_flag(p);
  }
@@@ -879,7 -900,8 +905,8 @@@ static struct task_struct *copy_process
                                        struct pt_regs *regs,
                                        unsigned long stack_size,
                                        int __user *child_tidptr,
-                                       struct pid *pid)
+                                       struct pid *pid,
+                                       int trace)
  {
        int retval;
        struct task_struct *p;
  
        rt_mutex_init_task(p);
  
- #ifdef CONFIG_TRACE_IRQFLAGS
+ #ifdef CONFIG_PROVE_LOCKING
        DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
        DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
  #endif
        p->last_switch_timestamp = 0;
  #endif
  
- #ifdef CONFIG_TASK_XACCT
-       p->rchar = 0;           /* I/O counter: bytes read */
-       p->wchar = 0;           /* I/O counter: bytes written */
-       p->syscr = 0;           /* I/O counter: read syscalls */
-       p->syscw = 0;           /* I/O counter: write syscalls */
- #endif
-       task_io_accounting_init(p);
+       task_io_accounting_init(&p->ioac);
        acct_clear_integrals(p);
  
        p->it_virt_expires = cputime_zero;
        if (clone_flags & CLONE_THREAD)
                p->tgid = current->tgid;
  
+       if (current->nsproxy != p->nsproxy) {
+               retval = ns_cgroup_clone(p, pid);
+               if (retval)
+                       goto bad_fork_free_pid;
+       }
        p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
        /*
         * Clear TID on mm_release()?
         */
        p->group_leader = p;
        INIT_LIST_HEAD(&p->thread_group);
-       INIT_LIST_HEAD(&p->ptrace_children);
-       INIT_LIST_HEAD(&p->ptrace_list);
  
        /* Now that the task is set up, run cgroup callbacks if
         * necessary. We need to run them before the task is visible
                p->real_parent = current->real_parent;
        else
                p->real_parent = current;
-       p->parent = p->real_parent;
  
        spin_lock(&current->sighand->siglock);
  
        }
  
        if (likely(p->pid)) {
-               add_parent(p);
-               if (unlikely(p->ptrace & PT_PTRACED))
-                       __ptrace_link(p, current->parent);
+               list_add_tail(&p->sibling, &p->real_parent->children);
+               tracehook_finish_clone(p, clone_flags, trace);
  
                if (thread_group_leader(p)) {
                        if (clone_flags & CLONE_NEWPID)
                                p->nsproxy->pid_ns->child_reaper = p;
  
                        p->signal->leader_pid = pid;
-                       p->signal->tty = current->signal->tty;
+                       tty_kref_put(p->signal->tty);
+                       p->signal->tty = tty_kref_get(current->signal->tty);
                        set_task_pgrp(p, task_pgrp_nr(current));
                        set_task_session(p, task_session_nr(current));
                        attach_pid(p, PIDTYPE_PGID, task_pgrp(current));
@@@ -1289,29 -1308,13 +1313,13 @@@ struct task_struct * __cpuinit fork_idl
        struct pt_regs regs;
  
        task = copy_process(CLONE_VM, 0, idle_regs(&regs), 0, NULL,
-                               &init_struct_pid);
+                           &init_struct_pid, 0);
        if (!IS_ERR(task))
                init_idle(task, cpu);
  
        return task;
  }
  
- static int fork_traceflag(unsigned clone_flags)
- {
-       if (clone_flags & CLONE_UNTRACED)
-               return 0;
-       else if (clone_flags & CLONE_VFORK) {
-               if (current->ptrace & PT_TRACE_VFORK)
-                       return PTRACE_EVENT_VFORK;
-       } else if ((clone_flags & CSIGNAL) != SIGCHLD) {
-               if (current->ptrace & PT_TRACE_CLONE)
-                       return PTRACE_EVENT_CLONE;
-       } else if (current->ptrace & PT_TRACE_FORK)
-               return PTRACE_EVENT_FORK;
-       return 0;
- }
  /*
   *  Ok, this is the main fork-routine.
   *
@@@ -1346,14 -1349,14 +1354,14 @@@ long do_fork(unsigned long clone_flags
                }
        }
  
-       if (unlikely(current->ptrace)) {
-               trace = fork_traceflag (clone_flags);
-               if (trace)
-                       clone_flags |= CLONE_PTRACE;
-       }
+       /*
+        * When called from kernel_thread, don't do user tracing stuff.
+        */
+       if (likely(user_mode(regs)))
+               trace = tracehook_prepare_clone(clone_flags);
  
        p = copy_process(clone_flags, stack_start, regs, stack_size,
-                       child_tidptr, NULL);
+                        child_tidptr, NULL, trace);
        /*
         * Do this prior waking up the new thread - the thread pointer
         * might get invalid after that point, if the thread exits quickly.
                        init_completion(&vfork);
                }
  
-               if ((p->ptrace & PT_PTRACED) || (clone_flags & CLONE_STOPPED)) {
+               tracehook_report_clone(trace, regs, clone_flags, nr, p);
+               /*
+                * We set PF_STARTING at creation in case tracing wants to
+                * use this to distinguish a fully live task from one that
+                * hasn't gotten to tracehook_report_clone() yet.  Now we
+                * clear it and set the child going.
+                */
+               p->flags &= ~PF_STARTING;
+               if (unlikely(clone_flags & CLONE_STOPPED)) {
                        /*
                         * We'll start up with an immediate SIGSTOP.
                         */
                        sigaddset(&p->pending.signal, SIGSTOP);
                        set_tsk_thread_flag(p, TIF_SIGPENDING);
-               }
-               if (!(clone_flags & CLONE_STOPPED))
-                       wake_up_new_task(p, clone_flags);
-               else
                        __set_task_state(p, TASK_STOPPED);
-               if (unlikely (trace)) {
-                       current->ptrace_message = nr;
-                       ptrace_notify ((trace << 8) | SIGTRAP);
+               } else {
+                       wake_up_new_task(p, clone_flags);
                }
  
+               tracehook_report_clone_complete(trace, regs,
+                                               clone_flags, nr, p);
                if (clone_flags & CLONE_VFORK) {
                        freezer_do_not_count();
                        wait_for_completion(&vfork);
                        freezer_count();
-                       if (unlikely (current->ptrace & PT_TRACE_VFORK_DONE)) {
-                               current->ptrace_message = nr;
-                               ptrace_notify ((PTRACE_EVENT_VFORK_DONE << 8) | SIGTRAP);
-                       }
+                       tracehook_report_vfork_done(p, nr);
                }
        } else {
                nr = PTR_ERR(p);
  #define ARCH_MIN_MMSTRUCT_ALIGN 0
  #endif
  
- static void sighand_ctor(struct kmem_cache *cachep, void *data)
+ static void sighand_ctor(void *data)
  {
        struct sighand_struct *sighand = data;
  
diff --combined kernel/panic.c
@@@ -80,9 -80,6 +80,9 @@@ NORET_TYPE void panic(const char * fmt
        vsnprintf(buf, sizeof(buf), fmt, args);
        va_end(args);
        printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
 +#ifdef CONFIG_DEBUG_BUGVERBOSE
 +      dump_stack();
 +#endif
        bust_spinlocks(0);
  
        /*
@@@ -321,23 -318,38 +321,45 @@@ void warn_on_slowpath(const char *file
        add_taint(TAINT_WARN);
  }
  EXPORT_SYMBOL(warn_on_slowpath);
+ void warn_slowpath(const char *file, int line, const char *fmt, ...)
+ {
+       va_list args;
+       char function[KSYM_SYMBOL_LEN];
+       unsigned long caller = (unsigned long)__builtin_return_address(0);
+       sprint_symbol(function, caller);
+       printk(KERN_WARNING "------------[ cut here ]------------\n");
+       printk(KERN_WARNING "WARNING: at %s:%d %s()\n", file,
+               line, function);
+       va_start(args, fmt);
+       vprintk(fmt, args);
+       va_end(args);
+       print_modules();
+       dump_stack();
+       print_oops_end_marker();
+       add_taint(TAINT_WARN);
+ }
+ EXPORT_SYMBOL(warn_slowpath);
  #endif
  
  #ifdef CONFIG_CC_STACKPROTECTOR
 +
 +#ifndef GCC_HAS_SP
 +#warning You have selected the CONFIG_CC_STACKPROTECTOR option, but the gcc used does not support this.
 +#endif
 +
  /*
   * Called when gcc's -fstack-protector feature is used, and
   * gcc detects corruption of the on-stack canary value
   */
  void __stack_chk_fail(void)
  {
 -      panic("stack-protector: Kernel stack is corrupted");
 +      panic("stack-protector: Kernel stack is corrupted in: %p\n",
 +              __builtin_return_address(0));
  }
  EXPORT_SYMBOL(__stack_chk_fail);
 +
  #endif
diff --combined kernel/sched.c
  #include <linux/bootmem.h>
  #include <linux/debugfs.h>
  #include <linux/ctype.h>
+ #include <linux/ftrace.h>
  
  #include <asm/tlb.h>
  #include <asm/irq_regs.h>
  
+ #include "sched_cpupri.h"
  /*
   * Convert user-nice values [ -20 ... 0 ... 19 ]
   * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
@@@ -198,14 -201,19 +201,19 @@@ void init_rt_bandwidth(struct rt_bandwi
        hrtimer_init(&rt_b->rt_period_timer,
                        CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        rt_b->rt_period_timer.function = sched_rt_period_timer;
-       rt_b->rt_period_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ;
+       rt_b->rt_period_timer.cb_mode = HRTIMER_CB_IRQSAFE_UNLOCKED;
+ }
+ static inline int rt_bandwidth_enabled(void)
+ {
+       return sysctl_sched_rt_runtime >= 0;
  }
  
  static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
  {
        ktime_t now;
  
-       if (rt_b->rt_runtime == RUNTIME_INF)
+       if (rt_bandwidth_enabled() && rt_b->rt_runtime == RUNTIME_INF)
                return;
  
        if (hrtimer_active(&rt_b->rt_period_timer))
@@@ -289,15 -297,15 +297,15 @@@ struct task_group root_task_group
  static DEFINE_PER_CPU(struct sched_entity, init_sched_entity);
  /* Default task group's cfs_rq on each cpu */
  static DEFINE_PER_CPU(struct cfs_rq, init_cfs_rq) ____cacheline_aligned_in_smp;
- #endif
+ #endif /* CONFIG_FAIR_GROUP_SCHED */
  
  #ifdef CONFIG_RT_GROUP_SCHED
  static DEFINE_PER_CPU(struct sched_rt_entity, init_sched_rt_entity);
  static DEFINE_PER_CPU(struct rt_rq, init_rt_rq) ____cacheline_aligned_in_smp;
- #endif
- #else
+ #endif /* CONFIG_RT_GROUP_SCHED */
+ #else /* !CONFIG_USER_SCHED */
  #define root_task_group init_task_group
- #endif
+ #endif /* CONFIG_USER_SCHED */
  
  /* task_group_lock serializes add/remove of task groups and also changes to
   * a task group's cpu shares.
@@@ -307,9 -315,9 +315,9 @@@ static DEFINE_SPINLOCK(task_group_lock)
  #ifdef CONFIG_FAIR_GROUP_SCHED
  #ifdef CONFIG_USER_SCHED
  # define INIT_TASK_GROUP_LOAD (2*NICE_0_LOAD)
- #else
+ #else /* !CONFIG_USER_SCHED */
  # define INIT_TASK_GROUP_LOAD NICE_0_LOAD
- #endif
+ #endif /* CONFIG_USER_SCHED */
  
  /*
   * A weight of 0 or 1 can cause arithmetics problems.
@@@ -363,6 -371,10 +371,10 @@@ static inline void set_task_rq(struct t
  #else
  
  static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { }
+ static inline struct task_group *task_group(struct task_struct *p)
+ {
+       return NULL;
+ }
  
  #endif        /* CONFIG_GROUP_SCHED */
  
@@@ -373,6 -385,7 +385,7 @@@ struct cfs_rq 
  
        u64 exec_clock;
        u64 min_vruntime;
+       u64 pair_start;
  
        struct rb_root tasks_timeline;
        struct rb_node *rb_leftmost;
         */
        struct list_head leaf_cfs_rq_list;
        struct task_group *tg;  /* group that "owns" this runqueue */
+ #ifdef CONFIG_SMP
+       /*
+        * the part of load.weight contributed by tasks
+        */
+       unsigned long task_weight;
+       /*
+        *   h_load = weight * f(tg)
+        *
+        * Where f(tg) is the recursive weight fraction assigned to
+        * this group.
+        */
+       unsigned long h_load;
+       /*
+        * this cpu's part of tg->shares
+        */
+       unsigned long shares;
+       /*
+        * load.weight at the time we set shares
+        */
+       unsigned long rq_weight;
+ #endif
  #endif
  };
  
@@@ -452,6 -490,9 +490,9 @@@ struct root_domain 
         */
        cpumask_t rto_mask;
        atomic_t rto_count;
+ #ifdef CONFIG_SMP
+       struct cpupri cpupri;
+ #endif
  };
  
  /*
@@@ -526,14 -567,19 +567,19 @@@ struct rq 
        int push_cpu;
        /* cpu of this runqueue: */
        int cpu;
+       int online;
+       unsigned long avg_load_per_task;
  
        struct task_struct *migration_thread;
        struct list_head migration_queue;
  #endif
  
  #ifdef CONFIG_SCHED_HRTICK
-       unsigned long hrtick_flags;
-       ktime_t hrtick_expire;
+ #ifdef CONFIG_SMP
+       int hrtick_csd_pending;
+       struct call_single_data hrtick_csd;
+ #endif
        struct hrtimer hrtick_timer;
  #endif
  
        /* BKL stats */
        unsigned int bkl_count;
  #endif
-       struct lock_class_key rq_lock_key;
  };
  
  static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
  
- static inline void check_preempt_curr(struct rq *rq, struct task_struct *p)
+ static inline void check_preempt_curr(struct rq *rq, struct task_struct *p, int sync)
  {
-       rq->curr->sched_class->check_preempt_curr(rq, p);
+       rq->curr->sched_class->check_preempt_curr(rq, p, sync);
  }
  
  static inline int cpu_of(struct rq *rq)
@@@ -607,6 -652,24 +652,24 @@@ static inline void update_rq_clock(stru
  # define const_debug static const
  #endif
  
+ /**
+  * runqueue_is_locked
+  *
+  * Returns true if the current cpu runqueue is locked.
+  * This interface allows printk to be called with the runqueue lock
+  * held and know whether or not it is OK to wake up the klogd.
+  */
+ int runqueue_is_locked(void)
+ {
+       int cpu = get_cpu();
+       struct rq *rq = cpu_rq(cpu);
+       int ret;
+       ret = spin_is_locked(&rq->lock);
+       put_cpu();
+       return ret;
+ }
  /*
   * Debugging: various feature bits
   */
@@@ -748,6 -811,12 +811,12 @@@ late_initcall(sched_init_debug)
   */
  const_debug unsigned int sysctl_sched_nr_migrate = 32;
  
+ /*
+  * ratelimit for updating the group shares.
+  * default: 0.25ms
+  */
+ unsigned int sysctl_sched_shares_ratelimit = 250000;
  /*
   * period over which we measure -rt task cpu usage in us.
   * default: 1s
@@@ -769,88 -838,12 +838,12 @@@ static inline u64 global_rt_period(void
  
  static inline u64 global_rt_runtime(void)
  {
-       if (sysctl_sched_rt_period < 0)
+       if (sysctl_sched_rt_runtime < 0)
                return RUNTIME_INF;
  
        return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC;
  }
  
- unsigned long long time_sync_thresh = 100000;
- static DEFINE_PER_CPU(unsigned long long, time_offset);
- static DEFINE_PER_CPU(unsigned long long, prev_cpu_time);
- /*
-  * Global lock which we take every now and then to synchronize
-  * the CPUs time. This method is not warp-safe, but it's good
-  * enough to synchronize slowly diverging time sources and thus
-  * it's good enough for tracing:
-  */
- static DEFINE_SPINLOCK(time_sync_lock);
- static unsigned long long prev_global_time;
- static unsigned long long __sync_cpu_clock(unsigned long long time, int cpu)
- {
-       /*
-        * We want this inlined, to not get tracer function calls
-        * in this critical section:
-        */
-       spin_acquire(&time_sync_lock.dep_map, 0, 0, _THIS_IP_);
-       __raw_spin_lock(&time_sync_lock.raw_lock);
-       if (time < prev_global_time) {
-               per_cpu(time_offset, cpu) += prev_global_time - time;
-               time = prev_global_time;
-       } else {
-               prev_global_time = time;
-       }
-       __raw_spin_unlock(&time_sync_lock.raw_lock);
-       spin_release(&time_sync_lock.dep_map, 1, _THIS_IP_);
-       return time;
- }
- static unsigned long long __cpu_clock(int cpu)
- {
-       unsigned long long now;
-       /*
-        * Only call sched_clock() if the scheduler has already been
-        * initialized (some code might call cpu_clock() very early):
-        */
-       if (unlikely(!scheduler_running))
-               return 0;
-       now = sched_clock_cpu(cpu);
-       return now;
- }
- /*
-  * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
-  * clock constructed from sched_clock():
-  */
- unsigned long long cpu_clock(int cpu)
- {
-       unsigned long long prev_cpu_time, time, delta_time;
-       unsigned long flags;
-       local_irq_save(flags);
-       prev_cpu_time = per_cpu(prev_cpu_time, cpu);
-       time = __cpu_clock(cpu) + per_cpu(time_offset, cpu);
-       delta_time = time-prev_cpu_time;
-       if (unlikely(delta_time > time_sync_thresh)) {
-               time = __sync_cpu_clock(time, cpu);
-               per_cpu(prev_cpu_time, cpu) = time;
-       }
-       local_irq_restore(flags);
-       return time;
- }
- EXPORT_SYMBOL_GPL(cpu_clock);
  #ifndef prepare_arch_switch
  # define prepare_arch_switch(next)    do { } while (0)
  #endif
@@@ -996,13 -989,6 +989,6 @@@ static struct rq *this_rq_lock(void
        return rq;
  }
  
- static void __resched_task(struct task_struct *p, int tif_bit);
- static inline void resched_task(struct task_struct *p)
- {
-       __resched_task(p, TIF_NEED_RESCHED);
- }
  #ifdef CONFIG_SCHED_HRTICK
  /*
   * Use HR-timers to deliver accurate preemption points.
   * When we get rescheduled we reprogram the hrtick_timer outside of the
   * rq->lock.
   */
- static inline void resched_hrt(struct task_struct *p)
- {
-       __resched_task(p, TIF_HRTICK_RESCHED);
- }
- static inline void resched_rq(struct rq *rq)
- {
-       unsigned long flags;
-       spin_lock_irqsave(&rq->lock, flags);
-       resched_task(rq->curr);
-       spin_unlock_irqrestore(&rq->lock, flags);
- }
- enum {
-       HRTICK_SET,             /* re-programm hrtick_timer */
-       HRTICK_RESET,           /* not a new slice */
-       HRTICK_BLOCK,           /* stop hrtick operations */
- };
  
  /*
   * Use hrtick when:
@@@ -1043,72 -1010,17 +1010,17 @@@ static inline int hrtick_enabled(struc
  {
        if (!sched_feat(HRTICK))
                return 0;
-       if (unlikely(test_bit(HRTICK_BLOCK, &rq->hrtick_flags)))
+       if (!cpu_active(cpu_of(rq)))
                return 0;
        return hrtimer_is_hres_active(&rq->hrtick_timer);
  }
  
- /*
-  * Called to set the hrtick timer state.
-  *
-  * called with rq->lock held and irqs disabled
-  */
- static void hrtick_start(struct rq *rq, u64 delay, int reset)
- {
-       assert_spin_locked(&rq->lock);
-       /*
-        * preempt at: now + delay
-        */
-       rq->hrtick_expire =
-               ktime_add_ns(rq->hrtick_timer.base->get_time(), delay);
-       /*
-        * indicate we need to program the timer
-        */
-       __set_bit(HRTICK_SET, &rq->hrtick_flags);
-       if (reset)
-               __set_bit(HRTICK_RESET, &rq->hrtick_flags);
-       /*
-        * New slices are called from the schedule path and don't need a
-        * forced reschedule.
-        */
-       if (reset)
-               resched_hrt(rq->curr);
- }
  static void hrtick_clear(struct rq *rq)
  {
        if (hrtimer_active(&rq->hrtick_timer))
                hrtimer_cancel(&rq->hrtick_timer);
  }
  
- /*
-  * Update the timer from the possible pending state.
-  */
- static void hrtick_set(struct rq *rq)
- {
-       ktime_t time;
-       int set, reset;
-       unsigned long flags;
-       WARN_ON_ONCE(cpu_of(rq) != smp_processor_id());
-       spin_lock_irqsave(&rq->lock, flags);
-       set = __test_and_clear_bit(HRTICK_SET, &rq->hrtick_flags);
-       reset = __test_and_clear_bit(HRTICK_RESET, &rq->hrtick_flags);
-       time = rq->hrtick_expire;
-       clear_thread_flag(TIF_HRTICK_RESCHED);
-       spin_unlock_irqrestore(&rq->lock, flags);
-       if (set) {
-               hrtimer_start(&rq->hrtick_timer, time, HRTIMER_MODE_ABS);
-               if (reset && !hrtimer_active(&rq->hrtick_timer))
-                       resched_rq(rq);
-       } else
-               hrtick_clear(rq);
- }
  /*
   * High-resolution timer tick.
   * Runs from hardirq context with interrupts disabled.
@@@ -1128,27 -1040,37 +1040,37 @@@ static enum hrtimer_restart hrtick(stru
  }
  
  #ifdef CONFIG_SMP
- static void hotplug_hrtick_disable(int cpu)
+ /*
+  * called from hardirq (IPI) context
+  */
+ static void __hrtick_start(void *arg)
  {
-       struct rq *rq = cpu_rq(cpu);
-       unsigned long flags;
-       spin_lock_irqsave(&rq->lock, flags);
-       rq->hrtick_flags = 0;
-       __set_bit(HRTICK_BLOCK, &rq->hrtick_flags);
-       spin_unlock_irqrestore(&rq->lock, flags);
+       struct rq *rq = arg;
  
-       hrtick_clear(rq);
+       spin_lock(&rq->lock);
+       hrtimer_restart(&rq->hrtick_timer);
+       rq->hrtick_csd_pending = 0;
+       spin_unlock(&rq->lock);
  }
  
- static void hotplug_hrtick_enable(int cpu)
+ /*
+  * Called to set the hrtick timer state.
+  *
+  * called with rq->lock held and irqs disabled
+  */
+ static void hrtick_start(struct rq *rq, u64 delay)
  {
-       struct rq *rq = cpu_rq(cpu);
-       unsigned long flags;
+       struct hrtimer *timer = &rq->hrtick_timer;
+       ktime_t time = ktime_add_ns(timer->base->get_time(), delay);
  
-       spin_lock_irqsave(&rq->lock, flags);
-       __clear_bit(HRTICK_BLOCK, &rq->hrtick_flags);
-       spin_unlock_irqrestore(&rq->lock, flags);
+       timer->expires = time;
+       if (rq == this_rq()) {
+               hrtimer_restart(timer);
+       } else if (!rq->hrtick_csd_pending) {
+               __smp_call_function_single(cpu_of(rq), &rq->hrtick_csd);
+               rq->hrtick_csd_pending = 1;
+       }
  }
  
  static int
@@@ -1163,70 -1085,60 +1085,60 @@@ hotplug_hrtick(struct notifier_block *n
        case CPU_DOWN_PREPARE_FROZEN:
        case CPU_DEAD:
        case CPU_DEAD_FROZEN:
-               hotplug_hrtick_disable(cpu);
-               return NOTIFY_OK;
-       case CPU_UP_PREPARE:
-       case CPU_UP_PREPARE_FROZEN:
-       case CPU_DOWN_FAILED:
-       case CPU_DOWN_FAILED_FROZEN:
-       case CPU_ONLINE:
-       case CPU_ONLINE_FROZEN:
-               hotplug_hrtick_enable(cpu);
+               hrtick_clear(cpu_rq(cpu));
                return NOTIFY_OK;
        }
  
        return NOTIFY_DONE;
  }
  
- static void init_hrtick(void)
+ static __init void init_hrtick(void)
  {
        hotcpu_notifier(hotplug_hrtick, 0);
  }
- #endif /* CONFIG_SMP */
+ #else
+ /*
+  * Called to set the hrtick timer state.
+  *
+  * called with rq->lock held and irqs disabled
+  */
+ static void hrtick_start(struct rq *rq, u64 delay)
+ {
+       hrtimer_start(&rq->hrtick_timer, ns_to_ktime(delay), HRTIMER_MODE_REL);
+ }
  
- static void init_rq_hrtick(struct rq *rq)
+ static inline void init_hrtick(void)
  {
-       rq->hrtick_flags = 0;
-       hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-       rq->hrtick_timer.function = hrtick;
-       rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ;
  }
+ #endif /* CONFIG_SMP */
  
void hrtick_resched(void)
static void init_rq_hrtick(struct rq *rq)
  {
-       struct rq *rq;
-       unsigned long flags;
+ #ifdef CONFIG_SMP
+       rq->hrtick_csd_pending = 0;
  
-       if (!test_thread_flag(TIF_HRTICK_RESCHED))
-               return;
+       rq->hrtick_csd.flags = 0;
+       rq->hrtick_csd.func = __hrtick_start;
+       rq->hrtick_csd.info = rq;
+ #endif
  
-       local_irq_save(flags);
-       rq = cpu_rq(smp_processor_id());
-       hrtick_set(rq);
-       local_irq_restore(flags);
+       hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+       rq->hrtick_timer.function = hrtick;
+       rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_PERCPU;
  }
- #else
+ #else /* CONFIG_SCHED_HRTICK */
  static inline void hrtick_clear(struct rq *rq)
  {
  }
  
- static inline void hrtick_set(struct rq *rq)
- {
- }
  static inline void init_rq_hrtick(struct rq *rq)
  {
  }
  
- void hrtick_resched(void)
- {
- }
  static inline void init_hrtick(void)
  {
  }
- #endif
+ #endif        /* CONFIG_SCHED_HRTICK */
  
  /*
   * resched_task - mark a task 'to be rescheduled now'.
  #define tsk_is_polling(t) test_tsk_thread_flag(t, TIF_POLLING_NRFLAG)
  #endif
  
- static void __resched_task(struct task_struct *p, int tif_bit)
+ static void resched_task(struct task_struct *p)
  {
        int cpu;
  
        assert_spin_locked(&task_rq(p)->lock);
  
-       if (unlikely(test_tsk_thread_flag(p, tif_bit)))
+       if (unlikely(test_tsk_thread_flag(p, TIF_NEED_RESCHED)))
                return;
  
-       set_tsk_thread_flag(p, tif_bit);
+       set_tsk_thread_flag(p, TIF_NEED_RESCHED);
  
        cpu = task_cpu(p);
        if (cpu == smp_processor_id())
@@@ -1313,15 -1225,15 +1225,15 @@@ void wake_up_idle_cpu(int cpu
        if (!tsk_is_polling(rq->idle))
                smp_send_reschedule(cpu);
  }
- #endif
+ #endif /* CONFIG_NO_HZ */
  
- #else
- static void __resched_task(struct task_struct *p, int tif_bit)
+ #else /* !CONFIG_SMP */
+ static void resched_task(struct task_struct *p)
  {
        assert_spin_locked(&task_rq(p)->lock);
-       set_tsk_thread_flag(p, tif_bit);
+       set_tsk_need_resched(p);
  }
- #endif
+ #endif /* CONFIG_SMP */
  
  #if BITS_PER_LONG == 32
  # define WMULT_CONST  (~0UL)
   */
  #define SRR(x, y) (((x) + (1UL << ((y) - 1))) >> (y))
  
+ /*
+  * delta *= weight / lw
+  */
  static unsigned long
  calc_delta_mine(unsigned long delta_exec, unsigned long weight,
                struct load_weight *lw)
        return (unsigned long)min(tmp, (u64)(unsigned long)LONG_MAX);
  }
  
- static inline unsigned long
- calc_delta_fair(unsigned long delta_exec, struct load_weight *lw)
- {
-       return calc_delta_mine(delta_exec, NICE_0_LOAD, lw);
- }
  static inline void update_load_add(struct load_weight *lw, unsigned long inc)
  {
        lw->weight += inc;
@@@ -1447,50 -1356,257 +1356,257 @@@ struct rq_iterator 
        struct task_struct *(*next)(void *);
  };
  
- #ifdef CONFIG_SMP
- static unsigned long
- balance_tasks(struct rq *this_rq, int this_cpu, struct rq *busiest,
-             unsigned long max_load_move, struct sched_domain *sd,
-             enum cpu_idle_type idle, int *all_pinned,
-             int *this_best_prio, struct rq_iterator *iterator);
+ #ifdef CONFIG_SMP
+ static unsigned long
+ balance_tasks(struct rq *this_rq, int this_cpu, struct rq *busiest,
+             unsigned long max_load_move, struct sched_domain *sd,
+             enum cpu_idle_type idle, int *all_pinned,
+             int *this_best_prio, struct rq_iterator *iterator);
+ static int
+ iter_move_one_task(struct rq *this_rq, int this_cpu, struct rq *busiest,
+                  struct sched_domain *sd, enum cpu_idle_type idle,
+                  struct rq_iterator *iterator);
+ #endif
+ #ifdef CONFIG_CGROUP_CPUACCT
+ static void cpuacct_charge(struct task_struct *tsk, u64 cputime);
+ #else
+ static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime) {}
+ #endif
+ static inline void inc_cpu_load(struct rq *rq, unsigned long load)
+ {
+       update_load_add(&rq->load, load);
+ }
+ static inline void dec_cpu_load(struct rq *rq, unsigned long load)
+ {
+       update_load_sub(&rq->load, load);
+ }
+ #if (defined(CONFIG_SMP) && defined(CONFIG_FAIR_GROUP_SCHED)) || defined(CONFIG_RT_GROUP_SCHED)
+ typedef int (*tg_visitor)(struct task_group *, void *);
+ /*
+  * Iterate the full tree, calling @down when first entering a node and @up when
+  * leaving it for the final time.
+  */
+ static int walk_tg_tree(tg_visitor down, tg_visitor up, void *data)
+ {
+       struct task_group *parent, *child;
+       int ret;
+       rcu_read_lock();
+       parent = &root_task_group;
+ down:
+       ret = (*down)(parent, data);
+       if (ret)
+               goto out_unlock;
+       list_for_each_entry_rcu(child, &parent->children, siblings) {
+               parent = child;
+               goto down;
+ up:
+               continue;
+       }
+       ret = (*up)(parent, data);
+       if (ret)
+               goto out_unlock;
+       child = parent;
+       parent = parent->parent;
+       if (parent)
+               goto up;
+ out_unlock:
+       rcu_read_unlock();
+       return ret;
+ }
+ static int tg_nop(struct task_group *tg, void *data)
+ {
+       return 0;
+ }
+ #endif
+ #ifdef CONFIG_SMP
+ static unsigned long source_load(int cpu, int type);
+ static unsigned long target_load(int cpu, int type);
+ static int task_hot(struct task_struct *p, u64 now, struct sched_domain *sd);
+ static unsigned long cpu_avg_load_per_task(int cpu)
+ {
+       struct rq *rq = cpu_rq(cpu);
+       if (rq->nr_running)
+               rq->avg_load_per_task = rq->load.weight / rq->nr_running;
+       return rq->avg_load_per_task;
+ }
+ #ifdef CONFIG_FAIR_GROUP_SCHED
+ static void __set_se_shares(struct sched_entity *se, unsigned long shares);
+ /*
+  * Calculate and set the cpu's group shares.
+  */
+ static void
+ __update_group_shares_cpu(struct task_group *tg, int cpu,
+                         unsigned long sd_shares, unsigned long sd_rq_weight)
+ {
+       int boost = 0;
+       unsigned long shares;
+       unsigned long rq_weight;
+       if (!tg->se[cpu])
+               return;
+       rq_weight = tg->cfs_rq[cpu]->load.weight;
+       /*
+        * If there are currently no tasks on the cpu pretend there is one of
+        * average load so that when a new task gets to run here it will not
+        * get delayed by group starvation.
+        */
+       if (!rq_weight) {
+               boost = 1;
+               rq_weight = NICE_0_LOAD;
+       }
+       if (unlikely(rq_weight > sd_rq_weight))
+               rq_weight = sd_rq_weight;
+       /*
+        *           \Sum shares * rq_weight
+        * shares =  -----------------------
+        *               \Sum rq_weight
+        *
+        */
+       shares = (sd_shares * rq_weight) / (sd_rq_weight + 1);
+       /*
+        * record the actual number of shares, not the boosted amount.
+        */
+       tg->cfs_rq[cpu]->shares = boost ? 0 : shares;
+       tg->cfs_rq[cpu]->rq_weight = rq_weight;
+       if (shares < MIN_SHARES)
+               shares = MIN_SHARES;
+       else if (shares > MAX_SHARES)
+               shares = MAX_SHARES;
+       __set_se_shares(tg->se[cpu], shares);
+ }
+ /*
+  * Re-compute the task group their per cpu shares over the given domain.
+  * This needs to be done in a bottom-up fashion because the rq weight of a
+  * parent group depends on the shares of its child groups.
+  */
+ static int tg_shares_up(struct task_group *tg, void *data)
+ {
+       unsigned long rq_weight = 0;
+       unsigned long shares = 0;
+       struct sched_domain *sd = data;
+       int i;
+       for_each_cpu_mask(i, sd->span) {
+               rq_weight += tg->cfs_rq[i]->load.weight;
+               shares += tg->cfs_rq[i]->shares;
+       }
+       if ((!shares && rq_weight) || shares > tg->shares)
+               shares = tg->shares;
+       if (!sd->parent || !(sd->parent->flags & SD_LOAD_BALANCE))
+               shares = tg->shares;
+       if (!rq_weight)
+               rq_weight = cpus_weight(sd->span) * NICE_0_LOAD;
+       for_each_cpu_mask(i, sd->span) {
+               struct rq *rq = cpu_rq(i);
+               unsigned long flags;
+               spin_lock_irqsave(&rq->lock, flags);
+               __update_group_shares_cpu(tg, i, shares, rq_weight);
+               spin_unlock_irqrestore(&rq->lock, flags);
+       }
+       return 0;
+ }
+ /*
+  * Compute the cpu's hierarchical load factor for each task group.
+  * This needs to be done in a top-down fashion because the load of a child
+  * group is a fraction of its parents load.
+  */
+ static int tg_load_down(struct task_group *tg, void *data)
+ {
+       unsigned long load;
+       long cpu = (long)data;
+       if (!tg->parent) {
+               load = cpu_rq(cpu)->load.weight;
+       } else {
+               load = tg->parent->cfs_rq[cpu]->h_load;
+               load *= tg->cfs_rq[cpu]->shares;
+               load /= tg->parent->cfs_rq[cpu]->load.weight + 1;
+       }
+       tg->cfs_rq[cpu]->h_load = load;
+       return 0;
+ }
+ static void update_shares(struct sched_domain *sd)
+ {
+       u64 now = cpu_clock(raw_smp_processor_id());
+       s64 elapsed = now - sd->last_update;
  
- static int
- iter_move_one_task(struct rq *this_rq, int this_cpu, struct rq *busiest,
-                  struct sched_domain *sd, enum cpu_idle_type idle,
-                  struct rq_iterator *iterator);
- #endif
+       if (elapsed >= (s64)(u64)sysctl_sched_shares_ratelimit) {
+               sd->last_update = now;
+               walk_tg_tree(tg_nop, tg_shares_up, sd);
+       }
+ }
+ static void update_shares_locked(struct rq *rq, struct sched_domain *sd)
+ {
+       spin_unlock(&rq->lock);
+       update_shares(sd);
+       spin_lock(&rq->lock);
+ }
+ static void update_h_load(long cpu)
+ {
+       walk_tg_tree(tg_load_down, tg_nop, (void *)cpu);
+ }
  
- #ifdef CONFIG_CGROUP_CPUACCT
- static void cpuacct_charge(struct task_struct *tsk, u64 cputime);
  #else
- static inline void cpuacct_charge(struct task_struct *tsk, u64 cputime) {}
- #endif
  
- static inline void inc_cpu_load(struct rq *rq, unsigned long load)
+ static inline void update_shares(struct sched_domain *sd)
  {
-       update_load_add(&rq->load, load);
  }
  
- static inline void dec_cpu_load(struct rq *rq, unsigned long load)
+ static inline void update_shares_locked(struct rq *rq, struct sched_domain *sd)
  {
-       update_load_sub(&rq->load, load);
  }
  
- #ifdef CONFIG_SMP
- static unsigned long source_load(int cpu, int type);
- static unsigned long target_load(int cpu, int type);
- static unsigned long cpu_avg_load_per_task(int cpu);
- static int task_hot(struct task_struct *p, u64 now, struct sched_domain *sd);
- #else /* CONFIG_SMP */
+ #endif
+ #endif
  
  #ifdef CONFIG_FAIR_GROUP_SCHED
  static void cfs_rq_set_shares(struct cfs_rq *cfs_rq, unsigned long shares)
  {
+ #ifdef CONFIG_SMP
+       cfs_rq->shares = shares;
+ #endif
  }
  #endif
  
- #endif /* CONFIG_SMP */
  #include "sched_stats.h"
  #include "sched_idletask.c"
  #include "sched_fair.c"
  #endif
  
  #define sched_class_highest (&rt_sched_class)
+ #define for_each_class(class) \
+    for (class = sched_class_highest; class; class = class->next)
  
- static inline void inc_load(struct rq *rq, const struct task_struct *p)
- {
-       update_load_add(&rq->load, p->se.load.weight);
- }
- static inline void dec_load(struct rq *rq, const struct task_struct *p)
- {
-       update_load_sub(&rq->load, p->se.load.weight);
- }
- static void inc_nr_running(struct task_struct *p, struct rq *rq)
+ static void inc_nr_running(struct rq *rq)
  {
        rq->nr_running++;
-       inc_load(rq, p);
  }
  
- static void dec_nr_running(struct task_struct *p, struct rq *rq)
+ static void dec_nr_running(struct rq *rq)
  {
        rq->nr_running--;
-       dec_load(rq, p);
  }
  
  static void set_load_weight(struct task_struct *p)
        p->se.load.inv_weight = prio_to_wmult[p->static_prio - MAX_RT_PRIO];
  }
  
+ static void update_avg(u64 *avg, u64 sample)
+ {
+       s64 diff = sample - *avg;
+       *avg += diff >> 3;
+ }
  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
  {
        sched_info_queued(p);
  
  static void dequeue_task(struct rq *rq, struct task_struct *p, int sleep)
  {
+       if (sleep && p->se.last_wakeup) {
+               update_avg(&p->se.avg_overlap,
+                          p->se.sum_exec_runtime - p->se.last_wakeup);
+               p->se.last_wakeup = 0;
+       }
+       sched_info_dequeued(p);
        p->sched_class->dequeue_task(rq, p, sleep);
        p->se.on_rq = 0;
  }
@@@ -1612,7 -1731,7 +1731,7 @@@ static void activate_task(struct rq *rq
                rq->nr_uninterruptible--;
  
        enqueue_task(rq, p, wakeup);
-       inc_nr_running(p, rq);
+       inc_nr_running(rq);
  }
  
  /*
@@@ -1624,7 -1743,7 +1743,7 @@@ static void deactivate_task(struct rq *
                rq->nr_uninterruptible++;
  
        dequeue_task(rq, p, sleep);
-       dec_nr_running(p, rq);
+       dec_nr_running(rq);
  }
  
  /**
@@@ -1636,12 -1755,6 +1755,6 @@@ inline int task_curr(const struct task_
        return cpu_curr(task_cpu(p)) == p;
  }
  
- /* Used instead of source_load when we know the type == 0 */
- unsigned long weighted_cpuload(const int cpu)
- {
-       return cpu_rq(cpu)->load.weight;
- }
  static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
  {
        set_task_rq(p, cpu);
@@@ -1670,6 -1783,12 +1783,12 @@@ static inline void check_class_changed(
  
  #ifdef CONFIG_SMP
  
+ /* Used instead of source_load when we know the type == 0 */
+ static unsigned long weighted_cpuload(const int cpu)
+ {
+       return cpu_rq(cpu)->load.weight;
+ }
  /*
   * Is this task likely cache-hot:
   */
@@@ -1765,16 -1884,24 +1884,24 @@@ migrate_task(struct task_struct *p, in
  /*
   * wait_task_inactive - wait for a thread to unschedule.
   *
+  * If @match_state is nonzero, it's the @p->state value just checked and
+  * not expected to change.  If it changes, i.e. @p might have woken up,
+  * then return zero.  When we succeed in waiting for @p to be off its CPU,
+  * we return a positive number (its total switch count).  If a second call
+  * a short while later returns the same number, the caller can be sure that
+  * @p has remained unscheduled the whole time.
+  *
   * The caller must ensure that the task *will* unschedule sometime soon,
   * else this function might spin for a *long* time. This function can't
   * be called with interrupts off, or it may introduce deadlock with
   * smp_call_function() if an IPI is sent by the same process we are
   * waiting to become inactive.
   */
void wait_task_inactive(struct task_struct *p)
unsigned long wait_task_inactive(struct task_struct *p, long match_state)
  {
        unsigned long flags;
        int running, on_rq;
+       unsigned long ncsw;
        struct rq *rq;
  
        for (;;) {
                 * return false if the runqueue has changed and p
                 * is actually now running somewhere else!
                 */
-               while (task_running(rq, p))
+               while (task_running(rq, p)) {
+                       if (match_state && unlikely(p->state != match_state))
+                               return 0;
                        cpu_relax();
+               }
  
                /*
                 * Ok, time to look more closely! We need the rq
                rq = task_rq_lock(p, &flags);
                running = task_running(rq, p);
                on_rq = p->se.on_rq;
+               ncsw = 0;
+               if (!match_state || p->state == match_state)
+                       ncsw = p->nvcsw | LONG_MIN; /* sets MSB */
                task_rq_unlock(rq, &flags);
  
+               /*
+                * If it changed from the expected state, bail out now.
+                */
+               if (unlikely(!ncsw))
+                       break;
                /*
                 * Was it really running after all now that we
                 * checked with the proper locks actually held?
                 */
                break;
        }
+       return ncsw;
  }
  
  /***
@@@ -1880,7 -2021,7 +2021,7 @@@ static unsigned long source_load(int cp
        struct rq *rq = cpu_rq(cpu);
        unsigned long total = weighted_cpuload(cpu);
  
-       if (type == 0)
+       if (type == 0 || !sched_feat(LB_BIAS))
                return total;
  
        return min(rq->cpu_load[type-1], total);
@@@ -1895,24 -2036,12 +2036,12 @@@ static unsigned long target_load(int cp
        struct rq *rq = cpu_rq(cpu);
        unsigned long total = weighted_cpuload(cpu);
  
-       if (type == 0)
+       if (type == 0 || !sched_feat(LB_BIAS))
                return total;
  
        return max(rq->cpu_load[type-1], total);
  }
  
- /*
-  * Return the average load per task on the cpu's run queue
-  */
- static unsigned long cpu_avg_load_per_task(int cpu)
- {
-       struct rq *rq = cpu_rq(cpu);
-       unsigned long total = weighted_cpuload(cpu);
-       unsigned long n = rq->nr_running;
-       return n ? total / n : SCHED_LOAD_SCALE;
- }
  /*
   * find_idlest_group finds and returns the least busy CPU group within the
   * domain.
@@@ -1939,7 -2068,7 +2068,7 @@@ find_idlest_group(struct sched_domain *
                /* Tally up the load of all CPUs in the group */
                avg_load = 0;
  
-               for_each_cpu_mask(i, group->cpumask) {
+               for_each_cpu_mask_nr(i, group->cpumask) {
                        /* Bias balancing toward cpus of our domain */
                        if (local_group)
                                load = source_load(i, load_idx);
@@@ -1981,7 -2110,7 +2110,7 @@@ find_idlest_cpu(struct sched_group *gro
        /* Traverse only the allowed CPUs */
        cpus_and(*tmp, group->cpumask, p->cpus_allowed);
  
-       for_each_cpu_mask(i, *tmp) {
+       for_each_cpu_mask_nr(i, *tmp) {
                load = weighted_cpuload(i);
  
                if (load < min_load || (load == min_load && i == this_cpu)) {
@@@ -2019,6 -2148,9 +2148,9 @@@ static int sched_balance_self(int cpu, 
                        sd = tmp;
        }
  
+       if (sd)
+               update_shares(sd);
        while (sd) {
                cpumask_t span, tmpmask;
                struct sched_group *group;
@@@ -2085,6 -2217,22 +2217,22 @@@ static int try_to_wake_up(struct task_s
        if (!sched_feat(SYNC_WAKEUPS))
                sync = 0;
  
+ #ifdef CONFIG_SMP
+       if (sched_feat(LB_WAKEUP_UPDATE)) {
+               struct sched_domain *sd;
+               this_cpu = raw_smp_processor_id();
+               cpu = task_cpu(p);
+               for_each_domain(this_cpu, sd) {
+                       if (cpu_isset(cpu, sd->span)) {
+                               update_shares(sd);
+                               break;
+                       }
+               }
+       }
+ #endif
        smp_wmb();
        rq = task_rq_lock(p, &flags);
        old_state = p->state;
                        }
                }
        }
- #endif
+ #endif /* CONFIG_SCHEDSTATS */
  
  out_activate:
  #endif /* CONFIG_SMP */
        success = 1;
  
  out_running:
-       check_preempt_curr(rq, p);
+       trace_mark(kernel_sched_wakeup,
+               "pid %d state %ld ## rq %p task %p rq->curr %p",
+               p->pid, p->state, rq, p, rq->curr);
+       check_preempt_curr(rq, p, sync);
  
        p->state = TASK_RUNNING;
  #ifdef CONFIG_SMP
                p->sched_class->task_wake_up(rq, p);
  #endif
  out:
+       current->se.last_wakeup = current->se.sum_exec_runtime;
        task_rq_unlock(rq, &flags);
  
        return success;
@@@ -2277,9 -2430,12 +2430,12 @@@ void wake_up_new_task(struct task_struc
                 * management (if any):
                 */
                p->sched_class->task_new(rq, p);
-               inc_nr_running(p, rq);
+               inc_nr_running(rq);
        }
-       check_preempt_curr(rq, p);
+       trace_mark(kernel_sched_wakeup_new,
+               "pid %d state %ld ## rq %p task %p rq->curr %p",
+               p->pid, p->state, rq, p, rq->curr);
+       check_preempt_curr(rq, p, 0);
  #ifdef CONFIG_SMP
        if (p->sched_class->task_wake_up)
                p->sched_class->task_wake_up(rq, p);
@@@ -2331,7 -2487,7 +2487,7 @@@ fire_sched_out_preempt_notifiers(struc
                notifier->ops->sched_out(notifier, next);
  }
  
- #else
+ #else /* !CONFIG_PREEMPT_NOTIFIERS */
  
  static void fire_sched_in_preempt_notifiers(struct task_struct *curr)
  {
@@@ -2343,7 -2499,7 +2499,7 @@@ fire_sched_out_preempt_notifiers(struc
  {
  }
  
- #endif
+ #endif /* CONFIG_PREEMPT_NOTIFIERS */
  
  /**
   * prepare_task_switch - prepare to switch tasks
@@@ -2451,6 -2607,11 +2607,11 @@@ context_switch(struct rq *rq, struct ta
        struct mm_struct *mm, *oldmm;
  
        prepare_task_switch(rq, prev, next);
+       trace_mark(kernel_sched_schedule,
+               "prev_pid %d next_pid %d prev_state %ld "
+               "## rq %p prev %p next %p",
+               prev->pid, next->pid, prev->state,
+               rq, prev, next);
        mm = next->mm;
        oldmm = prev->active_mm;
        /*
@@@ -2612,10 -2773,10 +2773,10 @@@ static void double_rq_lock(struct rq *r
        } else {
                if (rq1 < rq2) {
                        spin_lock(&rq1->lock);
-                       spin_lock(&rq2->lock);
+                       spin_lock_nested(&rq2->lock, SINGLE_DEPTH_NESTING);
                } else {
                        spin_lock(&rq2->lock);
-                       spin_lock(&rq1->lock);
+                       spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING);
                }
        }
        update_rq_clock(rq1);
@@@ -2658,14 -2819,21 +2819,21 @@@ static int double_lock_balance(struct r
                if (busiest < this_rq) {
                        spin_unlock(&this_rq->lock);
                        spin_lock(&busiest->lock);
-                       spin_lock(&this_rq->lock);
+                       spin_lock_nested(&this_rq->lock, SINGLE_DEPTH_NESTING);
                        ret = 1;
                } else
-                       spin_lock(&busiest->lock);
+                       spin_lock_nested(&busiest->lock, SINGLE_DEPTH_NESTING);
        }
        return ret;
  }
  
+ static void double_unlock_balance(struct rq *this_rq, struct rq *busiest)
+       __releases(busiest->lock)
+ {
+       spin_unlock(&busiest->lock);
+       lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_);
+ }
  /*
   * If dest_cpu is allowed for this process, migrate the task to it.
   * This is accomplished by forcing the cpu_allowed mask to only
@@@ -2680,7 -2848,7 +2848,7 @@@ static void sched_migrate_task(struct t
  
        rq = task_rq_lock(p, &flags);
        if (!cpu_isset(dest_cpu, p->cpus_allowed)
-           || unlikely(cpu_is_offline(dest_cpu)))
+           || unlikely(!cpu_active(dest_cpu)))
                goto out;
  
        /* force the process onto the specified CPU */
@@@ -2727,7 -2895,7 +2895,7 @@@ static void pull_task(struct rq *src_rq
         * Note that idle threads have a prio of MAX_PRIO, for this test
         * to be always true for them.
         */
-       check_preempt_curr(this_rq, p);
+       check_preempt_curr(this_rq, p, 0);
  }
  
  /*
@@@ -2785,7 -2953,7 +2953,7 @@@ balance_tasks(struct rq *this_rq, int t
              enum cpu_idle_type idle, int *all_pinned,
              int *this_best_prio, struct rq_iterator *iterator)
  {
-       int loops = 0, pulled = 0, pinned = 0, skip_for_load;
+       int loops = 0, pulled = 0, pinned = 0;
        struct task_struct *p;
        long rem_load_move = max_load_move;
  
  next:
        if (!p || loops++ > sysctl_sched_nr_migrate)
                goto out;
-       /*
-        * To help distribute high priority tasks across CPUs we don't
-        * skip a task if it will be the highest priority task (i.e. smallest
-        * prio value) on its new queue regardless of its load weight
-        */
-       skip_for_load = (p->se.load.weight >> 1) > rem_load_move +
-                                                        SCHED_LOAD_SCALE_FUZZ;
-       if ((skip_for_load && p->prio >= *this_best_prio) ||
+       if ((p->se.load.weight >> 1) > rem_load_move ||
            !can_migrate_task(p, busiest, this_cpu, sd, idle, &pinned)) {
                p = iterator->next(iterator->arg);
                goto next;
@@@ -2863,6 -3025,10 +3025,10 @@@ static int move_tasks(struct rq *this_r
                                max_load_move - total_load_moved,
                                sd, idle, all_pinned, &this_best_prio);
                class = class->next;
+               if (idle == CPU_NEWLY_IDLE && this_rq->nr_running)
+                       break;
        } while (class && max_load_move > total_load_moved);
  
        return total_load_moved > 0;
@@@ -2939,6 -3105,7 +3105,7 @@@ find_busiest_group(struct sched_domain 
        max_load = this_load = total_load = total_pwr = 0;
        busiest_load_per_task = busiest_nr_running = 0;
        this_load_per_task = this_nr_running = 0;
        if (idle == CPU_NOT_IDLE)
                load_idx = sd->busy_idx;
        else if (idle == CPU_NEWLY_IDLE)
                int __group_imb = 0;
                unsigned int balance_cpu = -1, first_idle_cpu = 0;
                unsigned long sum_nr_running, sum_weighted_load;
+               unsigned long sum_avg_load_per_task;
+               unsigned long avg_load_per_task;
  
                local_group = cpu_isset(this_cpu, group->cpumask);
  
  
                /* Tally up the load of all CPUs in the group */
                sum_weighted_load = sum_nr_running = avg_load = 0;
+               sum_avg_load_per_task = avg_load_per_task = 0;
                max_cpu_load = 0;
                min_cpu_load = ~0UL;
  
-               for_each_cpu_mask(i, group->cpumask) {
+               for_each_cpu_mask_nr(i, group->cpumask) {
                        struct rq *rq;
  
                        if (!cpu_isset(i, *cpus))
                        avg_load += load;
                        sum_nr_running += rq->nr_running;
                        sum_weighted_load += weighted_cpuload(i);
+                       sum_avg_load_per_task += cpu_avg_load_per_task(i);
                }
  
                /*
                avg_load = sg_div_cpu_power(group,
                                avg_load * SCHED_LOAD_SCALE);
  
-               if ((max_cpu_load - min_cpu_load) > SCHED_LOAD_SCALE)
+               /*
+                * Consider the group unbalanced when the imbalance is larger
+                * than the average weight of two tasks.
+                *
+                * APZ: with cgroup the avg task weight can vary wildly and
+                *      might not be a suitable number - should we keep a
+                *      normalized nr_running number somewhere that negates
+                *      the hierarchy?
+                */
+               avg_load_per_task = sg_div_cpu_power(group,
+                               sum_avg_load_per_task * SCHED_LOAD_SCALE);
+               if ((max_cpu_load - min_cpu_load) > 2*avg_load_per_task)
                        __group_imb = 1;
  
                group_capacity = group->__cpu_power / SCHED_LOAD_SCALE;
@@@ -3156,9 -3342,9 +3342,9 @@@ small_imbalance
                        if (busiest_load_per_task > this_load_per_task)
                                imbn = 1;
                } else
-                       this_load_per_task = SCHED_LOAD_SCALE;
+                       this_load_per_task = cpu_avg_load_per_task(this_cpu);
  
-               if (max_load - this_load + SCHED_LOAD_SCALE_FUZZ >=
+               if (max_load - this_load + 2*busiest_load_per_task >=
                                        busiest_load_per_task * imbn) {
                        *imbalance = busiest_load_per_task;
                        return busiest;
@@@ -3228,7 -3414,7 +3414,7 @@@ find_busiest_queue(struct sched_group *
        unsigned long max_load = 0;
        int i;
  
-       for_each_cpu_mask(i, group->cpumask) {
+       for_each_cpu_mask_nr(i, group->cpumask) {
                unsigned long wl;
  
                if (!cpu_isset(i, *cpus))
@@@ -3284,6 -3470,7 +3470,7 @@@ static int load_balance(int this_cpu, s
        schedstat_inc(sd, lb_count[idle]);
  
  redo:
+       update_shares(sd);
        group = find_busiest_group(sd, this_cpu, &imbalance, idle, &sd_idle,
                                   cpus, balance);
  
  
        if (!ld_moved && !sd_idle && sd->flags & SD_SHARE_CPUPOWER &&
            !test_sd_parent(sd, SD_POWERSAVINGS_BALANCE))
-               return -1;
-       return ld_moved;
+               ld_moved = -1;
+       goto out;
  
  out_balanced:
        schedstat_inc(sd, lb_balanced[idle]);
@@@ -3402,8 -3590,13 +3590,13 @@@ out_one_pinned
  
        if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER &&
            !test_sd_parent(sd, SD_POWERSAVINGS_BALANCE))
-               return -1;
-       return 0;
+               ld_moved = -1;
+       else
+               ld_moved = 0;
+ out:
+       if (ld_moved)
+               update_shares(sd);
+       return ld_moved;
  }
  
  /*
@@@ -3438,6 -3631,7 +3631,7 @@@ load_balance_newidle(int this_cpu, stru
  
        schedstat_inc(sd, lb_count[CPU_NEWLY_IDLE]);
  redo:
+       update_shares_locked(this_rq, sd);
        group = find_busiest_group(sd, this_cpu, &imbalance, CPU_NEWLY_IDLE,
                                   &sd_idle, cpus, NULL);
        if (!group) {
                ld_moved = move_tasks(this_rq, this_cpu, busiest,
                                        imbalance, sd, CPU_NEWLY_IDLE,
                                        &all_pinned);
-               spin_unlock(&busiest->lock);
+               double_unlock_balance(this_rq, busiest);
  
                if (unlikely(all_pinned)) {
                        cpu_clear(cpu_of(busiest), *cpus);
        } else
                sd->nr_balance_failed = 0;
  
+       update_shares_locked(this_rq, sd);
        return ld_moved;
  
  out_balanced:
@@@ -3578,7 -3773,7 +3773,7 @@@ static void active_load_balance(struct 
                else
                        schedstat_inc(sd, alb_failed);
        }
-       spin_unlock(&target_rq->lock);
+       double_unlock_balance(busiest_rq, target_rq);
  }
  
  #ifdef CONFIG_NO_HZ
@@@ -3621,7 -3816,7 +3816,7 @@@ int select_nohz_load_balancer(int stop_
                /*
                 * If we are going offline and still the leader, give up!
                 */
-               if (cpu_is_offline(cpu) &&
+               if (!cpu_active(cpu) &&
                    atomic_read(&nohz.load_balancer) == cpu) {
                        if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu)
                                BUG();
@@@ -3672,6 -3867,7 +3867,7 @@@ static void rebalance_domains(int cpu, 
        /* Earliest time when we have to do rebalance again */
        unsigned long next_balance = jiffies + 60*HZ;
        int update_next_balance = 0;
+       int need_serialize;
        cpumask_t tmp;
  
        for_each_domain(cpu, sd) {
                if (interval > HZ*NR_CPUS/10)
                        interval = HZ*NR_CPUS/10;
  
+               need_serialize = sd->flags & SD_SERIALIZE;
  
-               if (sd->flags & SD_SERIALIZE) {
+               if (need_serialize) {
                        if (!spin_trylock(&balancing))
                                goto out;
                }
                        }
                        sd->last_balance = jiffies;
                }
-               if (sd->flags & SD_SERIALIZE)
+               if (need_serialize)
                        spin_unlock(&balancing);
  out:
                if (time_after(next_balance, sd->last_balance + interval)) {
@@@ -3759,7 -3956,7 +3956,7 @@@ static void run_rebalance_domains(struc
                int balance_cpu;
  
                cpu_clear(this_cpu, cpus);
-               for_each_cpu_mask(balance_cpu, cpus) {
+               for_each_cpu_mask_nr(balance_cpu, cpus) {
                        /*
                         * If this cpu gets work to do, stop the load balancing
                         * work being done for other cpus. Next load
@@@ -3895,6 -4092,8 +4092,8 @@@ void account_user_time(struct task_stru
                cpustat->nice = cputime64_add(cpustat->nice, tmp);
        else
                cpustat->user = cputime64_add(cpustat->user, tmp);
+       /* Account for user time used */
+       acct_update_integrals(p);
  }
  
  /*
@@@ -3994,6 -4193,65 +4193,65 @@@ void account_steal_time(struct task_str
                cpustat->steal = cputime64_add(cpustat->steal, tmp);
  }
  
+ /*
+  * Use precise platform statistics if available:
+  */
+ #ifdef CONFIG_VIRT_CPU_ACCOUNTING
+ cputime_t task_utime(struct task_struct *p)
+ {
+       return p->utime;
+ }
+ cputime_t task_stime(struct task_struct *p)
+ {
+       return p->stime;
+ }
+ #else
+ cputime_t task_utime(struct task_struct *p)
+ {
+       clock_t utime = cputime_to_clock_t(p->utime),
+               total = utime + cputime_to_clock_t(p->stime);
+       u64 temp;
+       /*
+        * Use CFS's precise accounting:
+        */
+       temp = (u64)nsec_to_clock_t(p->se.sum_exec_runtime);
+       if (total) {
+               temp *= utime;
+               do_div(temp, total);
+       }
+       utime = (clock_t)temp;
+       p->prev_utime = max(p->prev_utime, clock_t_to_cputime(utime));
+       return p->prev_utime;
+ }
+ cputime_t task_stime(struct task_struct *p)
+ {
+       clock_t stime;
+       /*
+        * Use CFS's precise accounting. (we subtract utime from
+        * the total, to make sure the total observed by userspace
+        * grows monotonically - apps rely on that):
+        */
+       stime = nsec_to_clock_t(p->se.sum_exec_runtime) -
+                       cputime_to_clock_t(task_utime(p));
+       if (stime >= 0)
+               p->prev_stime = max(p->prev_stime, clock_t_to_cputime(stime));
+       return p->prev_stime;
+ }
+ #endif
+ inline cputime_t task_gtime(struct task_struct *p)
+ {
+       return p->gtime;
+ }
  /*
   * This function gets called by the timer code, with HZ frequency.
   * We call it with interrupts disabled.
@@@ -4021,26 -4279,44 +4279,44 @@@ void scheduler_tick(void
  #endif
  }
  
- #if defined(CONFIG_PREEMPT) && defined(CONFIG_DEBUG_PREEMPT)
+ #if defined(CONFIG_PREEMPT) && (defined(CONFIG_DEBUG_PREEMPT) || \
+                               defined(CONFIG_PREEMPT_TRACER))
+ static inline unsigned long get_parent_ip(unsigned long addr)
+ {
+       if (in_lock_functions(addr)) {
+               addr = CALLER_ADDR2;
+               if (in_lock_functions(addr))
+                       addr = CALLER_ADDR3;
+       }
+       return addr;
+ }
  
  void __kprobes add_preempt_count(int val)
  {
+ #ifdef CONFIG_DEBUG_PREEMPT
        /*
         * Underflow?
         */
        if (DEBUG_LOCKS_WARN_ON((preempt_count() < 0)))
                return;
+ #endif
        preempt_count() += val;
+ #ifdef CONFIG_DEBUG_PREEMPT
        /*
         * Spinlock count overflowing soon?
         */
        DEBUG_LOCKS_WARN_ON((preempt_count() & PREEMPT_MASK) >=
                                PREEMPT_MASK - 10);
+ #endif
+       if (preempt_count() == val)
+               trace_preempt_off(CALLER_ADDR0, get_parent_ip(CALLER_ADDR1));
  }
  EXPORT_SYMBOL(add_preempt_count);
  
  void __kprobes sub_preempt_count(int val)
  {
+ #ifdef CONFIG_DEBUG_PREEMPT
        /*
         * Underflow?
         */
        if (DEBUG_LOCKS_WARN_ON((val < PREEMPT_MASK) &&
                        !(preempt_count() & PREEMPT_MASK)))
                return;
+ #endif
  
+       if (preempt_count() == val)
+               trace_preempt_on(CALLER_ADDR0, get_parent_ip(CALLER_ADDR1));
        preempt_count() -= val;
  }
  EXPORT_SYMBOL(sub_preempt_count);
@@@ -4070,6 -4349,7 +4349,7 @@@ static noinline void __schedule_bug(str
                prev->comm, prev->pid, preempt_count());
  
        debug_show_held_locks(prev);
+       print_modules();
        if (irqs_disabled())
                print_irqtrace_events(prev);
  
@@@ -4158,7 -4438,8 +4438,8 @@@ need_resched_nonpreemptible
  
        schedule_debug(prev);
  
-       hrtick_clear(rq);
+       if (sched_feat(HRTICK))
+               hrtick_clear(rq);
  
        /*
         * Do the rq-clock update outside the rq lock:
        } else
                spin_unlock_irq(&rq->lock);
  
-       hrtick_set(rq);
        if (unlikely(reacquire_kernel_lock(current) < 0))
                goto need_resched_nonpreemptible;
  
@@@ -4363,6 -4642,15 +4642,15 @@@ __wake_up_sync(wait_queue_head_t *q, un
  }
  EXPORT_SYMBOL_GPL(__wake_up_sync);    /* For internal use only */
  
+ /**
+  * complete: - signals a single thread waiting on this completion
+  * @x:  holds the state of this particular completion
+  *
+  * This will wake up a single thread waiting on this completion. Threads will be
+  * awakened in the same order in which they were queued.
+  *
+  * See also complete_all(), wait_for_completion() and related routines.
+  */
  void complete(struct completion *x)
  {
        unsigned long flags;
  }
  EXPORT_SYMBOL(complete);
  
+ /**
+  * complete_all: - signals all threads waiting on this completion
+  * @x:  holds the state of this particular completion
+  *
+  * This will wake up all threads waiting on this particular completion event.
+  */
  void complete_all(struct completion *x)
  {
        unsigned long flags;
@@@ -4394,10 -4688,7 +4688,7 @@@ do_wait_for_common(struct completion *x
                wait.flags |= WQ_FLAG_EXCLUSIVE;
                __add_wait_queue_tail(&x->wait, &wait);
                do {
-                       if ((state == TASK_INTERRUPTIBLE &&
-                            signal_pending(current)) ||
-                           (state == TASK_KILLABLE &&
-                            fatal_signal_pending(current))) {
+                       if (signal_pending_state(state, current)) {
                                timeout = -ERESTARTSYS;
                                break;
                        }
@@@ -4425,12 -4716,31 +4716,31 @@@ wait_for_common(struct completion *x, l
        return timeout;
  }
  
+ /**
+  * wait_for_completion: - waits for completion of a task
+  * @x:  holds the state of this particular completion
+  *
+  * This waits to be signaled for completion of a specific task. It is NOT
+  * interruptible and there is no timeout.
+  *
+  * See also similar routines (i.e. wait_for_completion_timeout()) with timeout
+  * and interrupt capability. Also see complete().
+  */
  void __sched wait_for_completion(struct completion *x)
  {
        wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_UNINTERRUPTIBLE);
  }
  EXPORT_SYMBOL(wait_for_completion);
  
+ /**
+  * wait_for_completion_timeout: - waits for completion of a task (w/timeout)
+  * @x:  holds the state of this particular completion
+  * @timeout:  timeout value in jiffies
+  *
+  * This waits for either a completion of a specific task to be signaled or for a
+  * specified timeout to expire. The timeout is in jiffies. It is not
+  * interruptible.
+  */
  unsigned long __sched
  wait_for_completion_timeout(struct completion *x, unsigned long timeout)
  {
  }
  EXPORT_SYMBOL(wait_for_completion_timeout);
  
+ /**
+  * wait_for_completion_interruptible: - waits for completion of a task (w/intr)
+  * @x:  holds the state of this particular completion
+  *
+  * This waits for completion of a specific task to be signaled. It is
+  * interruptible.
+  */
  int __sched wait_for_completion_interruptible(struct completion *x)
  {
        long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_INTERRUPTIBLE);
  }
  EXPORT_SYMBOL(wait_for_completion_interruptible);
  
+ /**
+  * wait_for_completion_interruptible_timeout: - waits for completion (w/(to,intr))
+  * @x:  holds the state of this particular completion
+  * @timeout:  timeout value in jiffies
+  *
+  * This waits for either a completion of a specific task to be signaled or for a
+  * specified timeout to expire. It is interruptible. The timeout is in jiffies.
+  */
  unsigned long __sched
  wait_for_completion_interruptible_timeout(struct completion *x,
                                          unsigned long timeout)
  }
  EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
  
+ /**
+  * wait_for_completion_killable: - waits for completion of a task (killable)
+  * @x:  holds the state of this particular completion
+  *
+  * This waits to be signaled for completion of a specific task. It can be
+  * interrupted by a kill signal.
+  */
  int __sched wait_for_completion_killable(struct completion *x)
  {
        long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
  }
  EXPORT_SYMBOL(wait_for_completion_killable);
  
+ /**
+  *    try_wait_for_completion - try to decrement a completion without blocking
+  *    @x:     completion structure
+  *
+  *    Returns: 0 if a decrement cannot be done without blocking
+  *             1 if a decrement succeeded.
+  *
+  *    If a completion is being used as a counting completion,
+  *    attempt to decrement the counter without blocking. This
+  *    enables us to avoid waiting if the resource the completion
+  *    is protecting is not available.
+  */
+ bool try_wait_for_completion(struct completion *x)
+ {
+       int ret = 1;
+       spin_lock_irq(&x->wait.lock);
+       if (!x->done)
+               ret = 0;
+       else
+               x->done--;
+       spin_unlock_irq(&x->wait.lock);
+       return ret;
+ }
+ EXPORT_SYMBOL(try_wait_for_completion);
+ /**
+  *    completion_done - Test to see if a completion has any waiters
+  *    @x:     completion structure
+  *
+  *    Returns: 0 if there are waiters (wait_for_completion() in progress)
+  *             1 if there are no waiters.
+  *
+  */
+ bool completion_done(struct completion *x)
+ {
+       int ret = 1;
+       spin_lock_irq(&x->wait.lock);
+       if (!x->done)
+               ret = 0;
+       spin_unlock_irq(&x->wait.lock);
+       return ret;
+ }
+ EXPORT_SYMBOL(completion_done);
  static long __sched
  sleep_on_common(wait_queue_head_t *q, int state, long timeout)
  {
@@@ -4586,10 -4964,8 +4964,8 @@@ void set_user_nice(struct task_struct *
                goto out_unlock;
        }
        on_rq = p->se.on_rq;
-       if (on_rq) {
+       if (on_rq)
                dequeue_task(rq, p, 0);
-               dec_load(rq, p);
-       }
  
        p->static_prio = NICE_TO_PRIO(nice);
        set_load_weight(p);
  
        if (on_rq) {
                enqueue_task(rq, p, 0);
-               inc_load(rq, p);
                /*
                 * If the task increased its priority or is running and
                 * lowered its priority, then reschedule its CPU:
@@@ -4744,16 -5119,8 +5119,8 @@@ __setscheduler(struct rq *rq, struct ta
        set_load_weight(p);
  }
  
- /**
-  * sched_setscheduler - change the scheduling policy and/or RT priority of a thread.
-  * @p: the task in question.
-  * @policy: new policy.
-  * @param: structure containing the new RT priority.
-  *
-  * NOTE that the task may be already dead.
-  */
- int sched_setscheduler(struct task_struct *p, int policy,
-                      struct sched_param *param)
+ static int __sched_setscheduler(struct task_struct *p, int policy,
+                               struct sched_param *param, bool user)
  {
        int retval, oldprio, oldpolicy = -1, on_rq, running;
        unsigned long flags;
@@@ -4785,7 -5152,7 +5152,7 @@@ recheck
        /*
         * Allow unprivileged RT tasks to decrease priority:
         */
-       if (!capable(CAP_SYS_NICE)) {
+       if (user && !capable(CAP_SYS_NICE)) {
                if (rt_policy(policy)) {
                        unsigned long rlim_rtprio;
  
                        return -EPERM;
        }
  
+       if (user) {
  #ifdef CONFIG_RT_GROUP_SCHED
-       /*
-        * Do not allow realtime tasks into groups that have no runtime
-        * assigned.
-        */
-       if (rt_policy(policy) && task_group(p)->rt_bandwidth.rt_runtime == 0)
-               return -EPERM;
+               /*
+                * Do not allow realtime tasks into groups that have no runtime
+                * assigned.
+                */
+               if (rt_bandwidth_enabled() && rt_policy(policy) &&
+                               task_group(p)->rt_bandwidth.rt_runtime == 0)
+                       return -EPERM;
  #endif
  
-       retval = security_task_setscheduler(p, policy, param);
-       if (retval)
-               return retval;
+               retval = security_task_setscheduler(p, policy, param);
+               if (retval)
+                       return retval;
+       }
        /*
         * make sure no PI-waiters arrive (or leave) while we are
         * changing the priority of the task:
  
        return 0;
  }
+ /**
+  * sched_setscheduler - change the scheduling policy and/or RT priority of a thread.
+  * @p: the task in question.
+  * @policy: new policy.
+  * @param: structure containing the new RT priority.
+  *
+  * NOTE that the task may be already dead.
+  */
+ int sched_setscheduler(struct task_struct *p, int policy,
+                      struct sched_param *param)
+ {
+       return __sched_setscheduler(p, policy, param, true);
+ }
  EXPORT_SYMBOL_GPL(sched_setscheduler);
  
+ /**
+  * sched_setscheduler_nocheck - change the scheduling policy and/or RT priority of a thread from kernelspace.
+  * @p: the task in question.
+  * @policy: new policy.
+  * @param: structure containing the new RT priority.
+  *
+  * Just like sched_setscheduler, only don't bother checking if the
+  * current context has permission.  For example, this is needed in
+  * stop_machine(): we create temporary high priority worker threads,
+  * but our caller might not have that capability.
+  */
+ int sched_setscheduler_nocheck(struct task_struct *p, int policy,
+                              struct sched_param *param)
+ {
+       return __sched_setscheduler(p, policy, param, false);
+ }
  static int
  do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param)
  {
@@@ -5070,24 -5472,6 +5472,6 @@@ asmlinkage long sys_sched_setaffinity(p
        return sched_setaffinity(pid, &new_mask);
  }
  
- /*
-  * Represents all cpu's present in the system
-  * In systems capable of hotplug, this map could dynamically grow
-  * as new cpu's are detected in the system via any platform specific
-  * method, such as ACPI for e.g.
-  */
- cpumask_t cpu_present_map __read_mostly;
- EXPORT_SYMBOL(cpu_present_map);
- #ifndef CONFIG_SMP
- cpumask_t cpu_online_map __read_mostly = CPU_MASK_ALL;
- EXPORT_SYMBOL(cpu_online_map);
- cpumask_t cpu_possible_map __read_mostly = CPU_MASK_ALL;
- EXPORT_SYMBOL(cpu_possible_map);
- #endif
  long sched_getaffinity(pid_t pid, cpumask_t *mask)
  {
        struct task_struct *p;
@@@ -5384,7 -5768,7 +5768,7 @@@ out_unlock
        return retval;
  }
  
- static const char stat_nam[] = "RSDTtZX";
+ static const char stat_nam[] = TASK_STATE_TO_CHAR_STR;
  
  void sched_show_task(struct task_struct *p)
  {
                printk(KERN_CONT " %016lx ", thread_saved_pc(p));
  #endif
  #ifdef CONFIG_DEBUG_STACK_USAGE
 -      {
 -              unsigned long *n = end_of_stack(p);
 -              while (!*n)
 -                      n++;
 -              free = (unsigned long)n - (unsigned long)end_of_stack(p);
 -      }
 +      free = stack_not_used(p);
  #endif
        printk(KERN_CONT "%5lu %5d %6d\n", free,
                task_pid_nr(p), task_pid_nr(p->real_parent));
@@@ -5525,6 -5914,8 +5909,8 @@@ static inline void sched_init_granulari
                sysctl_sched_latency = limit;
  
        sysctl_sched_wakeup_granularity *= factor;
+       sysctl_sched_shares_ratelimit *= factor;
  }
  
  #ifdef CONFIG_SMP
@@@ -5566,6 -5957,12 +5952,12 @@@ int set_cpus_allowed_ptr(struct task_st
                goto out;
        }
  
+       if (unlikely((p->flags & PF_THREAD_BOUND) && p != current &&
+                    !cpus_equal(p->cpus_allowed, *new_mask))) {
+               ret = -EINVAL;
+               goto out;
+       }
        if (p->sched_class->set_cpus_allowed)
                p->sched_class->set_cpus_allowed(p, new_mask);
        else {
@@@ -5608,7 -6005,7 +6000,7 @@@ static int __migrate_task(struct task_s
        struct rq *rq_dest, *rq_src;
        int ret = 0, on_rq;
  
-       if (unlikely(cpu_is_offline(dest_cpu)))
+       if (unlikely(!cpu_active(dest_cpu)))
                return ret;
  
        rq_src = cpu_rq(src_cpu);
        double_rq_lock(rq_src, rq_dest);
        /* Already moved. */
        if (task_cpu(p) != src_cpu)
-               goto out;
+               goto done;
        /* Affinity changed (again). */
        if (!cpu_isset(dest_cpu, p->cpus_allowed))
-               goto out;
+               goto fail;
  
        on_rq = p->se.on_rq;
        if (on_rq)
        set_task_cpu(p, dest_cpu);
        if (on_rq) {
                activate_task(rq_dest, p, 0);
-               check_preempt_curr(rq_dest, p);
+               check_preempt_curr(rq_dest, p, 0);
        }
+ done:
        ret = 1;
out:
fail:
        double_rq_unlock(rq_src, rq_dest);
        return ret;
  }
@@@ -5882,6 -6280,7 +6275,7 @@@ static void migrate_dead_tasks(unsigne
                next = pick_next_task(rq, rq->curr);
                if (!next)
                        break;
+               next->sched_class->put_prev_task(rq, next);
                migrate_dead(dead_cpu, next);
  
        }
@@@ -5952,7 -6351,7 +6346,7 @@@ set_table_entry(struct ctl_table *entry
  static struct ctl_table *
  sd_alloc_ctl_domain_table(struct sched_domain *sd)
  {
-       struct ctl_table *table = sd_alloc_ctl_entry(12);
+       struct ctl_table *table = sd_alloc_ctl_entry(13);
  
        if (table == NULL)
                return NULL;
                sizeof(int), 0644, proc_dointvec_minmax);
        set_table_entry(&table[10], "flags", &sd->flags,
                sizeof(int), 0644, proc_dointvec_minmax);
-       /* &table[11] is terminator */
+       set_table_entry(&table[11], "name", sd->name,
+               CORENAME_MAX_SIZE, 0444, proc_dostring);
+       /* &table[12] is terminator */
  
        return table;
  }
@@@ -6053,6 -6454,36 +6449,36 @@@ static void unregister_sched_domain_sys
  }
  #endif
  
+ static void set_rq_online(struct rq *rq)
+ {
+       if (!rq->online) {
+               const struct sched_class *class;
+               cpu_set(rq->cpu, rq->rd->online);
+               rq->online = 1;
+               for_each_class(class) {
+                       if (class->rq_online)
+                               class->rq_online(rq);
+               }
+       }
+ }
+ static void set_rq_offline(struct rq *rq)
+ {
+       if (rq->online) {
+               const struct sched_class *class;
+               for_each_class(class) {
+                       if (class->rq_offline)
+                               class->rq_offline(rq);
+               }
+               cpu_clear(rq->cpu, rq->rd->online);
+               rq->online = 0;
+       }
+ }
  /*
   * migration_call - callback that gets triggered when a CPU is added.
   * Here we can start up the necessary migration thread for the new CPU.
@@@ -6090,7 -6521,8 +6516,8 @@@ migration_call(struct notifier_block *n
                spin_lock_irqsave(&rq->lock, flags);
                if (rq->rd) {
                        BUG_ON(!cpu_isset(cpu, rq->rd->span));
-                       cpu_set(cpu, rq->rd->online);
+                       set_rq_online(rq);
                }
                spin_unlock_irqrestore(&rq->lock, flags);
                break;
                spin_lock_irqsave(&rq->lock, flags);
                if (rq->rd) {
                        BUG_ON(!cpu_isset(cpu, rq->rd->span));
-                       cpu_clear(cpu, rq->rd->online);
+                       set_rq_offline(rq);
                }
                spin_unlock_irqrestore(&rq->lock, flags);
                break;
@@@ -6168,7 -6600,7 +6595,7 @@@ static struct notifier_block __cpuinitd
        .priority = 10
  };
  
void __init migration_init(void)
static int __init migration_init(void)
  {
        void *cpu = (void *)(long)smp_processor_id();
        int err;
        BUG_ON(err == NOTIFY_BAD);
        migration_call(&migration_notifier, CPU_ONLINE, cpu);
        register_cpu_notifier(&migration_notifier);
+       return err;
  }
+ early_initcall(migration_init);
  #endif
  
  #ifdef CONFIG_SMP
  
  #ifdef CONFIG_SCHED_DEBUG
  
+ static inline const char *sd_level_to_string(enum sched_domain_level lvl)
+ {
+       switch (lvl) {
+       case SD_LV_NONE:
+                       return "NONE";
+       case SD_LV_SIBLING:
+                       return "SIBLING";
+       case SD_LV_MC:
+                       return "MC";
+       case SD_LV_CPU:
+                       return "CPU";
+       case SD_LV_NODE:
+                       return "NODE";
+       case SD_LV_ALLNODES:
+                       return "ALLNODES";
+       case SD_LV_MAX:
+                       return "MAX";
+       }
+       return "MAX";
+ }
  static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
                                  cpumask_t *groupmask)
  {
                return -1;
        }
  
-       printk(KERN_CONT "span %s\n", str);
+       printk(KERN_CONT "span %s level %s\n",
+               str, sd_level_to_string(sd->level));
  
        if (!cpu_isset(cpu, sd->span)) {
                printk(KERN_ERR "ERROR: domain->span does not contain "
@@@ -6288,9 -6746,9 +6741,9 @@@ static void sched_domain_debug(struct s
        }
        kfree(groupmask);
  }
- #else
+ #else /* !CONFIG_SCHED_DEBUG */
  # define sched_domain_debug(sd, cpu) do { } while (0)
- #endif
+ #endif /* CONFIG_SCHED_DEBUG */
  
  static int sd_degenerate(struct sched_domain *sd)
  {
@@@ -6350,20 -6808,16 +6803,16 @@@ sd_parent_degenerate(struct sched_domai
  static void rq_attach_root(struct rq *rq, struct root_domain *rd)
  {
        unsigned long flags;
-       const struct sched_class *class;
  
        spin_lock_irqsave(&rq->lock, flags);
  
        if (rq->rd) {
                struct root_domain *old_rd = rq->rd;
  
-               for (class = sched_class_highest; class; class = class->next) {
-                       if (class->leave_domain)
-                               class->leave_domain(rq);
-               }
+               if (cpu_isset(rq->cpu, old_rd->online))
+                       set_rq_offline(rq);
  
                cpu_clear(rq->cpu, old_rd->span);
-               cpu_clear(rq->cpu, old_rd->online);
  
                if (atomic_dec_and_test(&old_rd->refcount))
                        kfree(old_rd);
  
        cpu_set(rq->cpu, rd->span);
        if (cpu_isset(rq->cpu, cpu_online_map))
-               cpu_set(rq->cpu, rd->online);
-       for (class = sched_class_highest; class; class = class->next) {
-               if (class->join_domain)
-                       class->join_domain(rq);
-       }
+               set_rq_online(rq);
  
        spin_unlock_irqrestore(&rq->lock, flags);
  }
@@@ -6390,6 -6839,8 +6834,8 @@@ static void init_rootdomain(struct root
  
        cpus_clear(rd->span);
        cpus_clear(rd->online);
+       cpupri_init(&rd->cpupri);
  }
  
  static void init_defrootdomain(void)
@@@ -6451,7 -6902,8 +6897,8 @@@ static cpumask_t cpu_isolated_map = CPU
  /* Setup the mask of cpus configured for isolated domains */
  static int __init isolated_cpu_setup(char *str)
  {
-       int ints[NR_CPUS], i;
+       static int __initdata ints[NR_CPUS];
+       int i;
  
        str = get_options(str, ARRAY_SIZE(ints), ints);
        cpus_clear(cpu_isolated_map);
@@@ -6485,7 -6937,7 +6932,7 @@@ init_sched_build_groups(const cpumask_
  
        cpus_clear(*covered);
  
-       for_each_cpu_mask(i, *span) {
+       for_each_cpu_mask_nr(i, *span) {
                struct sched_group *sg;
                int group = group_fn(i, cpu_map, &sg, tmpmask);
                int j;
                cpus_clear(sg->cpumask);
                sg->__cpu_power = 0;
  
-               for_each_cpu_mask(j, *span) {
+               for_each_cpu_mask_nr(j, *span) {
                        if (group_fn(j, cpu_map, NULL, tmpmask) != group)
                                continue;
  
@@@ -6532,9 -6984,9 +6979,9 @@@ static int find_next_best_node(int node
  
        min_val = INT_MAX;
  
-       for (i = 0; i < MAX_NUMNODES; i++) {
+       for (i = 0; i < nr_node_ids; i++) {
                /* Start at @node */
-               n = (node + i) % MAX_NUMNODES;
+               n = (node + i) % nr_node_ids;
  
                if (!nr_cpus_node(n))
                        continue;
@@@ -6584,7 -7036,7 +7031,7 @@@ static void sched_domain_node_span(int 
                cpus_or(*span, *span, *nodemask);
        }
  }
- #endif
+ #endif /* CONFIG_NUMA */
  
  int sched_smt_power_savings = 0, sched_mc_power_savings = 0;
  
@@@ -6603,7 -7055,7 +7050,7 @@@ cpu_to_cpu_group(int cpu, const cpumask
                *sg = &per_cpu(sched_group_cpus, cpu);
        return cpu;
  }
- #endif
+ #endif /* CONFIG_SCHED_SMT */
  
  /*
   * multi-core sched-domains:
  #ifdef CONFIG_SCHED_MC
  static DEFINE_PER_CPU(struct sched_domain, core_domains);
  static DEFINE_PER_CPU(struct sched_group, sched_group_core);
- #endif
+ #endif /* CONFIG_SCHED_MC */
  
  #if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT)
  static int
@@@ -6696,7 -7148,7 +7143,7 @@@ static void init_numa_sched_groups_powe
        if (!sg)
                return;
        do {
-               for_each_cpu_mask(j, sg->cpumask) {
+               for_each_cpu_mask_nr(j, sg->cpumask) {
                        struct sched_domain *sd;
  
                        sd = &per_cpu(phys_domains, j);
                sg = sg->next;
        } while (sg != group_head);
  }
- #endif
+ #endif /* CONFIG_NUMA */
  
  #ifdef CONFIG_NUMA
  /* Free memory allocated for various sched_group structures */
@@@ -6721,14 -7173,14 +7168,14 @@@ static void free_sched_groups(const cpu
  {
        int cpu, i;
  
-       for_each_cpu_mask(cpu, *cpu_map) {
+       for_each_cpu_mask_nr(cpu, *cpu_map) {
                struct sched_group **sched_group_nodes
                        = sched_group_nodes_bycpu[cpu];
  
                if (!sched_group_nodes)
                        continue;
  
-               for (i = 0; i < MAX_NUMNODES; i++) {
+               for (i = 0; i < nr_node_ids; i++) {
                        struct sched_group *oldsg, *sg = sched_group_nodes[i];
  
                        *nodemask = node_to_cpumask(i);
@@@ -6750,11 -7202,11 +7197,11 @@@ next_sg
                sched_group_nodes_bycpu[cpu] = NULL;
        }
  }
- #else
+ #else /* !CONFIG_NUMA */
  static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask)
  {
  }
- #endif
+ #endif /* CONFIG_NUMA */
  
  /*
   * Initialize sched groups cpu_power.
@@@ -6813,13 -7265,21 +7260,21 @@@ static void init_sched_groups_power(in
   * Non-inlined to reduce accumulated stack pressure in build_sched_domains()
   */
  
+ #ifdef CONFIG_SCHED_DEBUG
+ # define SD_INIT_NAME(sd, type)               sd->name = #type
+ #else
+ # define SD_INIT_NAME(sd, type)               do { } while (0)
+ #endif
  #define       SD_INIT(sd, type)       sd_init_##type(sd)
  #define SD_INIT_FUNC(type)    \
  static noinline void sd_init_##type(struct sched_domain *sd)  \
  {                                                             \
        memset(sd, 0, sizeof(*sd));                             \
        *sd = SD_##type##_INIT;                                 \
        sd->level = SD_LV_##type;                               \
+       SD_INIT_NAME(sd, type);                                 \
  }
  
  SD_INIT_FUNC(CPU)
@@@ -6921,7 -7381,7 +7376,7 @@@ static int __build_sched_domains(const 
        /*
         * Allocate the per-node list of sched groups
         */
-       sched_group_nodes = kcalloc(MAX_NUMNODES, sizeof(struct sched_group *),
+       sched_group_nodes = kcalloc(nr_node_ids, sizeof(struct sched_group *),
                                    GFP_KERNEL);
        if (!sched_group_nodes) {
                printk(KERN_WARNING "Can not alloc sched group node list\n");
        /*
         * Set up domains for cpus specified by the cpu_map.
         */
-       for_each_cpu_mask(i, *cpu_map) {
+       for_each_cpu_mask_nr(i, *cpu_map) {
                struct sched_domain *sd = NULL, *p;
                SCHED_CPUMASK_VAR(nodemask, allmasks);
  
  
  #ifdef CONFIG_SCHED_SMT
        /* Set up CPU (sibling) groups */
-       for_each_cpu_mask(i, *cpu_map) {
+       for_each_cpu_mask_nr(i, *cpu_map) {
                SCHED_CPUMASK_VAR(this_sibling_map, allmasks);
                SCHED_CPUMASK_VAR(send_covered, allmasks);
  
  
  #ifdef CONFIG_SCHED_MC
        /* Set up multi-core groups */
-       for_each_cpu_mask(i, *cpu_map) {
+       for_each_cpu_mask_nr(i, *cpu_map) {
                SCHED_CPUMASK_VAR(this_core_map, allmasks);
                SCHED_CPUMASK_VAR(send_covered, allmasks);
  
  #endif
  
        /* Set up physical groups */
-       for (i = 0; i < MAX_NUMNODES; i++) {
+       for (i = 0; i < nr_node_ids; i++) {
                SCHED_CPUMASK_VAR(nodemask, allmasks);
                SCHED_CPUMASK_VAR(send_covered, allmasks);
  
                                        send_covered, tmpmask);
        }
  
-       for (i = 0; i < MAX_NUMNODES; i++) {
+       for (i = 0; i < nr_node_ids; i++) {
                /* Set up node groups */
                struct sched_group *sg, *prev;
                SCHED_CPUMASK_VAR(nodemask, allmasks);
                        goto error;
                }
                sched_group_nodes[i] = sg;
-               for_each_cpu_mask(j, *nodemask) {
+               for_each_cpu_mask_nr(j, *nodemask) {
                        struct sched_domain *sd;
  
                        sd = &per_cpu(node_domains, j);
                cpus_or(*covered, *covered, *nodemask);
                prev = sg;
  
-               for (j = 0; j < MAX_NUMNODES; j++) {
+               for (j = 0; j < nr_node_ids; j++) {
                        SCHED_CPUMASK_VAR(notcovered, allmasks);
-                       int n = (i + j) % MAX_NUMNODES;
+                       int n = (i + j) % nr_node_ids;
                        node_to_cpumask_ptr(pnodemask, n);
  
                        cpus_complement(*notcovered, *covered);
  
        /* Calculate CPU power for physical packages and nodes */
  #ifdef CONFIG_SCHED_SMT
-       for_each_cpu_mask(i, *cpu_map) {
+       for_each_cpu_mask_nr(i, *cpu_map) {
                struct sched_domain *sd = &per_cpu(cpu_domains, i);
  
                init_sched_groups_power(i, sd);
        }
  #endif
  #ifdef CONFIG_SCHED_MC
-       for_each_cpu_mask(i, *cpu_map) {
+       for_each_cpu_mask_nr(i, *cpu_map) {
                struct sched_domain *sd = &per_cpu(core_domains, i);
  
                init_sched_groups_power(i, sd);
        }
  #endif
  
-       for_each_cpu_mask(i, *cpu_map) {
+       for_each_cpu_mask_nr(i, *cpu_map) {
                struct sched_domain *sd = &per_cpu(phys_domains, i);
  
                init_sched_groups_power(i, sd);
        }
  
  #ifdef CONFIG_NUMA
-       for (i = 0; i < MAX_NUMNODES; i++)
+       for (i = 0; i < nr_node_ids; i++)
                init_numa_sched_groups_power(sched_group_nodes[i]);
  
        if (sd_allnodes) {
  #endif
  
        /* Attach the domains */
-       for_each_cpu_mask(i, *cpu_map) {
+       for_each_cpu_mask_nr(i, *cpu_map) {
                struct sched_domain *sd;
  #ifdef CONFIG_SCHED_SMT
                sd = &per_cpu(cpu_domains, i);
@@@ -7235,18 -7695,6 +7690,6 @@@ void __attribute__((weak)) arch_update_
  {
  }
  
- /*
-  * Free current domain masks.
-  * Called after all cpus are attached to NULL domain.
-  */
- static void free_sched_domains(void)
- {
-       ndoms_cur = 0;
-       if (doms_cur != &fallback_doms)
-               kfree(doms_cur);
-       doms_cur = &fallback_doms;
- }
  /*
   * Set up scheduler domains and groups. Callers must hold the hotplug lock.
   * For now this just excludes isolated cpus, but could be used to
@@@ -7286,7 -7734,7 +7729,7 @@@ static void detach_destroy_domains(cons
  
        unregister_sched_domain_sysctl();
  
-       for_each_cpu_mask(i, *cpu_map)
+       for_each_cpu_mask_nr(i, *cpu_map)
                cpu_attach_domain(NULL, &def_root_domain, i);
        synchronize_sched();
        arch_destroy_sched_domains(cpu_map, &tmpmask);
@@@ -7325,30 -7773,29 +7768,29 @@@ static int dattrs_equal(struct sched_do
   * ownership of it and will kfree it when done with it. If the caller
   * failed the kmalloc call, then it can pass in doms_new == NULL,
   * and partition_sched_domains() will fallback to the single partition
-  * 'fallback_doms'.
+  * 'fallback_doms', it also forces the domains to be rebuilt.
+  *
+  * If doms_new==NULL it will be replaced with cpu_online_map.
+  * ndoms_new==0 is a special case for destroying existing domains.
+  * It will not create the default domain.
   *
   * Call with hotplug lock held
   */
  void partition_sched_domains(int ndoms_new, cpumask_t *doms_new,
                             struct sched_domain_attr *dattr_new)
  {
-       int i, j;
+       int i, j, n;
  
        mutex_lock(&sched_domains_mutex);
  
        /* always unregister in case we don't destroy any domains */
        unregister_sched_domain_sysctl();
  
-       if (doms_new == NULL) {
-               ndoms_new = 1;
-               doms_new = &fallback_doms;
-               cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map);
-               dattr_new = NULL;
-       }
+       n = doms_new ? ndoms_new : 0;
  
        /* Destroy deleted domains */
        for (i = 0; i < ndoms_cur; i++) {
-               for (j = 0; j < ndoms_new; j++) {
+               for (j = 0; j < n; j++) {
                        if (cpus_equal(doms_cur[i], doms_new[j])
                            && dattrs_equal(dattr_cur, i, dattr_new, j))
                                goto match1;
@@@ -7359,6 -7806,13 +7801,13 @@@ match1
                ;
        }
  
+       if (doms_new == NULL) {
+               ndoms_cur = 0;
+               doms_new = &fallback_doms;
+               cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map);
+               dattr_new = NULL;
+       }
        /* Build new domains */
        for (i = 0; i < ndoms_new; i++) {
                for (j = 0; j < ndoms_cur; j++) {
@@@ -7389,17 -7843,15 +7838,15 @@@ match2
  #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT)
  int arch_reinit_sched_domains(void)
  {
-       int err;
        get_online_cpus();
-       mutex_lock(&sched_domains_mutex);
-       detach_destroy_domains(&cpu_online_map);
-       free_sched_domains();
-       err = arch_init_sched_domains(&cpu_online_map);
-       mutex_unlock(&sched_domains_mutex);
+       /* Destroy domains first to force the rebuild */
+       partition_sched_domains(0, NULL, NULL);
+       rebuild_sched_domains();
        put_online_cpus();
  
-       return err;
+       return 0;
  }
  
  static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt)
  }
  
  #ifdef CONFIG_SCHED_MC
- static ssize_t sched_mc_power_savings_show(struct sys_device *dev, char *page)
+ static ssize_t sched_mc_power_savings_show(struct sysdev_class *class,
+                                          char *page)
  {
        return sprintf(page, "%u\n", sched_mc_power_savings);
  }
- static ssize_t sched_mc_power_savings_store(struct sys_device *dev,
+ static ssize_t sched_mc_power_savings_store(struct sysdev_class *class,
                                            const char *buf, size_t count)
  {
        return sched_power_savings_store(buf, count, 0);
  }
- static SYSDEV_ATTR(sched_mc_power_savings, 0644, sched_mc_power_savings_show,
-                  sched_mc_power_savings_store);
+ static SYSDEV_CLASS_ATTR(sched_mc_power_savings, 0644,
+                        sched_mc_power_savings_show,
+                        sched_mc_power_savings_store);
  #endif
  
  #ifdef CONFIG_SCHED_SMT
- static ssize_t sched_smt_power_savings_show(struct sys_device *dev, char *page)
+ static ssize_t sched_smt_power_savings_show(struct sysdev_class *dev,
+                                           char *page)
  {
        return sprintf(page, "%u\n", sched_smt_power_savings);
  }
- static ssize_t sched_smt_power_savings_store(struct sys_device *dev,
+ static ssize_t sched_smt_power_savings_store(struct sysdev_class *dev,
                                             const char *buf, size_t count)
  {
        return sched_power_savings_store(buf, count, 1);
  }
- static SYSDEV_ATTR(sched_smt_power_savings, 0644, sched_smt_power_savings_show,
+ static SYSDEV_CLASS_ATTR(sched_smt_power_savings, 0644,
+                  sched_smt_power_savings_show,
                   sched_smt_power_savings_store);
  #endif
  
@@@ -7463,54 -7919,51 +7914,51 @@@ int sched_create_sysfs_power_savings_en
  #endif
        return err;
  }
- #endif
+ #endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */
  
+ #ifndef CONFIG_CPUSETS
  /*
-  * Force a reinitialization of the sched domains hierarchy. The domains
-  * and groups cannot be updated in place without racing with the balancing
-  * code, so we temporarily attach all running cpus to the NULL domain
-  * which will prevent rebalancing while the sched domains are recalculated.
+  * Add online and remove offline CPUs from the scheduler domains.
+  * When cpusets are enabled they take over this function.
   */
  static int update_sched_domains(struct notifier_block *nfb,
                                unsigned long action, void *hcpu)
  {
        switch (action) {
-       case CPU_UP_PREPARE:
-       case CPU_UP_PREPARE_FROZEN:
+       case CPU_ONLINE:
+       case CPU_ONLINE_FROZEN:
+       case CPU_DEAD:
+       case CPU_DEAD_FROZEN:
+               partition_sched_domains(1, NULL, NULL);
+               return NOTIFY_OK;
+       default:
+               return NOTIFY_DONE;
+       }
+ }
+ #endif
+ static int update_runtime(struct notifier_block *nfb,
+                               unsigned long action, void *hcpu)
+ {
+       int cpu = (int)(long)hcpu;
+       switch (action) {
        case CPU_DOWN_PREPARE:
        case CPU_DOWN_PREPARE_FROZEN:
-               detach_destroy_domains(&cpu_online_map);
-               free_sched_domains();
+               disable_runtime(cpu_rq(cpu));
                return NOTIFY_OK;
  
-       case CPU_UP_CANCELED:
-       case CPU_UP_CANCELED_FROZEN:
        case CPU_DOWN_FAILED:
        case CPU_DOWN_FAILED_FROZEN:
        case CPU_ONLINE:
        case CPU_ONLINE_FROZEN:
-       case CPU_DEAD:
-       case CPU_DEAD_FROZEN:
-               /*
-                * Fall through and re-initialise the domains.
-                */
-               break;
+               enable_runtime(cpu_rq(cpu));
+               return NOTIFY_OK;
        default:
                return NOTIFY_DONE;
        }
- #ifndef CONFIG_CPUSETS
-       /*
-        * Create default domain partitioning if cpusets are disabled.
-        * Otherwise we let cpusets rebuild the domains based on the
-        * current setup.
-        */
-       /* The hotplug lock is already held by cpu_up/cpu_down */
-       arch_init_sched_domains(&cpu_online_map);
- #endif
-       return NOTIFY_OK;
  }
  
  void __init sched_init_smp(void)
                cpu_set(smp_processor_id(), non_isolated_cpus);
        mutex_unlock(&sched_domains_mutex);
        put_online_cpus();
+ #ifndef CONFIG_CPUSETS
        /* XXX: Theoretical race here - CPU may be hotplugged now */
        hotcpu_notifier(update_sched_domains, 0);
+ #endif
+       /* RT runtime code needs to handle some hotplug events */
+       hotcpu_notifier(update_runtime, 0);
        init_hrtick();
  
        /* Move init over to a non-isolated CPU */
@@@ -7688,8 -8148,8 +8143,8 @@@ void __init sched_init(void
  
                root_task_group.cfs_rq = (struct cfs_rq **)ptr;
                ptr += nr_cpu_ids * sizeof(void **);
- #endif
- #endif
+ #endif /* CONFIG_USER_SCHED */
+ #endif /* CONFIG_FAIR_GROUP_SCHED */
  #ifdef CONFIG_RT_GROUP_SCHED
                init_task_group.rt_se = (struct sched_rt_entity **)ptr;
                ptr += nr_cpu_ids * sizeof(void **);
  
                root_task_group.rt_rq = (struct rt_rq **)ptr;
                ptr += nr_cpu_ids * sizeof(void **);
- #endif
- #endif
+ #endif /* CONFIG_USER_SCHED */
+ #endif /* CONFIG_RT_GROUP_SCHED */
        }
  
  #ifdef CONFIG_SMP
  #ifdef CONFIG_USER_SCHED
        init_rt_bandwidth(&root_task_group.rt_bandwidth,
                        global_rt_period(), RUNTIME_INF);
- #endif
- #endif
+ #endif /* CONFIG_USER_SCHED */
+ #endif /* CONFIG_RT_GROUP_SCHED */
  
  #ifdef CONFIG_GROUP_SCHED
        list_add(&init_task_group.list, &task_groups);
        INIT_LIST_HEAD(&root_task_group.children);
        init_task_group.parent = &root_task_group;
        list_add(&init_task_group.siblings, &root_task_group.children);
- #endif
- #endif
+ #endif /* CONFIG_USER_SCHED */
+ #endif /* CONFIG_GROUP_SCHED */
  
        for_each_possible_cpu(i) {
                struct rq *rq;
  
                rq = cpu_rq(i);
                spin_lock_init(&rq->lock);
-               lockdep_set_class(&rq->lock, &rq->rq_lock_key);
                rq->nr_running = 0;
                init_cfs_rq(&rq->cfs, rq);
                init_rt_rq(&rq->rt, rq);
                rq->next_balance = jiffies;
                rq->push_cpu = 0;
                rq->cpu = i;
+               rq->online = 0;
                rq->migration_thread = NULL;
                INIT_LIST_HEAD(&rq->migration_queue);
                rq_attach_root(rq, &def_root_domain);
  #endif
  
  #ifdef CONFIG_SMP
-       open_softirq(SCHED_SOFTIRQ, run_rebalance_domains, NULL);
+       open_softirq(SCHED_SOFTIRQ, run_rebalance_domains);
  #endif
  
  #ifdef CONFIG_RT_MUTEXES
@@@ -7861,20 -8321,25 +8316,25 @@@ void __might_sleep(char *file, int line
  #ifdef in_atomic
        static unsigned long prev_jiffy;        /* ratelimiting */
  
-       if ((in_atomic() || irqs_disabled()) &&
-           system_state == SYSTEM_RUNNING && !oops_in_progress) {
-               if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
-                       return;
-               prev_jiffy = jiffies;
-               printk(KERN_ERR "BUG: sleeping function called from invalid"
-                               " context at %s:%d\n", file, line);
-               printk("in_atomic():%d, irqs_disabled():%d\n",
-                       in_atomic(), irqs_disabled());
-               debug_show_held_locks(current);
-               if (irqs_disabled())
-                       print_irqtrace_events(current);
-               dump_stack();
-       }
+       if ((!in_atomic() && !irqs_disabled()) ||
+                   system_state != SYSTEM_RUNNING || oops_in_progress)
+               return;
+       if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
+               return;
+       prev_jiffy = jiffies;
+       printk(KERN_ERR
+               "BUG: sleeping function called from invalid context at %s:%d\n",
+                       file, line);
+       printk(KERN_ERR
+               "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n",
+                       in_atomic(), irqs_disabled(),
+                       current->pid, current->comm);
+       debug_show_held_locks(current);
+       if (irqs_disabled())
+               print_irqtrace_events(current);
+       dump_stack();
  #endif
  }
  EXPORT_SYMBOL(__might_sleep);
@@@ -8051,7 -8516,7 +8511,7 @@@ static inline void unregister_fair_sche
  {
        list_del_rcu(&tg->cfs_rq[cpu]->leaf_cfs_rq_list);
  }
- #else
+ #else /* !CONFG_FAIR_GROUP_SCHED */
  static inline void free_fair_sched_group(struct task_group *tg)
  {
  }
@@@ -8069,7 -8534,7 +8529,7 @@@ static inline void register_fair_sched_
  static inline void unregister_fair_sched_group(struct task_group *tg, int cpu)
  {
  }
- #endif
+ #endif /* CONFIG_FAIR_GROUP_SCHED */
  
  #ifdef CONFIG_RT_GROUP_SCHED
  static void free_rt_sched_group(struct task_group *tg)
@@@ -8140,7 -8605,7 +8600,7 @@@ static inline void unregister_rt_sched_
  {
        list_del_rcu(&tg->rt_rq[cpu]->leaf_rt_rq_list);
  }
- #else
+ #else /* !CONFIG_RT_GROUP_SCHED */
  static inline void free_rt_sched_group(struct task_group *tg)
  {
  }
@@@ -8158,7 -8623,7 +8618,7 @@@ static inline void register_rt_sched_gr
  static inline void unregister_rt_sched_group(struct task_group *tg, int cpu)
  {
  }
- #endif
+ #endif /* CONFIG_RT_GROUP_SCHED */
  
  #ifdef CONFIG_GROUP_SCHED
  static void free_sched_group(struct task_group *tg)
@@@ -8195,8 -8660,8 +8655,8 @@@ struct task_group *sched_create_group(s
        WARN_ON(!parent); /* root should already exist */
  
        tg->parent = parent;
-       list_add_rcu(&tg->siblings, &parent->children);
        INIT_LIST_HEAD(&tg->children);
+       list_add_rcu(&tg->siblings, &parent->children);
        spin_unlock_irqrestore(&task_group_lock, flags);
  
        return tg;
@@@ -8269,17 -8734,14 +8729,14 @@@ void sched_move_task(struct task_struc
  
        task_rq_unlock(rq, &flags);
  }
- #endif
+ #endif /* CONFIG_GROUP_SCHED */
  
  #ifdef CONFIG_FAIR_GROUP_SCHED
- static void set_se_shares(struct sched_entity *se, unsigned long shares)
+ static void __set_se_shares(struct sched_entity *se, unsigned long shares)
  {
        struct cfs_rq *cfs_rq = se->cfs_rq;
-       struct rq *rq = cfs_rq->rq;
        int on_rq;
  
-       spin_lock_irq(&rq->lock);
        on_rq = se->on_rq;
        if (on_rq)
                dequeue_entity(cfs_rq, se, 0);
  
        if (on_rq)
                enqueue_entity(cfs_rq, se, 0);
+ }
  
-       spin_unlock_irq(&rq->lock);
+ static void set_se_shares(struct sched_entity *se, unsigned long shares)
+ {
+       struct cfs_rq *cfs_rq = se->cfs_rq;
+       struct rq *rq = cfs_rq->rq;
+       unsigned long flags;
+       spin_lock_irqsave(&rq->lock, flags);
+       __set_se_shares(se, shares);
+       spin_unlock_irqrestore(&rq->lock, flags);
  }
  
  static DEFINE_MUTEX(shares_mutex);
@@@ -8329,8 -8800,13 +8795,13 @@@ int sched_group_set_shares(struct task_
         * w/o tripping rebalance_share or load_balance_fair.
         */
        tg->shares = shares;
-       for_each_possible_cpu(i)
+       for_each_possible_cpu(i) {
+               /*
+                * force a rebalance
+                */
+               cfs_rq_set_shares(tg->cfs_rq[i], 0);
                set_se_shares(tg->se[i], shares);
+       }
  
        /*
         * Enable load balance activity on this group, by inserting it back on
@@@ -8361,73 -8837,95 +8832,95 @@@ static DEFINE_MUTEX(rt_constraints_mute
  static unsigned long to_ratio(u64 period, u64 runtime)
  {
        if (runtime == RUNTIME_INF)
-               return 1ULL << 16;
+               return 1ULL << 20;
  
-       return div64_u64(runtime << 16, period);
+       return div64_u64(runtime << 20, period);
  }
  
- #ifdef CONFIG_CGROUP_SCHED
- static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime)
+ /* Must be called with tasklist_lock held */
+ static inline int tg_has_rt_tasks(struct task_group *tg)
  {
-       struct task_group *tgi, *parent = tg ? tg->parent : NULL;
-       unsigned long total = 0;
+       struct task_struct *g, *p;
  
-       if (!parent) {
-               if (global_rt_period() < period)
-                       return 0;
+       do_each_thread(g, p) {
+               if (rt_task(p) && rt_rq_of_se(&p->rt)->tg == tg)
+                       return 1;
+       } while_each_thread(g, p);
  
-               return to_ratio(period, runtime) <
-                       to_ratio(global_rt_period(), global_rt_runtime());
-       }
+       return 0;
+ }
  
-       if (ktime_to_ns(parent->rt_bandwidth.rt_period) < period)
-               return 0;
+ struct rt_schedulable_data {
+       struct task_group *tg;
+       u64 rt_period;
+       u64 rt_runtime;
+ };
  
-       rcu_read_lock();
-       list_for_each_entry_rcu(tgi, &parent->children, siblings) {
-               if (tgi == tg)
-                       continue;
+ static int tg_schedulable(struct task_group *tg, void *data)
+ {
+       struct rt_schedulable_data *d = data;
+       struct task_group *child;
+       unsigned long total, sum = 0;
+       u64 period, runtime;
  
-               total += to_ratio(ktime_to_ns(tgi->rt_bandwidth.rt_period),
-                               tgi->rt_bandwidth.rt_runtime);
+       period = ktime_to_ns(tg->rt_bandwidth.rt_period);
+       runtime = tg->rt_bandwidth.rt_runtime;
+       if (tg == d->tg) {
+               period = d->rt_period;
+               runtime = d->rt_runtime;
        }
-       rcu_read_unlock();
  
-       return total + to_ratio(period, runtime) <
-               to_ratio(ktime_to_ns(parent->rt_bandwidth.rt_period),
-                               parent->rt_bandwidth.rt_runtime);
- }
- #elif defined CONFIG_USER_SCHED
- static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime)
- {
-       struct task_group *tgi;
-       unsigned long total = 0;
-       unsigned long global_ratio =
-               to_ratio(global_rt_period(), global_rt_runtime());
+       /*
+        * Cannot have more runtime than the period.
+        */
+       if (runtime > period && runtime != RUNTIME_INF)
+               return -EINVAL;
  
-       rcu_read_lock();
-       list_for_each_entry_rcu(tgi, &task_groups, list) {
-               if (tgi == tg)
-                       continue;
+       /*
+        * Ensure we don't starve existing RT tasks.
+        */
+       if (rt_bandwidth_enabled() && !runtime && tg_has_rt_tasks(tg))
+               return -EBUSY;
+       total = to_ratio(period, runtime);
  
-               total += to_ratio(ktime_to_ns(tgi->rt_bandwidth.rt_period),
-                               tgi->rt_bandwidth.rt_runtime);
+       /*
+        * Nobody can have more than the global setting allows.
+        */
+       if (total > to_ratio(global_rt_period(), global_rt_runtime()))
+               return -EINVAL;
+       /*
+        * The sum of our children's runtime should not exceed our own.
+        */
+       list_for_each_entry_rcu(child, &tg->children, siblings) {
+               period = ktime_to_ns(child->rt_bandwidth.rt_period);
+               runtime = child->rt_bandwidth.rt_runtime;
+               if (child == d->tg) {
+                       period = d->rt_period;
+                       runtime = d->rt_runtime;
+               }
+               sum += to_ratio(period, runtime);
        }
-       rcu_read_unlock();
  
-       return total + to_ratio(period, runtime) < global_ratio;
+       if (sum > total)
+               return -EINVAL;
+       return 0;
  }
- #endif
  
- /* Must be called with tasklist_lock held */
- static inline int tg_has_rt_tasks(struct task_group *tg)
+ static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime)
  {
-       struct task_struct *g, *p;
-       do_each_thread(g, p) {
-               if (rt_task(p) && rt_rq_of_se(&p->rt)->tg == tg)
-                       return 1;
-       } while_each_thread(g, p);
-       return 0;
+       struct rt_schedulable_data data = {
+               .tg = tg,
+               .rt_period = period,
+               .rt_runtime = runtime,
+       };
+       return walk_tg_tree(tg_schedulable, tg_nop, &data);
  }
  
  static int tg_set_bandwidth(struct task_group *tg,
  
        mutex_lock(&rt_constraints_mutex);
        read_lock(&tasklist_lock);
-       if (rt_runtime == 0 && tg_has_rt_tasks(tg)) {
-               err = -EBUSY;
-               goto unlock;
-       }
-       if (!__rt_schedulable(tg, rt_period, rt_runtime)) {
-               err = -EINVAL;
+       err = __rt_schedulable(tg, rt_period, rt_runtime);
+       if (err)
                goto unlock;
-       }
  
        spin_lock_irq(&tg->rt_bandwidth.rt_runtime_lock);
        tg->rt_bandwidth.rt_period = ns_to_ktime(rt_period);
@@@ -8496,6 -8989,9 +8984,9 @@@ int sched_group_set_rt_period(struct ta
        rt_period = (u64)rt_period_us * NSEC_PER_USEC;
        rt_runtime = tg->rt_bandwidth.rt_runtime;
  
+       if (rt_period == 0)
+               return -EINVAL;
        return tg_set_bandwidth(tg, rt_period, rt_runtime);
  }
  
@@@ -8510,21 -9006,38 +9001,38 @@@ long sched_group_rt_period(struct task_
  
  static int sched_rt_global_constraints(void)
  {
+       u64 runtime, period;
        int ret = 0;
  
+       if (sysctl_sched_rt_period <= 0)
+               return -EINVAL;
+       runtime = global_rt_runtime();
+       period = global_rt_period();
+       /*
+        * Sanity check on the sysctl variables.
+        */
+       if (runtime > period && runtime != RUNTIME_INF)
+               return -EINVAL;
        mutex_lock(&rt_constraints_mutex);
-       if (!__rt_schedulable(NULL, 1, 0))
-               ret = -EINVAL;
+       read_lock(&tasklist_lock);
+       ret = __rt_schedulable(NULL, 0, 0);
+       read_unlock(&tasklist_lock);
        mutex_unlock(&rt_constraints_mutex);
  
        return ret;
  }
- #else
+ #else /* !CONFIG_RT_GROUP_SCHED */
  static int sched_rt_global_constraints(void)
  {
        unsigned long flags;
        int i;
  
+       if (sysctl_sched_rt_period <= 0)
+               return -EINVAL;
        spin_lock_irqsave(&def_rt_bandwidth.rt_runtime_lock, flags);
        for_each_possible_cpu(i) {
                struct rt_rq *rt_rq = &cpu_rq(i)->rt;
  
        return 0;
  }
- #endif
+ #endif /* CONFIG_RT_GROUP_SCHED */
  
  int sched_rt_handler(struct ctl_table *table, int write,
                struct file *filp, void __user *buffer, size_t *lenp,
@@@ -8585,7 -9098,6 +9093,6 @@@ cpu_cgroup_create(struct cgroup_subsys 
  
        if (!cgrp->parent) {
                /* This is early initialization for the top cgroup */
-               init_task_group.css.cgroup = cgrp;
                return &init_task_group.css;
        }
  
        if (IS_ERR(tg))
                return ERR_PTR(-ENOMEM);
  
-       /* Bind the cgroup to task_group object we just created */
-       tg->css.cgroup = cgrp;
        return &tg->css;
  }
  
@@@ -8645,7 -9154,7 +9149,7 @@@ static u64 cpu_shares_read_u64(struct c
  
        return (u64) tg->shares;
  }
- #endif
+ #endif /* CONFIG_FAIR_GROUP_SCHED */
  
  #ifdef CONFIG_RT_GROUP_SCHED
  static int cpu_rt_runtime_write(struct cgroup *cgrp, struct cftype *cft,
@@@ -8669,7 -9178,7 +9173,7 @@@ static u64 cpu_rt_period_read_uint(stru
  {
        return sched_group_rt_period(cgroup_tg(cgrp));
  }
- #endif
+ #endif /* CONFIG_RT_GROUP_SCHED */
  
  static struct cftype cpu_files[] = {
  #ifdef CONFIG_FAIR_GROUP_SCHED