]> git.pld-linux.org Git - packages/kernel.git/blobdiff - kernel-rt.patch
- up to 4.9.162
[packages/kernel.git] / kernel-rt.patch
index b19eb6e32129adae576be016175d945dc650be4f..840aada4c0627bd874bacf5be3004deb9a3b9db8 100644 (file)
@@ -1,73 +1,3 @@
-diff --git a/Documentation/hwlat_detector.txt b/Documentation/hwlat_detector.txt
-new file mode 100644
-index 000000000000..cb61516483d3
---- /dev/null
-+++ b/Documentation/hwlat_detector.txt
-@@ -0,0 +1,64 @@
-+Introduction:
-+-------------
-+
-+The module hwlat_detector is a special purpose kernel module that is used to
-+detect large system latencies induced by the behavior of certain underlying
-+hardware or firmware, independent of Linux itself. The code was developed
-+originally to detect SMIs (System Management Interrupts) on x86 systems,
-+however there is nothing x86 specific about this patchset. It was
-+originally written for use by the "RT" patch since the Real Time
-+kernel is highly latency sensitive.
-+
-+SMIs are usually not serviced by the Linux kernel, which typically does not
-+even know that they are occuring. SMIs are instead are set up by BIOS code
-+and are serviced by BIOS code, usually for "critical" events such as
-+management of thermal sensors and fans. Sometimes though, SMIs are used for
-+other tasks and those tasks can spend an inordinate amount of time in the
-+handler (sometimes measured in milliseconds). Obviously this is a problem if
-+you are trying to keep event service latencies down in the microsecond range.
-+
-+The hardware latency detector works by hogging all of the cpus for configurable
-+amounts of time (by calling stop_machine()), polling the CPU Time Stamp Counter
-+for some period, then looking for gaps in the TSC data. Any gap indicates a
-+time when the polling was interrupted and since the machine is stopped and
-+interrupts turned off the only thing that could do that would be an SMI.
-+
-+Note that the SMI detector should *NEVER* be used in a production environment.
-+It is intended to be run manually to determine if the hardware platform has a
-+problem with long system firmware service routines.
-+
-+Usage:
-+------
-+
-+Loading the module hwlat_detector passing the parameter "enabled=1" (or by
-+setting the "enable" entry in "hwlat_detector" debugfs toggled on) is the only
-+step required to start the hwlat_detector. It is possible to redefine the
-+threshold in microseconds (us) above which latency spikes will be taken
-+into account (parameter "threshold=").
-+
-+Example:
-+
-+      # modprobe hwlat_detector enabled=1 threshold=100
-+
-+After the module is loaded, it creates a directory named "hwlat_detector" under
-+the debugfs mountpoint, "/debug/hwlat_detector" for this text. It is necessary
-+to have debugfs mounted, which might be on /sys/debug on your system.
-+
-+The /debug/hwlat_detector interface contains the following files:
-+
-+count                 - number of latency spikes observed since last reset
-+enable                        - a global enable/disable toggle (0/1), resets count
-+max                   - maximum hardware latency actually observed (usecs)
-+sample                        - a pipe from which to read current raw sample data
-+                        in the format <timestamp> <latency observed usecs>
-+                        (can be opened O_NONBLOCK for a single sample)
-+threshold             - minimum latency value to be considered (usecs)
-+width                 - time period to sample with CPUs held (usecs)
-+                        must be less than the total window size (enforced)
-+window                        - total period of sampling, width being inside (usecs)
-+
-+By default we will set width to 500,000 and window to 1,000,000, meaning that
-+we will sample every 1,000,000 usecs (1s) for 500,000 usecs (0.5s). If we
-+observe any latencies that exceed the threshold (initially 100 usecs),
-+then we write to a global sample ring buffer of 8K samples, which is
-+consumed by reading from the "sample" (pipe) debugfs file interface.
 diff --git a/Documentation/sysrq.txt b/Documentation/sysrq.txt
 index 3a3b30ac2a75..9e0745cafbd8 100644
 --- a/Documentation/sysrq.txt
@@ -284,27 +214,36 @@ index 000000000000..6f2aeabf7faa
 +is provided.
 +
 +These data are also reset when the wakeup histogram is reset.
-diff --git a/Makefile b/Makefile
-index b249529204cd..5d699d055995 100644
---- a/Makefile
-+++ b/Makefile
-@@ -398,12 +398,12 @@ KBUILD_CPPFLAGS := -D__KERNEL__
- KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-                  -fno-strict-aliasing -fno-common \
-                  -Werror-implicit-function-declaration \
--                 -Wno-format-security \
-+                 -Wno-format-security -fno-PIE \
-                  -std=gnu89
- KBUILD_AFLAGS_KERNEL :=
- KBUILD_CFLAGS_KERNEL :=
--KBUILD_AFLAGS   := -D__ASSEMBLY__
-+KBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-PIE
- KBUILD_AFLAGS_MODULE  := -DMODULE
- KBUILD_CFLAGS_MODULE  := -DMODULE
- KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
+diff --git a/MAINTAINERS b/MAINTAINERS
+index 63cefa62324c..be0ea1e5c4cc 100644
+--- a/MAINTAINERS
++++ b/MAINTAINERS
+@@ -5196,6 +5196,23 @@ F:      fs/fuse/
+ F:    include/uapi/linux/fuse.h
+ F:    Documentation/filesystems/fuse.txt
++FUTEX SUBSYSTEM
++M:    Thomas Gleixner <tglx@linutronix.de>
++M:    Ingo Molnar <mingo@redhat.com>
++R:    Peter Zijlstra <peterz@infradead.org>
++R:    Darren Hart <dvhart@infradead.org>
++L:    linux-kernel@vger.kernel.org
++T:    git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/core
++S:    Maintained
++F:    kernel/futex.c
++F:    kernel/futex_compat.c
++F:    include/asm-generic/futex.h
++F:    include/linux/futex.h
++F:    include/uapi/linux/futex.h
++F:    tools/testing/selftests/futex/
++F:    tools/perf/bench/futex*
++F:    Documentation/*futex*
++
+ FUTURE DOMAIN TMC-16x0 SCSI DRIVER (16-bit)
+ M:    Rik Faith <faith@cs.unc.edu>
+ L:    linux-scsi@vger.kernel.org
 diff --git a/arch/Kconfig b/arch/Kconfig
-index fd6e9712af81..085134ee13e9 100644
+index 659bdd079277..099fc0f5155e 100644
 --- a/arch/Kconfig
 +++ b/arch/Kconfig
 @@ -9,6 +9,7 @@ config OPROFILE
@@ -324,7 +263,7 @@ index fd6e9712af81..085134ee13e9 100644
           This option enables a transparent branch optimization that
         makes certain almost-always-true or almost-always-false branch
 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
-index a9c4e48bb7ec..6eefe4f32302 100644
+index b5d529fdffab..5715844e83e3 100644
 --- a/arch/arm/Kconfig
 +++ b/arch/arm/Kconfig
 @@ -36,7 +36,7 @@ config ARM
@@ -344,6 +283,19 @@ index a9c4e48bb7ec..6eefe4f32302 100644
        select HAVE_RCU_TABLE_FREE if (SMP && ARM_LPAE)
        select HAVE_REGS_AND_STACK_ACCESS_API
        select HAVE_SYSCALL_TRACEPOINTS
+diff --git a/arch/arm/include/asm/irq.h b/arch/arm/include/asm/irq.h
+index e53638c8ed8a..6095a1649865 100644
+--- a/arch/arm/include/asm/irq.h
++++ b/arch/arm/include/asm/irq.h
+@@ -22,6 +22,8 @@
+ #endif
+ #ifndef __ASSEMBLY__
++#include <linux/cpumask.h>
++
+ struct irqaction;
+ struct pt_regs;
+ extern void migrate_irqs(void);
 diff --git a/arch/arm/include/asm/switch_to.h b/arch/arm/include/asm/switch_to.h
 index 12ebfcc1d539..c962084605bc 100644
 --- a/arch/arm/include/asm/switch_to.h
@@ -426,7 +378,7 @@ diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
 index 9f157e7c51e7..468e224d76aa 100644
 --- a/arch/arm/kernel/entry-armv.S
 +++ b/arch/arm/kernel/entry-armv.S
-@@ -220,11 +220,18 @@ ENDPROC(__dabt_svc)
+@@ -220,11 +220,18 @@ __irq_svc:
  
  #ifdef CONFIG_PREEMPT
        ldr     r8, [tsk, #TI_PREEMPT]          @ get preempt count
@@ -447,7 +399,7 @@ index 9f157e7c51e7..468e224d76aa 100644
  #endif
  
        svc_exit r5, irq = 1                    @ return from exception
-@@ -239,8 +246,14 @@ ENDPROC(__irq_svc)
+@@ -239,8 +246,14 @@ svc_preempt:
  1:    bl      preempt_schedule_irq            @ irq en/disable is done inside
        ldr     r0, [tsk, #TI_FLAGS]            @ get new tasks TI_FLAGS
        tst     r0, #_TIF_NEED_RESCHED
@@ -467,7 +419,7 @@ diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
 index 10c3283d6c19..8872937862cc 100644
 --- a/arch/arm/kernel/entry-common.S
 +++ b/arch/arm/kernel/entry-common.S
-@@ -36,7 +36,9 @@
+@@ -36,7 +36,9 @@ ret_fast_syscall:
   UNWIND(.cantunwind   )
        disable_irq_notrace                     @ disable interrupts
        ldr     r1, [tsk, #TI_FLAGS]            @ re-check for syscall tracing
@@ -478,7 +430,7 @@ index 10c3283d6c19..8872937862cc 100644
        bne     fast_work_pending
  
        /* perform architecture specific actions before user return */
-@@ -62,8 +64,11 @@ ENDPROC(ret_fast_syscall)
+@@ -62,8 +64,11 @@ ret_fast_syscall:
        str     r0, [sp, #S_R0 + S_OFF]!        @ save returned r0
        disable_irq_notrace                     @ disable interrupts
        ldr     r1, [tsk, #TI_FLAGS]            @ re-check for syscall tracing
@@ -491,11 +443,42 @@ index 10c3283d6c19..8872937862cc 100644
   UNWIND(.fnend                )
  ENDPROC(ret_fast_syscall)
  
+diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
+index 69bda1a5707e..1f665acaa6a9 100644
+--- a/arch/arm/kernel/patch.c
++++ b/arch/arm/kernel/patch.c
+@@ -15,7 +15,7 @@ struct patch {
+       unsigned int insn;
+ };
+-static DEFINE_SPINLOCK(patch_lock);
++static DEFINE_RAW_SPINLOCK(patch_lock);
+ static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags)
+       __acquires(&patch_lock)
+@@ -32,7 +32,7 @@ static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags)
+               return addr;
+       if (flags)
+-              spin_lock_irqsave(&patch_lock, *flags);
++              raw_spin_lock_irqsave(&patch_lock, *flags);
+       else
+               __acquire(&patch_lock);
+@@ -47,7 +47,7 @@ static void __kprobes patch_unmap(int fixmap, unsigned long *flags)
+       clear_fixmap(fixmap);
+       if (flags)
+-              spin_unlock_irqrestore(&patch_lock, *flags);
++              raw_spin_unlock_irqrestore(&patch_lock, *flags);
+       else
+               __release(&patch_lock);
+ }
 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
-index 612eb530f33f..cd3006dc1fd3 100644
+index 91d2d5b01414..750550098b59 100644
 --- a/arch/arm/kernel/process.c
 +++ b/arch/arm/kernel/process.c
-@@ -323,6 +323,30 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
+@@ -322,6 +322,30 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
  }
  
  #ifdef CONFIG_MMU
@@ -541,7 +524,7 @@ index 7b8f2141427b..96541e00b74a 100644
                } else {
                        if (unlikely(!user_mode(regs)))
 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
-index 861521606c6d..e5ca865d321b 100644
+index 7dd14e8395e6..4cd7e3d98035 100644
 --- a/arch/arm/kernel/smp.c
 +++ b/arch/arm/kernel/smp.c
 @@ -234,8 +234,6 @@ int __cpu_disable(void)
@@ -619,10 +602,10 @@ index 0bee233fef9a..314cfb232a63 100644
        kfree(tab);
  }
 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
-index c94b90d43772..244dde72018a 100644
+index 19b5f5c1c0ff..82aa639e6737 100644
 --- a/arch/arm/kvm/arm.c
 +++ b/arch/arm/kvm/arm.c
-@@ -584,7 +584,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
+@@ -619,7 +619,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
                 * involves poking the GIC, which must be done in a
                 * non-preemptible context.
                 */
@@ -631,7 +614,7 @@ index c94b90d43772..244dde72018a 100644
                kvm_pmu_flush_hwstate(vcpu);
                kvm_timer_flush_hwstate(vcpu);
                kvm_vgic_flush_hwstate(vcpu);
-@@ -605,7 +605,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
+@@ -640,7 +640,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
                        kvm_pmu_sync_hwstate(vcpu);
                        kvm_timer_sync_hwstate(vcpu);
                        kvm_vgic_sync_hwstate(vcpu);
@@ -640,7 +623,7 @@ index c94b90d43772..244dde72018a 100644
                        continue;
                }
  
-@@ -661,7 +661,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
+@@ -696,7 +696,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  
                kvm_vgic_sync_hwstate(vcpu);
  
@@ -1000,10 +983,10 @@ index ea5a2277ee46..b988e081ac79 100644
        return pen_release != -1 ? -ENOSYS : 0;
  }
 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
-index 3a2e678b8d30..3ed1e9ba6a01 100644
+index f7861dc83182..ce47dfe25fb0 100644
 --- a/arch/arm/mm/fault.c
 +++ b/arch/arm/mm/fault.c
-@@ -430,6 +430,9 @@ do_translation_fault(unsigned long addr, unsigned int fsr,
+@@ -433,6 +433,9 @@ do_translation_fault(unsigned long addr, unsigned int fsr,
        if (addr < TASK_SIZE)
                return do_page_fault(addr, fsr, regs);
  
@@ -1013,7 +996,7 @@ index 3a2e678b8d30..3ed1e9ba6a01 100644
        if (user_mode(regs))
                goto bad_area;
  
-@@ -497,6 +500,9 @@ do_translation_fault(unsigned long addr, unsigned int fsr,
+@@ -500,6 +503,9 @@ do_translation_fault(unsigned long addr, unsigned int fsr,
  static int
  do_sect_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  {
@@ -1200,10 +1183,10 @@ index c2366510187a..6b60f582b738 100644
        return pen_release != -1 ? -ENOSYS : 0;
  }
 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
-index bc3f00f586f1..0f3df6d5154a 100644
+index cf57a7799a0f..78d1b49fbed5 100644
 --- a/arch/arm64/Kconfig
 +++ b/arch/arm64/Kconfig
-@@ -90,6 +90,7 @@ config ARM64
+@@ -91,6 +91,7 @@ config ARM64
        select HAVE_PERF_EVENTS
        select HAVE_PERF_REGS
        select HAVE_PERF_USER_STACK_DUMP
@@ -1211,7 +1194,7 @@ index bc3f00f586f1..0f3df6d5154a 100644
        select HAVE_REGS_AND_STACK_ACCESS_API
        select HAVE_RCU_TABLE_FREE
        select HAVE_SYSCALL_TRACEPOINTS
-@@ -689,7 +690,7 @@ config XEN_DOM0
+@@ -704,7 +705,7 @@ config XEN_DOM0
  
  config XEN
        bool "Xen guest support on ARM64"
@@ -1221,7 +1204,7 @@ index bc3f00f586f1..0f3df6d5154a 100644
        select PARAVIRT
        help
 diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h
-index abd64bd1f6d9..9170788ffa37 100644
+index e9ea5a6bd449..6c500ad63c6a 100644
 --- a/arch/arm64/include/asm/thread_info.h
 +++ b/arch/arm64/include/asm/thread_info.h
 @@ -49,6 +49,7 @@ struct thread_info {
@@ -1232,7 +1215,7 @@ index abd64bd1f6d9..9170788ffa37 100644
        int                     cpu;            /* cpu */
  };
  
-@@ -109,6 +110,7 @@ static inline struct thread_info *current_thread_info(void)
+@@ -112,6 +113,7 @@ static inline struct thread_info *current_thread_info(void)
  #define TIF_NEED_RESCHED      1
  #define TIF_NOTIFY_RESUME     2       /* callback before returning to user */
  #define TIF_FOREIGN_FPSTATE   3       /* CPU's FP state is not current's */
@@ -1240,7 +1223,7 @@ index abd64bd1f6d9..9170788ffa37 100644
  #define TIF_NOHZ              7
  #define TIF_SYSCALL_TRACE     8
  #define TIF_SYSCALL_AUDIT     9
-@@ -124,6 +126,7 @@ static inline struct thread_info *current_thread_info(void)
+@@ -127,6 +129,7 @@ static inline struct thread_info *current_thread_info(void)
  #define _TIF_NEED_RESCHED     (1 << TIF_NEED_RESCHED)
  #define _TIF_NOTIFY_RESUME    (1 << TIF_NOTIFY_RESUME)
  #define _TIF_FOREIGN_FPSTATE  (1 << TIF_FOREIGN_FPSTATE)
@@ -1248,21 +1231,22 @@ index abd64bd1f6d9..9170788ffa37 100644
  #define _TIF_NOHZ             (1 << TIF_NOHZ)
  #define _TIF_SYSCALL_TRACE    (1 << TIF_SYSCALL_TRACE)
  #define _TIF_SYSCALL_AUDIT    (1 << TIF_SYSCALL_AUDIT)
-@@ -132,7 +135,8 @@ static inline struct thread_info *current_thread_info(void)
+@@ -135,7 +138,9 @@ static inline struct thread_info *current_thread_info(void)
  #define _TIF_32BIT            (1 << TIF_32BIT)
  
  #define _TIF_WORK_MASK                (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
 -                               _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE)
 +                               _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \
 +                               _TIF_NEED_RESCHED_LAZY)
++#define _TIF_NEED_RESCHED_MASK        (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
  
  #define _TIF_SYSCALL_WORK     (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
                                 _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
 diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
-index 05070b72fc28..acfeddb1283a 100644
+index c58ddf8c4062..a8f2f7c1fe12 100644
 --- a/arch/arm64/kernel/asm-offsets.c
 +++ b/arch/arm64/kernel/asm-offsets.c
-@@ -37,6 +37,7 @@ int main(void)
+@@ -38,6 +38,7 @@ int main(void)
    BLANK();
    DEFINE(TI_FLAGS,            offsetof(struct thread_info, flags));
    DEFINE(TI_PREEMPT,          offsetof(struct thread_info, preempt_count));
@@ -1271,10 +1255,10 @@ index 05070b72fc28..acfeddb1283a 100644
    DEFINE(TI_TASK,             offsetof(struct thread_info, task));
    DEFINE(TI_CPU,              offsetof(struct thread_info, cpu));
 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
-index 441420ca7d08..404792bdca99 100644
+index b4c7db434654..433d846f4f51 100644
 --- a/arch/arm64/kernel/entry.S
 +++ b/arch/arm64/kernel/entry.S
-@@ -434,11 +434,16 @@ ENDPROC(el1_sync)
+@@ -430,11 +430,16 @@ el1_irq:
  
  #ifdef CONFIG_PREEMPT
        ldr     w24, [tsk, #TI_PREEMPT]         // get preempt count
@@ -1294,7 +1278,7 @@ index 441420ca7d08..404792bdca99 100644
  #endif
  #ifdef CONFIG_TRACE_IRQFLAGS
        bl      trace_hardirqs_on
-@@ -452,6 +457,7 @@ ENDPROC(el1_irq)
+@@ -448,6 +453,7 @@ el1_preempt:
  1:    bl      preempt_schedule_irq            // irq en/disable is done inside
        ldr     x0, [tsk, #TI_FLAGS]            // get new tasks TI_FLAGS
        tbnz    x0, #TIF_NEED_RESCHED, 1b       // needs rescheduling?
@@ -1302,19 +1286,24 @@ index 441420ca7d08..404792bdca99 100644
        ret     x24
  #endif
  
-@@ -708,6 +714,7 @@ ENDPROC(cpu_switch_to)
-  */
- work_pending:
-       tbnz    x1, #TIF_NEED_RESCHED, work_resched
-+      tbnz    x1, #TIF_NEED_RESCHED_LAZY, work_resched
-       /* TIF_SIGPENDING, TIF_NOTIFY_RESUME or TIF_FOREIGN_FPSTATE case */
-       mov     x0, sp                          // 'regs'
-       enable_irq                              // enable interrupts for do_notify_resume()
+diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
+index 404dd67080b9..639dc6d12e72 100644
+--- a/arch/arm64/kernel/signal.c
++++ b/arch/arm64/kernel/signal.c
+@@ -409,7 +409,7 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,
+        */
+       trace_hardirqs_off();
+       do {
+-              if (thread_flags & _TIF_NEED_RESCHED) {
++              if (thread_flags & _TIF_NEED_RESCHED_MASK) {
+                       schedule();
+               } else {
+                       local_irq_enable();
 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
-index 212ff92920d2..71ad38d3d76b 100644
+index 5e844f68e847..dc613cc10f54 100644
 --- a/arch/mips/Kconfig
 +++ b/arch/mips/Kconfig
-@@ -2480,7 +2480,7 @@ config MIPS_ASID_BITS_VARIABLE
+@@ -2516,7 +2516,7 @@ config MIPS_ASID_BITS_VARIABLE
  #
  config HIGHMEM
        bool "High Memory Support"
@@ -1324,10 +1313,10 @@ index 212ff92920d2..71ad38d3d76b 100644
  config CPU_SUPPORTS_HIGHMEM
        bool
 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
-index 792cb1768c8f..ddf5a0fdb25a 100644
+index 6eda5abbd719..601e27701a4a 100644
 --- a/arch/powerpc/Kconfig
 +++ b/arch/powerpc/Kconfig
-@@ -57,10 +57,11 @@ config LOCKDEP_SUPPORT
+@@ -52,10 +52,11 @@ config LOCKDEP_SUPPORT
  
  config RWSEM_GENERIC_SPINLOCK
        bool
@@ -1340,7 +1329,7 @@ index 792cb1768c8f..ddf5a0fdb25a 100644
  
  config GENERIC_LOCKBREAK
        bool
-@@ -140,6 +141,7 @@ config PPC
+@@ -134,6 +135,7 @@ config PPC
        select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
        select GENERIC_STRNCPY_FROM_USER
        select GENERIC_STRNLEN_USER
@@ -1348,7 +1337,7 @@ index 792cb1768c8f..ddf5a0fdb25a 100644
        select HAVE_MOD_ARCH_SPECIFIC
        select MODULES_USE_ELF_RELA
        select CLONE_BACKWARDS
-@@ -326,7 +328,7 @@ menu "Kernel options"
+@@ -321,7 +323,7 @@ menu "Kernel options"
  
  config HIGHMEM
        bool "High memory support"
@@ -1408,7 +1397,7 @@ index 87e4b2d8dcd4..981e501a4359 100644
  /* Bits in local_flags */
  /* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
 diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
-index b89d14c0352c..81ae8f4c88f6 100644
+index c833d88c423d..96e9fbc3f684 100644
 --- a/arch/powerpc/kernel/asm-offsets.c
 +++ b/arch/powerpc/kernel/asm-offsets.c
 @@ -156,6 +156,7 @@ int main(void)
@@ -1420,10 +1409,10 @@ index b89d14c0352c..81ae8f4c88f6 100644
        DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  
 diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
-index 9899032230b4..f95b93f46c47 100644
+index 3841d749a430..6dbaeff192b9 100644
 --- a/arch/powerpc/kernel/entry_32.S
 +++ b/arch/powerpc/kernel/entry_32.S
-@@ -835,7 +835,14 @@ user_exc_return:          /* r10 contains MSR_KERNEL here */
+@@ -835,7 +835,14 @@ resume_kernel:
        cmpwi   0,r0,0          /* if non-zero, just restore regs and return */
        bne     restore
        andi.   r8,r8,_TIF_NEED_RESCHED
@@ -1438,7 +1427,7 @@ index 9899032230b4..f95b93f46c47 100644
        lwz     r3,_MSR(r1)
        andi.   r0,r3,MSR_EE    /* interrupts off? */
        beq     restore         /* don't schedule if so */
-@@ -846,11 +853,11 @@ user_exc_return:         /* r10 contains MSR_KERNEL here */
+@@ -846,11 +853,11 @@ resume_kernel:
         */
        bl      trace_hardirqs_off
  #endif
@@ -1453,7 +1442,7 @@ index 9899032230b4..f95b93f46c47 100644
  #ifdef CONFIG_TRACE_IRQFLAGS
        /* And now, to properly rebalance the above, we tell lockdep they
         * are being turned back on, which will happen when we return
-@@ -1171,7 +1178,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
+@@ -1171,7 +1178,7 @@ global_dbcr0:
  #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
  
  do_work:                      /* r10 contains MSR_KERNEL here */
@@ -1462,7 +1451,7 @@ index 9899032230b4..f95b93f46c47 100644
        beq     do_user_signal
  
  do_resched:                   /* r10 contains MSR_KERNEL here */
-@@ -1192,7 +1199,7 @@ do_resched:                      /* r10 contains MSR_KERNEL here */
+@@ -1192,7 +1199,7 @@ recheck:
        MTMSRD(r10)             /* disable interrupts */
        CURRENT_THREAD_INFO(r9, r1)
        lwz     r9,TI_FLAGS(r9)
@@ -1472,10 +1461,10 @@ index 9899032230b4..f95b93f46c47 100644
        andi.   r0,r9,_TIF_USER_WORK_MASK
        beq     restore_user
 diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
-index 5afd03e5e8b8..f5d4c2a033ef 100644
+index caa659671599..891080c4a41e 100644
 --- a/arch/powerpc/kernel/entry_64.S
 +++ b/arch/powerpc/kernel/entry_64.S
-@@ -657,7 +657,7 @@ _GLOBAL(ret_from_except_lite)
+@@ -656,7 +656,7 @@ _GLOBAL(ret_from_except_lite)
        bl      restore_math
        b       restore
  #endif
@@ -1484,29 +1473,27 @@ index 5afd03e5e8b8..f5d4c2a033ef 100644
        beq     2f
        bl      restore_interrupts
        SCHEDULE_USER
-@@ -719,10 +719,18 @@ _GLOBAL(ret_from_except_lite)
+@@ -718,10 +718,18 @@ resume_kernel:
  
  #ifdef CONFIG_PREEMPT
        /* Check if we need to preempt */
--      andi.   r0,r4,_TIF_NEED_RESCHED
--      beq+    restore
--      /* Check that preempt_count() == 0 and interrupts are enabled */
-       lwz     r8,TI_PREEMPT(r9)
++      lwz     r8,TI_PREEMPT(r9)
 +      cmpwi   0,r8,0          /* if non-zero, just restore regs and return */
 +      bne     restore
-+      andi.   r0,r4,_TIF_NEED_RESCHED
+       andi.   r0,r4,_TIF_NEED_RESCHED
 +      bne+    check_count
 +
 +      andi.   r0,r4,_TIF_NEED_RESCHED_LAZY
-+      beq+    restore
+       beq+    restore
 +      lwz     r8,TI_PREEMPT_LAZY(r9)
 +
-+      /* Check that preempt_count() == 0 and interrupts are enabled */
+       /* Check that preempt_count() == 0 and interrupts are enabled */
+-      lwz     r8,TI_PREEMPT(r9)
 +check_count:
        cmpwi   cr1,r8,0
        ld      r0,SOFTE(r1)
        cmpdi   r0,0
-@@ -739,7 +747,7 @@ _GLOBAL(ret_from_except_lite)
+@@ -738,7 +746,7 @@ resume_kernel:
        /* Re-test flags and eventually loop */
        CURRENT_THREAD_INFO(r9, r1)
        ld      r4,TI_FLAGS(r9)
@@ -1516,10 +1503,10 @@ index 5afd03e5e8b8..f5d4c2a033ef 100644
  
        /*
 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
-index 08887cf2b20e..f1770ea2d094 100644
+index 028a22bfa90c..a75e2dd3e71f 100644
 --- a/arch/powerpc/kernel/irq.c
 +++ b/arch/powerpc/kernel/irq.c
-@@ -633,6 +633,7 @@ void irq_ctx_init(void)
+@@ -651,6 +651,7 @@ void irq_ctx_init(void)
        }
  }
  
@@ -1527,7 +1514,7 @@ index 08887cf2b20e..f1770ea2d094 100644
  void do_softirq_own_stack(void)
  {
        struct thread_info *curtp, *irqtp;
-@@ -650,6 +651,7 @@ void do_softirq_own_stack(void)
+@@ -668,6 +669,7 @@ void do_softirq_own_stack(void)
        if (irqtp->flags)
                set_bits(irqtp->flags, &curtp->flags);
  }
@@ -1536,10 +1523,10 @@ index 08887cf2b20e..f1770ea2d094 100644
  irq_hw_number_t virq_to_hw(unsigned int virq)
  {
 diff --git a/arch/powerpc/kernel/misc_32.S b/arch/powerpc/kernel/misc_32.S
-index d9c912b6e632..7b2e997a5083 100644
+index 030d72df5dd5..b471a709e100 100644
 --- a/arch/powerpc/kernel/misc_32.S
 +++ b/arch/powerpc/kernel/misc_32.S
-@@ -40,6 +40,7 @@
+@@ -41,6 +41,7 @@
   * We store the saved ksp_limit in the unused part
   * of the STACK_FRAME_OVERHEAD
   */
@@ -1547,7 +1534,7 @@ index d9c912b6e632..7b2e997a5083 100644
  _GLOBAL(call_do_softirq)
        mflr    r0
        stw     r0,4(r1)
-@@ -56,6 +57,7 @@ _GLOBAL(call_do_softirq)
+@@ -57,6 +58,7 @@ _GLOBAL(call_do_softirq)
        stw     r10,THREAD+KSP_LIMIT(r2)
        mtlr    r0
        blr
@@ -1556,10 +1543,10 @@ index d9c912b6e632..7b2e997a5083 100644
  /*
   * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp);
 diff --git a/arch/powerpc/kernel/misc_64.S b/arch/powerpc/kernel/misc_64.S
-index cb195157b318..c919a2bfd0ca 100644
+index 4cefe6888b18..cb2ee4be999a 100644
 --- a/arch/powerpc/kernel/misc_64.S
 +++ b/arch/powerpc/kernel/misc_64.S
-@@ -30,6 +30,7 @@
+@@ -31,6 +31,7 @@
  
        .text
  
@@ -1567,7 +1554,7 @@ index cb195157b318..c919a2bfd0ca 100644
  _GLOBAL(call_do_softirq)
        mflr    r0
        std     r0,16(r1)
-@@ -40,6 +41,7 @@ _GLOBAL(call_do_softirq)
+@@ -41,6 +42,7 @@ _GLOBAL(call_do_softirq)
        ld      r0,16(r1)
        mtlr    r0
        blr
@@ -1576,10 +1563,10 @@ index cb195157b318..c919a2bfd0ca 100644
  _GLOBAL(call_do_irq)
        mflr    r0
 diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
-index c2024ac9d4e8..2303788da7e1 100644
+index 029be26b5a17..9528089ea142 100644
 --- a/arch/powerpc/kvm/Kconfig
 +++ b/arch/powerpc/kvm/Kconfig
-@@ -172,6 +172,7 @@ config KVM_E500MC
+@@ -175,6 +175,7 @@ config KVM_E500MC
  config KVM_MPIC
        bool "KVM in-kernel MPIC emulation"
        depends on KVM && E500
@@ -1588,7 +1575,7 @@ index c2024ac9d4e8..2303788da7e1 100644
        select HAVE_KVM_IRQFD
        select HAVE_KVM_IRQ_ROUTING
 diff --git a/arch/powerpc/platforms/ps3/device-init.c b/arch/powerpc/platforms/ps3/device-init.c
-index 57caaf11a83f..030c9bfe52e3 100644
+index e48462447ff0..2670cee66064 100644
 --- a/arch/powerpc/platforms/ps3/device-init.c
 +++ b/arch/powerpc/platforms/ps3/device-init.c
 @@ -752,7 +752,7 @@ static int ps3_notification_read_write(struct ps3_notification_device *dev,
@@ -1621,10 +1608,10 @@ index 6c0378c0b8b5..abd58b4dff97 100644
  static inline void handle_one_irq(unsigned int irq)
  {
 diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
-index 59b09600dd32..1b073eb3dc2a 100644
+index 8b4152f3a764..c5cca159692a 100644
 --- a/arch/sparc/Kconfig
 +++ b/arch/sparc/Kconfig
-@@ -187,12 +187,10 @@ config NR_CPUS
+@@ -194,12 +194,10 @@ config NR_CPUS
  source kernel/Kconfig.hz
  
  config RWSEM_GENERIC_SPINLOCK
@@ -1640,7 +1627,7 @@ index 59b09600dd32..1b073eb3dc2a 100644
  config GENERIC_HWEIGHT
        bool
 diff --git a/arch/sparc/kernel/irq_64.c b/arch/sparc/kernel/irq_64.c
-index 34a7930b76ef..773740521008 100644
+index 5cbf03c14981..6067d9379e5b 100644
 --- a/arch/sparc/kernel/irq_64.c
 +++ b/arch/sparc/kernel/irq_64.c
 @@ -854,6 +854,7 @@ void __irq_entry handler_irq(int pil, struct pt_regs *regs)
@@ -1660,7 +1647,7 @@ index 34a7930b76ef..773740521008 100644
  #ifdef CONFIG_HOTPLUG_CPU
  void fixup_irqs(void)
 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
-index 2a1f0ce7c59a..bd4ab87efb31 100644
+index b9c546a305a4..e96c2975af4f 100644
 --- a/arch/x86/Kconfig
 +++ b/arch/x86/Kconfig
 @@ -17,6 +17,7 @@ config X86_64
@@ -1671,7 +1658,7 @@ index 2a1f0ce7c59a..bd4ab87efb31 100644
        select ACPI_LEGACY_TABLES_LOOKUP        if ACPI
        select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
        select ANON_INODES
-@@ -231,8 +232,11 @@ config ARCH_MAY_HAVE_PC_FDC
+@@ -232,8 +233,11 @@ config ARCH_MAY_HAVE_PC_FDC
        def_bool y
        depends on ISA_DMA_API
  
@@ -1684,7 +1671,7 @@ index 2a1f0ce7c59a..bd4ab87efb31 100644
  
  config GENERIC_CALIBRATE_DELAY
        def_bool y
-@@ -885,7 +889,7 @@ config IOMMU_HELPER
+@@ -897,7 +901,7 @@ config IOMMU_HELPER
  config MAXSMP
        bool "Enable Maximum number of SMP Processors and NUMA Nodes"
        depends on X86_64 && SMP && DEBUG_KERNEL
@@ -1694,7 +1681,7 @@ index 2a1f0ce7c59a..bd4ab87efb31 100644
          Enable maximum number of CPUS and NUMA Nodes for this architecture.
          If unsure, say N.
 diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
-index 0ab5ee1c26af..fff8f6f1f90c 100644
+index aa8b0672f87a..2429414bfc71 100644
 --- a/arch/x86/crypto/aesni-intel_glue.c
 +++ b/arch/x86/crypto/aesni-intel_glue.c
 @@ -372,14 +372,14 @@ static int ecb_encrypt(struct blkcipher_desc *desc,
@@ -1992,10 +1979,10 @@ index 6a85598931b5..3a506ce7ed93 100644
  }
  EXPORT_SYMBOL_GPL(glue_xts_crypt_128bit);
 diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
-index 1433f6b4607d..f963fde8e4fa 100644
+index bdd9cc59d20f..56d01a339ba4 100644
 --- a/arch/x86/entry/common.c
 +++ b/arch/x86/entry/common.c
-@@ -136,7 +136,7 @@ static long syscall_trace_enter(struct pt_regs *regs)
+@@ -129,7 +129,7 @@ static long syscall_trace_enter(struct pt_regs *regs)
  
  #define EXIT_TO_USERMODE_LOOP_FLAGS                           \
        (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE |   \
@@ -2004,7 +1991,7 @@ index 1433f6b4607d..f963fde8e4fa 100644
  
  static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
  {
-@@ -152,9 +152,16 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
+@@ -145,9 +145,16 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
                /* We have work to do. */
                local_irq_enable();
  
@@ -2023,10 +2010,10 @@ index 1433f6b4607d..f963fde8e4fa 100644
                        uprobe_notify_resume(regs);
  
 diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S
-index 0b56666e6039..1d8ee026c9c5 100644
+index edba8606b99a..4a3389535fc6 100644
 --- a/arch/x86/entry/entry_32.S
 +++ b/arch/x86/entry/entry_32.S
-@@ -271,8 +271,25 @@ END(ret_from_exception)
+@@ -308,8 +308,25 @@ END(ret_from_exception)
  ENTRY(resume_kernel)
        DISABLE_INTERRUPTS(CLBR_ANY)
  need_resched:
@@ -2041,11 +2028,11 @@ index 0b56666e6039..1d8ee026c9c5 100644
 +      cmpl $_PREEMPT_ENABLED,PER_CPU_VAR(__preempt_count)
 +      jne restore_all
 +
-+      GET_THREAD_INFO(%ebp)
-+      cmpl $0,TI_preempt_lazy_count(%ebp)     # non-zero preempt_lazy_count ?
++      movl    PER_CPU_VAR(current_task), %ebp
++      cmpl $0,TASK_TI_preempt_lazy_count(%ebp)        # non-zero preempt_lazy_count ?
 +      jnz restore_all
 +
-+      testl $_TIF_NEED_RESCHED_LAZY, TI_flags(%ebp)
++      testl $_TIF_NEED_RESCHED_LAZY, TASK_TI_flags(%ebp)
 +      jz restore_all
 +test_int_off:
 +#endif
@@ -2053,10 +2040,10 @@ index 0b56666e6039..1d8ee026c9c5 100644
        jz      restore_all
        call    preempt_schedule_irq
 diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
-index 02fff3ebfb87..81ec3d016df0 100644
+index e7b0e7ff4c58..65916d49dbc9 100644
 --- a/arch/x86/entry/entry_64.S
 +++ b/arch/x86/entry/entry_64.S
-@@ -512,7 +512,23 @@ GLOBAL(retint_user)
+@@ -546,7 +546,23 @@ retint_kernel:
        bt      $9, EFLAGS(%rsp)                /* were interrupts off? */
        jnc     1f
  0:    cmpl    $0, PER_CPU_VAR(__preempt_count)
@@ -2069,18 +2056,18 @@ index 02fff3ebfb87..81ec3d016df0 100644
 +      cmpl $_PREEMPT_ENABLED,PER_CPU_VAR(__preempt_count)
 +      jnz     1f
 +
-+      GET_THREAD_INFO(%rcx)
-+      cmpl    $0, TI_preempt_lazy_count(%rcx)
++      movq    PER_CPU_VAR(current_task), %rcx
++      cmpl    $0, TASK_TI_preempt_lazy_count(%rcx)
 +      jnz     1f
 +
-+      bt      $TIF_NEED_RESCHED_LAZY,TI_flags(%rcx)
++      bt      $TIF_NEED_RESCHED_LAZY,TASK_TI_flags(%rcx)
 +      jnc     1f
 +do_preempt_schedule_irq:
 +#endif
        call    preempt_schedule_irq
        jmp     0b
  1:
-@@ -817,6 +833,7 @@ END(native_load_gs_index)
+@@ -894,6 +910,7 @@ bad_gs:
        jmp     2b
        .previous
  
@@ -2088,7 +2075,7 @@ index 02fff3ebfb87..81ec3d016df0 100644
  /* Call softirq on interrupt stack. Interrupts are off. */
  ENTRY(do_softirq_own_stack)
        pushq   %rbp
-@@ -829,6 +846,7 @@ ENTRY(do_softirq_own_stack)
+@@ -906,6 +923,7 @@ ENTRY(do_softirq_own_stack)
        decl    PER_CPU_VAR(irq_count)
        ret
  END(do_softirq_own_stack)
@@ -2149,12 +2136,12 @@ index 17f218645701..11bd1b7ee6eb 100644
  
  #ifdef CONFIG_PREEMPT
 diff --git a/arch/x86/include/asm/signal.h b/arch/x86/include/asm/signal.h
-index dd1e7d6387ab..d59bedb28bab 100644
+index 8af22be0fe61..d1328789b759 100644
 --- a/arch/x86/include/asm/signal.h
 +++ b/arch/x86/include/asm/signal.h
-@@ -23,6 +23,19 @@ typedef struct {
-       unsigned long sig[_NSIG_WORDS];
- } sigset_t;
+@@ -27,6 +27,19 @@ typedef struct {
+ #define SA_IA32_ABI   0x02000000u
+ #define SA_X32_ABI    0x01000000u
  
 +/*
 + * Because some traps use the IST stack, we must keep preemption
@@ -2202,19 +2189,25 @@ index 58505f01962f..02fa39652cd6 100644
        canary += tsc + (tsc << 32UL);
  
 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
-index 8b7c8d8e0852..631059ef61da 100644
+index ad6f5eb07a95..5ceb3a1c2b1a 100644
 --- a/arch/x86/include/asm/thread_info.h
 +++ b/arch/x86/include/asm/thread_info.h
-@@ -57,6 +57,8 @@ struct thread_info {
-       __u32                   flags;          /* low level flags */
-       __u32                   status;         /* thread synchronous flags */
-       __u32                   cpu;            /* current CPU */
-+      int                     preempt_lazy_count;     /* 0 => lazy preemptable
+@@ -54,11 +54,14 @@ struct task_struct;
+ struct thread_info {
+       unsigned long           flags;          /* low level flags */
++      int                     preempt_lazy_count;     /* 0 => lazy preemptable
 +                                                         <0 => BUG */
  };
  
  #define INIT_THREAD_INFO(tsk)                 \
-@@ -73,6 +75,10 @@ struct thread_info {
+ {                                             \
+       .flags          = 0,                    \
++      .preempt_lazy_count = 0,                \
+ }
+ #define init_stack            (init_thread_union.stack)
+@@ -67,6 +70,10 @@ struct thread_info {
  
  #include <asm/asm-offsets.h>
  
@@ -2225,7 +2218,7 @@ index 8b7c8d8e0852..631059ef61da 100644
  #endif
  
  /*
-@@ -91,6 +97,7 @@ struct thread_info {
+@@ -85,6 +92,7 @@ struct thread_info {
  #define TIF_SYSCALL_EMU               6       /* syscall emulation active */
  #define TIF_SYSCALL_AUDIT     7       /* syscall auditing active */
  #define TIF_SECCOMP           8       /* secure computing */
@@ -2233,7 +2226,7 @@ index 8b7c8d8e0852..631059ef61da 100644
  #define TIF_USER_RETURN_NOTIFY        11      /* notify kernel of userspace return */
  #define TIF_UPROBE            12      /* breakpointed or singlestepping */
  #define TIF_NOTSC             16      /* TSC is not accessible in userland */
-@@ -115,6 +122,7 @@ struct thread_info {
+@@ -108,6 +116,7 @@ struct thread_info {
  #define _TIF_SYSCALL_EMU      (1 << TIF_SYSCALL_EMU)
  #define _TIF_SYSCALL_AUDIT    (1 << TIF_SYSCALL_AUDIT)
  #define _TIF_SECCOMP          (1 << TIF_SECCOMP)
@@ -2241,7 +2234,7 @@ index 8b7c8d8e0852..631059ef61da 100644
  #define _TIF_USER_RETURN_NOTIFY       (1 << TIF_USER_RETURN_NOTIFY)
  #define _TIF_UPROBE           (1 << TIF_UPROBE)
  #define _TIF_NOTSC            (1 << TIF_NOTSC)
-@@ -151,6 +159,8 @@ struct thread_info {
+@@ -143,6 +152,8 @@ struct thread_info {
  #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
  #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
  
@@ -2251,10 +2244,10 @@ index 8b7c8d8e0852..631059ef61da 100644
  
  /*
 diff --git a/arch/x86/include/asm/uv/uv_bau.h b/arch/x86/include/asm/uv/uv_bau.h
-index cc44d926c17e..df278aa0f638 100644
+index 57ab86d94d64..35d25e27180f 100644
 --- a/arch/x86/include/asm/uv/uv_bau.h
 +++ b/arch/x86/include/asm/uv/uv_bau.h
-@@ -615,9 +615,9 @@ struct bau_control {
+@@ -624,9 +624,9 @@ struct bau_control {
        cycles_t                send_message;
        cycles_t                period_end;
        cycles_t                period_time;
@@ -2267,7 +2260,7 @@ index cc44d926c17e..df278aa0f638 100644
        /* tunables */
        int                     max_concurr;
        int                     max_concurr_const;
-@@ -776,15 +776,15 @@ static inline int atom_asr(short i, struct atomic_short *v)
+@@ -815,15 +815,15 @@ static inline int atom_asr(short i, struct atomic_short *v)
   * to be lowered below the current 'v'.  atomic_add_unless can only stop
   * on equal.
   */
@@ -2288,7 +2281,7 @@ index cc44d926c17e..df278aa0f638 100644
  }
  
 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
-index fbd19444403f..e78f477a4ae3 100644
+index b89bef95f63b..c3c1ad2fce5c 100644
 --- a/arch/x86/kernel/acpi/boot.c
 +++ b/arch/x86/kernel/acpi/boot.c
 @@ -87,7 +87,9 @@ static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
@@ -2302,7 +2295,7 @@ index fbd19444403f..e78f477a4ae3 100644
  /* --------------------------------------------------------------------------
                                Boot-time Configuration
 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
-index 48e6d84f173e..0b5a8b994f65 100644
+index cf89928dbd46..18b5ec2a71df 100644
 --- a/arch/x86/kernel/apic/io_apic.c
 +++ b/arch/x86/kernel/apic/io_apic.c
 @@ -1712,7 +1712,8 @@ static bool io_apic_level_ack_pending(struct mp_chip_data *data)
@@ -2316,25 +2309,25 @@ index 48e6d84f173e..0b5a8b994f65 100644
                return true;
        }
 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
-index 2bd5c6ff7ee7..a2c317f5839b 100644
+index c62e015b126c..0cc71257fca6 100644
 --- a/arch/x86/kernel/asm-offsets.c
 +++ b/arch/x86/kernel/asm-offsets.c
-@@ -31,6 +31,7 @@ void common(void) {
-       BLANK();
-       OFFSET(TI_flags, thread_info, flags);
-       OFFSET(TI_status, thread_info, status);
-+      OFFSET(TI_preempt_lazy_count, thread_info, preempt_lazy_count);
+@@ -36,6 +36,7 @@ void common(void) {
  
        BLANK();
+       OFFSET(TASK_TI_flags, task_struct, thread_info.flags);
++      OFFSET(TASK_TI_preempt_lazy_count, task_struct, thread_info.preempt_lazy_count);
        OFFSET(TASK_addr_limit, task_struct, thread.addr_limit);
-@@ -88,4 +89,5 @@ void common(void) {
+       BLANK();
+@@ -91,4 +92,5 @@ void common(void) {
  
        BLANK();
        DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
 +      DEFINE(_PREEMPT_ENABLED, PREEMPT_ENABLED);
  }
 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
-index 79d8ec849468..accbf0e806d0 100644
+index 8ca5f8ad008e..edcbd18b3189 100644
 --- a/arch/x86/kernel/cpu/mcheck/mce.c
 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
 @@ -41,6 +41,8 @@
@@ -2343,10 +2336,10 @@ index 79d8ec849468..accbf0e806d0 100644
  #include <linux/export.h>
 +#include <linux/jiffies.h>
 +#include <linux/swork.h>
+ #include <linux/jump_label.h>
  
  #include <asm/processor.h>
- #include <asm/traps.h>
-@@ -1291,7 +1293,7 @@ void mce_log_therm_throt_event(__u64 status)
+@@ -1306,7 +1308,7 @@ void mce_log_therm_throt_event(__u64 status)
  static unsigned long check_interval = INITIAL_CHECK_INTERVAL;
  
  static DEFINE_PER_CPU(unsigned long, mce_next_interval); /* in jiffies */
@@ -2355,7 +2348,7 @@ index 79d8ec849468..accbf0e806d0 100644
  
  static unsigned long mce_adjust_timer_default(unsigned long interval)
  {
-@@ -1300,32 +1302,18 @@ static unsigned long mce_adjust_timer_default(unsigned long interval)
+@@ -1315,32 +1317,18 @@ static unsigned long mce_adjust_timer_default(unsigned long interval)
  
  static unsigned long (*mce_adjust_timer)(unsigned long interval) = mce_adjust_timer_default;
  
@@ -2394,7 +2387,7 @@ index 79d8ec849468..accbf0e806d0 100644
        iv = __this_cpu_read(mce_next_interval);
  
        if (mce_available(this_cpu_ptr(&cpu_info))) {
-@@ -1348,7 +1336,7 @@ static void mce_timer_fn(unsigned long data)
+@@ -1363,7 +1351,7 @@ static void mce_timer_fn(unsigned long data)
  
  done:
        __this_cpu_write(mce_next_interval, iv);
@@ -2403,7 +2396,7 @@ index 79d8ec849468..accbf0e806d0 100644
  }
  
  /*
-@@ -1356,7 +1344,7 @@ static void mce_timer_fn(unsigned long data)
+@@ -1371,7 +1359,7 @@ static void mce_timer_fn(unsigned long data)
   */
  void mce_timer_kick(unsigned long interval)
  {
@@ -2412,7 +2405,7 @@ index 79d8ec849468..accbf0e806d0 100644
        unsigned long iv = __this_cpu_read(mce_next_interval);
  
        __restart_timer(t, interval);
-@@ -1371,7 +1359,7 @@ static void mce_timer_delete_all(void)
+@@ -1386,7 +1374,7 @@ static void mce_timer_delete_all(void)
        int cpu;
  
        for_each_online_cpu(cpu)
@@ -2421,7 +2414,7 @@ index 79d8ec849468..accbf0e806d0 100644
  }
  
  static void mce_do_trigger(struct work_struct *work)
-@@ -1381,6 +1369,56 @@ static void mce_do_trigger(struct work_struct *work)
+@@ -1396,6 +1384,56 @@ static void mce_do_trigger(struct work_struct *work)
  
  static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
  
@@ -2478,7 +2471,7 @@ index 79d8ec849468..accbf0e806d0 100644
  /*
   * Notify the user(s) about new machine check events.
   * Can be called from interrupt context, but not from machine check/NMI
-@@ -1388,19 +1426,8 @@ static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
+@@ -1403,19 +1441,8 @@ static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
   */
  int mce_notify_irq(void)
  {
@@ -2499,7 +2492,7 @@ index 79d8ec849468..accbf0e806d0 100644
                return 1;
        }
        return 0;
-@@ -1717,7 +1744,7 @@ static void __mcheck_cpu_clear_vendor(struct cpuinfo_x86 *c)
+@@ -1721,7 +1748,7 @@ static void __mcheck_cpu_clear_vendor(struct cpuinfo_x86 *c)
        }
  }
  
@@ -2508,7 +2501,7 @@ index 79d8ec849468..accbf0e806d0 100644
  {
        unsigned long iv = check_interval * HZ;
  
-@@ -1726,16 +1753,17 @@ static void mce_start_timer(unsigned int cpu, struct timer_list *t)
+@@ -1730,16 +1757,17 @@ static void mce_start_timer(unsigned int cpu, struct timer_list *t)
  
        per_cpu(mce_next_interval, cpu) = iv;
  
@@ -2530,7 +2523,7 @@ index 79d8ec849468..accbf0e806d0 100644
        mce_start_timer(cpu, t);
  }
  
-@@ -2459,6 +2487,8 @@ static void mce_disable_cpu(void *h)
+@@ -2464,6 +2492,8 @@ static void mce_disable_cpu(void *h)
        if (!mce_available(raw_cpu_ptr(&cpu_info)))
                return;
  
@@ -2539,7 +2532,7 @@ index 79d8ec849468..accbf0e806d0 100644
        if (!(action & CPU_TASKS_FROZEN))
                cmci_clear();
  
-@@ -2481,6 +2511,7 @@ static void mce_reenable_cpu(void *h)
+@@ -2486,6 +2516,7 @@ static void mce_reenable_cpu(void *h)
                if (b->init)
                        wrmsrl(msr_ops.ctl(i), b->ctl);
        }
@@ -2547,7 +2540,7 @@ index 79d8ec849468..accbf0e806d0 100644
  }
  
  /* Get notified when a cpu comes on/off. Be hotplug friendly. */
-@@ -2488,7 +2519,6 @@ static int
+@@ -2493,7 +2524,6 @@ static int
  mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
  {
        unsigned int cpu = (unsigned long)hcpu;
@@ -2555,7 +2548,7 @@ index 79d8ec849468..accbf0e806d0 100644
  
        switch (action & ~CPU_TASKS_FROZEN) {
        case CPU_ONLINE:
-@@ -2508,11 +2538,9 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
+@@ -2513,11 +2543,9 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
                break;
        case CPU_DOWN_PREPARE:
                smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
@@ -2567,7 +2560,7 @@ index 79d8ec849468..accbf0e806d0 100644
                break;
        }
  
-@@ -2551,6 +2579,10 @@ static __init int mcheck_init_device(void)
+@@ -2556,6 +2584,10 @@ static __init int mcheck_init_device(void)
                goto err_out;
        }
  
@@ -2578,68 +2571,6 @@ index 79d8ec849468..accbf0e806d0 100644
        if (!zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL)) {
                err = -ENOMEM;
                goto err_out;
-diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
-index 09675712eba8..eea7557b355d 100644
---- a/arch/x86/kernel/dumpstack_32.c
-+++ b/arch/x86/kernel/dumpstack_32.c
-@@ -42,7 +42,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
-               unsigned long *stack, unsigned long bp,
-               const struct stacktrace_ops *ops, void *data)
- {
--      const unsigned cpu = get_cpu();
-+      const unsigned cpu = get_cpu_light();
-       int graph = 0;
-       u32 *prev_esp;
-@@ -84,7 +84,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
-                       break;
-               touch_nmi_watchdog();
-       }
--      put_cpu();
-+      put_cpu_light();
- }
- EXPORT_SYMBOL(dump_trace);
-diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
-index 9ee4520ce83c..2cd610b68868 100644
---- a/arch/x86/kernel/dumpstack_64.c
-+++ b/arch/x86/kernel/dumpstack_64.c
-@@ -152,7 +152,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
-               unsigned long *stack, unsigned long bp,
-               const struct stacktrace_ops *ops, void *data)
- {
--      const unsigned cpu = get_cpu();
-+      const unsigned cpu = get_cpu_light();
-       unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
-       unsigned long dummy;
-       unsigned used = 0;
-@@ -239,7 +239,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
-        * This handles the process stack:
-        */
-       bp = ops->walk_stack(task, stack, bp, ops, data, NULL, &graph);
--      put_cpu();
-+      put_cpu_light();
- }
- EXPORT_SYMBOL(dump_trace);
-@@ -253,7 +253,7 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
-       int cpu;
-       int i;
--      preempt_disable();
-+      migrate_disable();
-       cpu = smp_processor_id();
-       irq_stack_end   = (unsigned long *)(per_cpu(irq_stack_ptr, cpu));
-@@ -299,7 +299,7 @@ show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
-               stack++;
-               touch_nmi_watchdog();
-       }
--      preempt_enable();
-+      migrate_enable();
-       pr_cont("\n");
-       show_trace_log_lvl(task, regs, sp, bp, log_lvl);
 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
 index 1f38d9a4d9de..053bf3b2ef39 100644
 --- a/arch/x86/kernel/irq_32.c
@@ -2661,7 +2592,7 @@ index 1f38d9a4d9de..053bf3b2ef39 100644
  bool handle_irq(struct irq_desc *desc, struct pt_regs *regs)
  {
 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
-index d86be29c38c7..b0e29d1a0571 100644
+index bd7be8efdc4c..b3b0a7f7b1ca 100644
 --- a/arch/x86/kernel/process_32.c
 +++ b/arch/x86/kernel/process_32.c
 @@ -35,6 +35,7 @@
@@ -2672,7 +2603,7 @@ index d86be29c38c7..b0e29d1a0571 100644
  
  #include <asm/pgtable.h>
  #include <asm/ldt.h>
-@@ -210,6 +211,35 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
+@@ -195,6 +196,35 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
  }
  EXPORT_SYMBOL_GPL(start_thread);
  
@@ -2708,7 +2639,7 @@ index d86be29c38c7..b0e29d1a0571 100644
  
  /*
   *    switch_to(x,y) should switch tasks from x to y.
-@@ -286,6 +316,8 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
+@@ -271,6 +301,8 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
                     task_thread_info(next_p)->flags & _TIF_WORK_CTXSW_NEXT))
                __switch_to_xtra(prev_p, next_p, tss);
  
@@ -2718,10 +2649,10 @@ index d86be29c38c7..b0e29d1a0571 100644
         * Leave lazy mode, flushing any hypercalls made here.
         * This must be done before restoring TLS segments so
 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
-index b62c85229711..d907b281a9d6 100644
+index b24b3c6d686e..02a062b0de5d 100644
 --- a/arch/x86/kvm/lapic.c
 +++ b/arch/x86/kvm/lapic.c
-@@ -1938,6 +1938,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
+@@ -1944,6 +1944,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
        hrtimer_init(&apic->lapic_timer.timer, CLOCK_MONOTONIC,
                     HRTIMER_MODE_ABS_PINNED);
        apic->lapic_timer.timer.function = apic_timer_fn;
@@ -2730,10 +2661,10 @@ index b62c85229711..d907b281a9d6 100644
        /*
         * APIC is created enabled. This will prevent kvm_lapic_set_base from
 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
-index 699f8726539a..24f30c86510c 100644
+index 02d45296a97c..4963bd51d20b 100644
 --- a/arch/x86/kvm/x86.c
 +++ b/arch/x86/kvm/x86.c
-@@ -5865,6 +5865,13 @@ int kvm_arch_init(void *opaque)
+@@ -5966,6 +5966,13 @@ int kvm_arch_init(void *opaque)
                goto out;
        }
  
@@ -2831,11 +2762,31 @@ index ada98b39b8ad..585f6829653b 100644
                kpte_clear_flush(kmap_pte-idx, vaddr);
                kmap_atomic_idx_pop();
        }
+diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
+index e3353c97d086..01664968555c 100644
+--- a/arch/x86/mm/pageattr.c
++++ b/arch/x86/mm/pageattr.c
+@@ -214,7 +214,15 @@ static void cpa_flush_array(unsigned long *start, int numpages, int cache,
+                           int in_flags, struct page **pages)
+ {
+       unsigned int i, level;
++#ifdef CONFIG_PREEMPT
++      /*
++       * Avoid wbinvd() because it causes latencies on all CPUs,
++       * regardless of any CPU isolation that may be in effect.
++       */
++      unsigned long do_wbinvd = 0;
++#else
+       unsigned long do_wbinvd = cache && numpages >= 1024; /* 4M threshold */
++#endif
+       BUG_ON(irqs_disabled());
 diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
-index fdb4d42b4ce5..8ab90fbecff0 100644
+index 9e42842e924a..5398f97172f9 100644
 --- a/arch/x86/platform/uv/tlb_uv.c
 +++ b/arch/x86/platform/uv/tlb_uv.c
-@@ -729,9 +729,9 @@ static void destination_plugged(struct bau_desc *bau_desc,
+@@ -748,9 +748,9 @@ static void destination_plugged(struct bau_desc *bau_desc,
  
                quiesce_local_uvhub(hmaster);
  
@@ -2847,7 +2798,7 @@ index fdb4d42b4ce5..8ab90fbecff0 100644
  
                end_uvhub_quiesce(hmaster);
  
-@@ -751,9 +751,9 @@ static void destination_timeout(struct bau_desc *bau_desc,
+@@ -770,9 +770,9 @@ static void destination_timeout(struct bau_desc *bau_desc,
  
                quiesce_local_uvhub(hmaster);
  
@@ -2859,7 +2810,7 @@ index fdb4d42b4ce5..8ab90fbecff0 100644
  
                end_uvhub_quiesce(hmaster);
  
-@@ -774,7 +774,7 @@ static void disable_for_period(struct bau_control *bcp, struct ptc_stats *stat)
+@@ -793,7 +793,7 @@ static void disable_for_period(struct bau_control *bcp, struct ptc_stats *stat)
        cycles_t tm1;
  
        hmaster = bcp->uvhub_master;
@@ -2868,7 +2819,7 @@ index fdb4d42b4ce5..8ab90fbecff0 100644
        if (!bcp->baudisabled) {
                stat->s_bau_disabled++;
                tm1 = get_cycles();
-@@ -787,7 +787,7 @@ static void disable_for_period(struct bau_control *bcp, struct ptc_stats *stat)
+@@ -806,7 +806,7 @@ static void disable_for_period(struct bau_control *bcp, struct ptc_stats *stat)
                        }
                }
        }
@@ -2877,7 +2828,7 @@ index fdb4d42b4ce5..8ab90fbecff0 100644
  }
  
  static void count_max_concurr(int stat, struct bau_control *bcp,
-@@ -850,7 +850,7 @@ static void record_send_stats(cycles_t time1, cycles_t time2,
+@@ -869,7 +869,7 @@ static void record_send_stats(cycles_t time1, cycles_t time2,
   */
  static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
  {
@@ -2886,7 +2837,7 @@ index fdb4d42b4ce5..8ab90fbecff0 100644
        atomic_t *v;
  
        v = &hmaster->active_descriptor_count;
-@@ -983,7 +983,7 @@ static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
+@@ -1002,7 +1002,7 @@ static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
        struct bau_control *hmaster;
  
        hmaster = bcp->uvhub_master;
@@ -2895,7 +2846,7 @@ index fdb4d42b4ce5..8ab90fbecff0 100644
        if (bcp->baudisabled && (get_cycles() >= bcp->set_bau_on_time)) {
                stat->s_bau_reenabled++;
                for_each_present_cpu(tcpu) {
-@@ -995,10 +995,10 @@ static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
+@@ -1014,10 +1014,10 @@ static int check_enable(struct bau_control *bcp, struct ptc_stats *stat)
                                tbcp->period_giveups = 0;
                        }
                }
@@ -2908,10 +2859,10 @@ index fdb4d42b4ce5..8ab90fbecff0 100644
        return -1;
  }
  
-@@ -1916,9 +1916,9 @@ static void __init init_per_cpu_tunables(void)
+@@ -1940,9 +1940,9 @@ static void __init init_per_cpu_tunables(void)
                bcp->cong_reps                  = congested_reps;
-               bcp->disabled_period =          sec_2_cycles(disabled_period);
-               bcp->giveup_limit =             giveup_limit;
+               bcp->disabled_period            = sec_2_cycles(disabled_period);
+               bcp->giveup_limit               = giveup_limit;
 -              spin_lock_init(&bcp->queue_lock);
 -              spin_lock_init(&bcp->uvhub_lock);
 -              spin_lock_init(&bcp->disable_lock);
@@ -3006,7 +2957,7 @@ index b333fc45f9ec..8b85916e6986 100644
  
  /*
 diff --git a/block/blk-core.c b/block/blk-core.c
-index 36c7ac328d8c..caa5fc1be2a2 100644
+index b1c76aa73492..5808a85a7974 100644
 --- a/block/blk-core.c
 +++ b/block/blk-core.c
 @@ -125,6 +125,9 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
@@ -3023,12 +2974,12 @@ index 36c7ac328d8c..caa5fc1be2a2 100644
   **/
  void blk_start_queue(struct request_queue *q)
  {
--      WARN_ON(!irqs_disabled());
-+      WARN_ON_NONRT(!irqs_disabled());
+-      WARN_ON(!in_interrupt() && !irqs_disabled());
++      WARN_ON_NONRT(!in_interrupt() && !irqs_disabled());
  
        queue_flag_clear(QUEUE_FLAG_STOPPED, q);
        __blk_run_queue(q);
-@@ -659,7 +662,7 @@ int blk_queue_enter(struct request_queue *q, bool nowait)
+@@ -660,7 +663,7 @@ int blk_queue_enter(struct request_queue *q, bool nowait)
                if (nowait)
                        return -EBUSY;
  
@@ -3037,7 +2988,7 @@ index 36c7ac328d8c..caa5fc1be2a2 100644
                                !atomic_read(&q->mq_freeze_depth) ||
                                blk_queue_dying(q));
                if (blk_queue_dying(q))
-@@ -679,7 +682,7 @@ static void blk_queue_usage_counter_release(struct percpu_ref *ref)
+@@ -680,7 +683,7 @@ static void blk_queue_usage_counter_release(struct percpu_ref *ref)
        struct request_queue *q =
                container_of(ref, struct request_queue, q_usage_counter);
  
@@ -3046,7 +2997,7 @@ index 36c7ac328d8c..caa5fc1be2a2 100644
  }
  
  static void blk_rq_timed_out_timer(unsigned long data)
-@@ -748,7 +751,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
+@@ -750,7 +753,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
        q->bypass_depth = 1;
        __set_bit(QUEUE_FLAG_BYPASS, &q->queue_flags);
  
@@ -3055,7 +3006,7 @@ index 36c7ac328d8c..caa5fc1be2a2 100644
  
        /*
         * Init percpu_ref in atomic mode so that it's faster to shutdown.
-@@ -3171,7 +3174,7 @@ static void queue_unplugged(struct request_queue *q, unsigned int depth,
+@@ -3202,7 +3205,7 @@ static void queue_unplugged(struct request_queue *q, unsigned int depth,
                blk_run_queue_async(q);
        else
                __blk_run_queue(q);
@@ -3064,7 +3015,7 @@ index 36c7ac328d8c..caa5fc1be2a2 100644
  }
  
  static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
-@@ -3219,7 +3222,6 @@ EXPORT_SYMBOL(blk_check_plugged);
+@@ -3250,7 +3253,6 @@ EXPORT_SYMBOL(blk_check_plugged);
  void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
  {
        struct request_queue *q;
@@ -3072,7 +3023,7 @@ index 36c7ac328d8c..caa5fc1be2a2 100644
        struct request *rq;
        LIST_HEAD(list);
        unsigned int depth;
-@@ -3239,11 +3241,6 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
+@@ -3270,11 +3272,6 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
        q = NULL;
        depth = 0;
  
@@ -3084,7 +3035,7 @@ index 36c7ac328d8c..caa5fc1be2a2 100644
        while (!list_empty(&list)) {
                rq = list_entry_rq(list.next);
                list_del_init(&rq->queuelist);
-@@ -3256,7 +3253,7 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
+@@ -3287,7 +3284,7 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
                                queue_unplugged(q, depth, from_schedule);
                        q = rq->q;
                        depth = 0;
@@ -3093,7 +3044,7 @@ index 36c7ac328d8c..caa5fc1be2a2 100644
                }
  
                /*
-@@ -3283,8 +3280,6 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
+@@ -3314,8 +3311,6 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
         */
        if (q)
                queue_unplugged(q, depth, from_schedule);
@@ -3132,66 +3083,11 @@ index 381cb50a673c..dc8785233d94 100644
                        goto retry;
                }
        }
-diff --git a/block/blk-mq-cpu.c b/block/blk-mq-cpu.c
-index bb3ed488f7b5..628c6c13c482 100644
---- a/block/blk-mq-cpu.c
-+++ b/block/blk-mq-cpu.c
-@@ -16,7 +16,7 @@
- #include "blk-mq.h"
- static LIST_HEAD(blk_mq_cpu_notify_list);
--static DEFINE_RAW_SPINLOCK(blk_mq_cpu_notify_lock);
-+static DEFINE_SPINLOCK(blk_mq_cpu_notify_lock);
- static int blk_mq_main_cpu_notify(struct notifier_block *self,
-                                 unsigned long action, void *hcpu)
-@@ -25,7 +25,10 @@ static int blk_mq_main_cpu_notify(struct notifier_block *self,
-       struct blk_mq_cpu_notifier *notify;
-       int ret = NOTIFY_OK;
--      raw_spin_lock(&blk_mq_cpu_notify_lock);
-+      if (action != CPU_POST_DEAD)
-+              return NOTIFY_OK;
-+
-+      spin_lock(&blk_mq_cpu_notify_lock);
-       list_for_each_entry(notify, &blk_mq_cpu_notify_list, list) {
-               ret = notify->notify(notify->data, action, cpu);
-@@ -33,7 +36,7 @@ static int blk_mq_main_cpu_notify(struct notifier_block *self,
-                       break;
-       }
--      raw_spin_unlock(&blk_mq_cpu_notify_lock);
-+      spin_unlock(&blk_mq_cpu_notify_lock);
-       return ret;
- }
-@@ -41,16 +44,16 @@ void blk_mq_register_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
- {
-       BUG_ON(!notifier->notify);
--      raw_spin_lock(&blk_mq_cpu_notify_lock);
-+      spin_lock(&blk_mq_cpu_notify_lock);
-       list_add_tail(&notifier->list, &blk_mq_cpu_notify_list);
--      raw_spin_unlock(&blk_mq_cpu_notify_lock);
-+      spin_unlock(&blk_mq_cpu_notify_lock);
- }
- void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
- {
--      raw_spin_lock(&blk_mq_cpu_notify_lock);
-+      spin_lock(&blk_mq_cpu_notify_lock);
-       list_del(&notifier->list);
--      raw_spin_unlock(&blk_mq_cpu_notify_lock);
-+      spin_unlock(&blk_mq_cpu_notify_lock);
- }
- void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier,
 diff --git a/block/blk-mq.c b/block/blk-mq.c
-index c207fa9870eb..ac71b0455e9f 100644
+index 7b597ec4e9c5..48c9652a701c 100644
 --- a/block/blk-mq.c
 +++ b/block/blk-mq.c
-@@ -92,7 +92,7 @@ EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_start);
+@@ -72,7 +72,7 @@ EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_start);
  
  static void blk_mq_freeze_queue_wait(struct request_queue *q)
  {
@@ -3200,7 +3096,7 @@ index c207fa9870eb..ac71b0455e9f 100644
  }
  
  /*
-@@ -130,7 +130,7 @@ void blk_mq_unfreeze_queue(struct request_queue *q)
+@@ -110,7 +110,7 @@ void blk_mq_unfreeze_queue(struct request_queue *q)
        WARN_ON_ONCE(freeze_depth < 0);
        if (!freeze_depth) {
                percpu_ref_reinit(&q->q_usage_counter);
@@ -3209,7 +3105,7 @@ index c207fa9870eb..ac71b0455e9f 100644
        }
  }
  EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);
-@@ -149,7 +149,7 @@ void blk_mq_wake_waiters(struct request_queue *q)
+@@ -129,7 +129,7 @@ void blk_mq_wake_waiters(struct request_queue *q)
         * dying, we need to ensure that processes currently waiting on
         * the queue are notified as well.
         */
@@ -3218,7 +3114,7 @@ index c207fa9870eb..ac71b0455e9f 100644
  }
  
  bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx)
-@@ -197,6 +197,9 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
+@@ -177,6 +177,9 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
        rq->resid_len = 0;
        rq->sense = NULL;
  
@@ -3228,7 +3124,7 @@ index c207fa9870eb..ac71b0455e9f 100644
        INIT_LIST_HEAD(&rq->timeout_list);
        rq->timeout = 0;
  
-@@ -379,6 +382,17 @@ void blk_mq_end_request(struct request *rq, int error)
+@@ -345,6 +348,17 @@ void blk_mq_end_request(struct request *rq, int error)
  }
  EXPORT_SYMBOL(blk_mq_end_request);
  
@@ -3246,7 +3142,7 @@ index c207fa9870eb..ac71b0455e9f 100644
  static void __blk_mq_complete_request_remote(void *data)
  {
        struct request *rq = data;
-@@ -386,6 +400,8 @@ static void __blk_mq_complete_request_remote(void *data)
+@@ -352,6 +366,8 @@ static void __blk_mq_complete_request_remote(void *data)
        rq->q->softirq_done_fn(rq);
  }
  
@@ -3255,7 +3151,7 @@ index c207fa9870eb..ac71b0455e9f 100644
  static void blk_mq_ipi_complete_request(struct request *rq)
  {
        struct blk_mq_ctx *ctx = rq->mq_ctx;
-@@ -397,19 +413,23 @@ static void blk_mq_ipi_complete_request(struct request *rq)
+@@ -363,19 +379,23 @@ static void blk_mq_ipi_complete_request(struct request *rq)
                return;
        }
  
@@ -3281,10 +3177,10 @@ index c207fa9870eb..ac71b0455e9f 100644
  }
  
  static void __blk_mq_complete_request(struct request *rq)
-@@ -938,14 +958,14 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async)
+@@ -906,14 +926,14 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async)
                return;
  
-       if (!async) {
+       if (!async && !(hctx->flags & BLK_MQ_F_BLOCKING)) {
 -              int cpu = get_cpu();
 +              int cpu = get_cpu_light();
                if (cpumask_test_cpu(cpu, hctx->cpumask)) {
@@ -3298,21 +3194,12 @@ index c207fa9870eb..ac71b0455e9f 100644
 +              put_cpu_light();
        }
  
-       kblockd_schedule_delayed_work_on(blk_mq_hctx_next_cpu(hctx),
-@@ -1667,7 +1687,7 @@ static int blk_mq_hctx_notify(void *data, unsigned long action,
- {
-       struct blk_mq_hw_ctx *hctx = data;
--      if (action == CPU_DEAD || action == CPU_DEAD_FROZEN)
-+      if (action == CPU_POST_DEAD)
-               return blk_mq_hctx_cpu_offline(hctx, cpu);
-       /*
+       kblockd_schedule_work_on(blk_mq_hctx_next_cpu(hctx), &hctx->run_work);
 diff --git a/block/blk-mq.h b/block/blk-mq.h
-index 9087b11037b7..0401d76e827c 100644
+index e5d25249028c..1e846b842eab 100644
 --- a/block/blk-mq.h
 +++ b/block/blk-mq.h
-@@ -86,12 +86,12 @@ static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q,
+@@ -72,12 +72,12 @@ static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q,
   */
  static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q)
  {
@@ -3328,7 +3215,7 @@ index 9087b11037b7..0401d76e827c 100644
  
  struct blk_mq_alloc_data {
 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
-index 53b1737e978d..81c3c0a62edf 100644
+index 06cf9807f49a..c40342643ca0 100644
 --- a/block/blk-softirq.c
 +++ b/block/blk-softirq.c
 @@ -51,6 +51,7 @@ static void trigger_softirq(void *data)
@@ -3339,15 +3226,15 @@ index 53b1737e978d..81c3c0a62edf 100644
  }
  
  /*
-@@ -93,6 +94,7 @@ static int blk_cpu_notify(struct notifier_block *self, unsigned long action,
-                                this_cpu_ptr(&blk_cpu_done));
-               raise_softirq_irqoff(BLOCK_SOFTIRQ);
-               local_irq_enable();
-+              preempt_check_resched_rt();
-       }
+@@ -89,6 +90,7 @@ static int blk_softirq_cpu_dead(unsigned int cpu)
+                        this_cpu_ptr(&blk_cpu_done));
+       raise_softirq_irqoff(BLOCK_SOFTIRQ);
+       local_irq_enable();
++      preempt_check_resched_rt();
  
-       return NOTIFY_OK;
-@@ -150,6 +152,7 @@ void __blk_complete_request(struct request *req)
+       return 0;
+ }
+@@ -141,6 +143,7 @@ void __blk_complete_request(struct request *req)
                goto do_local;
  
        local_irq_restore(flags);
@@ -3374,10 +3261,10 @@ index 1cb5dd3a5da1..2f1ec8a67cbe 100644
  
  #else /* CONFIG_HIGHMEM */
 diff --git a/crypto/algapi.c b/crypto/algapi.c
-index df939b54b09f..efe5e06adcf7 100644
+index 1fad2a6b3bbb..ecb7315426a9 100644
 --- a/crypto/algapi.c
 +++ b/crypto/algapi.c
-@@ -718,13 +718,13 @@ EXPORT_SYMBOL_GPL(crypto_spawn_tfm2);
+@@ -719,13 +719,13 @@ EXPORT_SYMBOL_GPL(crypto_spawn_tfm2);
  
  int crypto_register_notifier(struct notifier_block *nb)
  {
@@ -3442,7 +3329,7 @@ index 7eefcdb00227..0ecc7f5a2f40 100644
  
  #endif        /* _CRYPTO_INTERNAL_H */
 diff --git a/drivers/acpi/acpica/acglobal.h b/drivers/acpi/acpica/acglobal.h
-index fded776236e2..bda523219d50 100644
+index 750fa824d42c..441edf51484a 100644
 --- a/drivers/acpi/acpica/acglobal.h
 +++ b/drivers/acpi/acpica/acglobal.h
 @@ -116,7 +116,7 @@ ACPI_GLOBAL(u8, acpi_gbl_global_lock_pending);
@@ -3572,17 +3459,17 @@ index 051b6158d1b7..7ad293bef6ed 100644
                buf = page_address(page);
                consumed = ap->ops->sff_data_xfer(dev,  buf + offset,
 diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
-index 4b5cd3a7b2b6..fa8329ad79fd 100644
+index 4b5cd3a7b2b6..8c93ee150ee8 100644
 --- a/drivers/block/zram/zcomp.c
 +++ b/drivers/block/zram/zcomp.c
-@@ -118,12 +118,19 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
+@@ -118,12 +118,20 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
  
  struct zcomp_strm *zcomp_stream_get(struct zcomp *comp)
  {
 -      return *get_cpu_ptr(comp->stream);
 +      struct zcomp_strm *zstrm;
 +
-+      zstrm = *this_cpu_ptr(comp->stream);
++      zstrm = *get_local_ptr(comp->stream);
 +      spin_lock(&zstrm->zcomp_lock);
 +      return zstrm;
  }
@@ -3594,10 +3481,11 @@ index 4b5cd3a7b2b6..fa8329ad79fd 100644
 +
 +      zstrm = *this_cpu_ptr(comp->stream);
 +      spin_unlock(&zstrm->zcomp_lock);
++      put_local_ptr(zstrm);
  }
  
  int zcomp_compress(struct zcomp_strm *zstrm,
-@@ -174,6 +181,7 @@ static int __zcomp_cpu_notifier(struct zcomp *comp,
+@@ -174,6 +182,7 @@ static int __zcomp_cpu_notifier(struct zcomp *comp,
                        pr_err("Can't allocate a compression stream\n");
                        return NOTIFY_BAD;
                }
@@ -3618,10 +3506,10 @@ index 478cac2ed465..f7a6efdc3285 100644
  
  /* dynamic per-device compression frontend */
 diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
-index 04365b17ee67..b4a0577a4dbc 100644
+index c9914d653968..2038d138f286 100644
 --- a/drivers/block/zram/zram_drv.c
 +++ b/drivers/block/zram/zram_drv.c
-@@ -519,6 +519,8 @@ static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
+@@ -528,6 +528,8 @@ static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
                goto out_error;
        }
  
@@ -3630,7 +3518,7 @@ index 04365b17ee67..b4a0577a4dbc 100644
        return meta;
  
  out_error:
-@@ -566,28 +568,28 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
+@@ -575,28 +577,28 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
        struct zram_meta *meta = zram->meta;
        unsigned long handle;
        unsigned int size;
@@ -3644,14 +3532,14 @@ index 04365b17ee67..b4a0577a4dbc 100644
        if (!handle || zram_test_flag(meta, index, ZRAM_ZERO)) {
 -              bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
 +              zram_unlock_table(&meta->table[index]);
-               clear_page(mem);
+               memset(mem, 0, PAGE_SIZE);
                return 0;
        }
  
 +      zstrm = zcomp_stream_get(zram->comp);
        cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_RO);
        if (size == PAGE_SIZE) {
-               copy_page(mem, cmem);
+               memcpy(mem, cmem, PAGE_SIZE);
        } else {
 -              struct zcomp_strm *zstrm = zcomp_stream_get(zram->comp);
 -
@@ -3665,7 +3553,7 @@ index 04365b17ee67..b4a0577a4dbc 100644
  
        /* Should NEVER happen. Return bio error if it does. */
        if (unlikely(ret)) {
-@@ -607,14 +609,14 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
+@@ -616,14 +618,14 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
        struct zram_meta *meta = zram->meta;
        page = bvec->bv_page;
  
@@ -3683,7 +3571,7 @@ index 04365b17ee67..b4a0577a4dbc 100644
  
        if (is_partial_io(bvec))
                /* Use  a temporary buffer to decompress the page */
-@@ -691,10 +693,10 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
+@@ -700,10 +702,10 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
                if (user_mem)
                        kunmap_atomic(user_mem);
                /* Free memory associated with this sector now. */
@@ -3696,7 +3584,7 @@ index 04365b17ee67..b4a0577a4dbc 100644
  
                atomic64_inc(&zram->stats.zero_pages);
                ret = 0;
-@@ -785,12 +787,12 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
+@@ -794,12 +796,12 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
         * Free memory associated with this sector
         * before overwriting unused sectors.
         */
@@ -3711,7 +3599,7 @@ index 04365b17ee67..b4a0577a4dbc 100644
  
        /* Update stats */
        atomic64_add(clen, &zram->stats.compr_data_size);
-@@ -833,9 +835,9 @@ static void zram_bio_discard(struct zram *zram, u32 index,
+@@ -842,9 +844,9 @@ static void zram_bio_discard(struct zram *zram, u32 index,
        }
  
        while (n >= PAGE_SIZE) {
@@ -3723,7 +3611,7 @@ index 04365b17ee67..b4a0577a4dbc 100644
                atomic64_inc(&zram->stats.notify_free);
                index++;
                n -= PAGE_SIZE;
-@@ -964,9 +966,9 @@ static void zram_slot_free_notify(struct block_device *bdev,
+@@ -973,9 +975,9 @@ static void zram_slot_free_notify(struct block_device *bdev,
        zram = bdev->bd_disk->private_data;
        meta = zram->meta;
  
@@ -3793,10 +3681,18 @@ index 74fcf10da374..fd4020c99b9e 100644
 +
  #endif
 diff --git a/drivers/char/random.c b/drivers/char/random.c
-index 3efb3bf0ab83..c894d2e266f3 100644
+index 08d1dd58c0d2..25ee319dc8e3 100644
 --- a/drivers/char/random.c
 +++ b/drivers/char/random.c
-@@ -1028,8 +1028,6 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
+@@ -262,6 +262,7 @@
+ #include <linux/syscalls.h>
+ #include <linux/completion.h>
+ #include <linux/uuid.h>
++#include <linux/locallock.h>
+ #include <crypto/chacha20.h>
+ #include <asm/processor.h>
+@@ -1028,8 +1029,6 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
        } sample;
        long delta, delta2, delta3;
  
@@ -3805,7 +3701,7 @@ index 3efb3bf0ab83..c894d2e266f3 100644
        sample.jiffies = jiffies;
        sample.cycles = random_get_entropy();
        sample.num = num;
-@@ -1070,7 +1068,6 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
+@@ -1070,7 +1069,6 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
                 */
                credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
        }
@@ -3813,7 +3709,7 @@ index 3efb3bf0ab83..c894d2e266f3 100644
  }
  
  void add_input_randomness(unsigned int type, unsigned int code,
-@@ -1123,28 +1120,27 @@ static __u32 get_reg(struct fast_pool *f, struct pt_regs *regs)
+@@ -1123,28 +1121,27 @@ static __u32 get_reg(struct fast_pool *f, struct pt_regs *regs)
        return *(ptr + f->reg_idx++);
  }
  
@@ -3847,6 +3743,109 @@ index 3efb3bf0ab83..c894d2e266f3 100644
  
        fast_mix(fast_pool);
        add_interrupt_bench(cycles);
+@@ -2056,6 +2053,7 @@ struct batched_entropy {
+  * goal of being quite fast and not depleting entropy.
+  */
+ static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_long);
++static DEFINE_LOCAL_IRQ_LOCK(batched_entropy_long_lock);
+ unsigned long get_random_long(void)
+ {
+       unsigned long ret;
+@@ -2064,13 +2062,13 @@ unsigned long get_random_long(void)
+       if (arch_get_random_long(&ret))
+               return ret;
+-      batch = &get_cpu_var(batched_entropy_long);
++      batch = &get_locked_var(batched_entropy_long_lock, batched_entropy_long);
+       if (batch->position % ARRAY_SIZE(batch->entropy_long) == 0) {
+               extract_crng((u8 *)batch->entropy_long);
+               batch->position = 0;
+       }
+       ret = batch->entropy_long[batch->position++];
+-      put_cpu_var(batched_entropy_long);
++      put_locked_var(batched_entropy_long_lock, batched_entropy_long);
+       return ret;
+ }
+ EXPORT_SYMBOL(get_random_long);
+@@ -2082,6 +2080,8 @@ unsigned int get_random_int(void)
+ }
+ #else
+ static DEFINE_PER_CPU(struct batched_entropy, batched_entropy_int);
++static DEFINE_LOCAL_IRQ_LOCK(batched_entropy_int_lock);
++
+ unsigned int get_random_int(void)
+ {
+       unsigned int ret;
+@@ -2090,13 +2090,13 @@ unsigned int get_random_int(void)
+       if (arch_get_random_int(&ret))
+               return ret;
+-      batch = &get_cpu_var(batched_entropy_int);
++      batch = &get_locked_var(batched_entropy_int_lock, batched_entropy_int);
+       if (batch->position % ARRAY_SIZE(batch->entropy_int) == 0) {
+               extract_crng((u8 *)batch->entropy_int);
+               batch->position = 0;
+       }
+       ret = batch->entropy_int[batch->position++];
+-      put_cpu_var(batched_entropy_int);
++      put_locked_var(batched_entropy_int_lock, batched_entropy_int);
+       return ret;
+ }
+ #endif
+diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
+index 8022bea27fed..247330efd310 100644
+--- a/drivers/char/tpm/tpm_tis.c
++++ b/drivers/char/tpm/tpm_tis.c
+@@ -50,6 +50,31 @@ static inline struct tpm_tis_tcg_phy *to_tpm_tis_tcg_phy(struct tpm_tis_data *da
+       return container_of(data, struct tpm_tis_tcg_phy, priv);
+ }
++#ifdef CONFIG_PREEMPT_RT_FULL
++/*
++ * Flushes previous write operations to chip so that a subsequent
++ * ioread*()s won't stall a cpu.
++ */
++static inline void tpm_tis_flush(void __iomem *iobase)
++{
++      ioread8(iobase + TPM_ACCESS(0));
++}
++#else
++#define tpm_tis_flush(iobase) do { } while (0)
++#endif
++
++static inline void tpm_tis_iowrite8(u8 b, void __iomem *iobase, u32 addr)
++{
++      iowrite8(b, iobase + addr);
++      tpm_tis_flush(iobase);
++}
++
++static inline void tpm_tis_iowrite32(u32 b, void __iomem *iobase, u32 addr)
++{
++      iowrite32(b, iobase + addr);
++      tpm_tis_flush(iobase);
++}
++
+ static bool interrupts = true;
+ module_param(interrupts, bool, 0444);
+ MODULE_PARM_DESC(interrupts, "Enable interrupts");
+@@ -103,7 +128,7 @@ static int tpm_tcg_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
+       struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
+       while (len--)
+-              iowrite8(*value++, phy->iobase + addr);
++              tpm_tis_iowrite8(*value++, phy->iobase, addr);
+       return 0;
+ }
+@@ -127,7 +152,7 @@ static int tpm_tcg_write32(struct tpm_tis_data *data, u32 addr, u32 value)
+ {
+       struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
+-      iowrite32(value, phy->iobase + addr);
++      tpm_tis_iowrite32(value, phy->iobase, addr);
+       return 0;
+ }
 diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c
 index 4da2af9694a2..5b6f57f500b8 100644
 --- a/drivers/clocksource/tcb_clksrc.c
@@ -4009,7 +4008,7 @@ index 4da2af9694a2..5b6f57f500b8 100644
                goto err_unregister_clksrc;
  
 diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
-index 7f0f5b26d8c5..1553f19e73e7 100644
+index 6555821bbdae..93288849b2bd 100644
 --- a/drivers/clocksource/timer-atmel-pit.c
 +++ b/drivers/clocksource/timer-atmel-pit.c
 @@ -46,6 +46,7 @@ struct pit_data {
@@ -4050,7 +4049,7 @@ index 7f0f5b26d8c5..1553f19e73e7 100644
  
        /* update clocksource counter */
        data->cnt += data->cycle * PIT_PICNT(pit_read(data->base, AT91_PIT_PIVR));
-@@ -211,15 +226,6 @@ static int __init at91sam926x_pit_common_init(struct pit_data *data)
+@@ -230,15 +245,6 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
                return ret;
        }
  
@@ -4198,10 +4197,10 @@ index adbd1de1cea5..1fac5074f2cf 100644
          This adds the CPUFreq driver for K8/early Opteron/Athlon64 processors.
          Support for K10 and newer processors is now in acpi-cpufreq.
 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
-index b35e5b6475b2..ce60807fb1d4 100644
+index 2117f172d7a2..96c15501b0c8 100644
 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
-@@ -1302,7 +1302,9 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params,
+@@ -1489,7 +1489,9 @@ execbuf_submit(struct i915_execbuffer_params *params,
        if (ret)
                return ret;
  
@@ -4212,7 +4211,7 @@ index b35e5b6475b2..ce60807fb1d4 100644
        i915_gem_execbuffer_move_to_active(vmas, params->request);
  
 diff --git a/drivers/gpu/drm/i915/i915_gem_shrinker.c b/drivers/gpu/drm/i915/i915_gem_shrinker.c
-index 6f10b421487b..dd3a9a6ace11 100644
+index 755d78832a66..97fb03dc4971 100644
 --- a/drivers/gpu/drm/i915/i915_gem_shrinker.c
 +++ b/drivers/gpu/drm/i915/i915_gem_shrinker.c
 @@ -40,7 +40,7 @@ static bool mutex_is_locked_by(struct mutex *mutex, struct task_struct *task)
@@ -4225,7 +4224,7 @@ index 6f10b421487b..dd3a9a6ace11 100644
  #else
        /* Since UP may be pre-empted, we cannot assume that we own the lock */
 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
-index 1c2aec392412..1d85c0c791f1 100644
+index 02908e37c228..05c0480576e1 100644
 --- a/drivers/gpu/drm/i915/i915_irq.c
 +++ b/drivers/gpu/drm/i915/i915_irq.c
 @@ -812,6 +812,7 @@ static int i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
@@ -4245,10 +4244,10 @@ index 1c2aec392412..1d85c0c791f1 100644
        spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  
 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
-index e9a64fba6333..2aac27b13d86 100644
+index ce32303b3013..c0a53bf2e952 100644
 --- a/drivers/gpu/drm/i915/intel_display.c
 +++ b/drivers/gpu/drm/i915/intel_display.c
-@@ -11647,7 +11647,7 @@ void intel_check_page_flip(struct drm_i915_private *dev_priv, int pipe)
+@@ -12138,7 +12138,7 @@ void intel_check_page_flip(struct drm_i915_private *dev_priv, int pipe)
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        struct intel_flip_work *work;
  
@@ -4258,18 +4257,18 @@ index e9a64fba6333..2aac27b13d86 100644
        if (crtc == NULL)
                return;
 diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c
-index 4178849631ad..0eb939c92544 100644
+index 64f4e2e18594..aebf1e9eabcb 100644
 --- a/drivers/gpu/drm/i915/intel_sprite.c
 +++ b/drivers/gpu/drm/i915/intel_sprite.c
-@@ -38,6 +38,7 @@
+@@ -35,6 +35,7 @@
+ #include <drm/drm_rect.h>
+ #include <drm/drm_atomic.h>
+ #include <drm/drm_plane_helper.h>
++#include <linux/locallock.h>
  #include "intel_drv.h"
+ #include "intel_frontbuffer.h"
  #include <drm/i915_drm.h>
- #include "i915_drv.h"
-+#include <linux/locallock.h>
- static bool
- format_is_yuv(uint32_t format)
-@@ -64,6 +65,8 @@ int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
+@@ -65,6 +66,8 @@ int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
                            1000 * adjusted_mode->crtc_htotal);
  }
  
@@ -4278,7 +4277,7 @@ index 4178849631ad..0eb939c92544 100644
  /**
   * intel_pipe_update_start() - start update of a set of display registers
   * @crtc: the crtc of which the registers are going to be updated
-@@ -94,7 +97,7 @@ void intel_pipe_update_start(struct intel_crtc *crtc)
+@@ -98,7 +101,7 @@ void intel_pipe_update_start(struct intel_crtc *crtc)
        min = vblank_start - intel_usecs_to_scanlines(adjusted_mode, 100);
        max = vblank_start - 1;
  
@@ -4287,7 +4286,7 @@ index 4178849631ad..0eb939c92544 100644
  
        if (min <= 0 || max <= 0)
                return;
-@@ -124,11 +127,11 @@ void intel_pipe_update_start(struct intel_crtc *crtc)
+@@ -128,11 +131,11 @@ void intel_pipe_update_start(struct intel_crtc *crtc)
                        break;
                }
  
@@ -4301,7 +4300,7 @@ index 4178849631ad..0eb939c92544 100644
        }
  
        finish_wait(wq, &wait);
-@@ -180,7 +183,7 @@ void intel_pipe_update_end(struct intel_crtc *crtc, struct intel_flip_work *work
+@@ -202,7 +205,7 @@ void intel_pipe_update_end(struct intel_crtc *crtc, struct intel_flip_work *work
                crtc->base.state->event = NULL;
        }
  
@@ -4311,7 +4310,7 @@ index 4178849631ad..0eb939c92544 100644
        if (crtc->debug.start_vbl_count &&
            crtc->debug.start_vbl_count != end_vbl_count) {
 diff --git a/drivers/gpu/drm/msm/msm_gem_shrinker.c b/drivers/gpu/drm/msm/msm_gem_shrinker.c
-index 283d2841ba58..d01f6ed1977e 100644
+index 192b2d3a79cb..d5372a207326 100644
 --- a/drivers/gpu/drm/msm/msm_gem_shrinker.c
 +++ b/drivers/gpu/drm/msm/msm_gem_shrinker.c
 @@ -23,7 +23,7 @@ static bool mutex_is_locked_by(struct mutex *mutex, struct task_struct *task)
@@ -4324,10 +4323,10 @@ index 283d2841ba58..d01f6ed1977e 100644
  #else
        /* Since UP may be pre-empted, we cannot assume that we own the lock */
 diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
-index c3206fb8f4cf..6e2423186e2a 100644
+index cdb8cb568c15..b6d7fd964cbc 100644
 --- a/drivers/gpu/drm/radeon/radeon_display.c
 +++ b/drivers/gpu/drm/radeon/radeon_display.c
-@@ -1869,6 +1869,7 @@ int radeon_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
+@@ -1845,6 +1845,7 @@ int radeon_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
        struct radeon_device *rdev = dev->dev_private;
  
        /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
@@ -4335,7 +4334,7 @@ index c3206fb8f4cf..6e2423186e2a 100644
  
        /* Get optional system timestamp before query. */
        if (stime)
-@@ -1961,6 +1962,7 @@ int radeon_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
+@@ -1937,6 +1938,7 @@ int radeon_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
                *etime = ktime_get();
  
        /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
@@ -4344,7 +4343,7 @@ index c3206fb8f4cf..6e2423186e2a 100644
        /* Decode into vertical and horizontal scanout position. */
        *vpos = position & 0x1fff;
 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
-index e82f7e1c217c..b57d917b6ab7 100644
+index 0276d2ef06ee..8868045eabde 100644
 --- a/drivers/hv/vmbus_drv.c
 +++ b/drivers/hv/vmbus_drv.c
 @@ -761,6 +761,8 @@ static void vmbus_isr(void)
@@ -4530,10 +4529,10 @@ index a716693417a3..be0568c722d6 100644
        ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
  
 diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
-index d3394b6add24..506bfba6ec9f 100644
+index fddff403d5d2..cca1bb4fbfe3 100644
 --- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
 +++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
-@@ -897,7 +897,7 @@ void ipoib_mcast_restart_task(struct work_struct *work)
+@@ -902,7 +902,7 @@ void ipoib_mcast_restart_task(struct work_struct *work)
  
        ipoib_dbg_mcast(priv, "restarting multicast task\n");
  
@@ -4542,7 +4541,7 @@ index d3394b6add24..506bfba6ec9f 100644
        netif_addr_lock(dev);
        spin_lock(&priv->lock);
  
-@@ -979,7 +979,7 @@ void ipoib_mcast_restart_task(struct work_struct *work)
+@@ -984,7 +984,7 @@ void ipoib_mcast_restart_task(struct work_struct *work)
  
        spin_unlock(&priv->lock);
        netif_addr_unlock(dev);
@@ -4601,10 +4600,10 @@ index 4a2a9e370be7..e970d9afd179 100644
                if (t2 - t1 < tx) tx = t2 - t1;
        }
 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
-index 96de97a46079..a6ec875d941b 100644
+index 1a0b110f12c0..ff5c2424eb9e 100644
 --- a/drivers/iommu/amd_iommu.c
 +++ b/drivers/iommu/amd_iommu.c
-@@ -1832,10 +1832,10 @@ static int __attach_device(struct iommu_dev_data *dev_data,
+@@ -1923,10 +1923,10 @@ static int __attach_device(struct iommu_dev_data *dev_data,
        int ret;
  
        /*
@@ -4618,7 +4617,7 @@ index 96de97a46079..a6ec875d941b 100644
  
        /* lock domain */
        spin_lock(&domain->lock);
-@@ -2003,10 +2003,10 @@ static void __detach_device(struct iommu_dev_data *dev_data)
+@@ -2094,10 +2094,10 @@ static void __detach_device(struct iommu_dev_data *dev_data)
        struct protection_domain *domain;
  
        /*
@@ -4632,8 +4631,26 @@ index 96de97a46079..a6ec875d941b 100644
  
        if (WARN_ON(!dev_data->domain))
                return;
+@@ -2283,7 +2283,7 @@ static void queue_add(struct dma_ops_domain *dma_dom,
+       pages     = __roundup_pow_of_two(pages);
+       address >>= PAGE_SHIFT;
+-      queue = get_cpu_ptr(&flush_queue);
++      queue = raw_cpu_ptr(&flush_queue);
+       spin_lock_irqsave(&queue->lock, flags);
+       if (queue->next == FLUSH_QUEUE_SIZE)
+@@ -2300,8 +2300,6 @@ static void queue_add(struct dma_ops_domain *dma_dom,
+       if (atomic_cmpxchg(&queue_timer_on, 0, 1) == 0)
+               mod_timer(&queue_timer, jiffies + msecs_to_jiffies(10));
+-
+-      put_cpu_ptr(&flush_queue);
+ }
 diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
-index ebb5bf3ddbd9..598f5df45f6b 100644
+index 002f8a421efa..980f41f1a194 100644
 --- a/drivers/iommu/intel-iommu.c
 +++ b/drivers/iommu/intel-iommu.c
 @@ -479,7 +479,7 @@ struct deferred_flush_data {
@@ -4645,7 +4662,7 @@ index ebb5bf3ddbd9..598f5df45f6b 100644
  
  /* bitmap for indexing intel_iommus */
  static int g_num_of_iommus;
-@@ -3626,10 +3626,8 @@ static void add_unmap(struct dmar_domain *dom, unsigned long iova_pfn,
+@@ -3719,10 +3719,8 @@ static void add_unmap(struct dmar_domain *dom, unsigned long iova_pfn,
        struct intel_iommu *iommu;
        struct deferred_flush_entry *entry;
        struct deferred_flush_data *flush_data;
@@ -4657,7 +4674,7 @@ index ebb5bf3ddbd9..598f5df45f6b 100644
  
        /* Flush all CPUs' entries to avoid deferring too much.  If
         * this becomes a bottleneck, can just flush us, and rely on
-@@ -3662,8 +3660,6 @@ static void add_unmap(struct dmar_domain *dom, unsigned long iova_pfn,
+@@ -3755,8 +3753,6 @@ static void add_unmap(struct dmar_domain *dom, unsigned long iova_pfn,
        }
        flush_data->size++;
        spin_unlock_irqrestore(&flush_data->lock, flags);
@@ -4749,23 +4766,41 @@ index 4d200883c505..98b64ed5cb81 100644
        Allows a block device to be used as cache for other devices; uses
        a btree for indexing and the layout is optimized for SSDs.
 diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
-index 5da86c8b6545..2aa092f2977e 100644
+index ba7c4c685db3..834ec328f217 100644
 --- a/drivers/md/dm-rq.c
 +++ b/drivers/md/dm-rq.c
-@@ -811,7 +811,7 @@ static void dm_old_request_fn(struct request_queue *q)
+@@ -842,7 +842,7 @@ static void dm_old_request_fn(struct request_queue *q)
                /* Establish tio->ti before queuing work (map_tio_request) */
                tio->ti = ti;
-               queue_kthread_work(&md->kworker, &tio->work);
+               kthread_queue_work(&md->kworker, &tio->work);
 -              BUG_ON(!irqs_disabled());
 +              BUG_ON_NONRT(!irqs_disabled());
        }
  }
  
 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
-index ee7fc3701700..ae59c9e13911 100644
+index 7aea0221530c..4dde911925dc 100644
 --- a/drivers/md/raid5.c
 +++ b/drivers/md/raid5.c
-@@ -1928,8 +1928,9 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
+@@ -429,7 +429,7 @@ void raid5_release_stripe(struct stripe_head *sh)
+               md_wakeup_thread(conf->mddev->thread);
+       return;
+ slow_path:
+-      local_irq_save(flags);
++      local_irq_save_nort(flags);
+       /* we are ok here if STRIPE_ON_RELEASE_LIST is set or not */
+       if (atomic_dec_and_lock(&sh->count, &conf->device_lock)) {
+               INIT_LIST_HEAD(&list);
+@@ -438,7 +438,7 @@ void raid5_release_stripe(struct stripe_head *sh)
+               spin_unlock(&conf->device_lock);
+               release_inactive_stripe_list(conf, &list, hash);
+       }
+-      local_irq_restore(flags);
++      local_irq_restore_nort(flags);
+ }
+ static inline void remove_hash(struct stripe_head *sh)
+@@ -1934,8 +1934,9 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
        struct raid5_percpu *percpu;
        unsigned long cpu;
  
@@ -4776,7 +4811,7 @@ index ee7fc3701700..ae59c9e13911 100644
        if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) {
                ops_run_biofill(sh);
                overlap_clear++;
-@@ -1985,7 +1986,8 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
+@@ -1991,7 +1992,8 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
                        if (test_and_clear_bit(R5_Overlap, &dev->flags))
                                wake_up(&sh->raid_conf->wait_for_overlap);
                }
@@ -4786,16 +4821,24 @@ index ee7fc3701700..ae59c9e13911 100644
  }
  
  static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp,
-@@ -6438,6 +6440,7 @@ static int raid5_alloc_percpu(struct r5conf *conf)
-                              __func__, cpu);
-                       break;
-               }
-+              spin_lock_init(&per_cpu_ptr(conf->percpu, cpu)->lock);
+@@ -6407,6 +6409,7 @@ static int raid456_cpu_up_prepare(unsigned int cpu, struct hlist_node *node)
+                      __func__, cpu);
+               return -ENOMEM;
        }
-       put_online_cpus();
++      spin_lock_init(&per_cpu_ptr(conf->percpu, cpu)->lock);
+       return 0;
+ }
  
+@@ -6417,7 +6420,6 @@ static int raid5_alloc_percpu(struct r5conf *conf)
+       conf->percpu = alloc_percpu(struct raid5_percpu);
+       if (!conf->percpu)
+               return -ENOMEM;
+-
+       err = cpuhp_state_add_instance(CPUHP_MD_RAID5_PREPARE, &conf->node);
+       if (!err) {
+               conf->scribble_disks = max(conf->raid_disks,
 diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
-index 517d4b68a1be..efe91887ecd7 100644
+index 57ec49f0839e..0739604990b7 100644
 --- a/drivers/md/raid5.h
 +++ b/drivers/md/raid5.h
 @@ -504,6 +504,7 @@ struct r5conf {
@@ -4807,7 +4850,7 @@ index 517d4b68a1be..efe91887ecd7 100644
                struct flex_array *scribble;   /* space for constructing buffer
                                              * lists and performing address
 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
-index d00252828966..9faab404faac 100644
+index 64971baf11fa..215e91e36198 100644
 --- a/drivers/misc/Kconfig
 +++ b/drivers/misc/Kconfig
 @@ -54,6 +54,7 @@ config AD525X_DPOT_SPI
@@ -4844,1300 +4887,6 @@ index d00252828966..9faab404faac 100644
  config DUMMY_IRQ
        tristate "Dummy IRQ handler"
        default n
-@@ -114,6 +123,35 @@ config IBM_ASM
-         for information on the specific driver level and support statement
-         for your IBM server.
-+config HWLAT_DETECTOR
-+      tristate "Testing module to detect hardware-induced latencies"
-+      depends on DEBUG_FS
-+      depends on RING_BUFFER
-+      default m
-+      ---help---
-+        A simple hardware latency detector. Use this module to detect
-+        large latencies introduced by the behavior of the underlying
-+        system firmware external to Linux. We do this using periodic
-+        use of stop_machine to grab all available CPUs and measure
-+        for unexplainable gaps in the CPU timestamp counter(s). By
-+        default, the module is not enabled until the "enable" file
-+        within the "hwlat_detector" debugfs directory is toggled.
-+
-+        This module is often used to detect SMI (System Management
-+        Interrupts) on x86 systems, though is not x86 specific. To
-+        this end, we default to using a sample window of 1 second,
-+        during which we will sample for 0.5 seconds. If an SMI or
-+        similar event occurs during that time, it is recorded
-+        into an 8K samples global ring buffer until retreived.
-+
-+        WARNING: This software should never be enabled (it can be built
-+        but should not be turned on after it is loaded) in a production
-+        environment where high latencies are a concern since the
-+        sampling mechanism actually introduces latencies for
-+        regular tasks while the CPU(s) are being held.
-+
-+        If unsure, say N
-+
- config PHANTOM
-       tristate "Sensable PHANToM (PCI)"
-       depends on PCI
-diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
-index fb32516ddfe2..8643df9af3c4 100644
---- a/drivers/misc/Makefile
-+++ b/drivers/misc/Makefile
-@@ -38,6 +38,7 @@ obj-$(CONFIG_C2PORT)         += c2port/
- obj-$(CONFIG_HMC6352)         += hmc6352.o
- obj-y                         += eeprom/
- obj-y                         += cb710/
-+obj-$(CONFIG_HWLAT_DETECTOR)  += hwlat_detector.o
- obj-$(CONFIG_SPEAR13XX_PCIE_GADGET)   += spear13xx_pcie_gadget.o
- obj-$(CONFIG_VMWARE_BALLOON)  += vmw_balloon.o
- obj-$(CONFIG_ARM_CHARLCD)     += arm-charlcd.o
-diff --git a/drivers/misc/hwlat_detector.c b/drivers/misc/hwlat_detector.c
-new file mode 100644
-index 000000000000..52f5ad5fd9c0
---- /dev/null
-+++ b/drivers/misc/hwlat_detector.c
-@@ -0,0 +1,1240 @@
-+/*
-+ * hwlat_detector.c - A simple Hardware Latency detector.
-+ *
-+ * Use this module to detect large system latencies induced by the behavior of
-+ * certain underlying system hardware or firmware, independent of Linux itself.
-+ * The code was developed originally to detect the presence of SMIs on Intel
-+ * and AMD systems, although there is no dependency upon x86 herein.
-+ *
-+ * The classical example usage of this module is in detecting the presence of
-+ * SMIs or System Management Interrupts on Intel and AMD systems. An SMI is a
-+ * somewhat special form of hardware interrupt spawned from earlier CPU debug
-+ * modes in which the (BIOS/EFI/etc.) firmware arranges for the South Bridge
-+ * LPC (or other device) to generate a special interrupt under certain
-+ * circumstances, for example, upon expiration of a special SMI timer device,
-+ * due to certain external thermal readings, on certain I/O address accesses,
-+ * and other situations. An SMI hits a special CPU pin, triggers a special
-+ * SMI mode (complete with special memory map), and the OS is unaware.
-+ *
-+ * Although certain hardware-inducing latencies are necessary (for example,
-+ * a modern system often requires an SMI handler for correct thermal control
-+ * and remote management) they can wreak havoc upon any OS-level performance
-+ * guarantees toward low-latency, especially when the OS is not even made
-+ * aware of the presence of these interrupts. For this reason, we need a
-+ * somewhat brute force mechanism to detect these interrupts. In this case,
-+ * we do it by hogging all of the CPU(s) for configurable timer intervals,
-+ * sampling the built-in CPU timer, looking for discontiguous readings.
-+ *
-+ * WARNING: This implementation necessarily introduces latencies. Therefore,
-+ *          you should NEVER use this module in a production environment
-+ *          requiring any kind of low-latency performance guarantee(s).
-+ *
-+ * Copyright (C) 2008-2009 Jon Masters, Red Hat, Inc. <jcm@redhat.com>
-+ *
-+ * Includes useful feedback from Clark Williams <clark@redhat.com>
-+ *
-+ * This file is licensed under the terms of the GNU General Public
-+ * License version 2. This program is licensed "as is" without any
-+ * warranty of any kind, whether express or implied.
-+ */
-+
-+#include <linux/module.h>
-+#include <linux/init.h>
-+#include <linux/ring_buffer.h>
-+#include <linux/time.h>
-+#include <linux/hrtimer.h>
-+#include <linux/kthread.h>
-+#include <linux/debugfs.h>
-+#include <linux/seq_file.h>
-+#include <linux/uaccess.h>
-+#include <linux/version.h>
-+#include <linux/delay.h>
-+#include <linux/slab.h>
-+#include <linux/trace_clock.h>
-+
-+#define BUF_SIZE_DEFAULT      262144UL                /* 8K*(sizeof(entry)) */
-+#define BUF_FLAGS             (RB_FL_OVERWRITE)       /* no block on full */
-+#define U64STR_SIZE           22                      /* 20 digits max */
-+
-+#define VERSION                       "1.0.0"
-+#define BANNER                        "hwlat_detector: "
-+#define DRVNAME                       "hwlat_detector"
-+#define DEFAULT_SAMPLE_WINDOW 1000000                 /* 1s */
-+#define DEFAULT_SAMPLE_WIDTH  500000                  /* 0.5s */
-+#define DEFAULT_LAT_THRESHOLD 10                      /* 10us */
-+
-+/* Module metadata */
-+
-+MODULE_LICENSE("GPL");
-+MODULE_AUTHOR("Jon Masters <jcm@redhat.com>");
-+MODULE_DESCRIPTION("A simple hardware latency detector");
-+MODULE_VERSION(VERSION);
-+
-+/* Module parameters */
-+
-+static int debug;
-+static int enabled;
-+static int threshold;
-+
-+module_param(debug, int, 0);                  /* enable debug */
-+module_param(enabled, int, 0);                        /* enable detector */
-+module_param(threshold, int, 0);              /* latency threshold */
-+
-+/* Buffering and sampling */
-+
-+static struct ring_buffer *ring_buffer;               /* sample buffer */
-+static DEFINE_MUTEX(ring_buffer_mutex);               /* lock changes */
-+static unsigned long buf_size = BUF_SIZE_DEFAULT;
-+static struct task_struct *kthread;           /* sampling thread */
-+
-+/* DebugFS filesystem entries */
-+
-+static struct dentry *debug_dir;              /* debugfs directory */
-+static struct dentry *debug_max;              /* maximum TSC delta */
-+static struct dentry *debug_count;            /* total detect count */
-+static struct dentry *debug_sample_width;     /* sample width us */
-+static struct dentry *debug_sample_window;    /* sample window us */
-+static struct dentry *debug_sample;           /* raw samples us */
-+static struct dentry *debug_threshold;                /* threshold us */
-+static struct dentry *debug_enable;           /* enable/disable */
-+
-+/* Individual samples and global state */
-+
-+struct sample;                                        /* latency sample */
-+struct data;                                  /* Global state */
-+
-+/* Sampling functions */
-+static int __buffer_add_sample(struct sample *sample);
-+static struct sample *buffer_get_sample(struct sample *sample);
-+
-+/* Threading and state */
-+static int kthread_fn(void *unused);
-+static int start_kthread(void);
-+static int stop_kthread(void);
-+static void __reset_stats(void);
-+static int init_stats(void);
-+
-+/* Debugfs interface */
-+static ssize_t simple_data_read(struct file *filp, char __user *ubuf,
-+                              size_t cnt, loff_t *ppos, const u64 *entry);
-+static ssize_t simple_data_write(struct file *filp, const char __user *ubuf,
-+                               size_t cnt, loff_t *ppos, u64 *entry);
-+static int debug_sample_fopen(struct inode *inode, struct file *filp);
-+static ssize_t debug_sample_fread(struct file *filp, char __user *ubuf,
-+                                size_t cnt, loff_t *ppos);
-+static int debug_sample_release(struct inode *inode, struct file *filp);
-+static int debug_enable_fopen(struct inode *inode, struct file *filp);
-+static ssize_t debug_enable_fread(struct file *filp, char __user *ubuf,
-+                                size_t cnt, loff_t *ppos);
-+static ssize_t debug_enable_fwrite(struct file *file,
-+                                 const char __user *user_buffer,
-+                                 size_t user_size, loff_t *offset);
-+
-+/* Initialization functions */
-+static int init_debugfs(void);
-+static void free_debugfs(void);
-+static int detector_init(void);
-+static void detector_exit(void);
-+
-+/* Individual latency samples are stored here when detected and packed into
-+ * the ring_buffer circular buffer, where they are overwritten when
-+ * more than buf_size/sizeof(sample) samples are received. */
-+struct sample {
-+      u64             seqnum;         /* unique sequence */
-+      u64             duration;       /* ktime delta */
-+      u64             outer_duration; /* ktime delta (outer loop) */
-+      struct timespec timestamp;      /* wall time */
-+      unsigned long   lost;
-+};
-+
-+/* keep the global state somewhere. */
-+static struct data {
-+
-+      struct mutex lock;              /* protect changes */
-+
-+      u64     count;                  /* total since reset */
-+      u64     max_sample;             /* max hardware latency */
-+      u64     threshold;              /* sample threshold level */
-+
-+      u64     sample_window;          /* total sampling window (on+off) */
-+      u64     sample_width;           /* active sampling portion of window */
-+
-+      atomic_t sample_open;           /* whether the sample file is open */
-+
-+      wait_queue_head_t wq;           /* waitqeue for new sample values */
-+
-+} data;
-+
-+/**
-+ * __buffer_add_sample - add a new latency sample recording to the ring buffer
-+ * @sample: The new latency sample value
-+ *
-+ * This receives a new latency sample and records it in a global ring buffer.
-+ * No additional locking is used in this case.
-+ */
-+static int __buffer_add_sample(struct sample *sample)
-+{
-+      return ring_buffer_write(ring_buffer,
-+                               sizeof(struct sample), sample);
-+}
-+
-+/**
-+ * buffer_get_sample - remove a hardware latency sample from the ring buffer
-+ * @sample: Pre-allocated storage for the sample
-+ *
-+ * This retrieves a hardware latency sample from the global circular buffer
-+ */
-+static struct sample *buffer_get_sample(struct sample *sample)
-+{
-+      struct ring_buffer_event *e = NULL;
-+      struct sample *s = NULL;
-+      unsigned int cpu = 0;
-+
-+      if (!sample)
-+              return NULL;
-+
-+      mutex_lock(&ring_buffer_mutex);
-+      for_each_online_cpu(cpu) {
-+              e = ring_buffer_consume(ring_buffer, cpu, NULL, &sample->lost);
-+              if (e)
-+                      break;
-+      }
-+
-+      if (e) {
-+              s = ring_buffer_event_data(e);
-+              memcpy(sample, s, sizeof(struct sample));
-+      } else
-+              sample = NULL;
-+      mutex_unlock(&ring_buffer_mutex);
-+
-+      return sample;
-+}
-+
-+#ifndef CONFIG_TRACING
-+#define time_type     ktime_t
-+#define time_get()    ktime_get()
-+#define time_to_us(x) ktime_to_us(x)
-+#define time_sub(a, b)        ktime_sub(a, b)
-+#define init_time(a, b)       (a).tv64 = b
-+#define time_u64(a)   ((a).tv64)
-+#else
-+#define time_type     u64
-+#define time_get()    trace_clock_local()
-+#define time_to_us(x) div_u64(x, 1000)
-+#define time_sub(a, b)        ((a) - (b))
-+#define init_time(a, b)       (a = b)
-+#define time_u64(a)   a
-+#endif
-+/**
-+ * get_sample - sample the CPU TSC and look for likely hardware latencies
-+ *
-+ * Used to repeatedly capture the CPU TSC (or similar), looking for potential
-+ * hardware-induced latency. Called with interrupts disabled and with
-+ * data.lock held.
-+ */
-+static int get_sample(void)
-+{
-+      time_type start, t1, t2, last_t2;
-+      s64 diff, total = 0;
-+      u64 sample = 0;
-+      u64 outer_sample = 0;
-+      int ret = -1;
-+
-+      init_time(last_t2, 0);
-+      start = time_get(); /* start timestamp */
-+
-+      do {
-+
-+              t1 = time_get();        /* we'll look for a discontinuity */
-+              t2 = time_get();
-+
-+              if (time_u64(last_t2)) {
-+                      /* Check the delta from outer loop (t2 to next t1) */
-+                      diff = time_to_us(time_sub(t1, last_t2));
-+                      /* This shouldn't happen */
-+                      if (diff < 0) {
-+                              pr_err(BANNER "time running backwards\n");
-+                              goto out;
-+                      }
-+                      if (diff > outer_sample)
-+                              outer_sample = diff;
-+              }
-+              last_t2 = t2;
-+
-+              total = time_to_us(time_sub(t2, start)); /* sample width */
-+
-+              /* This checks the inner loop (t1 to t2) */
-+              diff = time_to_us(time_sub(t2, t1));     /* current diff */
-+
-+              /* This shouldn't happen */
-+              if (diff < 0) {
-+                      pr_err(BANNER "time running backwards\n");
-+                      goto out;
-+              }
-+
-+              if (diff > sample)
-+                      sample = diff; /* only want highest value */
-+
-+      } while (total <= data.sample_width);
-+
-+      ret = 0;
-+
-+      /* If we exceed the threshold value, we have found a hardware latency */
-+      if (sample > data.threshold || outer_sample > data.threshold) {
-+              struct sample s;
-+
-+              ret = 1;
-+
-+              data.count++;
-+              s.seqnum = data.count;
-+              s.duration = sample;
-+              s.outer_duration = outer_sample;
-+              s.timestamp = CURRENT_TIME;
-+              __buffer_add_sample(&s);
-+
-+              /* Keep a running maximum ever recorded hardware latency */
-+              if (sample > data.max_sample)
-+                      data.max_sample = sample;
-+      }
-+
-+out:
-+      return ret;
-+}
-+
-+/*
-+ * kthread_fn - The CPU time sampling/hardware latency detection kernel thread
-+ * @unused: A required part of the kthread API.
-+ *
-+ * Used to periodically sample the CPU TSC via a call to get_sample. We
-+ * disable interrupts, which does (intentionally) introduce latency since we
-+ * need to ensure nothing else might be running (and thus pre-empting).
-+ * Obviously this should never be used in production environments.
-+ *
-+ * Currently this runs on which ever CPU it was scheduled on, but most
-+ * real-worald hardware latency situations occur across several CPUs,
-+ * but we might later generalize this if we find there are any actualy
-+ * systems with alternate SMI delivery or other hardware latencies.
-+ */
-+static int kthread_fn(void *unused)
-+{
-+      int ret;
-+      u64 interval;
-+
-+      while (!kthread_should_stop()) {
-+
-+              mutex_lock(&data.lock);
-+
-+              local_irq_disable();
-+              ret = get_sample();
-+              local_irq_enable();
-+
-+              if (ret > 0)
-+                      wake_up(&data.wq); /* wake up reader(s) */
-+
-+              interval = data.sample_window - data.sample_width;
-+              do_div(interval, USEC_PER_MSEC); /* modifies interval value */
-+
-+              mutex_unlock(&data.lock);
-+
-+              if (msleep_interruptible(interval))
-+                      break;
-+      }
-+
-+      return 0;
-+}
-+
-+/**
-+ * start_kthread - Kick off the hardware latency sampling/detector kthread
-+ *
-+ * This starts a kernel thread that will sit and sample the CPU timestamp
-+ * counter (TSC or similar) and look for potential hardware latencies.
-+ */
-+static int start_kthread(void)
-+{
-+      kthread = kthread_run(kthread_fn, NULL,
-+                                      DRVNAME);
-+      if (IS_ERR(kthread)) {
-+              pr_err(BANNER "could not start sampling thread\n");
-+              enabled = 0;
-+              return -ENOMEM;
-+      }
-+
-+      return 0;
-+}
-+
-+/**
-+ * stop_kthread - Inform the hardware latency samping/detector kthread to stop
-+ *
-+ * This kicks the running hardware latency sampling/detector kernel thread and
-+ * tells it to stop sampling now. Use this on unload and at system shutdown.
-+ */
-+static int stop_kthread(void)
-+{
-+      int ret;
-+
-+      ret = kthread_stop(kthread);
-+
-+      return ret;
-+}
-+
-+/**
-+ * __reset_stats - Reset statistics for the hardware latency detector
-+ *
-+ * We use data to store various statistics and global state. We call this
-+ * function in order to reset those when "enable" is toggled on or off, and
-+ * also at initialization. Should be called with data.lock held.
-+ */
-+static void __reset_stats(void)
-+{
-+      data.count = 0;
-+      data.max_sample = 0;
-+      ring_buffer_reset(ring_buffer); /* flush out old sample entries */
-+}
-+
-+/**
-+ * init_stats - Setup global state statistics for the hardware latency detector
-+ *
-+ * We use data to store various statistics and global state. We also use
-+ * a global ring buffer (ring_buffer) to keep raw samples of detected hardware
-+ * induced system latencies. This function initializes these structures and
-+ * allocates the global ring buffer also.
-+ */
-+static int init_stats(void)
-+{
-+      int ret = -ENOMEM;
-+
-+      mutex_init(&data.lock);
-+      init_waitqueue_head(&data.wq);
-+      atomic_set(&data.sample_open, 0);
-+
-+      ring_buffer = ring_buffer_alloc(buf_size, BUF_FLAGS);
-+
-+      if (WARN(!ring_buffer, KERN_ERR BANNER
-+                             "failed to allocate ring buffer!\n"))
-+              goto out;
-+
-+      __reset_stats();
-+      data.threshold = threshold ?: DEFAULT_LAT_THRESHOLD; /* threshold us */
-+      data.sample_window = DEFAULT_SAMPLE_WINDOW; /* window us */
-+      data.sample_width = DEFAULT_SAMPLE_WIDTH;   /* width us */
-+
-+      ret = 0;
-+
-+out:
-+      return ret;
-+
-+}
-+
-+/*
-+ * simple_data_read - Wrapper read function for global state debugfs entries
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The userspace provided buffer to read value into
-+ * @cnt: The maximum number of bytes to read
-+ * @ppos: The current "file" position
-+ * @entry: The entry to read from
-+ *
-+ * This function provides a generic read implementation for the global state
-+ * "data" structure debugfs filesystem entries. It would be nice to use
-+ * simple_attr_read directly, but we need to make sure that the data.lock
-+ * is held during the actual read.
-+ */
-+static ssize_t simple_data_read(struct file *filp, char __user *ubuf,
-+                              size_t cnt, loff_t *ppos, const u64 *entry)
-+{
-+      char buf[U64STR_SIZE];
-+      u64 val = 0;
-+      int len = 0;
-+
-+      memset(buf, 0, sizeof(buf));
-+
-+      if (!entry)
-+              return -EFAULT;
-+
-+      mutex_lock(&data.lock);
-+      val = *entry;
-+      mutex_unlock(&data.lock);
-+
-+      len = snprintf(buf, sizeof(buf), "%llu\n", (unsigned long long)val);
-+
-+      return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
-+
-+}
-+
-+/*
-+ * simple_data_write - Wrapper write function for global state debugfs entries
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The userspace provided buffer to write value from
-+ * @cnt: The maximum number of bytes to write
-+ * @ppos: The current "file" position
-+ * @entry: The entry to write to
-+ *
-+ * This function provides a generic write implementation for the global state
-+ * "data" structure debugfs filesystem entries. It would be nice to use
-+ * simple_attr_write directly, but we need to make sure that the data.lock
-+ * is held during the actual write.
-+ */
-+static ssize_t simple_data_write(struct file *filp, const char __user *ubuf,
-+                               size_t cnt, loff_t *ppos, u64 *entry)
-+{
-+      char buf[U64STR_SIZE];
-+      int csize = min(cnt, sizeof(buf));
-+      u64 val = 0;
-+      int err = 0;
-+
-+      memset(buf, '\0', sizeof(buf));
-+      if (copy_from_user(buf, ubuf, csize))
-+              return -EFAULT;
-+
-+      buf[U64STR_SIZE-1] = '\0';                      /* just in case */
-+      err = kstrtoull(buf, 10, &val);
-+      if (err)
-+              return -EINVAL;
-+
-+      mutex_lock(&data.lock);
-+      *entry = val;
-+      mutex_unlock(&data.lock);
-+
-+      return csize;
-+}
-+
-+/**
-+ * debug_count_fopen - Open function for "count" debugfs entry
-+ * @inode: The in-kernel inode representation of the debugfs "file"
-+ * @filp: The active open file structure for the debugfs "file"
-+ *
-+ * This function provides an open implementation for the "count" debugfs
-+ * interface to the hardware latency detector.
-+ */
-+static int debug_count_fopen(struct inode *inode, struct file *filp)
-+{
-+      return 0;
-+}
-+
-+/**
-+ * debug_count_fread - Read function for "count" debugfs entry
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The userspace provided buffer to read value into
-+ * @cnt: The maximum number of bytes to read
-+ * @ppos: The current "file" position
-+ *
-+ * This function provides a read implementation for the "count" debugfs
-+ * interface to the hardware latency detector. Can be used to read the
-+ * number of latency readings exceeding the configured threshold since
-+ * the detector was last reset (e.g. by writing a zero into "count").
-+ */
-+static ssize_t debug_count_fread(struct file *filp, char __user *ubuf,
-+                                   size_t cnt, loff_t *ppos)
-+{
-+      return simple_data_read(filp, ubuf, cnt, ppos, &data.count);
-+}
-+
-+/**
-+ * debug_count_fwrite - Write function for "count" debugfs entry
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The user buffer that contains the value to write
-+ * @cnt: The maximum number of bytes to write to "file"
-+ * @ppos: The current position in the debugfs "file"
-+ *
-+ * This function provides a write implementation for the "count" debugfs
-+ * interface to the hardware latency detector. Can be used to write a
-+ * desired value, especially to zero the total count.
-+ */
-+static ssize_t  debug_count_fwrite(struct file *filp,
-+                                     const char __user *ubuf,
-+                                     size_t cnt,
-+                                     loff_t *ppos)
-+{
-+      return simple_data_write(filp, ubuf, cnt, ppos, &data.count);
-+}
-+
-+/**
-+ * debug_enable_fopen - Dummy open function for "enable" debugfs interface
-+ * @inode: The in-kernel inode representation of the debugfs "file"
-+ * @filp: The active open file structure for the debugfs "file"
-+ *
-+ * This function provides an open implementation for the "enable" debugfs
-+ * interface to the hardware latency detector.
-+ */
-+static int debug_enable_fopen(struct inode *inode, struct file *filp)
-+{
-+      return 0;
-+}
-+
-+/**
-+ * debug_enable_fread - Read function for "enable" debugfs interface
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The userspace provided buffer to read value into
-+ * @cnt: The maximum number of bytes to read
-+ * @ppos: The current "file" position
-+ *
-+ * This function provides a read implementation for the "enable" debugfs
-+ * interface to the hardware latency detector. Can be used to determine
-+ * whether the detector is currently enabled ("0\n" or "1\n" returned).
-+ */
-+static ssize_t debug_enable_fread(struct file *filp, char __user *ubuf,
-+                                    size_t cnt, loff_t *ppos)
-+{
-+      char buf[4];
-+
-+      if ((cnt < sizeof(buf)) || (*ppos))
-+              return 0;
-+
-+      buf[0] = enabled ? '1' : '0';
-+      buf[1] = '\n';
-+      buf[2] = '\0';
-+      if (copy_to_user(ubuf, buf, strlen(buf)))
-+              return -EFAULT;
-+      return *ppos = strlen(buf);
-+}
-+
-+/**
-+ * debug_enable_fwrite - Write function for "enable" debugfs interface
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The user buffer that contains the value to write
-+ * @cnt: The maximum number of bytes to write to "file"
-+ * @ppos: The current position in the debugfs "file"
-+ *
-+ * This function provides a write implementation for the "enable" debugfs
-+ * interface to the hardware latency detector. Can be used to enable or
-+ * disable the detector, which will have the side-effect of possibly
-+ * also resetting the global stats and kicking off the measuring
-+ * kthread (on an enable) or the converse (upon a disable).
-+ */
-+static ssize_t  debug_enable_fwrite(struct file *filp,
-+                                      const char __user *ubuf,
-+                                      size_t cnt,
-+                                      loff_t *ppos)
-+{
-+      char buf[4];
-+      int csize = min(cnt, sizeof(buf));
-+      long val = 0;
-+      int err = 0;
-+
-+      memset(buf, '\0', sizeof(buf));
-+      if (copy_from_user(buf, ubuf, csize))
-+              return -EFAULT;
-+
-+      buf[sizeof(buf)-1] = '\0';                      /* just in case */
-+      err = kstrtoul(buf, 10, &val);
-+      if (err)
-+              return -EINVAL;
-+
-+      if (val) {
-+              if (enabled)
-+                      goto unlock;
-+              enabled = 1;
-+              __reset_stats();
-+              if (start_kthread())
-+                      return -EFAULT;
-+      } else {
-+              if (!enabled)
-+                      goto unlock;
-+              enabled = 0;
-+              err = stop_kthread();
-+              if (err) {
-+                      pr_err(BANNER "cannot stop kthread\n");
-+                      return -EFAULT;
-+              }
-+              wake_up(&data.wq);              /* reader(s) should return */
-+      }
-+unlock:
-+      return csize;
-+}
-+
-+/**
-+ * debug_max_fopen - Open function for "max" debugfs entry
-+ * @inode: The in-kernel inode representation of the debugfs "file"
-+ * @filp: The active open file structure for the debugfs "file"
-+ *
-+ * This function provides an open implementation for the "max" debugfs
-+ * interface to the hardware latency detector.
-+ */
-+static int debug_max_fopen(struct inode *inode, struct file *filp)
-+{
-+      return 0;
-+}
-+
-+/**
-+ * debug_max_fread - Read function for "max" debugfs entry
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The userspace provided buffer to read value into
-+ * @cnt: The maximum number of bytes to read
-+ * @ppos: The current "file" position
-+ *
-+ * This function provides a read implementation for the "max" debugfs
-+ * interface to the hardware latency detector. Can be used to determine
-+ * the maximum latency value observed since it was last reset.
-+ */
-+static ssize_t debug_max_fread(struct file *filp, char __user *ubuf,
-+                                 size_t cnt, loff_t *ppos)
-+{
-+      return simple_data_read(filp, ubuf, cnt, ppos, &data.max_sample);
-+}
-+
-+/**
-+ * debug_max_fwrite - Write function for "max" debugfs entry
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The user buffer that contains the value to write
-+ * @cnt: The maximum number of bytes to write to "file"
-+ * @ppos: The current position in the debugfs "file"
-+ *
-+ * This function provides a write implementation for the "max" debugfs
-+ * interface to the hardware latency detector. Can be used to reset the
-+ * maximum or set it to some other desired value - if, then, subsequent
-+ * measurements exceed this value, the maximum will be updated.
-+ */
-+static ssize_t  debug_max_fwrite(struct file *filp,
-+                                   const char __user *ubuf,
-+                                   size_t cnt,
-+                                   loff_t *ppos)
-+{
-+      return simple_data_write(filp, ubuf, cnt, ppos, &data.max_sample);
-+}
-+
-+
-+/**
-+ * debug_sample_fopen - An open function for "sample" debugfs interface
-+ * @inode: The in-kernel inode representation of this debugfs "file"
-+ * @filp: The active open file structure for the debugfs "file"
-+ *
-+ * This function handles opening the "sample" file within the hardware
-+ * latency detector debugfs directory interface. This file is used to read
-+ * raw samples from the global ring_buffer and allows the user to see a
-+ * running latency history. Can be opened blocking or non-blocking,
-+ * affecting whether it behaves as a buffer read pipe, or does not.
-+ * Implements simple locking to prevent multiple simultaneous use.
-+ */
-+static int debug_sample_fopen(struct inode *inode, struct file *filp)
-+{
-+      if (!atomic_add_unless(&data.sample_open, 1, 1))
-+              return -EBUSY;
-+      else
-+              return 0;
-+}
-+
-+/**
-+ * debug_sample_fread - A read function for "sample" debugfs interface
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The user buffer that will contain the samples read
-+ * @cnt: The maximum bytes to read from the debugfs "file"
-+ * @ppos: The current position in the debugfs "file"
-+ *
-+ * This function handles reading from the "sample" file within the hardware
-+ * latency detector debugfs directory interface. This file is used to read
-+ * raw samples from the global ring_buffer and allows the user to see a
-+ * running latency history. By default this will block pending a new
-+ * value written into the sample buffer, unless there are already a
-+ * number of value(s) waiting in the buffer, or the sample file was
-+ * previously opened in a non-blocking mode of operation.
-+ */
-+static ssize_t debug_sample_fread(struct file *filp, char __user *ubuf,
-+                                      size_t cnt, loff_t *ppos)
-+{
-+      int len = 0;
-+      char buf[64];
-+      struct sample *sample = NULL;
-+
-+      if (!enabled)
-+              return 0;
-+
-+      sample = kzalloc(sizeof(struct sample), GFP_KERNEL);
-+      if (!sample)
-+              return -ENOMEM;
-+
-+      while (!buffer_get_sample(sample)) {
-+
-+              DEFINE_WAIT(wait);
-+
-+              if (filp->f_flags & O_NONBLOCK) {
-+                      len = -EAGAIN;
-+                      goto out;
-+              }
-+
-+              prepare_to_wait(&data.wq, &wait, TASK_INTERRUPTIBLE);
-+              schedule();
-+              finish_wait(&data.wq, &wait);
-+
-+              if (signal_pending(current)) {
-+                      len = -EINTR;
-+                      goto out;
-+              }
-+
-+              if (!enabled) {                 /* enable was toggled */
-+                      len = 0;
-+                      goto out;
-+              }
-+      }
-+
-+      len = snprintf(buf, sizeof(buf), "%010lu.%010lu\t%llu\t%llu\n",
-+                     sample->timestamp.tv_sec,
-+                     sample->timestamp.tv_nsec,
-+                     sample->duration,
-+                     sample->outer_duration);
-+
-+
-+      /* handling partial reads is more trouble than it's worth */
-+      if (len > cnt)
-+              goto out;
-+
-+      if (copy_to_user(ubuf, buf, len))
-+              len = -EFAULT;
-+
-+out:
-+      kfree(sample);
-+      return len;
-+}
-+
-+/**
-+ * debug_sample_release - Release function for "sample" debugfs interface
-+ * @inode: The in-kernel inode represenation of the debugfs "file"
-+ * @filp: The active open file structure for the debugfs "file"
-+ *
-+ * This function completes the close of the debugfs interface "sample" file.
-+ * Frees the sample_open "lock" so that other users may open the interface.
-+ */
-+static int debug_sample_release(struct inode *inode, struct file *filp)
-+{
-+      atomic_dec(&data.sample_open);
-+
-+      return 0;
-+}
-+
-+/**
-+ * debug_threshold_fopen - Open function for "threshold" debugfs entry
-+ * @inode: The in-kernel inode representation of the debugfs "file"
-+ * @filp: The active open file structure for the debugfs "file"
-+ *
-+ * This function provides an open implementation for the "threshold" debugfs
-+ * interface to the hardware latency detector.
-+ */
-+static int debug_threshold_fopen(struct inode *inode, struct file *filp)
-+{
-+      return 0;
-+}
-+
-+/**
-+ * debug_threshold_fread - Read function for "threshold" debugfs entry
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The userspace provided buffer to read value into
-+ * @cnt: The maximum number of bytes to read
-+ * @ppos: The current "file" position
-+ *
-+ * This function provides a read implementation for the "threshold" debugfs
-+ * interface to the hardware latency detector. It can be used to determine
-+ * the current threshold level at which a latency will be recorded in the
-+ * global ring buffer, typically on the order of 10us.
-+ */
-+static ssize_t debug_threshold_fread(struct file *filp, char __user *ubuf,
-+                                       size_t cnt, loff_t *ppos)
-+{
-+      return simple_data_read(filp, ubuf, cnt, ppos, &data.threshold);
-+}
-+
-+/**
-+ * debug_threshold_fwrite - Write function for "threshold" debugfs entry
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The user buffer that contains the value to write
-+ * @cnt: The maximum number of bytes to write to "file"
-+ * @ppos: The current position in the debugfs "file"
-+ *
-+ * This function provides a write implementation for the "threshold" debugfs
-+ * interface to the hardware latency detector. It can be used to configure
-+ * the threshold level at which any subsequently detected latencies will
-+ * be recorded into the global ring buffer.
-+ */
-+static ssize_t  debug_threshold_fwrite(struct file *filp,
-+                                      const char __user *ubuf,
-+                                      size_t cnt,
-+                                      loff_t *ppos)
-+{
-+      int ret;
-+
-+      ret = simple_data_write(filp, ubuf, cnt, ppos, &data.threshold);
-+
-+      if (enabled)
-+              wake_up_process(kthread);
-+
-+      return ret;
-+}
-+
-+/**
-+ * debug_width_fopen - Open function for "width" debugfs entry
-+ * @inode: The in-kernel inode representation of the debugfs "file"
-+ * @filp: The active open file structure for the debugfs "file"
-+ *
-+ * This function provides an open implementation for the "width" debugfs
-+ * interface to the hardware latency detector.
-+ */
-+static int debug_width_fopen(struct inode *inode, struct file *filp)
-+{
-+      return 0;
-+}
-+
-+/**
-+ * debug_width_fread - Read function for "width" debugfs entry
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The userspace provided buffer to read value into
-+ * @cnt: The maximum number of bytes to read
-+ * @ppos: The current "file" position
-+ *
-+ * This function provides a read implementation for the "width" debugfs
-+ * interface to the hardware latency detector. It can be used to determine
-+ * for how many us of the total window us we will actively sample for any
-+ * hardware-induced latecy periods. Obviously, it is not possible to
-+ * sample constantly and have the system respond to a sample reader, or,
-+ * worse, without having the system appear to have gone out to lunch.
-+ */
-+static ssize_t debug_width_fread(struct file *filp, char __user *ubuf,
-+                                   size_t cnt, loff_t *ppos)
-+{
-+      return simple_data_read(filp, ubuf, cnt, ppos, &data.sample_width);
-+}
-+
-+/**
-+ * debug_width_fwrite - Write function for "width" debugfs entry
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The user buffer that contains the value to write
-+ * @cnt: The maximum number of bytes to write to "file"
-+ * @ppos: The current position in the debugfs "file"
-+ *
-+ * This function provides a write implementation for the "width" debugfs
-+ * interface to the hardware latency detector. It can be used to configure
-+ * for how many us of the total window us we will actively sample for any
-+ * hardware-induced latency periods. Obviously, it is not possible to
-+ * sample constantly and have the system respond to a sample reader, or,
-+ * worse, without having the system appear to have gone out to lunch. It
-+ * is enforced that width is less that the total window size.
-+ */
-+static ssize_t  debug_width_fwrite(struct file *filp,
-+                                     const char __user *ubuf,
-+                                     size_t cnt,
-+                                     loff_t *ppos)
-+{
-+      char buf[U64STR_SIZE];
-+      int csize = min(cnt, sizeof(buf));
-+      u64 val = 0;
-+      int err = 0;
-+
-+      memset(buf, '\0', sizeof(buf));
-+      if (copy_from_user(buf, ubuf, csize))
-+              return -EFAULT;
-+
-+      buf[U64STR_SIZE-1] = '\0';                      /* just in case */
-+      err = kstrtoull(buf, 10, &val);
-+      if (err)
-+              return -EINVAL;
-+
-+      mutex_lock(&data.lock);
-+      if (val < data.sample_window)
-+              data.sample_width = val;
-+      else {
-+              mutex_unlock(&data.lock);
-+              return -EINVAL;
-+      }
-+      mutex_unlock(&data.lock);
-+
-+      if (enabled)
-+              wake_up_process(kthread);
-+
-+      return csize;
-+}
-+
-+/**
-+ * debug_window_fopen - Open function for "window" debugfs entry
-+ * @inode: The in-kernel inode representation of the debugfs "file"
-+ * @filp: The active open file structure for the debugfs "file"
-+ *
-+ * This function provides an open implementation for the "window" debugfs
-+ * interface to the hardware latency detector. The window is the total time
-+ * in us that will be considered one sample period. Conceptually, windows
-+ * occur back-to-back and contain a sample width period during which
-+ * actual sampling occurs.
-+ */
-+static int debug_window_fopen(struct inode *inode, struct file *filp)
-+{
-+      return 0;
-+}
-+
-+/**
-+ * debug_window_fread - Read function for "window" debugfs entry
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The userspace provided buffer to read value into
-+ * @cnt: The maximum number of bytes to read
-+ * @ppos: The current "file" position
-+ *
-+ * This function provides a read implementation for the "window" debugfs
-+ * interface to the hardware latency detector. The window is the total time
-+ * in us that will be considered one sample period. Conceptually, windows
-+ * occur back-to-back and contain a sample width period during which
-+ * actual sampling occurs. Can be used to read the total window size.
-+ */
-+static ssize_t debug_window_fread(struct file *filp, char __user *ubuf,
-+                                    size_t cnt, loff_t *ppos)
-+{
-+      return simple_data_read(filp, ubuf, cnt, ppos, &data.sample_window);
-+}
-+
-+/**
-+ * debug_window_fwrite - Write function for "window" debugfs entry
-+ * @filp: The active open file structure for the debugfs "file"
-+ * @ubuf: The user buffer that contains the value to write
-+ * @cnt: The maximum number of bytes to write to "file"
-+ * @ppos: The current position in the debugfs "file"
-+ *
-+ * This function provides a write implementation for the "window" debufds
-+ * interface to the hardware latency detetector. The window is the total time
-+ * in us that will be considered one sample period. Conceptually, windows
-+ * occur back-to-back and contain a sample width period during which
-+ * actual sampling occurs. Can be used to write a new total window size. It
-+ * is enfoced that any value written must be greater than the sample width
-+ * size, or an error results.
-+ */
-+static ssize_t  debug_window_fwrite(struct file *filp,
-+                                      const char __user *ubuf,
-+                                      size_t cnt,
-+                                      loff_t *ppos)
-+{
-+      char buf[U64STR_SIZE];
-+      int csize = min(cnt, sizeof(buf));
-+      u64 val = 0;
-+      int err = 0;
-+
-+      memset(buf, '\0', sizeof(buf));
-+      if (copy_from_user(buf, ubuf, csize))
-+              return -EFAULT;
-+
-+      buf[U64STR_SIZE-1] = '\0';                      /* just in case */
-+      err = kstrtoull(buf, 10, &val);
-+      if (err)
-+              return -EINVAL;
-+
-+      mutex_lock(&data.lock);
-+      if (data.sample_width < val)
-+              data.sample_window = val;
-+      else {
-+              mutex_unlock(&data.lock);
-+              return -EINVAL;
-+      }
-+      mutex_unlock(&data.lock);
-+
-+      return csize;
-+}
-+
-+/*
-+ * Function pointers for the "count" debugfs file operations
-+ */
-+static const struct file_operations count_fops = {
-+      .open           = debug_count_fopen,
-+      .read           = debug_count_fread,
-+      .write          = debug_count_fwrite,
-+      .owner          = THIS_MODULE,
-+};
-+
-+/*
-+ * Function pointers for the "enable" debugfs file operations
-+ */
-+static const struct file_operations enable_fops = {
-+      .open           = debug_enable_fopen,
-+      .read           = debug_enable_fread,
-+      .write          = debug_enable_fwrite,
-+      .owner          = THIS_MODULE,
-+};
-+
-+/*
-+ * Function pointers for the "max" debugfs file operations
-+ */
-+static const struct file_operations max_fops = {
-+      .open           = debug_max_fopen,
-+      .read           = debug_max_fread,
-+      .write          = debug_max_fwrite,
-+      .owner          = THIS_MODULE,
-+};
-+
-+/*
-+ * Function pointers for the "sample" debugfs file operations
-+ */
-+static const struct file_operations sample_fops = {
-+      .open           = debug_sample_fopen,
-+      .read           = debug_sample_fread,
-+      .release        = debug_sample_release,
-+      .owner          = THIS_MODULE,
-+};
-+
-+/*
-+ * Function pointers for the "threshold" debugfs file operations
-+ */
-+static const struct file_operations threshold_fops = {
-+      .open           = debug_threshold_fopen,
-+      .read           = debug_threshold_fread,
-+      .write          = debug_threshold_fwrite,
-+      .owner          = THIS_MODULE,
-+};
-+
-+/*
-+ * Function pointers for the "width" debugfs file operations
-+ */
-+static const struct file_operations width_fops = {
-+      .open           = debug_width_fopen,
-+      .read           = debug_width_fread,
-+      .write          = debug_width_fwrite,
-+      .owner          = THIS_MODULE,
-+};
-+
-+/*
-+ * Function pointers for the "window" debugfs file operations
-+ */
-+static const struct file_operations window_fops = {
-+      .open           = debug_window_fopen,
-+      .read           = debug_window_fread,
-+      .write          = debug_window_fwrite,
-+      .owner          = THIS_MODULE,
-+};
-+
-+/**
-+ * init_debugfs - A function to initialize the debugfs interface files
-+ *
-+ * This function creates entries in debugfs for "hwlat_detector", including
-+ * files to read values from the detector, current samples, and the
-+ * maximum sample that has been captured since the hardware latency
-+ * dectector was started.
-+ */
-+static int init_debugfs(void)
-+{
-+      int ret = -ENOMEM;
-+
-+      debug_dir = debugfs_create_dir(DRVNAME, NULL);
-+      if (!debug_dir)
-+              goto err_debug_dir;
-+
-+      debug_sample = debugfs_create_file("sample", 0444,
-+                                             debug_dir, NULL,
-+                                             &sample_fops);
-+      if (!debug_sample)
-+              goto err_sample;
-+
-+      debug_count = debugfs_create_file("count", 0444,
-+                                            debug_dir, NULL,
-+                                            &count_fops);
-+      if (!debug_count)
-+              goto err_count;
-+
-+      debug_max = debugfs_create_file("max", 0444,
-+                                          debug_dir, NULL,
-+                                          &max_fops);
-+      if (!debug_max)
-+              goto err_max;
-+
-+      debug_sample_window = debugfs_create_file("window", 0644,
-+                                                    debug_dir, NULL,
-+                                                    &window_fops);
-+      if (!debug_sample_window)
-+              goto err_window;
-+
-+      debug_sample_width = debugfs_create_file("width", 0644,
-+                                                   debug_dir, NULL,
-+                                                   &width_fops);
-+      if (!debug_sample_width)
-+              goto err_width;
-+
-+      debug_threshold = debugfs_create_file("threshold", 0644,
-+                                                debug_dir, NULL,
-+                                                &threshold_fops);
-+      if (!debug_threshold)
-+              goto err_threshold;
-+
-+      debug_enable = debugfs_create_file("enable", 0644,
-+                                             debug_dir, &enabled,
-+                                             &enable_fops);
-+      if (!debug_enable)
-+              goto err_enable;
-+
-+      else {
-+              ret = 0;
-+              goto out;
-+      }
-+
-+err_enable:
-+      debugfs_remove(debug_threshold);
-+err_threshold:
-+      debugfs_remove(debug_sample_width);
-+err_width:
-+      debugfs_remove(debug_sample_window);
-+err_window:
-+      debugfs_remove(debug_max);
-+err_max:
-+      debugfs_remove(debug_count);
-+err_count:
-+      debugfs_remove(debug_sample);
-+err_sample:
-+      debugfs_remove(debug_dir);
-+err_debug_dir:
-+out:
-+      return ret;
-+}
-+
-+/**
-+ * free_debugfs - A function to cleanup the debugfs file interface
-+ */
-+static void free_debugfs(void)
-+{
-+      /* could also use a debugfs_remove_recursive */
-+      debugfs_remove(debug_enable);
-+      debugfs_remove(debug_threshold);
-+      debugfs_remove(debug_sample_width);
-+      debugfs_remove(debug_sample_window);
-+      debugfs_remove(debug_max);
-+      debugfs_remove(debug_count);
-+      debugfs_remove(debug_sample);
-+      debugfs_remove(debug_dir);
-+}
-+
-+/**
-+ * detector_init - Standard module initialization code
-+ */
-+static int detector_init(void)
-+{
-+      int ret = -ENOMEM;
-+
-+      pr_info(BANNER "version %s\n", VERSION);
-+
-+      ret = init_stats();
-+      if (ret)
-+              goto out;
-+
-+      ret = init_debugfs();
-+      if (ret)
-+              goto err_stats;
-+
-+      if (enabled)
-+              ret = start_kthread();
-+
-+      goto out;
-+
-+err_stats:
-+      ring_buffer_free(ring_buffer);
-+out:
-+      return ret;
-+
-+}
-+
-+/**
-+ * detector_exit - Standard module cleanup code
-+ */
-+static void detector_exit(void)
-+{
-+      int err;
-+
-+      if (enabled) {
-+              enabled = 0;
-+              err = stop_kthread();
-+              if (err)
-+                      pr_err(BANNER "cannot stop kthread\n");
-+      }
-+
-+      free_debugfs();
-+      ring_buffer_free(ring_buffer);  /* free up the ring buffer */
-+
-+}
-+
-+module_init(detector_init);
-+module_exit(detector_exit);
 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
 index df990bb8c873..1a162709a85e 100644
 --- a/drivers/mmc/host/mmci.c
@@ -6168,7 +4917,7 @@ index df990bb8c873..1a162709a85e 100644
         * If we have less than the fifo 'half-full' threshold to transfer,
         * trigger a PIO interrupt as soon as any data is available.
 diff --git a/drivers/net/ethernet/3com/3c59x.c b/drivers/net/ethernet/3com/3c59x.c
-index 25c55ab05c7d..5a1d117a8744 100644
+index 9133e7926da5..63afb921ed40 100644
 --- a/drivers/net/ethernet/3com/3c59x.c
 +++ b/drivers/net/ethernet/3com/3c59x.c
 @@ -842,9 +842,9 @@ static void poll_vortex(struct net_device *dev)
@@ -6212,7 +4961,7 @@ index da4c2d8a4173..1420dfb56bac 100644
        enable_irq(irq);
  }
 diff --git a/drivers/net/wireless/intersil/orinoco/orinoco_usb.c b/drivers/net/wireless/intersil/orinoco/orinoco_usb.c
-index 56f109bc8394..02afc796bc71 100644
+index bca6935a94db..d7a35ee34d03 100644
 --- a/drivers/net/wireless/intersil/orinoco/orinoco_usb.c
 +++ b/drivers/net/wireless/intersil/orinoco/orinoco_usb.c
 @@ -697,7 +697,7 @@ static void ezusb_req_ctx_wait(struct ezusb_priv *upriv,
@@ -6224,19 +4973,215 @@ index 56f109bc8394..02afc796bc71 100644
                                                 ctx->done.done);
                }
                break;
-diff --git a/drivers/pci/access.c b/drivers/pci/access.c
-index d11cdbb8fba3..223bbb9acb03 100644
---- a/drivers/pci/access.c
-+++ b/drivers/pci/access.c
-@@ -672,7 +672,7 @@ void pci_cfg_access_unlock(struct pci_dev *dev)
-       WARN_ON(!dev->block_cfg_access);
-       dev->block_cfg_access = 0;
--      wake_up_all(&pci_cfg_wait);
-+      wake_up_all_locked(&pci_cfg_wait);
-       raw_spin_unlock_irqrestore(&pci_lock, flags);
- }
- EXPORT_SYMBOL_GPL(pci_cfg_access_unlock);
+diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c
+index bedce3453dd3..faf038978650 100644
+--- a/drivers/pinctrl/qcom/pinctrl-msm.c
++++ b/drivers/pinctrl/qcom/pinctrl-msm.c
+@@ -61,7 +61,7 @@ struct msm_pinctrl {
+       struct notifier_block restart_nb;
+       int irq;
+-      spinlock_t lock;
++      raw_spinlock_t lock;
+       DECLARE_BITMAP(dual_edge_irqs, MAX_NR_GPIO);
+       DECLARE_BITMAP(enabled_irqs, MAX_NR_GPIO);
+@@ -153,14 +153,14 @@ static int msm_pinmux_set_mux(struct pinctrl_dev *pctldev,
+       if (WARN_ON(i == g->nfuncs))
+               return -EINVAL;
+-      spin_lock_irqsave(&pctrl->lock, flags);
++      raw_spin_lock_irqsave(&pctrl->lock, flags);
+       val = readl(pctrl->regs + g->ctl_reg);
+       val &= ~mask;
+       val |= i << g->mux_bit;
+       writel(val, pctrl->regs + g->ctl_reg);
+-      spin_unlock_irqrestore(&pctrl->lock, flags);
++      raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+       return 0;
+ }
+@@ -323,14 +323,14 @@ static int msm_config_group_set(struct pinctrl_dev *pctldev,
+                       break;
+               case PIN_CONFIG_OUTPUT:
+                       /* set output value */
+-                      spin_lock_irqsave(&pctrl->lock, flags);
++                      raw_spin_lock_irqsave(&pctrl->lock, flags);
+                       val = readl(pctrl->regs + g->io_reg);
+                       if (arg)
+                               val |= BIT(g->out_bit);
+                       else
+                               val &= ~BIT(g->out_bit);
+                       writel(val, pctrl->regs + g->io_reg);
+-                      spin_unlock_irqrestore(&pctrl->lock, flags);
++                      raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+                       /* enable output */
+                       arg = 1;
+@@ -351,12 +351,12 @@ static int msm_config_group_set(struct pinctrl_dev *pctldev,
+                       return -EINVAL;
+               }
+-              spin_lock_irqsave(&pctrl->lock, flags);
++              raw_spin_lock_irqsave(&pctrl->lock, flags);
+               val = readl(pctrl->regs + g->ctl_reg);
+               val &= ~(mask << bit);
+               val |= arg << bit;
+               writel(val, pctrl->regs + g->ctl_reg);
+-              spin_unlock_irqrestore(&pctrl->lock, flags);
++              raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+       }
+       return 0;
+@@ -384,13 +384,13 @@ static int msm_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+       g = &pctrl->soc->groups[offset];
+-      spin_lock_irqsave(&pctrl->lock, flags);
++      raw_spin_lock_irqsave(&pctrl->lock, flags);
+       val = readl(pctrl->regs + g->ctl_reg);
+       val &= ~BIT(g->oe_bit);
+       writel(val, pctrl->regs + g->ctl_reg);
+-      spin_unlock_irqrestore(&pctrl->lock, flags);
++      raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+       return 0;
+ }
+@@ -404,7 +404,7 @@ static int msm_gpio_direction_output(struct gpio_chip *chip, unsigned offset, in
+       g = &pctrl->soc->groups[offset];
+-      spin_lock_irqsave(&pctrl->lock, flags);
++      raw_spin_lock_irqsave(&pctrl->lock, flags);
+       val = readl(pctrl->regs + g->io_reg);
+       if (value)
+@@ -417,7 +417,7 @@ static int msm_gpio_direction_output(struct gpio_chip *chip, unsigned offset, in
+       val |= BIT(g->oe_bit);
+       writel(val, pctrl->regs + g->ctl_reg);
+-      spin_unlock_irqrestore(&pctrl->lock, flags);
++      raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+       return 0;
+ }
+@@ -443,7 +443,7 @@ static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
+       g = &pctrl->soc->groups[offset];
+-      spin_lock_irqsave(&pctrl->lock, flags);
++      raw_spin_lock_irqsave(&pctrl->lock, flags);
+       val = readl(pctrl->regs + g->io_reg);
+       if (value)
+@@ -452,7 +452,7 @@ static void msm_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
+               val &= ~BIT(g->out_bit);
+       writel(val, pctrl->regs + g->io_reg);
+-      spin_unlock_irqrestore(&pctrl->lock, flags);
++      raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+ }
+ #ifdef CONFIG_DEBUG_FS
+@@ -571,7 +571,7 @@ static void msm_gpio_irq_mask(struct irq_data *d)
+       g = &pctrl->soc->groups[d->hwirq];
+-      spin_lock_irqsave(&pctrl->lock, flags);
++      raw_spin_lock_irqsave(&pctrl->lock, flags);
+       val = readl(pctrl->regs + g->intr_cfg_reg);
+       val &= ~BIT(g->intr_enable_bit);
+@@ -579,7 +579,7 @@ static void msm_gpio_irq_mask(struct irq_data *d)
+       clear_bit(d->hwirq, pctrl->enabled_irqs);
+-      spin_unlock_irqrestore(&pctrl->lock, flags);
++      raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+ }
+ static void msm_gpio_irq_unmask(struct irq_data *d)
+@@ -592,7 +592,7 @@ static void msm_gpio_irq_unmask(struct irq_data *d)
+       g = &pctrl->soc->groups[d->hwirq];
+-      spin_lock_irqsave(&pctrl->lock, flags);
++      raw_spin_lock_irqsave(&pctrl->lock, flags);
+       val = readl(pctrl->regs + g->intr_cfg_reg);
+       val |= BIT(g->intr_enable_bit);
+@@ -600,7 +600,7 @@ static void msm_gpio_irq_unmask(struct irq_data *d)
+       set_bit(d->hwirq, pctrl->enabled_irqs);
+-      spin_unlock_irqrestore(&pctrl->lock, flags);
++      raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+ }
+ static void msm_gpio_irq_ack(struct irq_data *d)
+@@ -613,7 +613,7 @@ static void msm_gpio_irq_ack(struct irq_data *d)
+       g = &pctrl->soc->groups[d->hwirq];
+-      spin_lock_irqsave(&pctrl->lock, flags);
++      raw_spin_lock_irqsave(&pctrl->lock, flags);
+       val = readl(pctrl->regs + g->intr_status_reg);
+       if (g->intr_ack_high)
+@@ -625,7 +625,7 @@ static void msm_gpio_irq_ack(struct irq_data *d)
+       if (test_bit(d->hwirq, pctrl->dual_edge_irqs))
+               msm_gpio_update_dual_edge_pos(pctrl, g, d);
+-      spin_unlock_irqrestore(&pctrl->lock, flags);
++      raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+ }
+ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
+@@ -638,7 +638,7 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
+       g = &pctrl->soc->groups[d->hwirq];
+-      spin_lock_irqsave(&pctrl->lock, flags);
++      raw_spin_lock_irqsave(&pctrl->lock, flags);
+       /*
+        * For hw without possibility of detecting both edges
+@@ -712,7 +712,7 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
+       if (test_bit(d->hwirq, pctrl->dual_edge_irqs))
+               msm_gpio_update_dual_edge_pos(pctrl, g, d);
+-      spin_unlock_irqrestore(&pctrl->lock, flags);
++      raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+       if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
+               irq_set_handler_locked(d, handle_level_irq);
+@@ -728,11 +728,11 @@ static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
+       struct msm_pinctrl *pctrl = gpiochip_get_data(gc);
+       unsigned long flags;
+-      spin_lock_irqsave(&pctrl->lock, flags);
++      raw_spin_lock_irqsave(&pctrl->lock, flags);
+       irq_set_irq_wake(pctrl->irq, on);
+-      spin_unlock_irqrestore(&pctrl->lock, flags);
++      raw_spin_unlock_irqrestore(&pctrl->lock, flags);
+       return 0;
+ }
+@@ -878,7 +878,7 @@ int msm_pinctrl_probe(struct platform_device *pdev,
+       pctrl->soc = soc_data;
+       pctrl->chip = msm_gpio_template;
+-      spin_lock_init(&pctrl->lock);
++      raw_spin_lock_init(&pctrl->lock);
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       pctrl->regs = devm_ioremap_resource(&pdev->dev, res);
 diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
 index 9bd41a35a78a..8e2d436c2e3f 100644
 --- a/drivers/scsi/fcoe/fcoe.c
@@ -6318,7 +5263,7 @@ index dcf36537a767..1a1f2e46452c 100644
        list_for_each_entry_safe(fcf, next, &del_list, list) {
                /* Removes fcf from current list */
 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
-index e72673b0a8fb..da598a6caa22 100644
+index 16ca31ad5ec0..c3987347e762 100644
 --- a/drivers/scsi/libfc/fc_exch.c
 +++ b/drivers/scsi/libfc/fc_exch.c
 @@ -814,10 +814,10 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
@@ -6335,7 +5280,7 @@ index e72673b0a8fb..da598a6caa22 100644
        /* peek cache of free slot */
        if (pool->left != FC_XID_UNKNOWN) {
 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
-index 763f012fdeca..d0f61b595470 100644
+index 87f5e694dbed..23c0a50fb6aa 100644
 --- a/drivers/scsi/libsas/sas_ata.c
 +++ b/drivers/scsi/libsas/sas_ata.c
 @@ -190,7 +190,7 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
@@ -6376,10 +5321,10 @@ index edc48f3b8230..ee5c6f9dfb6f 100644
  
  static inline uint8_t *
 diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
-index 987f1c729e9c..18391e07d70f 100644
+index bddaabb288d4..8de0ec4222fe 100644
 --- a/drivers/scsi/qla2xxx/qla_isr.c
 +++ b/drivers/scsi/qla2xxx/qla_isr.c
-@@ -3125,7 +3125,11 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
+@@ -3129,7 +3129,11 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
                * kref_put().
                */
                kref_get(&qentry->irq_notify.kref);
@@ -6392,7 +5337,7 @@ index 987f1c729e9c..18391e07d70f 100644
  
        /*
 diff --git a/drivers/thermal/x86_pkg_temp_thermal.c b/drivers/thermal/x86_pkg_temp_thermal.c
-index 97f0a2bd93ed..a4f45aaa9ad4 100644
+index 95f4c1bcdb4c..0be934799bff 100644
 --- a/drivers/thermal/x86_pkg_temp_thermal.c
 +++ b/drivers/thermal/x86_pkg_temp_thermal.c
 @@ -29,6 +29,7 @@
@@ -6403,7 +5348,7 @@ index 97f0a2bd93ed..a4f45aaa9ad4 100644
  #include <asm/cpu_device_id.h>
  #include <asm/mce.h>
  
-@@ -352,7 +353,7 @@ static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
+@@ -353,7 +354,7 @@ static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
        }
  }
  
@@ -6412,7 +5357,7 @@ index 97f0a2bd93ed..a4f45aaa9ad4 100644
  {
        unsigned long flags;
        int cpu = smp_processor_id();
-@@ -369,7 +370,7 @@ static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
+@@ -370,7 +371,7 @@ static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
                        pkg_work_scheduled[phy_id]) {
                disable_pkg_thres_interrupt();
                spin_unlock_irqrestore(&pkg_work_lock, flags);
@@ -6421,7 +5366,7 @@ index 97f0a2bd93ed..a4f45aaa9ad4 100644
        }
        pkg_work_scheduled[phy_id] = 1;
        spin_unlock_irqrestore(&pkg_work_lock, flags);
-@@ -378,9 +379,48 @@ static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
+@@ -379,9 +380,48 @@ static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
        schedule_delayed_work_on(cpu,
                                &per_cpu(pkg_temp_thermal_threshold_work, cpu),
                                msecs_to_jiffies(notify_delay_ms));
@@ -6470,7 +5415,7 @@ index 97f0a2bd93ed..a4f45aaa9ad4 100644
  static int find_siblings_cpu(int cpu)
  {
        int i;
-@@ -584,6 +624,9 @@ static int __init pkg_temp_thermal_init(void)
+@@ -585,6 +625,9 @@ static int __init pkg_temp_thermal_init(void)
        if (!x86_match_cpu(pkg_temp_thermal_ids))
                return -ENODEV;
  
@@ -6480,7 +5425,7 @@ index 97f0a2bd93ed..a4f45aaa9ad4 100644
        spin_lock_init(&pkg_work_lock);
        platform_thermal_package_notify =
                        pkg_temp_thermal_platform_thermal_notify;
-@@ -608,7 +651,7 @@ static int __init pkg_temp_thermal_init(void)
+@@ -609,7 +652,7 @@ static int __init pkg_temp_thermal_init(void)
        kfree(pkg_work_scheduled);
        platform_thermal_package_notify = NULL;
        platform_thermal_package_rate_control = NULL;
@@ -6489,7 +5434,7 @@ index 97f0a2bd93ed..a4f45aaa9ad4 100644
        return -ENODEV;
  }
  
-@@ -633,6 +676,7 @@ static void __exit pkg_temp_thermal_exit(void)
+@@ -634,6 +677,7 @@ static void __exit pkg_temp_thermal_exit(void)
        mutex_unlock(&phy_dev_list_mutex);
        platform_thermal_package_notify = NULL;
        platform_thermal_package_rate_control = NULL;
@@ -6498,7 +5443,7 @@ index 97f0a2bd93ed..a4f45aaa9ad4 100644
                cancel_delayed_work_sync(
                        &per_cpu(pkg_temp_thermal_threshold_work, i));
 diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
-index dcf43f66404f..a9ae57122841 100644
+index e8819aa20415..dd7f9bf45d6c 100644
 --- a/drivers/tty/serial/8250/8250_core.c
 +++ b/drivers/tty/serial/8250/8250_core.c
 @@ -58,7 +58,16 @@ static struct uart_driver serial8250_reg;
@@ -6520,7 +5465,7 @@ index dcf43f66404f..a9ae57122841 100644
  #include <asm/serial.h>
  /*
 diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
-index 858a54633664..fc44fb59aef6 100644
+index f6e4373a8850..4620b51b0e7c 100644
 --- a/drivers/tty/serial/8250/8250_port.c
 +++ b/drivers/tty/serial/8250/8250_port.c
 @@ -35,6 +35,7 @@
@@ -6531,7 +5476,7 @@ index 858a54633664..fc44fb59aef6 100644
  #include <linux/uaccess.h>
  #include <linux/pm_runtime.h>
  #include <linux/timer.h>
-@@ -3109,9 +3110,9 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s,
+@@ -3143,9 +3144,9 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s,
  
        serial8250_rpm_get(up);
  
@@ -6544,10 +5489,10 @@ index 858a54633664..fc44fb59aef6 100644
        else
                spin_lock_irqsave(&port->lock, flags);
 diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
-index 8a9e213387a7..dd1f9a426b74 100644
+index e2c33b9528d8..53af53c43e8c 100644
 --- a/drivers/tty/serial/amba-pl011.c
 +++ b/drivers/tty/serial/amba-pl011.c
-@@ -2167,13 +2167,19 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
+@@ -2194,13 +2194,19 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
  
        clk_enable(uap->clk);
  
@@ -6570,7 +5515,7 @@ index 8a9e213387a7..dd1f9a426b74 100644
  
        /*
         *      First save the CR then disable the interrupts
-@@ -2197,8 +2203,7 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
+@@ -2224,8 +2230,7 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
                pl011_write(old_cr, uap, REG_CR);
  
        if (locked)
@@ -6581,7 +5526,7 @@ index 8a9e213387a7..dd1f9a426b74 100644
        clk_disable(uap->clk);
  }
 diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
-index a2a529994ba5..0ee7c4c518df 100644
+index 472ba3c813c1..e654cb421fb7 100644
 --- a/drivers/tty/serial/omap-serial.c
 +++ b/drivers/tty/serial/omap-serial.c
 @@ -1257,13 +1257,10 @@ serial_omap_console_write(struct console *co, const char *s,
@@ -6611,24 +5556,11 @@ index a2a529994ba5..0ee7c4c518df 100644
  }
  
  static int __init
-diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
-index f36e6df2fa90..e086ea4d2997 100644
---- a/drivers/tty/serial/sc16is7xx.c
-+++ b/drivers/tty/serial/sc16is7xx.c
-@@ -1240,7 +1240,7 @@ static int sc16is7xx_probe(struct device *dev,
-       /* Setup interrupt */
-       ret = devm_request_irq(dev, irq, sc16is7xx_irq,
--                             IRQF_ONESHOT | flags, dev_name(dev), s);
-+                             flags, dev_name(dev), s);
-       if (!ret)
-               return 0;
 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
-index d2e3f655c26f..fdd027a9bbd7 100644
+index fcc7aa248ce7..fb2c38d875f9 100644
 --- a/drivers/usb/core/hcd.c
 +++ b/drivers/usb/core/hcd.c
-@@ -1760,9 +1760,9 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
+@@ -1764,9 +1764,9 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
         * and no one may trigger the above deadlock situation when
         * running complete() in tasklet.
         */
@@ -6641,10 +5573,10 @@ index d2e3f655c26f..fdd027a9bbd7 100644
        usb_anchor_resume_wakeups(anchor);
        atomic_dec(&urb->use_count);
 diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
-index 5c8429f23a89..fa835fb1a186 100644
+index 4fce83266926..5e902a89d8e6 100644
 --- a/drivers/usb/gadget/function/f_fs.c
 +++ b/drivers/usb/gadget/function/f_fs.c
-@@ -1509,7 +1509,7 @@ static void ffs_data_put(struct ffs_data *ffs)
+@@ -1593,7 +1593,7 @@ static void ffs_data_put(struct ffs_data *ffs)
                pr_info("%s(): freeing\n", __func__);
                ffs_data_clear(ffs);
                BUG_ON(waitqueue_active(&ffs->ev.waitq) ||
@@ -6654,10 +5586,10 @@ index 5c8429f23a89..fa835fb1a186 100644
                kfree(ffs);
        }
 diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
-index 16104b5ebdcb..5c506c2b88ad 100644
+index f69dbd4bcd18..3b7638322f9f 100644
 --- a/drivers/usb/gadget/legacy/inode.c
 +++ b/drivers/usb/gadget/legacy/inode.c
-@@ -346,7 +346,7 @@ ep_io (struct ep_data *epdata, void *buf, unsigned len)
+@@ -347,7 +347,7 @@ ep_io (struct ep_data *epdata, void *buf, unsigned len)
        spin_unlock_irq (&epdata->dev->lock);
  
        if (likely (value == 0)) {
@@ -6666,7 +5598,7 @@ index 16104b5ebdcb..5c506c2b88ad 100644
                if (value != 0) {
                        spin_lock_irq (&epdata->dev->lock);
                        if (likely (epdata->ep != NULL)) {
-@@ -355,7 +355,7 @@ ep_io (struct ep_data *epdata, void *buf, unsigned len)
+@@ -356,7 +356,7 @@ ep_io (struct ep_data *epdata, void *buf, unsigned len)
                                usb_ep_dequeue (epdata->ep, epdata->req);
                                spin_unlock_irq (&epdata->dev->lock);
  
@@ -6676,7 +5608,7 @@ index 16104b5ebdcb..5c506c2b88ad 100644
                                        epdata->status = -EINTR;
                        } else {
 diff --git a/fs/aio.c b/fs/aio.c
-index 4fe81d1c60f9..e68c06a4a017 100644
+index 0fcb49ad67d4..211ebc21e4db 100644
 --- a/fs/aio.c
 +++ b/fs/aio.c
 @@ -40,6 +40,7 @@
@@ -6704,7 +5636,7 @@ index 4fe81d1c60f9..e68c06a4a017 100644
        aio_mnt = kern_mount(&aio_fs);
        if (IS_ERR(aio_mnt))
                panic("Failed to create aio fs mount.");
-@@ -578,9 +580,9 @@ static int kiocb_cancel(struct aio_kiocb *kiocb)
+@@ -581,9 +583,9 @@ static int kiocb_cancel(struct aio_kiocb *kiocb)
        return cancel(&kiocb->common);
  }
  
@@ -6716,7 +5648,7 @@ index 4fe81d1c60f9..e68c06a4a017 100644
  
        pr_debug("freeing %p\n", ctx);
  
-@@ -599,8 +601,8 @@ static void free_ioctx_reqs(struct percpu_ref *ref)
+@@ -602,8 +604,8 @@ static void free_ioctx_reqs(struct percpu_ref *ref)
        if (ctx->rq_wait && atomic_dec_and_test(&ctx->rq_wait->count))
                complete(&ctx->rq_wait->comp);
  
@@ -6727,7 +5659,7 @@ index 4fe81d1c60f9..e68c06a4a017 100644
  }
  
  /*
-@@ -608,9 +610,9 @@ static void free_ioctx_reqs(struct percpu_ref *ref)
+@@ -611,9 +613,9 @@ static void free_ioctx_reqs(struct percpu_ref *ref)
   * and ctx->users has dropped to 0, so we know no more kiocbs can be submitted -
   * now it's safe to cancel any that need to be.
   */
@@ -6739,7 +5671,7 @@ index 4fe81d1c60f9..e68c06a4a017 100644
        struct aio_kiocb *req;
  
        spin_lock_irq(&ctx->ctx_lock);
-@@ -629,6 +631,14 @@ static void free_ioctx_users(struct percpu_ref *ref)
+@@ -632,6 +634,14 @@ static void free_ioctx_users(struct percpu_ref *ref)
        percpu_ref_put(&ctx->reqs);
  }
  
@@ -6755,10 +5687,10 @@ index 4fe81d1c60f9..e68c06a4a017 100644
  {
        unsigned i, new_nr;
 diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
-index a439548de785..7c392647d03b 100644
+index a1fba4285277..3796769b4cd1 100644
 --- a/fs/autofs4/autofs_i.h
 +++ b/fs/autofs4/autofs_i.h
-@@ -30,6 +30,7 @@
+@@ -31,6 +31,7 @@
  #include <linux/sched.h>
  #include <linux/mount.h>
  #include <linux/namei.h>
@@ -6780,7 +5712,7 @@ index d8e6d421c27f..2e689ab1306b 100644
                        }
                        spin_unlock(&p->d_lock);
 diff --git a/fs/buffer.c b/fs/buffer.c
-index 9c8eb9b6db6a..d15d77f72cf7 100644
+index 5d8f496d624e..48074bd91ea3 100644
 --- a/fs/buffer.c
 +++ b/fs/buffer.c
 @@ -301,8 +301,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
@@ -6842,7 +5774,7 @@ index 9c8eb9b6db6a..d15d77f72cf7 100644
  }
  EXPORT_SYMBOL(end_buffer_async_write);
  
-@@ -3384,6 +3376,7 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)
+@@ -3383,6 +3375,7 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)
        struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
        if (ret) {
                INIT_LIST_HEAD(&ret->b_assoc_buffers);
@@ -6851,7 +5783,7 @@ index 9c8eb9b6db6a..d15d77f72cf7 100644
                __this_cpu_inc(bh_accounting.nr);
                recalc_bh_state();
 diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
-index 8f6a2a5863b9..4217828d0b68 100644
+index a27fc8791551..791aecb7c1ac 100644
 --- a/fs/cifs/readdir.c
 +++ b/fs/cifs/readdir.c
 @@ -80,7 +80,7 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,
@@ -6864,7 +5796,7 @@ index 8f6a2a5863b9..4217828d0b68 100644
        cifs_dbg(FYI, "%s: for %s\n", __func__, name->name);
  
 diff --git a/fs/dcache.c b/fs/dcache.c
-index 5c7cc953ac81..a9bb31f1c1af 100644
+index 67957f5b325c..f0719b2f1be5 100644
 --- a/fs/dcache.c
 +++ b/fs/dcache.c
 @@ -19,6 +19,7 @@
@@ -6875,7 +5807,7 @@ index 5c7cc953ac81..a9bb31f1c1af 100644
  #include <linux/slab.h>
  #include <linux/init.h>
  #include <linux/hash.h>
-@@ -750,6 +751,8 @@ static inline bool fast_dput(struct dentry *dentry)
+@@ -777,6 +778,8 @@ static inline bool fast_dput(struct dentry *dentry)
   */
  void dput(struct dentry *dentry)
  {
@@ -6884,7 +5816,7 @@ index 5c7cc953ac81..a9bb31f1c1af 100644
        if (unlikely(!dentry))
                return;
  
-@@ -788,9 +791,18 @@ void dput(struct dentry *dentry)
+@@ -815,9 +818,18 @@ void dput(struct dentry *dentry)
        return;
  
  kill_it:
@@ -6906,7 +5838,7 @@ index 5c7cc953ac81..a9bb31f1c1af 100644
                goto repeat;
        }
  }
-@@ -2321,7 +2333,7 @@ void d_delete(struct dentry * dentry)
+@@ -2352,7 +2364,7 @@ void d_delete(struct dentry * dentry)
        if (dentry->d_lockref.count == 1) {
                if (!spin_trylock(&inode->i_lock)) {
                        spin_unlock(&dentry->d_lock);
@@ -6915,7 +5847,27 @@ index 5c7cc953ac81..a9bb31f1c1af 100644
                        goto again;
                }
                dentry->d_flags &= ~DCACHE_CANT_MOUNT;
-@@ -2381,21 +2393,24 @@ static inline void end_dir_add(struct inode *dir, unsigned n)
+@@ -2397,9 +2409,10 @@ EXPORT_SYMBOL(d_rehash);
+ static inline unsigned start_dir_add(struct inode *dir)
+ {
++      preempt_disable_rt();
+       for (;;) {
+-              unsigned n = dir->i_dir_seq;
+-              if (!(n & 1) && cmpxchg(&dir->i_dir_seq, n, n + 1) == n)
++              unsigned n = dir->__i_dir_seq;
++              if (!(n & 1) && cmpxchg(&dir->__i_dir_seq, n, n + 1) == n)
+                       return n;
+               cpu_relax();
+       }
+@@ -2407,26 +2420,30 @@ static inline unsigned start_dir_add(struct inode *dir)
+ static inline void end_dir_add(struct inode *dir, unsigned n)
+ {
+-      smp_store_release(&dir->i_dir_seq, n + 2);
++      smp_store_release(&dir->__i_dir_seq, n + 2);
++      preempt_enable_rt();
+ }
  
  static void d_wait_lookup(struct dentry *dentry)
  {
@@ -6951,7 +5903,25 @@ index 5c7cc953ac81..a9bb31f1c1af 100644
  {
        unsigned int hash = name->hash;
        struct hlist_bl_head *b = in_lookup_hash(parent, hash);
-@@ -2504,7 +2519,7 @@ void __d_lookup_done(struct dentry *dentry)
+@@ -2440,7 +2457,7 @@ struct dentry *d_alloc_parallel(struct dentry *parent,
+ retry:
+       rcu_read_lock();
+-      seq = smp_load_acquire(&parent->d_inode->i_dir_seq) & ~1;
++      seq = smp_load_acquire(&parent->d_inode->__i_dir_seq) & ~1;
+       r_seq = read_seqbegin(&rename_lock);
+       dentry = __d_lookup_rcu(parent, name, &d_seq);
+       if (unlikely(dentry)) {
+@@ -2462,7 +2479,7 @@ struct dentry *d_alloc_parallel(struct dentry *parent,
+               goto retry;
+       }
+       hlist_bl_lock(b);
+-      if (unlikely(parent->d_inode->i_dir_seq != seq)) {
++      if (unlikely(parent->d_inode->__i_dir_seq != seq)) {
+               hlist_bl_unlock(b);
+               rcu_read_unlock();
+               goto retry;
+@@ -2535,7 +2552,7 @@ void __d_lookup_done(struct dentry *dentry)
        hlist_bl_lock(b);
        dentry->d_flags &= ~DCACHE_PAR_LOOKUP;
        __hlist_bl_del(&dentry->d_u.d_in_lookup_hash);
@@ -6960,7 +5930,7 @@ index 5c7cc953ac81..a9bb31f1c1af 100644
        dentry->d_wait = NULL;
        hlist_bl_unlock(b);
        INIT_HLIST_NODE(&dentry->d_u.d_alias);
-@@ -3601,6 +3616,11 @@ EXPORT_SYMBOL(d_genocide);
+@@ -3632,6 +3649,11 @@ EXPORT_SYMBOL(d_genocide);
  
  void __init vfs_caches_init_early(void)
  {
@@ -6973,7 +5943,7 @@ index 5c7cc953ac81..a9bb31f1c1af 100644
        inode_init_early();
  }
 diff --git a/fs/eventpoll.c b/fs/eventpoll.c
-index 10db91218933..42af0a06f657 100644
+index 3cbc30413add..41a94f552aab 100644
 --- a/fs/eventpoll.c
 +++ b/fs/eventpoll.c
 @@ -510,12 +510,12 @@ static int ep_poll_wakeup_proc(void *priv, void *cookie, int call_nests)
@@ -6992,55 +5962,255 @@ index 10db91218933..42af0a06f657 100644
  
  static void ep_remove_wait_queue(struct eppoll_entry *pwq)
 diff --git a/fs/exec.c b/fs/exec.c
-index 6fcfb3f7b137..751370a71ec5 100644
+index b8c43be24751..71f4c6ec2bb8 100644
 --- a/fs/exec.c
 +++ b/fs/exec.c
-@@ -1012,12 +1012,14 @@ static int exec_mmap(struct mm_struct *mm)
+@@ -1038,12 +1038,14 @@ static int exec_mmap(struct mm_struct *mm)
                }
        }
-       task_lock(tsk);
-+      preempt_disable_rt();
-       active_mm = tsk->active_mm;
-       tsk->mm = mm;
-       tsk->active_mm = mm;
-       activate_mm(active_mm, mm);
-       tsk->mm->vmacache_seqnum = 0;
-       vmacache_flush(tsk);
-+      preempt_enable_rt();
-       task_unlock(tsk);
-       if (old_mm) {
-               up_read(&old_mm->mmap_sem);
-diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
-index 4ff9251e9d3a..8fe489ec2ef1 100644
---- a/fs/fuse/dir.c
-+++ b/fs/fuse/dir.c
-@@ -1174,7 +1174,7 @@ static int fuse_direntplus_link(struct file *file,
-       struct inode *dir = d_inode(parent);
-       struct fuse_conn *fc;
-       struct inode *inode;
--      DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
-+      DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
+       task_lock(tsk);
++      preempt_disable_rt();
+       active_mm = tsk->active_mm;
+       tsk->mm = mm;
+       tsk->active_mm = mm;
+       activate_mm(active_mm, mm);
+       tsk->mm->vmacache_seqnum = 0;
+       vmacache_flush(tsk);
++      preempt_enable_rt();
+       task_unlock(tsk);
+       if (old_mm) {
+               up_read(&old_mm->mmap_sem);
+diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
+index 0094923e5ebf..37fa06ef5417 100644
+--- a/fs/ext4/page-io.c
++++ b/fs/ext4/page-io.c
+@@ -95,8 +95,7 @@ static void ext4_finish_bio(struct bio *bio)
+                * We check all buffers in the page under BH_Uptodate_Lock
+                * to avoid races with other end io clearing async_write flags
+                */
+-              local_irq_save(flags);
+-              bit_spin_lock(BH_Uptodate_Lock, &head->b_state);
++              flags = bh_uptodate_lock_irqsave(head);
+               do {
+                       if (bh_offset(bh) < bio_start ||
+                           bh_offset(bh) + bh->b_size > bio_end) {
+@@ -108,8 +107,7 @@ static void ext4_finish_bio(struct bio *bio)
+                       if (bio->bi_error)
+                               buffer_io_error(bh);
+               } while ((bh = bh->b_this_page) != head);
+-              bit_spin_unlock(BH_Uptodate_Lock, &head->b_state);
+-              local_irq_restore(flags);
++              bh_uptodate_unlock_irqrestore(head, flags);
+               if (!under_io) {
+ #ifdef CONFIG_EXT4_FS_ENCRYPTION
+                       if (data_page)
+diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
+index 4bbad745415a..5f91ca248ab0 100644
+--- a/fs/fuse/dir.c
++++ b/fs/fuse/dir.c
+@@ -1191,7 +1191,7 @@ static int fuse_direntplus_link(struct file *file,
+       struct inode *dir = d_inode(parent);
+       struct fuse_conn *fc;
+       struct inode *inode;
+-      DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
++      DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
+       if (!o->nodeid) {
+               /*
+diff --git a/fs/inode.c b/fs/inode.c
+index 920aa0b1c6b0..3d6b5fd1bf06 100644
+--- a/fs/inode.c
++++ b/fs/inode.c
+@@ -153,7 +153,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
+       inode->i_bdev = NULL;
+       inode->i_cdev = NULL;
+       inode->i_link = NULL;
+-      inode->i_dir_seq = 0;
++      inode->__i_dir_seq = 0;
+       inode->i_rdev = 0;
+       inode->dirtied_when = 0;
+diff --git a/fs/libfs.c b/fs/libfs.c
+index 9588780ad43e..9b37abd354c9 100644
+--- a/fs/libfs.c
++++ b/fs/libfs.c
+@@ -89,7 +89,7 @@ static struct dentry *next_positive(struct dentry *parent,
+                                   struct list_head *from,
+                                   int count)
+ {
+-      unsigned *seq = &parent->d_inode->i_dir_seq, n;
++      unsigned *seq = &parent->d_inode->__i_dir_seq, n;
+       struct dentry *res;
+       struct list_head *p;
+       bool skipped;
+@@ -122,8 +122,9 @@ static struct dentry *next_positive(struct dentry *parent,
+ static void move_cursor(struct dentry *cursor, struct list_head *after)
+ {
+       struct dentry *parent = cursor->d_parent;
+-      unsigned n, *seq = &parent->d_inode->i_dir_seq;
++      unsigned n, *seq = &parent->d_inode->__i_dir_seq;
+       spin_lock(&parent->d_lock);
++      preempt_disable_rt();
+       for (;;) {
+               n = *seq;
+               if (!(n & 1) && cmpxchg(seq, n, n + 1) == n)
+@@ -136,6 +137,7 @@ static void move_cursor(struct dentry *cursor, struct list_head *after)
+       else
+               list_add_tail(&cursor->d_child, &parent->d_subdirs);
+       smp_store_release(seq, n + 2);
++      preempt_enable_rt();
+       spin_unlock(&parent->d_lock);
+ }
+diff --git a/fs/locks.c b/fs/locks.c
+index 22c5b4aa4961..269c6a44449a 100644
+--- a/fs/locks.c
++++ b/fs/locks.c
+@@ -935,7 +935,7 @@ static int flock_lock_inode(struct inode *inode, struct file_lock *request)
+                       return -ENOMEM;
+       }
+-      percpu_down_read_preempt_disable(&file_rwsem);
++      percpu_down_read(&file_rwsem);
+       spin_lock(&ctx->flc_lock);
+       if (request->fl_flags & FL_ACCESS)
+               goto find_conflict;
+@@ -976,7 +976,7 @@ static int flock_lock_inode(struct inode *inode, struct file_lock *request)
+ out:
+       spin_unlock(&ctx->flc_lock);
+-      percpu_up_read_preempt_enable(&file_rwsem);
++      percpu_up_read(&file_rwsem);
+       if (new_fl)
+               locks_free_lock(new_fl);
+       locks_dispose_list(&dispose);
+@@ -1013,7 +1013,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
+               new_fl2 = locks_alloc_lock();
+       }
+-      percpu_down_read_preempt_disable(&file_rwsem);
++      percpu_down_read(&file_rwsem);
+       spin_lock(&ctx->flc_lock);
+       /*
+        * New lock request. Walk all POSIX locks and look for conflicts. If
+@@ -1185,7 +1185,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
+       }
+  out:
+       spin_unlock(&ctx->flc_lock);
+-      percpu_up_read_preempt_enable(&file_rwsem);
++      percpu_up_read(&file_rwsem);
+       /*
+        * Free any unused locks.
+        */
+@@ -1460,7 +1460,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
+               return error;
+       }
+-      percpu_down_read_preempt_disable(&file_rwsem);
++      percpu_down_read(&file_rwsem);
+       spin_lock(&ctx->flc_lock);
+       time_out_leases(inode, &dispose);
+@@ -1512,13 +1512,13 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
+       locks_insert_block(fl, new_fl);
+       trace_break_lease_block(inode, new_fl);
+       spin_unlock(&ctx->flc_lock);
+-      percpu_up_read_preempt_enable(&file_rwsem);
++      percpu_up_read(&file_rwsem);
+       locks_dispose_list(&dispose);
+       error = wait_event_interruptible_timeout(new_fl->fl_wait,
+                                               !new_fl->fl_next, break_time);
+-      percpu_down_read_preempt_disable(&file_rwsem);
++      percpu_down_read(&file_rwsem);
+       spin_lock(&ctx->flc_lock);
+       trace_break_lease_unblock(inode, new_fl);
+       locks_delete_block(new_fl);
+@@ -1535,7 +1535,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
+       }
+ out:
+       spin_unlock(&ctx->flc_lock);
+-      percpu_up_read_preempt_enable(&file_rwsem);
++      percpu_up_read(&file_rwsem);
+       locks_dispose_list(&dispose);
+       locks_free_lock(new_fl);
+       return error;
+@@ -1609,7 +1609,7 @@ int fcntl_getlease(struct file *filp)
+       ctx = smp_load_acquire(&inode->i_flctx);
+       if (ctx && !list_empty_careful(&ctx->flc_lease)) {
+-              percpu_down_read_preempt_disable(&file_rwsem);
++              percpu_down_read(&file_rwsem);
+               spin_lock(&ctx->flc_lock);
+               time_out_leases(inode, &dispose);
+               list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
+@@ -1619,7 +1619,7 @@ int fcntl_getlease(struct file *filp)
+                       break;
+               }
+               spin_unlock(&ctx->flc_lock);
+-              percpu_up_read_preempt_enable(&file_rwsem);
++              percpu_up_read(&file_rwsem);
+               locks_dispose_list(&dispose);
+       }
+@@ -1694,7 +1694,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
+               return -EINVAL;
+       }
  
-       if (!o->nodeid) {
-               /*
-diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
-index 684996c8a3a4..6e18a06aaabe 100644
---- a/fs/jbd2/checkpoint.c
-+++ b/fs/jbd2/checkpoint.c
-@@ -116,6 +116,8 @@ void __jbd2_log_wait_for_space(journal_t *journal)
-       nblocks = jbd2_space_needed(journal);
-       while (jbd2_log_space_left(journal) < nblocks) {
-               write_unlock(&journal->j_state_lock);
-+              if (current->plug)
-+                      io_schedule();
-               mutex_lock(&journal->j_checkpoint_mutex);
+-      percpu_down_read_preempt_disable(&file_rwsem);
++      percpu_down_read(&file_rwsem);
+       spin_lock(&ctx->flc_lock);
+       time_out_leases(inode, &dispose);
+       error = check_conflicting_open(dentry, arg, lease->fl_flags);
+@@ -1765,7 +1765,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
+               lease->fl_lmops->lm_setup(lease, priv);
+ out:
+       spin_unlock(&ctx->flc_lock);
+-      percpu_up_read_preempt_enable(&file_rwsem);
++      percpu_up_read(&file_rwsem);
+       locks_dispose_list(&dispose);
+       if (is_deleg)
+               inode_unlock(inode);
+@@ -1788,7 +1788,7 @@ static int generic_delete_lease(struct file *filp, void *owner)
+               return error;
+       }
  
-               /*
+-      percpu_down_read_preempt_disable(&file_rwsem);
++      percpu_down_read(&file_rwsem);
+       spin_lock(&ctx->flc_lock);
+       list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
+               if (fl->fl_file == filp &&
+@@ -1801,7 +1801,7 @@ static int generic_delete_lease(struct file *filp, void *owner)
+       if (victim)
+               error = fl->fl_lmops->lm_change(victim, F_UNLCK, &dispose);
+       spin_unlock(&ctx->flc_lock);
+-      percpu_up_read_preempt_enable(&file_rwsem);
++      percpu_up_read(&file_rwsem);
+       locks_dispose_list(&dispose);
+       return error;
+ }
+@@ -2532,13 +2532,13 @@ locks_remove_lease(struct file *filp, struct file_lock_context *ctx)
+       if (list_empty(&ctx->flc_lease))
+               return;
+-      percpu_down_read_preempt_disable(&file_rwsem);
++      percpu_down_read(&file_rwsem);
+       spin_lock(&ctx->flc_lock);
+       list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list)
+               if (filp == fl->fl_file)
+                       lease_modify(fl, F_UNLCK, &dispose);
+       spin_unlock(&ctx->flc_lock);
+-      percpu_up_read_preempt_enable(&file_rwsem);
++      percpu_up_read(&file_rwsem);
+       locks_dispose_list(&dispose);
+ }
 diff --git a/fs/namei.c b/fs/namei.c
-index adb04146df09..a89dfaf9f209 100644
+index e7d125c23aa6..072a2f724437 100644
 --- a/fs/namei.c
 +++ b/fs/namei.c
-@@ -1629,7 +1629,7 @@ static struct dentry *lookup_slow(const struct qstr *name,
+@@ -1626,7 +1626,7 @@ static struct dentry *lookup_slow(const struct qstr *name,
  {
        struct dentry *dentry = ERR_PTR(-ENOENT), *old;
        struct inode *inode = dir->d_inode;
@@ -7049,7 +6219,7 @@ index adb04146df09..a89dfaf9f209 100644
  
        inode_lock_shared(inode);
        /* Don't go there if it's already dead */
-@@ -3086,7 +3086,7 @@ static int lookup_open(struct nameidata *nd, struct path *path,
+@@ -3089,7 +3089,7 @@ static int lookup_open(struct nameidata *nd, struct path *path,
        struct dentry *dentry;
        int error, create_error = 0;
        umode_t mode = op->mode;
@@ -7059,7 +6229,7 @@ index adb04146df09..a89dfaf9f209 100644
        if (unlikely(IS_DEADDIR(dir_inode)))
                return -ENOENT;
 diff --git a/fs/namespace.c b/fs/namespace.c
-index 7bb2cda3bfef..cf79b18e7b58 100644
+index d7360f9897b4..da188c6966a3 100644
 --- a/fs/namespace.c
 +++ b/fs/namespace.c
 @@ -14,6 +14,7 @@
@@ -7070,7 +6240,7 @@ index 7bb2cda3bfef..cf79b18e7b58 100644
  #include <linux/security.h>
  #include <linux/idr.h>
  #include <linux/init.h>               /* init_rootfs */
-@@ -353,8 +354,11 @@ int __mnt_want_write(struct vfsmount *m)
+@@ -357,8 +358,11 @@ int __mnt_want_write(struct vfsmount *m)
         * incremented count after it has set MNT_WRITE_HOLD.
         */
        smp_mb();
@@ -7085,7 +6255,7 @@ index 7bb2cda3bfef..cf79b18e7b58 100644
         * After the slowpath clears MNT_WRITE_HOLD, mnt_is_readonly will
         * be set to match its requirements. So we must not load that until
 diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
-index b9c65421ed81..03ffe8af8785 100644
+index dff600ae0d74..d726d2e09353 100644
 --- a/fs/nfs/delegation.c
 +++ b/fs/nfs/delegation.c
 @@ -150,11 +150,11 @@ static int nfs_delegation_claim_opens(struct inode *inode,
@@ -7103,7 +6273,7 @@ index b9c65421ed81..03ffe8af8785 100644
                mutex_unlock(&sp->so_delegreturn_mutex);
                put_nfs_open_context(ctx);
 diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
-index 6bc5a68e39f1..ce6488e07a13 100644
+index 65566d5fcf39..5f08183dddcd 100644
 --- a/fs/nfs/dir.c
 +++ b/fs/nfs/dir.c
 @@ -485,7 +485,7 @@ static
@@ -7115,7 +6285,7 @@ index 6bc5a68e39f1..ce6488e07a13 100644
        struct dentry *dentry;
        struct dentry *alias;
        struct inode *dir = d_inode(parent);
-@@ -1490,7 +1490,7 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
+@@ -1492,7 +1492,7 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
                    struct file *file, unsigned open_flags,
                    umode_t mode, int *opened)
  {
@@ -7124,7 +6294,7 @@ index 6bc5a68e39f1..ce6488e07a13 100644
        struct nfs_open_context *ctx;
        struct dentry *res;
        struct iattr attr = { .ia_valid = ATTR_OPEN };
-@@ -1805,7 +1805,11 @@ int nfs_rmdir(struct inode *dir, struct dentry *dentry)
+@@ -1807,7 +1807,11 @@ int nfs_rmdir(struct inode *dir, struct dentry *dentry)
  
        trace_nfs_rmdir_enter(dir, dentry);
        if (d_really_is_positive(dentry)) {
@@ -7136,7 +6306,7 @@ index 6bc5a68e39f1..ce6488e07a13 100644
                error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name);
                /* Ensure the VFS deletes this inode */
                switch (error) {
-@@ -1815,7 +1819,11 @@ int nfs_rmdir(struct inode *dir, struct dentry *dentry)
+@@ -1817,7 +1821,11 @@ int nfs_rmdir(struct inode *dir, struct dentry *dentry)
                case -ENOENT:
                        nfs_dentry_handle_enoent(dentry);
                }
@@ -7149,7 +6319,7 @@ index 6bc5a68e39f1..ce6488e07a13 100644
                error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name);
        trace_nfs_rmdir_exit(dir, dentry, error);
 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
-index bf4ec5ecc97e..36cd5fc9192c 100644
+index 76ae25661d3f..89159d298278 100644
 --- a/fs/nfs/inode.c
 +++ b/fs/nfs/inode.c
 @@ -1957,7 +1957,11 @@ static void init_once(void *foo)
@@ -7165,10 +6335,10 @@ index bf4ec5ecc97e..36cd5fc9192c 100644
  }
  
 diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
-index 9bf64eacba5b..041da5cb80f5 100644
+index 1452177c822d..f43b01d54c59 100644
 --- a/fs/nfs/nfs4_fs.h
 +++ b/fs/nfs/nfs4_fs.h
-@@ -107,7 +107,7 @@ struct nfs4_state_owner {
+@@ -111,7 +111,7 @@ struct nfs4_state_owner {
        unsigned long        so_flags;
        struct list_head     so_states;
        struct nfs_seqid_counter so_seqid;
@@ -7178,10 +6348,10 @@ index 9bf64eacba5b..041da5cb80f5 100644
  };
  
 diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
-index a9dec32ba9ba..49b64dfb307c 100644
+index 4638654e26f3..5dd6fd555c72 100644
 --- a/fs/nfs/nfs4proc.c
 +++ b/fs/nfs/nfs4proc.c
-@@ -2525,7 +2525,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
+@@ -2691,7 +2691,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
        unsigned int seq;
        int ret;
  
@@ -7190,8 +6360,8 @@ index a9dec32ba9ba..49b64dfb307c 100644
  
        ret = _nfs4_proc_open(opendata);
        if (ret != 0)
-@@ -2561,7 +2561,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
-       ctx->state = state;
+@@ -2729,7 +2729,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
        if (d_inode(dentry) == state->inode) {
                nfs_inode_attach_open_context(ctx);
 -              if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq))
@@ -7200,7 +6370,7 @@ index a9dec32ba9ba..49b64dfb307c 100644
        }
  out:
 diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
-index 8353f33f0466..657e13ed4b5d 100644
+index 71deeae6eefd..4be6999299dc 100644
 --- a/fs/nfs/nfs4state.c
 +++ b/fs/nfs/nfs4state.c
 @@ -488,7 +488,7 @@ nfs4_alloc_state_owner(struct nfs_server *server,
@@ -7212,7 +6382,7 @@ index 8353f33f0466..657e13ed4b5d 100644
        mutex_init(&sp->so_delegreturn_mutex);
        return sp;
  }
-@@ -1459,8 +1459,12 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
+@@ -1498,8 +1498,12 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
         * recovering after a network partition or a reboot from a
         * server that doesn't support a grace period.
         */
@@ -7226,7 +6396,7 @@ index 8353f33f0466..657e13ed4b5d 100644
  restart:
        list_for_each_entry(state, &sp->so_states, open_states) {
                if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
-@@ -1528,14 +1532,20 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
+@@ -1568,14 +1572,20 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
                spin_lock(&sp->so_lock);
                goto restart;
        }
@@ -7402,10 +6572,10 @@ index fe251f187ff8..e89da4fb14c2 100644
  
  /**
 diff --git a/fs/proc/base.c b/fs/proc/base.c
-index ac0df4dde823..ad1a4723ffdd 100644
+index e67fec3c9856..0edc16f95596 100644
 --- a/fs/proc/base.c
 +++ b/fs/proc/base.c
-@@ -1819,7 +1819,7 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx,
+@@ -1834,7 +1834,7 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx,
  
        child = d_hash_and_lookup(dir, &qname);
        if (!child) {
@@ -7415,10 +6585,10 @@ index ac0df4dde823..ad1a4723ffdd 100644
                if (IS_ERR(child))
                        goto end_instantiate;
 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
-index 1b93650dda2f..c553bf3ea541 100644
+index d4e37acd4821..000cea46434a 100644
 --- a/fs/proc/proc_sysctl.c
 +++ b/fs/proc/proc_sysctl.c
-@@ -627,7 +627,7 @@ static bool proc_sys_fill_cache(struct file *file,
+@@ -632,7 +632,7 @@ static bool proc_sys_fill_cache(struct file *file,
  
        child = d_lookup(dir, &qname);
        if (!child) {
@@ -7428,10 +6598,10 @@ index 1b93650dda2f..c553bf3ea541 100644
                if (IS_ERR(child))
                        return false;
 diff --git a/fs/timerfd.c b/fs/timerfd.c
-index 9ae4abb4110b..8644b67c48fd 100644
+index ab8dd1538381..5580853f57dd 100644
 --- a/fs/timerfd.c
 +++ b/fs/timerfd.c
-@@ -460,7 +460,10 @@ static int do_timerfd_settime(int ufd, int flags,
+@@ -471,7 +471,10 @@ static int do_timerfd_settime(int ufd, int flags,
                                break;
                }
                spin_unlock_irq(&ctx->wqh.lock);
@@ -7443,11 +6613,35 @@ index 9ae4abb4110b..8644b67c48fd 100644
        }
  
        /*
+diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
+index d31cd1ebd8e9..5ea3f933a52a 100644
+--- a/fs/xfs/xfs_aops.c
++++ b/fs/xfs/xfs_aops.c
+@@ -112,8 +112,7 @@ xfs_finish_page_writeback(
+       ASSERT(bvec->bv_offset + bvec->bv_len <= PAGE_SIZE);
+       ASSERT((bvec->bv_len & (i_blocksize(inode) - 1)) == 0);
+-      local_irq_save(flags);
+-      bit_spin_lock(BH_Uptodate_Lock, &head->b_state);
++      flags = bh_uptodate_lock_irqsave(head);
+       do {
+               if (off >= bvec->bv_offset &&
+                   off < bvec->bv_offset + bvec->bv_len) {
+@@ -136,8 +135,7 @@ xfs_finish_page_writeback(
+               }
+               off += bh->b_size;
+       } while ((bh = bh->b_this_page) != head);
+-      bit_spin_unlock(BH_Uptodate_Lock, &head->b_state);
+-      local_irq_restore(flags);
++      bh_uptodate_unlock_irqrestore(head, flags);
+       if (!busy)
+               end_page_writeback(bvec->bv_page);
 diff --git a/include/acpi/platform/aclinux.h b/include/acpi/platform/aclinux.h
-index 93b61b1f2beb..58270adb46ce 100644
+index e861a24f06f2..b5c97d3059c7 100644
 --- a/include/acpi/platform/aclinux.h
 +++ b/include/acpi/platform/aclinux.h
-@@ -131,6 +131,7 @@
+@@ -133,6 +133,7 @@
  
  #define acpi_cache_t                        struct kmem_cache
  #define acpi_spinlock                       spinlock_t *
@@ -7455,7 +6649,7 @@ index 93b61b1f2beb..58270adb46ce 100644
  #define acpi_cpu_flags                      unsigned long
  
  /* Use native linux version of acpi_os_allocate_zeroed */
-@@ -149,6 +150,20 @@
+@@ -151,6 +152,20 @@
  #define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_thread_id
  #define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_create_lock
  
@@ -7502,19 +6696,20 @@ index 6f96247226a4..fa53a21263c2 100644
  
  #endif
 diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
-index e43bbffb5b7a..c23892264109 100644
+index 535ab2e13d2e..cfc246899473 100644
 --- a/include/linux/blk-mq.h
 +++ b/include/linux/blk-mq.h
-@@ -222,6 +222,7 @@ static inline u16 blk_mq_unique_tag_to_tag(u32 unique_tag)
+@@ -209,7 +209,7 @@ static inline u16 blk_mq_unique_tag_to_tag(u32 unique_tag)
+       return unique_tag & BLK_MQ_UNIQUE_TAG_MASK;
+ }
  
- struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index);
- struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int);
+-
 +void __blk_mq_complete_request_remote_work(struct work_struct *work);
  int blk_mq_request_started(struct request *rq);
  void blk_mq_start_request(struct request *rq);
+ void blk_mq_end_request(struct request *rq, int error);
 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
-index e79055c8b577..8583c1af14ad 100644
+index f6a816129856..ec7a4676f8a8 100644
 --- a/include/linux/blkdev.h
 +++ b/include/linux/blkdev.h
 @@ -89,6 +89,7 @@ struct request {
@@ -7586,7 +6781,7 @@ index 8fdcb783197d..d07dbeec7bc1 100644
  
  #endif /* _LINUX_BH_H */
 diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
-index ebbacd14d450..be5e87f6360a 100644
+index 4431ea2c8802..0744157a97ca 100644
 --- a/include/linux/buffer_head.h
 +++ b/include/linux/buffer_head.h
 @@ -75,8 +75,50 @@ struct buffer_head {
@@ -7641,7 +6836,7 @@ index ebbacd14d450..be5e87f6360a 100644
   * macro tricks to expand the set_buffer_foo(), clear_buffer_foo()
   * and buffer_foo() functions.
 diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
-index 5b17de62c962..56027cc01a56 100644
+index 6fb1c34cf805..ccd2a5addb56 100644
 --- a/include/linux/cgroup-defs.h
 +++ b/include/linux/cgroup-defs.h
 @@ -16,6 +16,7 @@
@@ -7652,7 +6847,7 @@ index 5b17de62c962..56027cc01a56 100644
  
  #ifdef CONFIG_CGROUPS
  
-@@ -137,6 +138,7 @@ struct cgroup_subsys_state {
+@@ -138,6 +139,7 @@ struct cgroup_subsys_state {
        /* percpu_ref killing and RCU release */
        struct rcu_head rcu_head;
        struct work_struct destroy_work;
@@ -7698,10 +6893,10 @@ index 5d5aaae3af43..3bca1590e29f 100644
  
  /**
 diff --git a/include/linux/cpu.h b/include/linux/cpu.h
-index 797d9c8e9a1b..6eabd9e8a98b 100644
+index e571128ad99a..5e52d28c20c1 100644
 --- a/include/linux/cpu.h
 +++ b/include/linux/cpu.h
-@@ -201,6 +201,8 @@ extern void get_online_cpus(void);
+@@ -182,6 +182,8 @@ extern void get_online_cpus(void);
  extern void put_online_cpus(void);
  extern void cpu_hotplug_disable(void);
  extern void cpu_hotplug_enable(void);
@@ -7710,7 +6905,7 @@ index 797d9c8e9a1b..6eabd9e8a98b 100644
  #define hotcpu_notifier(fn, pri)      cpu_notifier(fn, pri)
  #define __hotcpu_notifier(fn, pri)    __cpu_notifier(fn, pri)
  #define register_hotcpu_notifier(nb)  register_cpu_notifier(nb)
-@@ -218,6 +220,8 @@ static inline void cpu_hotplug_done(void) {}
+@@ -199,6 +201,8 @@ static inline void cpu_hotplug_done(void) {}
  #define put_online_cpus()     do { } while (0)
  #define cpu_hotplug_disable() do { } while (0)
  #define cpu_hotplug_enable()  do { } while (0)
@@ -7720,7 +6915,7 @@ index 797d9c8e9a1b..6eabd9e8a98b 100644
  #define __hotcpu_notifier(fn, pri)    do { (void)(fn); } while (0)
  /* These aren't inline functions due to a GCC bug. */
 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
-index 5ff3e9a4fe5f..ed0431599fd7 100644
+index ff295e166b2c..d532c60f3fb5 100644
 --- a/include/linux/dcache.h
 +++ b/include/linux/dcache.h
 @@ -11,6 +11,7 @@
@@ -7764,26 +6959,19 @@ index a6ecb34cf547..37caab306336 100644
 +#endif
 +
  #endif /* defined(_LINUX_DELAY_H) */
-diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
-index 7d565afe35d2..8e31b4d245d2 100644
---- a/include/linux/ftrace.h
-+++ b/include/linux/ftrace.h
-@@ -714,6 +714,7 @@ static inline void __ftrace_enabled_restore(int enabled)
- #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
- #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
-+#ifdef CONFIG_USING_GET_LOCK_PARENT_IP
- static inline unsigned long get_lock_parent_ip(void)
- {
-       unsigned long addr = CALLER_ADDR0;
-@@ -725,6 +726,7 @@ static inline unsigned long get_lock_parent_ip(void)
-               return addr;
-       return CALLER_ADDR2;
- }
-+#endif
+diff --git a/include/linux/fs.h b/include/linux/fs.h
+index d705ae084edd..ab1946f4a729 100644
+--- a/include/linux/fs.h
++++ b/include/linux/fs.h
+@@ -688,7 +688,7 @@ struct inode {
+               struct block_device     *i_bdev;
+               struct cdev             *i_cdev;
+               char                    *i_link;
+-              unsigned                i_dir_seq;
++              unsigned                __i_dir_seq;
+       };
  
- #ifdef CONFIG_IRQSOFF_TRACER
-   extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
+       __u32                   i_generation;
 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
 index bb3f3297062a..a117a33ef72c 100644
 --- a/include/linux/highmem.h
@@ -7871,7 +7059,7 @@ index bb3f3297062a..a117a33ef72c 100644
  }
  
 diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
-index 5e00f80b1535..65d0671f20b4 100644
+index 5e00f80b1535..a34e10b55cde 100644
 --- a/include/linux/hrtimer.h
 +++ b/include/linux/hrtimer.h
 @@ -87,6 +87,9 @@ enum hrtimer_restart {
@@ -7956,15 +7144,24 @@ index 5e00f80b1535..65d0671f20b4 100644
  /* Query timers: */
  extern ktime_t __hrtimer_get_remaining(const struct hrtimer *timer, bool adjust);
  
-@@ -436,7 +453,7 @@ static inline int hrtimer_is_queued(struct hrtimer *timer)
+@@ -436,9 +453,15 @@ static inline int hrtimer_is_queued(struct hrtimer *timer)
   * Helper function to check, whether the timer is running the callback
   * function
   */
 -static inline int hrtimer_callback_running(struct hrtimer *timer)
 +static inline int hrtimer_callback_running(const struct hrtimer *timer)
  {
-       return timer->base->cpu_base->running == timer;
+-      return timer->base->cpu_base->running == timer;
++      if (timer->base->cpu_base->running == timer)
++              return 1;
++#ifdef CONFIG_PREEMPT_RT_BASE
++      if (timer->base->cpu_base->running_soft == timer)
++              return 1;
++#endif
++      return 0;
  }
+ /* Forward a hrtimer so it expires after now: */
 diff --git a/include/linux/idr.h b/include/linux/idr.h
 index 083d61e92706..5899796f50cb 100644
 --- a/include/linux/idr.h
@@ -7985,10 +7182,10 @@ index 083d61e92706..5899796f50cb 100644
  /**
   * idr_find - return pointer for given id
 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
-index f8834f820ec2..a688d5e19578 100644
+index 325f649d77ff..a56e263f5005 100644
 --- a/include/linux/init_task.h
 +++ b/include/linux/init_task.h
-@@ -148,6 +148,12 @@ extern struct task_group root_task_group;
+@@ -150,6 +150,12 @@ extern struct task_group root_task_group;
  # define INIT_PERF_EVENTS(tsk)
  #endif
  
@@ -8001,7 +7198,15 @@ index f8834f820ec2..a688d5e19578 100644
  #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  # define INIT_VTIME(tsk)                                              \
        .vtime_seqcount = SEQCNT_ZERO(tsk.vtime_seqcount),      \
-@@ -239,6 +245,7 @@ extern struct task_group root_task_group;
+@@ -164,6 +170,7 @@ extern struct task_group root_task_group;
+ #ifdef CONFIG_RT_MUTEXES
+ # define INIT_RT_MUTEXES(tsk)                                         \
+       .pi_waiters = RB_ROOT,                                          \
++      .pi_top_task = NULL,                                            \
+       .pi_waiters_leftmost = NULL,
+ #else
+ # define INIT_RT_MUTEXES(tsk)
+@@ -250,6 +257,7 @@ extern struct task_group root_task_group;
        .cpu_timers     = INIT_CPU_TIMERS(tsk.cpu_timers),              \
        .pi_lock        = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock),        \
        .timer_slack_ns = 50000, /* 50 usec default slack */            \
@@ -8010,7 +7215,7 @@ index f8834f820ec2..a688d5e19578 100644
                [PIDTYPE_PID]  = INIT_PID_LINK(PIDTYPE_PID),            \
                [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID),           \
 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
-index b6683f0ffc9f..c0a351daf736 100644
+index 72f0721f75e7..480972ae47d3 100644
 --- a/include/linux/interrupt.h
 +++ b/include/linux/interrupt.h
 @@ -14,6 +14,7 @@
@@ -8066,7 +7271,7 @@ index b6683f0ffc9f..c0a351daf736 100644
        void (*notify)(struct irq_affinity_notify *, const cpumask_t *mask);
        void (*release)(struct kref *ref);
  };
-@@ -398,9 +406,13 @@ extern int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
+@@ -406,9 +414,13 @@ extern int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
                                 bool state);
  
  #ifdef CONFIG_IRQ_FORCED_THREADING
@@ -8081,7 +7286,7 @@ index b6683f0ffc9f..c0a351daf736 100644
  #endif
  
  #ifndef __ARCH_SET_SOFTIRQ_PENDING
-@@ -457,9 +469,10 @@ struct softirq_action
+@@ -465,9 +477,10 @@ struct softirq_action
        void    (*action)(struct softirq_action *);
  };
  
@@ -8093,7 +7298,7 @@ index b6683f0ffc9f..c0a351daf736 100644
  #ifdef __ARCH_HAS_DO_SOFTIRQ
  void do_softirq_own_stack(void);
  #else
-@@ -468,13 +481,25 @@ static inline void do_softirq_own_stack(void)
+@@ -476,13 +489,25 @@ static inline void do_softirq_own_stack(void)
        __do_softirq();
  }
  #endif
@@ -8119,7 +7324,7 @@ index b6683f0ffc9f..c0a351daf736 100644
  
  DECLARE_PER_CPU(struct task_struct *, ksoftirqd);
  
-@@ -496,8 +521,9 @@ static inline struct task_struct *this_cpu_ksoftirqd(void)
+@@ -504,8 +529,9 @@ static inline struct task_struct *this_cpu_ksoftirqd(void)
       to be executed on some cpu at least once after this.
     * If the tasklet is already scheduled, but its execution is still not
       started, it will be executed only once.
@@ -8131,7 +7336,7 @@ index b6683f0ffc9f..c0a351daf736 100644
     * Tasklet is strictly serialized wrt itself, but not
       wrt another tasklets. If client needs some intertask synchronization,
       he makes it with spinlocks.
-@@ -522,27 +548,36 @@ struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
+@@ -530,27 +556,36 @@ struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
  enum
  {
        TASKLET_STATE_SCHED,    /* Tasklet is scheduled for execution */
@@ -8174,7 +7379,7 @@ index b6683f0ffc9f..c0a351daf736 100644
  #define tasklet_unlock_wait(t) do { } while (0)
  #define tasklet_unlock(t) do { } while (0)
  #endif
-@@ -591,12 +626,7 @@ static inline void tasklet_disable(struct tasklet_struct *t)
+@@ -599,12 +634,7 @@ static inline void tasklet_disable(struct tasklet_struct *t)
        smp_mb();
  }
  
@@ -8188,7 +7393,7 @@ index b6683f0ffc9f..c0a351daf736 100644
  extern void tasklet_kill(struct tasklet_struct *t);
  extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
  extern void tasklet_init(struct tasklet_struct *t,
-@@ -627,6 +657,12 @@ void tasklet_hrtimer_cancel(struct tasklet_hrtimer *ttimer)
+@@ -635,6 +665,12 @@ void tasklet_hrtimer_cancel(struct tasklet_hrtimer *ttimer)
        tasklet_kill(&ttimer->tasklet);
  }
  
@@ -8202,7 +7407,7 @@ index b6683f0ffc9f..c0a351daf736 100644
   * Autoprobing for irqs:
   *
 diff --git a/include/linux/irq.h b/include/linux/irq.h
-index 0ac26c892fe2..ede85f106aef 100644
+index 39e3254e5769..8ebac94fbb9f 100644
 --- a/include/linux/irq.h
 +++ b/include/linux/irq.h
 @@ -72,6 +72,7 @@ enum irqchip_irq_state;
@@ -8253,10 +7458,10 @@ index 47b9ebd4a74f..2543aab05daa 100644
 +
  #endif /* _LINUX_IRQ_WORK_H */
 diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
-index b51beebf9804..219d9824f762 100644
+index c9be57931b58..eeeb540971ae 100644
 --- a/include/linux/irqdesc.h
 +++ b/include/linux/irqdesc.h
-@@ -64,6 +64,7 @@ struct irq_desc {
+@@ -66,6 +66,7 @@ struct irq_desc {
        unsigned int            irqs_unhandled;
        atomic_t                threads_handled;
        int                     threads_handled_last;
@@ -8400,7 +7605,7 @@ index 410decacff8f..0861bebfc188 100644
  static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
                               char *help, short minlen) { return 0; }
 diff --git a/include/linux/kernel.h b/include/linux/kernel.h
-index d96a6118d26a..37de2ce2d290 100644
+index bc6ed52a39b9..7894d55e4998 100644
 --- a/include/linux/kernel.h
 +++ b/include/linux/kernel.h
 @@ -194,6 +194,9 @@ extern int _cond_resched(void);
@@ -8421,7 +7626,7 @@ index d96a6118d26a..37de2ce2d290 100644
  # define sched_annotate_sleep() do { } while (0)
  #endif
  
-@@ -491,6 +495,7 @@ extern enum system_states {
+@@ -488,6 +492,7 @@ extern enum system_states {
        SYSTEM_HALT,
        SYSTEM_POWER_OFF,
        SYSTEM_RESTART,
@@ -8429,62 +7634,6 @@ index d96a6118d26a..37de2ce2d290 100644
  } system_state;
  
  #define TAINT_PROPRIETARY_MODULE      0
-diff --git a/include/linux/lglock.h b/include/linux/lglock.h
-index c92ebd100d9b..6f035f635d0e 100644
---- a/include/linux/lglock.h
-+++ b/include/linux/lglock.h
-@@ -34,13 +34,30 @@
- #endif
- struct lglock {
-+#ifdef CONFIG_PREEMPT_RT_FULL
-+      struct rt_mutex __percpu *lock;
-+#else
-       arch_spinlock_t __percpu *lock;
-+#endif
- #ifdef CONFIG_DEBUG_LOCK_ALLOC
-       struct lock_class_key lock_key;
-       struct lockdep_map    lock_dep_map;
- #endif
- };
-+#ifdef CONFIG_PREEMPT_RT_FULL
-+# define DEFINE_LGLOCK(name)                                          \
-+      static DEFINE_PER_CPU(struct rt_mutex, name ## _lock)           \
-+      = __RT_MUTEX_INITIALIZER( name ## _lock);                       \
-+      struct lglock name = { .lock = &name ## _lock }
-+
-+# define DEFINE_STATIC_LGLOCK(name)                                   \
-+      static DEFINE_PER_CPU(struct rt_mutex, name ## _lock)           \
-+      = __RT_MUTEX_INITIALIZER( name ## _lock);                       \
-+      static struct lglock name = { .lock = &name ## _lock }
-+
-+#else
-+
- #define DEFINE_LGLOCK(name)                                           \
-       static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock)           \
-       = __ARCH_SPIN_LOCK_UNLOCKED;                                    \
-@@ -50,6 +67,7 @@ struct lglock {
-       static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock)           \
-       = __ARCH_SPIN_LOCK_UNLOCKED;                                    \
-       static struct lglock name = { .lock = &name ## _lock }
-+#endif
- void lg_lock_init(struct lglock *lg, char *name);
-@@ -64,6 +82,12 @@ void lg_double_unlock(struct lglock *lg, int cpu1, int cpu2);
- void lg_global_lock(struct lglock *lg);
- void lg_global_unlock(struct lglock *lg);
-+#ifndef CONFIG_PREEMPT_RT_FULL
-+#define lg_global_trylock_relax(name) lg_global_lock(name)
-+#else
-+void lg_global_trylock_relax(struct lglock *lg);
-+#endif
-+
- #else
- /* When !CONFIG_SMP, map lglock to spinlock */
- #define lglock spinlock
 diff --git a/include/linux/list_bl.h b/include/linux/list_bl.h
 index cb483305e1f5..4e5062316bb6 100644
 --- a/include/linux/list_bl.h
@@ -8553,10 +7702,10 @@ index cb483305e1f5..4e5062316bb6 100644
  static inline bool hlist_bl_is_locked(struct hlist_bl_head *b)
 diff --git a/include/linux/locallock.h b/include/linux/locallock.h
 new file mode 100644
-index 000000000000..845c77f1a5ca
+index 000000000000..280f884a05a3
 --- /dev/null
 +++ b/include/linux/locallock.h
-@@ -0,0 +1,278 @@
+@@ -0,0 +1,287 @@
 +#ifndef _LINUX_LOCALLOCK_H
 +#define _LINUX_LOCALLOCK_H
 +
@@ -8636,6 +7785,9 @@ index 000000000000..845c77f1a5ca
 +              lv->owner = current;
 +              lv->nestcnt = 1;
 +              return 1;
++      } else if (lv->owner == current) {
++              lv->nestcnt++;
++              return 1;
 +      }
 +      return 0;
 +}
@@ -8809,6 +7961,12 @@ index 000000000000..845c77f1a5ca
 +
 +static inline void local_irq_lock_init(int lvar) { }
 +
++#define local_trylock(lvar)                                   \
++      ({                                                      \
++              preempt_disable();                              \
++              1;                                              \
++      })
++
 +#define local_lock(lvar)                      preempt_disable()
 +#define local_unlock(lvar)                    preempt_enable()
 +#define local_lock_irq(lvar)                  local_irq_disable()
@@ -8836,7 +7994,7 @@ index 000000000000..845c77f1a5ca
 +
 +#endif
 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
-index 903200f4ec41..df670d441fc9 100644
+index e8471c2ca83a..08bde1a7a987 100644
 --- a/include/linux/mm_types.h
 +++ b/include/linux/mm_types.h
 @@ -11,6 +11,7 @@
@@ -8847,8 +8005,8 @@ index 903200f4ec41..df670d441fc9 100644
  #include <linux/page-flags-layout.h>
  #include <linux/workqueue.h>
  #include <asm/page.h>
-@@ -508,6 +509,9 @@ struct mm_struct {
-       bool tlb_flush_pending;
+@@ -513,6 +514,9 @@ struct mm_struct {
+       bool tlb_flush_batched;
  #endif
        struct uprobes_state uprobes_state;
 +#ifdef CONFIG_PREEMPT_RT_BASE
@@ -8857,6 +8015,30 @@ index 903200f4ec41..df670d441fc9 100644
  #ifdef CONFIG_X86_INTEL_MPX
        /* address of the bounds directory */
        void __user *bd_addr;
+diff --git a/include/linux/module.h b/include/linux/module.h
+index 0c3207d26ac0..5944baaa3f28 100644
+--- a/include/linux/module.h
++++ b/include/linux/module.h
+@@ -496,6 +496,7 @@ static inline int module_is_live(struct module *mod)
+ struct module *__module_text_address(unsigned long addr);
+ struct module *__module_address(unsigned long addr);
+ bool is_module_address(unsigned long addr);
++bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr);
+ bool is_module_percpu_address(unsigned long addr);
+ bool is_module_text_address(unsigned long addr);
+@@ -663,6 +664,11 @@ static inline bool is_module_percpu_address(unsigned long addr)
+       return false;
+ }
++static inline bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
++{
++      return false;
++}
++
+ static inline bool is_module_text_address(unsigned long addr)
+ {
+       return false;
 diff --git a/include/linux/mutex.h b/include/linux/mutex.h
 index 2cb7531e7d7a..b3fdfc820216 100644
 --- a/include/linux/mutex.h
@@ -8904,10 +8086,10 @@ index 2cb7531e7d7a..b3fdfc820216 100644
  #endif /* __LINUX_MUTEX_H */
 diff --git a/include/linux/mutex_rt.h b/include/linux/mutex_rt.h
 new file mode 100644
-index 000000000000..c38a44b14da5
+index 000000000000..e0284edec655
 --- /dev/null
 +++ b/include/linux/mutex_rt.h
-@@ -0,0 +1,84 @@
+@@ -0,0 +1,89 @@
 +#ifndef __LINUX_MUTEX_RT_H
 +#define __LINUX_MUTEX_RT_H
 +
@@ -8953,7 +8135,12 @@ index 000000000000..c38a44b14da5
 +#define mutex_lock_killable(l)                _mutex_lock_killable(l)
 +#define mutex_trylock(l)              _mutex_trylock(l)
 +#define mutex_unlock(l)                       _mutex_unlock(l)
++
++#ifdef CONFIG_DEBUG_MUTEXES
 +#define mutex_destroy(l)              rt_mutex_destroy(&(l)->lock)
++#else
++static inline void mutex_destroy(struct mutex *lock) {}
++#endif
 +
 +#ifdef CONFIG_DEBUG_LOCK_ALLOC
 +# define mutex_lock_nested(l, s)      _mutex_lock_nested(l, s)
@@ -8993,10 +8180,30 @@ index 000000000000..c38a44b14da5
 +
 +#endif
 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
-index e8d79d4ebcfe..2ae8fa187016 100644
+index 47c7f5b8f675..85fc72b8a92b 100644
 --- a/include/linux/netdevice.h
 +++ b/include/linux/netdevice.h
-@@ -2409,14 +2409,53 @@ void netdev_freemem(struct net_device *dev);
+@@ -396,7 +396,19 @@ typedef enum rx_handler_result rx_handler_result_t;
+ typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
+ void __napi_schedule(struct napi_struct *n);
++
++/*
++ * When PREEMPT_RT_FULL is defined, all device interrupt handlers
++ * run as threads, and they can also be preempted (without PREEMPT_RT
++ * interrupt threads can not be preempted). Which means that calling
++ * __napi_schedule_irqoff() from an interrupt handler can be preempted
++ * and can corrupt the napi->poll_list.
++ */
++#ifdef CONFIG_PREEMPT_RT_FULL
++#define __napi_schedule_irqoff(n) __napi_schedule(n)
++#else
+ void __napi_schedule_irqoff(struct napi_struct *n);
++#endif
+ static inline bool napi_disable_pending(struct napi_struct *n)
+ {
+@@ -2464,14 +2476,53 @@ void netdev_freemem(struct net_device *dev);
  void synchronize_net(void);
  int init_dummy_netdev(struct net_device *dev);
  
@@ -9051,7 +8258,7 @@ index e8d79d4ebcfe..2ae8fa187016 100644
  struct net_device *dev_get_by_index(struct net *net, int ifindex);
  struct net_device *__dev_get_by_index(struct net *net, int ifindex);
  struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
-@@ -2794,6 +2833,7 @@ struct softnet_data {
+@@ -2856,6 +2907,7 @@ struct softnet_data {
        unsigned int            dropped;
        struct sk_buff_head     input_pkt_queue;
        struct napi_struct      backlog;
@@ -9115,10 +8322,10 @@ index 810124b33327..d54ca43d571f 100644
  #if IS_ENABLED(CONFIG_NFS_V4)
        struct nfs4_cached_acl  *nfs4_acl;
 diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
-index 7cc0deee5bde..a20f49ee69ee 100644
+index 3bf867a0c3b3..71c6bdd14c8a 100644
 --- a/include/linux/nfs_xdr.h
 +++ b/include/linux/nfs_xdr.h
-@@ -1484,7 +1484,7 @@ struct nfs_unlinkdata {
+@@ -1490,7 +1490,7 @@ struct nfs_unlinkdata {
        struct nfs_removeargs args;
        struct nfs_removeres res;
        struct dentry *dentry;
@@ -9210,8 +8417,93 @@ index 4149868de4e6..babe5b9bcb91 100644
  /* CPU notfiers are defined in include/linux/cpu.h. */
  
  /* netdevice notifiers are defined in include/linux/netdevice.h */
+diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h
+index 5b2e6159b744..ea940f451606 100644
+--- a/include/linux/percpu-rwsem.h
++++ b/include/linux/percpu-rwsem.h
+@@ -4,7 +4,7 @@
+ #include <linux/atomic.h>
+ #include <linux/rwsem.h>
+ #include <linux/percpu.h>
+-#include <linux/wait.h>
++#include <linux/swait.h>
+ #include <linux/rcu_sync.h>
+ #include <linux/lockdep.h>
+@@ -12,7 +12,7 @@ struct percpu_rw_semaphore {
+       struct rcu_sync         rss;
+       unsigned int __percpu   *read_count;
+       struct rw_semaphore     rw_sem;
+-      wait_queue_head_t       writer;
++      struct swait_queue_head writer;
+       int                     readers_block;
+ };
+@@ -22,13 +22,13 @@ static struct percpu_rw_semaphore name = {                         \
+       .rss = __RCU_SYNC_INITIALIZER(name.rss, RCU_SCHED_SYNC),        \
+       .read_count = &__percpu_rwsem_rc_##name,                        \
+       .rw_sem = __RWSEM_INITIALIZER(name.rw_sem),                     \
+-      .writer = __WAIT_QUEUE_HEAD_INITIALIZER(name.writer),           \
++      .writer = __SWAIT_QUEUE_HEAD_INITIALIZER(name.writer),          \
+ }
+ extern int __percpu_down_read(struct percpu_rw_semaphore *, int);
+ extern void __percpu_up_read(struct percpu_rw_semaphore *);
+-static inline void percpu_down_read_preempt_disable(struct percpu_rw_semaphore *sem)
++static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
+ {
+       might_sleep();
+@@ -46,16 +46,10 @@ static inline void percpu_down_read_preempt_disable(struct percpu_rw_semaphore *
+       __this_cpu_inc(*sem->read_count);
+       if (unlikely(!rcu_sync_is_idle(&sem->rss)))
+               __percpu_down_read(sem, false); /* Unconditional memory barrier */
+-      barrier();
+       /*
+-       * The barrier() prevents the compiler from
++       * The preempt_enable() prevents the compiler from
+        * bleeding the critical section out.
+        */
+-}
+-
+-static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
+-{
+-      percpu_down_read_preempt_disable(sem);
+       preempt_enable();
+ }
+@@ -82,13 +76,9 @@ static inline int percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
+       return ret;
+ }
+-static inline void percpu_up_read_preempt_enable(struct percpu_rw_semaphore *sem)
++static inline void percpu_up_read(struct percpu_rw_semaphore *sem)
+ {
+-      /*
+-       * The barrier() prevents the compiler from
+-       * bleeding the critical section out.
+-       */
+-      barrier();
++      preempt_disable();
+       /*
+        * Same as in percpu_down_read().
+        */
+@@ -101,12 +91,6 @@ static inline void percpu_up_read_preempt_enable(struct percpu_rw_semaphore *sem
+       rwsem_release(&sem->rw_sem.dep_map, 1, _RET_IP_);
+ }
+-static inline void percpu_up_read(struct percpu_rw_semaphore *sem)
+-{
+-      preempt_disable();
+-      percpu_up_read_preempt_enable(sem);
+-}
+-
+ extern void percpu_down_write(struct percpu_rw_semaphore *);
+ extern void percpu_up_write(struct percpu_rw_semaphore *);
 diff --git a/include/linux/percpu.h b/include/linux/percpu.h
-index 56939d3f6e53..1c7e33fc83e4 100644
+index 56939d3f6e53..b988bf40ad3e 100644
 --- a/include/linux/percpu.h
 +++ b/include/linux/percpu.h
 @@ -18,6 +18,35 @@
@@ -9250,8 +8542,16 @@ index 56939d3f6e53..1c7e33fc83e4 100644
  /* minimum unit size, also is the maximum supported allocation size */
  #define PCPU_MIN_UNIT_SIZE            PFN_ALIGN(32 << 10)
  
+@@ -110,6 +139,7 @@ extern int __init pcpu_page_first_chunk(size_t reserved_size,
+ #endif
+ extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align);
++extern bool __is_kernel_percpu_address(unsigned long addr, unsigned long *can_addr);
+ extern bool is_kernel_percpu_address(unsigned long addr);
+ #if !defined(CONFIG_SMP) || !defined(CONFIG_HAVE_SETUP_PER_CPU_AREA)
 diff --git a/include/linux/pid.h b/include/linux/pid.h
-index 23705a53abba..2cc64b779f03 100644
+index 97b745ddece5..01a5460a0c85 100644
 --- a/include/linux/pid.h
 +++ b/include/linux/pid.h
 @@ -2,6 +2,7 @@
@@ -9263,7 +8563,7 @@ index 23705a53abba..2cc64b779f03 100644
  enum pid_type
  {
 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
-index 75e4e30677f1..1cfb1cb72354 100644
+index 7eeceac52dea..f97c54265904 100644
 --- a/include/linux/preempt.h
 +++ b/include/linux/preempt.h
 @@ -50,7 +50,11 @@
@@ -9296,15 +8596,15 @@ index 75e4e30677f1..1cfb1cb72354 100644
  
  /*
   * Are we doing bottom half or hardware interrupt processing?
-@@ -72,7 +82,6 @@
+@@ -79,7 +89,6 @@
  #define in_irq()              (hardirq_count())
  #define in_softirq()          (softirq_count())
  #define in_interrupt()                (irq_count())
 -#define in_serving_softirq()  (softirq_count() & SOFTIRQ_OFFSET)
- /*
-  * Are we in NMI context?
-@@ -91,7 +100,11 @@
+ #define in_nmi()              (preempt_count() & NMI_MASK)
+ #define in_task()             (!(preempt_count() & \
+                                  (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)))
+@@ -96,7 +105,11 @@
  /*
   * The preempt_count offset after spin_lock()
   */
@@ -9316,7 +8616,7 @@ index 75e4e30677f1..1cfb1cb72354 100644
  
  /*
   * The preempt_count offset needed for things like:
-@@ -140,6 +153,20 @@ extern void preempt_count_sub(int val);
+@@ -145,6 +158,20 @@ extern void preempt_count_sub(int val);
  #define preempt_count_inc() preempt_count_add(1)
  #define preempt_count_dec() preempt_count_sub(1)
  
@@ -9337,7 +8637,7 @@ index 75e4e30677f1..1cfb1cb72354 100644
  #ifdef CONFIG_PREEMPT_COUNT
  
  #define preempt_disable() \
-@@ -148,13 +175,25 @@ do { \
+@@ -153,13 +180,25 @@ do { \
        barrier(); \
  } while (0)
  
@@ -9364,7 +8664,7 @@ index 75e4e30677f1..1cfb1cb72354 100644
  
  #define preemptible() (preempt_count() == 0 && !irqs_disabled())
  
-@@ -179,6 +218,13 @@ do { \
+@@ -184,6 +223,13 @@ do { \
                __preempt_schedule(); \
  } while (0)
  
@@ -9378,7 +8678,7 @@ index 75e4e30677f1..1cfb1cb72354 100644
  #else /* !CONFIG_PREEMPT */
  #define preempt_enable() \
  do { \
-@@ -224,6 +270,7 @@ do { \
+@@ -229,6 +275,7 @@ do { \
  #define preempt_disable_notrace()             barrier()
  #define preempt_enable_no_resched_notrace()   barrier()
  #define preempt_enable_notrace()              barrier()
@@ -9386,7 +8686,7 @@ index 75e4e30677f1..1cfb1cb72354 100644
  #define preemptible()                         0
  
  #endif /* CONFIG_PREEMPT_COUNT */
-@@ -244,10 +291,31 @@ do { \
+@@ -249,10 +296,31 @@ do { \
  } while (0)
  #define preempt_fold_need_resched() \
  do { \
@@ -9420,10 +8720,10 @@ index 75e4e30677f1..1cfb1cb72354 100644
  
  struct preempt_notifier;
 diff --git a/include/linux/printk.h b/include/linux/printk.h
-index 696a56be7d3e..310aa321ef0c 100644
+index eac1af8502bb..37e647af0b0b 100644
 --- a/include/linux/printk.h
 +++ b/include/linux/printk.h
-@@ -125,9 +125,11 @@ struct va_format {
+@@ -126,9 +126,11 @@ struct va_format {
  #ifdef CONFIG_EARLY_PRINTK
  extern asmlinkage __printf(1, 2)
  void early_printk(const char *fmt, ...);
@@ -9436,48 +8736,40 @@ index 696a56be7d3e..310aa321ef0c 100644
  
  #ifdef CONFIG_PRINTK_NMI
 diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h
-index 52b97db93830..fd9ea1c68db6 100644
+index af3581b8a451..277295039c8f 100644
 --- a/include/linux/radix-tree.h
 +++ b/include/linux/radix-tree.h
-@@ -289,9 +289,19 @@ unsigned int radix_tree_gang_lookup(struct radix_tree_root *root,
- unsigned int radix_tree_gang_lookup_slot(struct radix_tree_root *root,
-                       void ***results, unsigned long *indices,
-                       unsigned long first_index, unsigned int max_items);
-+#ifdef CONFIG_PREEMPT_RT_FULL
-+static inline int radix_tree_preload(gfp_t gm) { return 0; }
-+static inline int radix_tree_maybe_preload(gfp_t gfp_mask) { return 0; }
-+static inline int radix_tree_maybe_preload_order(gfp_t gfp_mask, int order)
-+{
-+      return 0;
-+};
-+
-+#else
+@@ -292,6 +292,8 @@ unsigned int radix_tree_gang_lookup_slot(struct radix_tree_root *root,
  int radix_tree_preload(gfp_t gfp_mask);
  int radix_tree_maybe_preload(gfp_t gfp_mask);
  int radix_tree_maybe_preload_order(gfp_t gfp_mask, int order);
-+#endif
++void radix_tree_preload_end(void);
++
  void radix_tree_init(void);
  void *radix_tree_tag_set(struct radix_tree_root *root,
                        unsigned long index, unsigned int tag);
-@@ -316,7 +326,7 @@ unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item);
+@@ -314,11 +316,6 @@ unsigned long radix_tree_range_tag_if_tagged(struct radix_tree_root *root,
+ int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag);
+ unsigned long radix_tree_locate_item(struct radix_tree_root *root, void *item);
  
- static inline void radix_tree_preload_end(void)
- {
+-static inline void radix_tree_preload_end(void)
+-{
 -      preempt_enable();
-+      preempt_enable_nort();
- }
+-}
+-
  /**
+  * struct radix_tree_iter - radix tree iterator state
+  *
 diff --git a/include/linux/random.h b/include/linux/random.h
-index 3d6e9815cd85..f6e8860b6494 100644
+index 16ab429735a7..9d0fecb5b6c2 100644
 --- a/include/linux/random.h
 +++ b/include/linux/random.h
-@@ -20,7 +20,7 @@ struct random_ready_callback {
- extern void add_device_randomness(const void *, unsigned int);
+@@ -31,7 +31,7 @@ static inline void add_latent_entropy(void) {}
  extern void add_input_randomness(unsigned int type, unsigned int code,
-                                unsigned int value);
--extern void add_interrupt_randomness(int irq, int irq_flags);
-+extern void add_interrupt_randomness(int irq, int irq_flags, __u64 ip);
+                                unsigned int value) __latent_entropy;
+-extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
++extern void add_interrupt_randomness(int irq, int irq_flags, __u64 ip) __latent_entropy;
  
  extern void get_random_bytes(void *buf, int nbytes);
  extern int add_random_ready_callback(struct random_ready_callback *rdy);
@@ -9567,7 +8859,7 @@ index 000000000000..7066962a4379
 +
 +#endif
 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
-index 1aa62e1a761b..2a614acb433e 100644
+index 01f71e1d2e94..30cc001d0d5a 100644
 --- a/include/linux/rcupdate.h
 +++ b/include/linux/rcupdate.h
 @@ -46,6 +46,7 @@
@@ -9617,7 +8909,7 @@ index 1aa62e1a761b..2a614acb433e 100644
  #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  
  /* Internal to kernel */
-@@ -500,7 +512,14 @@ extern struct lockdep_map rcu_callback_map;
+@@ -505,7 +517,14 @@ extern struct lockdep_map rcu_callback_map;
  int debug_lockdep_rcu_enabled(void);
  
  int rcu_read_lock_held(void);
@@ -9632,7 +8924,7 @@ index 1aa62e1a761b..2a614acb433e 100644
  
  /**
   * rcu_read_lock_sched_held() - might we be in RCU-sched read-side critical section?
-@@ -621,54 +640,6 @@ static inline void rcu_preempt_sleep_check(void)
+@@ -626,54 +645,6 @@ static inline void rcu_preempt_sleep_check(void)
  })
  
  /**
@@ -9687,7 +8979,7 @@ index 1aa62e1a761b..2a614acb433e 100644
   * rcu_access_pointer() - fetch RCU pointer with no dereferencing
   * @p: The pointer to read
   *
-@@ -946,10 +917,14 @@ static inline void rcu_read_unlock(void)
+@@ -951,10 +922,14 @@ static inline void rcu_read_unlock(void)
  static inline void rcu_read_lock_bh(void)
  {
        local_bh_disable();
@@ -9702,7 +8994,7 @@ index 1aa62e1a761b..2a614acb433e 100644
  }
  
  /*
-@@ -959,10 +934,14 @@ static inline void rcu_read_lock_bh(void)
+@@ -964,10 +939,14 @@ static inline void rcu_read_lock_bh(void)
   */
  static inline void rcu_read_unlock_bh(void)
  {
@@ -9781,7 +9073,7 @@ index 63a4e4cf40a5..08ab12df2863 100644
  
  /* RCUtree hotplug events */
 diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h
-index 1abba5ce2a2f..30211c627511 100644
+index 1abba5ce2a2f..294a8b4875f1 100644
 --- a/include/linux/rtmutex.h
 +++ b/include/linux/rtmutex.h
 @@ -13,11 +13,15 @@
@@ -9850,9 +9142,11 @@ index 1abba5ce2a2f..30211c627511 100644
  
  #define DEFINE_RT_MUTEX(mutexname) \
        struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
-@@ -91,6 +106,7 @@ extern void rt_mutex_destroy(struct rt_mutex *lock);
+@@ -90,7 +105,9 @@ extern void __rt_mutex_init(struct rt_mutex *lock, const char *name);
+ extern void rt_mutex_destroy(struct rt_mutex *lock);
  
  extern void rt_mutex_lock(struct rt_mutex *lock);
++extern int rt_mutex_lock_state(struct rt_mutex *lock, int state);
  extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
 +extern int rt_mutex_lock_killable(struct rt_mutex *lock);
  extern int rt_mutex_timed_lock(struct rt_mutex *lock,
@@ -10018,7 +9312,7 @@ index 000000000000..51b28d775fe1
 +
 +#endif
 diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
-index dd1d14250340..8e1f44ff1f2f 100644
+index dd1d14250340..aa2ac1f65c2d 100644
 --- a/include/linux/rwsem.h
 +++ b/include/linux/rwsem.h
 @@ -19,6 +19,10 @@
@@ -10032,19 +9326,26 @@ index dd1d14250340..8e1f44ff1f2f 100644
  struct rw_semaphore;
  
  #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
-@@ -184,4 +188,6 @@ extern void up_read_non_owner(struct rw_semaphore *sem);
- # define up_read_non_owner(sem)                       up_read(sem)
- #endif
+@@ -106,6 +110,13 @@ static inline int rwsem_is_contended(struct rw_semaphore *sem)
+       return !list_empty(&sem->wait_list);
+ }
  
 +#endif /* !PREEMPT_RT_FULL */
 +
- #endif /* _LINUX_RWSEM_H */
++/*
++ * The functions below are the same for all rwsem implementations including
++ * the RT specific variant.
++ */
++
+ /*
+  * lock for reading
+  */
 diff --git a/include/linux/rwsem_rt.h b/include/linux/rwsem_rt.h
 new file mode 100644
-index 000000000000..e26bd95a57c3
+index 000000000000..2ffbf093ae92
 --- /dev/null
 +++ b/include/linux/rwsem_rt.h
-@@ -0,0 +1,167 @@
+@@ -0,0 +1,67 @@
 +#ifndef _LINUX_RWSEM_RT_H
 +#define _LINUX_RWSEM_RT_H
 +
@@ -10052,168 +9353,68 @@ index 000000000000..e26bd95a57c3
 +#error "Include rwsem.h"
 +#endif
 +
-+/*
-+ * RW-semaphores are a spinlock plus a reader-depth count.
-+ *
-+ * Note that the semantics are different from the usual
-+ * Linux rw-sems, in PREEMPT_RT mode we do not allow
-+ * multiple readers to hold the lock at once, we only allow
-+ * a read-lock owner to read-lock recursively. This is
-+ * better for latency, makes the implementation inherently
-+ * fair and makes it simpler as well.
-+ */
-+
 +#include <linux/rtmutex.h>
++#include <linux/swait.h>
++
++#define READER_BIAS           (1U << 31)
++#define WRITER_BIAS           (1U << 30)
 +
 +struct rw_semaphore {
-+      struct rt_mutex         lock;
-+      int                     read_depth;
++      atomic_t                readers;
++      struct rt_mutex         rtmutex;
 +#ifdef CONFIG_DEBUG_LOCK_ALLOC
 +      struct lockdep_map      dep_map;
 +#endif
 +};
 +
-+#define __RWSEM_INITIALIZER(name) \
-+      { .lock = __RT_MUTEX_INITIALIZER(name.lock), \
-+        RW_DEP_MAP_INIT(name) }
++#define __RWSEM_INITIALIZER(name)                             \
++{                                                             \
++      .readers = ATOMIC_INIT(READER_BIAS),                    \
++      .rtmutex = __RT_MUTEX_INITIALIZER(name.rtmutex),        \
++      RW_DEP_MAP_INIT(name)                                   \
++}
 +
 +#define DECLARE_RWSEM(lockname) \
 +      struct rw_semaphore lockname = __RWSEM_INITIALIZER(lockname)
 +
-+extern void  __rt_rwsem_init(struct rw_semaphore *rwsem, const char *name,
-+                                   struct lock_class_key *key);
-+
-+#define __rt_init_rwsem(sem, name, key)                       \
-+      do {                                            \
-+              rt_mutex_init(&(sem)->lock);            \
-+              __rt_rwsem_init((sem), (name), (key));\
-+      } while (0)
++extern void  __rwsem_init(struct rw_semaphore *rwsem, const char *name,
++                        struct lock_class_key *key);
 +
-+#define __init_rwsem(sem, name, key) __rt_init_rwsem(sem, name, key)
++#define __init_rwsem(sem, name, key)                  \
++do {                                                  \
++              rt_mutex_init(&(sem)->rtmutex);         \
++              __rwsem_init((sem), (name), (key));     \
++} while (0)
 +
-+# define rt_init_rwsem(sem)                           \
++#define init_rwsem(sem)                                       \
 +do {                                                  \
 +      static struct lock_class_key __key;             \
 +                                                      \
-+      __rt_init_rwsem((sem), #sem, &__key);           \
++      __init_rwsem((sem), #sem, &__key);              \
 +} while (0)
 +
-+extern void rt_down_write(struct rw_semaphore *rwsem);
-+extern int  rt_down_write_killable(struct rw_semaphore *rwsem);
-+extern void rt_down_read_nested(struct rw_semaphore *rwsem, int subclass);
-+extern void rt_down_write_nested(struct rw_semaphore *rwsem, int subclass);
-+extern int  rt_down_write_killable_nested(struct rw_semaphore *rwsem,
-+                                        int subclass);
-+extern void rt_down_write_nested_lock(struct rw_semaphore *rwsem,
-+                                    struct lockdep_map *nest);
-+extern void rt__down_read(struct rw_semaphore *rwsem);
-+extern void rt_down_read(struct rw_semaphore *rwsem);
-+extern int  rt_down_write_trylock(struct rw_semaphore *rwsem);
-+extern int  rt__down_read_trylock(struct rw_semaphore *rwsem);
-+extern int  rt_down_read_trylock(struct rw_semaphore *rwsem);
-+extern void __rt_up_read(struct rw_semaphore *rwsem);
-+extern void rt_up_read(struct rw_semaphore *rwsem);
-+extern void rt_up_write(struct rw_semaphore *rwsem);
-+extern void rt_downgrade_write(struct rw_semaphore *rwsem);
-+
-+#define init_rwsem(sem)               rt_init_rwsem(sem)
-+#define rwsem_is_locked(s)    rt_mutex_is_locked(&(s)->lock)
-+
-+static inline int rwsem_is_contended(struct rw_semaphore *sem)
-+{
-+      /* rt_mutex_has_waiters() */
-+      return !RB_EMPTY_ROOT(&sem->lock.waiters);
-+}
-+
-+static inline void __down_read(struct rw_semaphore *sem)
-+{
-+      rt__down_read(sem);
-+}
-+
-+static inline void down_read(struct rw_semaphore *sem)
-+{
-+      rt_down_read(sem);
-+}
-+
-+static inline int __down_read_trylock(struct rw_semaphore *sem)
-+{
-+      return rt__down_read_trylock(sem);
-+}
-+
-+static inline int down_read_trylock(struct rw_semaphore *sem)
-+{
-+      return rt_down_read_trylock(sem);
-+}
-+
-+static inline void down_write(struct rw_semaphore *sem)
-+{
-+      rt_down_write(sem);
-+}
-+
-+static inline int down_write_killable(struct rw_semaphore *sem)
-+{
-+      return rt_down_write_killable(sem);
-+}
-+
-+static inline int down_write_trylock(struct rw_semaphore *sem)
-+{
-+      return rt_down_write_trylock(sem);
-+}
-+
-+static inline void __up_read(struct rw_semaphore *sem)
-+{
-+      __rt_up_read(sem);
-+}
-+
-+static inline void up_read(struct rw_semaphore *sem)
-+{
-+      rt_up_read(sem);
-+}
-+
-+static inline void up_write(struct rw_semaphore *sem)
-+{
-+      rt_up_write(sem);
-+}
-+
-+static inline void downgrade_write(struct rw_semaphore *sem)
-+{
-+      rt_downgrade_write(sem);
-+}
-+
-+static inline void down_read_nested(struct rw_semaphore *sem, int subclass)
-+{
-+      return rt_down_read_nested(sem, subclass);
-+}
-+
-+static inline void down_write_nested(struct rw_semaphore *sem, int subclass)
-+{
-+      rt_down_write_nested(sem, subclass);
-+}
-+
-+static inline int down_write_killable_nested(struct rw_semaphore *sem,
-+                                           int subclass)
++static inline int rwsem_is_locked(struct rw_semaphore *sem)
 +{
-+      return rt_down_write_killable_nested(sem, subclass);
++      return atomic_read(&sem->readers) != READER_BIAS;
 +}
 +
-+#ifdef CONFIG_DEBUG_LOCK_ALLOC
-+static inline void down_write_nest_lock(struct rw_semaphore *sem,
-+              struct rw_semaphore *nest_lock)
++static inline int rwsem_is_contended(struct rw_semaphore *sem)
 +{
-+      rt_down_write_nested_lock(sem, &nest_lock->dep_map);
++      return atomic_read(&sem->readers) > 0;
 +}
 +
-+#else
++extern void __down_read(struct rw_semaphore *sem);
++extern int __down_read_trylock(struct rw_semaphore *sem);
++extern void __down_write(struct rw_semaphore *sem);
++extern int __must_check __down_write_killable(struct rw_semaphore *sem);
++extern int __down_write_trylock(struct rw_semaphore *sem);
++extern void __up_read(struct rw_semaphore *sem);
++extern void __up_write(struct rw_semaphore *sem);
++extern void __downgrade_write(struct rw_semaphore *sem);
 +
-+static inline void down_write_nest_lock(struct rw_semaphore *sem,
-+              struct rw_semaphore *nest_lock)
-+{
-+      rt_down_write_nested_lock(sem, NULL);
-+}
-+#endif
 +#endif
 diff --git a/include/linux/sched.h b/include/linux/sched.h
-index 62c68e513e39..c873ce0183ab 100644
+index a4d0afc009a7..e775696b480a 100644
 --- a/include/linux/sched.h
 +++ b/include/linux/sched.h
 @@ -26,6 +26,7 @@ struct sched_param {
@@ -10224,7 +9425,14 @@ index 62c68e513e39..c873ce0183ab 100644
  
  #include <asm/page.h>
  #include <asm/ptrace.h>
-@@ -243,10 +244,7 @@ extern char ___assert_task_state[1 - 2*!!(
+@@ -236,17 +237,13 @@ extern char ___assert_task_state[1 - 2*!!(
+ /* Convenience macros for the sake of wake_up */
+ #define TASK_NORMAL           (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
+-#define TASK_ALL              (TASK_NORMAL | __TASK_STOPPED | __TASK_TRACED)
+ /* get_task_state() */
+ #define TASK_REPORT           (TASK_RUNNING | TASK_INTERRUPTIBLE | \
                                 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
                                 __TASK_TRACED | EXIT_ZOMBIE | EXIT_DEAD)
  
@@ -10235,7 +9443,7 @@ index 62c68e513e39..c873ce0183ab 100644
  #define task_contributes_to_load(task)        \
                                ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
                                 (task->flags & PF_FROZEN) == 0 && \
-@@ -312,6 +310,11 @@ extern char ___assert_task_state[1 - 2*!!(
+@@ -312,6 +309,11 @@ extern char ___assert_task_state[1 - 2*!!(
  
  #endif
  
@@ -10247,13 +9455,27 @@ index 62c68e513e39..c873ce0183ab 100644
  /* Task command name length */
  #define TASK_COMM_LEN 16
  
-@@ -1009,8 +1012,18 @@ struct wake_q_head {
+@@ -1022,9 +1024,31 @@ struct wake_q_head {
+ #define WAKE_Q(name)                                  \
        struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
  
- extern void wake_q_add(struct wake_q_head *head,
+-extern void wake_q_add(struct wake_q_head *head,
 -                     struct task_struct *task);
 -extern void wake_up_q(struct wake_q_head *head);
-+                            struct task_struct *task);
++extern void __wake_q_add(struct wake_q_head *head,
++                       struct task_struct *task, bool sleeper);
++static inline void wake_q_add(struct wake_q_head *head,
++                            struct task_struct *task)
++{
++      __wake_q_add(head, task, false);
++}
++
++static inline void wake_q_add_sleeper(struct wake_q_head *head,
++                                    struct task_struct *task)
++{
++      __wake_q_add(head, task, true);
++}
++
 +extern void __wake_up_q(struct wake_q_head *head, bool sleeper);
 +
 +static inline void wake_up_q(struct wake_q_head *head)
@@ -10268,20 +9490,21 @@ index 62c68e513e39..c873ce0183ab 100644
  
  /*
   * sched-domains (multiprocessor balancing) declarations:
-@@ -1459,6 +1472,7 @@ struct tlbflush_unmap_batch {
- struct task_struct {
+@@ -1491,6 +1515,7 @@ struct task_struct {
+       struct thread_info thread_info;
+ #endif
        volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */
-+      volatile long saved_state;      /* saved state for "spinlock sleepers" */
++      volatile long saved_state; /* saved state for "spinlock sleepers" */
        void *stack;
        atomic_t usage;
        unsigned int flags;     /* per process flags, defined below */
-@@ -1495,6 +1509,12 @@ struct task_struct {
+@@ -1530,6 +1555,13 @@ struct task_struct {
  #endif
  
        unsigned int policy;
 +#ifdef CONFIG_PREEMPT_RT_FULL
 +      int migrate_disable;
++      int migrate_disable_update;
 +# ifdef CONFIG_SCHED_DEBUG
 +      int migrate_disable_atomic;
 +# endif
@@ -10289,7 +9512,7 @@ index 62c68e513e39..c873ce0183ab 100644
        int nr_cpus_allowed;
        cpumask_t cpus_allowed;
  
-@@ -1629,6 +1649,9 @@ struct task_struct {
+@@ -1668,6 +1700,9 @@ struct task_struct {
  
        struct task_cputime cputime_expires;
        struct list_head cpu_timers[3];
@@ -10298,8 +9521,8 @@ index 62c68e513e39..c873ce0183ab 100644
 +#endif
  
  /* process credentials */
-       const struct cred __rcu *real_cred; /* objective and real subjective task
-@@ -1659,10 +1682,15 @@ struct task_struct {
+       const struct cred __rcu *ptracer_cred; /* Tracer's credentials at attach */
+@@ -1699,10 +1734,15 @@ struct task_struct {
  /* signal handlers */
        struct signal_struct *signal;
        struct sighand_struct *sighand;
@@ -10315,7 +9538,22 @@ index 62c68e513e39..c873ce0183ab 100644
  
        unsigned long sas_ss_sp;
        size_t sas_ss_size;
-@@ -1891,6 +1919,12 @@ struct task_struct {
+@@ -1728,11 +1768,14 @@ struct task_struct {
+       raw_spinlock_t pi_lock;
+       struct wake_q_node wake_q;
++      struct wake_q_node wake_q_sleeper;
+ #ifdef CONFIG_RT_MUTEXES
+       /* PI waiters blocked on a rt_mutex held by this task */
+       struct rb_root pi_waiters;
+       struct rb_node *pi_waiters_leftmost;
++      /* Updated under owner's pi_lock and rq lock */
++      struct task_struct      *pi_top_task;
+       /* Deadlock detection and priority inheritance handling */
+       struct rt_mutex_waiter *pi_blocked_on;
+ #endif
+@@ -1931,6 +1974,12 @@ struct task_struct {
        /* bitmask and counter of trace recursion */
        unsigned long trace_recursion;
  #endif /* CONFIG_TRACING */
@@ -10328,7 +9566,7 @@ index 62c68e513e39..c873ce0183ab 100644
  #ifdef CONFIG_KCOV
        /* Coverage collection mode enabled for this task (0 if disabled). */
        enum kcov_mode kcov_mode;
-@@ -1916,9 +1950,23 @@ struct task_struct {
+@@ -1956,9 +2005,23 @@ struct task_struct {
        unsigned int    sequential_io;
        unsigned int    sequential_io_avg;
  #endif
@@ -10352,8 +9590,8 @@ index 62c68e513e39..c873ce0183ab 100644
        int pagefault_disabled;
  #ifdef CONFIG_MMU
        struct task_struct *oom_reaper_list;
-@@ -1939,14 +1987,6 @@ extern int arch_task_struct_size __read_mostly;
- # define arch_task_struct_size (sizeof(struct task_struct))
+@@ -1998,14 +2061,6 @@ static inline struct vm_struct *task_stack_vm_area(const struct task_struct *t)
+ }
  #endif
  
 -/* Future-safe accessor for struct task_struct's cpus_allowed. */
@@ -10367,7 +9605,7 @@ index 62c68e513e39..c873ce0183ab 100644
  #define TNF_MIGRATED  0x01
  #define TNF_NO_GROUP  0x02
  #define TNF_SHARED    0x04
-@@ -2162,6 +2202,15 @@ extern struct pid *cad_pid;
+@@ -2225,6 +2280,15 @@ extern struct pid *cad_pid;
  extern void free_task(struct task_struct *tsk);
  #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
  
@@ -10383,7 +9621,7 @@ index 62c68e513e39..c873ce0183ab 100644
  extern void __put_task_struct(struct task_struct *t);
  
  static inline void put_task_struct(struct task_struct *t)
-@@ -2169,6 +2218,7 @@ static inline void put_task_struct(struct task_struct *t)
+@@ -2232,6 +2296,7 @@ static inline void put_task_struct(struct task_struct *t)
        if (atomic_dec_and_test(&t->usage))
                __put_task_struct(t);
  }
@@ -10391,7 +9629,7 @@ index 62c68e513e39..c873ce0183ab 100644
  
  struct task_struct *task_rcu_dereference(struct task_struct **ptask);
  struct task_struct *try_get_task_struct(struct task_struct **ptask);
-@@ -2210,6 +2260,7 @@ extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut,
+@@ -2273,6 +2338,7 @@ extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut,
  /*
   * Per process flags
   */
@@ -10399,7 +9637,7 @@ index 62c68e513e39..c873ce0183ab 100644
  #define PF_EXITING    0x00000004      /* getting shut down */
  #define PF_EXITPIDONE 0x00000008      /* pi exit done on shut down */
  #define PF_VCPU               0x00000010      /* I'm a virtual CPU */
-@@ -2378,6 +2429,10 @@ extern void do_set_cpus_allowed(struct task_struct *p,
+@@ -2441,6 +2507,10 @@ extern void do_set_cpus_allowed(struct task_struct *p,
  
  extern int set_cpus_allowed_ptr(struct task_struct *p,
                                const struct cpumask *new_mask);
@@ -10410,7 +9648,7 @@ index 62c68e513e39..c873ce0183ab 100644
  #else
  static inline void do_set_cpus_allowed(struct task_struct *p,
                                      const struct cpumask *new_mask)
-@@ -2390,6 +2445,9 @@ static inline int set_cpus_allowed_ptr(struct task_struct *p,
+@@ -2453,6 +2523,9 @@ static inline int set_cpus_allowed_ptr(struct task_struct *p,
                return -EINVAL;
        return 0;
  }
@@ -10420,7 +9658,7 @@ index 62c68e513e39..c873ce0183ab 100644
  #endif
  
  #ifdef CONFIG_NO_HZ_COMMON
-@@ -2624,6 +2682,7 @@ extern void xtime_update(unsigned long ticks);
+@@ -2691,6 +2764,7 @@ extern void xtime_update(unsigned long ticks);
  
  extern int wake_up_state(struct task_struct *tsk, unsigned int state);
  extern int wake_up_process(struct task_struct *tsk);
@@ -10428,7 +9666,7 @@ index 62c68e513e39..c873ce0183ab 100644
  extern void wake_up_new_task(struct task_struct *tsk);
  #ifdef CONFIG_SMP
   extern void kick_process(struct task_struct *tsk);
-@@ -2832,6 +2891,17 @@ static inline void mmdrop(struct mm_struct *mm)
+@@ -2899,6 +2973,17 @@ static inline void mmdrop(struct mm_struct *mm)
                __mmdrop(mm);
  }
  
@@ -10443,10 +9681,10 @@ index 62c68e513e39..c873ce0183ab 100644
 +# define mmdrop_delayed(mm)   mmdrop(mm)
 +#endif
 +
- static inline bool mmget_not_zero(struct mm_struct *mm)
+ static inline void mmdrop_async_fn(struct work_struct *work)
  {
-       return atomic_inc_not_zero(&mm->mm_users);
-@@ -3168,6 +3238,43 @@ static inline int test_tsk_need_resched(struct task_struct *tsk)
+       struct mm_struct *mm = container_of(work, struct mm_struct, async_put_work);
+@@ -3291,6 +3376,43 @@ static inline int test_tsk_need_resched(struct task_struct *tsk)
        return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
  }
  
@@ -10490,7 +9728,7 @@ index 62c68e513e39..c873ce0183ab 100644
  static inline int restart_syscall(void)
  {
        set_tsk_thread_flag(current, TIF_SIGPENDING);
-@@ -3199,6 +3306,51 @@ static inline int signal_pending_state(long state, struct task_struct *p)
+@@ -3322,6 +3444,51 @@ static inline int signal_pending_state(long state, struct task_struct *p)
        return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
  }
  
@@ -10542,7 +9780,7 @@ index 62c68e513e39..c873ce0183ab 100644
  /*
   * cond_resched() and cond_resched_lock(): latency reduction via
   * explicit rescheduling in places that are safe. The return
-@@ -3220,12 +3372,16 @@ extern int __cond_resched_lock(spinlock_t *lock);
+@@ -3347,12 +3514,16 @@ extern int __cond_resched_lock(spinlock_t *lock);
        __cond_resched_lock(lock);                              \
  })
  
@@ -10559,7 +9797,7 @@ index 62c68e513e39..c873ce0183ab 100644
  
  static inline void cond_resched_rcu(void)
  {
-@@ -3387,6 +3543,31 @@ static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
+@@ -3527,6 +3698,31 @@ static inline void set_task_cpu(struct task_struct *p, unsigned int cpu)
  
  #endif /* CONFIG_SMP */
  
@@ -10591,6 +9829,46 @@ index 62c68e513e39..c873ce0183ab 100644
  extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
  extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
  
+diff --git a/include/linux/sched/rt.h b/include/linux/sched/rt.h
+index a30b172df6e1..db3e91f2bc03 100644
+--- a/include/linux/sched/rt.h
++++ b/include/linux/sched/rt.h
+@@ -16,27 +16,20 @@ static inline int rt_task(struct task_struct *p)
+ }
+ #ifdef CONFIG_RT_MUTEXES
+-extern int rt_mutex_getprio(struct task_struct *p);
+-extern void rt_mutex_setprio(struct task_struct *p, int prio);
+-extern int rt_mutex_get_effective_prio(struct task_struct *task, int newprio);
+-extern struct task_struct *rt_mutex_get_top_task(struct task_struct *task);
++/*
++ * Must hold either p->pi_lock or task_rq(p)->lock.
++ */
++static inline struct task_struct *rt_mutex_get_top_task(struct task_struct *p)
++{
++      return p->pi_top_task;
++}
++extern void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task);
+ extern void rt_mutex_adjust_pi(struct task_struct *p);
+ static inline bool tsk_is_pi_blocked(struct task_struct *tsk)
+ {
+       return tsk->pi_blocked_on != NULL;
+ }
+ #else
+-static inline int rt_mutex_getprio(struct task_struct *p)
+-{
+-      return p->normal_prio;
+-}
+-
+-static inline int rt_mutex_get_effective_prio(struct task_struct *task,
+-                                            int newprio)
+-{
+-      return newprio;
+-}
+-
+ static inline struct task_struct *rt_mutex_get_top_task(struct task_struct *task)
+ {
+       return NULL;
 diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
 index ead97654c4e9..3d7223ffdd3b 100644
 --- a/include/linux/seqlock.h
@@ -10746,7 +10024,7 @@ index b63f63eaa39c..295540fdfc72 100644
  /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
  static inline int valid_signal(unsigned long sig)
 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
-index 0f665cb26b50..59c38d1635c8 100644
+index 601dfa849d30..dca387a8fa6b 100644
 --- a/include/linux/skbuff.h
 +++ b/include/linux/skbuff.h
 @@ -284,6 +284,7 @@ struct sk_buff_head {
@@ -10757,7 +10035,7 @@ index 0f665cb26b50..59c38d1635c8 100644
  };
  
  struct sk_buff;
-@@ -1565,6 +1566,12 @@ static inline void skb_queue_head_init(struct sk_buff_head *list)
+@@ -1573,6 +1574,12 @@ static inline void skb_queue_head_init(struct sk_buff_head *list)
        __skb_queue_head_init(list);
  }
  
@@ -10771,10 +10049,36 @@ index 0f665cb26b50..59c38d1635c8 100644
                struct lock_class_key *class)
  {
 diff --git a/include/linux/smp.h b/include/linux/smp.h
-index eccae4690f41..64ec52d951c3 100644
+index 8e0cb7a0f836..891c533724f5 100644
 --- a/include/linux/smp.h
 +++ b/include/linux/smp.h
-@@ -185,6 +185,9 @@ static inline void smp_init(void) { }
+@@ -120,6 +120,13 @@ extern unsigned int setup_max_cpus;
+ extern void __init setup_nr_cpu_ids(void);
+ extern void __init smp_init(void);
++extern int __boot_cpu_id;
++
++static inline int get_boot_cpu_id(void)
++{
++      return __boot_cpu_id;
++}
++
+ #else /* !SMP */
+ static inline void smp_send_stop(void) { }
+@@ -158,6 +165,11 @@ static inline void smp_init(void) { up_late_init(); }
+ static inline void smp_init(void) { }
+ #endif
++static inline int get_boot_cpu_id(void)
++{
++      return 0;
++}
++
+ #endif /* !SMP */
+ /*
+@@ -185,6 +197,9 @@ static inline void smp_init(void) { }
  #define get_cpu()             ({ preempt_disable(); smp_processor_id(); })
  #define put_cpu()             preempt_enable()
  
@@ -10785,7 +10089,7 @@ index eccae4690f41..64ec52d951c3 100644
   * Callback to arch code if there's nosmp or maxcpus=0 on the
   * boot command line:
 diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
-index 47dd0cebd204..02928fa5499d 100644
+index 47dd0cebd204..b241cc044bd3 100644
 --- a/include/linux/spinlock.h
 +++ b/include/linux/spinlock.h
 @@ -271,7 +271,11 @@ static inline void do_raw_spin_unlock(raw_spinlock_t *lock) __releases(lock)
@@ -10812,20 +10116,7 @@ index 47dd0cebd204..02928fa5499d 100644
  /*
   * Map the spin_lock functions to the raw variants for PREEMPT_RT=n
   */
-@@ -347,6 +355,12 @@ static __always_inline void spin_unlock(spinlock_t *lock)
-       raw_spin_unlock(&lock->rlock);
- }
-+static __always_inline int spin_unlock_no_deboost(spinlock_t *lock)
-+{
-+      raw_spin_unlock(&lock->rlock);
-+      return 0;
-+}
-+
- static __always_inline void spin_unlock_bh(spinlock_t *lock)
- {
-       raw_spin_unlock_bh(&lock->rlock);
-@@ -416,4 +430,6 @@ extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);
+@@ -416,4 +424,6 @@ extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);
  #define atomic_dec_and_lock(atomic, lock) \
                __cond_lock(lock, _atomic_dec_and_lock(atomic, lock))
  
@@ -10848,10 +10139,10 @@ index 5344268e6e62..043263f30e81 100644
  #endif /* __LINUX_SPINLOCK_API_SMP_H */
 diff --git a/include/linux/spinlock_rt.h b/include/linux/spinlock_rt.h
 new file mode 100644
-index 000000000000..7eb87584e843
+index 000000000000..43ca841b913a
 --- /dev/null
 +++ b/include/linux/spinlock_rt.h
-@@ -0,0 +1,165 @@
+@@ -0,0 +1,162 @@
 +#ifndef __LINUX_SPINLOCK_RT_H
 +#define __LINUX_SPINLOCK_RT_H
 +
@@ -10880,7 +10171,6 @@ index 000000000000..7eb87584e843
 +extern unsigned long __lockfunc rt_spin_lock_trace_flags(spinlock_t *lock);
 +extern void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass);
 +extern void __lockfunc rt_spin_unlock(spinlock_t *lock);
-+extern int __lockfunc rt_spin_unlock_no_deboost(spinlock_t *lock);
 +extern void __lockfunc rt_spin_unlock_wait(spinlock_t *lock);
 +extern int __lockfunc rt_spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags);
 +extern int __lockfunc rt_spin_trylock_bh(spinlock_t *lock);
@@ -10894,7 +10184,6 @@ index 000000000000..7eb87584e843
 +extern void __lockfunc __rt_spin_lock__no_mg(struct rt_mutex *lock);
 +extern void __lockfunc __rt_spin_lock(struct rt_mutex *lock);
 +extern void __lockfunc __rt_spin_unlock(struct rt_mutex *lock);
-+extern int __lockfunc __rt_spin_trylock(struct rt_mutex *lock);
 +
 +#define spin_lock(lock)                       rt_spin_lock(lock)
 +
@@ -10967,7 +10256,6 @@ index 000000000000..7eb87584e843
 +#define spin_lock_nest_lock(lock, nest_lock) spin_lock_nested(lock, 0)
 +
 +#define spin_unlock(lock)                     rt_spin_unlock(lock)
-+#define spin_unlock_no_deboost(lock)          rt_spin_unlock_no_deboost(lock)
 +
 +#define spin_unlock_bh(lock)                          \
 +      do {                                            \
@@ -11027,18 +10315,10 @@ index 73548eb13a5d..10bac715ea96 100644
  
 -#if defined(CONFIG_SMP)
 -# include <asm/spinlock_types.h>
-+#include <linux/spinlock_types_raw.h>
-+
-+#ifndef CONFIG_PREEMPT_RT_FULL
-+# include <linux/spinlock_types_nort.h>
-+# include <linux/rwlock_types.h>
- #else
+-#else
 -# include <linux/spinlock_types_up.h>
-+# include <linux/rtmutex.h>
-+# include <linux/spinlock_types_rt.h>
-+# include <linux/rwlock_types_rt.h>
- #endif
+-#endif
+-
 -#include <linux/lockdep.h>
 -
 -typedef struct raw_spinlock {
@@ -11064,16 +10344,23 @@ index 73548eb13a5d..10bac715ea96 100644
 -#else
 -# define SPIN_DEP_MAP_INIT(lockname)
 -#endif
--
++#include <linux/spinlock_types_raw.h>
 -#ifdef CONFIG_DEBUG_SPINLOCK
 -# define SPIN_DEBUG_INIT(lockname)            \
 -      .magic = SPINLOCK_MAGIC,                \
 -      .owner_cpu = -1,                        \
 -      .owner = SPINLOCK_OWNER_INIT,
--#else
++#ifndef CONFIG_PREEMPT_RT_FULL
++# include <linux/spinlock_types_nort.h>
++# include <linux/rwlock_types.h>
+ #else
 -# define SPIN_DEBUG_INIT(lockname)
--#endif
--
++# include <linux/rtmutex.h>
++# include <linux/spinlock_types_rt.h>
++# include <linux/rwlock_types_rt.h>
+ #endif
 -#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
 -      {                                       \
 -      .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED,  \
@@ -11292,7 +10579,7 @@ index dc8eb63c6568..e793d3a257da 100644
  #define DEFINE_STATIC_SRCU(name)      __DEFINE_SRCU(name, static)
  
 diff --git a/include/linux/suspend.h b/include/linux/suspend.h
-index 7693e39b14fe..b36eedeb28d1 100644
+index d9718378a8be..e81e6dc7dcb1 100644
 --- a/include/linux/suspend.h
 +++ b/include/linux/suspend.h
 @@ -193,6 +193,12 @@ struct platform_freeze_ops {
@@ -11321,7 +10608,7 @@ index c1f9c62a8a50..83f004a72320 100644
  extern void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait);
  extern void prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait, int state);
 diff --git a/include/linux/swap.h b/include/linux/swap.h
-index e1d761463243..4ae9a4434ad3 100644
+index 55ff5593c193..52bf5477dc92 100644
 --- a/include/linux/swap.h
 +++ b/include/linux/swap.h
 @@ -11,6 +11,7 @@
@@ -11332,7 +10619,7 @@ index e1d761463243..4ae9a4434ad3 100644
  #include <asm/page.h>
  
  struct notifier_block;
-@@ -243,7 +244,8 @@ struct swap_info_struct {
+@@ -247,7 +248,8 @@ struct swap_info_struct {
  void *workingset_eviction(struct address_space *mapping, struct page *page);
  bool workingset_refault(void *shadow);
  void workingset_activation(struct page *page);
@@ -11342,7 +10629,7 @@ index e1d761463243..4ae9a4434ad3 100644
  
  static inline unsigned int workingset_node_pages(struct radix_tree_node *node)
  {
-@@ -288,6 +290,7 @@ extern unsigned long nr_free_pagecache_pages(void);
+@@ -292,6 +294,7 @@ extern unsigned long nr_free_pagecache_pages(void);
  
  
  /* linux/mm/swap.c */
@@ -11381,10 +10668,10 @@ index 000000000000..f175fa9a6016
 +
 +#endif /* _LINUX_SWORK_H */
 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
-index 2b5b10eed74f..8bf15b1858f5 100644
+index 2873baf5372a..eb1a108f17ca 100644
 --- a/include/linux/thread_info.h
 +++ b/include/linux/thread_info.h
-@@ -103,7 +103,17 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
+@@ -107,7 +107,17 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
  #define test_thread_flag(flag) \
        test_ti_thread_flag(current_thread_info(), flag)
  
@@ -11417,7 +10704,7 @@ index 51d601f192d4..83cea629efe1 100644
  #else
  # define del_timer_sync(t)            del_timer(t)
 diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
-index be007610ceb0..15154b13a53b 100644
+index ba57266d9e80..5c36934ec2bc 100644
 --- a/include/linux/trace_events.h
 +++ b/include/linux/trace_events.h
 @@ -56,6 +56,9 @@ struct trace_entry {
@@ -11487,7 +10774,7 @@ index 613771909b6e..e28c5a43229d 100644
  
  static inline void count_vm_events(enum vm_event_item item, long delta)
 diff --git a/include/linux/wait.h b/include/linux/wait.h
-index c3ff74d764fa..60222150a409 100644
+index 2408e8d5c05c..db50d6609195 100644
 --- a/include/linux/wait.h
 +++ b/include/linux/wait.h
 @@ -8,6 +8,7 @@
@@ -11499,10 +10786,10 @@ index c3ff74d764fa..60222150a409 100644
  typedef struct __wait_queue wait_queue_t;
  typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
 diff --git a/include/net/dst.h b/include/net/dst.h
-index 6835d224d47b..55a5a9698f14 100644
+index ddcff17615da..a1fc787b1a8c 100644
 --- a/include/net/dst.h
 +++ b/include/net/dst.h
-@@ -446,7 +446,7 @@ static inline void dst_confirm(struct dst_entry *dst)
+@@ -452,7 +452,7 @@ static inline void dst_confirm(struct dst_entry *dst)
  static inline int dst_neigh_output(struct dst_entry *dst, struct neighbour *n,
                                   struct sk_buff *skb)
  {
@@ -11598,10 +10885,10 @@ index 000000000000..a7034298a82a
 +
 +#endif
 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
-index d061ffeb1e71..12ef433dc3b8 100644
+index 7adf4386ac8f..d3fd5c357268 100644
 --- a/include/net/netns/ipv4.h
 +++ b/include/net/netns/ipv4.h
-@@ -70,6 +70,7 @@ struct netns_ipv4 {
+@@ -69,6 +69,7 @@ struct netns_ipv4 {
  
        int sysctl_icmp_echo_ignore_all;
        int sysctl_icmp_echo_ignore_broadcasts;
@@ -11610,7 +10897,7 @@ index d061ffeb1e71..12ef433dc3b8 100644
        int sysctl_icmp_ratelimit;
        int sysctl_icmp_ratemask;
 diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h
-index 909aff2db2b3..c47219d6e4bc 100644
+index f18fc1a0321f..5d2c9b89c168 100644
 --- a/include/net/sch_generic.h
 +++ b/include/net/sch_generic.h
 @@ -10,6 +10,7 @@
@@ -11621,16 +10908,16 @@ index 909aff2db2b3..c47219d6e4bc 100644
  
  struct Qdisc_ops;
  struct qdisc_walker;
-@@ -78,7 +79,7 @@ struct Qdisc {
+@@ -86,7 +87,7 @@ struct Qdisc {
        struct sk_buff          *gso_skb ____cacheline_aligned_in_smp;
-       struct sk_buff_head     q;
+       struct qdisc_skb_head   q;
        struct gnet_stats_basic_packed bstats;
 -      seqcount_t              running;
 +      net_seqlock_t           running;
        struct gnet_stats_queue qstats;
        unsigned long           state;
        struct Qdisc            *next_sched;
-@@ -90,13 +91,22 @@ struct Qdisc {
+@@ -98,13 +99,22 @@ struct Qdisc {
        spinlock_t              busylock ____cacheline_aligned_in_smp;
  };
  
@@ -11654,7 +10941,7 @@ index 909aff2db2b3..c47219d6e4bc 100644
        if (qdisc_is_running(qdisc))
                return false;
        /* Variant of write_seqcount_begin() telling lockdep a trylock
-@@ -105,11 +115,16 @@ static inline bool qdisc_run_begin(struct Qdisc *qdisc)
+@@ -113,11 +123,16 @@ static inline bool qdisc_run_begin(struct Qdisc *qdisc)
        raw_write_seqcount_begin(&qdisc->running);
        seqcount_acquire(&qdisc->running.dep_map, 0, 1, _RET_IP_);
        return true;
@@ -11671,7 +10958,7 @@ index 909aff2db2b3..c47219d6e4bc 100644
  }
  
  static inline bool qdisc_may_bulk(const struct Qdisc *qdisc)
-@@ -300,7 +315,7 @@ static inline spinlock_t *qdisc_root_sleeping_lock(const struct Qdisc *qdisc)
+@@ -308,7 +323,7 @@ static inline spinlock_t *qdisc_root_sleeping_lock(const struct Qdisc *qdisc)
        return qdisc_lock(root);
  }
  
@@ -11794,11 +11081,81 @@ index 000000000000..d3f2fbd560b1
 +}
 +
 +#endif /* _LATENCY_HIST_H */
+diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
+index 9b90c57517a9..516ae88cddf4 100644
+--- a/include/trace/events/sched.h
++++ b/include/trace/events/sched.h
+@@ -70,7 +70,7 @@ DECLARE_EVENT_CLASS(sched_wakeup_template,
+       TP_fast_assign(
+               memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
+               __entry->pid            = p->pid;
+-              __entry->prio           = p->prio;
++              __entry->prio           = p->prio; /* XXX SCHED_DEADLINE */
+               __entry->success        = 1; /* rudiment, kill when possible */
+               __entry->target_cpu     = task_cpu(p);
+       ),
+@@ -147,6 +147,7 @@ TRACE_EVENT(sched_switch,
+               memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
+               __entry->next_pid       = next->pid;
+               __entry->next_prio      = next->prio;
++              /* XXX SCHED_DEADLINE */
+       ),
+       TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d",
+@@ -181,7 +182,7 @@ TRACE_EVENT(sched_migrate_task,
+       TP_fast_assign(
+               memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
+               __entry->pid            = p->pid;
+-              __entry->prio           = p->prio;
++              __entry->prio           = p->prio; /* XXX SCHED_DEADLINE */
+               __entry->orig_cpu       = task_cpu(p);
+               __entry->dest_cpu       = dest_cpu;
+       ),
+@@ -206,7 +207,7 @@ DECLARE_EVENT_CLASS(sched_process_template,
+       TP_fast_assign(
+               memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
+               __entry->pid            = p->pid;
+-              __entry->prio           = p->prio;
++              __entry->prio           = p->prio; /* XXX SCHED_DEADLINE */
+       ),
+       TP_printk("comm=%s pid=%d prio=%d",
+@@ -253,7 +254,7 @@ TRACE_EVENT(sched_process_wait,
+       TP_fast_assign(
+               memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
+               __entry->pid            = pid_nr(pid);
+-              __entry->prio           = current->prio;
++              __entry->prio           = current->prio; /* XXX SCHED_DEADLINE */
+       ),
+       TP_printk("comm=%s pid=%d prio=%d",
+@@ -413,9 +414,9 @@ DEFINE_EVENT(sched_stat_runtime, sched_stat_runtime,
+  */
+ TRACE_EVENT(sched_pi_setprio,
+-      TP_PROTO(struct task_struct *tsk, int newprio),
++      TP_PROTO(struct task_struct *tsk, struct task_struct *pi_task),
+-      TP_ARGS(tsk, newprio),
++      TP_ARGS(tsk, pi_task),
+       TP_STRUCT__entry(
+               __array( char,  comm,   TASK_COMM_LEN   )
+@@ -428,7 +429,8 @@ TRACE_EVENT(sched_pi_setprio,
+               memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
+               __entry->pid            = tsk->pid;
+               __entry->oldprio        = tsk->prio;
+-              __entry->newprio        = newprio;
++              __entry->newprio        = pi_task ? pi_task->prio : tsk->prio;
++              /* XXX SCHED_DEADLINE bits missing */
+       ),
+       TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
 diff --git a/init/Kconfig b/init/Kconfig
-index cac3f096050d..b6c9166d878a 100644
+index 34407f15e6d3..2ce33a32e65d 100644
 --- a/init/Kconfig
 +++ b/init/Kconfig
-@@ -496,7 +496,7 @@ config TINY_RCU
+@@ -506,7 +506,7 @@ config TINY_RCU
  
  config RCU_EXPERT
        bool "Make expert-level adjustments to RCU configuration"
@@ -11807,7 +11164,7 @@ index cac3f096050d..b6c9166d878a 100644
        help
          This option needs to be enabled if you wish to make
          expert-level adjustments to RCU configuration.  By default,
-@@ -613,7 +613,7 @@ config RCU_FANOUT_LEAF
+@@ -623,7 +623,7 @@ config RCU_FANOUT_LEAF
  
  config RCU_FAST_NO_HZ
        bool "Accelerate last non-dyntick-idle CPU's grace periods"
@@ -11816,7 +11173,7 @@ index cac3f096050d..b6c9166d878a 100644
        default n
        help
          This option permits CPUs to enter dynticks-idle state even if
-@@ -640,7 +640,7 @@ config TREE_RCU_TRACE
+@@ -650,7 +650,7 @@ config TREE_RCU_TRACE
  config RCU_BOOST
        bool "Enable RCU priority boosting"
        depends on RT_MUTEXES && PREEMPT_RCU && RCU_EXPERT
@@ -11825,7 +11182,27 @@ index cac3f096050d..b6c9166d878a 100644
        help
          This option boosts the priority of preempted RCU readers that
          block the current preemptible RCU grace period for too long.
-@@ -1054,6 +1054,7 @@ config CFS_BANDWIDTH
+@@ -781,19 +781,6 @@ config RCU_NOCB_CPU_ALL
+ endchoice
+-config RCU_EXPEDITE_BOOT
+-      bool
+-      default n
+-      help
+-        This option enables expedited grace periods at boot time,
+-        as if rcu_expedite_gp() had been invoked early in boot.
+-        The corresponding rcu_unexpedite_gp() is invoked from
+-        rcu_end_inkernel_boot(), which is intended to be invoked
+-        at the end of the kernel-only boot sequence, just before
+-        init is exec'ed.
+-
+-        Accept the default if unsure.
+-
+ endmenu # "RCU Subsystem"
+ config BUILD_BIN2C
+@@ -1064,6 +1051,7 @@ config CFS_BANDWIDTH
  config RT_GROUP_SCHED
        bool "Group scheduling for SCHED_RR/FIFO"
        depends on CGROUP_SCHED
@@ -11833,7 +11210,7 @@ index cac3f096050d..b6c9166d878a 100644
        default n
        help
          This feature lets you explicitly allocate real CPU bandwidth
-@@ -1761,6 +1762,7 @@ choice
+@@ -1772,6 +1760,7 @@ choice
  
  config SLAB
        bool "SLAB"
@@ -11841,7 +11218,7 @@ index cac3f096050d..b6c9166d878a 100644
        select HAVE_HARDENED_USERCOPY_ALLOCATOR
        help
          The regular slab allocator that is established and known to work
-@@ -1781,6 +1783,7 @@ config SLUB
+@@ -1792,6 +1781,7 @@ config SLUB
  config SLOB
        depends on EXPERT
        bool "SLOB (Simple Allocator)"
@@ -11849,7 +11226,7 @@ index cac3f096050d..b6c9166d878a 100644
        help
           SLOB replaces the stock allocator with a drastically simpler
           allocator. SLOB is generally more space efficient but
-@@ -1799,7 +1802,7 @@ config SLAB_FREELIST_RANDOM
+@@ -1810,7 +1800,7 @@ config SLAB_FREELIST_RANDOM
  
  config SLUB_CPU_PARTIAL
        default y
@@ -11859,20 +11236,20 @@ index cac3f096050d..b6c9166d878a 100644
        help
          Per cpu partial caches accellerate objects allocation and freeing
 diff --git a/init/Makefile b/init/Makefile
-index 7bc47ee31c36..88cf473554e0 100644
+index c4fb45525d08..821190dfaa75 100644
 --- a/init/Makefile
 +++ b/init/Makefile
-@@ -33,4 +33,4 @@ $(obj)/version.o: include/generated/compile.h
+@@ -35,4 +35,4 @@ silent_chk_compile.h = :
  include/generated/compile.h: FORCE
        @$($(quiet)chk_compile.h)
        $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \
 -      "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CC) $(KBUILD_CFLAGS)"
 +      "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CONFIG_PREEMPT_RT_FULL)" "$(CC) $(KBUILD_CFLAGS)"
 diff --git a/init/main.c b/init/main.c
-index a8a58e2794a5..e4c979e37a91 100644
+index 25bac88bc66e..a4a61e7d2248 100644
 --- a/init/main.c
 +++ b/init/main.c
-@@ -507,6 +507,7 @@ asmlinkage __visible void __init start_kernel(void)
+@@ -506,6 +506,7 @@ asmlinkage __visible void __init start_kernel(void)
        setup_command_line(command_line);
        setup_nr_cpu_ids();
        setup_per_cpu_areas();
@@ -11880,211 +11257,8 @@ index a8a58e2794a5..e4c979e37a91 100644
        boot_cpu_state_init();
        smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
  
-diff --git a/ipc/msg.c b/ipc/msg.c
-index c6521c205cb4..996d89023552 100644
---- a/ipc/msg.c
-+++ b/ipc/msg.c
-@@ -183,20 +183,14 @@ static void ss_wakeup(struct list_head *h, int kill)
-       }
- }
--static void expunge_all(struct msg_queue *msq, int res)
-+static void expunge_all(struct msg_queue *msq, int res,
-+                      struct wake_q_head *wake_q)
- {
-       struct msg_receiver *msr, *t;
-       list_for_each_entry_safe(msr, t, &msq->q_receivers, r_list) {
--              msr->r_msg = NULL; /* initialize expunge ordering */
--              wake_up_process(msr->r_tsk);
--              /*
--               * Ensure that the wakeup is visible before setting r_msg as
--               * the receiving end depends on it: either spinning on a nil,
--               * or dealing with -EAGAIN cases. See lockless receive part 1
--               * and 2 in do_msgrcv().
--               */
--              smp_wmb(); /* barrier (B) */
-+
-+              wake_q_add(wake_q, msr->r_tsk);
-               msr->r_msg = ERR_PTR(res);
-       }
- }
-@@ -213,11 +207,13 @@ static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
- {
-       struct msg_msg *msg, *t;
-       struct msg_queue *msq = container_of(ipcp, struct msg_queue, q_perm);
-+      WAKE_Q(wake_q);
--      expunge_all(msq, -EIDRM);
-+      expunge_all(msq, -EIDRM, &wake_q);
-       ss_wakeup(&msq->q_senders, 1);
-       msg_rmid(ns, msq);
-       ipc_unlock_object(&msq->q_perm);
-+      wake_up_q(&wake_q);
-       rcu_read_unlock();
-       list_for_each_entry_safe(msg, t, &msq->q_messages, m_list) {
-@@ -342,6 +338,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,
-       struct kern_ipc_perm *ipcp;
-       struct msqid64_ds uninitialized_var(msqid64);
-       struct msg_queue *msq;
-+      WAKE_Q(wake_q);
-       int err;
-       if (cmd == IPC_SET) {
-@@ -389,7 +386,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,
-               /* sleeping receivers might be excluded by
-                * stricter permissions.
-                */
--              expunge_all(msq, -EAGAIN);
-+              expunge_all(msq, -EAGAIN, &wake_q);
-               /* sleeping senders might be able to send
-                * due to a larger queue size.
-                */
-@@ -402,6 +399,7 @@ static int msgctl_down(struct ipc_namespace *ns, int msqid, int cmd,
- out_unlock0:
-       ipc_unlock_object(&msq->q_perm);
-+      wake_up_q(&wake_q);
- out_unlock1:
-       rcu_read_unlock();
- out_up:
-@@ -566,7 +564,8 @@ static int testmsg(struct msg_msg *msg, long type, int mode)
-       return 0;
- }
--static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg)
-+static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg,
-+                               struct wake_q_head *wake_q)
- {
-       struct msg_receiver *msr, *t;
-@@ -577,27 +576,13 @@ static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg)
-                       list_del(&msr->r_list);
-                       if (msr->r_maxsize < msg->m_ts) {
--                              /* initialize pipelined send ordering */
--                              msr->r_msg = NULL;
--                              wake_up_process(msr->r_tsk);
--                              /* barrier (B) see barrier comment below */
--                              smp_wmb();
-+                              wake_q_add(wake_q, msr->r_tsk);
-                               msr->r_msg = ERR_PTR(-E2BIG);
-                       } else {
--                              msr->r_msg = NULL;
-                               msq->q_lrpid = task_pid_vnr(msr->r_tsk);
-                               msq->q_rtime = get_seconds();
--                              wake_up_process(msr->r_tsk);
--                              /*
--                               * Ensure that the wakeup is visible before
--                               * setting r_msg, as the receiving can otherwise
--                               * exit - once r_msg is set, the receiver can
--                               * continue. See lockless receive part 1 and 2
--                               * in do_msgrcv(). Barrier (B).
--                               */
--                              smp_wmb();
-+                              wake_q_add(wake_q, msr->r_tsk);
-                               msr->r_msg = msg;
--
-                               return 1;
-                       }
-               }
-@@ -613,6 +598,7 @@ long do_msgsnd(int msqid, long mtype, void __user *mtext,
-       struct msg_msg *msg;
-       int err;
-       struct ipc_namespace *ns;
-+      WAKE_Q(wake_q);
-       ns = current->nsproxy->ipc_ns;
-@@ -698,7 +684,7 @@ long do_msgsnd(int msqid, long mtype, void __user *mtext,
-       msq->q_lspid = task_tgid_vnr(current);
-       msq->q_stime = get_seconds();
--      if (!pipelined_send(msq, msg)) {
-+      if (!pipelined_send(msq, msg, &wake_q)) {
-               /* no one is waiting for this message, enqueue it */
-               list_add_tail(&msg->m_list, &msq->q_messages);
-               msq->q_cbytes += msgsz;
-@@ -712,6 +698,7 @@ long do_msgsnd(int msqid, long mtype, void __user *mtext,
- out_unlock0:
-       ipc_unlock_object(&msq->q_perm);
-+      wake_up_q(&wake_q);
- out_unlock1:
-       rcu_read_unlock();
-       if (msg != NULL)
-@@ -932,57 +919,25 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp, int msgfl
-               rcu_read_lock();
-               /* Lockless receive, part 2:
--               * Wait until pipelined_send or expunge_all are outside of
--               * wake_up_process(). There is a race with exit(), see
--               * ipc/mqueue.c for the details. The correct serialization
--               * ensures that a receiver cannot continue without the wakeup
--               * being visibible _before_ setting r_msg:
-+               * The work in pipelined_send() and expunge_all():
-+               * - Set pointer to message
-+               * - Queue the receiver task for later wakeup
-+               * - Wake up the process after the lock is dropped.
-                *
--               * CPU 0                             CPU 1
--               * <loop receiver>
--               *   smp_rmb(); (A) <-- pair -.      <waker thread>
--               *   <load ->r_msg>           |        msr->r_msg = NULL;
--               *                            |        wake_up_process();
--               * <continue>                 `------> smp_wmb(); (B)
--               *                                     msr->r_msg = msg;
--               *
--               * Where (A) orders the message value read and where (B) orders
--               * the write to the r_msg -- done in both pipelined_send and
--               * expunge_all.
-+               * Should the process wake up before this wakeup (due to a
-+               * signal) it will either see the message and continue â€¦
-                */
--              for (;;) {
--                      /*
--                       * Pairs with writer barrier in pipelined_send
--                       * or expunge_all.
--                       */
--                      smp_rmb(); /* barrier (A) */
--                      msg = (struct msg_msg *)msr_d.r_msg;
--                      if (msg)
--                              break;
--                      /*
--                       * The cpu_relax() call is a compiler barrier
--                       * which forces everything in this loop to be
--                       * re-loaded.
--                       */
--                      cpu_relax();
--              }
--
--              /* Lockless receive, part 3:
--               * If there is a message or an error then accept it without
--               * locking.
--               */
-+              msg = (struct msg_msg *)msr_d.r_msg;
-               if (msg != ERR_PTR(-EAGAIN))
-                       goto out_unlock1;
--              /* Lockless receive, part 3:
--               * Acquire the queue spinlock.
--               */
-+               /*
-+                * â€¦ or see -EAGAIN, acquire the lock to check the message
-+                * again.
-+                */
-               ipc_lock_object(&msq->q_perm);
--              /* Lockless receive, part 4:
--               * Repeat test after acquiring the spinlock.
--               */
-               msg = (struct msg_msg *)msr_d.r_msg;
-               if (msg != ERR_PTR(-EAGAIN))
-                       goto out_unlock0;
 diff --git a/ipc/sem.c b/ipc/sem.c
-index 5e318c5f749d..ec9203971539 100644
+index 10b94bc59d4a..b8360eaacc7a 100644
 --- a/ipc/sem.c
 +++ b/ipc/sem.c
 @@ -712,6 +712,13 @@ static int perform_atomic_semop(struct sem_array *sma, struct sem_queue *q)
@@ -12199,29 +11373,11 @@ index 3f9c97419f02..11dbe26a8279 100644
  endchoice
  
  config PREEMPT_COUNT
-diff --git a/kernel/Makefile b/kernel/Makefile
-index e2ec54e2b952..bff8214bf5f6 100644
---- a/kernel/Makefile
-+++ b/kernel/Makefile
-@@ -11,6 +11,13 @@ obj-y     = fork.o exec_domain.o panic.o \
-           notifier.o ksysfs.o cred.o reboot.o \
-           async.o range.o smpboot.o
-+# Tracing may do some dangerous __builtin_return_address() operations
-+# We know they are dangerous, we don't need gcc telling us that.
-+ifdef CONFIG_USING_GET_LOCK_PARENT_IP
-+FRAME_CFLAGS := $(call cc-disable-warning,frame-address)
-+KBUILD_CFLAGS += $(FRAME_CFLAGS)
-+endif
-+
- obj-$(CONFIG_MULTIUSER) += groups.o
- ifdef CONFIG_FUNCTION_TRACER
 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
-index d6b729beba49..11d61b2ca938 100644
+index 4c233437ee1a..6c3c9f298f22 100644
 --- a/kernel/cgroup.c
 +++ b/kernel/cgroup.c
-@@ -5027,10 +5027,10 @@ static void css_free_rcu_fn(struct rcu_head *rcu_head)
+@@ -5041,10 +5041,10 @@ static void css_free_rcu_fn(struct rcu_head *rcu_head)
        queue_work(cgroup_destroy_wq, &css->destroy_work);
  }
  
@@ -12234,7 +11390,7 @@ index d6b729beba49..11d61b2ca938 100644
        struct cgroup_subsys *ss = css->ss;
        struct cgroup *cgrp = css->cgroup;
  
-@@ -5071,8 +5071,8 @@ static void css_release(struct percpu_ref *ref)
+@@ -5087,8 +5087,8 @@ static void css_release(struct percpu_ref *ref)
        struct cgroup_subsys_state *css =
                container_of(ref, struct cgroup_subsys_state, refcnt);
  
@@ -12245,7 +11401,7 @@ index d6b729beba49..11d61b2ca938 100644
  }
  
  static void init_and_link_css(struct cgroup_subsys_state *css,
-@@ -5716,6 +5716,7 @@ static int __init cgroup_wq_init(void)
+@@ -5749,6 +5749,7 @@ static int __init cgroup_wq_init(void)
         */
        cgroup_destroy_wq = alloc_workqueue("cgroup_destroy", 0, 1);
        BUG_ON(!cgroup_destroy_wq);
@@ -12254,20 +11410,10 @@ index d6b729beba49..11d61b2ca938 100644
        /*
         * Used to destroy pidlists and separate to serve as flush domain.
 diff --git a/kernel/cpu.c b/kernel/cpu.c
-index 341bf80f80bd..b575429a8a00 100644
+index 26a4f74bff83..010db3c943cd 100644
 --- a/kernel/cpu.c
 +++ b/kernel/cpu.c
-@@ -152,8 +152,8 @@ static struct {
- #endif
- } cpu_hotplug = {
-       .active_writer = NULL,
--      .wq = __WAIT_QUEUE_HEAD_INITIALIZER(cpu_hotplug.wq),
-       .lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
-+      .wq = __WAIT_QUEUE_HEAD_INITIALIZER(cpu_hotplug.wq),
- #ifdef CONFIG_DEBUG_LOCK_ALLOC
-       .dep_map = {.name = "cpu_hotplug.lock" },
- #endif
-@@ -166,6 +166,289 @@ static struct {
+@@ -239,6 +239,289 @@ static struct {
  #define cpuhp_lock_acquire()      lock_map_acquire(&cpu_hotplug.dep_map)
  #define cpuhp_lock_release()      lock_map_release(&cpu_hotplug.dep_map)
  
@@ -12555,82 +11701,463 @@ index 341bf80f80bd..b575429a8a00 100644
 +      tell_sched_cpu_down_done(cpu);
 +}
  
- void get_online_cpus(void)
+ void get_online_cpus(void)
+ {
+@@ -802,10 +1085,14 @@ static int takedown_cpu(unsigned int cpu)
+       struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
+       int err;
++      __cpu_unplug_wait(cpu);
+       /* Park the smpboot threads */
+       kthread_park(per_cpu_ptr(&cpuhp_state, cpu)->thread);
+       smpboot_park_threads(cpu);
++      /* Notifiers are done. Don't let any more tasks pin this CPU. */
++      cpu_unplug_sync(cpu);
++
+       /*
+        * Prevent irq alloc/free while the dying cpu reorganizes the
+        * interrupt affinities.
+@@ -890,6 +1177,9 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
+       struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
+       int prev_state, ret = 0;
+       bool hasdied = false;
++      int mycpu;
++      cpumask_var_t cpumask;
++      cpumask_var_t cpumask_org;
+       if (num_online_cpus() == 1)
+               return -EBUSY;
+@@ -897,7 +1187,34 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
+       if (!cpu_present(cpu))
+               return -EINVAL;
++      /* Move the downtaker off the unplug cpu */
++      if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
++              return -ENOMEM;
++      if (!alloc_cpumask_var(&cpumask_org, GFP_KERNEL))  {
++              free_cpumask_var(cpumask);
++              return -ENOMEM;
++      }
++
++      cpumask_copy(cpumask_org, tsk_cpus_allowed(current));
++      cpumask_andnot(cpumask, cpu_online_mask, cpumask_of(cpu));
++      set_cpus_allowed_ptr(current, cpumask);
++      free_cpumask_var(cpumask);
++      migrate_disable();
++      mycpu = smp_processor_id();
++      if (mycpu == cpu) {
++              printk(KERN_ERR "Yuck! Still on unplug CPU\n!");
++              migrate_enable();
++              ret = -EBUSY;
++              goto restore_cpus;
++      }
++
++      migrate_enable();
+       cpu_hotplug_begin();
++      ret = cpu_unplug_begin(cpu);
++      if (ret) {
++              printk("cpu_unplug_begin(%d) failed\n", cpu);
++              goto out_cancel;
++      }
+       cpuhp_tasks_frozen = tasks_frozen;
+@@ -936,10 +1253,15 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
+       hasdied = prev_state != st->state && st->state == CPUHP_OFFLINE;
+ out:
++      cpu_unplug_done(cpu);
++out_cancel:
+       cpu_hotplug_done();
+       /* This post dead nonsense must die */
+       if (!ret && hasdied)
+               cpu_notify_nofail(CPU_POST_DEAD, cpu);
++restore_cpus:
++      set_cpus_allowed_ptr(current, cpumask_org);
++      free_cpumask_var(cpumask_org);
+       return ret;
+ }
+@@ -1242,6 +1564,8 @@ core_initcall(cpu_hotplug_pm_sync_init);
+ #endif /* CONFIG_PM_SLEEP_SMP */
++int __boot_cpu_id;
++
+ #endif /* CONFIG_SMP */
+ /* Boot processor state steps */
+@@ -1926,6 +2250,10 @@ void __init boot_cpu_init(void)
+       set_cpu_active(cpu, true);
+       set_cpu_present(cpu, true);
+       set_cpu_possible(cpu, true);
++
++#ifdef CONFIG_SMP
++      __boot_cpu_id = cpu;
++#endif
+ }
+ /*
+diff --git a/kernel/cpu_pm.c b/kernel/cpu_pm.c
+index 009cc9a17d95..67b02e138a47 100644
+--- a/kernel/cpu_pm.c
++++ b/kernel/cpu_pm.c
+@@ -22,15 +22,21 @@
+ #include <linux/spinlock.h>
+ #include <linux/syscore_ops.h>
+-static DEFINE_RWLOCK(cpu_pm_notifier_lock);
+-static RAW_NOTIFIER_HEAD(cpu_pm_notifier_chain);
++static ATOMIC_NOTIFIER_HEAD(cpu_pm_notifier_chain);
+ static int cpu_pm_notify(enum cpu_pm_event event, int nr_to_call, int *nr_calls)
+ {
+       int ret;
+-      ret = __raw_notifier_call_chain(&cpu_pm_notifier_chain, event, NULL,
++      /*
++       * __atomic_notifier_call_chain has a RCU read critical section, which
++       * could be disfunctional in cpu idle. Copy RCU_NONIDLE code to let
++       * RCU know this.
++       */
++      rcu_irq_enter_irqson();
++      ret = __atomic_notifier_call_chain(&cpu_pm_notifier_chain, event, NULL,
+               nr_to_call, nr_calls);
++      rcu_irq_exit_irqson();
+       return notifier_to_errno(ret);
+ }
+@@ -47,14 +53,7 @@ static int cpu_pm_notify(enum cpu_pm_event event, int nr_to_call, int *nr_calls)
+  */
+ int cpu_pm_register_notifier(struct notifier_block *nb)
+ {
+-      unsigned long flags;
+-      int ret;
+-
+-      write_lock_irqsave(&cpu_pm_notifier_lock, flags);
+-      ret = raw_notifier_chain_register(&cpu_pm_notifier_chain, nb);
+-      write_unlock_irqrestore(&cpu_pm_notifier_lock, flags);
+-
+-      return ret;
++      return atomic_notifier_chain_register(&cpu_pm_notifier_chain, nb);
+ }
+ EXPORT_SYMBOL_GPL(cpu_pm_register_notifier);
+@@ -69,14 +68,7 @@ EXPORT_SYMBOL_GPL(cpu_pm_register_notifier);
+  */
+ int cpu_pm_unregister_notifier(struct notifier_block *nb)
+ {
+-      unsigned long flags;
+-      int ret;
+-
+-      write_lock_irqsave(&cpu_pm_notifier_lock, flags);
+-      ret = raw_notifier_chain_unregister(&cpu_pm_notifier_chain, nb);
+-      write_unlock_irqrestore(&cpu_pm_notifier_lock, flags);
+-
+-      return ret;
++      return atomic_notifier_chain_unregister(&cpu_pm_notifier_chain, nb);
+ }
+ EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier);
+@@ -100,7 +92,6 @@ int cpu_pm_enter(void)
+       int nr_calls;
+       int ret = 0;
+-      read_lock(&cpu_pm_notifier_lock);
+       ret = cpu_pm_notify(CPU_PM_ENTER, -1, &nr_calls);
+       if (ret)
+               /*
+@@ -108,7 +99,6 @@ int cpu_pm_enter(void)
+                * PM entry who are notified earlier to prepare for it.
+                */
+               cpu_pm_notify(CPU_PM_ENTER_FAILED, nr_calls - 1, NULL);
+-      read_unlock(&cpu_pm_notifier_lock);
+       return ret;
+ }
+@@ -128,13 +118,7 @@ EXPORT_SYMBOL_GPL(cpu_pm_enter);
+  */
+ int cpu_pm_exit(void)
+ {
+-      int ret;
+-
+-      read_lock(&cpu_pm_notifier_lock);
+-      ret = cpu_pm_notify(CPU_PM_EXIT, -1, NULL);
+-      read_unlock(&cpu_pm_notifier_lock);
+-
+-      return ret;
++      return cpu_pm_notify(CPU_PM_EXIT, -1, NULL);
+ }
+ EXPORT_SYMBOL_GPL(cpu_pm_exit);
+@@ -159,7 +143,6 @@ int cpu_cluster_pm_enter(void)
+       int nr_calls;
+       int ret = 0;
+-      read_lock(&cpu_pm_notifier_lock);
+       ret = cpu_pm_notify(CPU_CLUSTER_PM_ENTER, -1, &nr_calls);
+       if (ret)
+               /*
+@@ -167,7 +150,6 @@ int cpu_cluster_pm_enter(void)
+                * PM entry who are notified earlier to prepare for it.
+                */
+               cpu_pm_notify(CPU_CLUSTER_PM_ENTER_FAILED, nr_calls - 1, NULL);
+-      read_unlock(&cpu_pm_notifier_lock);
+       return ret;
+ }
+@@ -190,13 +172,7 @@ EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
+  */
+ int cpu_cluster_pm_exit(void)
+ {
+-      int ret;
+-
+-      read_lock(&cpu_pm_notifier_lock);
+-      ret = cpu_pm_notify(CPU_CLUSTER_PM_EXIT, -1, NULL);
+-      read_unlock(&cpu_pm_notifier_lock);
+-
+-      return ret;
++      return cpu_pm_notify(CPU_CLUSTER_PM_EXIT, -1, NULL);
+ }
+ EXPORT_SYMBOL_GPL(cpu_cluster_pm_exit);
+diff --git a/kernel/cpuset.c b/kernel/cpuset.c
+index 511b1dd8ff09..1dd63833ecdc 100644
+--- a/kernel/cpuset.c
++++ b/kernel/cpuset.c
+@@ -285,7 +285,7 @@ static struct cpuset top_cpuset = {
+  */
+ static DEFINE_MUTEX(cpuset_mutex);
+-static DEFINE_SPINLOCK(callback_lock);
++static DEFINE_RAW_SPINLOCK(callback_lock);
+ static struct workqueue_struct *cpuset_migrate_mm_wq;
+@@ -908,9 +908,9 @@ static void update_cpumasks_hier(struct cpuset *cs, struct cpumask *new_cpus)
+                       continue;
+               rcu_read_unlock();
+-              spin_lock_irq(&callback_lock);
++              raw_spin_lock_irq(&callback_lock);
+               cpumask_copy(cp->effective_cpus, new_cpus);
+-              spin_unlock_irq(&callback_lock);
++              raw_spin_unlock_irq(&callback_lock);
+               WARN_ON(!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
+                       !cpumask_equal(cp->cpus_allowed, cp->effective_cpus));
+@@ -975,9 +975,9 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
+       if (retval < 0)
+               return retval;
+-      spin_lock_irq(&callback_lock);
++      raw_spin_lock_irq(&callback_lock);
+       cpumask_copy(cs->cpus_allowed, trialcs->cpus_allowed);
+-      spin_unlock_irq(&callback_lock);
++      raw_spin_unlock_irq(&callback_lock);
+       /* use trialcs->cpus_allowed as a temp variable */
+       update_cpumasks_hier(cs, trialcs->cpus_allowed);
+@@ -1177,9 +1177,9 @@ static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
+                       continue;
+               rcu_read_unlock();
+-              spin_lock_irq(&callback_lock);
++              raw_spin_lock_irq(&callback_lock);
+               cp->effective_mems = *new_mems;
+-              spin_unlock_irq(&callback_lock);
++              raw_spin_unlock_irq(&callback_lock);
+               WARN_ON(!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
+                       !nodes_equal(cp->mems_allowed, cp->effective_mems));
+@@ -1247,9 +1247,9 @@ static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs,
+       if (retval < 0)
+               goto done;
+-      spin_lock_irq(&callback_lock);
++      raw_spin_lock_irq(&callback_lock);
+       cs->mems_allowed = trialcs->mems_allowed;
+-      spin_unlock_irq(&callback_lock);
++      raw_spin_unlock_irq(&callback_lock);
+       /* use trialcs->mems_allowed as a temp variable */
+       update_nodemasks_hier(cs, &trialcs->mems_allowed);
+@@ -1340,9 +1340,9 @@ static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
+       spread_flag_changed = ((is_spread_slab(cs) != is_spread_slab(trialcs))
+                       || (is_spread_page(cs) != is_spread_page(trialcs)));
+-      spin_lock_irq(&callback_lock);
++      raw_spin_lock_irq(&callback_lock);
+       cs->flags = trialcs->flags;
+-      spin_unlock_irq(&callback_lock);
++      raw_spin_unlock_irq(&callback_lock);
+       if (!cpumask_empty(trialcs->cpus_allowed) && balance_flag_changed)
+               rebuild_sched_domains_locked();
+@@ -1757,7 +1757,7 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
+       cpuset_filetype_t type = seq_cft(sf)->private;
+       int ret = 0;
+-      spin_lock_irq(&callback_lock);
++      raw_spin_lock_irq(&callback_lock);
+       switch (type) {
+       case FILE_CPULIST:
+@@ -1776,7 +1776,7 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
+               ret = -EINVAL;
+       }
+-      spin_unlock_irq(&callback_lock);
++      raw_spin_unlock_irq(&callback_lock);
+       return ret;
+ }
+@@ -1991,12 +1991,12 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
+       cpuset_inc();
+-      spin_lock_irq(&callback_lock);
++      raw_spin_lock_irq(&callback_lock);
+       if (cgroup_subsys_on_dfl(cpuset_cgrp_subsys)) {
+               cpumask_copy(cs->effective_cpus, parent->effective_cpus);
+               cs->effective_mems = parent->effective_mems;
+       }
+-      spin_unlock_irq(&callback_lock);
++      raw_spin_unlock_irq(&callback_lock);
+       if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags))
+               goto out_unlock;
+@@ -2023,12 +2023,12 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
+       }
+       rcu_read_unlock();
+-      spin_lock_irq(&callback_lock);
++      raw_spin_lock_irq(&callback_lock);
+       cs->mems_allowed = parent->mems_allowed;
+       cs->effective_mems = parent->mems_allowed;
+       cpumask_copy(cs->cpus_allowed, parent->cpus_allowed);
+       cpumask_copy(cs->effective_cpus, parent->cpus_allowed);
+-      spin_unlock_irq(&callback_lock);
++      raw_spin_unlock_irq(&callback_lock);
+ out_unlock:
+       mutex_unlock(&cpuset_mutex);
+       return 0;
+@@ -2067,7 +2067,7 @@ static void cpuset_css_free(struct cgroup_subsys_state *css)
+ static void cpuset_bind(struct cgroup_subsys_state *root_css)
  {
-@@ -710,10 +993,14 @@ static int takedown_cpu(unsigned int cpu)
-       struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
-       int err;
+       mutex_lock(&cpuset_mutex);
+-      spin_lock_irq(&callback_lock);
++      raw_spin_lock_irq(&callback_lock);
  
-+      __cpu_unplug_wait(cpu);
-       /* Park the smpboot threads */
-       kthread_park(per_cpu_ptr(&cpuhp_state, cpu)->thread);
-       smpboot_park_threads(cpu);
+       if (cgroup_subsys_on_dfl(cpuset_cgrp_subsys)) {
+               cpumask_copy(top_cpuset.cpus_allowed, cpu_possible_mask);
+@@ -2078,7 +2078,7 @@ static void cpuset_bind(struct cgroup_subsys_state *root_css)
+               top_cpuset.mems_allowed = top_cpuset.effective_mems;
+       }
+-      spin_unlock_irq(&callback_lock);
++      raw_spin_unlock_irq(&callback_lock);
+       mutex_unlock(&cpuset_mutex);
+ }
+@@ -2179,12 +2179,12 @@ hotplug_update_tasks_legacy(struct cpuset *cs,
+ {
+       bool is_empty;
+-      spin_lock_irq(&callback_lock);
++      raw_spin_lock_irq(&callback_lock);
+       cpumask_copy(cs->cpus_allowed, new_cpus);
+       cpumask_copy(cs->effective_cpus, new_cpus);
+       cs->mems_allowed = *new_mems;
+       cs->effective_mems = *new_mems;
+-      spin_unlock_irq(&callback_lock);
++      raw_spin_unlock_irq(&callback_lock);
  
-+      /* Notifiers are done. Don't let any more tasks pin this CPU. */
-+      cpu_unplug_sync(cpu);
-+
        /*
-        * Prevent irq alloc/free while the dying cpu reorganizes the
-        * interrupt affinities.
-@@ -799,6 +1086,9 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
-       struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
-       int prev_state, ret = 0;
-       bool hasdied = false;
-+      int mycpu;
-+      cpumask_var_t cpumask;
-+      cpumask_var_t cpumask_org;
+        * Don't call update_tasks_cpumask() if the cpuset becomes empty,
+@@ -2221,10 +2221,10 @@ hotplug_update_tasks(struct cpuset *cs,
+       if (nodes_empty(*new_mems))
+               *new_mems = parent_cs(cs)->effective_mems;
+-      spin_lock_irq(&callback_lock);
++      raw_spin_lock_irq(&callback_lock);
+       cpumask_copy(cs->effective_cpus, new_cpus);
+       cs->effective_mems = *new_mems;
+-      spin_unlock_irq(&callback_lock);
++      raw_spin_unlock_irq(&callback_lock);
+       if (cpus_updated)
+               update_tasks_cpumask(cs);
+@@ -2317,21 +2317,21 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
+       /* synchronize cpus_allowed to cpu_active_mask */
+       if (cpus_updated) {
+-              spin_lock_irq(&callback_lock);
++              raw_spin_lock_irq(&callback_lock);
+               if (!on_dfl)
+                       cpumask_copy(top_cpuset.cpus_allowed, &new_cpus);
+               cpumask_copy(top_cpuset.effective_cpus, &new_cpus);
+-              spin_unlock_irq(&callback_lock);
++              raw_spin_unlock_irq(&callback_lock);
+               /* we don't mess with cpumasks of tasks in top_cpuset */
+       }
  
-       if (num_online_cpus() == 1)
-               return -EBUSY;
-@@ -806,7 +1096,34 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
-       if (!cpu_present(cpu))
-               return -EINVAL;
+       /* synchronize mems_allowed to N_MEMORY */
+       if (mems_updated) {
+-              spin_lock_irq(&callback_lock);
++              raw_spin_lock_irq(&callback_lock);
+               if (!on_dfl)
+                       top_cpuset.mems_allowed = new_mems;
+               top_cpuset.effective_mems = new_mems;
+-              spin_unlock_irq(&callback_lock);
++              raw_spin_unlock_irq(&callback_lock);
+               update_tasks_nodemask(&top_cpuset);
+       }
  
-+      /* Move the downtaker off the unplug cpu */
-+      if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
-+              return -ENOMEM;
-+      if (!alloc_cpumask_var(&cpumask_org, GFP_KERNEL))  {
-+              free_cpumask_var(cpumask);
-+              return -ENOMEM;
-+      }
-+
-+      cpumask_copy(cpumask_org, tsk_cpus_allowed(current));
-+      cpumask_andnot(cpumask, cpu_online_mask, cpumask_of(cpu));
-+      set_cpus_allowed_ptr(current, cpumask);
-+      free_cpumask_var(cpumask);
-+      migrate_disable();
-+      mycpu = smp_processor_id();
-+      if (mycpu == cpu) {
-+              printk(KERN_ERR "Yuck! Still on unplug CPU\n!");
-+              migrate_enable();
-+              ret = -EBUSY;
-+              goto restore_cpus;
-+      }
-+
-+      migrate_enable();
-       cpu_hotplug_begin();
-+      ret = cpu_unplug_begin(cpu);
-+      if (ret) {
-+              printk("cpu_unplug_begin(%d) failed\n", cpu);
-+              goto out_cancel;
-+      }
+@@ -2436,11 +2436,11 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
+ {
+       unsigned long flags;
  
-       cpuhp_tasks_frozen = tasks_frozen;
+-      spin_lock_irqsave(&callback_lock, flags);
++      raw_spin_lock_irqsave(&callback_lock, flags);
+       rcu_read_lock();
+       guarantee_online_cpus(task_cs(tsk), pmask);
+       rcu_read_unlock();
+-      spin_unlock_irqrestore(&callback_lock, flags);
++      raw_spin_unlock_irqrestore(&callback_lock, flags);
+ }
  
-@@ -845,10 +1162,15 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
+ void cpuset_cpus_allowed_fallback(struct task_struct *tsk)
+@@ -2488,11 +2488,11 @@ nodemask_t cpuset_mems_allowed(struct task_struct *tsk)
+       nodemask_t mask;
+       unsigned long flags;
  
-       hasdied = prev_state != st->state && st->state == CPUHP_OFFLINE;
- out:
-+      cpu_unplug_done(cpu);
-+out_cancel:
-       cpu_hotplug_done();
-       /* This post dead nonsense must die */
-       if (!ret && hasdied)
-               cpu_notify_nofail(CPU_POST_DEAD, cpu);
-+restore_cpus:
-+      set_cpus_allowed_ptr(current, cpumask_org);
-+      free_cpumask_var(cpumask_org);
-       return ret;
+-      spin_lock_irqsave(&callback_lock, flags);
++      raw_spin_lock_irqsave(&callback_lock, flags);
+       rcu_read_lock();
+       guarantee_online_mems(task_cs(tsk), &mask);
+       rcu_read_unlock();
+-      spin_unlock_irqrestore(&callback_lock, flags);
++      raw_spin_unlock_irqrestore(&callback_lock, flags);
+       return mask;
+ }
+@@ -2584,14 +2584,14 @@ bool __cpuset_node_allowed(int node, gfp_t gfp_mask)
+               return true;
+       /* Not hardwall and node outside mems_allowed: scan up cpusets */
+-      spin_lock_irqsave(&callback_lock, flags);
++      raw_spin_lock_irqsave(&callback_lock, flags);
+       rcu_read_lock();
+       cs = nearest_hardwall_ancestor(task_cs(current));
+       allowed = node_isset(node, cs->mems_allowed);
+       rcu_read_unlock();
+-      spin_unlock_irqrestore(&callback_lock, flags);
++      raw_spin_unlock_irqrestore(&callback_lock, flags);
+       return allowed;
  }
  
 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
@@ -12675,10 +12202,10 @@ index fc1ef736253c..83c666537a7a 100644
        return r;
  }
 diff --git a/kernel/events/core.c b/kernel/events/core.c
-index fc9bb2225291..bc2db7e1ae04 100644
+index 13b9784427b0..f74fbfe5465c 100644
 --- a/kernel/events/core.c
 +++ b/kernel/events/core.c
-@@ -1042,6 +1042,7 @@ static void __perf_mux_hrtimer_init(struct perf_cpu_context *cpuctx, int cpu)
+@@ -1050,6 +1050,7 @@ static void __perf_mux_hrtimer_init(struct perf_cpu_context *cpuctx, int cpu)
        raw_spin_lock_init(&cpuctx->hrtimer_lock);
        hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED);
        timer->function = perf_mux_hrtimer_handler;
@@ -12686,7 +12213,7 @@ index fc9bb2225291..bc2db7e1ae04 100644
  }
  
  static int perf_mux_hrtimer_restart(struct perf_cpu_context *cpuctx)
-@@ -8215,6 +8216,7 @@ static void perf_swevent_init_hrtimer(struct perf_event *event)
+@@ -8405,6 +8406,7 @@ static void perf_swevent_init_hrtimer(struct perf_event *event)
  
        hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        hwc->hrtimer.function = perf_swevent_hrtimer;
@@ -12695,7 +12222,7 @@ index fc9bb2225291..bc2db7e1ae04 100644
        /*
         * Since hrtimers have a fixed rate, we can do a static freq->period
 diff --git a/kernel/exit.c b/kernel/exit.c
-index 091a78be3b09..170b672bbb38 100644
+index 3076f3089919..fb2ebcf3ca7c 100644
 --- a/kernel/exit.c
 +++ b/kernel/exit.c
 @@ -143,7 +143,7 @@ static void __exit_signal(struct task_struct *tsk)
@@ -12708,10 +12235,18 @@ index 091a78be3b09..170b672bbb38 100644
        spin_unlock(&sighand->siglock);
  
 diff --git a/kernel/fork.c b/kernel/fork.c
-index beb31725f7e2..e398cb9e62fa 100644
+index 9321b1ad3335..276acd8acf0a 100644
 --- a/kernel/fork.c
 +++ b/kernel/fork.c
-@@ -251,7 +251,9 @@ static inline void put_signal_struct(struct signal_struct *sig)
+@@ -76,6 +76,7 @@
+ #include <linux/compiler.h>
+ #include <linux/sysctl.h>
+ #include <linux/kcov.h>
++#include <linux/kprobes.h>
+ #include <asm/pgtable.h>
+ #include <asm/pgalloc.h>
+@@ -376,13 +377,24 @@ static inline void put_signal_struct(struct signal_struct *sig)
        if (atomic_dec_and_test(&sig->sigcnt))
                free_signal_struct(sig);
  }
@@ -12722,7 +12257,22 @@ index beb31725f7e2..e398cb9e62fa 100644
  void __put_task_struct(struct task_struct *tsk)
  {
        WARN_ON(!tsk->exit_state);
-@@ -268,7 +270,18 @@ void __put_task_struct(struct task_struct *tsk)
+       WARN_ON(atomic_read(&tsk->usage));
+       WARN_ON(tsk == current);
++      /*
++       * Remove function-return probe instances associated with this
++       * task and put them back on the free list.
++       */
++      kprobe_flush_task(tsk);
++
++      /* Task is done with its stack. */
++      put_task_stack(tsk);
++
+       cgroup_free(tsk);
+       task_numa_free(tsk);
+       security_task_free(tsk);
+@@ -393,7 +405,18 @@ void __put_task_struct(struct task_struct *tsk)
        if (!profile_handoff_task(tsk))
                free_task(tsk);
  }
@@ -12741,7 +12291,15 @@ index beb31725f7e2..e398cb9e62fa 100644
  
  void __init __weak arch_task_cache_init(void) { }
  
-@@ -702,6 +715,19 @@ void __mmdrop(struct mm_struct *mm)
+@@ -535,6 +558,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
+       tsk->splice_pipe = NULL;
+       tsk->task_frag.page = NULL;
+       tsk->wake_q.next = NULL;
++      tsk->wake_q_sleeper.next = NULL;
+       account_kernel_stack(tsk, 1);
+@@ -861,6 +885,19 @@ void __mmdrop(struct mm_struct *mm)
  }
  EXPORT_SYMBOL_GPL(__mmdrop);
  
@@ -12761,68 +12319,468 @@ index beb31725f7e2..e398cb9e62fa 100644
  static inline void __mmput(struct mm_struct *mm)
  {
        VM_BUG_ON(atomic_read(&mm->mm_users));
-@@ -1274,6 +1300,9 @@ static void rt_mutex_init_task(struct task_struct *p)
+@@ -1426,6 +1463,7 @@ static void rt_mutex_init_task(struct task_struct *p)
+ #ifdef CONFIG_RT_MUTEXES
+       p->pi_waiters = RB_ROOT;
+       p->pi_waiters_leftmost = NULL;
++      p->pi_top_task = NULL;
+       p->pi_blocked_on = NULL;
+ #endif
+ }
+@@ -1435,6 +1473,9 @@ static void rt_mutex_init_task(struct task_struct *p)
   */
  static void posix_cpu_timers_init(struct task_struct *tsk)
  {
-+#ifdef CONFIG_PREEMPT_RT_BASE
-+      tsk->posix_timer_list = NULL;
-+#endif
-       tsk->cputime_expires.prof_exp = 0;
-       tsk->cputime_expires.virt_exp = 0;
-       tsk->cputime_expires.sched_exp = 0;
-@@ -1399,6 +1428,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
-       spin_lock_init(&p->alloc_lock);
++#ifdef CONFIG_PREEMPT_RT_BASE
++      tsk->posix_timer_list = NULL;
++#endif
+       tsk->cputime_expires.prof_exp = 0;
+       tsk->cputime_expires.virt_exp = 0;
+       tsk->cputime_expires.sched_exp = 0;
+@@ -1561,6 +1602,7 @@ static __latent_entropy struct task_struct *copy_process(
+       spin_lock_init(&p->alloc_lock);
+       init_sigpending(&p->pending);
++      p->sigqueue_cache = NULL;
+       p->utime = p->stime = p->gtime = 0;
+       p->utimescaled = p->stimescaled = 0;
+diff --git a/kernel/futex.c b/kernel/futex.c
+index 88bad86180ac..2e074d63e8fa 100644
+--- a/kernel/futex.c
++++ b/kernel/futex.c
+@@ -801,7 +801,7 @@ static int refill_pi_state_cache(void)
+       return 0;
+ }
+-static struct futex_pi_state * alloc_pi_state(void)
++static struct futex_pi_state *alloc_pi_state(void)
+ {
+       struct futex_pi_state *pi_state = current->pi_state_cache;
+@@ -811,6 +811,11 @@ static struct futex_pi_state * alloc_pi_state(void)
+       return pi_state;
+ }
++static void get_pi_state(struct futex_pi_state *pi_state)
++{
++      WARN_ON_ONCE(!atomic_inc_not_zero(&pi_state->refcount));
++}
++
+ /*
+  * Drops a reference to the pi_state object and frees or caches it
+  * when the last reference is gone.
+@@ -855,7 +860,7 @@ static void put_pi_state(struct futex_pi_state *pi_state)
+  * Look up the task based on what TID userspace gave us.
+  * We dont trust it.
+  */
+-static struct task_struct * futex_find_get_task(pid_t pid)
++static struct task_struct *futex_find_get_task(pid_t pid)
+ {
+       struct task_struct *p;
+@@ -905,7 +910,9 @@ void exit_pi_state_list(struct task_struct *curr)
+                * task still owns the PI-state:
+                */
+               if (head->next != next) {
++                      raw_spin_unlock_irq(&curr->pi_lock);
+                       spin_unlock(&hb->lock);
++                      raw_spin_lock_irq(&curr->pi_lock);
+                       continue;
+               }
+@@ -915,10 +922,12 @@ void exit_pi_state_list(struct task_struct *curr)
+               pi_state->owner = NULL;
+               raw_spin_unlock_irq(&curr->pi_lock);
+-              rt_mutex_unlock(&pi_state->pi_mutex);
+-
++              get_pi_state(pi_state);
+               spin_unlock(&hb->lock);
++              rt_mutex_futex_unlock(&pi_state->pi_mutex);
++              put_pi_state(pi_state);
++
+               raw_spin_lock_irq(&curr->pi_lock);
+       }
+       raw_spin_unlock_irq(&curr->pi_lock);
+@@ -972,6 +981,39 @@ void exit_pi_state_list(struct task_struct *curr)
+  *
+  * [10] There is no transient state which leaves owner and user space
+  *    TID out of sync.
++ *
++ *
++ * Serialization and lifetime rules:
++ *
++ * hb->lock:
++ *
++ *    hb -> futex_q, relation
++ *    futex_q -> pi_state, relation
++ *
++ *    (cannot be raw because hb can contain arbitrary amount
++ *     of futex_q's)
++ *
++ * pi_mutex->wait_lock:
++ *
++ *    {uval, pi_state}
++ *
++ *    (and pi_mutex 'obviously')
++ *
++ * p->pi_lock:
++ *
++ *    p->pi_state_list -> pi_state->list, relation
++ *
++ * pi_state->refcount:
++ *
++ *    pi_state lifetime
++ *
++ *
++ * Lock order:
++ *
++ *   hb->lock
++ *     pi_mutex->wait_lock
++ *       p->pi_lock
++ *
+  */
+ /*
+@@ -979,10 +1021,13 @@ void exit_pi_state_list(struct task_struct *curr)
+  * the pi_state against the user space value. If correct, attach to
+  * it.
+  */
+-static int attach_to_pi_state(u32 uval, struct futex_pi_state *pi_state,
++static int attach_to_pi_state(u32 __user *uaddr, u32 uval,
++                            struct futex_pi_state *pi_state,
+                             struct futex_pi_state **ps)
+ {
+       pid_t pid = uval & FUTEX_TID_MASK;
++      u32 uval2;
++      int ret;
+       /*
+        * Userspace might have messed up non-PI and PI futexes [3]
+@@ -990,9 +1035,39 @@ static int attach_to_pi_state(u32 uval, struct futex_pi_state *pi_state,
+       if (unlikely(!pi_state))
+               return -EINVAL;
++      /*
++       * We get here with hb->lock held, and having found a
++       * futex_top_waiter(). This means that futex_lock_pi() of said futex_q
++       * has dropped the hb->lock in between queue_me() and unqueue_me_pi(),
++       * which in turn means that futex_lock_pi() still has a reference on
++       * our pi_state.
++       *
++       * The waiter holding a reference on @pi_state also protects against
++       * the unlocked put_pi_state() in futex_unlock_pi(), futex_lock_pi()
++       * and futex_wait_requeue_pi() as it cannot go to 0 and consequently
++       * free pi_state before we can take a reference ourselves.
++       */
+       WARN_ON(!atomic_read(&pi_state->refcount));
+       /*
++       * Now that we have a pi_state, we can acquire wait_lock
++       * and do the state validation.
++       */
++      raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
++
++      /*
++       * Since {uval, pi_state} is serialized by wait_lock, and our current
++       * uval was read without holding it, it can have changed. Verify it
++       * still is what we expect it to be, otherwise retry the entire
++       * operation.
++       */
++      if (get_futex_value_locked(&uval2, uaddr))
++              goto out_efault;
++
++      if (uval != uval2)
++              goto out_eagain;
++
++      /*
+        * Handle the owner died case:
+        */
+       if (uval & FUTEX_OWNER_DIED) {
+@@ -1007,11 +1082,11 @@ static int attach_to_pi_state(u32 uval, struct futex_pi_state *pi_state,
+                        * is not 0. Inconsistent state. [5]
+                        */
+                       if (pid)
+-                              return -EINVAL;
++                              goto out_einval;
+                       /*
+                        * Take a ref on the state and return success. [4]
+                        */
+-                      goto out_state;
++                      goto out_attach;
+               }
+               /*
+@@ -1023,14 +1098,14 @@ static int attach_to_pi_state(u32 uval, struct futex_pi_state *pi_state,
+                * Take a ref on the state and return success. [6]
+                */
+               if (!pid)
+-                      goto out_state;
++                      goto out_attach;
+       } else {
+               /*
+                * If the owner died bit is not set, then the pi_state
+                * must have an owner. [7]
+                */
+               if (!pi_state->owner)
+-                      return -EINVAL;
++                      goto out_einval;
+       }
+       /*
+@@ -1039,11 +1114,29 @@ static int attach_to_pi_state(u32 uval, struct futex_pi_state *pi_state,
+        * user space TID. [9/10]
+        */
+       if (pid != task_pid_vnr(pi_state->owner))
+-              return -EINVAL;
+-out_state:
+-      atomic_inc(&pi_state->refcount);
++              goto out_einval;
++
++out_attach:
++      get_pi_state(pi_state);
++      raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
+       *ps = pi_state;
+       return 0;
++
++out_einval:
++      ret = -EINVAL;
++      goto out_error;
++
++out_eagain:
++      ret = -EAGAIN;
++      goto out_error;
++
++out_efault:
++      ret = -EFAULT;
++      goto out_error;
++
++out_error:
++      raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
++      return ret;
+ }
+ /*
+@@ -1094,6 +1187,9 @@ static int attach_to_pi_owner(u32 uval, union futex_key *key,
+       /*
+        * No existing pi state. First waiter. [2]
++       *
++       * This creates pi_state, we have hb->lock held, this means nothing can
++       * observe this state, wait_lock is irrelevant.
+        */
+       pi_state = alloc_pi_state();
+@@ -1118,17 +1214,18 @@ static int attach_to_pi_owner(u32 uval, union futex_key *key,
+       return 0;
+ }
+-static int lookup_pi_state(u32 uval, struct futex_hash_bucket *hb,
++static int lookup_pi_state(u32 __user *uaddr, u32 uval,
++                         struct futex_hash_bucket *hb,
+                          union futex_key *key, struct futex_pi_state **ps)
+ {
+-      struct futex_q *match = futex_top_waiter(hb, key);
++      struct futex_q *top_waiter = futex_top_waiter(hb, key);
+       /*
+        * If there is a waiter on that futex, validate it and
+        * attach to the pi_state when the validation succeeds.
+        */
+-      if (match)
+-              return attach_to_pi_state(uval, match->pi_state, ps);
++      if (top_waiter)
++              return attach_to_pi_state(uaddr, uval, top_waiter->pi_state, ps);
+       /*
+        * We are the first waiter - try to look up the owner based on
+@@ -1147,7 +1244,7 @@ static int lock_pi_update_atomic(u32 __user *uaddr, u32 uval, u32 newval)
+       if (unlikely(cmpxchg_futex_value_locked(&curval, uaddr, uval, newval)))
+               return -EFAULT;
+-      /*If user space value changed, let the caller retry */
++      /* If user space value changed, let the caller retry */
+       return curval != uval ? -EAGAIN : 0;
+ }
+@@ -1175,7 +1272,7 @@ static int futex_lock_pi_atomic(u32 __user *uaddr, struct futex_hash_bucket *hb,
+                               struct task_struct *task, int set_waiters)
+ {
+       u32 uval, newval, vpid = task_pid_vnr(task);
+-      struct futex_q *match;
++      struct futex_q *top_waiter;
+       int ret;
  
-       init_sigpending(&p->pending);
-+      p->sigqueue_cache = NULL;
+       /*
+@@ -1201,9 +1298,9 @@ static int futex_lock_pi_atomic(u32 __user *uaddr, struct futex_hash_bucket *hb,
+        * Lookup existing state first. If it exists, try to attach to
+        * its pi_state.
+        */
+-      match = futex_top_waiter(hb, key);
+-      if (match)
+-              return attach_to_pi_state(uval, match->pi_state, ps);
++      top_waiter = futex_top_waiter(hb, key);
++      if (top_waiter)
++              return attach_to_pi_state(uaddr, uval, top_waiter->pi_state, ps);
  
-       p->utime = p->stime = p->gtime = 0;
-       p->utimescaled = p->stimescaled = 0;
-diff --git a/kernel/futex.c b/kernel/futex.c
-index 46cb3a301bc1..6de82b959729 100644
---- a/kernel/futex.c
-+++ b/kernel/futex.c
-@@ -895,7 +895,9 @@ void exit_pi_state_list(struct task_struct *curr)
-                * task still owns the PI-state:
-                */
-               if (head->next != next) {
-+                      raw_spin_unlock_irq(&curr->pi_lock);
-                       spin_unlock(&hb->lock);
-+                      raw_spin_lock_irq(&curr->pi_lock);
-                       continue;
-               }
+       /*
+        * No waiter and user TID is 0. We are here because the
+@@ -1284,50 +1381,45 @@ static void mark_wake_futex(struct wake_q_head *wake_q, struct futex_q *q)
+       wake_q_add(wake_q, p);
+       __unqueue_futex(q);
+       /*
+-       * The waiting task can free the futex_q as soon as
+-       * q->lock_ptr = NULL is written, without taking any locks. A
+-       * memory barrier is required here to prevent the following
+-       * store to lock_ptr from getting ahead of the plist_del.
++       * The waiting task can free the futex_q as soon as q->lock_ptr = NULL
++       * is written, without taking any locks. This is possible in the event
++       * of a spurious wakeup, for example. A memory barrier is required here
++       * to prevent the following store to lock_ptr from getting ahead of the
++       * plist_del in __unqueue_futex().
+        */
+-      smp_wmb();
+-      q->lock_ptr = NULL;
++      smp_store_release(&q->lock_ptr, NULL);
+ }
  
-@@ -1290,6 +1292,7 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
-       struct futex_pi_state *pi_state = this->pi_state;
+-static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
+-                       struct futex_hash_bucket *hb)
++/*
++ * Caller must hold a reference on @pi_state.
++ */
++static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_pi_state *pi_state)
+ {
+-      struct task_struct *new_owner;
+-      struct futex_pi_state *pi_state = this->pi_state;
        u32 uninitialized_var(curval), newval;
++      struct task_struct *new_owner;
++      bool postunlock = false;
        WAKE_Q(wake_q);
+-      bool deboost;
 +      WAKE_Q(wake_sleeper_q);
-       bool deboost;
        int ret = 0;
  
-@@ -1356,7 +1359,8 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
+-      if (!pi_state)
+-              return -EINVAL;
+-
+-      /*
+-       * If current does not own the pi_state then the futex is
+-       * inconsistent and user space fiddled with the futex value.
+-       */
+-      if (pi_state->owner != current)
+-              return -EINVAL;
+-
+-      raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
+       new_owner = rt_mutex_next_owner(&pi_state->pi_mutex);
++      if (WARN_ON_ONCE(!new_owner)) {
++              /*
++               * As per the comment in futex_unlock_pi() this should not happen.
++               *
++               * When this happens, give up our locks and try again, giving
++               * the futex_lock_pi() instance time to complete, either by
++               * waiting on the rtmutex or removing itself from the futex
++               * queue.
++               */
++              ret = -EAGAIN;
++              goto out_unlock;
++      }
+       /*
+-       * It is possible that the next waiter (the one that brought
+-       * this owner to the kernel) timed out and is no longer
+-       * waiting on the lock.
+-       */
+-      if (!new_owner)
+-              new_owner = this->task;
+-
+-      /*
+-       * We pass it to the next owner. The WAITERS bit is always
+-       * kept enabled while there is PI state around. We cleanup the
+-       * owner died bit, because we are the owner.
++       * We pass it to the next owner. The WAITERS bit is always kept
++       * enabled while there is PI state around. We cleanup the owner
++       * died bit, because we are the owner.
+        */
+       newval = FUTEX_WAITERS | task_pid_vnr(new_owner);
+@@ -1336,6 +1428,7 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
+       if (cmpxchg_futex_value_locked(&curval, uaddr, uval, newval)) {
+               ret = -EFAULT;
++
+       } else if (curval != uval) {
+               /*
+                * If a unconditional UNLOCK_PI operation (user space did not
+@@ -1348,10 +1441,14 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
+               else
+                       ret = -EINVAL;
+       }
+-      if (ret) {
+-              raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
+-              return ret;
+-      }
++
++      if (ret)
++              goto out_unlock;
++
++      /*
++       * This is a point of no return; once we modify the uval there is no
++       * going back and subsequent operations must not fail.
++       */
+       raw_spin_lock(&pi_state->owner->pi_lock);
+       WARN_ON(list_empty(&pi_state->list));
+@@ -1364,22 +1461,15 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
+       pi_state->owner = new_owner;
+       raw_spin_unlock(&new_owner->pi_lock);
  
++      postunlock = __rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q,
++                                           &wake_sleeper_q);
++out_unlock:
        raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
  
 -      deboost = rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q);
-+      deboost = rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q,
-+                                      &wake_sleeper_q);
++      if (postunlock)
++              rt_mutex_postunlock(&wake_q, &wake_sleeper_q);
  
-       /*
-        * First unlock HB so the waiter does not spin on it once he got woken
-@@ -1364,8 +1368,9 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
-        * deboost first (and lose our higher priority), then the task might get
-        * scheduled away before the wake up can take place.
-        */
+-      /*
+-       * First unlock HB so the waiter does not spin on it once he got woken
+-       * up. Second wake up the waiter before the priority is adjusted. If we
+-       * deboost first (and lose our higher priority), then the task might get
+-       * scheduled away before the wake up can take place.
+-       */
 -      spin_unlock(&hb->lock);
-+      deboost |= spin_unlock_no_deboost(&hb->lock);
-       wake_up_q(&wake_q);
-+      wake_up_q_sleeper(&wake_sleeper_q);
-       if (deboost)
-               rt_mutex_adjust_prio(current);
+-      wake_up_q(&wake_q);
+-      if (deboost)
+-              rt_mutex_adjust_prio(current);
+-
+-      return 0;
++      return ret;
+ }
+ /*
+@@ -1825,7 +1915,7 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
+                        * If that call succeeds then we have pi_state and an
+                        * initial refcount on it.
+                        */
+-                      ret = lookup_pi_state(ret, hb2, &key2, &pi_state);
++                      ret = lookup_pi_state(uaddr2, ret, hb2, &key2, &pi_state);
+               }
  
-@@ -1915,6 +1920,16 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
+               switch (ret) {
+@@ -1908,7 +1998,7 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
+                        * refcount on the pi_state and store the pointer in
+                        * the futex_q object of the waiter.
+                        */
+-                      atomic_inc(&pi_state->refcount);
++                      get_pi_state(pi_state);
+                       this->pi_state = pi_state;
+                       ret = rt_mutex_start_proxy_lock(&pi_state->pi_mutex,
+                                                       this->rt_waiter,
+@@ -1925,6 +2015,16 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
                                requeue_pi_wake_futex(this, &key2, hb2);
                                drop_count++;
                                continue;
@@ -12839,16 +12797,483 @@ index 46cb3a301bc1..6de82b959729 100644
                        } else if (ret) {
                                /*
                                 * rt_mutex_start_proxy_lock() detected a
-@@ -2805,7 +2820,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
+@@ -2008,20 +2108,7 @@ queue_unlock(struct futex_hash_bucket *hb)
+       hb_waiters_dec(hb);
+ }
+-/**
+- * queue_me() - Enqueue the futex_q on the futex_hash_bucket
+- * @q:        The futex_q to enqueue
+- * @hb:       The destination hash bucket
+- *
+- * The hb->lock must be held by the caller, and is released here. A call to
+- * queue_me() is typically paired with exactly one call to unqueue_me().  The
+- * exceptions involve the PI related operations, which may use unqueue_me_pi()
+- * or nothing if the unqueue is done as part of the wake process and the unqueue
+- * state is implicit in the state of woken task (see futex_wait_requeue_pi() for
+- * an example).
+- */
+-static inline void queue_me(struct futex_q *q, struct futex_hash_bucket *hb)
+-      __releases(&hb->lock)
++static inline void __queue_me(struct futex_q *q, struct futex_hash_bucket *hb)
+ {
+       int prio;
+@@ -2038,6 +2125,24 @@ static inline void queue_me(struct futex_q *q, struct futex_hash_bucket *hb)
+       plist_node_init(&q->list, prio);
+       plist_add(&q->list, &hb->chain);
+       q->task = current;
++}
++
++/**
++ * queue_me() - Enqueue the futex_q on the futex_hash_bucket
++ * @q:        The futex_q to enqueue
++ * @hb:       The destination hash bucket
++ *
++ * The hb->lock must be held by the caller, and is released here. A call to
++ * queue_me() is typically paired with exactly one call to unqueue_me().  The
++ * exceptions involve the PI related operations, which may use unqueue_me_pi()
++ * or nothing if the unqueue is done as part of the wake process and the unqueue
++ * state is implicit in the state of woken task (see futex_wait_requeue_pi() for
++ * an example).
++ */
++static inline void queue_me(struct futex_q *q, struct futex_hash_bucket *hb)
++      __releases(&hb->lock)
++{
++      __queue_me(q, hb);
+       spin_unlock(&hb->lock);
+ }
+@@ -2124,10 +2229,13 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
+ {
+       u32 newtid = task_pid_vnr(newowner) | FUTEX_WAITERS;
+       struct futex_pi_state *pi_state = q->pi_state;
+-      struct task_struct *oldowner = pi_state->owner;
+       u32 uval, uninitialized_var(curval), newval;
++      struct task_struct *oldowner;
+       int ret;
++      raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
++
++      oldowner = pi_state->owner;
+       /* Owner died? */
+       if (!pi_state->owner)
+               newtid |= FUTEX_OWNER_DIED;
+@@ -2135,7 +2243,8 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
+       /*
+        * We are here either because we stole the rtmutex from the
+        * previous highest priority waiter or we are the highest priority
+-       * waiter but failed to get the rtmutex the first time.
++       * waiter but have failed to get the rtmutex the first time.
++       *
+        * We have to replace the newowner TID in the user space variable.
+        * This must be atomic as we have to preserve the owner died bit here.
+        *
+@@ -2143,17 +2252,16 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
+        * because we can fault here. Imagine swapped out pages or a fork
+        * that marked all the anonymous memory readonly for cow.
+        *
+-       * Modifying pi_state _before_ the user space value would
+-       * leave the pi_state in an inconsistent state when we fault
+-       * here, because we need to drop the hash bucket lock to
+-       * handle the fault. This might be observed in the PID check
+-       * in lookup_pi_state.
++       * Modifying pi_state _before_ the user space value would leave the
++       * pi_state in an inconsistent state when we fault here, because we
++       * need to drop the locks to handle the fault. This might be observed
++       * in the PID check in lookup_pi_state.
+        */
+ retry:
+       if (get_futex_value_locked(&uval, uaddr))
+               goto handle_fault;
+-      while (1) {
++      for (;;) {
+               newval = (uval & FUTEX_OWNER_DIED) | newtid;
+               if (cmpxchg_futex_value_locked(&curval, uaddr, uval, newval))
+@@ -2168,47 +2276,60 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct futex_q *q,
+        * itself.
+        */
+       if (pi_state->owner != NULL) {
+-              raw_spin_lock_irq(&pi_state->owner->pi_lock);
++              raw_spin_lock(&pi_state->owner->pi_lock);
+               WARN_ON(list_empty(&pi_state->list));
+               list_del_init(&pi_state->list);
+-              raw_spin_unlock_irq(&pi_state->owner->pi_lock);
++              raw_spin_unlock(&pi_state->owner->pi_lock);
+       }
+       pi_state->owner = newowner;
+-      raw_spin_lock_irq(&newowner->pi_lock);
++      raw_spin_lock(&newowner->pi_lock);
+       WARN_ON(!list_empty(&pi_state->list));
+       list_add(&pi_state->list, &newowner->pi_state_list);
+-      raw_spin_unlock_irq(&newowner->pi_lock);
++      raw_spin_unlock(&newowner->pi_lock);
++      raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
++
+       return 0;
+       /*
+-       * To handle the page fault we need to drop the hash bucket
+-       * lock here. That gives the other task (either the highest priority
+-       * waiter itself or the task which stole the rtmutex) the
+-       * chance to try the fixup of the pi_state. So once we are
+-       * back from handling the fault we need to check the pi_state
+-       * after reacquiring the hash bucket lock and before trying to
+-       * do another fixup. When the fixup has been done already we
+-       * simply return.
++       * To handle the page fault we need to drop the locks here. That gives
++       * the other task (either the highest priority waiter itself or the
++       * task which stole the rtmutex) the chance to try the fixup of the
++       * pi_state. So once we are back from handling the fault we need to
++       * check the pi_state after reacquiring the locks and before trying to
++       * do another fixup. When the fixup has been done already we simply
++       * return.
++       *
++       * Note: we hold both hb->lock and pi_mutex->wait_lock. We can safely
++       * drop hb->lock since the caller owns the hb -> futex_q relation.
++       * Dropping the pi_mutex->wait_lock requires the state revalidate.
+        */
+ handle_fault:
++      raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
+       spin_unlock(q->lock_ptr);
+       ret = fault_in_user_writeable(uaddr);
+       spin_lock(q->lock_ptr);
++      raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
+       /*
+        * Check if someone else fixed it for us:
+        */
+-      if (pi_state->owner != oldowner)
+-              return 0;
++      if (pi_state->owner != oldowner) {
++              ret = 0;
++              goto out_unlock;
++      }
+       if (ret)
+-              return ret;
++              goto out_unlock;
+       goto retry;
++
++out_unlock:
++      raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
++      return ret;
+ }
+ static long futex_wait_restart(struct restart_block *restart);
+@@ -2230,13 +2351,16 @@ static long futex_wait_restart(struct restart_block *restart);
+  */
+ static int fixup_owner(u32 __user *uaddr, struct futex_q *q, int locked)
+ {
+-      struct task_struct *owner;
+       int ret = 0;
+       if (locked) {
+               /*
+                * Got the lock. We might not be the anticipated owner if we
+                * did a lock-steal - fix up the PI-state in that case:
++               *
++               * We can safely read pi_state->owner without holding wait_lock
++               * because we now own the rt_mutex, only the owner will attempt
++               * to change it.
+                */
+               if (q->pi_state->owner != current)
+                       ret = fixup_pi_state_owner(uaddr, q, current);
+@@ -2244,43 +2368,15 @@ static int fixup_owner(u32 __user *uaddr, struct futex_q *q, int locked)
+       }
+       /*
+-       * Catch the rare case, where the lock was released when we were on the
+-       * way back before we locked the hash bucket.
+-       */
+-      if (q->pi_state->owner == current) {
+-              /*
+-               * Try to get the rt_mutex now. This might fail as some other
+-               * task acquired the rt_mutex after we removed ourself from the
+-               * rt_mutex waiters list.
+-               */
+-              if (rt_mutex_trylock(&q->pi_state->pi_mutex)) {
+-                      locked = 1;
+-                      goto out;
+-              }
+-
+-              /*
+-               * pi_state is incorrect, some other task did a lock steal and
+-               * we returned due to timeout or signal without taking the
+-               * rt_mutex. Too late.
+-               */
+-              raw_spin_lock_irq(&q->pi_state->pi_mutex.wait_lock);
+-              owner = rt_mutex_owner(&q->pi_state->pi_mutex);
+-              if (!owner)
+-                      owner = rt_mutex_next_owner(&q->pi_state->pi_mutex);
+-              raw_spin_unlock_irq(&q->pi_state->pi_mutex.wait_lock);
+-              ret = fixup_pi_state_owner(uaddr, q, owner);
+-              goto out;
+-      }
+-
+-      /*
+        * Paranoia check. If we did not take the lock, then we should not be
+        * the owner of the rt_mutex.
+        */
+-      if (rt_mutex_owner(&q->pi_state->pi_mutex) == current)
++      if (rt_mutex_owner(&q->pi_state->pi_mutex) == current) {
+               printk(KERN_ERR "fixup_owner: ret = %d pi-mutex: %p "
+                               "pi-state %p\n", ret,
+                               q->pi_state->pi_mutex.owner,
+                               q->pi_state->owner);
++      }
+ out:
+       return ret ? ret : locked;
+@@ -2504,6 +2600,8 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags,
+                        ktime_t *time, int trylock)
+ {
+       struct hrtimer_sleeper timeout, *to = NULL;
++      struct futex_pi_state *pi_state = NULL;
++      struct rt_mutex_waiter rt_waiter;
+       struct futex_hash_bucket *hb;
+       struct futex_q q = futex_q_init;
+       int res, ret;
+@@ -2556,25 +2654,77 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags,
+               }
+       }
++      WARN_ON(!q.pi_state);
++
+       /*
+        * Only actually queue now that the atomic ops are done:
+        */
+-      queue_me(&q, hb);
++      __queue_me(&q, hb);
+-      WARN_ON(!q.pi_state);
+-      /*
+-       * Block on the PI mutex:
+-       */
+-      if (!trylock) {
+-              ret = rt_mutex_timed_futex_lock(&q.pi_state->pi_mutex, to);
+-      } else {
+-              ret = rt_mutex_trylock(&q.pi_state->pi_mutex);
++      if (trylock) {
++              ret = rt_mutex_futex_trylock(&q.pi_state->pi_mutex);
+               /* Fixup the trylock return value: */
+               ret = ret ? 0 : -EWOULDBLOCK;
++              goto no_block;
++      }
++
++      rt_mutex_init_waiter(&rt_waiter, false);
++
++      /*
++       * On PREEMPT_RT_FULL, when hb->lock becomes an rt_mutex, we must not
++       * hold it while doing rt_mutex_start_proxy(), because then it will
++       * include hb->lock in the blocking chain, even through we'll not in
++       * fact hold it while blocking. This will lead it to report -EDEADLK
++       * and BUG when futex_unlock_pi() interleaves with this.
++       *
++       * Therefore acquire wait_lock while holding hb->lock, but drop the
++       * latter before calling rt_mutex_start_proxy_lock(). This still fully
++       * serializes against futex_unlock_pi() as that does the exact same
++       * lock handoff sequence.
++       */
++      raw_spin_lock_irq(&q.pi_state->pi_mutex.wait_lock);
++      /*
++       * the migrate_disable() here disables migration in the in_atomic() fast
++       * path which is enabled again in the following spin_unlock(). We have
++       * one migrate_disable() pending in the slow-path which is reversed
++       * after the raw_spin_unlock_irq() where we leave the atomic context.
++       */
++      migrate_disable();
++
++      spin_unlock(q.lock_ptr);
++      ret = __rt_mutex_start_proxy_lock(&q.pi_state->pi_mutex, &rt_waiter, current);
++      raw_spin_unlock_irq(&q.pi_state->pi_mutex.wait_lock);
++      migrate_enable();
++
++      if (ret) {
++              if (ret == 1)
++                      ret = 0;
++
++              spin_lock(q.lock_ptr);
++              goto no_block;
+       }
++
++      if (unlikely(to))
++              hrtimer_start_expires(&to->timer, HRTIMER_MODE_ABS);
++
++      ret = rt_mutex_wait_proxy_lock(&q.pi_state->pi_mutex, to, &rt_waiter);
++
+       spin_lock(q.lock_ptr);
+       /*
++       * If we failed to acquire the lock (signal/timeout), we must
++       * first acquire the hb->lock before removing the lock from the
++       * rt_mutex waitqueue, such that we can keep the hb and rt_mutex
++       * wait lists consistent.
++       *
++       * In particular; it is important that futex_unlock_pi() can not
++       * observe this inconsistency.
++       */
++      if (ret && !rt_mutex_cleanup_proxy_lock(&q.pi_state->pi_mutex, &rt_waiter))
++              ret = 0;
++
++no_block:
++      /*
+        * Fixup the pi_state owner and possibly acquire the lock if we
+        * haven't already.
+        */
+@@ -2590,12 +2740,19 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags,
+        * If fixup_owner() faulted and was unable to handle the fault, unlock
+        * it and return the fault to userspace.
+        */
+-      if (ret && (rt_mutex_owner(&q.pi_state->pi_mutex) == current))
+-              rt_mutex_unlock(&q.pi_state->pi_mutex);
++      if (ret && (rt_mutex_owner(&q.pi_state->pi_mutex) == current)) {
++              pi_state = q.pi_state;
++              get_pi_state(pi_state);
++      }
+       /* Unqueue and drop the lock */
+       unqueue_me_pi(&q);
++      if (pi_state) {
++              rt_mutex_futex_unlock(&pi_state->pi_mutex);
++              put_pi_state(pi_state);
++      }
++
+       goto out_put_key;
+ out_unlock_put_key:
+@@ -2604,8 +2761,10 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags,
+ out_put_key:
+       put_futex_key(&q.key);
+ out:
+-      if (to)
++      if (to) {
++              hrtimer_cancel(&to->timer);
+               destroy_hrtimer_on_stack(&to->timer);
++      }
+       return ret != -EINTR ? ret : -ERESTARTNOINTR;
+ uaddr_faulted:
+@@ -2632,7 +2791,7 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
+       u32 uninitialized_var(curval), uval, vpid = task_pid_vnr(current);
+       union futex_key key = FUTEX_KEY_INIT;
+       struct futex_hash_bucket *hb;
+-      struct futex_q *match;
++      struct futex_q *top_waiter;
+       int ret;
+ retry:
+@@ -2656,12 +2815,48 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
+        * all and we at least want to know if user space fiddled
+        * with the futex value instead of blindly unlocking.
+        */
+-      match = futex_top_waiter(hb, &key);
+-      if (match) {
+-              ret = wake_futex_pi(uaddr, uval, match, hb);
++      top_waiter = futex_top_waiter(hb, &key);
++      if (top_waiter) {
++              struct futex_pi_state *pi_state = top_waiter->pi_state;
++
++              ret = -EINVAL;
++              if (!pi_state)
++                      goto out_unlock;
++
++              /*
++               * If current does not own the pi_state then the futex is
++               * inconsistent and user space fiddled with the futex value.
++               */
++              if (pi_state->owner != current)
++                      goto out_unlock;
++
++              get_pi_state(pi_state);
++              /*
++               * By taking wait_lock while still holding hb->lock, we ensure
++               * there is no point where we hold neither; and therefore
++               * wake_futex_pi() must observe a state consistent with what we
++               * observed.
++               */
++              raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
++              /*
++               * Magic trickery for now to make the RT migrate disable
++               * logic happy. The following spin_unlock() happens with
++               * interrupts disabled so the internal migrate_enable()
++               * won't undo the migrate_disable() which was issued when
++               * locking hb->lock.
++               */
++              migrate_disable();
++              spin_unlock(&hb->lock);
++
++              /* Drops pi_state->pi_mutex.wait_lock */
++              ret = wake_futex_pi(uaddr, uval, pi_state);
++
++              migrate_enable();
++
++              put_pi_state(pi_state);
++
+               /*
+-               * In case of success wake_futex_pi dropped the hash
+-               * bucket lock.
++               * Success, we're done! No tricky corner cases.
+                */
+               if (!ret)
+                       goto out_putkey;
+@@ -2676,7 +2871,6 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
+                * setting the FUTEX_WAITERS bit. Try again.
+                */
+               if (ret == -EAGAIN) {
+-                      spin_unlock(&hb->lock);
+                       put_futex_key(&key);
+                       goto retry;
+               }
+@@ -2684,7 +2878,7 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
+                * wake_futex_pi has detected invalid state. Tell user
+                * space.
+                */
+-              goto out_unlock;
++              goto out_putkey;
+       }
+       /*
+@@ -2694,8 +2888,10 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
+        * preserve the WAITERS bit not the OWNER_DIED one. We are the
+        * owner.
+        */
+-      if (cmpxchg_futex_value_locked(&curval, uaddr, uval, 0))
++      if (cmpxchg_futex_value_locked(&curval, uaddr, uval, 0)) {
++              spin_unlock(&hb->lock);
+               goto pi_faulted;
++      }
+       /*
+        * If uval has changed, let user space handle it.
+@@ -2709,7 +2905,6 @@ static int futex_unlock_pi(u32 __user *uaddr, unsigned int flags)
+       return ret;
+ pi_faulted:
+-      spin_unlock(&hb->lock);
+       put_futex_key(&key);
+       ret = fault_in_user_writeable(uaddr);
+@@ -2813,8 +3008,9 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
+                                u32 __user *uaddr2)
+ {
        struct hrtimer_sleeper timeout, *to = NULL;
++      struct futex_pi_state *pi_state = NULL;
        struct rt_mutex_waiter rt_waiter;
-       struct rt_mutex *pi_mutex = NULL;
 -      struct futex_hash_bucket *hb;
 +      struct futex_hash_bucket *hb, *hb2;
        union futex_key key2 = FUTEX_KEY_INIT;
        struct futex_q q = futex_q_init;
        int res, ret;
-@@ -2830,10 +2845,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
+@@ -2839,10 +3035,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
         * The waiter is allocated on our stack, manipulated by the requeue
         * code while we sleep on uaddr.
         */
@@ -12860,7 +13285,7 @@ index 46cb3a301bc1..6de82b959729 100644
  
        ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, VERIFY_WRITE);
        if (unlikely(ret != 0))
-@@ -2864,20 +2876,55 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
+@@ -2873,20 +3066,55 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
        /* Queue the futex_q, drop the hb lock, wait for wakeup. */
        futex_wait_queue_me(hb, &q, to);
  
@@ -12927,7 +13352,7 @@ index 46cb3a301bc1..6de82b959729 100644
  
        /* Check if the requeue code acquired the second futex for us. */
        if (!q.rt_waiter) {
-@@ -2886,14 +2933,15 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
+@@ -2895,16 +3123,19 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
                 * did a lock-steal - fix up the PI-state in that case.
                 */
                if (q.pi_state && (q.pi_state->owner != current)) {
@@ -12935,6 +13360,12 @@ index 46cb3a301bc1..6de82b959729 100644
 +                      spin_lock(&hb2->lock);
 +                      BUG_ON(&hb2->lock != q.lock_ptr);
                        ret = fixup_pi_state_owner(uaddr2, &q, current);
+-                      if (ret && rt_mutex_owner(&q.pi_state->pi_mutex) == current)
+-                              rt_mutex_unlock(&q.pi_state->pi_mutex);
++                      if (ret && rt_mutex_owner(&q.pi_state->pi_mutex) == current) {
++                              pi_state = q.pi_state;
++                              get_pi_state(pi_state);
++                      }
                        /*
                         * Drop the reference to the pi state which
                         * the requeue_pi() code acquired for us.
@@ -12944,17 +13375,48 @@ index 46cb3a301bc1..6de82b959729 100644
 +                      spin_unlock(&hb2->lock);
                }
        } else {
-               /*
-@@ -2906,7 +2954,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
-               ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter);
-               debug_rt_mutex_free_waiter(&rt_waiter);
+               struct rt_mutex *pi_mutex;
+@@ -2916,10 +3147,14 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
+                */
+               WARN_ON(!q.pi_state);
+               pi_mutex = &q.pi_state->pi_mutex;
+-              ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter);
+-              debug_rt_mutex_free_waiter(&rt_waiter);
++              ret = rt_mutex_wait_proxy_lock(pi_mutex, to, &rt_waiter);
  
 -              spin_lock(q.lock_ptr);
 +              spin_lock(&hb2->lock);
 +              BUG_ON(&hb2->lock != q.lock_ptr);
++              if (ret && !rt_mutex_cleanup_proxy_lock(pi_mutex, &rt_waiter))
++                      ret = 0;
++
++              debug_rt_mutex_free_waiter(&rt_waiter);
                /*
                 * Fixup the pi_state owner and possibly acquire the lock if we
                 * haven't already.
+@@ -2937,13 +3172,20 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
+                * the fault, unlock the rt_mutex and return the fault to
+                * userspace.
+                */
+-              if (ret && rt_mutex_owner(pi_mutex) == current)
+-                      rt_mutex_unlock(pi_mutex);
++              if (ret && rt_mutex_owner(&q.pi_state->pi_mutex) == current) {
++                      pi_state = q.pi_state;
++                      get_pi_state(pi_state);
++              }
+               /* Unqueue and drop the lock. */
+               unqueue_me_pi(&q);
+       }
++      if (pi_state) {
++              rt_mutex_futex_unlock(&pi_state->pi_mutex);
++              put_pi_state(pi_state);
++      }
++
+       if (ret == -EINTR) {
+               /*
+                * We've already been requeued, but cannot restart by calling
 diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c
 index d3f24905852c..f87aa8fdcc51 100644
 --- a/kernel/irq/handle.c
@@ -12978,7 +13440,7 @@ index d3f24905852c..f87aa8fdcc51 100644
        if (!noirqdebug)
                note_interrupt(desc, retval);
 diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
-index 9530fcd27704..fadf8f848299 100644
+index ea41820ab12e..5994867526f3 100644
 --- a/kernel/irq/manage.c
 +++ b/kernel/irq/manage.c
 @@ -22,6 +22,7 @@
@@ -13101,7 +13563,7 @@ index 9530fcd27704..fadf8f848299 100644
                wake_threads_waitq(desc);
        }
  
-@@ -1336,6 +1389,9 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
+@@ -1338,6 +1391,9 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
                        irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
                }
  
@@ -13111,7 +13573,7 @@ index 9530fcd27704..fadf8f848299 100644
                /* Set default affinity mask once everything is setup */
                setup_affinity(desc, mask);
  
-@@ -2061,7 +2117,7 @@ EXPORT_SYMBOL_GPL(irq_get_irqchip_state);
+@@ -2063,7 +2119,7 @@ EXPORT_SYMBOL_GPL(irq_get_irqchip_state);
   *    This call sets the internal irqchip state of an interrupt,
   *    depending on the value of @which.
   *
@@ -13339,7 +13801,7 @@ index ee1bc1bb8feb..ddef07958840 100644
  };
  
 diff --git a/kernel/locking/Makefile b/kernel/locking/Makefile
-index 31322a4275cd..c6bba9299d8b 100644
+index 6f88e352cd4f..6ff9e8011dd0 100644
 --- a/kernel/locking/Makefile
 +++ b/kernel/locking/Makefile
 @@ -2,7 +2,7 @@
@@ -13358,12 +13820,12 @@ index 31322a4275cd..c6bba9299d8b 100644
 +ifneq ($(CONFIG_PREEMPT_RT_FULL),y)
 +obj-y += mutex.o
  obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
-+obj-y += rwsem.o
 +endif
++obj-y += rwsem.o
  obj-$(CONFIG_LOCKDEP) += lockdep.o
  ifeq ($(CONFIG_PROC_FS),y)
  obj-$(CONFIG_LOCKDEP) += lockdep_proc.o
-@@ -25,7 +29,10 @@ obj-$(CONFIG_RT_MUTEXES) += rtmutex.o
+@@ -24,7 +28,10 @@ obj-$(CONFIG_RT_MUTEXES) += rtmutex.o
  obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o
  obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
  obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
@@ -13371,186 +13833,90 @@ index 31322a4275cd..c6bba9299d8b 100644
  obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
  obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o
 +endif
-+obj-$(CONFIG_PREEMPT_RT_FULL) += rt.o
++obj-$(CONFIG_PREEMPT_RT_FULL) += rt.o rwsem-rt.o
  obj-$(CONFIG_QUEUED_RWLOCKS) += qrwlock.o
  obj-$(CONFIG_LOCK_TORTURE_TEST) += locktorture.o
-diff --git a/kernel/locking/lglock.c b/kernel/locking/lglock.c
-index 951cfcd10b4a..57e0ea72c28a 100644
---- a/kernel/locking/lglock.c
-+++ b/kernel/locking/lglock.c
-@@ -4,6 +4,15 @@
- #include <linux/cpu.h>
- #include <linux/string.h>
+diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
+index 6599c7f3071d..79f8e00e802e 100644
+--- a/kernel/locking/lockdep.c
++++ b/kernel/locking/lockdep.c
+@@ -658,6 +658,7 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int subclass)
+       struct lockdep_subclass_key *key;
+       struct hlist_head *hash_head;
+       struct lock_class *class;
++      bool is_static = false;
  
-+#ifndef CONFIG_PREEMPT_RT_FULL
-+# define lg_lock_ptr          arch_spinlock_t
-+# define lg_do_lock(l)                arch_spin_lock(l)
-+# define lg_do_unlock(l)      arch_spin_unlock(l)
-+#else
-+# define lg_lock_ptr          struct rt_mutex
-+# define lg_do_lock(l)                __rt_spin_lock__no_mg(l)
-+# define lg_do_unlock(l)      __rt_spin_unlock(l)
-+#endif
- /*
-  * Note there is no uninit, so lglocks cannot be defined in
-  * modules (but it's fine to use them from there)
-@@ -12,51 +21,60 @@
+       if (unlikely(subclass >= MAX_LOCKDEP_SUBCLASSES)) {
+               debug_locks_off();
+@@ -671,10 +672,23 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int subclass)
  
- void lg_lock_init(struct lglock *lg, char *name)
- {
-+#ifdef CONFIG_PREEMPT_RT_FULL
-+      int i;
-+
-+      for_each_possible_cpu(i) {
-+              struct rt_mutex *lock = per_cpu_ptr(lg->lock, i);
-+
-+              rt_mutex_init(lock);
+       /*
+        * Static locks do not have their class-keys yet - for them the key
+-       * is the lock object itself:
++       * is the lock object itself. If the lock is in the per cpu area,
++       * the canonical address of the lock (per cpu offset removed) is
++       * used.
+        */
+-      if (unlikely(!lock->key))
+-              lock->key = (void *)lock;
++      if (unlikely(!lock->key)) {
++              unsigned long can_addr, addr = (unsigned long)lock;
++
++              if (__is_kernel_percpu_address(addr, &can_addr))
++                      lock->key = (void *)can_addr;
++              else if (__is_module_percpu_address(addr, &can_addr))
++                      lock->key = (void *)can_addr;
++              else if (static_obj(lock))
++                      lock->key = (void *)lock;
++              else
++                      return ERR_PTR(-EINVAL);
++              is_static = true;
 +      }
-+#endif
-       LOCKDEP_INIT_MAP(&lg->lock_dep_map, name, &lg->lock_key, 0);
- }
- EXPORT_SYMBOL(lg_lock_init);
- void lg_local_lock(struct lglock *lg)
- {
--      arch_spinlock_t *lock;
-+      lg_lock_ptr *lock;
--      preempt_disable();
-+      migrate_disable();
-       lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
-       lock = this_cpu_ptr(lg->lock);
--      arch_spin_lock(lock);
-+      lg_do_lock(lock);
- }
- EXPORT_SYMBOL(lg_local_lock);
- void lg_local_unlock(struct lglock *lg)
- {
--      arch_spinlock_t *lock;
-+      lg_lock_ptr *lock;
-       lock_release(&lg->lock_dep_map, 1, _RET_IP_);
-       lock = this_cpu_ptr(lg->lock);
--      arch_spin_unlock(lock);
--      preempt_enable();
-+      lg_do_unlock(lock);
-+      migrate_enable();
- }
- EXPORT_SYMBOL(lg_local_unlock);
- void lg_local_lock_cpu(struct lglock *lg, int cpu)
- {
--      arch_spinlock_t *lock;
-+      lg_lock_ptr *lock;
--      preempt_disable();
-+      preempt_disable_nort();
-       lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
-       lock = per_cpu_ptr(lg->lock, cpu);
--      arch_spin_lock(lock);
-+      lg_do_lock(lock);
- }
- EXPORT_SYMBOL(lg_local_lock_cpu);
  
- void lg_local_unlock_cpu(struct lglock *lg, int cpu)
- {
--      arch_spinlock_t *lock;
-+      lg_lock_ptr *lock;
+       /*
+        * NOTE: the class-key must be unique. For dynamic locks, a static
+@@ -706,7 +720,7 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int subclass)
+               }
+       }
  
-       lock_release(&lg->lock_dep_map, 1, _RET_IP_);
-       lock = per_cpu_ptr(lg->lock, cpu);
--      arch_spin_unlock(lock);
--      preempt_enable();
-+      lg_do_unlock(lock);
-+      preempt_enable_nort();
+-      return NULL;
++      return is_static || static_obj(lock->key) ? NULL : ERR_PTR(-EINVAL);
  }
- EXPORT_SYMBOL(lg_local_unlock_cpu);
  
-@@ -68,30 +86,30 @@ void lg_double_lock(struct lglock *lg, int cpu1, int cpu2)
-       if (cpu2 < cpu1)
-               swap(cpu1, cpu2);
+ /*
+@@ -724,19 +738,18 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
+       DEBUG_LOCKS_WARN_ON(!irqs_disabled());
  
--      preempt_disable();
-+      preempt_disable_nort();
-       lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
--      arch_spin_lock(per_cpu_ptr(lg->lock, cpu1));
--      arch_spin_lock(per_cpu_ptr(lg->lock, cpu2));
-+      lg_do_lock(per_cpu_ptr(lg->lock, cpu1));
-+      lg_do_lock(per_cpu_ptr(lg->lock, cpu2));
- }
+       class = look_up_lock_class(lock, subclass);
+-      if (likely(class))
++      if (likely(!IS_ERR_OR_NULL(class)))
+               goto out_set_class_cache;
  
- void lg_double_unlock(struct lglock *lg, int cpu1, int cpu2)
- {
-       lock_release(&lg->lock_dep_map, 1, _RET_IP_);
--      arch_spin_unlock(per_cpu_ptr(lg->lock, cpu1));
--      arch_spin_unlock(per_cpu_ptr(lg->lock, cpu2));
--      preempt_enable();
-+      lg_do_unlock(per_cpu_ptr(lg->lock, cpu1));
-+      lg_do_unlock(per_cpu_ptr(lg->lock, cpu2));
-+      preempt_enable_nort();
- }
+       /*
+        * Debug-check: all keys must be persistent!
+-       */
+-      if (!static_obj(lock->key)) {
++       */
++      if (IS_ERR(class)) {
+               debug_locks_off();
+               printk("INFO: trying to register non-static key.\n");
+               printk("the code is fine but needs lockdep annotation.\n");
+               printk("turning off the locking correctness validator.\n");
+               dump_stack();
+-
+               return NULL;
+       }
  
- void lg_global_lock(struct lglock *lg)
- {
-       int i;
+@@ -3417,7 +3430,7 @@ static int match_held_lock(struct held_lock *hlock, struct lockdep_map *lock)
+                * Clearly if the lock hasn't been acquired _ever_, we're not
+                * holding it either, so report failure.
+                */
+-              if (!class)
++              if (IS_ERR_OR_NULL(class))
+                       return 0;
  
--      preempt_disable();
-+      preempt_disable_nort();
-       lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
-       for_each_possible_cpu(i) {
--              arch_spinlock_t *lock;
-+              lg_lock_ptr *lock;
-               lock = per_cpu_ptr(lg->lock, i);
--              arch_spin_lock(lock);
-+              lg_do_lock(lock);
-       }
- }
- EXPORT_SYMBOL(lg_global_lock);
-@@ -102,10 +120,35 @@ void lg_global_unlock(struct lglock *lg)
-       lock_release(&lg->lock_dep_map, 1, _RET_IP_);
-       for_each_possible_cpu(i) {
--              arch_spinlock_t *lock;
-+              lg_lock_ptr *lock;
-               lock = per_cpu_ptr(lg->lock, i);
--              arch_spin_unlock(lock);
-+              lg_do_unlock(lock);
-       }
--      preempt_enable();
-+      preempt_enable_nort();
- }
- EXPORT_SYMBOL(lg_global_unlock);
-+
-+#ifdef CONFIG_PREEMPT_RT_FULL
-+/*
-+ * HACK: If you use this, you get to keep the pieces.
-+ * Used in queue_stop_cpus_work() when stop machinery
-+ * is called from inactive CPU, so we can't schedule.
-+ */
-+# define lg_do_trylock_relax(l)                       \
-+      do {                                    \
-+              while (!__rt_spin_trylock(l))   \
-+                      cpu_relax();            \
-+      } while (0)
-+
-+void lg_global_trylock_relax(struct lglock *lg)
-+{
-+      int i;
-+
-+      lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
-+      for_each_possible_cpu(i) {
-+              lg_lock_ptr *lock;
-+              lock = per_cpu_ptr(lg->lock, i);
-+              lg_do_trylock_relax(lock);
-+      }
-+}
-+#endif
-diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
-index 589d763a49b3..4b48c4bfb60c 100644
---- a/kernel/locking/lockdep.c
-+++ b/kernel/locking/lockdep.c
-@@ -3686,6 +3686,7 @@ static void check_flags(unsigned long flags)
+               /*
+@@ -3696,6 +3709,7 @@ static void check_flags(unsigned long flags)
                }
        }
  
@@ -13558,7 +13924,7 @@ index 589d763a49b3..4b48c4bfb60c 100644
        /*
         * We dont accurately track softirq state in e.g.
         * hardirq contexts (such as on 4KSTACKS), so only
-@@ -3700,6 +3701,7 @@ static void check_flags(unsigned long flags)
+@@ -3710,6 +3724,7 @@ static void check_flags(unsigned long flags)
                        DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled);
                }
        }
@@ -13566,8 +13932,17 @@ index 589d763a49b3..4b48c4bfb60c 100644
  
        if (!debug_locks)
                print_irqtrace_events(current);
+@@ -4166,7 +4181,7 @@ void lockdep_reset_lock(struct lockdep_map *lock)
+                * If the class exists we look it up and zap it:
+                */
+               class = look_up_lock_class(lock, j);
+-              if (class)
++              if (!IS_ERR_OR_NULL(class))
+                       zap_class(class);
+       }
+       /*
 diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
-index f8c5af52a131..788068773e61 100644
+index d3de04b12f8c..0f49abeae337 100644
 --- a/kernel/locking/locktorture.c
 +++ b/kernel/locking/locktorture.c
 @@ -26,7 +26,6 @@
@@ -13578,12 +13953,43 @@ index f8c5af52a131..788068773e61 100644
  #include <linux/mutex.h>
  #include <linux/rwsem.h>
  #include <linux/smp.h>
+diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c
+index ce182599cf2e..2ad3a1e8344c 100644
+--- a/kernel/locking/percpu-rwsem.c
++++ b/kernel/locking/percpu-rwsem.c
+@@ -18,7 +18,7 @@ int __percpu_init_rwsem(struct percpu_rw_semaphore *sem,
+       /* ->rw_sem represents the whole percpu_rw_semaphore for lockdep */
+       rcu_sync_init(&sem->rss, RCU_SCHED_SYNC);
+       __init_rwsem(&sem->rw_sem, name, rwsem_key);
+-      init_waitqueue_head(&sem->writer);
++      init_swait_queue_head(&sem->writer);
+       sem->readers_block = 0;
+       return 0;
+ }
+@@ -103,7 +103,7 @@ void __percpu_up_read(struct percpu_rw_semaphore *sem)
+       __this_cpu_dec(*sem->read_count);
+       /* Prod writer to recheck readers_active */
+-      wake_up(&sem->writer);
++      swake_up(&sem->writer);
+ }
+ EXPORT_SYMBOL_GPL(__percpu_up_read);
+@@ -160,7 +160,7 @@ void percpu_down_write(struct percpu_rw_semaphore *sem)
+        */
+       /* Wait for all now active readers to complete. */
+-      wait_event(sem->writer, readers_active_check(sem));
++      swait_event(sem->writer, readers_active_check(sem));
+ }
+ EXPORT_SYMBOL_GPL(percpu_down_write);
 diff --git a/kernel/locking/rt.c b/kernel/locking/rt.c
 new file mode 100644
-index 000000000000..665754c00e1e
+index 000000000000..6284e3b15091
 --- /dev/null
 +++ b/kernel/locking/rt.c
-@@ -0,0 +1,498 @@
+@@ -0,0 +1,331 @@
 +/*
 + * kernel/rt.c
 + *
@@ -13892,173 +14298,6 @@ index 000000000000..665754c00e1e
 +}
 +EXPORT_SYMBOL(__rt_rwlock_init);
 +
-+/*
-+ * rw_semaphores
-+ */
-+
-+void  rt_up_write(struct rw_semaphore *rwsem)
-+{
-+      rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
-+      rt_mutex_unlock(&rwsem->lock);
-+}
-+EXPORT_SYMBOL(rt_up_write);
-+
-+void __rt_up_read(struct rw_semaphore *rwsem)
-+{
-+      if (--rwsem->read_depth == 0)
-+              rt_mutex_unlock(&rwsem->lock);
-+}
-+
-+void  rt_up_read(struct rw_semaphore *rwsem)
-+{
-+      rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
-+      __rt_up_read(rwsem);
-+}
-+EXPORT_SYMBOL(rt_up_read);
-+
-+/*
-+ * downgrade a write lock into a read lock
-+ * - just wake up any readers at the front of the queue
-+ */
-+void  rt_downgrade_write(struct rw_semaphore *rwsem)
-+{
-+      BUG_ON(rt_mutex_owner(&rwsem->lock) != current);
-+      rwsem->read_depth = 1;
-+}
-+EXPORT_SYMBOL(rt_downgrade_write);
-+
-+int  rt_down_write_trylock(struct rw_semaphore *rwsem)
-+{
-+      int ret = rt_mutex_trylock(&rwsem->lock);
-+
-+      if (ret)
-+              rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
-+      return ret;
-+}
-+EXPORT_SYMBOL(rt_down_write_trylock);
-+
-+void  rt_down_write(struct rw_semaphore *rwsem)
-+{
-+      rwsem_acquire(&rwsem->dep_map, 0, 0, _RET_IP_);
-+      rt_mutex_lock(&rwsem->lock);
-+}
-+EXPORT_SYMBOL(rt_down_write);
-+
-+int rt_down_write_killable(struct rw_semaphore *rwsem)
-+{
-+      int ret;
-+
-+      rwsem_acquire(&rwsem->dep_map, 0, 0, _RET_IP_);
-+      ret = rt_mutex_lock_killable(&rwsem->lock);
-+      if (ret)
-+              rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
-+      return ret;
-+}
-+EXPORT_SYMBOL(rt_down_write_killable);
-+
-+int rt_down_write_killable_nested(struct rw_semaphore *rwsem, int subclass)
-+{
-+      int ret;
-+
-+      rwsem_acquire(&rwsem->dep_map, subclass, 0, _RET_IP_);
-+      ret = rt_mutex_lock_killable(&rwsem->lock);
-+      if (ret)
-+              rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
-+      return ret;
-+}
-+EXPORT_SYMBOL(rt_down_write_killable_nested);
-+
-+void  rt_down_write_nested(struct rw_semaphore *rwsem, int subclass)
-+{
-+      rwsem_acquire(&rwsem->dep_map, subclass, 0, _RET_IP_);
-+      rt_mutex_lock(&rwsem->lock);
-+}
-+EXPORT_SYMBOL(rt_down_write_nested);
-+
-+void rt_down_write_nested_lock(struct rw_semaphore *rwsem,
-+                             struct lockdep_map *nest)
-+{
-+      rwsem_acquire_nest(&rwsem->dep_map, 0, 0, nest, _RET_IP_);
-+      rt_mutex_lock(&rwsem->lock);
-+}
-+EXPORT_SYMBOL(rt_down_write_nested_lock);
-+
-+int rt__down_read_trylock(struct rw_semaphore *rwsem)
-+{
-+      struct rt_mutex *lock = &rwsem->lock;
-+      int ret = 1;
-+
-+      /*
-+       * recursive read locks succeed when current owns the rwsem,
-+       * but not when read_depth == 0 which means that the rwsem is
-+       * write locked.
-+       */
-+      if (rt_mutex_owner(lock) != current)
-+              ret = rt_mutex_trylock(&rwsem->lock);
-+      else if (!rwsem->read_depth)
-+              ret = 0;
-+
-+      if (ret)
-+              rwsem->read_depth++;
-+      return ret;
-+
-+}
-+
-+int  rt_down_read_trylock(struct rw_semaphore *rwsem)
-+{
-+      int ret;
-+
-+      ret = rt__down_read_trylock(rwsem);
-+      if (ret)
-+              rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
-+
-+      return ret;
-+}
-+EXPORT_SYMBOL(rt_down_read_trylock);
-+
-+void rt__down_read(struct rw_semaphore *rwsem)
-+{
-+      struct rt_mutex *lock = &rwsem->lock;
-+
-+      if (rt_mutex_owner(lock) != current)
-+              rt_mutex_lock(&rwsem->lock);
-+      rwsem->read_depth++;
-+}
-+EXPORT_SYMBOL(rt__down_read);
-+
-+static void __rt_down_read(struct rw_semaphore *rwsem, int subclass)
-+{
-+      rwsem_acquire_read(&rwsem->dep_map, subclass, 0, _RET_IP_);
-+      rt__down_read(rwsem);
-+}
-+
-+void  rt_down_read(struct rw_semaphore *rwsem)
-+{
-+      __rt_down_read(rwsem, 0);
-+}
-+EXPORT_SYMBOL(rt_down_read);
-+
-+void  rt_down_read_nested(struct rw_semaphore *rwsem, int subclass)
-+{
-+      __rt_down_read(rwsem, subclass);
-+}
-+EXPORT_SYMBOL(rt_down_read_nested);
-+
-+void  __rt_rwsem_init(struct rw_semaphore *rwsem, const char *name,
-+                            struct lock_class_key *key)
-+{
-+#ifdef CONFIG_DEBUG_LOCK_ALLOC
-+      /*
-+       * Make sure we are not reinitializing a held lock:
-+       */
-+      debug_check_no_locks_freed((void *)rwsem, sizeof(*rwsem));
-+      lockdep_init_map(&rwsem->dep_map, name, key, 0);
-+#endif
-+      rwsem->read_depth = 0;
-+      rwsem->lock.save_state = 0;
-+}
-+EXPORT_SYMBOL(__rt_rwsem_init);
-+
 +/**
 + * atomic_dec_and_mutex_lock - return holding mutex if we dec to 0
 + * @cnt: the atomic which we are to dec
@@ -14082,8 +14321,39 @@ index 000000000000..665754c00e1e
 +      return 1;
 +}
 +EXPORT_SYMBOL(atomic_dec_and_mutex_lock);
+diff --git a/kernel/locking/rtmutex-debug.c b/kernel/locking/rtmutex-debug.c
+index 62b6cee8ea7f..0613c4b1d059 100644
+--- a/kernel/locking/rtmutex-debug.c
++++ b/kernel/locking/rtmutex-debug.c
+@@ -173,12 +173,3 @@ void debug_rt_mutex_init(struct rt_mutex *lock, const char *name)
+       lock->name = name;
+ }
+-void
+-rt_mutex_deadlock_account_lock(struct rt_mutex *lock, struct task_struct *task)
+-{
+-}
+-
+-void rt_mutex_deadlock_account_unlock(struct task_struct *task)
+-{
+-}
+-
+diff --git a/kernel/locking/rtmutex-debug.h b/kernel/locking/rtmutex-debug.h
+index d0519c3432b6..b585af9a1b50 100644
+--- a/kernel/locking/rtmutex-debug.h
++++ b/kernel/locking/rtmutex-debug.h
+@@ -9,9 +9,6 @@
+  * This file contains macros used solely by rtmutex.c. Debug version.
+  */
+-extern void
+-rt_mutex_deadlock_account_lock(struct rt_mutex *lock, struct task_struct *task);
+-extern void rt_mutex_deadlock_account_unlock(struct task_struct *task);
+ extern void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter);
+ extern void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter);
+ extern void debug_rt_mutex_init(struct rt_mutex *lock, const char *name);
 diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
-index 1ec0f48962b3..2576f7ccf8e2 100644
+index 2c49d76f96c3..3a8b5d44aaf8 100644
 --- a/kernel/locking/rtmutex.c
 +++ b/kernel/locking/rtmutex.c
 @@ -7,6 +7,11 @@
@@ -14098,28 +14368,175 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
   *
   *  See Documentation/locking/rt-mutex-design.txt for details.
   */
-@@ -16,6 +21,7 @@
+@@ -16,6 +21,8 @@
  #include <linux/sched/rt.h>
  #include <linux/sched/deadline.h>
  #include <linux/timer.h>
 +#include <linux/ww_mutex.h>
++#include <linux/blkdev.h>
+ #include "rtmutex_common.h"
+@@ -133,6 +140,12 @@ static void fixup_rt_mutex_waiters(struct rt_mutex *lock)
+               WRITE_ONCE(*p, owner & ~RT_MUTEX_HAS_WAITERS);
+ }
++static int rt_mutex_real_waiter(struct rt_mutex_waiter *waiter)
++{
++      return waiter && waiter != PI_WAKEUP_INPROGRESS &&
++              waiter != PI_REQUEUE_INPROGRESS;
++}
++
+ /*
+  * We can speed up the acquire/release, if there's no debugging state to be
+  * set up.
+@@ -222,6 +235,12 @@ static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock,
+ }
+ #endif
++/*
++ * Only use with rt_mutex_waiter_{less,equal}()
++ */
++#define task_to_waiter(p) &(struct rt_mutex_waiter) \
++      { .prio = (p)->prio, .deadline = (p)->dl.deadline, .task = (p) }
++
+ static inline int
+ rt_mutex_waiter_less(struct rt_mutex_waiter *left,
+                    struct rt_mutex_waiter *right)
+@@ -236,12 +255,51 @@ rt_mutex_waiter_less(struct rt_mutex_waiter *left,
+        * then right waiter has a dl_prio() too.
+        */
+       if (dl_prio(left->prio))
+-              return dl_time_before(left->task->dl.deadline,
+-                                    right->task->dl.deadline);
++              return dl_time_before(left->deadline, right->deadline);
+       return 0;
+ }
++static inline int
++rt_mutex_waiter_equal(struct rt_mutex_waiter *left,
++                    struct rt_mutex_waiter *right)
++{
++      if (left->prio != right->prio)
++              return 0;
++
++      /*
++       * If both waiters have dl_prio(), we check the deadlines of the
++       * associated tasks.
++       * If left waiter has a dl_prio(), and we didn't return 0 above,
++       * then right waiter has a dl_prio() too.
++       */
++      if (dl_prio(left->prio))
++              return left->deadline == right->deadline;
++
++      return 1;
++}
++
++#define STEAL_NORMAL  0
++#define STEAL_LATERAL 1
++
++static inline int
++rt_mutex_steal(struct rt_mutex *lock, struct rt_mutex_waiter *waiter, int mode)
++{
++      struct rt_mutex_waiter *top_waiter = rt_mutex_top_waiter(lock);
++
++      if (waiter == top_waiter || rt_mutex_waiter_less(waiter, top_waiter))
++              return 1;
++
++      /*
++       * Note that RT tasks are excluded from lateral-steals
++       * to prevent the introduction of an unbounded latency.
++       */
++      if (mode == STEAL_NORMAL || rt_task(waiter->task))
++              return 0;
++
++      return rt_mutex_waiter_equal(waiter, top_waiter);
++}
++
+ static void
+ rt_mutex_enqueue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter)
+ {
+@@ -320,72 +378,16 @@ rt_mutex_dequeue_pi(struct task_struct *task, struct rt_mutex_waiter *waiter)
+       RB_CLEAR_NODE(&waiter->pi_tree_entry);
+ }
+-/*
+- * Calculate task priority from the waiter tree priority
+- *
+- * Return task->normal_prio when the waiter tree is empty or when
+- * the waiter is not allowed to do priority boosting
+- */
+-int rt_mutex_getprio(struct task_struct *task)
+-{
+-      if (likely(!task_has_pi_waiters(task)))
+-              return task->normal_prio;
+-
+-      return min(task_top_pi_waiter(task)->prio,
+-                 task->normal_prio);
+-}
+-
+-struct task_struct *rt_mutex_get_top_task(struct task_struct *task)
+-{
+-      if (likely(!task_has_pi_waiters(task)))
+-              return NULL;
+-
+-      return task_top_pi_waiter(task)->task;
+-}
+-
+-/*
+- * Called by sched_setscheduler() to get the priority which will be
+- * effective after the change.
+- */
+-int rt_mutex_get_effective_prio(struct task_struct *task, int newprio)
+-{
+-      if (!task_has_pi_waiters(task))
+-              return newprio;
+-
+-      if (task_top_pi_waiter(task)->task->prio <= newprio)
+-              return task_top_pi_waiter(task)->task->prio;
+-      return newprio;
+-}
+-
+-/*
+- * Adjust the priority of a task, after its pi_waiters got modified.
+- *
+- * This can be both boosting and unboosting. task->pi_lock must be held.
+- */
+-static void __rt_mutex_adjust_prio(struct task_struct *task)
++static void rt_mutex_adjust_prio(struct task_struct *p)
+ {
+-      int prio = rt_mutex_getprio(task);
++      struct task_struct *pi_task = NULL;
  
- #include "rtmutex_common.h"
+-      if (task->prio != prio || dl_prio(prio))
+-              rt_mutex_setprio(task, prio);
+-}
++      lockdep_assert_held(&p->pi_lock);
+-/*
+- * Adjust task priority (undo boosting). Called from the exit path of
+- * rt_mutex_slowunlock() and rt_mutex_slowlock().
+- *
+- * (Note: We do this outside of the protection of lock->wait_lock to
+- * allow the lock to be taken while or before we readjust the priority
+- * of task. We do not use the spin_xx_mutex() variants here as we are
+- * outside of the debug path.)
+- */
+-void rt_mutex_adjust_prio(struct task_struct *task)
+-{
+-      unsigned long flags;
++      if (task_has_pi_waiters(p))
++              pi_task = task_top_pi_waiter(p)->task;
  
-@@ -69,6 +75,12 @@ static void fixup_rt_mutex_waiters(struct rt_mutex *lock)
-               clear_rt_mutex_waiters(lock);
+-      raw_spin_lock_irqsave(&task->pi_lock, flags);
+-      __rt_mutex_adjust_prio(task);
+-      raw_spin_unlock_irqrestore(&task->pi_lock, flags);
++      rt_mutex_setprio(p, pi_task);
  }
  
-+static int rt_mutex_real_waiter(struct rt_mutex_waiter *waiter)
-+{
-+      return waiter && waiter != PI_WAKEUP_INPROGRESS &&
-+              waiter != PI_REQUEUE_INPROGRESS;
-+}
-+
  /*
-  * We can speed up the acquire/release, if there's no debugging state to be
-  * set up.
-@@ -350,6 +362,14 @@ static bool rt_mutex_cond_detect_deadlock(struct rt_mutex_waiter *waiter,
+@@ -414,6 +416,14 @@ static bool rt_mutex_cond_detect_deadlock(struct rt_mutex_waiter *waiter,
        return debug_rt_mutex_detect_deadlock(waiter, chwalk);
  }
  
@@ -14134,7 +14551,7 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
  /*
   * Max number of times we'll walk the boosting chain:
   */
-@@ -357,7 +377,8 @@ int max_lock_depth = 1024;
+@@ -421,7 +431,8 @@ int max_lock_depth = 1024;
  
  static inline struct rt_mutex *task_blocked_on_lock(struct task_struct *p)
  {
@@ -14144,7 +14561,7 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
  }
  
  /*
-@@ -493,7 +514,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
+@@ -557,7 +568,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
         * reached or the state of the chain has changed while we
         * dropped the locks.
         */
@@ -14153,7 +14570,43 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
                goto out_unlock_pi;
  
        /*
-@@ -655,13 +676,16 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
+@@ -608,7 +619,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
+        * enabled we continue, but stop the requeueing in the chain
+        * walk.
+        */
+-      if (waiter->prio == task->prio) {
++      if (rt_mutex_waiter_equal(waiter, task_to_waiter(task))) {
+               if (!detect_deadlock)
+                       goto out_unlock_pi;
+               else
+@@ -704,7 +715,26 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
+       /* [7] Requeue the waiter in the lock waiter tree. */
+       rt_mutex_dequeue(lock, waiter);
++
++      /*
++       * Update the waiter prio fields now that we're dequeued.
++       *
++       * These values can have changed through either:
++       *
++       *   sys_sched_set_scheduler() / sys_sched_setattr()
++       *
++       * or
++       *
++       *   DL CBS enforcement advancing the effective deadline.
++       *
++       * Even though pi_waiters also uses these fields, and that tree is only
++       * updated in [11], we can do this here, since we hold [L], which
++       * serializes all pi_waiters access and rb_erase() does not care about
++       * the values of the node being removed.
++       */
+       waiter->prio = task->prio;
++      waiter->deadline = task->dl.deadline;
++
+       rt_mutex_enqueue(lock, waiter);
+       /* [8] Release the task */
+@@ -719,13 +749,16 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
         * follow here. This is the end of the chain we are walking.
         */
        if (!rt_mutex_owner(lock)) {
@@ -14172,35 +14625,37 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
                raw_spin_unlock_irq(&lock->wait_lock);
                return 0;
        }
-@@ -754,6 +778,25 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
+@@ -745,7 +778,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
+                */
+               rt_mutex_dequeue_pi(task, prerequeue_top_waiter);
+               rt_mutex_enqueue_pi(task, waiter);
+-              __rt_mutex_adjust_prio(task);
++              rt_mutex_adjust_prio(task);
+       } else if (prerequeue_top_waiter == waiter) {
+               /*
+@@ -761,7 +794,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
+               rt_mutex_dequeue_pi(task, waiter);
+               waiter = rt_mutex_top_waiter(lock);
+               rt_mutex_enqueue_pi(task, waiter);
+-              __rt_mutex_adjust_prio(task);
++              rt_mutex_adjust_prio(task);
+       } else {
+               /*
+                * Nothing changed. No need to do any priority
+@@ -818,6 +851,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
        return ret;
  }
  
-+
-+#define STEAL_NORMAL  0
-+#define STEAL_LATERAL 1
-+
-+/*
-+ * Note that RT tasks are excluded from lateral-steals to prevent the
-+ * introduction of an unbounded latency
-+ */
-+static inline int lock_is_stealable(struct task_struct *task,
-+                                  struct task_struct *pendowner, int mode)
-+{
-+    if (mode == STEAL_NORMAL || rt_task(task)) {
-+          if (task->prio >= pendowner->prio)
-+                  return 0;
-+    } else if (task->prio > pendowner->prio)
-+          return 0;
-+    return 1;
-+}
 +
  /*
   * Try to take an rt-mutex
   *
-@@ -764,8 +807,9 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
+@@ -827,10 +861,14 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
+  * @task:   The task which wants to acquire the lock
   * @waiter: The waiter that is queued to the lock's wait tree if the
   *        callsite called task_blocked_on_lock(), otherwise NULL
++ * @mode:   Lock steal mode (STEAL_NORMAL, STEAL_LATERAL)
   */
 -static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
 -                              struct rt_mutex_waiter *waiter)
@@ -14208,70 +14663,114 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +                                struct task_struct *task,
 +                                struct rt_mutex_waiter *waiter, int mode)
  {
++      lockdep_assert_held(&lock->wait_lock);
++
        /*
         * Before testing whether we can acquire @lock, we set the
-@@ -802,8 +846,10 @@ static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
-                * If waiter is not the highest priority waiter of
-                * @lock, give up.
+        * RT_MUTEX_HAS_WAITERS bit in @lock->owner. This forces all
+@@ -863,12 +901,11 @@ static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
+        */
+       if (waiter) {
+               /*
+-               * If waiter is not the highest priority waiter of
+-               * @lock, give up.
++               * If waiter is not the highest priority waiter of @lock,
++               * or its peer when lateral steal is allowed, give up.
                 */
 -              if (waiter != rt_mutex_top_waiter(lock))
-+              if (waiter != rt_mutex_top_waiter(lock)) {
-+                      /* XXX lock_is_stealable() ? */
++              if (!rt_mutex_steal(lock, waiter, mode))
                        return 0;
-+              }
+-
                /*
                 * We can acquire the lock. Remove the waiter from the
-@@ -821,14 +867,10 @@ static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
-                * not need to be dequeued.
+                * lock waiters tree.
+@@ -886,13 +923,12 @@ static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
                 */
                if (rt_mutex_has_waiters(lock)) {
--                      /*
+                       /*
 -                       * If @task->prio is greater than or equal to
 -                       * the top waiter priority (kernel view),
 -                       * @task lost.
--                       */
++                       * If @task->prio is greater than the top waiter
++                       * priority (kernel view), or equal to it when a
++                       * lateral steal is forbidden, @task lost.
+                        */
 -                      if (task->prio >= rt_mutex_top_waiter(lock)->prio)
--                              return 0;
-+                      struct task_struct *pown = rt_mutex_top_waiter(lock)->task;
-+                      if (task != pown && !lock_is_stealable(task, pown, mode))
-+                              return 0;
++                      if (!rt_mutex_steal(lock, task_to_waiter(task), mode))
+                               return 0;
+-
                        /*
                         * The current top waiter stays enqueued. We
                         * don't have to change anything in the lock
-@@ -877,6 +919,438 @@ static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
+@@ -936,177 +972,589 @@ static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
+        */
+       rt_mutex_set_owner(lock, task);
+-      rt_mutex_deadlock_account_lock(lock, task);
+-
        return 1;
  }
  
 +#ifdef CONFIG_PREEMPT_RT_FULL
-+/*
+ /*
+- * Task blocks on lock.
+- *
+- * Prepare waiter and propagate pi chain
+- *
+- * This must be called with lock->wait_lock held and interrupts disabled
 + * preemptible spin_lock functions:
-+ */
+  */
+-static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
+-                                 struct rt_mutex_waiter *waiter,
+-                                 struct task_struct *task,
+-                                 enum rtmutex_chainwalk chwalk)
 +static inline void rt_spin_lock_fastlock(struct rt_mutex *lock,
 +                                       void  (*slowfn)(struct rt_mutex *lock,
 +                                                       bool mg_off),
 +                                       bool do_mig_dis)
-+{
+ {
+-      struct task_struct *owner = rt_mutex_owner(lock);
+-      struct rt_mutex_waiter *top_waiter = waiter;
+-      struct rt_mutex *next_lock;
+-      int chain_walk = 0, res;
 +      might_sleep_no_state_check();
-+
+-      /*
+-       * Early deadlock detection. We really don't want the task to
+-       * enqueue on itself just to untangle the mess later. It's not
+-       * only an optimization. We drop the locks, so another waiter
+-       * can come in before the chain walk detects the deadlock. So
+-       * the other will detect the deadlock and return -EDEADLOCK,
+-       * which is wrong, as the other waiter is not in a deadlock
+-       * situation.
+-       */
+-      if (owner == task)
+-              return -EDEADLK;
 +      if (do_mig_dis)
 +              migrate_disable();
-+
+-      raw_spin_lock(&task->pi_lock);
+-      __rt_mutex_adjust_prio(task);
+-      waiter->task = task;
+-      waiter->lock = lock;
+-      waiter->prio = task->prio;
 +      if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current)))
-+              rt_mutex_deadlock_account_lock(lock, current);
++              return;
 +      else
 +              slowfn(lock, do_mig_dis);
 +}
-+
-+static inline int rt_spin_lock_fastunlock(struct rt_mutex *lock,
-+                                        int (*slowfn)(struct rt_mutex *lock))
+-      /* Get the top priority waiter on the lock */
+-      if (rt_mutex_has_waiters(lock))
+-              top_waiter = rt_mutex_top_waiter(lock);
+-      rt_mutex_enqueue(lock, waiter);
++static inline void rt_spin_lock_fastunlock(struct rt_mutex *lock,
++                                         void  (*slowfn)(struct rt_mutex *lock))
 +{
-+      if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
-+              rt_mutex_deadlock_account_unlock(current);
-+              return 0;
-+      }
-+      return slowfn(lock);
++      if (likely(rt_mutex_cmpxchg_release(lock, current, NULL)))
++              return;
++      else
++              slowfn(lock);
 +}
 +#ifdef CONFIG_SMP
 +/*
@@ -14282,7 +14781,8 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +                       struct task_struct *owner)
 +{
 +      int res = 0;
-+
+-      task->pi_blocked_on = waiter;
 +      rcu_read_lock();
 +      for (;;) {
 +              if (owner != rt_mutex_owner(lock))
@@ -14308,7 +14808,8 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +      return 1;
 +}
 +#endif
-+
+-      raw_spin_unlock(&task->pi_lock);
 +static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
 +                                 struct rt_mutex_waiter *waiter,
 +                                 struct task_struct *task,
@@ -14327,44 +14828,85 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +      struct rt_mutex_waiter waiter, *top_waiter;
 +      unsigned long flags;
 +      int ret;
-+
+-      if (!owner)
+-              return 0;
 +      rt_mutex_init_waiter(&waiter, true);
-+
+-      raw_spin_lock(&owner->pi_lock);
+-      if (waiter == rt_mutex_top_waiter(lock)) {
+-              rt_mutex_dequeue_pi(owner, top_waiter);
+-              rt_mutex_enqueue_pi(owner, waiter);
 +      raw_spin_lock_irqsave(&lock->wait_lock, flags);
-+
+-              __rt_mutex_adjust_prio(owner);
+-              if (owner->pi_blocked_on)
+-                      chain_walk = 1;
+-      } else if (rt_mutex_cond_detect_deadlock(waiter, chwalk)) {
+-              chain_walk = 1;
 +      if (__try_to_take_rt_mutex(lock, self, NULL, STEAL_LATERAL)) {
 +              raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
 +              return;
-+      }
-+
+       }
+-      /* Store the lock on which owner is blocked or NULL */
+-      next_lock = task_blocked_on_lock(owner);
 +      BUG_ON(rt_mutex_owner(lock) == self);
-+
-+      /*
+-      raw_spin_unlock(&owner->pi_lock);
+       /*
+-       * Even if full deadlock detection is on, if the owner is not
+-       * blocked itself, we can avoid finding this out in the chain
+-       * walk.
 +       * We save whatever state the task is in and we'll restore it
 +       * after acquiring the lock taking real wakeups into account
 +       * as well. We are serialized via pi_lock against wakeups. See
 +       * try_to_wake_up().
-+       */
+        */
+-      if (!chain_walk || !next_lock)
+-              return 0;
 +      raw_spin_lock(&self->pi_lock);
 +      self->saved_state = self->state;
 +      __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
 +      raw_spin_unlock(&self->pi_lock);
-+
+-      /*
+-       * The owner can't disappear while holding a lock,
+-       * so the owner struct is protected by wait_lock.
+-       * Gets dropped in rt_mutex_adjust_prio_chain()!
+-       */
+-      get_task_struct(owner);
 +      ret = task_blocks_on_rt_mutex(lock, &waiter, self, RT_MUTEX_MIN_CHAINWALK);
 +      BUG_ON(ret);
-+
+-      raw_spin_unlock_irq(&lock->wait_lock);
 +      for (;;) {
 +              /* Try to acquire the lock again. */
 +              if (__try_to_take_rt_mutex(lock, self, &waiter, STEAL_LATERAL))
 +                      break;
-+
+-      res = rt_mutex_adjust_prio_chain(owner, chwalk, lock,
+-                                       next_lock, waiter, task);
 +              top_waiter = rt_mutex_top_waiter(lock);
 +              lock_owner = rt_mutex_owner(lock);
-+
+-      raw_spin_lock_irq(&lock->wait_lock);
 +              raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
-+
+-      return res;
+-}
 +              debug_rt_mutex_print_deadlock(&waiter);
-+
+-/*
+- * Remove the top waiter from the current tasks pi waiter tree and
+- * queue it up.
+- *
+- * Called with lock->wait_lock held and interrupts disabled.
+- */
+-static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
+-                                  struct rt_mutex *lock)
+-{
+-      struct rt_mutex_waiter *waiter;
 +              if (top_waiter != &waiter || adaptive_wait(lock, lock_owner)) {
 +                      if (mg_off)
 +                              migrate_enable();
@@ -14372,127 +14914,129 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +                      if (mg_off)
 +                              migrate_disable();
 +              }
-+
+-      raw_spin_lock(&current->pi_lock);
 +              raw_spin_lock_irqsave(&lock->wait_lock, flags);
-+
+-      waiter = rt_mutex_top_waiter(lock);
 +              raw_spin_lock(&self->pi_lock);
 +              __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
 +              raw_spin_unlock(&self->pi_lock);
 +      }
-+
-+      /*
+       /*
+-       * Remove it from current->pi_waiters. We do not adjust a
+-       * possible priority boost right now. We execute wakeup in the
+-       * boosted mode and go back to normal after releasing
+-       * lock->wait_lock.
 +       * Restore the task state to current->saved_state. We set it
 +       * to the original state above and the try_to_wake_up() code
 +       * has possibly updated it when a real (non-rtmutex) wakeup
 +       * happened while we were blocked. Clear saved_state so
 +       * try_to_wakeup() does not get confused.
-+       */
+        */
+-      rt_mutex_dequeue_pi(current, waiter);
 +      raw_spin_lock(&self->pi_lock);
 +      __set_current_state_no_track(self->saved_state);
 +      self->saved_state = TASK_RUNNING;
 +      raw_spin_unlock(&self->pi_lock);
-+
-+      /*
+       /*
+-       * As we are waking up the top waiter, and the waiter stays
+-       * queued on the lock until it gets the lock, this lock
+-       * obviously has waiters. Just set the bit here and this has
+-       * the added benefit of forcing all new tasks into the
+-       * slow path making sure no task of lower priority than
+-       * the top waiter can steal this lock.
 +       * try_to_take_rt_mutex() sets the waiter bit
 +       * unconditionally. We might have to fix that up:
-+       */
+        */
+-      lock->owner = (void *) RT_MUTEX_HAS_WAITERS;
 +      fixup_rt_mutex_waiters(lock);
-+
+-      raw_spin_unlock(&current->pi_lock);
 +      BUG_ON(rt_mutex_has_waiters(lock) && &waiter == rt_mutex_top_waiter(lock));
 +      BUG_ON(!RB_EMPTY_NODE(&waiter.tree_entry));
-+
+-      wake_q_add(wake_q, waiter->task);
 +      raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
 +
 +      debug_rt_mutex_free_waiter(&waiter);
-+}
-+
-+static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
-+                                  struct wake_q_head *wake_sleeper_q,
-+                                  struct rt_mutex *lock);
-+/*
+ }
++static bool __sched __rt_mutex_unlock_common(struct rt_mutex *lock,
++                                           struct wake_q_head *wake_q,
++                                           struct wake_q_head *wq_sleeper);
+ /*
+- * Remove a waiter from a lock and give up
+- *
+- * Must be called with lock->wait_lock held and interrupts disabled. I must
+- * have just failed to try_to_take_rt_mutex().
 + * Slow path to release a rt_mutex spin_lock style
-+ */
-+static int noinline __sched rt_spin_lock_slowunlock(struct rt_mutex *lock)
-+{
-+      unsigned long flags;
-+      WAKE_Q(wake_q);
-+      WAKE_Q(wake_sleeper_q);
-+
-+      raw_spin_lock_irqsave(&lock->wait_lock, flags);
-+
-+      debug_rt_mutex_unlock(lock);
-+
-+      rt_mutex_deadlock_account_unlock(current);
-+
-+      if (!rt_mutex_has_waiters(lock)) {
-+              lock->owner = NULL;
-+              raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
-+              return 0;
-+      }
-+
-+      mark_wakeup_next_waiter(&wake_q, &wake_sleeper_q, lock);
-+
-+      raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
-+      wake_up_q(&wake_q);
-+      wake_up_q_sleeper(&wake_sleeper_q);
-+
-+      /* Undo pi boosting.when necessary */
-+      rt_mutex_adjust_prio(current);
-+      return 0;
-+}
-+
-+static int noinline __sched rt_spin_lock_slowunlock_no_deboost(struct rt_mutex *lock)
-+{
+  */
+-static void remove_waiter(struct rt_mutex *lock,
+-                        struct rt_mutex_waiter *waiter)
++static void  noinline __sched rt_spin_lock_slowunlock(struct rt_mutex *lock)
+ {
+-      bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
+-      struct task_struct *owner = rt_mutex_owner(lock);
+-      struct rt_mutex *next_lock;
 +      unsigned long flags;
 +      WAKE_Q(wake_q);
 +      WAKE_Q(wake_sleeper_q);
-+
++      bool postunlock;
+-      raw_spin_lock(&current->pi_lock);
+-      rt_mutex_dequeue(lock, waiter);
+-      current->pi_blocked_on = NULL;
+-      raw_spin_unlock(&current->pi_lock);
 +      raw_spin_lock_irqsave(&lock->wait_lock, flags);
-+
-+      debug_rt_mutex_unlock(lock);
-+
-+      rt_mutex_deadlock_account_unlock(current);
-+
-+      if (!rt_mutex_has_waiters(lock)) {
-+              lock->owner = NULL;
-+              raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
-+              return 0;
-+      }
-+
-+      mark_wakeup_next_waiter(&wake_q, &wake_sleeper_q, lock);
-+
++      postunlock = __rt_mutex_unlock_common(lock, &wake_q, &wake_sleeper_q);
 +      raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
-+      wake_up_q(&wake_q);
-+      wake_up_q_sleeper(&wake_sleeper_q);
-+      return 1;
+-      /*
+-       * Only update priority if the waiter was the highest priority
+-       * waiter of the lock and there is an owner to update.
+-       */
+-      if (!owner || !is_top_waiter)
+-              return;
++      if (postunlock)
++              rt_mutex_postunlock(&wake_q, &wake_sleeper_q);
 +}
-+
+-      raw_spin_lock(&owner->pi_lock);
 +void __lockfunc rt_spin_lock__no_mg(spinlock_t *lock)
 +{
 +      rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock, false);
 +      spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
 +}
 +EXPORT_SYMBOL(rt_spin_lock__no_mg);
-+
+-      rt_mutex_dequeue_pi(owner, waiter);
 +void __lockfunc rt_spin_lock(spinlock_t *lock)
 +{
 +      rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock, true);
 +      spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
 +}
 +EXPORT_SYMBOL(rt_spin_lock);
-+
+-      if (rt_mutex_has_waiters(lock))
+-              rt_mutex_enqueue_pi(owner, rt_mutex_top_waiter(lock));
 +void __lockfunc __rt_spin_lock(struct rt_mutex *lock)
 +{
 +      rt_spin_lock_fastlock(lock, rt_spin_lock_slowlock, true);
 +}
 +EXPORT_SYMBOL(__rt_spin_lock);
-+
+-      __rt_mutex_adjust_prio(owner);
 +void __lockfunc __rt_spin_lock__no_mg(struct rt_mutex *lock)
 +{
 +      rt_spin_lock_fastlock(lock, rt_spin_lock_slowlock, false);
 +}
 +EXPORT_SYMBOL(__rt_spin_lock__no_mg);
-+
+-      /* Store the lock on which owner is blocked or NULL */
+-      next_lock = task_blocked_on_lock(owner);
 +#ifdef CONFIG_DEBUG_LOCK_ALLOC
 +void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass)
 +{
@@ -14501,7 +15045,8 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +}
 +EXPORT_SYMBOL(rt_spin_lock_nested);
 +#endif
-+
+-      raw_spin_unlock(&owner->pi_lock);
 +void __lockfunc rt_spin_unlock__no_mg(spinlock_t *lock)
 +{
 +      /* NOTE: we always pass in '1' for nested, for simplicity */
@@ -14509,7 +15054,8 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +      rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock);
 +}
 +EXPORT_SYMBOL(rt_spin_unlock__no_mg);
-+
+-      /*
 +void __lockfunc rt_spin_unlock(spinlock_t *lock)
 +{
 +      /* NOTE: we always pass in '1' for nested, for simplicity */
@@ -14519,17 +15065,6 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +}
 +EXPORT_SYMBOL(rt_spin_unlock);
 +
-+int __lockfunc rt_spin_unlock_no_deboost(spinlock_t *lock)
-+{
-+      int ret;
-+
-+      /* NOTE: we always pass in '1' for nested, for simplicity */
-+      spin_release(&lock->dep_map, 1, _RET_IP_);
-+      ret = rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock_no_deboost);
-+      migrate_enable();
-+      return ret;
-+}
-+
 +void __lockfunc __rt_spin_unlock(struct rt_mutex *lock)
 +{
 +      rt_spin_lock_fastunlock(lock, rt_spin_lock_slowunlock);
@@ -14548,11 +15083,6 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +}
 +EXPORT_SYMBOL(rt_spin_unlock_wait);
 +
-+int __lockfunc __rt_spin_trylock(struct rt_mutex *lock)
-+{
-+      return rt_mutex_trylock(lock);
-+}
-+
 +int __lockfunc rt_spin_trylock__no_mg(spinlock_t *lock)
 +{
 +      int ret;
@@ -14673,16 +15203,41 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
 +                   struct rt_mutex_waiter *waiter)
 +{
-+      return __try_to_take_rt_mutex(lock, task, waiter, STEAL_NORMAL);
-+}
++      return __try_to_take_rt_mutex(lock, task, waiter, STEAL_NORMAL);
++}
++
++/*
++ * Task blocks on lock.
++ *
++ * Prepare waiter and propagate pi chain
++ *
++ * This must be called with lock->wait_lock held and interrupts disabled
++ */
++static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
++                                 struct rt_mutex_waiter *waiter,
++                                 struct task_struct *task,
++                                 enum rtmutex_chainwalk chwalk)
++{
++      struct task_struct *owner = rt_mutex_owner(lock);
++      struct rt_mutex_waiter *top_waiter = waiter;
++      struct rt_mutex *next_lock;
++      int chain_walk = 0, res;
 +
- /*
-  * Task blocks on lock.
-  *
-@@ -907,6 +1381,23 @@ static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
-               return -EDEADLK;
-       raw_spin_lock(&task->pi_lock);
++      lockdep_assert_held(&lock->wait_lock);
++
++      /*
++       * Early deadlock detection. We really don't want the task to
++       * enqueue on itself just to untangle the mess later. It's not
++       * only an optimization. We drop the locks, so another waiter
++       * can come in before the chain walk detects the deadlock. So
++       * the other will detect the deadlock and return -EDEADLOCK,
++       * which is wrong, as the other waiter is not in a deadlock
++       * situation.
++       */
++      if (owner == task)
++              return -EDEADLK;
++
++      raw_spin_lock(&task->pi_lock);
 +
 +      /*
 +       * In the case of futex requeue PI, this will be a proxy
@@ -14700,64 +15255,173 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +
 +      BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on));
 +
-       __rt_mutex_adjust_prio(task);
-       waiter->task = task;
-       waiter->lock = lock;
-@@ -930,7 +1421,7 @@ static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
-               rt_mutex_enqueue_pi(owner, waiter);
-               __rt_mutex_adjust_prio(owner);
--              if (owner->pi_blocked_on)
++      rt_mutex_adjust_prio(task);
++      waiter->task = task;
++      waiter->lock = lock;
++      waiter->prio = task->prio;
++      waiter->deadline = task->dl.deadline;
++
++      /* Get the top priority waiter on the lock */
++      if (rt_mutex_has_waiters(lock))
++              top_waiter = rt_mutex_top_waiter(lock);
++      rt_mutex_enqueue(lock, waiter);
++
++      task->pi_blocked_on = waiter;
++
++      raw_spin_unlock(&task->pi_lock);
++
++      if (!owner)
++              return 0;
++
++      raw_spin_lock(&owner->pi_lock);
++      if (waiter == rt_mutex_top_waiter(lock)) {
++              rt_mutex_dequeue_pi(owner, top_waiter);
++              rt_mutex_enqueue_pi(owner, waiter);
++
++              rt_mutex_adjust_prio(owner);
 +              if (rt_mutex_real_waiter(owner->pi_blocked_on))
-                       chain_walk = 1;
-       } else if (rt_mutex_cond_detect_deadlock(waiter, chwalk)) {
-               chain_walk = 1;
-@@ -972,6 +1463,7 @@ static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
-  * Called with lock->wait_lock held and interrupts disabled.
-  */
- static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
++                      chain_walk = 1;
++      } else if (rt_mutex_cond_detect_deadlock(waiter, chwalk)) {
++              chain_walk = 1;
++      }
++
++      /* Store the lock on which owner is blocked or NULL */
++      next_lock = task_blocked_on_lock(owner);
++
++      raw_spin_unlock(&owner->pi_lock);
++      /*
++       * Even if full deadlock detection is on, if the owner is not
++       * blocked itself, we can avoid finding this out in the chain
++       * walk.
++       */
++      if (!chain_walk || !next_lock)
++              return 0;
++
++      /*
++       * The owner can't disappear while holding a lock,
++       * so the owner struct is protected by wait_lock.
++       * Gets dropped in rt_mutex_adjust_prio_chain()!
++       */
++      get_task_struct(owner);
++
++      raw_spin_unlock_irq(&lock->wait_lock);
++
++      res = rt_mutex_adjust_prio_chain(owner, chwalk, lock,
++                                       next_lock, waiter, task);
++
++      raw_spin_lock_irq(&lock->wait_lock);
++
++      return res;
++}
++
++/*
++ * Remove the top waiter from the current tasks pi waiter tree and
++ * queue it up.
++ *
++ * Called with lock->wait_lock held and interrupts disabled.
++ */
++static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
 +                                  struct wake_q_head *wake_sleeper_q,
-                                   struct rt_mutex *lock)
- {
-       struct rt_mutex_waiter *waiter;
-@@ -1000,7 +1492,10 @@ static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
-       raw_spin_unlock(&current->pi_lock);
--      wake_q_add(wake_q, waiter->task);
++                                  struct rt_mutex *lock)
++{
++      struct rt_mutex_waiter *waiter;
++
++      raw_spin_lock(&current->pi_lock);
++
++      waiter = rt_mutex_top_waiter(lock);
++
++      /*
++       * Remove it from current->pi_waiters and deboost.
++       *
++       * We must in fact deboost here in order to ensure we call
++       * rt_mutex_setprio() to update p->pi_top_task before the
++       * task unblocks.
++       */
++      rt_mutex_dequeue_pi(current, waiter);
++      rt_mutex_adjust_prio(current);
++
++      /*
++       * As we are waking up the top waiter, and the waiter stays
++       * queued on the lock until it gets the lock, this lock
++       * obviously has waiters. Just set the bit here and this has
++       * the added benefit of forcing all new tasks into the
++       * slow path making sure no task of lower priority than
++       * the top waiter can steal this lock.
++       */
++      lock->owner = (void *) RT_MUTEX_HAS_WAITERS;
++
++      /*
++       * We deboosted before waking the top waiter task such that we don't
++       * run two tasks with the 'same' priority (and ensure the
++       * p->pi_top_task pointer points to a blocked task). This however can
++       * lead to priority inversion if we would get preempted after the
++       * deboost but before waking our donor task, hence the preempt_disable()
++       * before unlock.
++       *
++       * Pairs with preempt_enable() in rt_mutex_postunlock();
++       */
++      preempt_disable();
 +      if (waiter->savestate)
-+              wake_q_add(wake_sleeper_q, waiter->task);
++              wake_q_add_sleeper(wake_sleeper_q, waiter->task);
 +      else
 +              wake_q_add(wake_q, waiter->task);
- }
- /*
-@@ -1014,7 +1509,7 @@ static void remove_waiter(struct rt_mutex *lock,
- {
-       bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
-       struct task_struct *owner = rt_mutex_owner(lock);
--      struct rt_mutex *next_lock;
++      raw_spin_unlock(&current->pi_lock);
++}
++
++/*
++ * Remove a waiter from a lock and give up
++ *
++ * Must be called with lock->wait_lock held and interrupts disabled. I must
++ * have just failed to try_to_take_rt_mutex().
++ */
++static void remove_waiter(struct rt_mutex *lock,
++                        struct rt_mutex_waiter *waiter)
++{
++      bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
++      struct task_struct *owner = rt_mutex_owner(lock);
 +      struct rt_mutex *next_lock = NULL;
-       raw_spin_lock(&current->pi_lock);
-       rt_mutex_dequeue(lock, waiter);
-@@ -1038,7 +1533,8 @@ static void remove_waiter(struct rt_mutex *lock,
-       __rt_mutex_adjust_prio(owner);
-       /* Store the lock on which owner is blocked or NULL */
--      next_lock = task_blocked_on_lock(owner);
++
++      lockdep_assert_held(&lock->wait_lock);
++
++      raw_spin_lock(&current->pi_lock);
++      rt_mutex_dequeue(lock, waiter);
++      current->pi_blocked_on = NULL;
++      raw_spin_unlock(&current->pi_lock);
++
++      /*
++       * Only update priority if the waiter was the highest priority
++       * waiter of the lock and there is an owner to update.
++       */
++      if (!owner || !is_top_waiter)
++              return;
++
++      raw_spin_lock(&owner->pi_lock);
++
++      rt_mutex_dequeue_pi(owner, waiter);
++
++      if (rt_mutex_has_waiters(lock))
++              rt_mutex_enqueue_pi(owner, rt_mutex_top_waiter(lock));
++
++      rt_mutex_adjust_prio(owner);
++
++      /* Store the lock on which owner is blocked or NULL */
 +      if (rt_mutex_real_waiter(owner->pi_blocked_on))
 +              next_lock = task_blocked_on_lock(owner);
-       raw_spin_unlock(&owner->pi_lock);
-@@ -1074,17 +1570,17 @@ void rt_mutex_adjust_pi(struct task_struct *task)
++
++      raw_spin_unlock(&owner->pi_lock);
++
++      /*
+        * Don't walk the chain, if the owner task is not blocked
+        * itself.
+        */
+@@ -1138,21 +1586,30 @@ void rt_mutex_adjust_pi(struct task_struct *task)
        raw_spin_lock_irqsave(&task->pi_lock, flags);
  
        waiter = task->pi_blocked_on;
 -      if (!waiter || (waiter->prio == task->prio &&
-+      if (!rt_mutex_real_waiter(waiter) || (waiter->prio == task->prio &&
-                       !dl_prio(task->prio))) {
+-                      !dl_prio(task->prio))) {
++      if (!rt_mutex_real_waiter(waiter) ||
++          rt_mutex_waiter_equal(waiter, task_to_waiter(task))) {
                raw_spin_unlock_irqrestore(&task->pi_lock, flags);
                return;
        }
@@ -14771,7 +15435,20 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
        rt_mutex_adjust_prio_chain(task, RT_MUTEX_MIN_CHAINWALK, NULL,
                                   next_lock, NULL, task);
  }
-@@ -1102,7 +1598,8 @@ void rt_mutex_adjust_pi(struct task_struct *task)
++void rt_mutex_init_waiter(struct rt_mutex_waiter *waiter, bool savestate)
++{
++      debug_rt_mutex_init_waiter(waiter);
++      RB_CLEAR_NODE(&waiter->pi_tree_entry);
++      RB_CLEAR_NODE(&waiter->tree_entry);
++      waiter->task = NULL;
++      waiter->savestate = savestate;
++}
++
+ /**
+  * __rt_mutex_slowlock() - Perform the wait-wake-try-to-take loop
+  * @lock:              the rt_mutex to take
+@@ -1166,7 +1623,8 @@ void rt_mutex_adjust_pi(struct task_struct *task)
  static int __sched
  __rt_mutex_slowlock(struct rt_mutex *lock, int state,
                    struct hrtimer_sleeper *timeout,
@@ -14781,23 +15458,45 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
  {
        int ret = 0;
  
-@@ -1125,6 +1622,12 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state,
-                               break;
-               }
+@@ -1175,16 +1633,17 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state,
+               if (try_to_take_rt_mutex(lock, current, waiter))
+                       break;
  
-+              if (ww_ctx && ww_ctx->acquired > 0) {
-+                      ret = __mutex_lock_check_stamp(lock, ww_ctx);
-+                      if (ret)
-+                              break;
+-              /*
+-               * TASK_INTERRUPTIBLE checks for signals and
+-               * timeout. Ignored otherwise.
+-               */
+-              if (unlikely(state == TASK_INTERRUPTIBLE)) {
+-                      /* Signal pending? */
+-                      if (signal_pending(current))
+-                              ret = -EINTR;
+-                      if (timeout && !timeout->task)
+-                              ret = -ETIMEDOUT;
++              if (timeout && !timeout->task) {
++                      ret = -ETIMEDOUT;
++                      break;
++              }
++              if (signal_pending_state(state, current)) {
++                      ret = -EINTR;
++                      break;
 +              }
 +
-               raw_spin_unlock_irq(&lock->wait_lock);
-               debug_rt_mutex_print_deadlock(waiter);
-@@ -1159,21 +1662,96 @@ static void rt_mutex_handle_deadlock(int res, int detect_deadlock,
++              if (ww_ctx && ww_ctx->acquired > 0) {
++                      ret = __mutex_lock_check_stamp(lock, ww_ctx);
+                       if (ret)
+                               break;
+               }
+@@ -1223,35 +1682,94 @@ static void rt_mutex_handle_deadlock(int res, int detect_deadlock,
        }
  }
  
+-/*
+- * Slow path lock function:
+- */
+-static int __sched
+-rt_mutex_slowlock(struct rt_mutex *lock, int state,
+-                struct hrtimer_sleeper *timeout,
+-                enum rtmutex_chainwalk chwalk)
 +static __always_inline void ww_mutex_lock_acquired(struct ww_mutex *ww,
 +                                                 struct ww_acquire_ctx *ww_ctx)
 +{
@@ -14841,21 +15540,34 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +#ifdef CONFIG_PREEMPT_RT_FULL
 +static void ww_mutex_account_lock(struct rt_mutex *lock,
 +                                struct ww_acquire_ctx *ww_ctx)
-+{
+ {
+-      struct rt_mutex_waiter waiter;
+-      unsigned long flags;
+-      int ret = 0;
 +      struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
 +      struct rt_mutex_waiter *waiter, *n;
-+
+-      debug_rt_mutex_init_waiter(&waiter);
+-      RB_CLEAR_NODE(&waiter.pi_tree_entry);
+-      RB_CLEAR_NODE(&waiter.tree_entry);
 +      /*
 +       * This branch gets optimized out for the common case,
 +       * and is only important for ww_mutex_lock.
 +       */
 +      ww_mutex_lock_acquired(ww, ww_ctx);
 +      ww->ctx = ww_ctx;
-+
-+      /*
+       /*
+-       * Technically we could use raw_spin_[un]lock_irq() here, but this can
+-       * be called in early boot if the cmpxchg() fast path is disabled
+-       * (debug, no architecture support). In this case we will acquire the
+-       * rtmutex with lock->wait_lock held. But we cannot unconditionally
+-       * enable interrupts in that early boot case. So we need to use the
+-       * irqsave/restore variants.
 +       * Give any possible sleeping processes the chance to wake up,
 +       * so they can recheck if they have to back off.
-+       */
+        */
+-      raw_spin_lock_irqsave(&lock->wait_lock, flags);
 +      rbtree_postorder_for_each_entry_safe(waiter, n, &lock->waiters,
 +                                           tree_entry) {
 +              /* XXX debug rt mutex waiter wakeup */
@@ -14874,44 +15586,36 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +}
 +#endif
 +
- /*
-  * Slow path lock function:
-  */
- static int __sched
- rt_mutex_slowlock(struct rt_mutex *lock, int state,
-                 struct hrtimer_sleeper *timeout,
--                enum rtmutex_chainwalk chwalk)
-+                enum rtmutex_chainwalk chwalk,
-+                struct ww_acquire_ctx *ww_ctx)
- {
-       struct rt_mutex_waiter waiter;
-       unsigned long flags;
-       int ret = 0;
--      debug_rt_mutex_init_waiter(&waiter);
--      RB_CLEAR_NODE(&waiter.pi_tree_entry);
--      RB_CLEAR_NODE(&waiter.tree_entry);
-+      rt_mutex_init_waiter(&waiter, false);
-       /*
-        * Technically we could use raw_spin_[un]lock_irq() here, but this can
-@@ -1187,6 +1765,8 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state,
++int __sched rt_mutex_slowlock_locked(struct rt_mutex *lock, int state,
++                                   struct hrtimer_sleeper *timeout,
++                                   enum rtmutex_chainwalk chwalk,
++                                   struct ww_acquire_ctx *ww_ctx,
++                                   struct rt_mutex_waiter *waiter)
++{
++      int ret;
  
        /* Try to acquire the lock again: */
        if (try_to_take_rt_mutex(lock, current, NULL)) {
+-              raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
 +              if (ww_ctx)
 +                      ww_mutex_account_lock(lock, ww_ctx);
-               raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
                return 0;
        }
-@@ -1201,13 +1781,23 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state,
  
-       if (likely(!ret))
+@@ -1261,17 +1779,27 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state,
+       if (unlikely(timeout))
+               hrtimer_start_expires(&timeout->timer, HRTIMER_MODE_ABS);
+-      ret = task_blocks_on_rt_mutex(lock, &waiter, current, chwalk);
++      ret = task_blocks_on_rt_mutex(lock, waiter, current, chwalk);
+-      if (likely(!ret))
++      if (likely(!ret)) {
                /* sleep on the mutex */
 -              ret = __rt_mutex_slowlock(lock, state, timeout, &waiter);
-+              ret = __rt_mutex_slowlock(lock, state, timeout, &waiter,
++              ret = __rt_mutex_slowlock(lock, state, timeout, waiter,
 +                                        ww_ctx);
-+      else if (ww_ctx) {
++      else if (ww_ctx) {
 +              /* ww_mutex received EDEADLK, let it become EALREADY */
 +              ret = __mutex_lock_check_stamp(lock, ww_ctx);
 +              BUG_ON(!ret);
@@ -14920,18 +15624,61 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
        if (unlikely(ret)) {
                __set_current_state(TASK_RUNNING);
                if (rt_mutex_has_waiters(lock))
-                       remove_waiter(lock, &waiter);
+-                      remove_waiter(lock, &waiter);
 -              rt_mutex_handle_deadlock(ret, chwalk, &waiter);
++                      remove_waiter(lock, waiter);
 +              /* ww_mutex want to report EDEADLK/EALREADY, let them */
 +              if (!ww_ctx)
-+                      rt_mutex_handle_deadlock(ret, chwalk, &waiter);
++                      rt_mutex_handle_deadlock(ret, chwalk, waiter);
 +      } else if (ww_ctx) {
 +              ww_mutex_account_lock(lock, ww_ctx);
        }
  
        /*
-@@ -1267,7 +1857,8 @@ static inline int rt_mutex_slowtrylock(struct rt_mutex *lock)
-  * Return whether the current task needs to undo a potential priority boosting.
+@@ -1279,6 +1807,36 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state,
+        * unconditionally. We might have to fix that up.
+        */
+       fixup_rt_mutex_waiters(lock);
++      return ret;
++}
++
++/*
++ * Slow path lock function:
++ */
++static int __sched
++rt_mutex_slowlock(struct rt_mutex *lock, int state,
++                struct hrtimer_sleeper *timeout,
++                enum rtmutex_chainwalk chwalk,
++                struct ww_acquire_ctx *ww_ctx)
++{
++      struct rt_mutex_waiter waiter;
++      unsigned long flags;
++      int ret = 0;
++
++      rt_mutex_init_waiter(&waiter, false);
++
++      /*
++       * Technically we could use raw_spin_[un]lock_irq() here, but this can
++       * be called in early boot if the cmpxchg() fast path is disabled
++       * (debug, no architecture support). In this case we will acquire the
++       * rtmutex with lock->wait_lock held. But we cannot unconditionally
++       * enable interrupts in that early boot case. So we need to use the
++       * irqsave/restore variants.
++       */
++      raw_spin_lock_irqsave(&lock->wait_lock, flags);
++
++      ret = rt_mutex_slowlock_locked(lock, state, timeout, chwalk, ww_ctx,
++                                     &waiter);
+       raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
+@@ -1328,10 +1886,12 @@ static inline int rt_mutex_slowtrylock(struct rt_mutex *lock)
+ /*
+  * Slow path to release a rt-mutex.
+- * Return whether the current task needs to undo a potential priority boosting.
++ *
++ * Return whether the current task needs to call rt_mutex_postunlock().
   */
  static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
 -                                      struct wake_q_head *wake_q)
@@ -14940,16 +15687,31 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
  {
        unsigned long flags;
  
-@@ -1323,7 +1914,7 @@ static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
+@@ -1340,8 +1900,6 @@ static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
+       debug_rt_mutex_unlock(lock);
+-      rt_mutex_deadlock_account_unlock(current);
+-
+       /*
+        * We must be careful here if the fast path is enabled. If we
+        * have no waiters queued we cannot set owner to NULL here
+@@ -1387,12 +1945,10 @@ static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
         *
         * Queue the next waiter for wakeup once we release the wait_lock.
         */
 -      mark_wakeup_next_waiter(wake_q, lock);
+-
 +      mark_wakeup_next_waiter(wake_q, wake_sleeper_q, lock);
        raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  
-@@ -1339,31 +1930,36 @@ static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
+-      /* check PI boosting */
+-      return true;
++      return true; /* call rt_mutex_postunlock() */
+ }
+ /*
+@@ -1403,63 +1959,97 @@ static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
   */
  static inline int
  rt_mutex_fastlock(struct rt_mutex *lock, int state,
@@ -14960,13 +15722,23 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +                              enum rtmutex_chainwalk chwalk,
 +                              struct ww_acquire_ctx *ww_ctx))
  {
-       if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
-               rt_mutex_deadlock_account_lock(lock, current);
+-      if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
+-              rt_mutex_deadlock_account_lock(lock, current);
++      if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current)))
                return 0;
-       } else
+-      } else
 -              return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK);
-+              return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK,
-+                            ww_ctx);
++
++      /*
++       * If rt_mutex blocks, the function sched_submit_work will not call
++       * blk_schedule_flush_plug (because tsk_is_pi_blocked would be true).
++       * We must call blk_schedule_flush_plug here, if we don't call it,
++       * a deadlock in device mapper may happen.
++       */
++      if (unlikely(blk_needs_flush_plug(current)))
++              blk_schedule_flush_plug(current);
++
++      return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK, ww_ctx);
  }
  
  static inline int
@@ -14981,16 +15753,45 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +                                    struct ww_acquire_ctx *ww_ctx))
  {
        if (chwalk == RT_MUTEX_MIN_CHAINWALK &&
-           likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
-               rt_mutex_deadlock_account_lock(lock, current);
+-          likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
+-              rt_mutex_deadlock_account_lock(lock, current);
++          likely(rt_mutex_cmpxchg_acquire(lock, NULL, current)))
                return 0;
-       } else
+-      } else
 -              return slowfn(lock, state, timeout, chwalk);
-+              return slowfn(lock, state, timeout, chwalk, ww_ctx);
++
++      if (unlikely(blk_needs_flush_plug(current)))
++              blk_schedule_flush_plug(current);
++
++      return slowfn(lock, state, timeout, chwalk, ww_ctx);
  }
  
  static inline int
-@@ -1380,17 +1976,20 @@ rt_mutex_fasttrylock(struct rt_mutex *lock,
+ rt_mutex_fasttrylock(struct rt_mutex *lock,
+                    int (*slowfn)(struct rt_mutex *lock))
+ {
+-      if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
+-              rt_mutex_deadlock_account_lock(lock, current);
++      if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current)))
+               return 1;
+-      }
++
+       return slowfn(lock);
+ }
++/*
++ * Performs the wakeup of the the top-waiter and re-enables preemption.
++ */
++void rt_mutex_postunlock(struct wake_q_head *wake_q,
++                       struct wake_q_head *wq_sleeper)
++{
++      wake_up_q(wake_q);
++      wake_up_q_sleeper(wq_sleeper);
++
++      /* Pairs with preempt_disable() in rt_mutex_slowunlock() */
++      preempt_enable();
++}
++
  static inline void
  rt_mutex_fastunlock(struct rt_mutex *lock,
                    bool (*slowfn)(struct rt_mutex *lock,
@@ -15001,46 +15802,68 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
        WAKE_Q(wake_q);
 +      WAKE_Q(wake_sleeper_q);
  
-       if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
-               rt_mutex_deadlock_account_unlock(current);
+-      if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
+-              rt_mutex_deadlock_account_unlock(current);
++      if (likely(rt_mutex_cmpxchg_release(lock, current, NULL)))
++              return;
  
-       } else {
+-      } else {
 -              bool deboost = slowfn(lock, &wake_q);
-+              bool deboost = slowfn(lock, &wake_q, &wake_sleeper_q);
++      if (slowfn(lock, &wake_q,  &wake_sleeper_q))
++              rt_mutex_postunlock(&wake_q, &wake_sleeper_q);
++}
+-              wake_up_q(&wake_q);
++/**
++ * rt_mutex_lock_state - lock a rt_mutex with a given state
++ *
++ * @lock:     The rt_mutex to be locked
++ * @state:    The state to set when blocking on the rt_mutex
++ */
++int __sched rt_mutex_lock_state(struct rt_mutex *lock, int state)
++{
++      might_sleep();
  
-               wake_up_q(&wake_q);
-+              wake_up_q_sleeper(&wake_sleeper_q);
+-              /* Undo pi boosting if necessary: */
+-              if (deboost)
+-                      rt_mutex_adjust_prio(current);
+-      }
++      return rt_mutex_fastlock(lock, state, NULL, rt_mutex_slowlock);
+ }
  
-               /* Undo pi boosting if necessary: */
-               if (deboost)
-@@ -1407,7 +2006,7 @@ void __sched rt_mutex_lock(struct rt_mutex *lock)
+ /**
+@@ -1469,15 +2059,13 @@ rt_mutex_fastunlock(struct rt_mutex *lock,
+  */
+ void __sched rt_mutex_lock(struct rt_mutex *lock)
  {
-       might_sleep();
+-      might_sleep();
+-
 -      rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
-+      rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, NULL, rt_mutex_slowlock);
++      rt_mutex_lock_state(lock, TASK_UNINTERRUPTIBLE);
  }
  EXPORT_SYMBOL_GPL(rt_mutex_lock);
  
-@@ -1424,7 +2023,7 @@ int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock)
+ /**
+  * rt_mutex_lock_interruptible - lock a rt_mutex interruptible
+- *
++ **
+  * @lock:             the rt_mutex to be locked
+  *
+  * Returns:
+@@ -1486,23 +2074,32 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock);
+  */
+ int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock)
  {
-       might_sleep();
+-      might_sleep();
+-
 -      return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
-+      return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, NULL, rt_mutex_slowlock);
++      return rt_mutex_lock_state(lock, TASK_INTERRUPTIBLE);
  }
  EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
  
-@@ -1437,11 +2036,30 @@ int rt_mutex_timed_futex_lock(struct rt_mutex *lock,
-       might_sleep();
-       return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
--                                     RT_MUTEX_FULL_CHAINWALK,
-+                                     RT_MUTEX_FULL_CHAINWALK, NULL,
-                                      rt_mutex_slowlock);
- }
- /**
+-/*
+- * Futex variant with full deadlock detection.
++/**
 + * rt_mutex_lock_killable - lock a rt_mutex killable
 + *
 + * @lock:              the rt_mutex to be locked
@@ -15049,21 +15872,29 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 + * Returns:
 + *  0          on success
 + * -EINTR      when interrupted by a signal
-+ * -EDEADLK    when the lock would deadlock (when deadlock detection is on)
-+ */
+  */
+-int rt_mutex_timed_futex_lock(struct rt_mutex *lock,
+-                            struct hrtimer_sleeper *timeout)
 +int __sched rt_mutex_lock_killable(struct rt_mutex *lock)
-+{
-+      might_sleep();
-+
-+      return rt_mutex_fastlock(lock, TASK_KILLABLE, NULL, rt_mutex_slowlock);
+ {
+-      might_sleep();
++      return rt_mutex_lock_state(lock, TASK_KILLABLE);
 +}
 +EXPORT_SYMBOL_GPL(rt_mutex_lock_killable);
-+
-+/**
-  * rt_mutex_timed_lock - lock a rt_mutex interruptible
-  *                    the timeout structure is provided
-  *                    by the caller
-@@ -1461,6 +2079,7 @@ rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout)
+-      return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
+-                                     RT_MUTEX_FULL_CHAINWALK,
+-                                     rt_mutex_slowlock);
++/*
++ * Futex variant, must not use fastpath.
++ */
++int __sched rt_mutex_futex_trylock(struct rt_mutex *lock)
++{
++      return rt_mutex_slowtrylock(lock);
+ }
+ /**
+@@ -1525,6 +2122,7 @@ rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout)
  
        return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
                                       RT_MUTEX_MIN_CHAINWALK,
@@ -15071,7 +15902,7 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
                                       rt_mutex_slowlock);
  }
  EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
-@@ -1478,7 +2097,11 @@ EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
+@@ -1542,7 +2140,11 @@ EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
   */
  int __sched rt_mutex_trylock(struct rt_mutex *lock)
  {
@@ -15083,24 +15914,73 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
                return 0;
  
        return rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
-@@ -1504,13 +2127,14 @@ EXPORT_SYMBOL_GPL(rt_mutex_unlock);
-  * required or not.
+@@ -1560,21 +2162,53 @@ void __sched rt_mutex_unlock(struct rt_mutex *lock)
+ }
+ EXPORT_SYMBOL_GPL(rt_mutex_unlock);
++static bool __sched __rt_mutex_unlock_common(struct rt_mutex *lock,
++                                           struct wake_q_head *wake_q,
++                                           struct wake_q_head *wq_sleeper)
++{
++      lockdep_assert_held(&lock->wait_lock);
++
++      debug_rt_mutex_unlock(lock);
++
++      if (!rt_mutex_has_waiters(lock)) {
++              lock->owner = NULL;
++              return false; /* done */
++      }
++
++      /*
++       * We've already deboosted, mark_wakeup_next_waiter() will
++       * retain preempt_disabled when we drop the wait_lock, to
++       * avoid inversion prior to the wakeup.  preempt_disable()
++       * therein pairs with rt_mutex_postunlock().
++       */
++      mark_wakeup_next_waiter(wake_q, wq_sleeper, lock);
++
++      return true; /* call postunlock() */
++}
++
+ /**
+- * rt_mutex_futex_unlock - Futex variant of rt_mutex_unlock
+- * @lock: the rt_mutex to be unlocked
+- *
+- * Returns: true/false indicating whether priority adjustment is
+- * required or not.
++ * Futex variant, that since futex variants do not use the fast-path, can be
++ * simple and will not need to retry.
   */
- bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock,
+-bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock,
 -                                 struct wake_q_head *wqh)
-+                                 struct wake_q_head *wqh,
-+                                 struct wake_q_head *wq_sleeper)
++bool __sched __rt_mutex_futex_unlock(struct rt_mutex *lock,
++                                  struct wake_q_head *wake_q,
++                                  struct wake_q_head *wq_sleeper)
  {
-       if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
-               rt_mutex_deadlock_account_unlock(current);
-               return false;
-       }
+-      if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
+-              rt_mutex_deadlock_account_unlock(current);
+-              return false;
+-      }
 -      return rt_mutex_slowunlock(lock, wqh);
-+      return rt_mutex_slowunlock(lock, wqh, wq_sleeper);
++      return __rt_mutex_unlock_common(lock, wake_q, wq_sleeper);
++}
++
++void __sched rt_mutex_futex_unlock(struct rt_mutex *lock)
++{
++      WAKE_Q(wake_q);
++      WAKE_Q(wake_sleeper_q);
++      bool postunlock;
++
++      raw_spin_lock_irq(&lock->wait_lock);
++      postunlock = __rt_mutex_futex_unlock(lock, &wake_q, &wake_sleeper_q);
++      raw_spin_unlock_irq(&lock->wait_lock);
++
++      if (postunlock)
++              rt_mutex_postunlock(&wake_q, &wake_sleeper_q);
  }
  
  /**
-@@ -1543,13 +2167,12 @@ EXPORT_SYMBOL_GPL(rt_mutex_destroy);
+@@ -1607,13 +2241,12 @@ EXPORT_SYMBOL_GPL(rt_mutex_destroy);
  void __rt_mutex_init(struct rt_mutex *lock, const char *name)
  {
        lock->owner = NULL;
@@ -15115,7 +15995,7 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
  
  /**
   * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
-@@ -1564,7 +2187,7 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init);
+@@ -1628,10 +2261,9 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init);
  void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
                                struct task_struct *proxy_owner)
  {
@@ -15123,11 +16003,44 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +      rt_mutex_init(lock);
        debug_rt_mutex_proxy_lock(lock, proxy_owner);
        rt_mutex_set_owner(lock, proxy_owner);
-       rt_mutex_deadlock_account_lock(lock, proxy_owner);
-@@ -1612,6 +2235,35 @@ int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
-               return 1;
-       }
+-      rt_mutex_deadlock_account_lock(lock, proxy_owner);
+ }
+ /**
+@@ -1647,34 +2279,44 @@ void rt_mutex_proxy_unlock(struct rt_mutex *lock,
+ {
+       debug_rt_mutex_proxy_unlock(lock);
+       rt_mutex_set_owner(lock, NULL);
+-      rt_mutex_deadlock_account_unlock(proxy_owner);
+ }
+-/**
+- * rt_mutex_start_proxy_lock() - Start lock acquisition for another task
+- * @lock:             the rt_mutex to take
+- * @waiter:           the pre-initialized rt_mutex_waiter
+- * @task:             the task to prepare
+- *
+- * Returns:
+- *  0 - task blocked on lock
+- *  1 - acquired the lock for task, caller should wake it up
+- * <0 - error
+- *
+- * Special API call for FUTEX_REQUEUE_PI support.
+- */
+-int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
++int __rt_mutex_start_proxy_lock(struct rt_mutex *lock,
+                             struct rt_mutex_waiter *waiter,
+                             struct task_struct *task)
+ {
+       int ret;
  
+-      raw_spin_lock_irq(&lock->wait_lock);
+-
+-      if (try_to_take_rt_mutex(lock, task, NULL)) {
+-              raw_spin_unlock_irq(&lock->wait_lock);
++      if (try_to_take_rt_mutex(lock, task, NULL))
+               return 1;
++
 +#ifdef CONFIG_PREEMPT_RT_FULL
 +      /*
 +       * In PREEMPT_RT there's an added race.
@@ -15150,17 +16063,15 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +      raw_spin_lock(&task->pi_lock);
 +      if (task->pi_blocked_on) {
 +              raw_spin_unlock(&task->pi_lock);
-+              raw_spin_unlock_irq(&lock->wait_lock);
 +              return -EAGAIN;
-+      }
+       }
 +      task->pi_blocked_on = PI_REQUEUE_INPROGRESS;
 +      raw_spin_unlock(&task->pi_lock);
 +#endif
-+
        /* We enforce deadlock detection for futexes */
        ret = task_blocks_on_rt_mutex(lock, waiter, task,
-                                     RT_MUTEX_FULL_CHAINWALK);
-@@ -1626,7 +2278,7 @@ int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
+@@ -1690,17 +2332,41 @@ int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
                ret = 0;
        }
  
@@ -15168,20 +16079,165 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +      if (ret && rt_mutex_has_waiters(lock))
                remove_waiter(lock, waiter);
  
-       raw_spin_unlock_irq(&lock->wait_lock);
-@@ -1682,7 +2334,7 @@ int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
+-      raw_spin_unlock_irq(&lock->wait_lock);
+-
+       debug_rt_mutex_print_deadlock(waiter);
+       return ret;
+ }
+ /**
++ * rt_mutex_start_proxy_lock() - Start lock acquisition for another task
++ * @lock:             the rt_mutex to take
++ * @waiter:           the pre-initialized rt_mutex_waiter
++ * @task:             the task to prepare
++ *
++ * Returns:
++ *  0 - task blocked on lock
++ *  1 - acquired the lock for task, caller should wake it up
++ * <0 - error
++ *
++ * Special API call for FUTEX_REQUEUE_PI support.
++ */
++int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
++                            struct rt_mutex_waiter *waiter,
++                            struct task_struct *task)
++{
++      int ret;
++
++      raw_spin_lock_irq(&lock->wait_lock);
++      ret = __rt_mutex_start_proxy_lock(lock, waiter, task);
++      raw_spin_unlock_irq(&lock->wait_lock);
++
++      return ret;
++}
++
++/**
+  * rt_mutex_next_owner - return the next owner of the lock
+  *
+  * @lock: the rt lock query
+@@ -1721,36 +2387,106 @@ struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock)
+ }
+ /**
+- * rt_mutex_finish_proxy_lock() - Complete lock acquisition
++ * rt_mutex_wait_proxy_lock() - Wait for lock acquisition
+  * @lock:             the rt_mutex we were woken on
+  * @to:                       the timeout, null if none. hrtimer should already have
+  *                    been started.
+  * @waiter:           the pre-initialized rt_mutex_waiter
+  *
+- * Complete the lock acquisition started our behalf by another thread.
++ * Wait for the the lock acquisition started on our behalf by
++ * rt_mutex_start_proxy_lock(). Upon failure, the caller must call
++ * rt_mutex_cleanup_proxy_lock().
+  *
+  * Returns:
+  *  0 - success
+  * <0 - error, one of -EINTR, -ETIMEDOUT
+  *
+- * Special API call for PI-futex requeue support
++ * Special API call for PI-futex support
+  */
+-int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
++int rt_mutex_wait_proxy_lock(struct rt_mutex *lock,
+                              struct hrtimer_sleeper *to,
+                              struct rt_mutex_waiter *waiter)
+ {
++      struct task_struct *tsk = current;
+       int ret;
+       raw_spin_lock_irq(&lock->wait_lock);
+-
++      /* sleep on the mutex */
        set_current_state(TASK_INTERRUPTIBLE);
++      ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter, NULL);
++      /*
++       * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
++       * have to fix that up.
++       */
++      fixup_rt_mutex_waiters(lock);
  
-       /* sleep on the mutex */
+-      /* sleep on the mutex */
 -      ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
-+      ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter, NULL);
++      /*
++       * RT has a problem here when the wait got interrupted by a timeout
++       * or a signal. task->pi_blocked_on is still set. The task must
++       * acquire the hash bucket lock when returning from this function.
++       *
++       * If the hash bucket lock is contended then the
++       * BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on)) in
++       * task_blocks_on_rt_mutex() will trigger. This can be avoided by
++       * clearing task->pi_blocked_on which removes the task from the
++       * boosting chain of the rtmutex. That's correct because the task
++       * is not longer blocked on it.
++       */
++      if (ret) {
++              raw_spin_lock(&tsk->pi_lock);
++              tsk->pi_blocked_on = NULL;
++              raw_spin_unlock(&tsk->pi_lock);
++      }
++      raw_spin_unlock_irq(&lock->wait_lock);
  
-       if (unlikely(ret))
-               remove_waiter(lock, waiter);
-@@ -1697,3 +2349,89 @@ int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
+-      if (unlikely(ret))
+-              remove_waiter(lock, waiter);
++      return ret;
++}
++
++/**
++ * rt_mutex_cleanup_proxy_lock() - Cleanup failed lock acquisition
++ * @lock:             the rt_mutex we were woken on
++ * @waiter:           the pre-initialized rt_mutex_waiter
++ *
++ * Attempt to clean up after a failed rt_mutex_wait_proxy_lock().
++ *
++ * Unless we acquired the lock; we're still enqueued on the wait-list and can
++ * in fact still be granted ownership until we're removed. Therefore we can
++ * find we are in fact the owner and must disregard the
++ * rt_mutex_wait_proxy_lock() failure.
++ *
++ * Returns:
++ *  true  - did the cleanup, we done.
++ *  false - we acquired the lock after rt_mutex_wait_proxy_lock() returned,
++ *          caller should disregards its return value.
++ *
++ * Special API call for PI-futex support
++ */
++bool rt_mutex_cleanup_proxy_lock(struct rt_mutex *lock,
++                               struct rt_mutex_waiter *waiter)
++{
++      bool cleanup = false;
  
-       return ret;
- }
++      raw_spin_lock_irq(&lock->wait_lock);
++      /*
++       * Do an unconditional try-lock, this deals with the lock stealing
++       * state where __rt_mutex_futex_unlock() -> mark_wakeup_next_waiter()
++       * sets a NULL owner.
++       *
++       * We're not interested in the return value, because the subsequent
++       * test on rt_mutex_owner() will infer that. If the trylock succeeded,
++       * we will own the lock and it will have removed the waiter. If we
++       * failed the trylock, we're still not owner and we need to remove
++       * ourselves.
++       */
++      try_to_take_rt_mutex(lock, current, waiter);
++      /*
++       * Unless we're the owner; we're still enqueued on the wait_list.
++       * So check if we became owner, if not, take us off the wait_list.
++       */
++      if (rt_mutex_owner(lock) != current) {
++              remove_waiter(lock, waiter);
++              cleanup = true;
++      }
+       /*
+        * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
+        * have to fix that up.
+@@ -1759,5 +2495,91 @@ int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
+       raw_spin_unlock_irq(&lock->wait_lock);
++      return cleanup;
++}
 +
 +static inline int
 +ww_mutex_deadlock_injection(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
@@ -15242,8 +16298,8 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +      else if (!ret && ww_ctx->acquired > 1)
 +              return ww_mutex_deadlock_injection(lock, ww_ctx);
 +
-+      return ret;
-+}
+       return ret;
+ }
 +EXPORT_SYMBOL_GPL(__ww_mutex_lock);
 +
 +void __sched ww_mutex_unlock(struct ww_mutex *lock)
@@ -15268,11 +16324,24 @@ index 1ec0f48962b3..2576f7ccf8e2 100644
 +}
 +EXPORT_SYMBOL(ww_mutex_unlock);
 +#endif
+diff --git a/kernel/locking/rtmutex.h b/kernel/locking/rtmutex.h
+index c4060584c407..6607802efa8b 100644
+--- a/kernel/locking/rtmutex.h
++++ b/kernel/locking/rtmutex.h
+@@ -11,8 +11,6 @@
+  */
+ #define rt_mutex_deadlock_check(l)                    (0)
+-#define rt_mutex_deadlock_account_lock(m, t)          do { } while (0)
+-#define rt_mutex_deadlock_account_unlock(l)           do { } while (0)
+ #define debug_rt_mutex_init_waiter(w)                 do { } while (0)
+ #define debug_rt_mutex_free_waiter(w)                 do { } while (0)
+ #define debug_rt_mutex_lock(l)                                do { } while (0)
 diff --git a/kernel/locking/rtmutex_common.h b/kernel/locking/rtmutex_common.h
-index 4f5f83c7d2d3..289f062f26cd 100644
+index e317e1cbb3eb..64d89d780059 100644
 --- a/kernel/locking/rtmutex_common.h
 +++ b/kernel/locking/rtmutex_common.h
-@@ -27,6 +27,7 @@ struct rt_mutex_waiter {
+@@ -27,12 +27,14 @@ struct rt_mutex_waiter {
        struct rb_node          pi_tree_entry;
        struct task_struct      *task;
        struct rt_mutex         *lock;
@@ -15280,7 +16349,14 @@ index 4f5f83c7d2d3..289f062f26cd 100644
  #ifdef CONFIG_DEBUG_RT_MUTEXES
        unsigned long           ip;
        struct pid              *deadlock_task_pid;
-@@ -97,6 +98,9 @@ enum rtmutex_chainwalk {
+       struct rt_mutex         *deadlock_lock;
+ #endif
+       int prio;
++      u64 deadline;
+ };
+ /*
+@@ -98,21 +100,45 @@ enum rtmutex_chainwalk {
  /*
   * PI-futex support (proxy locking functions, etc.):
   */
@@ -15290,31 +16366,323 @@ index 4f5f83c7d2d3..289f062f26cd 100644
  extern struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock);
  extern void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
                                       struct task_struct *proxy_owner);
-@@ -110,7 +114,8 @@ extern int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
-                                     struct rt_mutex_waiter *waiter);
- extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
- extern bool rt_mutex_futex_unlock(struct rt_mutex *lock,
+ extern void rt_mutex_proxy_unlock(struct rt_mutex *lock,
+                                 struct task_struct *proxy_owner);
++extern void rt_mutex_init_waiter(struct rt_mutex_waiter *waiter, bool savetate);
++extern int __rt_mutex_start_proxy_lock(struct rt_mutex *lock,
++                                   struct rt_mutex_waiter *waiter,
++                                   struct task_struct *task);
+ extern int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
+                                    struct rt_mutex_waiter *waiter,
+                                    struct task_struct *task);
+-extern int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
+-                                    struct hrtimer_sleeper *to,
+-                                    struct rt_mutex_waiter *waiter);
+-extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
+-extern bool rt_mutex_futex_unlock(struct rt_mutex *lock,
 -                                struct wake_q_head *wqh);
-+                                struct wake_q_head *wqh,
-+                                struct wake_q_head *wq_sleeper);
- extern void rt_mutex_adjust_prio(struct task_struct *task);
+-extern void rt_mutex_adjust_prio(struct task_struct *task);
++extern int rt_mutex_wait_proxy_lock(struct rt_mutex *lock,
++                             struct hrtimer_sleeper *to,
++                             struct rt_mutex_waiter *waiter);
++extern bool rt_mutex_cleanup_proxy_lock(struct rt_mutex *lock,
++                               struct rt_mutex_waiter *waiter);
++
++extern int rt_mutex_futex_trylock(struct rt_mutex *l);
++
++extern void rt_mutex_futex_unlock(struct rt_mutex *lock);
++extern bool __rt_mutex_futex_unlock(struct rt_mutex *lock,
++                               struct wake_q_head *wqh,
++                               struct wake_q_head *wq_sleeper);
++
++extern void rt_mutex_postunlock(struct wake_q_head *wake_q,
++                              struct wake_q_head *wq_sleeper);
++
++/* RW semaphore special interface */
++struct ww_acquire_ctx;
++
++int __sched rt_mutex_slowlock_locked(struct rt_mutex *lock, int state,
++                                   struct hrtimer_sleeper *timeout,
++                                   enum rtmutex_chainwalk chwalk,
++                                   struct ww_acquire_ctx *ww_ctx,
++                                   struct rt_mutex_waiter *waiter);
  
  #ifdef CONFIG_DEBUG_RT_MUTEXES
-@@ -119,4 +124,14 @@ extern void rt_mutex_adjust_prio(struct task_struct *task);
- # include "rtmutex.h"
- #endif
-+static inline void
-+rt_mutex_init_waiter(struct rt_mutex_waiter *waiter, bool savestate)
+ # include "rtmutex-debug.h"
+diff --git a/kernel/locking/rwsem-rt.c b/kernel/locking/rwsem-rt.c
+new file mode 100644
+index 000000000000..4a708ffcded6
+--- /dev/null
++++ b/kernel/locking/rwsem-rt.c
+@@ -0,0 +1,268 @@
++/*
++ */
++#include <linux/rwsem.h>
++#include <linux/sched.h>
++#include <linux/export.h>
++
++#include "rtmutex_common.h"
++
++/*
++ * RT-specific reader/writer semaphores
++ *
++ * down_write()
++ *  1) Lock sem->rtmutex
++ *  2) Remove the reader BIAS to force readers into the slow path
++ *  3) Wait until all readers have left the critical region
++ *  4) Mark it write locked
++ *
++ * up_write()
++ *  1) Remove the write locked marker
++ *  2) Set the reader BIAS so readers can use the fast path again
++ *  3) Unlock sem->rtmutex to release blocked readers
++ *
++ * down_read()
++ *  1) Try fast path acquisition (reader BIAS is set)
++ *  2) Take sem->rtmutex.wait_lock which protects the writelocked flag
++ *  3) If !writelocked, acquire it for read
++ *  4) If writelocked, block on sem->rtmutex
++ *  5) unlock sem->rtmutex, goto 1)
++ *
++ * up_read()
++ *  1) Try fast path release (reader count != 1)
++ *  2) Wake the writer waiting in down_write()#3
++ *
++ * down_read()#3 has the consequence, that rw semaphores on RT are not writer
++ * fair, but writers, which should be avoided in RT tasks (think mmap_sem),
++ * are subject to the rtmutex priority/DL inheritance mechanism.
++ *
++ * It's possible to make the rw semaphores writer fair by keeping a list of
++ * active readers. A blocked writer would force all newly incoming readers to
++ * block on the rtmutex, but the rtmutex would have to be proxy locked for one
++ * reader after the other. We can't use multi-reader inheritance because there
++ * is no way to support that with SCHED_DEADLINE. Implementing the one by one
++ * reader boosting/handover mechanism is a major surgery for a very dubious
++ * value.
++ *
++ * The risk of writer starvation is there, but the pathological use cases
++ * which trigger it are not necessarily the typical RT workloads.
++ */
++
++void __rwsem_init(struct rw_semaphore *sem, const char *name,
++                struct lock_class_key *key)
++{
++#ifdef CONFIG_DEBUG_LOCK_ALLOC
++      /*
++       * Make sure we are not reinitializing a held semaphore:
++       */
++      debug_check_no_locks_freed((void *)sem, sizeof(*sem));
++      lockdep_init_map(&sem->dep_map, name, key, 0);
++#endif
++      atomic_set(&sem->readers, READER_BIAS);
++}
++EXPORT_SYMBOL(__rwsem_init);
++
++int __down_read_trylock(struct rw_semaphore *sem)
++{
++      int r, old;
++
++      /*
++       * Increment reader count, if sem->readers < 0, i.e. READER_BIAS is
++       * set.
++       */
++      for (r = atomic_read(&sem->readers); r < 0;) {
++              old = atomic_cmpxchg(&sem->readers, r, r + 1);
++              if (likely(old == r))
++                      return 1;
++              r = old;
++      }
++      return 0;
++}
++
++void __sched __down_read(struct rw_semaphore *sem)
++{
++      struct rt_mutex *m = &sem->rtmutex;
++      struct rt_mutex_waiter waiter;
++
++      if (__down_read_trylock(sem))
++              return;
++
++      might_sleep();
++      raw_spin_lock_irq(&m->wait_lock);
++      /*
++       * Allow readers as long as the writer has not completely
++       * acquired the semaphore for write.
++       */
++      if (atomic_read(&sem->readers) != WRITER_BIAS) {
++              atomic_inc(&sem->readers);
++              raw_spin_unlock_irq(&m->wait_lock);
++              return;
++      }
++
++      /*
++       * Call into the slow lock path with the rtmutex->wait_lock
++       * held, so this can't result in the following race:
++       *
++       * Reader1              Reader2         Writer
++       *                      down_read()
++       *                                      down_write()
++       *                                      rtmutex_lock(m)
++       *                                      swait()
++       * down_read()
++       * unlock(m->wait_lock)
++       *                      up_read()
++       *                      swake()
++       *                                      lock(m->wait_lock)
++       *                                      sem->writelocked=true
++       *                                      unlock(m->wait_lock)
++       *
++       *                                      up_write()
++       *                                      sem->writelocked=false
++       *                                      rtmutex_unlock(m)
++       *                      down_read()
++       *                                      down_write()
++       *                                      rtmutex_lock(m)
++       *                                      swait()
++       * rtmutex_lock(m)
++       *
++       * That would put Reader1 behind the writer waiting on
++       * Reader2 to call up_read() which might be unbound.
++       */
++      rt_mutex_init_waiter(&waiter, false);
++      rt_mutex_slowlock_locked(m, TASK_UNINTERRUPTIBLE, NULL,
++                               RT_MUTEX_MIN_CHAINWALK, NULL,
++                               &waiter);
++      /*
++       * The slowlock() above is guaranteed to return with the rtmutex is
++       * now held, so there can't be a writer active. Increment the reader
++       * count and immediately drop the rtmutex again.
++       */
++      atomic_inc(&sem->readers);
++      raw_spin_unlock_irq(&m->wait_lock);
++      rt_mutex_unlock(m);
++
++      debug_rt_mutex_free_waiter(&waiter);
++}
++
++void __up_read(struct rw_semaphore *sem)
++{
++      struct rt_mutex *m = &sem->rtmutex;
++      struct task_struct *tsk;
++
++      /*
++       * sem->readers can only hit 0 when a writer is waiting for the
++       * active readers to leave the critical region.
++       */
++      if (!atomic_dec_and_test(&sem->readers))
++              return;
++
++      might_sleep();
++      raw_spin_lock_irq(&m->wait_lock);
++      /*
++       * Wake the writer, i.e. the rtmutex owner. It might release the
++       * rtmutex concurrently in the fast path (due to a signal), but to
++       * clean up the rwsem it needs to acquire m->wait_lock. The worst
++       * case which can happen is a spurious wakeup.
++       */
++      tsk = rt_mutex_owner(m);
++      if (tsk)
++              wake_up_process(tsk);
++
++      raw_spin_unlock_irq(&m->wait_lock);
++}
++
++static void __up_write_unlock(struct rw_semaphore *sem, int bias,
++                            unsigned long flags)
++{
++      struct rt_mutex *m = &sem->rtmutex;
++
++      atomic_add(READER_BIAS - bias, &sem->readers);
++      raw_spin_unlock_irqrestore(&m->wait_lock, flags);
++      rt_mutex_unlock(m);
++}
++
++static int __sched __down_write_common(struct rw_semaphore *sem, int state)
++{
++      struct rt_mutex *m = &sem->rtmutex;
++      unsigned long flags;
++
++      /* Take the rtmutex as a first step */
++      if (rt_mutex_lock_state(m, state))
++              return -EINTR;
++
++      /* Force readers into slow path */
++      atomic_sub(READER_BIAS, &sem->readers);
++      might_sleep();
++
++      set_current_state(state);
++      for (;;) {
++              raw_spin_lock_irqsave(&m->wait_lock, flags);
++              /* Have all readers left the critical region? */
++              if (!atomic_read(&sem->readers)) {
++                      atomic_set(&sem->readers, WRITER_BIAS);
++                      __set_current_state(TASK_RUNNING);
++                      raw_spin_unlock_irqrestore(&m->wait_lock, flags);
++                      return 0;
++              }
++
++              if (signal_pending_state(state, current)) {
++                      __set_current_state(TASK_RUNNING);
++                      __up_write_unlock(sem, 0, flags);
++                      return -EINTR;
++              }
++              raw_spin_unlock_irqrestore(&m->wait_lock, flags);
++
++              if (atomic_read(&sem->readers) != 0) {
++                      schedule();
++                      set_current_state(state);
++              }
++      }
++}
++
++void __sched __down_write(struct rw_semaphore *sem)
++{
++      __down_write_common(sem, TASK_UNINTERRUPTIBLE);
++}
++
++int __sched __down_write_killable(struct rw_semaphore *sem)
++{
++      return __down_write_common(sem, TASK_KILLABLE);
++}
++
++int __down_write_trylock(struct rw_semaphore *sem)
++{
++      struct rt_mutex *m = &sem->rtmutex;
++      unsigned long flags;
++
++      if (!rt_mutex_trylock(m))
++              return 0;
++
++      atomic_sub(READER_BIAS, &sem->readers);
++
++      raw_spin_lock_irqsave(&m->wait_lock, flags);
++      if (!atomic_read(&sem->readers)) {
++              atomic_set(&sem->readers, WRITER_BIAS);
++              raw_spin_unlock_irqrestore(&m->wait_lock, flags);
++              return 1;
++      }
++      __up_write_unlock(sem, 0, flags);
++      return 0;
++}
++
++void __up_write(struct rw_semaphore *sem)
 +{
-+      debug_rt_mutex_init_waiter(waiter);
-+      waiter->task = NULL;
-+      waiter->savestate = savestate;
-+      RB_CLEAR_NODE(&waiter->pi_tree_entry);
-+      RB_CLEAR_NODE(&waiter->tree_entry);
++      struct rt_mutex *m = &sem->rtmutex;
++      unsigned long flags;
++
++      raw_spin_lock_irqsave(&m->wait_lock, flags);
++      __up_write_unlock(sem, WRITER_BIAS, flags);
 +}
 +
- #endif
++void __downgrade_write(struct rw_semaphore *sem)
++{
++      struct rt_mutex *m = &sem->rtmutex;
++      unsigned long flags;
++
++      raw_spin_lock_irqsave(&m->wait_lock, flags);
++      /* Release it and account current as reader */
++      __up_write_unlock(sem, WRITER_BIAS - 1, flags);
++}
 diff --git a/kernel/locking/spinlock.c b/kernel/locking/spinlock.c
 index db3ccb1dd614..909779647bd1 100644
 --- a/kernel/locking/spinlock.c
@@ -15350,7 +16718,7 @@ index db3ccb1dd614..909779647bd1 100644
  
  void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass)
 diff --git a/kernel/locking/spinlock_debug.c b/kernel/locking/spinlock_debug.c
-index 0374a596cffa..94970338d518 100644
+index 9aa0fccd5d43..76d0b40d9193 100644
 --- a/kernel/locking/spinlock_debug.c
 +++ b/kernel/locking/spinlock_debug.c
 @@ -31,6 +31,7 @@ void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name,
@@ -15369,7 +16737,7 @@ index 0374a596cffa..94970338d518 100644
  
  static void spin_dump(raw_spinlock_t *lock, const char *msg)
  {
-@@ -159,6 +161,7 @@ void do_raw_spin_unlock(raw_spinlock_t *lock)
+@@ -135,6 +137,7 @@ void do_raw_spin_unlock(raw_spinlock_t *lock)
        arch_spin_unlock(&lock->raw_lock);
  }
  
@@ -15377,17 +16745,91 @@ index 0374a596cffa..94970338d518 100644
  static void rwlock_bug(rwlock_t *lock, const char *msg)
  {
        if (!debug_locks_off())
-@@ -300,3 +303,5 @@ void do_raw_write_unlock(rwlock_t *lock)
+@@ -224,3 +227,5 @@ void do_raw_write_unlock(rwlock_t *lock)
        debug_write_unlock(lock);
        arch_write_unlock(&lock->raw_lock);
  }
 +
 +#endif
+diff --git a/kernel/module.c b/kernel/module.c
+index 0e54d5bf0097..f27764fbfa24 100644
+--- a/kernel/module.c
++++ b/kernel/module.c
+@@ -660,16 +660,7 @@ static void percpu_modcopy(struct module *mod,
+               memcpy(per_cpu_ptr(mod->percpu, cpu), from, size);
+ }
+-/**
+- * is_module_percpu_address - test whether address is from module static percpu
+- * @addr: address to test
+- *
+- * Test whether @addr belongs to module static percpu area.
+- *
+- * RETURNS:
+- * %true if @addr is from module static percpu area
+- */
+-bool is_module_percpu_address(unsigned long addr)
++bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
+ {
+       struct module *mod;
+       unsigned int cpu;
+@@ -683,9 +674,15 @@ bool is_module_percpu_address(unsigned long addr)
+                       continue;
+               for_each_possible_cpu(cpu) {
+                       void *start = per_cpu_ptr(mod->percpu, cpu);
+-
+-                      if ((void *)addr >= start &&
+-                          (void *)addr < start + mod->percpu_size) {
++                      void *va = (void *)addr;
++
++                      if (va >= start && va < start + mod->percpu_size) {
++                              if (can_addr) {
++                                      *can_addr = (unsigned long) (va - start);
++                                      *can_addr += (unsigned long)
++                                              per_cpu_ptr(mod->percpu,
++                                                          get_boot_cpu_id());
++                              }
+                               preempt_enable();
+                               return true;
+                       }
+@@ -696,6 +693,20 @@ bool is_module_percpu_address(unsigned long addr)
+       return false;
+ }
++/**
++ * is_module_percpu_address - test whether address is from module static percpu
++ * @addr: address to test
++ *
++ * Test whether @addr belongs to module static percpu area.
++ *
++ * RETURNS:
++ * %true if @addr is from module static percpu area
++ */
++bool is_module_percpu_address(unsigned long addr)
++{
++      return __is_module_percpu_address(addr, NULL);
++}
++
+ #else /* ... !CONFIG_SMP */
+ static inline void __percpu *mod_percpu(struct module *mod)
+@@ -727,6 +738,11 @@ bool is_module_percpu_address(unsigned long addr)
+       return false;
+ }
++bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
++{
++      return false;
++}
++
+ #endif /* CONFIG_SMP */
+ #define MODINFO_ATTR(field)   \
 diff --git a/kernel/panic.c b/kernel/panic.c
-index ca8cea1ef673..6b698115f003 100644
+index dbec387099b1..b67a4803ff2b 100644
 --- a/kernel/panic.c
 +++ b/kernel/panic.c
-@@ -449,9 +449,11 @@ static u64 oops_id;
+@@ -482,9 +482,11 @@ static u64 oops_id;
  
  static int init_oops_id(void)
  {
@@ -15400,7 +16842,7 @@ index ca8cea1ef673..6b698115f003 100644
  
        return 0;
 diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
-index 33c79b6105c5..f53375bc77df 100644
+index b26dbc48c75b..968255f27a33 100644
 --- a/kernel/power/hibernate.c
 +++ b/kernel/power/hibernate.c
 @@ -286,6 +286,8 @@ static int create_image(int platform_mode)
@@ -15412,7 +16854,7 @@ index 33c79b6105c5..f53375bc77df 100644
        error = syscore_suspend();
        if (error) {
                printk(KERN_ERR "PM: Some system devices failed to power down, "
-@@ -315,6 +317,7 @@ static int create_image(int platform_mode)
+@@ -317,6 +319,7 @@ static int create_image(int platform_mode)
        syscore_resume();
  
   Enable_irqs:
@@ -15420,7 +16862,7 @@ index 33c79b6105c5..f53375bc77df 100644
        local_irq_enable();
  
   Enable_cpus:
-@@ -444,6 +447,7 @@ static int resume_target_kernel(bool platform_mode)
+@@ -446,6 +449,7 @@ static int resume_target_kernel(bool platform_mode)
                goto Enable_cpus;
  
        local_irq_disable();
@@ -15428,7 +16870,7 @@ index 33c79b6105c5..f53375bc77df 100644
  
        error = syscore_suspend();
        if (error)
-@@ -477,6 +481,7 @@ static int resume_target_kernel(bool platform_mode)
+@@ -479,6 +483,7 @@ static int resume_target_kernel(bool platform_mode)
        syscore_resume();
  
   Enable_irqs:
@@ -15436,7 +16878,7 @@ index 33c79b6105c5..f53375bc77df 100644
        local_irq_enable();
  
   Enable_cpus:
-@@ -562,6 +567,7 @@ int hibernation_platform_enter(void)
+@@ -564,6 +569,7 @@ int hibernation_platform_enter(void)
                goto Enable_cpus;
  
        local_irq_disable();
@@ -15444,7 +16886,7 @@ index 33c79b6105c5..f53375bc77df 100644
        syscore_suspend();
        if (pm_wakeup_pending()) {
                error = -EAGAIN;
-@@ -574,6 +580,7 @@ int hibernation_platform_enter(void)
+@@ -576,6 +582,7 @@ int hibernation_platform_enter(void)
  
   Power_up:
        syscore_resume();
@@ -15452,7 +16894,7 @@ index 33c79b6105c5..f53375bc77df 100644
        local_irq_enable();
  
   Enable_cpus:
-@@ -674,6 +681,10 @@ static int load_image_and_restore(void)
+@@ -676,6 +683,10 @@ static int load_image_and_restore(void)
        return error;
  }
  
@@ -15463,7 +16905,7 @@ index 33c79b6105c5..f53375bc77df 100644
  /**
   * hibernate - Carry out system hibernation, including saving the image.
   */
-@@ -687,6 +698,8 @@ int hibernate(void)
+@@ -689,6 +700,8 @@ int hibernate(void)
                return -EPERM;
        }
  
@@ -15472,7 +16914,7 @@ index 33c79b6105c5..f53375bc77df 100644
        lock_system_sleep();
        /* The snapshot device should not be opened while we're running */
        if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
-@@ -764,6 +777,7 @@ int hibernate(void)
+@@ -766,6 +779,7 @@ int hibernate(void)
        atomic_inc(&snapshot_device_available);
   Unlock:
        unlock_system_sleep();
@@ -15481,10 +16923,10 @@ index 33c79b6105c5..f53375bc77df 100644
  }
  
 diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
-index 0acab9d7f96f..aac06aad757c 100644
+index 6ccb08f57fcb..c8cbb5ed2fe3 100644
 --- a/kernel/power/suspend.c
 +++ b/kernel/power/suspend.c
-@@ -361,6 +361,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
+@@ -369,6 +369,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
        arch_suspend_disable_irqs();
        BUG_ON(!irqs_disabled());
  
@@ -15493,7 +16935,7 @@ index 0acab9d7f96f..aac06aad757c 100644
        error = syscore_suspend();
        if (!error) {
                *wakeup = pm_wakeup_pending();
-@@ -377,6 +379,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
+@@ -385,6 +387,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
                syscore_resume();
        }
  
@@ -15502,7 +16944,7 @@ index 0acab9d7f96f..aac06aad757c 100644
        arch_suspend_enable_irqs();
        BUG_ON(irqs_disabled());
  
-@@ -519,6 +523,8 @@ static int enter_state(suspend_state_t state)
+@@ -527,6 +531,8 @@ static int enter_state(suspend_state_t state)
        return error;
  }
  
@@ -15511,7 +16953,7 @@ index 0acab9d7f96f..aac06aad757c 100644
  /**
   * pm_suspend - Externally visible function for suspending the system.
   * @state: System sleep state to enter.
-@@ -533,6 +539,8 @@ int pm_suspend(suspend_state_t state)
+@@ -541,6 +547,8 @@ int pm_suspend(suspend_state_t state)
        if (state <= PM_SUSPEND_ON || state >= PM_SUSPEND_MAX)
                return -EINVAL;
  
@@ -15520,7 +16962,7 @@ index 0acab9d7f96f..aac06aad757c 100644
        error = enter_state(state);
        if (error) {
                suspend_stats.fail++;
-@@ -540,6 +548,7 @@ int pm_suspend(suspend_state_t state)
+@@ -548,6 +556,7 @@ int pm_suspend(suspend_state_t state)
        } else {
                suspend_stats.success++;
        }
@@ -15529,7 +16971,7 @@ index 0acab9d7f96f..aac06aad757c 100644
  }
  EXPORT_SYMBOL(pm_suspend);
 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
-index eea6dbc2d8cf..6f01c7ecb45e 100644
+index 9c5b231684d0..cf15bdb6855b 100644
 --- a/kernel/printk/printk.c
 +++ b/kernel/printk/printk.c
 @@ -351,6 +351,65 @@ __packed __aligned(4)
@@ -15598,7 +17040,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
  #ifdef CONFIG_PRINTK
  DECLARE_WAIT_QUEUE_HEAD(log_wait);
  /* the next printk record to read by syslog(READ) or /proc/kmsg */
-@@ -1340,6 +1399,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
+@@ -1337,6 +1396,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
  {
        char *text;
        int len = 0;
@@ -15606,7 +17048,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
  
        text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
        if (!text)
-@@ -1351,6 +1411,14 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
+@@ -1348,6 +1408,14 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
                u64 seq;
                u32 idx;
                enum log_flags prev;
@@ -15621,7 +17063,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
  
                /*
                 * Find first record that fits, including all following records,
-@@ -1366,6 +1434,14 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
+@@ -1363,6 +1431,14 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
                        prev = msg->flags;
                        idx = log_next(idx);
                        seq++;
@@ -15636,7 +17078,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
                }
  
                /* move first record forward until length fits into the buffer */
-@@ -1379,6 +1455,14 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
+@@ -1376,6 +1452,14 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
                        prev = msg->flags;
                        idx = log_next(idx);
                        seq++;
@@ -15651,7 +17093,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
                }
  
                /* last message fitting into this dump */
-@@ -1419,6 +1503,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
+@@ -1416,6 +1500,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
                clear_seq = log_next_seq;
                clear_idx = log_next_idx;
        }
@@ -15659,7 +17101,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
        raw_spin_unlock_irq(&logbuf_lock);
  
        kfree(text);
-@@ -1572,6 +1657,12 @@ static void call_console_drivers(int level,
+@@ -1569,6 +1654,12 @@ static void call_console_drivers(int level,
        if (!console_drivers)
                return;
  
@@ -15672,7 +17114,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
        for_each_console(con) {
                if (exclusive_console && con != exclusive_console)
                        continue;
-@@ -1587,6 +1678,7 @@ static void call_console_drivers(int level,
+@@ -1584,6 +1675,7 @@ static void call_console_drivers(int level,
                else
                        con->write(con, text, len);
        }
@@ -15680,7 +17122,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
  }
  
  /*
-@@ -1750,6 +1842,13 @@ asmlinkage int vprintk_emit(int facility, int level,
+@@ -1781,6 +1873,13 @@ asmlinkage int vprintk_emit(int facility, int level,
        /* cpu currently holding logbuf_lock in this function */
        static unsigned int logbuf_cpu = UINT_MAX;
  
@@ -15694,7 +17136,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
        if (level == LOGLEVEL_SCHED) {
                level = LOGLEVEL_DEFAULT;
                in_sched = true;
-@@ -1894,13 +1993,23 @@ asmlinkage int vprintk_emit(int facility, int level,
+@@ -1885,13 +1984,23 @@ asmlinkage int vprintk_emit(int facility, int level,
  
        /* If called from the scheduler, we can not call up(). */
        if (!in_sched) {
@@ -15719,7 +17161,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
                        console_unlock();
                lockdep_on();
        }
-@@ -2023,26 +2132,6 @@ DEFINE_PER_CPU(printk_func_t, printk_func);
+@@ -2014,26 +2123,6 @@ DEFINE_PER_CPU(printk_func_t, printk_func);
  
  #endif /* CONFIG_PRINTK */
  
@@ -15746,7 +17188,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
  static int __add_preferred_console(char *name, int idx, char *options,
                                   char *brl_options)
  {
-@@ -2312,11 +2401,16 @@ static void console_cont_flush(char *text, size_t size)
+@@ -2303,11 +2392,16 @@ static void console_cont_flush(char *text, size_t size)
                goto out;
  
        len = cont_print_text(text, size);
@@ -15763,7 +17205,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
        return;
  out:
        raw_spin_unlock_irqrestore(&logbuf_lock, flags);
-@@ -2440,13 +2534,17 @@ void console_unlock(void)
+@@ -2431,13 +2525,17 @@ void console_unlock(void)
                console_idx = log_next(console_idx);
                console_seq++;
                console_prev = msg->flags;
@@ -15782,7 +17224,7 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
                if (do_cond_resched)
                        cond_resched();
        }
-@@ -2498,6 +2596,11 @@ void console_unblank(void)
+@@ -2489,6 +2587,11 @@ void console_unblank(void)
  {
        struct console *c;
  
@@ -15795,10 +17237,10 @@ index eea6dbc2d8cf..6f01c7ecb45e 100644
         * console_unblank can no longer be called in interrupt context unless
         * oops_in_progress is set to 1..
 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
-index 1d3b7665d0be..ce666639789d 100644
+index f39a7be98fc1..583ce3aad891 100644
 --- a/kernel/ptrace.c
 +++ b/kernel/ptrace.c
-@@ -128,7 +128,14 @@ static bool ptrace_freeze_traced(struct task_struct *task)
+@@ -172,7 +172,14 @@ static bool ptrace_freeze_traced(struct task_struct *task)
  
        spin_lock_irq(&task->sighand->siglock);
        if (task_is_traced(task) && !__fatal_signal_pending(task)) {
@@ -15815,7 +17257,7 @@ index 1d3b7665d0be..ce666639789d 100644
        }
        spin_unlock_irq(&task->sighand->siglock);
 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
-index 971e2b138063..a304670fb917 100644
+index bf08fee53dc7..eeb8ce4ad7b6 100644
 --- a/kernel/rcu/rcutorture.c
 +++ b/kernel/rcu/rcutorture.c
 @@ -404,6 +404,7 @@ static struct rcu_torture_ops rcu_ops = {
@@ -15840,10 +17282,10 @@ index 971e2b138063..a304670fb917 100644
   * Don't even think about trying any of these in real life!!!
   * The names includes "busted", and they really means it!
 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
-index 5d80925e7fc8..2b4bc2b2c25a 100644
+index d1a02877a42c..a7b11a29e03a 100644
 --- a/kernel/rcu/tree.c
 +++ b/kernel/rcu/tree.c
-@@ -56,6 +56,11 @@
+@@ -55,6 +55,11 @@
  #include <linux/random.h>
  #include <linux/trace_events.h>
  #include <linux/suspend.h>
@@ -15855,7 +17297,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  
  #include "tree.h"
  #include "rcu.h"
-@@ -259,6 +264,19 @@ void rcu_sched_qs(void)
+@@ -260,6 +265,19 @@ void rcu_sched_qs(void)
                           this_cpu_ptr(&rcu_sched_data), true);
  }
  
@@ -15875,7 +17317,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  void rcu_bh_qs(void)
  {
        if (__this_cpu_read(rcu_bh_data.cpu_no_qs.s)) {
-@@ -268,6 +286,7 @@ void rcu_bh_qs(void)
+@@ -269,6 +287,7 @@ void rcu_bh_qs(void)
                __this_cpu_write(rcu_bh_data.cpu_no_qs.b.norm, false);
        }
  }
@@ -15883,7 +17325,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  
  static DEFINE_PER_CPU(int, rcu_sched_qs_mask);
  
-@@ -448,11 +467,13 @@ EXPORT_SYMBOL_GPL(rcu_batches_started_sched);
+@@ -449,11 +468,13 @@ EXPORT_SYMBOL_GPL(rcu_batches_started_sched);
  /*
   * Return the number of RCU BH batches started thus far for debug & stats.
   */
@@ -15897,7 +17339,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  
  /*
   * Return the number of RCU batches completed thus far for debug & stats.
-@@ -472,6 +493,7 @@ unsigned long rcu_batches_completed_sched(void)
+@@ -473,6 +494,7 @@ unsigned long rcu_batches_completed_sched(void)
  }
  EXPORT_SYMBOL_GPL(rcu_batches_completed_sched);
  
@@ -15905,7 +17347,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  /*
   * Return the number of RCU BH batches completed thus far for debug & stats.
   */
-@@ -480,6 +502,7 @@ unsigned long rcu_batches_completed_bh(void)
+@@ -481,6 +503,7 @@ unsigned long rcu_batches_completed_bh(void)
        return rcu_bh_state.completed;
  }
  EXPORT_SYMBOL_GPL(rcu_batches_completed_bh);
@@ -15913,7 +17355,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  
  /*
   * Return the number of RCU expedited batches completed thus far for
-@@ -503,6 +526,7 @@ unsigned long rcu_exp_batches_completed_sched(void)
+@@ -504,6 +527,7 @@ unsigned long rcu_exp_batches_completed_sched(void)
  }
  EXPORT_SYMBOL_GPL(rcu_exp_batches_completed_sched);
  
@@ -15921,7 +17363,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  /*
   * Force a quiescent state.
   */
-@@ -521,6 +545,13 @@ void rcu_bh_force_quiescent_state(void)
+@@ -522,6 +546,13 @@ void rcu_bh_force_quiescent_state(void)
  }
  EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state);
  
@@ -15935,7 +17377,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  /*
   * Force a quiescent state for RCU-sched.
   */
-@@ -571,9 +602,11 @@ void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags,
+@@ -572,9 +603,11 @@ void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags,
        case RCU_FLAVOR:
                rsp = rcu_state_p;
                break;
@@ -15947,12 +17389,12 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
        case RCU_SCHED_FLAVOR:
                rsp = &rcu_sched_state;
                break;
-@@ -3013,18 +3046,17 @@ __rcu_process_callbacks(struct rcu_state *rsp)
+@@ -3026,18 +3059,17 @@ __rcu_process_callbacks(struct rcu_state *rsp)
  /*
   * Do RCU core processing for the current CPU.
   */
--static void rcu_process_callbacks(struct softirq_action *unused)
-+static void rcu_process_callbacks(void)
+-static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused)
++static __latent_entropy void rcu_process_callbacks(void)
  {
        struct rcu_state *rsp;
  
@@ -15968,7 +17410,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  /*
   * Schedule RCU callback invocation.  If the specified type of RCU
   * does not support RCU priority boosting, just do a direct call,
-@@ -3036,19 +3068,106 @@ static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
+@@ -3049,20 +3081,107 @@ static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
  {
        if (unlikely(!READ_ONCE(rcu_scheduler_fully_active)))
                return;
@@ -15978,8 +17420,8 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
 -      }
 -      invoke_rcu_callbacks_kthread();
 +      rcu_do_batch(rsp, rdp);
- }
++}
++
 +static void rcu_wake_cond(struct task_struct *t, int status)
 +{
 +      /*
@@ -15988,8 +17430,8 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
 +       */
 +      if (t && (status != RCU_KTHREAD_YIELDING || is_idle_task(current)))
 +              wake_up_process(t);
-+}
-+
+ }
 +/*
 + * Wake up this CPU's rcuc kthread to do RCU core processing.
 + */
@@ -16008,8 +17450,8 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
 +      if (t != NULL && current != t)
 +              rcu_wake_cond(t, __this_cpu_read(rcu_cpu_kthread_status));
 +      local_irq_restore(flags);
- }
++}
++
 +static void rcu_cpu_kthread_park(unsigned int cpu)
 +{
 +      per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
@@ -16018,9 +17460,9 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
 +static int rcu_cpu_kthread_should_run(unsigned int cpu)
 +{
 +      return __this_cpu_read(rcu_cpu_has_work);
-+}
-+
-+/*
+ }
+ /*
 + * Per-CPU kernel thread that invokes RCU callbacks.  This replaces the
 + * RCU softirq used in flavors and configurations of RCU that do not
 + * support RCU priority boosting.
@@ -16079,10 +17521,11 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
 +}
 +early_initcall(rcu_spawn_core_kthreads);
 +
- /*
++/*
   * Handle any core-RCU processing required by a call_rcu() invocation.
   */
-@@ -3192,6 +3311,7 @@ void call_rcu_sched(struct rcu_head *head, rcu_callback_t func)
+ static void __call_rcu_core(struct rcu_state *rsp, struct rcu_data *rdp,
+@@ -3205,6 +3324,7 @@ void call_rcu_sched(struct rcu_head *head, rcu_callback_t func)
  }
  EXPORT_SYMBOL_GPL(call_rcu_sched);
  
@@ -16090,7 +17533,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  /*
   * Queue an RCU callback for invocation after a quicker grace period.
   */
-@@ -3200,6 +3320,7 @@ void call_rcu_bh(struct rcu_head *head, rcu_callback_t func)
+@@ -3213,6 +3333,7 @@ void call_rcu_bh(struct rcu_head *head, rcu_callback_t func)
        __call_rcu(head, func, &rcu_bh_state, -1, 0);
  }
  EXPORT_SYMBOL_GPL(call_rcu_bh);
@@ -16098,7 +17541,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  
  /*
   * Queue an RCU callback for lazy invocation after a grace period.
-@@ -3291,6 +3412,7 @@ void synchronize_sched(void)
+@@ -3304,6 +3425,7 @@ void synchronize_sched(void)
  }
  EXPORT_SYMBOL_GPL(synchronize_sched);
  
@@ -16106,7 +17549,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  /**
   * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
   *
-@@ -3317,6 +3439,7 @@ void synchronize_rcu_bh(void)
+@@ -3330,6 +3452,7 @@ void synchronize_rcu_bh(void)
                wait_rcu_gp(call_rcu_bh);
  }
  EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
@@ -16114,7 +17557,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  
  /**
   * get_state_synchronize_rcu - Snapshot current RCU state
-@@ -3695,6 +3818,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
+@@ -3708,6 +3831,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
        mutex_unlock(&rsp->barrier_mutex);
  }
  
@@ -16122,7 +17565,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  /**
   * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
   */
-@@ -3703,6 +3827,7 @@ void rcu_barrier_bh(void)
+@@ -3716,6 +3840,7 @@ void rcu_barrier_bh(void)
        _rcu_barrier(&rcu_bh_state);
  }
  EXPORT_SYMBOL_GPL(rcu_barrier_bh);
@@ -16130,7 +17573,7 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
  
  /**
   * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
-@@ -4196,12 +4321,13 @@ void __init rcu_init(void)
+@@ -4237,12 +4362,13 @@ void __init rcu_init(void)
  
        rcu_bootup_announce();
        rcu_init_geometry();
@@ -16146,10 +17589,10 @@ index 5d80925e7fc8..2b4bc2b2c25a 100644
        /*
         * We don't need protection against CPU-hotplug here because
 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
-index f714f873bf9d..71631196e66e 100644
+index e99a5234d9ed..958ac107062c 100644
 --- a/kernel/rcu/tree.h
 +++ b/kernel/rcu/tree.h
-@@ -587,18 +587,18 @@ extern struct list_head rcu_struct_flavors;
+@@ -588,18 +588,18 @@ extern struct list_head rcu_struct_flavors;
   */
  extern struct rcu_state rcu_sched_state;
  
@@ -16170,7 +17613,7 @@ index f714f873bf9d..71631196e66e 100644
  
  #ifndef RCU_TREE_NONCORE
  
-@@ -618,10 +618,9 @@ void call_rcu(struct rcu_head *head, rcu_callback_t func);
+@@ -619,10 +619,9 @@ void call_rcu(struct rcu_head *head, rcu_callback_t func);
  static void __init __rcu_init_preempt(void);
  static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);
  static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);
@@ -16183,7 +17626,7 @@ index f714f873bf9d..71631196e66e 100644
                                                 struct rcu_node *rnp);
  #endif /* #ifdef CONFIG_RCU_BOOST */
 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
-index 0082fce402a0..e08cddadd9c7 100644
+index e3944c4b072d..be12d1aac840 100644
 --- a/kernel/rcu/tree_plugin.h
 +++ b/kernel/rcu/tree_plugin.h
 @@ -24,25 +24,10 @@
@@ -16457,10 +17900,39 @@ index 0082fce402a0..e08cddadd9c7 100644
  /*
   * Prepare a CPU for idle from an RCU perspective.  The first major task
 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
-index f0d8322bc3ec..b40d3468ba4e 100644
+index 4f6db7e6a117..ee02e1e1b3e5 100644
 --- a/kernel/rcu/update.c
 +++ b/kernel/rcu/update.c
-@@ -295,6 +295,7 @@ int rcu_read_lock_held(void)
+@@ -62,7 +62,7 @@
+ #ifndef CONFIG_TINY_RCU
+ module_param(rcu_expedited, int, 0);
+ module_param(rcu_normal, int, 0);
+-static int rcu_normal_after_boot;
++static int rcu_normal_after_boot = IS_ENABLED(CONFIG_PREEMPT_RT_FULL);
+ module_param(rcu_normal_after_boot, int, 0);
+ #endif /* #ifndef CONFIG_TINY_RCU */
+@@ -132,8 +132,7 @@ bool rcu_gp_is_normal(void)
+ }
+ EXPORT_SYMBOL_GPL(rcu_gp_is_normal);
+-static atomic_t rcu_expedited_nesting =
+-      ATOMIC_INIT(IS_ENABLED(CONFIG_RCU_EXPEDITE_BOOT) ? 1 : 0);
++static atomic_t rcu_expedited_nesting =       ATOMIC_INIT(1);
+ /*
+  * Should normal grace-period primitives be expedited?  Intended for
+@@ -182,8 +181,7 @@ EXPORT_SYMBOL_GPL(rcu_unexpedite_gp);
+  */
+ void rcu_end_inkernel_boot(void)
+ {
+-      if (IS_ENABLED(CONFIG_RCU_EXPEDITE_BOOT))
+-              rcu_unexpedite_gp();
++      rcu_unexpedite_gp();
+       if (rcu_normal_after_boot)
+               WRITE_ONCE(rcu_normal, 1);
+ }
+@@ -298,6 +296,7 @@ int rcu_read_lock_held(void)
  }
  EXPORT_SYMBOL_GPL(rcu_read_lock_held);
  
@@ -16468,7 +17940,7 @@ index f0d8322bc3ec..b40d3468ba4e 100644
  /**
   * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section?
   *
-@@ -321,6 +322,7 @@ int rcu_read_lock_bh_held(void)
+@@ -324,6 +323,7 @@ int rcu_read_lock_bh_held(void)
        return in_softirq() || irqs_disabled();
  }
  EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held);
@@ -16476,45 +17948,6 @@ index f0d8322bc3ec..b40d3468ba4e 100644
  
  #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  
-diff --git a/kernel/relay.c b/kernel/relay.c
-index d797502140b9..cf05c17ddbed 100644
---- a/kernel/relay.c
-+++ b/kernel/relay.c
-@@ -336,6 +336,10 @@ static void wakeup_readers(unsigned long data)
- {
-       struct rchan_buf *buf = (struct rchan_buf *)data;
-       wake_up_interruptible(&buf->read_wait);
-+      /*
-+       * Stupid polling for now:
-+       */
-+      mod_timer(&buf->timer, jiffies + 1);
- }
- /**
-@@ -353,6 +357,7 @@ static void __relay_reset(struct rchan_buf *buf, unsigned int init)
-               init_waitqueue_head(&buf->read_wait);
-               kref_init(&buf->kref);
-               setup_timer(&buf->timer, wakeup_readers, (unsigned long)buf);
-+              mod_timer(&buf->timer, jiffies + 1);
-       } else
-               del_timer_sync(&buf->timer);
-@@ -767,15 +772,6 @@ size_t relay_switch_subbuf(struct rchan_buf *buf, size_t length)
-               else
-                       buf->early_bytes += buf->chan->subbuf_size -
-                                           buf->padding[old_subbuf];
--              smp_mb();
--              if (waitqueue_active(&buf->read_wait))
--                      /*
--                       * Calling wake_up_interruptible() from here
--                       * will deadlock if we happen to be logging
--                       * from the scheduler (trying to re-grab
--                       * rq->lock), so defer it.
--                       */
--                      mod_timer(&buf->timer, jiffies + 1);
-       }
-       old = buf->data;
 diff --git a/kernel/sched/Makefile b/kernel/sched/Makefile
 index 5e59b832ae2b..7337a7f60e3f 100644
 --- a/kernel/sched/Makefile
@@ -16623,7 +18056,7 @@ index 8d0f35debf35..b62cf6400fe0 100644
  }
  EXPORT_SYMBOL(completion_done);
 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
-index 44817c640e99..55aafcff5810 100644
+index e5066955cc3a..ed1ebcc2ff3d 100644
 --- a/kernel/sched/core.c
 +++ b/kernel/sched/core.c
 @@ -129,7 +129,11 @@ const_debug unsigned int sysctl_sched_features =
@@ -16646,7 +18079,25 @@ index 44817c640e99..55aafcff5810 100644
  }
  #else /* CONFIG_SCHED_HRTICK */
  static inline void hrtick_clear(struct rq *rq)
-@@ -449,7 +454,7 @@ void wake_q_add(struct wake_q_head *head, struct task_struct *task)
+@@ -425,9 +430,15 @@ static bool set_nr_if_polling(struct task_struct *p)
+ #endif
+ #endif
+-void wake_q_add(struct wake_q_head *head, struct task_struct *task)
++void __wake_q_add(struct wake_q_head *head, struct task_struct *task,
++                bool sleeper)
+ {
+-      struct wake_q_node *node = &task->wake_q;
++      struct wake_q_node *node;
++
++      if (sleeper)
++              node = &task->wake_q_sleeper;
++      else
++              node = &task->wake_q;
+       /*
+        * Atomically grab the task, if ->wake_q is !nil already it means
+@@ -449,24 +460,33 @@ void wake_q_add(struct wake_q_head *head, struct task_struct *task)
        head->lastp = &node->next;
  }
  
@@ -16655,7 +18106,24 @@ index 44817c640e99..55aafcff5810 100644
  {
        struct wake_q_node *node = head->first;
  
-@@ -466,7 +471,10 @@ void wake_up_q(struct wake_q_head *head)
+       while (node != WAKE_Q_TAIL) {
+               struct task_struct *task;
+-              task = container_of(node, struct task_struct, wake_q);
++              if (sleeper)
++                      task = container_of(node, struct task_struct, wake_q_sleeper);
++              else
++                      task = container_of(node, struct task_struct, wake_q);
+               BUG_ON(!task);
+               /* task can safely be re-inserted now */
+               node = node->next;
+-              task->wake_q.next = NULL;
++              if (sleeper)
++                      task->wake_q_sleeper.next = NULL;
++              else
++                      task->wake_q.next = NULL;
+               /*
                 * wake_up_process() implies a wmb() to pair with the queueing
                 * in wake_q_add() so as not to miss wakeups.
                 */
@@ -16667,7 +18135,7 @@ index 44817c640e99..55aafcff5810 100644
                put_task_struct(task);
        }
  }
-@@ -502,6 +510,38 @@ void resched_curr(struct rq *rq)
+@@ -502,6 +522,38 @@ void resched_curr(struct rq *rq)
                trace_sched_wake_idle_without_ipi(cpu);
  }
  
@@ -16706,7 +18174,7 @@ index 44817c640e99..55aafcff5810 100644
  void resched_cpu(int cpu)
  {
        struct rq *rq = cpu_rq(cpu);
-@@ -525,11 +565,14 @@ void resched_cpu(int cpu)
+@@ -524,11 +576,14 @@ void resched_cpu(int cpu)
   */
  int get_nohz_timer_target(void)
  {
@@ -16723,7 +18191,7 @@ index 44817c640e99..55aafcff5810 100644
  
        rcu_read_lock();
        for_each_domain(cpu, sd) {
-@@ -548,6 +591,8 @@ int get_nohz_timer_target(void)
+@@ -547,6 +602,8 @@ int get_nohz_timer_target(void)
                cpu = housekeeping_any_cpu();
  unlock:
        rcu_read_unlock();
@@ -16732,22 +18200,34 @@ index 44817c640e99..55aafcff5810 100644
        return cpu;
  }
  /*
-@@ -1089,6 +1134,11 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
+@@ -1092,7 +1149,8 @@ void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_ma
+       p->nr_cpus_allowed = cpumask_weight(new_mask);
+ }
  
-       lockdep_assert_held(&p->pi_lock);
+-void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
++static void __do_set_cpus_allowed_tail(struct task_struct *p,
++                                     const struct cpumask *new_mask)
+ {
+       struct rq *rq = task_rq(p);
+       bool queued, running;
+@@ -1121,6 +1179,98 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
+               set_curr_task(rq, p);
+ }
  
++void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
++{
 +      if (__migrate_disabled(p)) {
++              lockdep_assert_held(&p->pi_lock);
++
 +              cpumask_copy(&p->cpus_allowed, new_mask);
++#if defined(CONFIG_PREEMPT_RT_FULL) && defined(CONFIG_SMP)
++              p->migrate_disable_update = 1;
++#endif
 +              return;
 +      }
++      __do_set_cpus_allowed_tail(p, new_mask);
++}
 +
-       queued = task_on_rq_queued(p);
-       running = task_current(rq, p);
-@@ -1111,6 +1161,84 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
-               enqueue_task(rq, p, ENQUEUE_RESTORE);
- }
 +static DEFINE_PER_CPU(struct cpumask, sched_cpumasks);
 +static DEFINE_MUTEX(sched_down_mutex);
 +static cpumask_t sched_down_cpumask;
@@ -16829,7 +18309,7 @@ index 44817c640e99..55aafcff5810 100644
  /*
   * Change a given task's CPU affinity. Migrate the thread to a
   * proper CPU and schedule it away if the CPU it's executing on
-@@ -1168,7 +1296,7 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,
+@@ -1179,7 +1329,7 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,
        }
  
        /* Can the task run on the task's current CPU? If so, we're done */
@@ -16838,7 +18318,7 @@ index 44817c640e99..55aafcff5810 100644
                goto out;
  
        dest_cpu = cpumask_any_and(cpu_valid_mask, new_mask);
-@@ -1355,6 +1483,18 @@ int migrate_swap(struct task_struct *cur, struct task_struct *p)
+@@ -1366,6 +1516,18 @@ int migrate_swap(struct task_struct *cur, struct task_struct *p)
        return ret;
  }
  
@@ -16857,7 +18337,7 @@ index 44817c640e99..55aafcff5810 100644
  /*
   * wait_task_inactive - wait for a thread to unschedule.
   *
-@@ -1399,7 +1539,7 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state)
+@@ -1410,7 +1572,7 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state)
                 * is actually now running somewhere else!
                 */
                while (task_running(rq, p)) {
@@ -16866,7 +18346,7 @@ index 44817c640e99..55aafcff5810 100644
                                return 0;
                        cpu_relax();
                }
-@@ -1414,7 +1554,8 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state)
+@@ -1425,7 +1587,8 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state)
                running = task_running(rq, p);
                queued = task_on_rq_queued(p);
                ncsw = 0;
@@ -16876,7 +18356,7 @@ index 44817c640e99..55aafcff5810 100644
                        ncsw = p->nvcsw | LONG_MIN; /* sets MSB */
                task_rq_unlock(rq, p, &rf);
  
-@@ -1670,10 +1811,6 @@ static inline void ttwu_activate(struct rq *rq, struct task_struct *p, int en_fl
+@@ -1680,10 +1843,6 @@ static inline void ttwu_activate(struct rq *rq, struct task_struct *p, int en_fl
  {
        activate_task(rq, p, en_flags);
        p->on_rq = TASK_ON_RQ_QUEUED;
@@ -16887,7 +18367,7 @@ index 44817c640e99..55aafcff5810 100644
  }
  
  /*
-@@ -2008,8 +2145,27 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
+@@ -2018,8 +2177,27 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
         */
        smp_mb__before_spinlock();
        raw_spin_lock_irqsave(&p->pi_lock, flags);
@@ -16916,12 +18396,13 @@ index 44817c640e99..55aafcff5810 100644
  
        trace_sched_waking(p);
  
-@@ -2093,53 +2249,6 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
+@@ -2102,53 +2280,6 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
  }
  
  /**
 - * try_to_wake_up_local - try to wake up a local task with rq lock held
 - * @p: the thread to be awakened
+- * @cookie: context's cookie for pinning
 - *
 - * Put @p on the run-queue if it's not already there. The caller must
 - * ensure that this_rq() is locked, @p is bound to this_rq() and not
@@ -16960,8 +18441,7 @@ index 44817c640e99..55aafcff5810 100644
 -              ttwu_activate(rq, p, ENQUEUE_WAKEUP);
 -
 -      ttwu_do_wakeup(rq, p, 0, cookie);
--      if (schedstat_enabled())
--              ttwu_stat(p, smp_processor_id(), 0);
+-      ttwu_stat(p, smp_processor_id(), 0);
 -out:
 -      raw_spin_unlock(&p->pi_lock);
 -}
@@ -16970,7 +18450,7 @@ index 44817c640e99..55aafcff5810 100644
   * wake_up_process - Wake up a specific process
   * @p: The process to be woken up.
   *
-@@ -2157,6 +2266,18 @@ int wake_up_process(struct task_struct *p)
+@@ -2166,6 +2297,18 @@ int wake_up_process(struct task_struct *p)
  }
  EXPORT_SYMBOL(wake_up_process);
  
@@ -16983,13 +18463,13 @@ index 44817c640e99..55aafcff5810 100644
 + */
 +int wake_up_lock_sleeper(struct task_struct *p)
 +{
-+      return try_to_wake_up(p, TASK_ALL, WF_LOCK_SLEEPER);
++      return try_to_wake_up(p, TASK_UNINTERRUPTIBLE, WF_LOCK_SLEEPER);
 +}
 +
  int wake_up_state(struct task_struct *p, unsigned int state)
  {
        return try_to_wake_up(p, state, 0);
-@@ -2433,6 +2554,9 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
+@@ -2442,6 +2585,9 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
        p->on_cpu = 0;
  #endif
        init_task_preempt_count(p);
@@ -16999,7 +18479,7 @@ index 44817c640e99..55aafcff5810 100644
  #ifdef CONFIG_SMP
        plist_node_init(&p->pushable_tasks, MAX_PRIO);
        RB_CLEAR_NODE(&p->pushable_dl_tasks);
-@@ -2761,8 +2885,12 @@ static struct rq *finish_task_switch(struct task_struct *prev)
+@@ -2770,21 +2916,16 @@ static struct rq *finish_task_switch(struct task_struct *prev)
        finish_arch_post_lock_switch();
  
        fire_sched_in_preempt_notifiers(current);
@@ -17013,8 +18493,21 @@ index 44817c640e99..55aafcff5810 100644
        if (unlikely(prev_state == TASK_DEAD)) {
                if (prev->sched_class->task_dead)
                        prev->sched_class->task_dead(prev);
-@@ -3237,6 +3365,77 @@ static inline void schedule_debug(struct task_struct *prev)
-       schedstat_inc(this_rq(), sched_count);
+-              /*
+-               * Remove function-return probe instances associated with this
+-               * task and put them back on the free list.
+-               */
+-              kprobe_flush_task(prev);
+-
+-              /* Task is done with its stack. */
+-              put_task_stack(prev);
+-
+               put_task_struct(prev);
+       }
+@@ -3252,6 +3393,114 @@ static inline void schedule_debug(struct task_struct *prev)
+       schedstat_inc(this_rq()->sched_count);
  }
  
 +#if defined(CONFIG_PREEMPT_RT_FULL) && defined(CONFIG_SMP)
@@ -17081,6 +18574,43 @@ index 44817c640e99..55aafcff5810 100644
 +       */
 +      p->migrate_disable = 0;
 +
++      if (p->migrate_disable_update) {
++              struct rq *rq;
++              struct rq_flags rf;
++
++              rq = task_rq_lock(p, &rf);
++              update_rq_clock(rq);
++
++              __do_set_cpus_allowed_tail(p, &p->cpus_allowed);
++              task_rq_unlock(rq, p, &rf);
++
++              p->migrate_disable_update = 0;
++
++              WARN_ON(smp_processor_id() != task_cpu(p));
++              if (!cpumask_test_cpu(task_cpu(p), &p->cpus_allowed)) {
++                      const struct cpumask *cpu_valid_mask = cpu_active_mask;
++                      struct migration_arg arg;
++                      unsigned int dest_cpu;
++
++                      if (p->flags & PF_KTHREAD) {
++                              /*
++                               * Kernel threads are allowed on online && !active CPUs
++                               */
++                              cpu_valid_mask = cpu_online_mask;
++                      }
++                      dest_cpu = cpumask_any_and(cpu_valid_mask, &p->cpus_allowed);
++                      arg.task = p;
++                      arg.dest_cpu = dest_cpu;
++
++                      unpin_current_cpu();
++                      preempt_lazy_enable();
++                      preempt_enable();
++                      stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg);
++                      tlb_migrate_finish(p->mm);
++                      return;
++              }
++      }
++
 +      unpin_current_cpu();
 +      preempt_enable();
 +      preempt_lazy_enable();
@@ -17091,7 +18621,7 @@ index 44817c640e99..55aafcff5810 100644
  /*
   * Pick up the highest-prio task:
   */
-@@ -3364,19 +3563,6 @@ static void __sched notrace __schedule(bool preempt)
+@@ -3368,19 +3617,6 @@ static void __sched notrace __schedule(bool preempt)
                } else {
                        deactivate_task(rq, prev, DEQUEUE_SLEEP);
                        prev->on_rq = 0;
@@ -17111,7 +18641,7 @@ index 44817c640e99..55aafcff5810 100644
                }
                switch_count = &prev->nvcsw;
        }
-@@ -3386,6 +3572,7 @@ static void __sched notrace __schedule(bool preempt)
+@@ -3390,6 +3626,7 @@ static void __sched notrace __schedule(bool preempt)
  
        next = pick_next_task(rq, prev, cookie);
        clear_tsk_need_resched(prev);
@@ -17119,7 +18649,7 @@ index 44817c640e99..55aafcff5810 100644
        clear_preempt_need_resched();
        rq->clock_skip_update = 0;
  
-@@ -3407,9 +3594,20 @@ STACK_FRAME_NON_STANDARD(__schedule); /* switch_to() */
+@@ -3437,9 +3674,20 @@ void __noreturn do_task_dead(void)
  
  static inline void sched_submit_work(struct task_struct *tsk)
  {
@@ -17141,7 +18671,7 @@ index 44817c640e99..55aafcff5810 100644
         * If we are going to sleep and we have plugged IO queued,
         * make sure to submit it to avoid deadlocks.
         */
-@@ -3417,6 +3615,12 @@ static inline void sched_submit_work(struct task_struct *tsk)
+@@ -3447,6 +3695,12 @@ static inline void sched_submit_work(struct task_struct *tsk)
                blk_schedule_flush_plug(tsk);
  }
  
@@ -17154,7 +18684,7 @@ index 44817c640e99..55aafcff5810 100644
  asmlinkage __visible void __sched schedule(void)
  {
        struct task_struct *tsk = current;
-@@ -3427,6 +3631,7 @@ asmlinkage __visible void __sched schedule(void)
+@@ -3457,6 +3711,7 @@ asmlinkage __visible void __sched schedule(void)
                __schedule(false);
                sched_preempt_enable_no_resched();
        } while (need_resched());
@@ -17162,7 +18692,7 @@ index 44817c640e99..55aafcff5810 100644
  }
  EXPORT_SYMBOL(schedule);
  
-@@ -3490,6 +3695,30 @@ static void __sched notrace preempt_schedule_common(void)
+@@ -3520,6 +3775,30 @@ static void __sched notrace preempt_schedule_common(void)
        } while (need_resched());
  }
  
@@ -17193,7 +18723,7 @@ index 44817c640e99..55aafcff5810 100644
  #ifdef CONFIG_PREEMPT
  /*
   * this is the entry point to schedule() from in-kernel preemption
-@@ -3504,7 +3733,8 @@ asmlinkage __visible void __sched notrace preempt_schedule(void)
+@@ -3534,7 +3813,8 @@ asmlinkage __visible void __sched notrace preempt_schedule(void)
         */
        if (likely(!preemptible()))
                return;
@@ -17203,7 +18733,7 @@ index 44817c640e99..55aafcff5810 100644
        preempt_schedule_common();
  }
  NOKPROBE_SYMBOL(preempt_schedule);
-@@ -3531,6 +3761,9 @@ asmlinkage __visible void __sched notrace preempt_schedule_notrace(void)
+@@ -3561,6 +3841,9 @@ asmlinkage __visible void __sched notrace preempt_schedule_notrace(void)
        if (likely(!preemptible()))
                return;
  
@@ -17213,7 +18743,7 @@ index 44817c640e99..55aafcff5810 100644
        do {
                /*
                 * Because the function tracer can trace preempt_count_sub()
-@@ -3553,7 +3786,16 @@ asmlinkage __visible void __sched notrace preempt_schedule_notrace(void)
+@@ -3583,7 +3866,16 @@ asmlinkage __visible void __sched notrace preempt_schedule_notrace(void)
                 * an infinite recursion.
                 */
                prev_ctx = exception_enter();
@@ -17230,7 +18760,130 @@ index 44817c640e99..55aafcff5810 100644
                exception_exit(prev_ctx);
  
                preempt_latency_stop(1);
-@@ -4901,6 +5143,7 @@ int __cond_resched_lock(spinlock_t *lock)
+@@ -3629,10 +3921,25 @@ EXPORT_SYMBOL(default_wake_function);
+ #ifdef CONFIG_RT_MUTEXES
++static inline int __rt_effective_prio(struct task_struct *pi_task, int prio)
++{
++      if (pi_task)
++              prio = min(prio, pi_task->prio);
++
++      return prio;
++}
++
++static inline int rt_effective_prio(struct task_struct *p, int prio)
++{
++      struct task_struct *pi_task = rt_mutex_get_top_task(p);
++
++      return __rt_effective_prio(pi_task, prio);
++}
++
+ /*
+  * rt_mutex_setprio - set the current priority of a task
+- * @p: task
+- * @prio: prio value (kernel-internal form)
++ * @p: task to boost
++ * @pi_task: donor task
+  *
+  * This function changes the 'effective' priority of a task. It does
+  * not touch ->normal_prio like __setscheduler().
+@@ -3640,16 +3947,40 @@ EXPORT_SYMBOL(default_wake_function);
+  * Used by the rt_mutex code to implement priority inheritance
+  * logic. Call site only calls if the priority of the task changed.
+  */
+-void rt_mutex_setprio(struct task_struct *p, int prio)
++void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
+ {
+-      int oldprio, queued, running, queue_flag = DEQUEUE_SAVE | DEQUEUE_MOVE;
++      int prio, oldprio, queued, running, queue_flag = DEQUEUE_SAVE | DEQUEUE_MOVE;
+       const struct sched_class *prev_class;
+       struct rq_flags rf;
+       struct rq *rq;
+-      BUG_ON(prio > MAX_PRIO);
++      /* XXX used to be waiter->prio, not waiter->task->prio */
++      prio = __rt_effective_prio(pi_task, p->normal_prio);
++
++      /*
++       * If nothing changed; bail early.
++       */
++      if (p->pi_top_task == pi_task && prio == p->prio && !dl_prio(prio))
++              return;
+       rq = __task_rq_lock(p, &rf);
++      /*
++       * Set under pi_lock && rq->lock, such that the value can be used under
++       * either lock.
++       *
++       * Note that there is loads of tricky to make this pointer cache work
++       * right. rt_mutex_slowunlock()+rt_mutex_postunlock() work together to
++       * ensure a task is de-boosted (pi_task is set to NULL) before the
++       * task is allowed to run again (and can exit). This ensures the pointer
++       * points to a blocked task -- which guaratees the task is present.
++       */
++      p->pi_top_task = pi_task;
++
++      /*
++       * For FIFO/RR we only need to set prio, if that matches we're done.
++       */
++      if (prio == p->prio && !dl_prio(prio))
++              goto out_unlock;
+       /*
+        * Idle task boosting is a nono in general. There is one
+@@ -3669,7 +4000,7 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
+               goto out_unlock;
+       }
+-      trace_sched_pi_setprio(p, prio);
++      trace_sched_pi_setprio(p, pi_task);
+       oldprio = p->prio;
+       if (oldprio == prio)
+@@ -3693,7 +4024,6 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
+        *          running task
+        */
+       if (dl_prio(prio)) {
+-              struct task_struct *pi_task = rt_mutex_get_top_task(p);
+               if (!dl_prio(p->normal_prio) ||
+                   (pi_task && dl_entity_preempt(&pi_task->dl, &p->dl))) {
+                       p->dl.dl_boosted = 1;
+@@ -3730,6 +4060,11 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
+       balance_callback(rq);
+       preempt_enable();
+ }
++#else
++static inline int rt_effective_prio(struct task_struct *p, int prio)
++{
++      return prio;
++}
+ #endif
+ void set_user_nice(struct task_struct *p, long nice)
+@@ -3974,10 +4309,9 @@ static void __setscheduler(struct rq *rq, struct task_struct *p,
+        * Keep a potential priority boosting if called from
+        * sched_setscheduler().
+        */
++      p->prio = normal_prio(p);
+       if (keep_boost)
+-              p->prio = rt_mutex_get_effective_prio(p, normal_prio(p));
+-      else
+-              p->prio = normal_prio(p);
++              p->prio = rt_effective_prio(p, p->prio);
+       if (dl_prio(p->prio))
+               p->sched_class = &dl_sched_class;
+@@ -4264,7 +4598,7 @@ static int __sched_setscheduler(struct task_struct *p,
+                * the runqueue. This will be done when the task deboost
+                * itself.
+                */
+-              new_effective_prio = rt_mutex_get_effective_prio(p, newprio);
++              new_effective_prio = rt_effective_prio(p, newprio);
+               if (new_effective_prio == oldprio)
+                       queue_flags &= ~DEQUEUE_MOVE;
+       }
+@@ -4939,6 +5273,7 @@ int __cond_resched_lock(spinlock_t *lock)
  }
  EXPORT_SYMBOL(__cond_resched_lock);
  
@@ -17238,7 +18891,7 @@ index 44817c640e99..55aafcff5810 100644
  int __sched __cond_resched_softirq(void)
  {
        BUG_ON(!in_softirq());
-@@ -4914,6 +5157,7 @@ int __sched __cond_resched_softirq(void)
+@@ -4952,6 +5287,7 @@ int __sched __cond_resched_softirq(void)
        return 0;
  }
  EXPORT_SYMBOL(__cond_resched_softirq);
@@ -17246,7 +18899,7 @@ index 44817c640e99..55aafcff5810 100644
  
  /**
   * yield - yield the current processor to other threads.
-@@ -5283,7 +5527,9 @@ void init_idle(struct task_struct *idle, int cpu)
+@@ -5315,7 +5651,9 @@ void init_idle(struct task_struct *idle, int cpu)
  
        /* Set the preempt count _outside_ the spinlocks! */
        init_idle_preempt_count(idle, cpu);
@@ -17257,7 +18910,7 @@ index 44817c640e99..55aafcff5810 100644
        /*
         * The idle tasks have their own, simple scheduling class:
         */
-@@ -5426,6 +5672,8 @@ void sched_setnuma(struct task_struct *p, int nid)
+@@ -5458,6 +5796,8 @@ void sched_setnuma(struct task_struct *p, int nid)
  #endif /* CONFIG_NUMA_BALANCING */
  
  #ifdef CONFIG_HOTPLUG_CPU
@@ -17266,8 +18919,8 @@ index 44817c640e99..55aafcff5810 100644
  /*
   * Ensures that the idle task is using init_mm right before its cpu goes
   * offline.
-@@ -5440,7 +5688,12 @@ void idle_task_exit(void)
-               switch_mm_irqs_off(mm, &init_mm, current);
+@@ -5472,7 +5812,12 @@ void idle_task_exit(void)
+               switch_mm(mm, &init_mm, current);
                finish_arch_post_lock_switch();
        }
 -      mmdrop(mm);
@@ -17280,7 +18933,15 @@ index 44817c640e99..55aafcff5810 100644
  }
  
  /*
-@@ -7315,6 +7568,10 @@ int sched_cpu_dying(unsigned int cpu)
+@@ -5881,6 +6226,7 @@ static int init_rootdomain(struct root_domain *rd)
+       rd->rto_cpu = -1;
+       raw_spin_lock_init(&rd->rto_lock);
+       init_irq_work(&rd->rto_push_work, rto_push_irq_work_func);
++      rd->rto_push_work.flags |= IRQ_WORK_HARD_IRQ;
+ #endif
+       init_dl_bw(&rd->dl_bw);
+@@ -7439,6 +7785,10 @@ int sched_cpu_dying(unsigned int cpu)
        update_max_interval();
        nohz_balance_exit_idle(cpu);
        hrtick_clear(rq);
@@ -17291,7 +18952,7 @@ index 44817c640e99..55aafcff5810 100644
        return 0;
  }
  #endif
-@@ -7566,7 +7823,7 @@ void __init sched_init(void)
+@@ -7700,7 +8050,7 @@ void __init sched_init(void)
  #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
  static inline int preempt_count_equals(int preempt_offset)
  {
@@ -17301,10 +18962,10 @@ index 44817c640e99..55aafcff5810 100644
        return (nested == preempt_offset);
  }
 diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
-index 1ce8867283dc..766da04b06a0 100644
+index c95c5122b105..e00accf92a4b 100644
 --- a/kernel/sched/deadline.c
 +++ b/kernel/sched/deadline.c
-@@ -697,6 +697,7 @@ void init_dl_task_timer(struct sched_dl_entity *dl_se)
+@@ -687,6 +687,7 @@ void init_dl_task_timer(struct sched_dl_entity *dl_se)
  
        hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        timer->function = dl_task_timer;
@@ -17313,10 +18974,10 @@ index 1ce8867283dc..766da04b06a0 100644
  
  static
 diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
-index 2a0a9995256d..48a9b6f57249 100644
+index fa178b62ea79..935224123441 100644
 --- a/kernel/sched/debug.c
 +++ b/kernel/sched/debug.c
-@@ -552,6 +552,9 @@ void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
+@@ -558,6 +558,9 @@ void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
        P(rt_throttled);
        PN(rt_time);
        PN(rt_runtime);
@@ -17326,7 +18987,7 @@ index 2a0a9995256d..48a9b6f57249 100644
  
  #undef PN
  #undef P
-@@ -947,6 +950,10 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
+@@ -953,6 +956,10 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
  #endif
        P(policy);
        P(prio);
@@ -17334,14 +18995,14 @@ index 2a0a9995256d..48a9b6f57249 100644
 +      P(migrate_disable);
 +#endif
 +      P(nr_cpus_allowed);
+ #undef PN_SCHEDSTAT
  #undef PN
  #undef __PN
- #undef P
 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
-index 8b3610c871f2..1145079af264 100644
+index 7a68c631d5b5..f9189909640b 100644
 --- a/kernel/sched/fair.c
 +++ b/kernel/sched/fair.c
-@@ -3508,7 +3508,7 @@ check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
+@@ -3518,7 +3518,7 @@ check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
        ideal_runtime = sched_slice(cfs_rq, curr);
        delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
        if (delta_exec > ideal_runtime) {
@@ -17350,7 +19011,7 @@ index 8b3610c871f2..1145079af264 100644
                /*
                 * The current task ran long enough, ensure it doesn't get
                 * re-elected due to buddy favours.
-@@ -3532,7 +3532,7 @@ check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
+@@ -3542,7 +3542,7 @@ check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
                return;
  
        if (delta > ideal_runtime)
@@ -17359,7 +19020,7 @@ index 8b3610c871f2..1145079af264 100644
  }
  
  static void
-@@ -3677,7 +3677,7 @@ entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)
+@@ -3684,7 +3684,7 @@ entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)
         * validating it and just reschedule.
         */
        if (queued) {
@@ -17368,7 +19029,7 @@ index 8b3610c871f2..1145079af264 100644
                return;
        }
        /*
-@@ -3859,7 +3859,7 @@ static void __account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec)
+@@ -3866,7 +3866,7 @@ static void __account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec)
         * hierarchy can be throttled
         */
        if (!assign_cfs_rq_runtime(cfs_rq) && likely(cfs_rq->curr))
@@ -17377,7 +19038,7 @@ index 8b3610c871f2..1145079af264 100644
  }
  
  static __always_inline
-@@ -4487,7 +4487,7 @@ static void hrtick_start_fair(struct rq *rq, struct task_struct *p)
+@@ -4494,7 +4494,7 @@ static void hrtick_start_fair(struct rq *rq, struct task_struct *p)
  
                if (delta < 0) {
                        if (rq->curr == p)
@@ -17386,7 +19047,7 @@ index 8b3610c871f2..1145079af264 100644
                        return;
                }
                hrtick_start(rq, delta);
-@@ -5676,7 +5676,7 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
+@@ -5862,7 +5862,7 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
        return;
  
  preempt:
@@ -17395,7 +19056,7 @@ index 8b3610c871f2..1145079af264 100644
        /*
         * Only set the backward buddy when the current task is still
         * on the rq. This can happen when a wakeup gets interleaved
-@@ -8402,7 +8402,7 @@ static void task_fork_fair(struct task_struct *p)
+@@ -8588,7 +8588,7 @@ static void task_fork_fair(struct task_struct *p)
                 * 'current' within the tree based on its new key value.
                 */
                swap(curr->vruntime, se->vruntime);
@@ -17404,7 +19065,7 @@ index 8b3610c871f2..1145079af264 100644
        }
  
        se->vruntime -= cfs_rq->min_vruntime;
-@@ -8426,7 +8426,7 @@ prio_changed_fair(struct rq *rq, struct task_struct *p, int oldprio)
+@@ -8612,7 +8612,7 @@ prio_changed_fair(struct rq *rq, struct task_struct *p, int oldprio)
         */
        if (rq->curr == p) {
                if (p->prio > oldprio)
@@ -17438,7 +19099,7 @@ index 69631fa46c2f..6d28fcd08872 100644
  #ifdef HAVE_RT_PUSH_IPI
  /*
 diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
-index d5690b722691..731cd0e98c15 100644
+index 9c131168d933..340a0a5d435c 100644
 --- a/kernel/sched/rt.c
 +++ b/kernel/sched/rt.c
 @@ -47,6 +47,7 @@ void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime)
@@ -17449,19 +19110,11 @@ index d5690b722691..731cd0e98c15 100644
        rt_b->rt_period_timer.function = sched_rt_period_timer;
  }
  
-@@ -101,6 +102,7 @@ void init_rt_rq(struct rt_rq *rt_rq)
-       rt_rq->push_cpu = nr_cpu_ids;
-       raw_spin_lock_init(&rt_rq->push_lock);
-       init_irq_work(&rt_rq->push_work, push_irq_work_func);
-+      rt_rq->push_work.flags |= IRQ_WORK_HARD_IRQ;
- #endif
- #endif /* CONFIG_SMP */
-       /* We start is dequeued state, because no RT tasks are queued */
 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
-index c64fc5114004..af58f9b3ece4 100644
+index cff985feb6e7..280c7d5a7657 100644
 --- a/kernel/sched/sched.h
 +++ b/kernel/sched/sched.h
-@@ -1138,6 +1138,7 @@ static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
+@@ -1162,6 +1162,7 @@ static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
  #define WF_SYNC               0x01            /* waker goes to sleep after wakeup */
  #define WF_FORK               0x02            /* child wakeup after fork */
  #define WF_MIGRATED   0x4             /* internal use, task got migrated */
@@ -17469,7 +19122,7 @@ index c64fc5114004..af58f9b3ece4 100644
  
  /*
   * To aid in avoiding the subversion of "niceness" due to uneven distribution
-@@ -1316,6 +1317,15 @@ extern void init_sched_fair_class(void);
+@@ -1345,6 +1346,15 @@ extern void init_sched_fair_class(void);
  extern void resched_curr(struct rq *rq);
  extern void resched_cpu(int cpu);
  
@@ -17710,7 +19363,7 @@ index 000000000000..1950f40ca725
 +}
 +EXPORT_SYMBOL_GPL(swork_put);
 diff --git a/kernel/signal.c b/kernel/signal.c
-index af21afc00d08..7ead97a43298 100644
+index e48668c3c972..99918dcd836f 100644
 --- a/kernel/signal.c
 +++ b/kernel/signal.c
 @@ -14,6 +14,7 @@
@@ -17823,17 +19476,17 @@ index af21afc00d08..7ead97a43298 100644
   * Flush all pending signals for this kthread.
   */
  void flush_signals(struct task_struct *t)
-@@ -525,7 +583,7 @@ static void collect_signal(int sig, struct sigpending *list, siginfo_t *info)
- still_pending:
-               list_del_init(&first->list);
-               copy_siginfo(info, &first->info);
+@@ -532,7 +590,7 @@ static void collect_signal(int sig, struct sigpending *list, siginfo_t *info,
+                       (info->si_code == SI_TIMER) &&
+                       (info->si_sys_private);
 -              __sigqueue_free(first);
 +              sigqueue_free_current(first);
        } else {
                /*
                 * Ok, it wasn't in the queue.  This must be
-@@ -560,6 +618,8 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
- {
+@@ -568,6 +626,8 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
+       bool resched_timer = false;
        int signr;
  
 +      WARN_ON_ONCE(tsk != current);
@@ -17841,7 +19494,7 @@ index af21afc00d08..7ead97a43298 100644
        /* We only dequeue private signals from ourselves, we don't let
         * signalfd steal them
         */
-@@ -1156,8 +1216,8 @@ int do_send_sig_info(int sig, struct siginfo *info, struct task_struct *p,
+@@ -1164,8 +1224,8 @@ int do_send_sig_info(int sig, struct siginfo *info, struct task_struct *p,
   * We don't want to have recursive SIGSEGV's etc, for example,
   * that is why we also clear SIGNAL_UNKILLABLE.
   */
@@ -17852,7 +19505,7 @@ index af21afc00d08..7ead97a43298 100644
  {
        unsigned long int flags;
        int ret, blocked, ignored;
-@@ -1182,6 +1242,39 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
+@@ -1190,6 +1250,39 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
        return ret;
  }
  
@@ -17892,7 +19545,7 @@ index af21afc00d08..7ead97a43298 100644
  /*
   * Nuke all other threads in the group.
   */
-@@ -1216,12 +1309,12 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
+@@ -1224,12 +1317,12 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
                 * Disable interrupts early to avoid deadlocks.
                 * See rcu_read_unlock() comment header for details.
                 */
@@ -17907,7 +19560,7 @@ index af21afc00d08..7ead97a43298 100644
                        break;
                }
                /*
-@@ -1242,7 +1335,7 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
+@@ -1250,7 +1343,7 @@ struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
                }
                spin_unlock(&sighand->siglock);
                rcu_read_unlock();
@@ -17916,7 +19569,7 @@ index af21afc00d08..7ead97a43298 100644
        }
  
        return sighand;
-@@ -1485,7 +1578,8 @@ EXPORT_SYMBOL(kill_pid);
+@@ -1493,7 +1586,8 @@ EXPORT_SYMBOL(kill_pid);
   */
  struct sigqueue *sigqueue_alloc(void)
  {
@@ -17926,7 +19579,7 @@ index af21afc00d08..7ead97a43298 100644
  
        if (q)
                q->flags |= SIGQUEUE_PREALLOC;
-@@ -1846,15 +1940,7 @@ static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info)
+@@ -1854,15 +1948,7 @@ static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info)
                if (gstop_done && ptrace_reparented(current))
                        do_notify_parent_cldstop(current, false, why);
  
@@ -17943,7 +19596,7 @@ index af21afc00d08..7ead97a43298 100644
        } else {
                /*
 diff --git a/kernel/softirq.c b/kernel/softirq.c
-index 17caf4b63342..a602b7152de7 100644
+index 744fa611cae0..819bd7cf5ad0 100644
 --- a/kernel/softirq.c
 +++ b/kernel/softirq.c
 @@ -21,10 +21,12 @@
@@ -17964,12 +19617,12 @@ index 17caf4b63342..a602b7152de7 100644
  
  DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
 +#ifdef CONFIG_PREEMPT_RT_FULL
-+#define TIMER_SOFTIRQS        ((1 << TIMER_SOFTIRQ) | (1 << HRTIMER_SOFTIRQ))
++#define TIMER_SOFTIRQS ((1 << TIMER_SOFTIRQ) | (1 << HRTIMER_SOFTIRQ))
 +DEFINE_PER_CPU(struct task_struct *, ktimer_softirqd);
 +#endif
  
  const char * const softirq_to_name[NR_SOFTIRQS] = {
-       "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
+       "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "IRQ_POLL",
        "TASKLET", "SCHED", "HRTIMER", "RCU"
  };
  
@@ -18068,7 +19721,7 @@ index 17caf4b63342..a602b7152de7 100644
  /*
   * we cannot loop indefinitely here to avoid userspace starvation,
   * but we also don't want to introduce a worst case 1/HZ latency
-@@ -77,6 +175,79 @@ static void wakeup_softirqd(void)
+@@ -77,6 +175,38 @@ static void wakeup_softirqd(void)
                wake_up_process(tsk);
  }
  
@@ -18104,6 +19757,13 @@ index 17caf4b63342..a602b7152de7 100644
 +}
 +
 +#ifndef CONFIG_PREEMPT_RT_FULL
+ /*
+  * If ksoftirqd is scheduled, we do not want to process pending softirqs
+  * right now. Let ksoftirqd handle this at its own rate, to get fairness.
+@@ -88,6 +218,47 @@ static bool ksoftirqd_running(void)
+       return tsk && (tsk->state == TASK_RUNNING);
+ }
 +static inline int ksoftirqd_softirq_pending(void)
 +{
 +      return local_softirq_pending();
@@ -18148,7 +19808,7 @@ index 17caf4b63342..a602b7152de7 100644
  /*
   * preempt_count and SOFTIRQ_OFFSET usage:
   * - preempt_count is changed by SOFTIRQ_OFFSET on entering or leaving
-@@ -232,10 +403,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
+@@ -243,10 +414,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
        unsigned long end = jiffies + MAX_SOFTIRQ_TIME;
        unsigned long old_flags = current->flags;
        int max_restart = MAX_SOFTIRQ_RESTART;
@@ -18159,7 +19819,7 @@ index 17caf4b63342..a602b7152de7 100644
  
        /*
         * Mask out PF_MEMALLOC s current task context is borrowed for the
-@@ -254,36 +423,7 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
+@@ -265,36 +434,7 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
        /* Reset the pending bitmask before enabling irqs */
        set_softirq_pending(0);
  
@@ -18197,7 +19857,7 @@ index 17caf4b63342..a602b7152de7 100644
  
        pending = local_softirq_pending();
        if (pending) {
-@@ -320,6 +460,310 @@ asmlinkage __visible void do_softirq(void)
+@@ -331,6 +471,309 @@ asmlinkage __visible void do_softirq(void)
  }
  
  /*
@@ -18407,7 +20067,6 @@ index 17caf4b63342..a602b7152de7 100644
 +              wakeup_softirqd();
 +}
 +
-+
 +void __raise_softirq_irqoff(unsigned int nr)
 +{
 +      do_raise_softirq_irqoff(nr);
@@ -18508,7 +20167,7 @@ index 17caf4b63342..a602b7152de7 100644
   * Enter an interrupt context.
   */
  void irq_enter(void)
-@@ -330,9 +774,9 @@ void irq_enter(void)
+@@ -341,9 +784,9 @@ void irq_enter(void)
                 * Prevent raise_softirq from needlessly waking up ksoftirqd
                 * here, as softirq will be serviced on return from interrupt.
                 */
@@ -18520,15 +20179,15 @@ index 17caf4b63342..a602b7152de7 100644
        }
  
        __irq_enter();
-@@ -340,6 +784,7 @@ void irq_enter(void)
+@@ -351,6 +794,7 @@ void irq_enter(void)
  
  static inline void invoke_softirq(void)
  {
 +#ifndef CONFIG_PREEMPT_RT_FULL
-       if (!force_irqthreads) {
- #ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
-               /*
-@@ -359,6 +804,18 @@ static inline void invoke_softirq(void)
+       if (ksoftirqd_running())
+               return;
+@@ -373,6 +817,18 @@ static inline void invoke_softirq(void)
        } else {
                wakeup_softirqd();
        }
@@ -18547,7 +20206,7 @@ index 17caf4b63342..a602b7152de7 100644
  }
  
  static inline void tick_irq_exit(void)
-@@ -395,26 +852,6 @@ void irq_exit(void)
+@@ -409,26 +865,6 @@ void irq_exit(void)
        trace_hardirq_exit(); /* must be last! */
  }
  
@@ -18574,7 +20233,7 @@ index 17caf4b63342..a602b7152de7 100644
  void raise_softirq(unsigned int nr)
  {
        unsigned long flags;
-@@ -424,12 +861,6 @@ void raise_softirq(unsigned int nr)
+@@ -438,12 +874,6 @@ void raise_softirq(unsigned int nr)
        local_irq_restore(flags);
  }
  
@@ -18587,7 +20246,7 @@ index 17caf4b63342..a602b7152de7 100644
  void open_softirq(int nr, void (*action)(struct softirq_action *))
  {
        softirq_vec[nr].action = action;
-@@ -446,15 +877,45 @@ struct tasklet_head {
+@@ -460,15 +890,45 @@ struct tasklet_head {
  static DEFINE_PER_CPU(struct tasklet_head, tasklet_vec);
  static DEFINE_PER_CPU(struct tasklet_head, tasklet_hi_vec);
  
@@ -18637,7 +20296,7 @@ index 17caf4b63342..a602b7152de7 100644
        local_irq_restore(flags);
  }
  EXPORT_SYMBOL(__tasklet_schedule);
-@@ -464,10 +925,7 @@ void __tasklet_hi_schedule(struct tasklet_struct *t)
+@@ -478,10 +938,7 @@ void __tasklet_hi_schedule(struct tasklet_struct *t)
        unsigned long flags;
  
        local_irq_save(flags);
@@ -18649,7 +20308,7 @@ index 17caf4b63342..a602b7152de7 100644
        local_irq_restore(flags);
  }
  EXPORT_SYMBOL(__tasklet_hi_schedule);
-@@ -476,82 +934,122 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
+@@ -490,82 +947,122 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
  {
        BUG_ON(!irqs_disabled());
  
@@ -18660,7 +20319,7 @@ index 17caf4b63342..a602b7152de7 100644
  }
  EXPORT_SYMBOL(__tasklet_hi_schedule_first);
  
--static void tasklet_action(struct softirq_action *a)
+-static __latent_entropy void tasklet_action(struct softirq_action *a)
 +void  tasklet_enable(struct tasklet_struct *t)
  {
 -      struct tasklet_struct *list;
@@ -18781,7 +20440,7 @@ index 17caf4b63342..a602b7152de7 100644
 +      __tasklet_action(a, list);
 +}
 +
- static void tasklet_hi_action(struct softirq_action *a)
+ static __latent_entropy void tasklet_hi_action(struct softirq_action *a)
  {
        struct tasklet_struct *list;
  
@@ -18790,12 +20449,11 @@ index 17caf4b63342..a602b7152de7 100644
        list = __this_cpu_read(tasklet_hi_vec.head);
        __this_cpu_write(tasklet_hi_vec.head, NULL);
        __this_cpu_write(tasklet_hi_vec.tail, this_cpu_ptr(&tasklet_hi_vec.head));
-+
-       local_irq_enable();
+-      local_irq_enable();
+-
 -      while (list) {
 -              struct tasklet_struct *t = list;
--
 -              list = list->next;
 -
 -              if (tasklet_trylock(t)) {
@@ -18809,7 +20467,8 @@ index 17caf4b63342..a602b7152de7 100644
 -                      }
 -                      tasklet_unlock(t);
 -              }
--
++      local_irq_enable();
 -              local_irq_disable();
 -              t->next = NULL;
 -              *__this_cpu_read(tasklet_hi_vec.tail) = t;
@@ -18821,7 +20480,7 @@ index 17caf4b63342..a602b7152de7 100644
  }
  
  void tasklet_init(struct tasklet_struct *t,
-@@ -572,7 +1070,7 @@ void tasklet_kill(struct tasklet_struct *t)
+@@ -586,7 +1083,7 @@ void tasklet_kill(struct tasklet_struct *t)
  
        while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
                do {
@@ -18830,28 +20489,13 @@ index 17caf4b63342..a602b7152de7 100644
                } while (test_bit(TASKLET_STATE_SCHED, &t->state));
        }
        tasklet_unlock_wait(t);
-@@ -646,25 +1144,26 @@ void __init softirq_init(void)
+@@ -660,25 +1157,26 @@ void __init softirq_init(void)
        open_softirq(HI_SOFTIRQ, tasklet_hi_action);
  }
  
+-static int ksoftirqd_should_run(unsigned int cpu)
 +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
 +void tasklet_unlock_wait(struct tasklet_struct *t)
-+{
-+      while (test_bit(TASKLET_STATE_RUN, &(t)->state)) {
-+              /*
-+               * Hack for now to avoid this busy-loop:
-+               */
-+#ifdef CONFIG_PREEMPT_RT_FULL
-+              msleep(1);
-+#else
-+              barrier();
-+#endif
-+      }
-+}
-+EXPORT_SYMBOL(tasklet_unlock_wait);
-+#endif
-+
- static int ksoftirqd_should_run(unsigned int cpu)
  {
 -      return local_softirq_pending();
 -}
@@ -18860,21 +20504,34 @@ index 17caf4b63342..a602b7152de7 100644
 -{
 -      local_irq_disable();
 -      if (local_softirq_pending()) {
--              /*
++      while (test_bit(TASKLET_STATE_RUN, &(t)->state)) {
+               /*
 -               * We can safely run softirq on inline stack, as we are not deep
 -               * in the task stack here.
--               */
++               * Hack for now to avoid this busy-loop:
+                */
 -              __do_softirq();
 -              local_irq_enable();
 -              cond_resched_rcu_qs();
 -              return;
--      }
++#ifdef CONFIG_PREEMPT_RT_FULL
++              msleep(1);
++#else
++              barrier();
++#endif
+       }
 -      local_irq_enable();
++}
++EXPORT_SYMBOL(tasklet_unlock_wait);
++#endif
++
++static int ksoftirqd_should_run(unsigned int cpu)
++{
 +      return ksoftirqd_softirq_pending();
  }
  
  #ifdef CONFIG_HOTPLUG_CPU
-@@ -746,16 +1245,31 @@ static struct notifier_block cpu_nfb = {
+@@ -745,17 +1243,31 @@ static int takeover_tasklets(unsigned int cpu)
  
  static struct smp_hotplug_thread softirq_threads = {
        .store                  = &ksoftirqd,
@@ -18897,20 +20554,21 @@ index 17caf4b63342..a602b7152de7 100644
 +
  static __init int spawn_ksoftirqd(void)
  {
-       register_cpu_notifier(&cpu_nfb);
+       cpuhp_setup_state_nocalls(CPUHP_SOFTIRQ_DEAD, "softirq:dead", NULL,
+                                 takeover_tasklets);
        BUG_ON(smpboot_register_percpu_thread(&softirq_threads));
+-
 +#ifdef CONFIG_PREEMPT_RT_FULL
 +      BUG_ON(smpboot_register_percpu_thread(&softirq_timer_threads));
 +#endif
        return 0;
  }
+ early_initcall(spawn_ksoftirqd);
 diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
-index 4a1ca5f6da7e..3226e22b9e42 100644
+index ec9ab2f01489..8b89dbedeaff 100644
 --- a/kernel/stop_machine.c
 +++ b/kernel/stop_machine.c
-@@ -37,7 +37,7 @@ struct cpu_stop_done {
+@@ -36,7 +36,7 @@ struct cpu_stop_done {
  struct cpu_stopper {
        struct task_struct      *thread;
  
@@ -18919,7 +20577,7 @@ index 4a1ca5f6da7e..3226e22b9e42 100644
        bool                    enabled;        /* is this stopper enabled? */
        struct list_head        works;          /* list of pending works */
  
-@@ -83,14 +83,14 @@ static bool cpu_stop_queue_work(unsigned int cpu, struct cpu_stop_work *work)
+@@ -78,14 +78,14 @@ static bool cpu_stop_queue_work(unsigned int cpu, struct cpu_stop_work *work)
        unsigned long flags;
        bool enabled;
  
@@ -18936,65 +20594,29 @@ index 4a1ca5f6da7e..3226e22b9e42 100644
        return enabled;
  }
  
-@@ -232,8 +232,8 @@ static int cpu_stop_queue_two_works(int cpu1, struct cpu_stop_work *work1,
+@@ -231,8 +231,8 @@ static int cpu_stop_queue_two_works(int cpu1, struct cpu_stop_work *work1,
+       struct cpu_stopper *stopper2 = per_cpu_ptr(&cpu_stopper, cpu2);
        int err;
-       lg_double_lock(&stop_cpus_lock, cpu1, cpu2);
+ retry:
 -      spin_lock_irq(&stopper1->lock);
 -      spin_lock_nested(&stopper2->lock, SINGLE_DEPTH_NESTING);
 +      raw_spin_lock_irq(&stopper1->lock);
 +      raw_spin_lock_nested(&stopper2->lock, SINGLE_DEPTH_NESTING);
  
-       err = -ENOENT;
-       if (!stopper1->enabled || !stopper2->enabled)
-@@ -243,8 +243,8 @@ static int cpu_stop_queue_two_works(int cpu1, struct cpu_stop_work *work1,
-       __cpu_stop_queue_work(stopper1, work1);
-       __cpu_stop_queue_work(stopper2, work2);
- unlock:
--      spin_unlock(&stopper2->lock);
--      spin_unlock_irq(&stopper1->lock);
-+      raw_spin_unlock(&stopper2->lock);
-+      raw_spin_unlock_irq(&stopper1->lock);
-       lg_double_unlock(&stop_cpus_lock, cpu1, cpu2);
-       return err;
-@@ -321,18 +321,21 @@ static DEFINE_MUTEX(stop_cpus_mutex);
- static bool queue_stop_cpus_work(const struct cpumask *cpumask,
-                                cpu_stop_fn_t fn, void *arg,
--                               struct cpu_stop_done *done)
-+                               struct cpu_stop_done *done, bool inactive)
- {
-       struct cpu_stop_work *work;
-       unsigned int cpu;
-       bool queued = false;
-       /*
--       * Disable preemption while queueing to avoid getting
--       * preempted by a stopper which might wait for other stoppers
--       * to enter @fn which can lead to deadlock.
-+       * Make sure that all work is queued on all cpus before
-+       * any of the cpus can execute it.
-        */
--      lg_global_lock(&stop_cpus_lock);
-+      if (!inactive)
-+              lg_global_lock(&stop_cpus_lock);
-+      else
-+              lg_global_trylock_relax(&stop_cpus_lock);
-+
-       for_each_cpu(cpu, cpumask) {
-               work = &per_cpu(cpu_stopper.stop_work, cpu);
-               work->fn = fn;
-@@ -352,7 +355,7 @@ static int __stop_cpus(const struct cpumask *cpumask,
-       struct cpu_stop_done done;
+       err = -ENOENT;
+       if (!stopper1->enabled || !stopper2->enabled)
+@@ -255,8 +255,8 @@ static int cpu_stop_queue_two_works(int cpu1, struct cpu_stop_work *work1,
+       __cpu_stop_queue_work(stopper1, work1);
+       __cpu_stop_queue_work(stopper2, work2);
+ unlock:
+-      spin_unlock(&stopper2->lock);
+-      spin_unlock_irq(&stopper1->lock);
++      raw_spin_unlock(&stopper2->lock);
++      raw_spin_unlock_irq(&stopper1->lock);
  
-       cpu_stop_init_done(&done, cpumask_weight(cpumask));
--      if (!queue_stop_cpus_work(cpumask, fn, arg, &done))
-+      if (!queue_stop_cpus_work(cpumask, fn, arg, &done, false))
-               return -ENOENT;
-       wait_for_completion(&done.completion);
-       return done.ret;
-@@ -433,9 +436,9 @@ static int cpu_stop_should_run(unsigned int cpu)
+       if (unlikely(err == -EDEADLK)) {
+               while (stop_cpus_in_progress)
+@@ -448,9 +448,9 @@ static int cpu_stop_should_run(unsigned int cpu)
        unsigned long flags;
        int run;
  
@@ -19006,7 +20628,7 @@ index 4a1ca5f6da7e..3226e22b9e42 100644
        return run;
  }
  
-@@ -446,13 +449,13 @@ static void cpu_stopper_thread(unsigned int cpu)
+@@ -461,13 +461,13 @@ static void cpu_stopper_thread(unsigned int cpu)
  
  repeat:
        work = NULL;
@@ -19022,24 +20644,16 @@ index 4a1ca5f6da7e..3226e22b9e42 100644
  
        if (work) {
                cpu_stop_fn_t fn = work->fn;
-@@ -460,6 +463,16 @@ static void cpu_stopper_thread(unsigned int cpu)
+@@ -475,6 +475,8 @@ static void cpu_stopper_thread(unsigned int cpu)
                struct cpu_stop_done *done = work->done;
                int ret;
  
-+              /*
-+               * Wait until the stopper finished scheduling on all
-+               * cpus
-+               */
-+              lg_global_lock(&stop_cpus_lock);
-+              /*
-+               * Let other cpu threads continue as well
-+               */
-+              lg_global_unlock(&stop_cpus_lock);
++              /* XXX */
 +
                /* cpu stop callbacks must not sleep, make in_atomic() == T */
                preempt_count_inc();
                ret = fn(arg);
-@@ -526,10 +539,12 @@ static int __init cpu_stop_init(void)
+@@ -541,7 +543,7 @@ static int __init cpu_stop_init(void)
        for_each_possible_cpu(cpu) {
                struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  
@@ -19048,22 +20662,8 @@ index 4a1ca5f6da7e..3226e22b9e42 100644
                INIT_LIST_HEAD(&stopper->works);
        }
  
-+      lg_lock_init(&stop_cpus_lock, "stop_cpus_lock");
-+
-       BUG_ON(smpboot_register_percpu_thread(&cpu_stop_threads));
-       stop_machine_unpark(raw_smp_processor_id());
-       stop_machine_initialized = true;
-@@ -624,7 +639,7 @@ int stop_machine_from_inactive_cpu(cpu_stop_fn_t fn, void *data,
-       set_state(&msdata, MULTI_STOP_PREPARE);
-       cpu_stop_init_done(&done, num_active_cpus());
-       queue_stop_cpus_work(cpu_active_mask, multi_cpu_stop, &msdata,
--                           &done);
-+                           &done, true);
-       ret = multi_cpu_stop(&msdata);
-       /* Busy wait for completion. */
 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
-index 9ba7c820fc23..d85f638fd99e 100644
+index eeb7f2f5698d..369203af6406 100644
 --- a/kernel/time/hrtimer.c
 +++ b/kernel/time/hrtimer.c
 @@ -53,6 +53,7 @@
@@ -19074,7 +20674,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
  
  #include "tick-internal.h"
  
-@@ -695,6 +696,29 @@ static void hrtimer_switch_to_hres(void)
+@@ -693,6 +694,29 @@ static void hrtimer_switch_to_hres(void)
        retrigger_next_event(NULL);
  }
  
@@ -19104,7 +20704,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
  static void clock_was_set_work(struct work_struct *work)
  {
        clock_was_set();
-@@ -710,6 +734,7 @@ void clock_was_set_delayed(void)
+@@ -708,6 +732,7 @@ void clock_was_set_delayed(void)
  {
        schedule_work(&hrtimer_work);
  }
@@ -19112,7 +20712,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
  
  #else
  
-@@ -719,11 +744,8 @@ static inline int hrtimer_is_hres_enabled(void) { return 0; }
+@@ -717,11 +742,8 @@ static inline int hrtimer_is_hres_enabled(void) { return 0; }
  static inline void hrtimer_switch_to_hres(void) { }
  static inline void
  hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { }
@@ -19126,7 +20726,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
  static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { }
  static inline void retrigger_next_event(void *arg) { }
  
-@@ -855,6 +877,32 @@ u64 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
+@@ -853,6 +875,32 @@ u64 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
  }
  EXPORT_SYMBOL_GPL(hrtimer_forward);
  
@@ -19159,7 +20759,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
  /*
   * enqueue_hrtimer - internal function to (re)start a timer
   *
-@@ -896,6 +944,11 @@ static void __remove_hrtimer(struct hrtimer *timer,
+@@ -894,6 +942,11 @@ static void __remove_hrtimer(struct hrtimer *timer,
        if (!(state & HRTIMER_STATE_ENQUEUED))
                return;
  
@@ -19171,7 +20771,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
        if (!timerqueue_del(&base->active, &timer->node))
                cpu_base->active_bases &= ~(1 << base->index);
  
-@@ -991,7 +1044,16 @@ void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
+@@ -989,7 +1042,16 @@ void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
        new_base = switch_hrtimer_base(timer, base, mode & HRTIMER_MODE_PINNED);
  
        timer_stats_hrtimer_set_start_info(timer);
@@ -19188,7 +20788,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
        leftmost = enqueue_hrtimer(timer, new_base);
        if (!leftmost)
                goto unlock;
-@@ -1063,7 +1125,7 @@ int hrtimer_cancel(struct hrtimer *timer)
+@@ -1061,7 +1123,7 @@ int hrtimer_cancel(struct hrtimer *timer)
  
                if (ret >= 0)
                        return ret;
@@ -19197,7 +20797,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
        }
  }
  EXPORT_SYMBOL_GPL(hrtimer_cancel);
-@@ -1127,6 +1189,7 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
+@@ -1137,6 +1199,7 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
  
        base = hrtimer_clockid_to_base(clock_id);
        timer->base = &cpu_base->clock_base[base];
@@ -19205,7 +20805,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
        timerqueue_init(&timer->node);
  
  #ifdef CONFIG_TIMER_STATS
-@@ -1167,6 +1230,7 @@ bool hrtimer_active(const struct hrtimer *timer)
+@@ -1177,6 +1240,7 @@ bool hrtimer_active(const struct hrtimer *timer)
                seq = raw_read_seqcount_begin(&cpu_base->seq);
  
                if (timer->state != HRTIMER_STATE_INACTIVE ||
@@ -19213,10 +20813,11 @@ index 9ba7c820fc23..d85f638fd99e 100644
                    cpu_base->running == timer)
                        return true;
  
-@@ -1265,10 +1329,112 @@ static void __run_hrtimer(struct hrtimer_cpu_base *cpu_base,
+@@ -1275,10 +1339,112 @@ static void __run_hrtimer(struct hrtimer_cpu_base *cpu_base,
        cpu_base->running = NULL;
  }
  
+-static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now)
 +#ifdef CONFIG_PREEMPT_RT_BASE
 +static void hrtimer_rt_reprogram(int restart, struct hrtimer *timer,
 +                               struct hrtimer_clock_base *base)
@@ -19318,7 +20919,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
 +
 +static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer);
 +
- static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now)
++static int __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now)
  {
        struct hrtimer_clock_base *base = cpu_base->clock_base;
        unsigned int active = cpu_base->active_bases;
@@ -19326,7 +20927,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
  
        for (; active; base++, active >>= 1) {
                struct timerqueue_node *node;
-@@ -1284,6 +1450,15 @@ static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now)
+@@ -1294,6 +1460,15 @@ static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now)
  
                        timer = container_of(node, struct hrtimer, node);
  
@@ -19342,7 +20943,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
                        /*
                         * The immediate goal for using the softexpires is
                         * minimizing wakeups, not running timers at the
-@@ -1299,9 +1474,14 @@ static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now)
+@@ -1309,9 +1484,13 @@ static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now)
                        if (basenow.tv64 < hrtimer_get_softexpires_tv64(timer))
                                break;
  
@@ -19353,12 +20954,57 @@ index 9ba7c820fc23..d85f638fd99e 100644
 +                              raise = 1;
                }
        }
++      return raise;
+ }
+ #ifdef CONFIG_HIGH_RES_TIMERS
+@@ -1325,6 +1504,7 @@ void hrtimer_interrupt(struct clock_event_device *dev)
+       struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
+       ktime_t expires_next, now, entry_time, delta;
+       int retries = 0;
++      int raise;
+       BUG_ON(!cpu_base->hres_active);
+       cpu_base->nr_events++;
+@@ -1343,7 +1523,7 @@ void hrtimer_interrupt(struct clock_event_device *dev)
+        */
+       cpu_base->expires_next.tv64 = KTIME_MAX;
+-      __hrtimer_run_queues(cpu_base, now);
++      raise = __hrtimer_run_queues(cpu_base, now);
+       /* Reevaluate the clock bases for the next expiry */
+       expires_next = __hrtimer_get_next_event(cpu_base);
+@@ -1354,6 +1534,8 @@ void hrtimer_interrupt(struct clock_event_device *dev)
+       cpu_base->expires_next = expires_next;
+       cpu_base->in_hrtirq = 0;
+       raw_spin_unlock(&cpu_base->lock);
++      if (raise)
++              raise_softirq_irqoff(HRTIMER_SOFTIRQ);
+       /* Reprogramming necessary ? */
+       if (!tick_program_event(expires_next, 0)) {
+@@ -1433,6 +1615,7 @@ void hrtimer_run_queues(void)
+ {
+       struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
+       ktime_t now;
++      int raise;
+       if (__hrtimer_hres_active(cpu_base))
+               return;
+@@ -1451,8 +1634,10 @@ void hrtimer_run_queues(void)
+       raw_spin_lock(&cpu_base->lock);
+       now = hrtimer_update_base(cpu_base);
+-      __hrtimer_run_queues(cpu_base, now);
++      raise = __hrtimer_run_queues(cpu_base, now);
+       raw_spin_unlock(&cpu_base->lock);
 +      if (raise)
 +              raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  }
  
- #ifdef CONFIG_HIGH_RES_TIMERS
-@@ -1464,16 +1644,18 @@ static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer)
+ /*
+@@ -1474,16 +1659,18 @@ static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer)
  void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task)
  {
        sl->timer.function = hrtimer_wakeup;
@@ -19379,7 +21025,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
                hrtimer_start_expires(&t->timer, mode);
  
                if (likely(t->task))
-@@ -1515,7 +1697,8 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
+@@ -1525,7 +1712,8 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
                                HRTIMER_MODE_ABS);
        hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
  
@@ -19389,7 +21035,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
                goto out;
  
        rmtp = restart->nanosleep.rmtp;
-@@ -1532,8 +1715,10 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
+@@ -1542,8 +1730,10 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
        return ret;
  }
  
@@ -19402,7 +21048,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
  {
        struct restart_block *restart;
        struct hrtimer_sleeper t;
-@@ -1546,7 +1731,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
+@@ -1556,7 +1746,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  
        hrtimer_init_on_stack(&t.timer, clockid, mode);
        hrtimer_set_expires_range_ns(&t.timer, timespec_to_ktime(*rqtp), slack);
@@ -19411,7 +21057,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
                goto out;
  
        /* Absolute timers do not update the rmtp value and restart: */
-@@ -1573,6 +1758,12 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
+@@ -1583,6 +1773,12 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
        return ret;
  }
  
@@ -19424,7 +21070,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
  SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,
                struct timespec __user *, rmtp)
  {
-@@ -1587,6 +1778,26 @@ SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,
+@@ -1597,6 +1793,26 @@ SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,
        return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
  }
  
@@ -19451,7 +21097,7 @@ index 9ba7c820fc23..d85f638fd99e 100644
  /*
   * Functions related to boot-time initialization:
   */
-@@ -1598,10 +1809,14 @@ int hrtimers_prepare_cpu(unsigned int cpu)
+@@ -1608,16 +1824,20 @@ int hrtimers_prepare_cpu(unsigned int cpu)
        for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
                cpu_base->clock_base[i].cpu_base = cpu_base;
                timerqueue_init_head(&cpu_base->clock_base[i].active);
@@ -19466,7 +21112,56 @@ index 9ba7c820fc23..d85f638fd99e 100644
        return 0;
  }
  
-@@ -1671,9 +1886,26 @@ int hrtimers_dead_cpu(unsigned int scpu)
+ #ifdef CONFIG_HOTPLUG_CPU
+-static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
++static int migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
+                               struct hrtimer_clock_base *new_base)
+ {
+       struct hrtimer *timer;
+@@ -1645,12 +1865,21 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
+                */
+               enqueue_hrtimer(timer, new_base);
+       }
++#ifdef CONFIG_PREEMPT_RT_BASE
++      list_splice_tail(&old_base->expired, &new_base->expired);
++      /*
++       * Tell the caller to raise HRTIMER_SOFTIRQ.  We can't safely
++       * acquire ktimersoftd->pi_lock while the base lock is held.
++       */
++      return !list_empty(&new_base->expired);
++#endif
++      return 0;
+ }
+ int hrtimers_dead_cpu(unsigned int scpu)
+ {
+       struct hrtimer_cpu_base *old_base, *new_base;
+-      int i;
++      int i, raise = 0;
+       BUG_ON(cpu_online(scpu));
+       tick_cancel_sched_timer(scpu);
+@@ -1666,13 +1895,16 @@ int hrtimers_dead_cpu(unsigned int scpu)
+       raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
+       for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
+-              migrate_hrtimer_list(&old_base->clock_base[i],
+-                                   &new_base->clock_base[i]);
++              raise |= migrate_hrtimer_list(&old_base->clock_base[i],
++                                            &new_base->clock_base[i]);
+       }
+       raw_spin_unlock(&old_base->lock);
+       raw_spin_unlock(&new_base->lock);
++      if (raise)
++              raise_softirq_irqoff(HRTIMER_SOFTIRQ);
++
+       /* Check, if we got expired work to do */
+       __hrtimer_peek_ahead_timers();
+       local_irq_enable();
+@@ -1681,9 +1913,26 @@ int hrtimers_dead_cpu(unsigned int scpu)
  
  #endif /* CONFIG_HOTPLUG_CPU */
  
@@ -19900,16 +21595,15 @@ index f2826c35e918..464a98155a0e 100644
  retry_delete:
        spin_lock_irqsave(&timer->it_lock, flags);
  
--      if (timer_delete_hook(timer) == TIMER_RETRY) {
 +      /* On RT we can race with a deletion */
 +      if (!timer->it_signal) {
-               unlock_timer(timer, flags);
++              unlock_timer(timer, flags);
 +              return;
 +      }
 +
-+      if (timer_delete_hook(timer) == TIMER_RETRY) {
+       if (timer_delete_hook(timer) == TIMER_RETRY) {
 +              rcu_read_lock();
-+              unlock_timer(timer, flags);
+               unlock_timer(timer, flags);
 +              timer_wait_for_callback(clockid_to_kclock(timer->it_clock),
 +                                      timer);
 +              rcu_read_unlock();
@@ -19962,7 +21656,7 @@ index 4fcd99e12aa0..5a47f2e98faf 100644
                clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
  
 diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
-index 2ec7c00228f3..c1b30b8c671a 100644
+index 3bcb61b52f6c..66d85482a96e 100644
 --- a/kernel/time/tick-sched.c
 +++ b/kernel/time/tick-sched.c
 @@ -62,7 +62,8 @@ static void tick_do_update_jiffies64(ktime_t now)
@@ -20007,7 +21701,7 @@ index 2ec7c00228f3..c1b30b8c671a 100644
        return period;
  }
  
-@@ -212,6 +217,7 @@ static void nohz_full_kick_func(struct irq_work *work)
+@@ -215,6 +220,7 @@ static void nohz_full_kick_func(struct irq_work *work)
  
  static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) = {
        .func = nohz_full_kick_func,
@@ -20015,7 +21709,7 @@ index 2ec7c00228f3..c1b30b8c671a 100644
  };
  
  /*
-@@ -670,10 +676,10 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts,
+@@ -673,10 +679,10 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts,
  
        /* Read jiffies and the time when jiffies were updated last */
        do {
@@ -20028,7 +21722,7 @@ index 2ec7c00228f3..c1b30b8c671a 100644
        ts->last_jiffies = basejiff;
  
        if (rcu_needs_cpu(basemono, &next_rcu) ||
-@@ -874,14 +880,7 @@ static bool can_stop_idle_tick(int cpu, struct tick_sched *ts)
+@@ -877,14 +883,7 @@ static bool can_stop_idle_tick(int cpu, struct tick_sched *ts)
                return false;
  
        if (unlikely(local_softirq_pending() && cpu_online(cpu))) {
@@ -20044,7 +21738,7 @@ index 2ec7c00228f3..c1b30b8c671a 100644
                return false;
        }
  
-@@ -1190,6 +1189,7 @@ void tick_setup_sched_timer(void)
+@@ -1193,6 +1192,7 @@ void tick_setup_sched_timer(void)
         * Emulate tick processing via per-CPU hrtimers:
         */
        hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
@@ -20053,10 +21747,10 @@ index 2ec7c00228f3..c1b30b8c671a 100644
  
        /* Get the next period (per-CPU) */
 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
-index 37dec7e3db43..fa8d90d2acc3 100644
+index d831827d7ab0..76d982c11ac3 100644
 --- a/kernel/time/timekeeping.c
 +++ b/kernel/time/timekeeping.c
-@@ -2328,8 +2328,10 @@ EXPORT_SYMBOL(hardpps);
+@@ -2348,8 +2348,10 @@ EXPORT_SYMBOL(hardpps);
   */
  void xtime_update(unsigned long ticks)
  {
@@ -20084,7 +21778,7 @@ index 704f595ce83f..763a3e5121ff 100644
  #define CS_NAME_LEN   32
  
 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
-index 32bf6f75a8fe..ba53447a03f5 100644
+index 7d670362891a..31703677505f 100644
 --- a/kernel/time/timer.c
 +++ b/kernel/time/timer.c
 @@ -193,8 +193,11 @@ EXPORT_SYMBOL(jiffies_64);
@@ -20100,7 +21794,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
        unsigned long           clk;
        unsigned long           next_expiry;
        unsigned int            cpu;
-@@ -947,10 +950,10 @@ static struct timer_base *lock_timer_base(struct timer_list *timer,
+@@ -955,10 +958,10 @@ static struct timer_base *lock_timer_base(struct timer_list *timer,
  
                if (!(tf & TIMER_MIGRATING)) {
                        base = get_timer_base(tf);
@@ -20113,7 +21807,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
                }
                cpu_relax();
        }
-@@ -1017,9 +1020,9 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
+@@ -1037,9 +1040,9 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
                        /* See the comment in lock_timer_base() */
                        timer->flags |= TIMER_MIGRATING;
  
@@ -20124,8 +21818,8 @@ index 32bf6f75a8fe..ba53447a03f5 100644
 +                      raw_spin_lock(&base->lock);
                        WRITE_ONCE(timer->flags,
                                   (timer->flags & ~TIMER_BASEMASK) | base->cpu);
-               }
-@@ -1040,7 +1043,7 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
+                       forward_timer_base(base);
+@@ -1062,7 +1065,7 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only)
        }
  
  out_unlock:
@@ -20134,7 +21828,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
  
        return ret;
  }
-@@ -1134,19 +1137,46 @@ void add_timer_on(struct timer_list *timer, int cpu)
+@@ -1156,9 +1159,9 @@ void add_timer_on(struct timer_list *timer, int cpu)
        if (base != new_base) {
                timer->flags |= TIMER_MIGRATING;
  
@@ -20146,6 +21840,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
                WRITE_ONCE(timer->flags,
                           (timer->flags & ~TIMER_BASEMASK) | cpu);
        }
+@@ -1166,10 +1169,37 @@ void add_timer_on(struct timer_list *timer, int cpu)
  
        debug_activate(timer, timer->expires);
        internal_add_timer(base, timer);
@@ -20184,7 +21879,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
  /**
   * del_timer - deactive a timer.
   * @timer: the timer to be deactivated
-@@ -1170,7 +1200,7 @@ int del_timer(struct timer_list *timer)
+@@ -1193,7 +1223,7 @@ int del_timer(struct timer_list *timer)
        if (timer_pending(timer)) {
                base = lock_timer_base(timer, &flags);
                ret = detach_if_pending(timer, base, true);
@@ -20193,7 +21888,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
        }
  
        return ret;
-@@ -1198,13 +1228,13 @@ int try_to_del_timer_sync(struct timer_list *timer)
+@@ -1221,13 +1251,13 @@ int try_to_del_timer_sync(struct timer_list *timer)
                timer_stats_timer_clear_start_info(timer);
                ret = detach_if_pending(timer, base, true);
        }
@@ -20209,7 +21904,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
  /**
   * del_timer_sync - deactivate a timer and wait for the handler to finish.
   * @timer: the timer to be deactivated
-@@ -1264,7 +1294,7 @@ int del_timer_sync(struct timer_list *timer)
+@@ -1287,7 +1317,7 @@ int del_timer_sync(struct timer_list *timer)
                int ret = try_to_del_timer_sync(timer);
                if (ret >= 0)
                        return ret;
@@ -20218,7 +21913,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
        }
  }
  EXPORT_SYMBOL(del_timer_sync);
-@@ -1329,14 +1359,17 @@ static void expire_timers(struct timer_base *base, struct hlist_head *head)
+@@ -1352,14 +1382,17 @@ static void expire_timers(struct timer_base *base, struct hlist_head *head)
                fn = timer->function;
                data = timer->data;
  
@@ -20241,7 +21936,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
                }
        }
  }
-@@ -1505,7 +1538,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
+@@ -1528,7 +1561,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
        if (cpu_is_offline(smp_processor_id()))
                return expires;
  
@@ -20250,16 +21945,16 @@ index 32bf6f75a8fe..ba53447a03f5 100644
        nextevt = __next_timer_interrupt(base);
        is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA);
        base->next_expiry = nextevt;
-@@ -1529,7 +1562,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
-               if ((expires - basem) > TICK_NSEC)
+@@ -1562,7 +1595,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
                        base->is_idle = true;
+               }
        }
 -      spin_unlock(&base->lock);
 +      raw_spin_unlock(&base->lock);
  
        return cmp_next_hrtimer_event(basem, expires);
  }
-@@ -1594,13 +1627,13 @@ void update_process_times(int user_tick)
+@@ -1627,13 +1660,13 @@ void update_process_times(int user_tick)
  
        /* Note: this timer irq context must be accounted for as well. */
        account_process_tick(p, user_tick);
@@ -20275,7 +21970,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
        run_posix_cpu_timers(p);
  }
  
-@@ -1616,7 +1649,7 @@ static inline void __run_timers(struct timer_base *base)
+@@ -1649,7 +1682,7 @@ static inline void __run_timers(struct timer_base *base)
        if (!time_after_eq(jiffies, base->clk))
                return;
  
@@ -20284,7 +21979,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
  
        while (time_after_eq(jiffies, base->clk)) {
  
-@@ -1626,8 +1659,8 @@ static inline void __run_timers(struct timer_base *base)
+@@ -1659,8 +1692,8 @@ static inline void __run_timers(struct timer_base *base)
                while (levels--)
                        expire_timers(base, heads + levels);
        }
@@ -20295,16 +21990,16 @@ index 32bf6f75a8fe..ba53447a03f5 100644
  }
  
  /*
-@@ -1637,6 +1670,8 @@ static void run_timer_softirq(struct softirq_action *h)
- {
-       struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
+@@ -1683,6 +1716,8 @@ static __latent_entropy void run_timer_softirq(struct softirq_action *h)
+        */
+       base->must_forward_clk = false;
  
 +      irq_work_tick_soft();
 +
        __run_timers(base);
        if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && base->nohz_active)
                __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF]));
-@@ -1822,16 +1857,16 @@ int timers_dead_cpu(unsigned int cpu)
+@@ -1868,16 +1903,16 @@ int timers_dead_cpu(unsigned int cpu)
                 * The caller is globally serialized and nobody else
                 * takes two locks at once, deadlock is not possible.
                 */
@@ -20325,7 +22020,7 @@ index 32bf6f75a8fe..ba53447a03f5 100644
                put_cpu_ptr(&timer_bases);
        }
        return 0;
-@@ -1847,8 +1882,11 @@ static void __init init_timer_cpu(int cpu)
+@@ -1893,8 +1928,11 @@ static void __init init_timer_cpu(int cpu)
        for (i = 0; i < NR_BASES; i++) {
                base = per_cpu_ptr(&timer_bases[i], cpu);
                base->cpu = cpu;
@@ -20339,10 +22034,10 @@ index 32bf6f75a8fe..ba53447a03f5 100644
  }
  
 diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
-index f4b86e8ca1e7..340f14eef24a 100644
+index 2a96b063d659..812e37237eb8 100644
 --- a/kernel/trace/Kconfig
 +++ b/kernel/trace/Kconfig
-@@ -187,6 +187,24 @@ config IRQSOFF_TRACER
+@@ -182,6 +182,24 @@ config IRQSOFF_TRACER
          enabled. This option and the preempt-off timing option can be
          used together or separately.)
  
@@ -20367,15 +22062,7 @@ index f4b86e8ca1e7..340f14eef24a 100644
  config PREEMPT_TRACER
        bool "Preemption-off Latency Tracer"
        default n
-@@ -197,6 +215,7 @@ config PREEMPT_TRACER
-       select RING_BUFFER_ALLOW_SWAP
-       select TRACER_SNAPSHOT
-       select TRACER_SNAPSHOT_PER_CPU_SWAP
-+      select USING_GET_LOCK_PARENT_IP
-       help
-         This option measures the time spent in preemption-off critical
-         sections, with microsecond accuracy.
-@@ -211,6 +230,24 @@ config PREEMPT_TRACER
+@@ -206,6 +224,24 @@ config PREEMPT_TRACER
          enabled. This option and the irqs-off timing option can be
          used together or separately.)
  
@@ -20400,9 +22087,9 @@ index f4b86e8ca1e7..340f14eef24a 100644
  config SCHED_TRACER
        bool "Scheduling Latency Tracer"
        select GENERIC_TRACER
-@@ -221,6 +258,74 @@ config SCHED_TRACER
-         This tracer tracks the latency of the highest priority task
-         to be scheduled in, starting from the point it has woken up.
+@@ -251,6 +287,74 @@ config HWLAT_TRACER
+        file. Every time a latency is greater than tracing_thresh, it will
+        be recorded into the ring buffer.
  
 +config WAKEUP_LATENCY_HIST
 +      bool "Scheduling Latency Histogram"
@@ -20476,13 +22163,13 @@ index f4b86e8ca1e7..340f14eef24a 100644
        bool "Trace process context switches and events"
        depends on !GENERIC_TRACER
 diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
-index d0a1617b52b4..6bf9e9ff1fa5 100644
+index e57980845549..83af000b783c 100644
 --- a/kernel/trace/Makefile
 +++ b/kernel/trace/Makefile
-@@ -41,6 +41,10 @@ obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o
- obj-$(CONFIG_IRQSOFF_TRACER) += trace_irqsoff.o
+@@ -38,6 +38,10 @@ obj-$(CONFIG_IRQSOFF_TRACER) += trace_irqsoff.o
  obj-$(CONFIG_PREEMPT_TRACER) += trace_irqsoff.o
  obj-$(CONFIG_SCHED_TRACER) += trace_sched_wakeup.o
+ obj-$(CONFIG_HWLAT_TRACER) += trace_hwlat.o
 +obj-$(CONFIG_INTERRUPT_OFF_HIST) += latency_hist.o
 +obj-$(CONFIG_PREEMPT_OFF_HIST) += latency_hist.o
 +obj-$(CONFIG_WAKEUP_LATENCY_HIST) += latency_hist.o
@@ -21675,7 +23362,7 @@ index 000000000000..7f6ee70dea41
 +
 +device_initcall(latency_hist_init);
 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
-index 7bc56762ca35..84ffcb813263 100644
+index c1e50cc0d7b0..035e61604455 100644
 --- a/kernel/trace/trace.c
 +++ b/kernel/trace/trace.c
 @@ -1897,6 +1897,7 @@ tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
@@ -21689,7 +23376,7 @@ index 7bc56762ca35..84ffcb813263 100644
 @@ -1907,8 +1908,11 @@ tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags,
                ((pc & NMI_MASK    ) ? TRACE_FLAG_NMI     : 0) |
                ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
-               ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
+               ((pc & SOFTIRQ_OFFSET) ? TRACE_FLAG_SOFTIRQ : 0) |
 -              (tif_need_resched() ? TRACE_FLAG_NEED_RESCHED : 0) |
 +              (tif_need_resched_now() ? TRACE_FLAG_NEED_RESCHED : 0) |
 +              (need_resched_lazy() ? TRACE_FLAG_NEED_RESCHED_LAZY : 0) |
@@ -21699,7 +23386,7 @@ index 7bc56762ca35..84ffcb813263 100644
  }
  EXPORT_SYMBOL_GPL(tracing_generic_entry_update);
  
-@@ -2892,14 +2896,17 @@ get_total_entries(struct trace_buffer *buf,
+@@ -2898,14 +2902,17 @@ get_total_entries(struct trace_buffer *buf,
  
  static void print_lat_help_header(struct seq_file *m)
  {
@@ -21725,7 +23412,7 @@ index 7bc56762ca35..84ffcb813263 100644
  }
  
  static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
-@@ -2925,11 +2932,14 @@ static void print_func_help_header_irq(struct trace_buffer *buf, struct seq_file
+@@ -2931,11 +2938,14 @@ static void print_func_help_header_irq(struct trace_buffer *buf, struct seq_file
        print_event_info(buf, m);
        seq_puts(m, "#                              _-----=> irqs-off\n"
                    "#                             / _----=> need-resched\n"
@@ -21746,10 +23433,10 @@ index 7bc56762ca35..84ffcb813263 100644
  
  void
 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
-index f783df416726..6f2d0fa4fbf1 100644
+index b0d8576c27ae..702b9376b278 100644
 --- a/kernel/trace/trace.h
 +++ b/kernel/trace/trace.h
-@@ -123,6 +123,7 @@ struct kretprobe_trace_entry_head {
+@@ -124,6 +124,7 @@ struct kretprobe_trace_entry_head {
   *  NEED_RESCHED      - reschedule is requested
   *  HARDIRQ           - inside an interrupt handler
   *  SOFTIRQ           - inside a softirq handler
@@ -21757,7 +23444,7 @@ index f783df416726..6f2d0fa4fbf1 100644
   */
  enum trace_flag_type {
        TRACE_FLAG_IRQS_OFF             = 0x01,
-@@ -132,6 +133,7 @@ enum trace_flag_type {
+@@ -133,6 +134,7 @@ enum trace_flag_type {
        TRACE_FLAG_SOFTIRQ              = 0x10,
        TRACE_FLAG_PREEMPT_RESCHED      = 0x20,
        TRACE_FLAG_NMI                  = 0x40,
@@ -21866,7 +23553,7 @@ index 03cdff84d026..940bd10b4406 100644
                start_critical_timing(a0, a1);
  }
 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
-index 0bb9cf2d53e6..455a7464772f 100644
+index 3fc20422c166..65a6dde71a7d 100644
 --- a/kernel/trace/trace_output.c
 +++ b/kernel/trace/trace_output.c
 @@ -386,6 +386,7 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
@@ -21934,19 +23621,30 @@ index b069ccbfb0b0..1a2e88e98b5e 100644
  
  struct user_struct *alloc_uid(kuid_t uid)
 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
-index 9acb29f280ec..caba62080411 100644
+index 63177be0159e..59fe007ad496 100644
 --- a/kernel/watchdog.c
 +++ b/kernel/watchdog.c
-@@ -315,6 +315,8 @@ static int is_softlockup(unsigned long touch_ts)
- #ifdef CONFIG_HARDLOCKUP_DETECTOR
+@@ -381,6 +381,7 @@ static void watchdog_enable(unsigned int cpu)
+       /* kick off the timer for the hardlockup detector */
+       hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+       hrtimer->function = watchdog_timer_fn;
++      hrtimer->irqsafe = 1;
  
+       /* Enable the perf event */
+       watchdog_nmi_enable(cpu);
+diff --git a/kernel/watchdog_hld.c b/kernel/watchdog_hld.c
+index 12b8dd640786..4c90d2ee7433 100644
+--- a/kernel/watchdog_hld.c
++++ b/kernel/watchdog_hld.c
+@@ -19,6 +19,7 @@
+ static DEFINE_PER_CPU(bool, hard_watchdog_warn);
+ static DEFINE_PER_CPU(bool, watchdog_nmi_touch);
+ static DEFINE_PER_CPU(struct perf_event *, watchdog_ev);
 +static DEFINE_RAW_SPINLOCK(watchdog_output_lock);
-+
- static struct perf_event_attr wd_hw_attr = {
-       .type           = PERF_TYPE_HARDWARE,
-       .config         = PERF_COUNT_HW_CPU_CYCLES,
-@@ -349,6 +351,13 @@ static void watchdog_overflow_callback(struct perf_event *event,
+ /* boot commands */
+ /*
+@@ -104,6 +105,13 @@ static void watchdog_overflow_callback(struct perf_event *event,
                /* only print hardlockups once */
                if (__this_cpu_read(hard_watchdog_warn) == true)
                        return;
@@ -21960,7 +23658,7 @@ index 9acb29f280ec..caba62080411 100644
  
                pr_emerg("Watchdog detected hard LOCKUP on cpu %d", this_cpu);
                print_modules();
-@@ -366,6 +375,7 @@ static void watchdog_overflow_callback(struct perf_event *event,
+@@ -121,6 +129,7 @@ static void watchdog_overflow_callback(struct perf_event *event,
                                !test_and_set_bit(0, &hardlockup_allcpu_dumped))
                        trigger_allbutself_cpu_backtrace();
  
@@ -21968,16 +23666,8 @@ index 9acb29f280ec..caba62080411 100644
                if (hardlockup_panic)
                        nmi_panic(regs, "Hard LOCKUP");
  
-@@ -513,6 +523,7 @@ static void watchdog_enable(unsigned int cpu)
-       /* kick off the timer for the hardlockup detector */
-       hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-       hrtimer->function = watchdog_timer_fn;
-+      hrtimer->irqsafe = 1;
-       /* Enable the perf event */
-       watchdog_nmi_enable(cpu);
 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
-index ef071ca73fc3..c7a62d6adb00 100644
+index 296dcca77f33..beee8ad4b9ea 100644
 --- a/kernel/workqueue.c
 +++ b/kernel/workqueue.c
 @@ -48,6 +48,8 @@
@@ -21989,7 +23679,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
  #include "workqueue_internal.h"
  
-@@ -121,11 +123,16 @@ enum {
+@@ -122,11 +124,16 @@ enum {
   *    cpu or grabbing pool->lock is enough for read access.  If
   *    POOL_DISASSOCIATED is set, it's identical to L.
   *
@@ -22007,7 +23697,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
   *
   * PW: wq_pool_mutex and wq->mutex protected for writes.  Either for reads.
   *
-@@ -134,7 +141,7 @@ enum {
+@@ -135,7 +142,7 @@ enum {
   *
   * WQ: wq->mutex protected.
   *
@@ -22034,7 +23724,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
         * determined without grabbing wq->mutex.
         */
        struct work_struct      unbound_release_work;
-@@ -348,6 +355,8 @@ EXPORT_SYMBOL_GPL(system_power_efficient_wq);
+@@ -349,6 +356,8 @@ EXPORT_SYMBOL_GPL(system_power_efficient_wq);
  struct workqueue_struct *system_freezable_power_efficient_wq __read_mostly;
  EXPORT_SYMBOL_GPL(system_freezable_power_efficient_wq);
  
@@ -22043,7 +23733,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  static int worker_thread(void *__worker);
  static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
  
-@@ -355,20 +364,20 @@ static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
+@@ -356,20 +365,20 @@ static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
  #include <trace/events/workqueue.h>
  
  #define assert_rcu_or_pool_mutex()                                    \
@@ -22070,7 +23760,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
  #define for_each_cpu_worker_pool(pool, cpu)                           \
        for ((pool) = &per_cpu(cpu_worker_pools, cpu)[0];               \
-@@ -380,7 +389,7 @@ static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
+@@ -381,7 +390,7 @@ static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
   * @pool: iteration cursor
   * @pi: integer used for iteration
   *
@@ -22079,7 +23769,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
   * locked.  If the pool needs to be used beyond the locking in effect, the
   * caller is responsible for guaranteeing that the pool stays online.
   *
-@@ -412,7 +421,7 @@ static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
+@@ -413,7 +422,7 @@ static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
   * @pwq: iteration cursor
   * @wq: the target workqueue
   *
@@ -22088,7 +23778,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
   * If the pwq needs to be used beyond the locking in effect, the caller is
   * responsible for guaranteeing that the pwq stays online.
   *
-@@ -424,6 +433,31 @@ static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
+@@ -425,6 +434,31 @@ static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
                if (({ assert_rcu_or_wq_mutex(wq); false; })) { }       \
                else
  
@@ -22120,7 +23810,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  #ifdef CONFIG_DEBUG_OBJECTS_WORK
  
  static struct debug_obj_descr work_debug_descr;
-@@ -548,7 +582,7 @@ static int worker_pool_assign_id(struct worker_pool *pool)
+@@ -549,7 +583,7 @@ static int worker_pool_assign_id(struct worker_pool *pool)
   * @wq: the target workqueue
   * @node: the node ID
   *
@@ -22129,7 +23819,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
   * read locked.
   * If the pwq needs to be used beyond the locking in effect, the caller is
   * responsible for guaranteeing that the pwq stays online.
-@@ -692,8 +726,8 @@ static struct pool_workqueue *get_work_pwq(struct work_struct *work)
+@@ -693,8 +727,8 @@ static struct pool_workqueue *get_work_pwq(struct work_struct *work)
   * @work: the work item of interest
   *
   * Pools are created and destroyed under wq_pool_mutex, and allows read
@@ -22140,7 +23830,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
   *
   * All fields of the returned pool are accessible as long as the above
   * mentioned locking is in effect.  If the returned pool needs to be used
-@@ -830,50 +864,45 @@ static struct worker *first_idle_worker(struct worker_pool *pool)
+@@ -831,50 +865,45 @@ static struct worker *first_idle_worker(struct worker_pool *pool)
   */
  static void wake_up_worker(struct worker_pool *pool)
  {
@@ -22209,7 +23899,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        struct worker_pool *pool;
  
        /*
-@@ -882,29 +911,26 @@ struct task_struct *wq_worker_sleeping(struct task_struct *task)
+@@ -883,29 +912,26 @@ struct task_struct *wq_worker_sleeping(struct task_struct *task)
         * checking NOT_RUNNING.
         */
        if (worker->flags & WORKER_NOT_RUNNING)
@@ -22249,7 +23939,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  }
  
  /**
-@@ -1098,12 +1124,12 @@ static void put_pwq_unlocked(struct pool_workqueue *pwq)
+@@ -1099,12 +1125,14 @@ static void put_pwq_unlocked(struct pool_workqueue *pwq)
  {
        if (pwq) {
                /*
@@ -22258,14 +23948,16 @@ index ef071ca73fc3..c7a62d6adb00 100644
                 * following lock operations are safe.
                 */
 -              spin_lock_irq(&pwq->pool->lock);
++              rcu_read_lock();
 +              local_spin_lock_irq(pendingb_lock, &pwq->pool->lock);
                put_pwq(pwq);
 -              spin_unlock_irq(&pwq->pool->lock);
 +              local_spin_unlock_irq(pendingb_lock, &pwq->pool->lock);
++              rcu_read_unlock();
        }
  }
  
-@@ -1207,7 +1233,7 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
+@@ -1208,7 +1236,7 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
        struct worker_pool *pool;
        struct pool_workqueue *pwq;
  
@@ -22274,7 +23966,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
        /* try to steal the timer if it exists */
        if (is_dwork) {
-@@ -1226,6 +1252,7 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
+@@ -1227,6 +1255,7 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
        if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)))
                return 0;
  
@@ -22282,7 +23974,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        /*
         * The queueing is in progress, or it is already queued. Try to
         * steal it from ->worklist without clearing WORK_STRUCT_PENDING.
-@@ -1264,14 +1291,16 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
+@@ -1265,14 +1294,16 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
                set_work_pool_and_keep_pending(work, pool->id);
  
                spin_unlock(&pool->lock);
@@ -22301,7 +23993,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        return -EAGAIN;
  }
  
-@@ -1373,7 +1402,7 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
+@@ -1374,7 +1405,7 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
         * queued or lose PENDING.  Grabbing PENDING and queueing should
         * happen with IRQ disabled.
         */
@@ -22310,7 +24002,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
        debug_work_activate(work);
  
-@@ -1381,6 +1410,7 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
+@@ -1382,6 +1413,7 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
        if (unlikely(wq->flags & __WQ_DRAINING) &&
            WARN_ON_ONCE(!is_chained_work(wq)))
                return;
@@ -22318,7 +24010,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  retry:
        if (req_cpu == WORK_CPU_UNBOUND)
                cpu = wq_select_unbound_cpu(raw_smp_processor_id());
-@@ -1437,10 +1467,8 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
+@@ -1438,10 +1470,8 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
        /* pwq determined, queue */
        trace_workqueue_queue_work(req_cpu, pwq, work);
  
@@ -22331,7 +24023,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
        pwq->nr_in_flight[pwq->work_color]++;
        work_flags = work_color_to_flags(pwq->work_color);
-@@ -1458,7 +1486,9 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
+@@ -1459,7 +1489,9 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
  
        insert_work(pwq, work, worklist, work_flags);
  
@@ -22341,7 +24033,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  }
  
  /**
-@@ -1478,14 +1508,14 @@ bool queue_work_on(int cpu, struct workqueue_struct *wq,
+@@ -1479,14 +1511,14 @@ bool queue_work_on(int cpu, struct workqueue_struct *wq,
        bool ret = false;
        unsigned long flags;
  
@@ -22358,7 +24050,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        return ret;
  }
  EXPORT_SYMBOL(queue_work_on);
-@@ -1552,14 +1582,14 @@ bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
+@@ -1553,14 +1585,14 @@ bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
        unsigned long flags;
  
        /* read the comment in __queue_work() */
@@ -22375,7 +24067,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        return ret;
  }
  EXPORT_SYMBOL(queue_delayed_work_on);
-@@ -1594,7 +1624,7 @@ bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
+@@ -1595,7 +1627,7 @@ bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
  
        if (likely(ret >= 0)) {
                __queue_delayed_work(cpu, wq, dwork, delay);
@@ -22384,7 +24076,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        }
  
        /* -ENOENT from try_to_grab_pending() becomes %true */
-@@ -1627,7 +1657,9 @@ static void worker_enter_idle(struct worker *worker)
+@@ -1628,7 +1660,9 @@ static void worker_enter_idle(struct worker *worker)
        worker->last_active = jiffies;
  
        /* idle_list is LIFO */
@@ -22394,7 +24086,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
        if (too_many_workers(pool) && !timer_pending(&pool->idle_timer))
                mod_timer(&pool->idle_timer, jiffies + IDLE_WORKER_TIMEOUT);
-@@ -1660,7 +1692,9 @@ static void worker_leave_idle(struct worker *worker)
+@@ -1661,7 +1695,9 @@ static void worker_leave_idle(struct worker *worker)
                return;
        worker_clr_flags(worker, WORKER_IDLE);
        pool->nr_idle--;
@@ -22404,7 +24096,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  }
  
  static struct worker *alloc_worker(int node)
-@@ -1826,7 +1860,9 @@ static void destroy_worker(struct worker *worker)
+@@ -1827,7 +1863,9 @@ static void destroy_worker(struct worker *worker)
        pool->nr_workers--;
        pool->nr_idle--;
  
@@ -22414,7 +24106,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        worker->flags |= WORKER_DIE;
        wake_up_process(worker->task);
  }
-@@ -2785,14 +2821,14 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr)
+@@ -2779,14 +2817,14 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr)
  
        might_sleep();
  
@@ -22432,7 +24124,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        /* see the comment in try_to_grab_pending() with the same code */
        pwq = get_work_pwq(work);
        if (pwq) {
-@@ -2821,10 +2857,11 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr)
+@@ -2815,10 +2853,11 @@ static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr)
        else
                lock_map_acquire_read(&pwq->wq->lockdep_map);
        lock_map_release(&pwq->wq->lockdep_map);
@@ -22445,7 +24137,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        return false;
  }
  
-@@ -2911,7 +2948,7 @@ static bool __cancel_work_timer(struct work_struct *work, bool is_dwork)
+@@ -2905,7 +2944,7 @@ static bool __cancel_work_timer(struct work_struct *work, bool is_dwork)
  
        /* tell other tasks trying to grab @work to back off */
        mark_work_canceling(work);
@@ -22454,7 +24146,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
        flush_work(work);
        clear_work_data(work);
-@@ -2966,10 +3003,10 @@ EXPORT_SYMBOL_GPL(cancel_work_sync);
+@@ -2960,10 +2999,10 @@ EXPORT_SYMBOL_GPL(cancel_work_sync);
   */
  bool flush_delayed_work(struct delayed_work *dwork)
  {
@@ -22467,16 +24159,16 @@ index ef071ca73fc3..c7a62d6adb00 100644
        return flush_work(&dwork->work);
  }
  EXPORT_SYMBOL(flush_delayed_work);
-@@ -3004,7 +3041,7 @@ bool cancel_delayed_work(struct delayed_work *dwork)
+@@ -2981,7 +3020,7 @@ static bool __cancel_work(struct work_struct *work, bool is_dwork)
+               return false;
  
-       set_work_pool_and_clear_pending(&dwork->work,
-                                       get_work_pool_id(&dwork->work));
+       set_work_pool_and_clear_pending(work, get_work_pool_id(work));
 -      local_irq_restore(flags);
 +      local_unlock_irqrestore(pendingb_lock, flags);
        return ret;
  }
- EXPORT_SYMBOL(cancel_delayed_work);
-@@ -3233,7 +3270,7 @@ static void rcu_free_pool(struct rcu_head *rcu)
+@@ -3238,7 +3277,7 @@ static void rcu_free_pool(struct rcu_head *rcu)
   * put_unbound_pool - put a worker_pool
   * @pool: worker_pool to put
   *
@@ -22485,7 +24177,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
   * safe manner.  get_unbound_pool() calls this function on its failure path
   * and this function should be able to release pools which went through,
   * successfully or not, init_worker_pool().
-@@ -3287,8 +3324,8 @@ static void put_unbound_pool(struct worker_pool *pool)
+@@ -3292,8 +3331,8 @@ static void put_unbound_pool(struct worker_pool *pool)
        del_timer_sync(&pool->idle_timer);
        del_timer_sync(&pool->mayday_timer);
  
@@ -22496,7 +24188,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  }
  
  /**
-@@ -3395,14 +3432,14 @@ static void pwq_unbound_release_workfn(struct work_struct *work)
+@@ -3400,14 +3439,14 @@ static void pwq_unbound_release_workfn(struct work_struct *work)
        put_unbound_pool(pool);
        mutex_unlock(&wq_pool_mutex);
  
@@ -22513,7 +24205,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  }
  
  /**
-@@ -4052,7 +4089,7 @@ void destroy_workqueue(struct workqueue_struct *wq)
+@@ -4071,7 +4110,7 @@ void destroy_workqueue(struct workqueue_struct *wq)
                 * The base ref is never dropped on per-cpu pwqs.  Directly
                 * schedule RCU free.
                 */
@@ -22522,7 +24214,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        } else {
                /*
                 * We're the sole accessor of @wq at this point.  Directly
-@@ -4145,7 +4182,8 @@ bool workqueue_congested(int cpu, struct workqueue_struct *wq)
+@@ -4165,7 +4204,8 @@ bool workqueue_congested(int cpu, struct workqueue_struct *wq)
        struct pool_workqueue *pwq;
        bool ret;
  
@@ -22532,7 +24224,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
        if (cpu == WORK_CPU_UNBOUND)
                cpu = smp_processor_id();
-@@ -4156,7 +4194,8 @@ bool workqueue_congested(int cpu, struct workqueue_struct *wq)
+@@ -4176,7 +4216,8 @@ bool workqueue_congested(int cpu, struct workqueue_struct *wq)
                pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu));
  
        ret = !list_empty(&pwq->delayed_works);
@@ -22542,7 +24234,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
        return ret;
  }
-@@ -4182,15 +4221,15 @@ unsigned int work_busy(struct work_struct *work)
+@@ -4202,15 +4243,15 @@ unsigned int work_busy(struct work_struct *work)
        if (work_pending(work))
                ret |= WORK_BUSY_PENDING;
  
@@ -22562,7 +24254,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
        return ret;
  }
-@@ -4379,7 +4418,7 @@ void show_workqueue_state(void)
+@@ -4399,7 +4440,7 @@ void show_workqueue_state(void)
        unsigned long flags;
        int pi;
  
@@ -22571,7 +24263,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  
        pr_info("Showing busy workqueues and worker pools:\n");
  
-@@ -4432,7 +4471,7 @@ void show_workqueue_state(void)
+@@ -4452,7 +4493,7 @@ void show_workqueue_state(void)
                spin_unlock_irqrestore(&pool->lock, flags);
        }
  
@@ -22580,7 +24272,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
  }
  
  /*
-@@ -4770,16 +4809,16 @@ bool freeze_workqueues_busy(void)
+@@ -4790,16 +4831,16 @@ bool freeze_workqueues_busy(void)
                 * nr_active is monotonically decreasing.  It's safe
                 * to peek without lock.
                 */
@@ -22600,7 +24292,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        }
  out_unlock:
        mutex_unlock(&wq_pool_mutex);
-@@ -4969,7 +5008,8 @@ static ssize_t wq_pool_ids_show(struct device *dev,
+@@ -4989,7 +5030,8 @@ static ssize_t wq_pool_ids_show(struct device *dev,
        const char *delim = "";
        int node, written = 0;
  
@@ -22610,7 +24302,7 @@ index ef071ca73fc3..c7a62d6adb00 100644
        for_each_node(node) {
                written += scnprintf(buf + written, PAGE_SIZE - written,
                                     "%s%d:%d", delim, node,
-@@ -4977,7 +5017,8 @@ static ssize_t wq_pool_ids_show(struct device *dev,
+@@ -4997,7 +5039,8 @@ static ssize_t wq_pool_ids_show(struct device *dev,
                delim = " ";
        }
        written += scnprintf(buf + written, PAGE_SIZE - written, "\n");
@@ -22621,10 +24313,10 @@ index ef071ca73fc3..c7a62d6adb00 100644
        return written;
  }
 diff --git a/kernel/workqueue_internal.h b/kernel/workqueue_internal.h
-index 8635417c587b..f000c4d6917e 100644
+index 29fa81f0f51a..42d1e3974554 100644
 --- a/kernel/workqueue_internal.h
 +++ b/kernel/workqueue_internal.h
-@@ -43,6 +43,7 @@ struct worker {
+@@ -44,6 +44,7 @@ struct worker {
        unsigned long           last_active;    /* L: last active timestamp */
        unsigned int            flags;          /* X: flags */
        int                     id;             /* I: worker id */
@@ -22632,7 +24324,7 @@ index 8635417c587b..f000c4d6917e 100644
  
        /*
         * Opaque string set with work_set_desc().  Printed out with task
-@@ -68,7 +69,7 @@ static inline struct worker *current_wq_worker(void)
+@@ -69,7 +70,7 @@ static inline struct worker *current_wq_worker(void)
   * Scheduler hooks for concurrency managed workqueue.  Only to be used from
   * sched/core.c and workqueue.c.
   */
@@ -22643,7 +24335,7 @@ index 8635417c587b..f000c4d6917e 100644
  
  #endif /* _KERNEL_WORKQUEUE_INTERNAL_H */
 diff --git a/lib/Kconfig b/lib/Kconfig
-index d79909dc01ec..fd2accb2f2bb 100644
+index 260a80e313b9..b06becb3f477 100644
 --- a/lib/Kconfig
 +++ b/lib/Kconfig
 @@ -400,6 +400,7 @@ config CHECK_SIGNATURE
@@ -22654,38 +24346,8 @@ index d79909dc01ec..fd2accb2f2bb 100644
        help
          Use dynamic allocation for cpumask_var_t, instead of putting
          them on the stack.  This is a bit more expensive, but avoids
-diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
-index cab7405f48d2..dbc49c48ff53 100644
---- a/lib/Kconfig.debug
-+++ b/lib/Kconfig.debug
-@@ -977,6 +977,7 @@ config TIMER_STATS
- config DEBUG_PREEMPT
-       bool "Debug preemptible kernel"
-       depends on DEBUG_KERNEL && PREEMPT && TRACE_IRQFLAGS_SUPPORT
-+      select USING_GET_LOCK_PARENT_IP
-       default y
-       help
-         If you say Y here then the kernel will use a debug variant of the
-@@ -1159,8 +1160,17 @@ config LOCK_TORTURE_TEST
- endmenu # lock debugging
-+config USING_GET_LOCK_PARENT_IP
-+        bool
-+      help
-+        Enables the use of the function get_lock_parent_ip() that
-+        will use __builtin_return_address(n) with n > 0 causing
-+        some gcc warnings. When this is selected, those warnings
-+        will be suppressed.
-+
- config TRACE_IRQFLAGS
-       bool
-+      select USING_GET_LOCK_PARENT_IP
-       help
-         Enables hooks to interrupt enabling and disabling for
-         either tracing or lock debugging.
 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
-index a8e12601eb37..c76d5f0beafe 100644
+index 056052dc8e91..d8494e126de8 100644
 --- a/lib/debugobjects.c
 +++ b/lib/debugobjects.c
 @@ -308,7 +308,10 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
@@ -22797,7 +24459,7 @@ index 6098336df267..9decbe914595 100644
                        break;
  
 diff --git a/lib/irq_poll.c b/lib/irq_poll.c
-index 836f7db4e548..709d4eed1df9 100644
+index 1d6565e81030..b23a79761df7 100644
 --- a/lib/irq_poll.c
 +++ b/lib/irq_poll.c
 @@ -36,6 +36,7 @@ void irq_poll_sched(struct irq_poll *iop)
@@ -22816,7 +24478,7 @@ index 836f7db4e548..709d4eed1df9 100644
  }
  EXPORT_SYMBOL(irq_poll_complete);
  
-@@ -95,6 +97,7 @@ static void irq_poll_softirq(struct softirq_action *h)
+@@ -95,6 +97,7 @@ static void __latent_entropy irq_poll_softirq(struct softirq_action *h)
                }
  
                local_irq_enable();
@@ -22824,7 +24486,7 @@ index 836f7db4e548..709d4eed1df9 100644
  
                /* Even though interrupts have been re-enabled, this
                 * access is safe because interrupts can only add new
-@@ -132,6 +135,7 @@ static void irq_poll_softirq(struct softirq_action *h)
+@@ -132,6 +135,7 @@ static void __latent_entropy irq_poll_softirq(struct softirq_action *h)
                __raise_softirq_irqoff(IRQ_POLL_SOFTIRQ);
  
        local_irq_enable();
@@ -22832,16 +24494,16 @@ index 836f7db4e548..709d4eed1df9 100644
  }
  
  /**
-@@ -199,6 +203,7 @@ static int irq_poll_cpu_notify(struct notifier_block *self,
-                                this_cpu_ptr(&blk_cpu_iopoll));
-               __raise_softirq_irqoff(IRQ_POLL_SOFTIRQ);
-               local_irq_enable();
-+              preempt_check_resched_rt();
-       }
+@@ -195,6 +199,7 @@ static int irq_poll_cpu_dead(unsigned int cpu)
+                        this_cpu_ptr(&blk_cpu_iopoll));
+       __raise_softirq_irqoff(IRQ_POLL_SOFTIRQ);
+       local_irq_enable();
++      preempt_check_resched_rt();
  
-       return NOTIFY_OK;
+       return 0;
+ }
 diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
-index 872a15a2a637..b93a6103fa4d 100644
+index f3a217ea0388..4611b156ef79 100644
 --- a/lib/locking-selftest.c
 +++ b/lib/locking-selftest.c
 @@ -590,6 +590,8 @@ GENERATE_TESTCASE(init_held_rsem)
@@ -23085,41 +24747,91 @@ index 6d40944960de..822a2c027e72 100644
  }
  EXPORT_SYMBOL_GPL(percpu_ida_for_each_free);
 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
-index 8e6d552c40dd..881cc195d85f 100644
+index 8e6d552c40dd..741da5a77fd5 100644
 --- a/lib/radix-tree.c
 +++ b/lib/radix-tree.c
-@@ -290,13 +290,14 @@ radix_tree_node_alloc(struct radix_tree_root *root)
+@@ -36,7 +36,7 @@
+ #include <linux/bitops.h>
+ #include <linux/rcupdate.h>
+ #include <linux/preempt.h>            /* in_interrupt() */
+-
++#include <linux/locallock.h>
+ /* Number of nodes in fully populated tree of given height */
+ static unsigned long height_to_maxnodes[RADIX_TREE_MAX_PATH + 1] __read_mostly;
+@@ -68,6 +68,7 @@ struct radix_tree_preload {
+       struct radix_tree_node *nodes;
+ };
+ static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
++static DEFINE_LOCAL_IRQ_LOCK(radix_tree_preloads_lock);
+ static inline void *node_to_entry(void *ptr)
+ {
+@@ -290,13 +291,14 @@ radix_tree_node_alloc(struct radix_tree_root *root)
                 * succeed in getting a node here (and never reach
                 * kmem_cache_alloc)
                 */
 -              rtp = this_cpu_ptr(&radix_tree_preloads);
-+              rtp = &get_cpu_var(radix_tree_preloads);
++              rtp = &get_locked_var(radix_tree_preloads_lock, radix_tree_preloads);
                if (rtp->nr) {
                        ret = rtp->nodes;
                        rtp->nodes = ret->private_data;
                        ret->private_data = NULL;
                        rtp->nr--;
                }
-+              put_cpu_var(radix_tree_preloads);
++              put_locked_var(radix_tree_preloads_lock, radix_tree_preloads);
                /*
                 * Update the allocation stack trace as this is more useful
                 * for debugging.
-@@ -336,6 +337,7 @@ radix_tree_node_free(struct radix_tree_node *node)
-       call_rcu(&node->rcu_head, radix_tree_node_rcu_free);
+@@ -357,14 +359,14 @@ static int __radix_tree_preload(gfp_t gfp_mask, int nr)
+        */
+       gfp_mask &= ~__GFP_ACCOUNT;
+-      preempt_disable();
++      local_lock(radix_tree_preloads_lock);
+       rtp = this_cpu_ptr(&radix_tree_preloads);
+       while (rtp->nr < nr) {
+-              preempt_enable();
++              local_unlock(radix_tree_preloads_lock);
+               node = kmem_cache_alloc(radix_tree_node_cachep, gfp_mask);
+               if (node == NULL)
+                       goto out;
+-              preempt_disable();
++              local_lock(radix_tree_preloads_lock);
+               rtp = this_cpu_ptr(&radix_tree_preloads);
+               if (rtp->nr < nr) {
+                       node->private_data = rtp->nodes;
+@@ -406,7 +408,7 @@ int radix_tree_maybe_preload(gfp_t gfp_mask)
+       if (gfpflags_allow_blocking(gfp_mask))
+               return __radix_tree_preload(gfp_mask, RADIX_TREE_PRELOAD_SIZE);
+       /* Preloading doesn't help anything with this gfp mask, skip it */
+-      preempt_disable();
++      local_lock(radix_tree_preloads_lock);
+       return 0;
  }
+ EXPORT_SYMBOL(radix_tree_maybe_preload);
+@@ -422,7 +424,7 @@ int radix_tree_maybe_preload_order(gfp_t gfp_mask, int order)
  
-+#ifndef CONFIG_PREEMPT_RT_FULL
- /*
-  * Load up this CPU's radix_tree_node buffer with sufficient objects to
-  * ensure that the addition of a single element in the tree cannot fail.  On
-@@ -455,6 +457,7 @@ int radix_tree_maybe_preload_order(gfp_t gfp_mask, int order)
+       /* Preloading doesn't help anything with this gfp mask, skip it */
+       if (!gfpflags_allow_blocking(gfp_mask)) {
+-              preempt_disable();
++              local_lock(radix_tree_preloads_lock);
+               return 0;
+       }
  
+@@ -456,6 +458,12 @@ int radix_tree_maybe_preload_order(gfp_t gfp_mask, int order)
        return __radix_tree_preload(gfp_mask, nr_nodes);
  }
-+#endif
  
++void radix_tree_preload_end(void)
++{
++      local_unlock(radix_tree_preloads_lock);
++}
++EXPORT_SYMBOL(radix_tree_preload_end);
++
  /*
   * The maximum index which can be stored in a radix tree
+  */
 diff --git a/lib/scatterlist.c b/lib/scatterlist.c
 index 004fc70fc56a..ccc46992a517 100644
 --- a/lib/scatterlist.c
@@ -23169,13 +24881,13 @@ index 1afec32de6f2..11fa431046a8 100644
        dump_stack();
 diff --git a/localversion-rt b/localversion-rt
 new file mode 100644
-index 000000000000..0efe7ba1930e
+index 000000000000..66fa05e70f29
 --- /dev/null
 +++ b/localversion-rt
 @@ -0,0 +1 @@
-+-rt5
++-rt60
 diff --git a/mm/Kconfig b/mm/Kconfig
-index be0ee11fa0d9..fe2857d67973 100644
+index 86e3e0e74d20..77e5862a1ed2 100644
 --- a/mm/Kconfig
 +++ b/mm/Kconfig
 @@ -410,7 +410,7 @@ config NOMMU_INITIAL_TRIM_EXCESS
@@ -23188,7 +24900,7 @@ index be0ee11fa0d9..fe2857d67973 100644
        select RADIX_TREE_MULTIORDER
        help
 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
-index 8fde443f36d7..d7a863b0ec20 100644
+index 6ff2d7744223..b5a91dd53b5f 100644
 --- a/mm/backing-dev.c
 +++ b/mm/backing-dev.c
 @@ -457,9 +457,9 @@ void wb_congested_put(struct bdi_writeback_congested *congested)
@@ -23204,10 +24916,10 @@ index 8fde443f36d7..d7a863b0ec20 100644
        }
  
 diff --git a/mm/compaction.c b/mm/compaction.c
-index 9affb2908304..d5eb0e52e96f 100644
+index 70e6bec46dc2..6678ed58b7c6 100644
 --- a/mm/compaction.c
 +++ b/mm/compaction.c
-@@ -1585,10 +1585,12 @@ static enum compact_result compact_zone(struct zone *zone, struct compact_contro
+@@ -1593,10 +1593,12 @@ static enum compact_result compact_zone(struct zone *zone, struct compact_contro
                                block_start_pfn(cc->migrate_pfn, cc->order);
  
                        if (cc->last_migrated_pfn < current_block_start) {
@@ -23223,7 +24935,7 @@ index 9affb2908304..d5eb0e52e96f 100644
                                cc->last_migrated_pfn = 0;
                        }
 diff --git a/mm/filemap.c b/mm/filemap.c
-index ced9ef6c06b0..19f6f0d77604 100644
+index edfb90e3830c..a8d2c7a73d54 100644
 --- a/mm/filemap.c
 +++ b/mm/filemap.c
 @@ -159,9 +159,12 @@ static int page_cache_tree_insert(struct address_space *mapping,
@@ -23283,7 +24995,7 @@ index 50b4ca6787f0..77518a3b35a1 100644
  unsigned int nr_free_highpages (void)
  {
 diff --git a/mm/memcontrol.c b/mm/memcontrol.c
-index 4be518d4e68a..724240ca2f35 100644
+index 2a800c4a39bd..c04403033aec 100644
 --- a/mm/memcontrol.c
 +++ b/mm/memcontrol.c
 @@ -67,6 +67,7 @@
@@ -23303,67 +25015,7 @@ index 4be518d4e68a..724240ca2f35 100644
  /* Whether legacy memory+swap accounting is active */
  static bool do_memsw_account(void)
  {
-@@ -1724,6 +1727,7 @@ struct memcg_stock_pcp {
- #define FLUSHING_CACHED_CHARGE        0
- };
- static DEFINE_PER_CPU(struct memcg_stock_pcp, memcg_stock);
-+static DEFINE_LOCAL_IRQ_LOCK(memcg_stock_ll);
- static DEFINE_MUTEX(percpu_charge_mutex);
- /**
-@@ -1746,7 +1750,7 @@ static bool consume_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
-       if (nr_pages > CHARGE_BATCH)
-               return ret;
--      local_irq_save(flags);
-+      local_lock_irqsave(memcg_stock_ll, flags);
-       stock = this_cpu_ptr(&memcg_stock);
-       if (memcg == stock->cached && stock->nr_pages >= nr_pages) {
-@@ -1754,7 +1758,7 @@ static bool consume_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
-               ret = true;
-       }
--      local_irq_restore(flags);
-+      local_unlock_irqrestore(memcg_stock_ll, flags);
-       return ret;
- }
-@@ -1781,13 +1785,13 @@ static void drain_local_stock(struct work_struct *dummy)
-       struct memcg_stock_pcp *stock;
-       unsigned long flags;
--      local_irq_save(flags);
-+      local_lock_irqsave(memcg_stock_ll, flags);
-       stock = this_cpu_ptr(&memcg_stock);
-       drain_stock(stock);
-       clear_bit(FLUSHING_CACHED_CHARGE, &stock->flags);
--      local_irq_restore(flags);
-+      local_unlock_irqrestore(memcg_stock_ll, flags);
- }
- /*
-@@ -1799,7 +1803,7 @@ static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
-       struct memcg_stock_pcp *stock;
-       unsigned long flags;
--      local_irq_save(flags);
-+      local_lock_irqsave(memcg_stock_ll, flags);
-       stock = this_cpu_ptr(&memcg_stock);
-       if (stock->cached != memcg) { /* reset if necessary */
-@@ -1808,7 +1812,7 @@ static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
-       }
-       stock->nr_pages += nr_pages;
--      local_irq_restore(flags);
-+      local_unlock_irqrestore(memcg_stock_ll, flags);
- }
- /*
-@@ -1824,7 +1828,7 @@ static void drain_all_stock(struct mem_cgroup *root_memcg)
+@@ -1795,7 +1798,7 @@ static void drain_all_stock(struct mem_cgroup *root_memcg)
                return;
        /* Notify other cpus that system-wide "drain" is running */
        get_online_cpus();
@@ -23372,7 +25024,7 @@ index 4be518d4e68a..724240ca2f35 100644
        for_each_online_cpu(cpu) {
                struct memcg_stock_pcp *stock = &per_cpu(memcg_stock, cpu);
                struct mem_cgroup *memcg;
-@@ -1841,7 +1845,7 @@ static void drain_all_stock(struct mem_cgroup *root_memcg)
+@@ -1812,7 +1815,7 @@ static void drain_all_stock(struct mem_cgroup *root_memcg)
                                schedule_work_on(cpu, &stock->work);
                }
        }
@@ -23381,7 +25033,7 @@ index 4be518d4e68a..724240ca2f35 100644
        put_online_cpus();
        mutex_unlock(&percpu_charge_mutex);
  }
-@@ -4566,12 +4570,12 @@ static int mem_cgroup_move_account(struct page *page,
+@@ -4558,12 +4561,12 @@ static int mem_cgroup_move_account(struct page *page,
  
        ret = 0;
  
@@ -23396,7 +25048,7 @@ index 4be518d4e68a..724240ca2f35 100644
  out_unlock:
        unlock_page(page);
  out:
-@@ -5444,10 +5448,10 @@ void mem_cgroup_commit_charge(struct page *page, struct mem_cgroup *memcg,
+@@ -5438,10 +5441,10 @@ void mem_cgroup_commit_charge(struct page *page, struct mem_cgroup *memcg,
  
        commit_charge(page, memcg, lrucare);
  
@@ -23409,7 +25061,7 @@ index 4be518d4e68a..724240ca2f35 100644
  
        if (do_memsw_account() && PageSwapCache(page)) {
                swp_entry_t entry = { .val = page_private(page) };
-@@ -5503,14 +5507,14 @@ static void uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout,
+@@ -5497,14 +5500,14 @@ static void uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout,
                memcg_oom_recover(memcg);
        }
  
@@ -23426,7 +25078,7 @@ index 4be518d4e68a..724240ca2f35 100644
  
        if (!mem_cgroup_is_root(memcg))
                css_put_many(&memcg->css, nr_pages);
-@@ -5665,10 +5669,10 @@ void mem_cgroup_migrate(struct page *oldpage, struct page *newpage)
+@@ -5659,10 +5662,10 @@ void mem_cgroup_migrate(struct page *oldpage, struct page *newpage)
  
        commit_charge(newpage, memcg, false);
  
@@ -23439,7 +25091,7 @@ index 4be518d4e68a..724240ca2f35 100644
  }
  
  DEFINE_STATIC_KEY_FALSE(memcg_sockets_enabled_key);
-@@ -5845,6 +5849,7 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
+@@ -5853,6 +5856,7 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
  {
        struct mem_cgroup *memcg, *swap_memcg;
        unsigned short oldid;
@@ -23447,7 +25099,7 @@ index 4be518d4e68a..724240ca2f35 100644
  
        VM_BUG_ON_PAGE(PageLRU(page), page);
        VM_BUG_ON_PAGE(page_count(page), page);
-@@ -5885,12 +5890,16 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
+@@ -5893,12 +5897,16 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
         * important here to have the interrupts disabled because it is the
         * only synchronisation we have for udpating the per-CPU variables.
         */
@@ -23485,7 +25137,7 @@ index 6f4d27c5bb32..5cd25c745a8f 100644
  #ifdef finish_arch_post_lock_switch
        finish_arch_post_lock_switch();
 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
-index a2214c64ed3c..4be4d5d66f73 100644
+index fbc38888252b..1cb08e1406ea 100644
 --- a/mm/page_alloc.c
 +++ b/mm/page_alloc.c
 @@ -61,6 +61,7 @@
@@ -23496,7 +25148,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  #include <linux/page_owner.h>
  #include <linux/kthread.h>
  #include <linux/memcontrol.h>
-@@ -276,6 +277,18 @@ EXPORT_SYMBOL(nr_node_ids);
+@@ -281,6 +282,18 @@ EXPORT_SYMBOL(nr_node_ids);
  EXPORT_SYMBOL(nr_online_nodes);
  #endif
  
@@ -23515,7 +25167,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  int page_group_by_mobility_disabled __read_mostly;
  
  #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
-@@ -1056,7 +1069,7 @@ static bool bulkfree_pcp_prepare(struct page *page)
+@@ -1092,7 +1105,7 @@ static bool bulkfree_pcp_prepare(struct page *page)
  #endif /* CONFIG_DEBUG_VM */
  
  /*
@@ -23524,7 +25176,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
   * Assumes all pages on list are in same zone, and of same order.
   * count is the number of pages to free.
   *
-@@ -1067,19 +1080,58 @@ static bool bulkfree_pcp_prepare(struct page *page)
+@@ -1103,19 +1116,58 @@ static bool bulkfree_pcp_prepare(struct page *page)
   * pinned" detection logic.
   */
  static void free_pcppages_bulk(struct zone *zone, int count,
@@ -23587,7 +25239,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
        while (count) {
                struct page *page;
                struct list_head *list;
-@@ -1095,7 +1147,7 @@ static void free_pcppages_bulk(struct zone *zone, int count,
+@@ -1131,7 +1183,7 @@ static void free_pcppages_bulk(struct zone *zone, int count,
                        batch_free++;
                        if (++migratetype == MIGRATE_PCPTYPES)
                                migratetype = 0;
@@ -23596,7 +25248,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
                } while (list_empty(list));
  
                /* This is the only non-empty list. Free them all. */
-@@ -1103,27 +1155,12 @@ static void free_pcppages_bulk(struct zone *zone, int count,
+@@ -1139,27 +1191,12 @@ static void free_pcppages_bulk(struct zone *zone, int count,
                        batch_free = count;
  
                do {
@@ -23625,7 +25277,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  }
  
  static void free_one_page(struct zone *zone,
-@@ -1132,7 +1169,9 @@ static void free_one_page(struct zone *zone,
+@@ -1168,7 +1205,9 @@ static void free_one_page(struct zone *zone,
                                int migratetype)
  {
        unsigned long nr_scanned;
@@ -23636,7 +25288,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
        nr_scanned = node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED);
        if (nr_scanned)
                __mod_node_page_state(zone->zone_pgdat, NR_PAGES_SCANNED, -nr_scanned);
-@@ -1142,7 +1181,7 @@ static void free_one_page(struct zone *zone,
+@@ -1178,7 +1217,7 @@ static void free_one_page(struct zone *zone,
                migratetype = get_pfnblock_migratetype(page, pfn);
        }
        __free_one_page(page, pfn, zone, order, migratetype);
@@ -23645,7 +25297,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  }
  
  static void __meminit __init_single_page(struct page *page, unsigned long pfn,
-@@ -1228,10 +1267,10 @@ static void __free_pages_ok(struct page *page, unsigned int order)
+@@ -1264,10 +1303,10 @@ static void __free_pages_ok(struct page *page, unsigned int order)
                return;
  
        migratetype = get_pfnblock_migratetype(page, pfn);
@@ -23658,7 +25310,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  }
  
  static void __init __free_pages_boot_core(struct page *page, unsigned int order)
-@@ -2219,16 +2258,18 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
+@@ -2282,16 +2321,18 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,
  void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp)
  {
        unsigned long flags;
@@ -23680,7 +25332,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  }
  #endif
  
-@@ -2244,16 +2285,21 @@ static void drain_pages_zone(unsigned int cpu, struct zone *zone)
+@@ -2307,16 +2348,21 @@ static void drain_pages_zone(unsigned int cpu, struct zone *zone)
        unsigned long flags;
        struct per_cpu_pageset *pset;
        struct per_cpu_pages *pcp;
@@ -23706,7 +25358,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  }
  
  /*
-@@ -2339,8 +2385,17 @@ void drain_all_pages(struct zone *zone)
+@@ -2402,8 +2448,17 @@ void drain_all_pages(struct zone *zone)
                else
                        cpumask_clear_cpu(cpu, &cpus_with_pcps);
        }
@@ -23724,7 +25376,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  }
  
  #ifdef CONFIG_HIBERNATION
-@@ -2400,7 +2455,7 @@ void free_hot_cold_page(struct page *page, bool cold)
+@@ -2463,7 +2518,7 @@ void free_hot_cold_page(struct page *page, bool cold)
  
        migratetype = get_pfnblock_migratetype(page, pfn);
        set_pcppage_migratetype(page, migratetype);
@@ -23733,7 +25385,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
        __count_vm_event(PGFREE);
  
        /*
-@@ -2426,12 +2481,17 @@ void free_hot_cold_page(struct page *page, bool cold)
+@@ -2489,12 +2544,17 @@ void free_hot_cold_page(struct page *page, bool cold)
        pcp->count++;
        if (pcp->count >= pcp->high) {
                unsigned long batch = READ_ONCE(pcp->batch);
@@ -23753,7 +25405,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  }
  
  /*
-@@ -2568,7 +2628,7 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
+@@ -2629,7 +2689,7 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
                struct per_cpu_pages *pcp;
                struct list_head *list;
  
@@ -23762,7 +25414,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
                do {
                        pcp = &this_cpu_ptr(zone->pageset)->pcp;
                        list = &pcp->lists[migratetype];
-@@ -2595,7 +2655,7 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
+@@ -2656,7 +2716,7 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
                 * allocate greater than order-1 page units with __GFP_NOFAIL.
                 */
                WARN_ON_ONCE((gfp_flags & __GFP_NOFAIL) && (order > 1));
@@ -23771,7 +25423,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  
                do {
                        page = NULL;
-@@ -2607,22 +2667,24 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
+@@ -2668,22 +2728,24 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
                        if (!page)
                                page = __rmqueue(zone, order, migratetype);
                } while (page && check_new_pages(page, order));
@@ -23800,7 +25452,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
        return NULL;
  }
  
-@@ -6528,7 +6590,9 @@ static int page_alloc_cpu_notify(struct notifier_block *self,
+@@ -6561,7 +6623,9 @@ static int page_alloc_cpu_notify(struct notifier_block *self,
        int cpu = (unsigned long)hcpu;
  
        if (action == CPU_DEAD || action == CPU_DEAD_FROZEN) {
@@ -23810,7 +25462,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
                drain_pages(cpu);
  
                /*
-@@ -6554,6 +6618,7 @@ static int page_alloc_cpu_notify(struct notifier_block *self,
+@@ -6587,6 +6651,7 @@ static int page_alloc_cpu_notify(struct notifier_block *self,
  void __init page_alloc_init(void)
  {
        hotcpu_notifier(page_alloc_cpu_notify, 0);
@@ -23818,7 +25470,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
  }
  
  /*
-@@ -7370,7 +7435,7 @@ void zone_pcp_reset(struct zone *zone)
+@@ -7422,7 +7487,7 @@ void zone_pcp_reset(struct zone *zone)
        struct per_cpu_pageset *pset;
  
        /* avoid races with drain_pages()  */
@@ -23827,7 +25479,7 @@ index a2214c64ed3c..4be4d5d66f73 100644
        if (zone->pageset != &boot_pageset) {
                for_each_online_cpu(cpu) {
                        pset = per_cpu_ptr(zone->pageset, cpu);
-@@ -7379,7 +7444,7 @@ void zone_pcp_reset(struct zone *zone)
+@@ -7431,7 +7496,7 @@ void zone_pcp_reset(struct zone *zone)
                free_percpu(zone->pageset);
                zone->pageset = &boot_pageset;
        }
@@ -23836,8 +25488,74 @@ index a2214c64ed3c..4be4d5d66f73 100644
  }
  
  #ifdef CONFIG_MEMORY_HOTREMOVE
+diff --git a/mm/percpu.c b/mm/percpu.c
+index f014cebbf405..4e739fcf91bf 100644
+--- a/mm/percpu.c
++++ b/mm/percpu.c
+@@ -1283,18 +1283,7 @@ void free_percpu(void __percpu *ptr)
+ }
+ EXPORT_SYMBOL_GPL(free_percpu);
+-/**
+- * is_kernel_percpu_address - test whether address is from static percpu area
+- * @addr: address to test
+- *
+- * Test whether @addr belongs to in-kernel static percpu area.  Module
+- * static percpu areas are not considered.  For those, use
+- * is_module_percpu_address().
+- *
+- * RETURNS:
+- * %true if @addr is from in-kernel static percpu area, %false otherwise.
+- */
+-bool is_kernel_percpu_address(unsigned long addr)
++bool __is_kernel_percpu_address(unsigned long addr, unsigned long *can_addr)
+ {
+ #ifdef CONFIG_SMP
+       const size_t static_size = __per_cpu_end - __per_cpu_start;
+@@ -1303,16 +1292,39 @@ bool is_kernel_percpu_address(unsigned long addr)
+       for_each_possible_cpu(cpu) {
+               void *start = per_cpu_ptr(base, cpu);
++              void *va = (void *)addr;
+-              if ((void *)addr >= start && (void *)addr < start + static_size)
++              if (va >= start && va < start + static_size) {
++                      if (can_addr) {
++                              *can_addr = (unsigned long) (va - start);
++                              *can_addr += (unsigned long)
++                                      per_cpu_ptr(base, get_boot_cpu_id());
++                      }
+                       return true;
+-        }
++              }
++      }
+ #endif
+       /* on UP, can't distinguish from other static vars, always false */
+       return false;
+ }
+ /**
++ * is_kernel_percpu_address - test whether address is from static percpu area
++ * @addr: address to test
++ *
++ * Test whether @addr belongs to in-kernel static percpu area.  Module
++ * static percpu areas are not considered.  For those, use
++ * is_module_percpu_address().
++ *
++ * RETURNS:
++ * %true if @addr is from in-kernel static percpu area, %false otherwise.
++ */
++bool is_kernel_percpu_address(unsigned long addr)
++{
++      return __is_kernel_percpu_address(addr, NULL);
++}
++
++/**
+  * per_cpu_ptr_to_phys - convert translated percpu address to physical address
+  * @addr: the address to be converted to physical address
+  *
 diff --git a/mm/slab.h b/mm/slab.h
-index 9653f2e2591a..b7371e026627 100644
+index ceb7d70cdb76..dfd281e43fbe 100644
 --- a/mm/slab.h
 +++ b/mm/slab.h
 @@ -426,7 +426,11 @@ static inline void slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags,
@@ -23853,10 +25571,10 @@ index 9653f2e2591a..b7371e026627 100644
  #ifdef CONFIG_SLAB
        struct list_head slabs_partial; /* partial list first, better asm code */
 diff --git a/mm/slub.c b/mm/slub.c
-index 9adae58462f8..4b386747f050 100644
+index edc79ca3c6d5..67eb368b9314 100644
 --- a/mm/slub.c
 +++ b/mm/slub.c
-@@ -1145,7 +1145,7 @@ static noinline int free_debug_processing(
+@@ -1144,7 +1144,7 @@ static noinline int free_debug_processing(
        unsigned long uninitialized_var(flags);
        int ret = 0;
  
@@ -23865,7 +25583,7 @@ index 9adae58462f8..4b386747f050 100644
        slab_lock(page);
  
        if (s->flags & SLAB_CONSISTENCY_CHECKS) {
-@@ -1180,7 +1180,7 @@ static noinline int free_debug_processing(
+@@ -1179,7 +1179,7 @@ static noinline int free_debug_processing(
                         bulk_cnt, cnt);
  
        slab_unlock(page);
@@ -23874,7 +25592,7 @@ index 9adae58462f8..4b386747f050 100644
        if (!ret)
                slab_fix(s, "Object at 0x%p not freed", object);
        return ret;
-@@ -1308,6 +1308,12 @@ static inline void dec_slabs_node(struct kmem_cache *s, int node,
+@@ -1307,6 +1307,12 @@ static inline void dec_slabs_node(struct kmem_cache *s, int node,
  
  #endif /* CONFIG_SLUB_DEBUG */
  
@@ -23887,7 +25605,7 @@ index 9adae58462f8..4b386747f050 100644
  /*
   * Hooks for other subsystems that check memory allocations. In a typical
   * production configuration these hooks all should produce no code at all.
-@@ -1527,10 +1533,17 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
+@@ -1530,10 +1536,17 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
        void *start, *p;
        int idx, order;
        bool shuffle;
@@ -23905,7 +25623,7 @@ index 9adae58462f8..4b386747f050 100644
                local_irq_enable();
  
        flags |= s->allocflags;
-@@ -1605,7 +1618,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
+@@ -1608,7 +1621,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
        page->frozen = 1;
  
  out:
@@ -23914,7 +25632,7 @@ index 9adae58462f8..4b386747f050 100644
                local_irq_disable();
        if (!page)
                return NULL;
-@@ -1664,6 +1677,16 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
+@@ -1667,6 +1680,16 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
        __free_pages(page, order);
  }
  
@@ -23931,7 +25649,7 @@ index 9adae58462f8..4b386747f050 100644
  #define need_reserve_slab_rcu                                         \
        (sizeof(((struct page *)NULL)->lru) < sizeof(struct rcu_head))
  
-@@ -1695,6 +1718,12 @@ static void free_slab(struct kmem_cache *s, struct page *page)
+@@ -1698,6 +1721,12 @@ static void free_slab(struct kmem_cache *s, struct page *page)
                }
  
                call_rcu(head, rcu_free_slab);
@@ -23944,7 +25662,7 @@ index 9adae58462f8..4b386747f050 100644
        } else
                __free_slab(s, page);
  }
-@@ -1802,7 +1831,7 @@ static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n,
+@@ -1805,7 +1834,7 @@ static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n,
        if (!n || !n->nr_partial)
                return NULL;
  
@@ -23953,7 +25671,7 @@ index 9adae58462f8..4b386747f050 100644
        list_for_each_entry_safe(page, page2, &n->partial, lru) {
                void *t;
  
-@@ -1827,7 +1856,7 @@ static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n,
+@@ -1830,7 +1859,7 @@ static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n,
                        break;
  
        }
@@ -23962,7 +25680,7 @@ index 9adae58462f8..4b386747f050 100644
        return object;
  }
  
-@@ -2073,7 +2102,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
+@@ -2076,7 +2105,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
                         * that acquire_slab() will see a slab page that
                         * is frozen
                         */
@@ -23971,7 +25689,7 @@ index 9adae58462f8..4b386747f050 100644
                }
        } else {
                m = M_FULL;
-@@ -2084,7 +2113,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
+@@ -2087,7 +2116,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
                         * slabs from diagnostic functions will not see
                         * any frozen slabs.
                         */
@@ -23980,7 +25698,7 @@ index 9adae58462f8..4b386747f050 100644
                }
        }
  
-@@ -2119,7 +2148,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
+@@ -2122,7 +2151,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
                goto redo;
  
        if (lock)
@@ -23989,7 +25707,7 @@ index 9adae58462f8..4b386747f050 100644
  
        if (m == M_FREE) {
                stat(s, DEACTIVATE_EMPTY);
-@@ -2151,10 +2180,10 @@ static void unfreeze_partials(struct kmem_cache *s,
+@@ -2154,10 +2183,10 @@ static void unfreeze_partials(struct kmem_cache *s,
                n2 = get_node(s, page_to_nid(page));
                if (n != n2) {
                        if (n)
@@ -24002,7 +25720,7 @@ index 9adae58462f8..4b386747f050 100644
                }
  
                do {
-@@ -2183,7 +2212,7 @@ static void unfreeze_partials(struct kmem_cache *s,
+@@ -2186,7 +2215,7 @@ static void unfreeze_partials(struct kmem_cache *s,
        }
  
        if (n)
@@ -24011,7 +25729,7 @@ index 9adae58462f8..4b386747f050 100644
  
        while (discard_page) {
                page = discard_page;
-@@ -2222,14 +2251,21 @@ static void put_cpu_partial(struct kmem_cache *s, struct page *page, int drain)
+@@ -2225,14 +2254,21 @@ static void put_cpu_partial(struct kmem_cache *s, struct page *page, int drain)
                        pobjects = oldpage->pobjects;
                        pages = oldpage->pages;
                        if (drain && pobjects > s->cpu_partial) {
@@ -24033,7 +25751,7 @@ index 9adae58462f8..4b386747f050 100644
                                oldpage = NULL;
                                pobjects = 0;
                                pages = 0;
-@@ -2301,7 +2337,22 @@ static bool has_cpu_slab(int cpu, void *info)
+@@ -2304,7 +2340,22 @@ static bool has_cpu_slab(int cpu, void *info)
  
  static void flush_all(struct kmem_cache *s)
  {
@@ -24056,7 +25774,7 @@ index 9adae58462f8..4b386747f050 100644
  }
  
  /*
-@@ -2337,10 +2388,10 @@ static unsigned long count_partial(struct kmem_cache_node *n,
+@@ -2359,10 +2410,10 @@ static unsigned long count_partial(struct kmem_cache_node *n,
        unsigned long x = 0;
        struct page *page;
  
@@ -24069,7 +25787,7 @@ index 9adae58462f8..4b386747f050 100644
        return x;
  }
  #endif /* CONFIG_SLUB_DEBUG || CONFIG_SYSFS */
-@@ -2478,8 +2529,10 @@ static inline void *get_freelist(struct kmem_cache *s, struct page *page)
+@@ -2500,8 +2551,10 @@ static inline void *get_freelist(struct kmem_cache *s, struct page *page)
   * already disabled (which is the case for bulk allocation).
   */
  static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
@@ -24081,7 +25799,7 @@ index 9adae58462f8..4b386747f050 100644
        void *freelist;
        struct page *page;
  
-@@ -2539,6 +2592,13 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
+@@ -2561,6 +2614,13 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
        VM_BUG_ON(!c->page->frozen);
        c->freelist = get_freepointer(s, freelist);
        c->tid = next_tid(c->tid);
@@ -24095,7 +25813,7 @@ index 9adae58462f8..4b386747f050 100644
        return freelist;
  
  new_slab:
-@@ -2570,7 +2630,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
+@@ -2592,7 +2652,7 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
        deactivate_slab(s, page, get_freepointer(s, freelist));
        c->page = NULL;
        c->freelist = NULL;
@@ -24104,7 +25822,7 @@ index 9adae58462f8..4b386747f050 100644
  }
  
  /*
-@@ -2582,6 +2642,7 @@ static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
+@@ -2604,6 +2664,7 @@ static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
  {
        void *p;
        unsigned long flags;
@@ -24112,7 +25830,7 @@ index 9adae58462f8..4b386747f050 100644
  
        local_irq_save(flags);
  #ifdef CONFIG_PREEMPT
-@@ -2593,8 +2654,9 @@ static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
+@@ -2615,8 +2676,9 @@ static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
        c = this_cpu_ptr(s->cpu_slab);
  #endif
  
@@ -24123,7 +25841,7 @@ index 9adae58462f8..4b386747f050 100644
        return p;
  }
  
-@@ -2780,7 +2842,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
+@@ -2802,7 +2864,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
  
        do {
                if (unlikely(n)) {
@@ -24132,7 +25850,7 @@ index 9adae58462f8..4b386747f050 100644
                        n = NULL;
                }
                prior = page->freelist;
-@@ -2812,7 +2874,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
+@@ -2834,7 +2896,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
                                 * Otherwise the list_lock will synchronize with
                                 * other processors updating the list of slabs.
                                 */
@@ -24141,7 +25859,7 @@ index 9adae58462f8..4b386747f050 100644
  
                        }
                }
-@@ -2854,7 +2916,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
+@@ -2876,7 +2938,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
                add_partial(n, page, DEACTIVATE_TO_TAIL);
                stat(s, FREE_ADD_PARTIAL);
        }
@@ -24150,7 +25868,7 @@ index 9adae58462f8..4b386747f050 100644
        return;
  
  slab_empty:
-@@ -2869,7 +2931,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
+@@ -2891,7 +2953,7 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
                remove_full(s, n, page);
        }
  
@@ -24159,7 +25877,7 @@ index 9adae58462f8..4b386747f050 100644
        stat(s, FREE_SLAB);
        discard_slab(s, page);
  }
-@@ -3074,6 +3136,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
+@@ -3096,6 +3158,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
                          void **p)
  {
        struct kmem_cache_cpu *c;
@@ -24167,7 +25885,7 @@ index 9adae58462f8..4b386747f050 100644
        int i;
  
        /* memcg and kmem_cache debug support */
-@@ -3097,7 +3160,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
+@@ -3119,7 +3182,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
                         * of re-populating per CPU c->freelist
                         */
                        p[i] = ___slab_alloc(s, flags, NUMA_NO_NODE,
@@ -24176,7 +25894,7 @@ index 9adae58462f8..4b386747f050 100644
                        if (unlikely(!p[i]))
                                goto error;
  
-@@ -3109,6 +3172,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
+@@ -3131,6 +3194,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
        }
        c->tid = next_tid(c->tid);
        local_irq_enable();
@@ -24184,7 +25902,7 @@ index 9adae58462f8..4b386747f050 100644
  
        /* Clear memory outside IRQ disabled fastpath loop */
        if (unlikely(flags & __GFP_ZERO)) {
-@@ -3256,7 +3320,7 @@ static void
+@@ -3278,7 +3342,7 @@ static void
  init_kmem_cache_node(struct kmem_cache_node *n)
  {
        n->nr_partial = 0;
@@ -24193,7 +25911,7 @@ index 9adae58462f8..4b386747f050 100644
        INIT_LIST_HEAD(&n->partial);
  #ifdef CONFIG_SLUB_DEBUG
        atomic_long_set(&n->nr_slabs, 0);
-@@ -3600,6 +3664,10 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
+@@ -3622,6 +3686,10 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
                                                        const char *text)
  {
  #ifdef CONFIG_SLUB_DEBUG
@@ -24204,7 +25922,7 @@ index 9adae58462f8..4b386747f050 100644
        void *addr = page_address(page);
        void *p;
        unsigned long *map = kzalloc(BITS_TO_LONGS(page->objects) *
-@@ -3620,6 +3688,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
+@@ -3642,6 +3710,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
        slab_unlock(page);
        kfree(map);
  #endif
@@ -24212,7 +25930,7 @@ index 9adae58462f8..4b386747f050 100644
  }
  
  /*
-@@ -3633,7 +3702,7 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
+@@ -3655,7 +3724,7 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
        struct page *page, *h;
  
        BUG_ON(irqs_disabled());
@@ -24221,7 +25939,7 @@ index 9adae58462f8..4b386747f050 100644
        list_for_each_entry_safe(page, h, &n->partial, lru) {
                if (!page->inuse) {
                        remove_partial(n, page);
-@@ -3643,7 +3712,7 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
+@@ -3665,7 +3734,7 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
                        "Objects remaining in %s on __kmem_cache_shutdown()");
                }
        }
@@ -24230,7 +25948,7 @@ index 9adae58462f8..4b386747f050 100644
  
        list_for_each_entry_safe(page, h, &discard, lru)
                discard_slab(s, page);
-@@ -3901,7 +3970,7 @@ int __kmem_cache_shrink(struct kmem_cache *s, bool deactivate)
+@@ -3908,7 +3977,7 @@ int __kmem_cache_shrink(struct kmem_cache *s)
                for (i = 0; i < SHRINK_PROMOTE_MAX; i++)
                        INIT_LIST_HEAD(promote + i);
  
@@ -24239,7 +25957,7 @@ index 9adae58462f8..4b386747f050 100644
  
                /*
                 * Build lists of slabs to discard or promote.
-@@ -3932,7 +4001,7 @@ int __kmem_cache_shrink(struct kmem_cache *s, bool deactivate)
+@@ -3939,7 +4008,7 @@ int __kmem_cache_shrink(struct kmem_cache *s)
                for (i = SHRINK_PROMOTE_MAX - 1; i >= 0; i--)
                        list_splice(promote + i, &n->partial);
  
@@ -24248,7 +25966,7 @@ index 9adae58462f8..4b386747f050 100644
  
                /* Release empty slabs */
                list_for_each_entry_safe(page, t, &discard, lru)
-@@ -4108,6 +4177,12 @@ void __init kmem_cache_init(void)
+@@ -4115,6 +4184,12 @@ void __init kmem_cache_init(void)
  {
        static __initdata struct kmem_cache boot_kmem_cache,
                boot_kmem_cache_node;
@@ -24261,7 +25979,7 @@ index 9adae58462f8..4b386747f050 100644
  
        if (debug_guardpage_minorder())
                slub_max_order = 0;
-@@ -4354,7 +4429,7 @@ static int validate_slab_node(struct kmem_cache *s,
+@@ -4323,7 +4398,7 @@ static int validate_slab_node(struct kmem_cache *s,
        struct page *page;
        unsigned long flags;
  
@@ -24270,7 +25988,7 @@ index 9adae58462f8..4b386747f050 100644
  
        list_for_each_entry(page, &n->partial, lru) {
                validate_slab_slab(s, page, map);
-@@ -4376,7 +4451,7 @@ static int validate_slab_node(struct kmem_cache *s,
+@@ -4345,7 +4420,7 @@ static int validate_slab_node(struct kmem_cache *s,
                       s->name, count, atomic_long_read(&n->nr_slabs));
  
  out:
@@ -24279,7 +25997,7 @@ index 9adae58462f8..4b386747f050 100644
        return count;
  }
  
-@@ -4564,12 +4639,12 @@ static int list_locations(struct kmem_cache *s, char *buf,
+@@ -4533,12 +4608,12 @@ static int list_locations(struct kmem_cache *s, char *buf,
                if (!atomic_long_read(&n->nr_slabs))
                        continue;
  
@@ -24295,7 +26013,7 @@ index 9adae58462f8..4b386747f050 100644
  
        for (i = 0; i < t.count; i++) {
 diff --git a/mm/swap.c b/mm/swap.c
-index 75c63bb2a1da..93fe549eb11e 100644
+index 4dcf852e1e6d..69c3a5b24060 100644
 --- a/mm/swap.c
 +++ b/mm/swap.c
 @@ -32,6 +32,7 @@
@@ -24500,7 +26218,7 @@ index 75c63bb2a1da..93fe549eb11e 100644
        put_online_cpus();
        mutex_unlock(&lock);
 diff --git a/mm/truncate.c b/mm/truncate.c
-index a01cce450a26..4bda37604f99 100644
+index 9c809e7d73c3..b7681e888ba0 100644
 --- a/mm/truncate.c
 +++ b/mm/truncate.c
 @@ -62,9 +62,12 @@ static void clear_exceptional_entry(struct address_space *mapping,
@@ -24519,10 +26237,10 @@ index a01cce450a26..4bda37604f99 100644
  unlock:
        spin_unlock_irq(&mapping->tree_lock);
 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
-index 91f44e78c516..06ec393bb97d 100644
+index 195de42bea1f..b46cb686fde7 100644
 --- a/mm/vmalloc.c
 +++ b/mm/vmalloc.c
-@@ -845,7 +845,7 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask)
+@@ -855,7 +855,7 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask)
        struct vmap_block *vb;
        struct vmap_area *va;
        unsigned long vb_idx;
@@ -24531,7 +26249,7 @@ index 91f44e78c516..06ec393bb97d 100644
        void *vaddr;
  
        node = numa_node_id();
-@@ -888,11 +888,12 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask)
+@@ -898,11 +898,12 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask)
        BUG_ON(err);
        radix_tree_preload_end();
  
@@ -24546,7 +26264,7 @@ index 91f44e78c516..06ec393bb97d 100644
  
        return vaddr;
  }
-@@ -961,6 +962,7 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
+@@ -971,6 +972,7 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
        struct vmap_block *vb;
        void *vaddr = NULL;
        unsigned int order;
@@ -24554,7 +26272,7 @@ index 91f44e78c516..06ec393bb97d 100644
  
        BUG_ON(offset_in_page(size));
        BUG_ON(size > PAGE_SIZE*VMAP_MAX_ALLOC);
-@@ -975,7 +977,8 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
+@@ -985,7 +987,8 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
        order = get_order(size);
  
        rcu_read_lock();
@@ -24564,7 +26282,7 @@ index 91f44e78c516..06ec393bb97d 100644
        list_for_each_entry_rcu(vb, &vbq->free, free_list) {
                unsigned long pages_off;
  
-@@ -998,7 +1001,7 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
+@@ -1008,7 +1011,7 @@ static void *vb_alloc(unsigned long size, gfp_t gfp_mask)
                break;
        }
  
@@ -24574,7 +26292,7 @@ index 91f44e78c516..06ec393bb97d 100644
  
        /* Allocate new block if nothing was found */
 diff --git a/mm/vmstat.c b/mm/vmstat.c
-index 89cec42d19ff..fb73631fb90b 100644
+index 604f26a4f696..312006d2db50 100644
 --- a/mm/vmstat.c
 +++ b/mm/vmstat.c
 @@ -245,6 +245,7 @@ void __mod_zone_page_state(struct zone *zone, enum zone_stat_item item,
@@ -24674,7 +26392,7 @@ index 89cec42d19ff..fb73631fb90b 100644
  
  void __dec_zone_page_state(struct page *page, enum zone_stat_item item)
 diff --git a/mm/workingset.c b/mm/workingset.c
-index 617475f529f4..48674bf36fb1 100644
+index 4c4f05655e6e..b97b1e87b54c 100644
 --- a/mm/workingset.c
 +++ b/mm/workingset.c
 @@ -334,7 +334,8 @@ void workingset_activation(struct page *page)
@@ -24698,7 +26416,7 @@ index 617475f529f4..48674bf36fb1 100644
 +      shadow_nodes = list_lru_shrink_count(&__workingset_shadow_nodes, sc);
 +      local_unlock_irq(workingset_shadow_lock);
  
-       if (memcg_kmem_enabled()) {
+       if (sc->memcg) {
                pages = mem_cgroup_node_nr_lru_pages(sc->memcg, sc->nid,
 @@ -438,9 +439,9 @@ static enum lru_status shadow_lru_isolate(struct list_head *item,
        spin_unlock(&mapping->tree_lock);
@@ -24730,8 +26448,8 @@ index 617475f529f4..48674bf36fb1 100644
        pr_info("workingset: timestamp_bits=%d max_order=%d bucket_order=%u\n",
               timestamp_bits, max_order, bucket_order);
  
--      ret = list_lru_init_key(&workingset_shadow_nodes, &shadow_nodes_key);
-+      ret = list_lru_init_key(&__workingset_shadow_nodes, &shadow_nodes_key);
+-      ret = __list_lru_init(&workingset_shadow_nodes, true, &shadow_nodes_key);
++      ret = __list_lru_init(&__workingset_shadow_nodes, true, &shadow_nodes_key);
        if (ret)
                goto err;
        ret = register_shrinker(&workingset_shadow_shrinker);
@@ -24745,7 +26463,7 @@ index 617475f529f4..48674bf36fb1 100644
        return ret;
  }
 diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
-index b0bc023d25c5..5af6426fbcbe 100644
+index 1689bb58e0d1..e52a8cb6aa5a 100644
 --- a/mm/zsmalloc.c
 +++ b/mm/zsmalloc.c
 @@ -53,6 +53,7 @@
@@ -24925,8 +26643,55 @@ index b0bc023d25c5..5af6426fbcbe 100644
  
        migrate_read_unlock(zspage);
        unpin_tag(handle);
+diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
+index c88a6007e643..5de85b55a821 100644
+--- a/net/bluetooth/hci_sock.c
++++ b/net/bluetooth/hci_sock.c
+@@ -251,15 +251,13 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
+ }
+ /* Send frame to sockets with specific channel */
+-void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
+-                       int flag, struct sock *skip_sk)
++static void __hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
++                                int flag, struct sock *skip_sk)
+ {
+       struct sock *sk;
+       BT_DBG("channel %u len %d", channel, skb->len);
+-      read_lock(&hci_sk_list.lock);
+-
+       sk_for_each(sk, &hci_sk_list.head) {
+               struct sk_buff *nskb;
+@@ -285,6 +283,13 @@ void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
+                       kfree_skb(nskb);
+       }
++}
++
++void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
++                       int flag, struct sock *skip_sk)
++{
++      read_lock(&hci_sk_list.lock);
++      __hci_send_to_channel(channel, skb, flag, skip_sk);
+       read_unlock(&hci_sk_list.lock);
+ }
+@@ -388,8 +393,8 @@ void hci_send_monitor_ctrl_event(struct hci_dev *hdev, u16 event,
+               hdr->index = index;
+               hdr->len = cpu_to_le16(skb->len - HCI_MON_HDR_SIZE);
+-              hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
+-                                  HCI_SOCK_TRUSTED, NULL);
++              __hci_send_to_channel(HCI_CHANNEL_MONITOR, skb,
++                                    HCI_SOCK_TRUSTED, NULL);
+               kfree_skb(skb);
+       }
 diff --git a/net/core/dev.c b/net/core/dev.c
-index ea6312057a71..d114a4692cde 100644
+index c37891828e4e..3235360cd9a4 100644
 --- a/net/core/dev.c
 +++ b/net/core/dev.c
 @@ -190,6 +190,7 @@ static unsigned int napi_gen_id = NR_CPUS;
@@ -25029,7 +26794,7 @@ index ea6312057a71..d114a4692cde 100644
  }
  
  /**
-@@ -2268,6 +2274,7 @@ static void __netif_reschedule(struct Qdisc *q)
+@@ -2286,6 +2292,7 @@ static void __netif_reschedule(struct Qdisc *q)
        sd->output_queue_tailp = &q->next_sched;
        raise_softirq_irqoff(NET_TX_SOFTIRQ);
        local_irq_restore(flags);
@@ -25037,7 +26802,7 @@ index ea6312057a71..d114a4692cde 100644
  }
  
  void __netif_schedule(struct Qdisc *q)
-@@ -2349,6 +2356,7 @@ void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason)
+@@ -2370,6 +2377,7 @@ void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason)
        __this_cpu_write(softnet_data.completion_queue, skb);
        raise_softirq_irqoff(NET_TX_SOFTIRQ);
        local_irq_restore(flags);
@@ -25045,7 +26810,7 @@ index ea6312057a71..d114a4692cde 100644
  }
  EXPORT_SYMBOL(__dev_kfree_skb_irq);
  
-@@ -3082,7 +3090,11 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
+@@ -3111,7 +3119,11 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
         * This permits qdisc->running owner to get the lock more
         * often and dequeue packets faster.
         */
@@ -25057,7 +26822,7 @@ index ea6312057a71..d114a4692cde 100644
        if (unlikely(contended))
                spin_lock(&q->busylock);
  
-@@ -3145,8 +3157,10 @@ static void skb_update_prio(struct sk_buff *skb)
+@@ -3174,8 +3186,10 @@ static void skb_update_prio(struct sk_buff *skb)
  #define skb_update_prio(skb)
  #endif
  
@@ -25068,7 +26833,7 @@ index ea6312057a71..d114a4692cde 100644
  
  /**
   *    dev_loopback_xmit - loop back @skb
-@@ -3390,8 +3404,7 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)
+@@ -3409,8 +3423,7 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)
                int cpu = smp_processor_id(); /* ok because BHs are off */
  
                if (txq->xmit_lock_owner != cpu) {
@@ -25078,7 +26843,7 @@ index ea6312057a71..d114a4692cde 100644
                                goto recursion_alert;
  
                        skb = validate_xmit_skb(skb, dev);
-@@ -3401,9 +3414,9 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)
+@@ -3420,9 +3433,9 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)
                        HARD_TX_LOCK(dev, txq, cpu);
  
                        if (!netif_xmit_stopped(txq)) {
@@ -25090,7 +26855,7 @@ index ea6312057a71..d114a4692cde 100644
                                if (dev_xmit_complete(rc)) {
                                        HARD_TX_UNLOCK(dev, txq);
                                        goto out;
-@@ -3777,6 +3790,7 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,
+@@ -3796,6 +3809,7 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,
        rps_unlock(sd);
  
        local_irq_restore(flags);
@@ -25098,7 +26863,7 @@ index ea6312057a71..d114a4692cde 100644
  
        atomic_long_inc(&skb->dev->rx_dropped);
        kfree_skb(skb);
-@@ -3795,7 +3809,7 @@ static int netif_rx_internal(struct sk_buff *skb)
+@@ -3814,7 +3828,7 @@ static int netif_rx_internal(struct sk_buff *skb)
                struct rps_dev_flow voidflow, *rflow = &voidflow;
                int cpu;
  
@@ -25107,7 +26872,7 @@ index ea6312057a71..d114a4692cde 100644
                rcu_read_lock();
  
                cpu = get_rps_cpu(skb->dev, skb, &rflow);
-@@ -3805,13 +3819,13 @@ static int netif_rx_internal(struct sk_buff *skb)
+@@ -3824,13 +3838,13 @@ static int netif_rx_internal(struct sk_buff *skb)
                ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail);
  
                rcu_read_unlock();
@@ -25124,7 +26889,7 @@ index ea6312057a71..d114a4692cde 100644
        }
        return ret;
  }
-@@ -3845,11 +3859,9 @@ int netif_rx_ni(struct sk_buff *skb)
+@@ -3864,11 +3878,9 @@ int netif_rx_ni(struct sk_buff *skb)
  
        trace_netif_rx_ni_entry(skb);
  
@@ -25138,31 +26903,32 @@ index ea6312057a71..d114a4692cde 100644
  
        return err;
  }
-@@ -4321,7 +4333,7 @@ static void flush_backlog(void *arg)
+@@ -4347,7 +4359,7 @@ static void flush_backlog(struct work_struct *work)
        skb_queue_walk_safe(&sd->input_pkt_queue, skb, tmp) {
-               if (skb->dev == dev) {
+               if (skb->dev->reg_state == NETREG_UNREGISTERING) {
                        __skb_unlink(skb, &sd->input_pkt_queue);
 -                      kfree_skb(skb);
 +                      __skb_queue_tail(&sd->tofree_queue, skb);
                        input_queue_head_incr(sd);
                }
        }
-@@ -4330,10 +4342,13 @@ static void flush_backlog(void *arg)
+@@ -4357,11 +4369,14 @@ static void flush_backlog(struct work_struct *work)
        skb_queue_walk_safe(&sd->process_queue, skb, tmp) {
-               if (skb->dev == dev) {
+               if (skb->dev->reg_state == NETREG_UNREGISTERING) {
                        __skb_unlink(skb, &sd->process_queue);
 -                      kfree_skb(skb);
 +                      __skb_queue_tail(&sd->tofree_queue, skb);
                        input_queue_head_incr(sd);
                }
        }
-+
 +      if (!skb_queue_empty(&sd->tofree_queue))
 +              raise_softirq_irqoff(NET_RX_SOFTIRQ);
+       local_bh_enable();
++
  }
  
- static int napi_gro_complete(struct sk_buff *skb)
-@@ -4795,6 +4810,7 @@ static void net_rps_action_and_irq_enable(struct softnet_data *sd)
+ static void flush_all_backlogs(void)
+@@ -4852,6 +4867,7 @@ static void net_rps_action_and_irq_enable(struct softnet_data *sd)
                sd->rps_ipi_list = NULL;
  
                local_irq_enable();
@@ -25170,7 +26936,7 @@ index ea6312057a71..d114a4692cde 100644
  
                /* Send pending IPI's to kick RPS processing on remote cpus. */
                while (remsd) {
-@@ -4808,6 +4824,7 @@ static void net_rps_action_and_irq_enable(struct softnet_data *sd)
+@@ -4865,6 +4881,7 @@ static void net_rps_action_and_irq_enable(struct softnet_data *sd)
        } else
  #endif
                local_irq_enable();
@@ -25178,7 +26944,28 @@ index ea6312057a71..d114a4692cde 100644
  }
  
  static bool sd_has_rps_ipi_waiting(struct softnet_data *sd)
-@@ -4889,6 +4906,7 @@ void __napi_schedule(struct napi_struct *n)
+@@ -4894,7 +4911,9 @@ static int process_backlog(struct napi_struct *napi, int quota)
+       while (again) {
+               struct sk_buff *skb;
++              local_irq_disable();
+               while ((skb = __skb_dequeue(&sd->process_queue))) {
++                      local_irq_enable();
+                       rcu_read_lock();
+                       __netif_receive_skb(skb);
+                       rcu_read_unlock();
+@@ -4902,9 +4921,9 @@ static int process_backlog(struct napi_struct *napi, int quota)
+                       if (++work >= quota)
+                               return work;
++                      local_irq_disable();
+               }
+-              local_irq_disable();
+               rps_lock(sd);
+               if (skb_queue_empty(&sd->input_pkt_queue)) {
+                       /*
+@@ -4942,9 +4961,11 @@ void __napi_schedule(struct napi_struct *n)
        local_irq_save(flags);
        ____napi_schedule(this_cpu_ptr(&softnet_data), n);
        local_irq_restore(flags);
@@ -25186,7 +26973,41 @@ index ea6312057a71..d114a4692cde 100644
  }
  EXPORT_SYMBOL(__napi_schedule);
  
-@@ -5229,7 +5247,7 @@ static void net_rx_action(struct softirq_action *h)
++#ifndef CONFIG_PREEMPT_RT_FULL
+ /**
+  * __napi_schedule_irqoff - schedule for receive
+  * @n: entry to schedule
+@@ -4956,6 +4977,7 @@ void __napi_schedule_irqoff(struct napi_struct *n)
+       ____napi_schedule(this_cpu_ptr(&softnet_data), n);
+ }
+ EXPORT_SYMBOL(__napi_schedule_irqoff);
++#endif
+ void __napi_complete(struct napi_struct *n)
+ {
+@@ -5245,13 +5267,21 @@ static __latent_entropy void net_rx_action(struct softirq_action *h)
+       struct softnet_data *sd = this_cpu_ptr(&softnet_data);
+       unsigned long time_limit = jiffies + 2;
+       int budget = netdev_budget;
++      struct sk_buff_head tofree_q;
++      struct sk_buff *skb;
+       LIST_HEAD(list);
+       LIST_HEAD(repoll);
++      __skb_queue_head_init(&tofree_q);
++
+       local_irq_disable();
++      skb_queue_splice_init(&sd->tofree_queue, &tofree_q);
+       list_splice_init(&sd->poll_list, &list);
+       local_irq_enable();
++      while ((skb = __skb_dequeue(&tofree_q)))
++              kfree_skb(skb);
++
+       for (;;) {
+               struct napi_struct *n;
+@@ -5282,7 +5312,7 @@ static __latent_entropy void net_rx_action(struct softirq_action *h)
        list_splice_tail(&repoll, &list);
        list_splice(&list, &sd->poll_list);
        if (!list_empty(&sd->poll_list))
@@ -25195,16 +27016,7 @@ index ea6312057a71..d114a4692cde 100644
  
        net_rps_action_and_irq_enable(sd);
  }
-@@ -7736,7 +7754,7 @@ EXPORT_SYMBOL(free_netdev);
- void synchronize_net(void)
- {
-       might_sleep();
--      if (rtnl_is_locked())
-+      if (rtnl_is_locked() && !IS_ENABLED(CONFIG_PREEMPT_RT_FULL))
-               synchronize_rcu_expedited();
-       else
-               synchronize_rcu();
-@@ -7977,16 +7995,20 @@ static int dev_cpu_callback(struct notifier_block *nfb,
+@@ -8044,16 +8074,20 @@ static int dev_cpu_callback(struct notifier_block *nfb,
  
        raise_softirq_irqoff(NET_TX_SOFTIRQ);
        local_irq_enable();
@@ -25226,9 +27038,9 @@ index ea6312057a71..d114a4692cde 100644
  
        return NOTIFY_OK;
  }
-@@ -8288,8 +8310,9 @@ static int __init net_dev_init(void)
-       for_each_possible_cpu(i) {
-               struct softnet_data *sd = &per_cpu(softnet_data, i);
+@@ -8358,8 +8392,9 @@ static int __init net_dev_init(void)
+               INIT_WORK(flush, flush_backlog);
  
 -              skb_queue_head_init(&sd->input_pkt_queue);
 -              skb_queue_head_init(&sd->process_queue);
@@ -25239,10 +27051,10 @@ index ea6312057a71..d114a4692cde 100644
                sd->output_queue_tailp = &sd->output_queue;
  #ifdef CONFIG_RPS
 diff --git a/net/core/filter.c b/net/core/filter.c
-index cb06aceb512a..3585a8982287 100644
+index 4eb4ce0aeef4..4f09d6a57217 100644
 --- a/net/core/filter.c
 +++ b/net/core/filter.c
-@@ -1592,7 +1592,7 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)
+@@ -1645,7 +1645,7 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)
  {
        int ret;
  
@@ -25251,7 +27063,7 @@ index cb06aceb512a..3585a8982287 100644
                net_crit_ratelimited("bpf: recursion limit reached on datapath, buggy bpf program?\n");
                kfree_skb(skb);
                return -ENETDOWN;
-@@ -1600,9 +1600,9 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)
+@@ -1653,9 +1653,9 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)
  
        skb->dev = dev;
  
@@ -25330,7 +27142,7 @@ index 508e051304fb..bc3b17b78c94 100644
                      struct gnet_stats_basic_cpu __percpu *cpu,
                      struct gnet_stats_basic_packed *b)
 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
-index 3864b4b68fa1..55c73ade9faa 100644
+index aec5605944d3..d4cb8bfdb83c 100644
 --- a/net/core/skbuff.c
 +++ b/net/core/skbuff.c
 @@ -64,6 +64,7 @@
@@ -25465,10 +27277,10 @@ index 3864b4b68fa1..55c73ade9faa 100644
  void __kfree_skb_defer(struct sk_buff *skb)
  {
 diff --git a/net/core/sock.c b/net/core/sock.c
-index fd7b41edf1ce..e425d259a9f0 100644
+index e3b60460dc9c..8d15848c3a22 100644
 --- a/net/core/sock.c
 +++ b/net/core/sock.c
-@@ -2508,12 +2508,11 @@ void lock_sock_nested(struct sock *sk, int subclass)
+@@ -2493,12 +2493,11 @@ void lock_sock_nested(struct sock *sk, int subclass)
        if (sk->sk_lock.owned)
                __lock_sock(sk);
        sk->sk_lock.owned = 1;
@@ -25483,7 +27295,7 @@ index fd7b41edf1ce..e425d259a9f0 100644
  EXPORT_SYMBOL(lock_sock_nested);
  
 diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
-index 38abe70e595f..443259a04862 100644
+index 48734ee6293f..330224ef4174 100644
 --- a/net/ipv4/icmp.c
 +++ b/net/ipv4/icmp.c
 @@ -69,6 +69,7 @@
@@ -25511,11 +27323,15 @@ index 38abe70e595f..443259a04862 100644
  static struct sock *icmp_sk(struct net *net)
  {
        return *this_cpu_ptr(net->ipv4.icmp_sk);
-@@ -215,12 +219,14 @@ static inline struct sock *icmp_xmit_lock(struct net *net)
+@@ -215,12 +219,18 @@ static inline struct sock *icmp_xmit_lock(struct net *net)
  
        local_bh_disable();
  
-+      local_lock(icmp_sk_lock);
++      if (!local_trylock(icmp_sk_lock)) {
++              local_bh_enable();
++              return NULL;
++      }
++
        sk = icmp_sk(net);
  
        if (unlikely(!spin_trylock(&sk->sk_lock.slock))) {
@@ -25526,7 +27342,7 @@ index 38abe70e595f..443259a04862 100644
                local_bh_enable();
                return NULL;
        }
-@@ -230,6 +236,7 @@ static inline struct sock *icmp_xmit_lock(struct net *net)
+@@ -230,6 +240,7 @@ static inline struct sock *icmp_xmit_lock(struct net *net)
  static inline void icmp_xmit_unlock(struct sock *sk)
  {
        spin_unlock_bh(&sk->sk_lock.slock);
@@ -25534,7 +27350,7 @@ index 38abe70e595f..443259a04862 100644
  }
  
  int sysctl_icmp_msgs_per_sec __read_mostly = 1000;
-@@ -358,6 +365,7 @@ static void icmp_push_reply(struct icmp_bxm *icmp_param,
+@@ -358,6 +369,7 @@ static void icmp_push_reply(struct icmp_bxm *icmp_param,
        struct sock *sk;
        struct sk_buff *skb;
  
@@ -25542,7 +27358,7 @@ index 38abe70e595f..443259a04862 100644
        sk = icmp_sk(dev_net((*rt)->dst.dev));
        if (ip_append_data(sk, fl4, icmp_glue_bits, icmp_param,
                           icmp_param->data_len+icmp_param->head_len,
-@@ -380,6 +388,7 @@ static void icmp_push_reply(struct icmp_bxm *icmp_param,
+@@ -380,6 +392,7 @@ static void icmp_push_reply(struct icmp_bxm *icmp_param,
                skb->ip_summed = CHECKSUM_NONE;
                ip_push_pending_frames(sk, fl4);
        }
@@ -25550,7 +27366,7 @@ index 38abe70e595f..443259a04862 100644
  }
  
  /*
-@@ -891,6 +900,30 @@ static bool icmp_redirect(struct sk_buff *skb)
+@@ -891,6 +904,30 @@ static bool icmp_redirect(struct sk_buff *skb)
  }
  
  /*
@@ -25581,7 +27397,7 @@ index 38abe70e595f..443259a04862 100644
   *    Handle ICMP_ECHO ("ping") requests.
   *
   *    RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
-@@ -917,6 +950,11 @@ static bool icmp_echo(struct sk_buff *skb)
+@@ -917,6 +954,11 @@ static bool icmp_echo(struct sk_buff *skb)
                icmp_param.data_len        = skb->len;
                icmp_param.head_len        = sizeof(struct icmphdr);
                icmp_reply(&icmp_param, skb);
@@ -25594,7 +27410,7 @@ index 38abe70e595f..443259a04862 100644
        /* should there be an ICMP stat for ignored echos? */
        return true;
 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
-index 1cb67de106fe..332a485323f0 100644
+index 566cfc50f7cf..4b8551d78a3b 100644
 --- a/net/ipv4/sysctl_net_ipv4.c
 +++ b/net/ipv4/sysctl_net_ipv4.c
 @@ -681,6 +681,13 @@ static struct ctl_table ipv4_net_table[] = {
@@ -25612,7 +27428,7 @@ index 1cb67de106fe..332a485323f0 100644
                .data           = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
                .maxlen         = sizeof(int),
 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
-index 7158d4f8dae4..0dc007fc6704 100644
+index d577ec07a0d8..3b7298459c87 100644
 --- a/net/ipv4/tcp_ipv4.c
 +++ b/net/ipv4/tcp_ipv4.c
 @@ -62,6 +62,7 @@
@@ -25623,7 +27439,7 @@ index 7158d4f8dae4..0dc007fc6704 100644
  
  #include <net/net_namespace.h>
  #include <net/icmp.h>
-@@ -565,6 +566,7 @@ void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb)
+@@ -568,6 +569,7 @@ void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb)
  }
  EXPORT_SYMBOL(tcp_v4_send_check);
  
@@ -25631,44 +27447,44 @@ index 7158d4f8dae4..0dc007fc6704 100644
  /*
   *    This routine will send an RST to the other tcp.
   *
-@@ -692,6 +694,8 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
+@@ -695,7 +697,9 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
                     offsetof(struct inet_timewait_sock, tw_bound_dev_if));
  
        arg.tos = ip_hdr(skb)->tos;
 +
-+      local_lock(tcp_sk_lock);
        local_bh_disable();
++      local_lock(tcp_sk_lock);
        ip_send_unicast_reply(*this_cpu_ptr(net->ipv4.tcp_sk),
                              skb, &TCP_SKB_CB(skb)->header.h4.opt,
-@@ -701,6 +705,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
+                             ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,
+@@ -703,6 +707,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
        __TCP_INC_STATS(net, TCP_MIB_OUTSEGS);
        __TCP_INC_STATS(net, TCP_MIB_OUTRSTS);
-       local_bh_enable();
 +      local_unlock(tcp_sk_lock);
+       local_bh_enable();
  
  #ifdef CONFIG_TCP_MD5SIG
- out:
-@@ -776,6 +781,7 @@ static void tcp_v4_send_ack(struct net *net,
-       if (oif)
+@@ -780,12 +785,14 @@ static void tcp_v4_send_ack(struct net *net,
                arg.bound_dev_if = oif;
        arg.tos = tos;
-+      local_lock(tcp_sk_lock);
        local_bh_disable();
++      local_lock(tcp_sk_lock);
        ip_send_unicast_reply(*this_cpu_ptr(net->ipv4.tcp_sk),
                              skb, &TCP_SKB_CB(skb)->header.h4.opt,
-@@ -784,6 +790,7 @@ static void tcp_v4_send_ack(struct net *net,
+                             ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,
+                             &arg, arg.iov[0].iov_len);
  
        __TCP_INC_STATS(net, TCP_MIB_OUTSEGS);
-       local_bh_enable();
 +      local_unlock(tcp_sk_lock);
+       local_bh_enable();
  }
  
- static void tcp_v4_timewait_ack(struct sock *sk, struct sk_buff *skb)
 diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
-index 9dce3b157908..525efa5309ac 100644
+index 439e597fd374..ca0daeaff370 100644
 --- a/net/mac80211/rx.c
 +++ b/net/mac80211/rx.c
-@@ -4064,7 +4064,7 @@ void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
+@@ -4229,7 +4229,7 @@ void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
        struct ieee80211_supported_band *sband;
        struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  
@@ -25678,14 +27494,15 @@ index 9dce3b157908..525efa5309ac 100644
        if (WARN_ON(status->band >= NUM_NL80211_BANDS))
                goto drop;
 diff --git a/net/netfilter/core.c b/net/netfilter/core.c
-index f39276d1c2d7..10880c89d62f 100644
+index 004af030ef1a..b64f751bda45 100644
 --- a/net/netfilter/core.c
 +++ b/net/netfilter/core.c
-@@ -22,11 +22,17 @@
+@@ -22,12 +22,18 @@
  #include <linux/proc_fs.h>
  #include <linux/mutex.h>
  #include <linux/slab.h>
 +#include <linux/locallock.h>
+ #include <linux/rcupdate.h>
  #include <net/net_namespace.h>
  #include <net/sock.h>
  
@@ -25700,7 +27517,7 @@ index f39276d1c2d7..10880c89d62f 100644
  
  const struct nf_afinfo __rcu *nf_afinfo[NFPROTO_NUMPROTO] __read_mostly;
 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
-index 33a4697d5539..475cb74bf825 100644
+index e7f6657269e0..f635b773d28f 100644
 --- a/net/packet/af_packet.c
 +++ b/net/packet/af_packet.c
 @@ -63,6 +63,7 @@
@@ -25711,7 +27528,7 @@ index 33a4697d5539..475cb74bf825 100644
  #include <linux/kmod.h>
  #include <linux/slab.h>
  #include <linux/vmalloc.h>
-@@ -695,7 +696,7 @@ static void prb_retire_rx_blk_timer_expired(unsigned long data)
+@@ -694,7 +695,7 @@ static void prb_retire_rx_blk_timer_expired(unsigned long data)
        if (BLOCK_NUM_PKTS(pbd)) {
                while (atomic_read(&pkc->blk_fill_in_prog)) {
                        /* Waiting for skb_copy_bits to finish... */
@@ -25720,7 +27537,7 @@ index 33a4697d5539..475cb74bf825 100644
                }
        }
  
-@@ -957,7 +958,7 @@ static void prb_retire_current_block(struct tpacket_kbdq_core *pkc,
+@@ -956,7 +957,7 @@ static void prb_retire_current_block(struct tpacket_kbdq_core *pkc,
                if (!(status & TP_STATUS_BLK_TMO)) {
                        while (atomic_read(&pkc->blk_fill_in_prog)) {
                                /* Waiting for skb_copy_bits to finish... */
@@ -25751,7 +27568,7 @@ index 977f69886c00..f3e7a36b0396 100644
  }
  
 diff --git a/net/rxrpc/security.c b/net/rxrpc/security.c
-index 814d285ff802..d4d088e9be85 100644
+index 7d921e56e715..13df56a738e5 100644
 --- a/net/rxrpc/security.c
 +++ b/net/rxrpc/security.c
 @@ -19,9 +19,6 @@
@@ -25765,10 +27582,10 @@ index 814d285ff802..d4d088e9be85 100644
        [RXRPC_SECURITY_NONE]   = &rxrpc_no_security,
  #ifdef CONFIG_RXKAD
 diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
-index 12ebde845523..99f3ce50c6c4 100644
+index ea13df1be067..76c20745b502 100644
 --- a/net/sched/sch_api.c
 +++ b/net/sched/sch_api.c
-@@ -975,7 +975,7 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
+@@ -980,7 +980,7 @@ static struct Qdisc *qdisc_create(struct net_device *dev,
                        rcu_assign_pointer(sch->stab, stab);
                }
                if (tca[TCA_RATE]) {
@@ -25778,11 +27595,11 @@ index 12ebde845523..99f3ce50c6c4 100644
                        err = -EOPNOTSUPP;
                        if (sch->flags & TCQ_F_MQROOT)
 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
-index 657c13362b19..cbab8d4d5864 100644
+index 9016c8baf2aa..d925f0e63679 100644
 --- a/net/sched/sch_generic.c
 +++ b/net/sched/sch_generic.c
-@@ -426,7 +426,11 @@ struct Qdisc noop_qdisc = {
-       .list           =       LIST_HEAD_INIT(noop_qdisc.list),
+@@ -425,7 +425,11 @@ struct Qdisc noop_qdisc = {
+       .ops            =       &noop_qdisc_ops,
        .q.lock         =       __SPIN_LOCK_UNLOCKED(noop_qdisc.q.lock),
        .dev_queue      =       &noop_netdev_queue,
 +#ifdef CONFIG_PREEMPT_RT_BASE
@@ -25793,7 +27610,7 @@ index 657c13362b19..cbab8d4d5864 100644
        .busylock       =       __SPIN_LOCK_UNLOCKED(noop_qdisc.busylock),
  };
  EXPORT_SYMBOL(noop_qdisc);
-@@ -620,9 +624,17 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
+@@ -624,9 +628,17 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
        lockdep_set_class(&sch->busylock,
                          dev->qdisc_tx_busylock ?: &qdisc_tx_busylock);
  
@@ -25811,7 +27628,7 @@ index 657c13362b19..cbab8d4d5864 100644
  
        sch->ops = ops;
        sch->enqueue = ops->enqueue;
-@@ -917,7 +929,7 @@ void dev_deactivate_many(struct list_head *head)
+@@ -926,7 +938,7 @@ void dev_deactivate_many(struct list_head *head)
        /* Wait for outstanding qdisc_run calls. */
        list_for_each_entry(dev, head, close_list)
                while (some_qdisc_is_busy(dev))
@@ -25821,7 +27638,7 @@ index 657c13362b19..cbab8d4d5864 100644
  
  void dev_deactivate(struct net_device *dev)
 diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
-index c3f652395a80..2dd84493528e 100644
+index 9c9db55a0c1e..e6583b018a72 100644
 --- a/net/sunrpc/svc_xprt.c
 +++ b/net/sunrpc/svc_xprt.c
 @@ -396,7 +396,7 @@ void svc_xprt_do_enqueue(struct svc_xprt *xprt)
@@ -25874,7 +27691,7 @@ index 6fdc97ef6023..523e0420d7f0 100755
  
  # Truncate to maximum length
 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
-index c61fd50f771f..1583de410f62 100644
+index 9d33c1e85c79..3d307bda86f9 100644
 --- a/sound/core/pcm_native.c
 +++ b/sound/core/pcm_native.c
 @@ -135,7 +135,7 @@ EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock);
This page took 0.882905 seconds and 4 git commands to generate.