]> git.pld-linux.org Git - packages/kernel.git/blobdiff - kernel-rt.patch
- 4.9.107
[packages/kernel.git] / kernel-rt.patch
index bef16fc037ff392933fe7cc88a4f4ae4babe5bda..840aada4c0627bd874bacf5be3004deb9a3b9db8 100644 (file)
@@ -214,6 +214,34 @@ index 000000000000..6f2aeabf7faa
 +is provided.
 +
 +These data are also reset when the wakeup histogram is reset.
+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 659bdd079277..099fc0f5155e 100644
 --- a/arch/Kconfig
@@ -350,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
@@ -371,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
@@ -391,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
@@ -402,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
@@ -955,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 0122ad1a6027..926b1be48043 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);
  
@@ -968,7 +996,7 @@ index 0122ad1a6027..926b1be48043 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)
  {
@@ -1155,7 +1183,7 @@ index c2366510187a..6b60f582b738 100644
        return pen_release != -1 ? -ENOSYS : 0;
  }
 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
-index 969ef880d234..1182fe883771 100644
+index cf57a7799a0f..78d1b49fbed5 100644
 --- a/arch/arm64/Kconfig
 +++ b/arch/arm64/Kconfig
 @@ -91,6 +91,7 @@ config ARM64
@@ -1166,7 +1194,7 @@ index 969ef880d234..1182fe883771 100644
        select HAVE_REGS_AND_STACK_ACCESS_API
        select HAVE_RCU_TABLE_FREE
        select HAVE_SYSCALL_TRACEPOINTS
-@@ -694,7 +695,7 @@ config XEN_DOM0
+@@ -704,7 +705,7 @@ config XEN_DOM0
  
  config XEN
        bool "Xen guest support on ARM64"
@@ -1215,7 +1243,7 @@ index e9ea5a6bd449..6c500ad63c6a 100644
  #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 4a2f0f0fef32..6bf2bc17c400 100644
+index c58ddf8c4062..a8f2f7c1fe12 100644
 --- a/arch/arm64/kernel/asm-offsets.c
 +++ b/arch/arm64/kernel/asm-offsets.c
 @@ -38,6 +38,7 @@ int main(void)
@@ -1227,10 +1255,10 @@ index 4a2f0f0fef32..6bf2bc17c400 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 79b0fe24d5b7..f3c959ade308 100644
+index b4c7db434654..433d846f4f51 100644
 --- a/arch/arm64/kernel/entry.S
 +++ b/arch/arm64/kernel/entry.S
-@@ -428,11 +428,16 @@ ENDPROC(el1_sync)
+@@ -430,11 +430,16 @@ el1_irq:
  
  #ifdef CONFIG_PREEMPT
        ldr     w24, [tsk, #TI_PREEMPT]         // get preempt count
@@ -1250,7 +1278,7 @@ index 79b0fe24d5b7..f3c959ade308 100644
  #endif
  #ifdef CONFIG_TRACE_IRQFLAGS
        bl      trace_hardirqs_on
-@@ -446,6 +451,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?
@@ -1272,10 +1300,10 @@ index 404dd67080b9..639dc6d12e72 100644
                } else {
                        local_irq_enable();
 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
-index b3c5bde43d34..8122bf058de0 100644
+index 5e844f68e847..dc613cc10f54 100644
 --- a/arch/mips/Kconfig
 +++ b/arch/mips/Kconfig
-@@ -2514,7 +2514,7 @@ config MIPS_ASID_BITS_VARIABLE
+@@ -2516,7 +2516,7 @@ config MIPS_ASID_BITS_VARIABLE
  #
  config HIGHMEM
        bool "High Memory Support"
@@ -1285,7 +1313,7 @@ index b3c5bde43d34..8122bf058de0 100644
  config CPU_SUPPORTS_HIGHMEM
        bool
 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
-index 65fba4c34cd7..4b5ba68910e0 100644
+index 6eda5abbd719..601e27701a4a 100644
 --- a/arch/powerpc/Kconfig
 +++ b/arch/powerpc/Kconfig
 @@ -52,10 +52,11 @@ config LOCKDEP_SUPPORT
@@ -1384,7 +1412,7 @@ diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
 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
@@ -1399,7 +1427,7 @@ index 3841d749a430..6dbaeff192b9 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
@@ -1414,7 +1442,7 @@ index 3841d749a430..6dbaeff192b9 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 */
@@ -1423,7 +1451,7 @@ index 3841d749a430..6dbaeff192b9 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)
@@ -1433,7 +1461,7 @@ index 3841d749a430..6dbaeff192b9 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 6432d4bf08c8..5509a26f1070 100644
+index caa659671599..891080c4a41e 100644
 --- a/arch/powerpc/kernel/entry_64.S
 +++ b/arch/powerpc/kernel/entry_64.S
 @@ -656,7 +656,7 @@ _GLOBAL(ret_from_except_lite)
@@ -1445,29 +1473,27 @@ index 6432d4bf08c8..5509a26f1070 100644
        beq     2f
        bl      restore_interrupts
        SCHEDULE_USER
-@@ -718,10 +718,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
-@@ -738,7 +746,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)
@@ -1477,10 +1503,10 @@ index 6432d4bf08c8..5509a26f1070 100644
  
        /*
 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
-index 3c05c311e35e..f83f6ac1274d 100644
+index 028a22bfa90c..a75e2dd3e71f 100644
 --- a/arch/powerpc/kernel/irq.c
 +++ b/arch/powerpc/kernel/irq.c
-@@ -638,6 +638,7 @@ void irq_ctx_init(void)
+@@ -651,6 +651,7 @@ void irq_ctx_init(void)
        }
  }
  
@@ -1488,7 +1514,7 @@ index 3c05c311e35e..f83f6ac1274d 100644
  void do_softirq_own_stack(void)
  {
        struct thread_info *curtp, *irqtp;
-@@ -655,6 +656,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);
  }
@@ -1517,7 +1543,7 @@ index 030d72df5dd5..b471a709e100 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 4f178671f230..39e7d84a3492 100644
+index 4cefe6888b18..cb2ee4be999a 100644
 --- a/arch/powerpc/kernel/misc_64.S
 +++ b/arch/powerpc/kernel/misc_64.S
 @@ -31,6 +31,7 @@
@@ -1582,7 +1608,7 @@ index 6c0378c0b8b5..abd58b4dff97 100644
  static inline void handle_one_irq(unsigned int irq)
  {
 diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
-index 165ecdd24d22..b68a464a22be 100644
+index 8b4152f3a764..c5cca159692a 100644
 --- a/arch/sparc/Kconfig
 +++ b/arch/sparc/Kconfig
 @@ -194,12 +194,10 @@ config NR_CPUS
@@ -1601,7 +1627,7 @@ index 165ecdd24d22..b68a464a22be 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)
@@ -1621,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 bada636d1065..f8a995c90c01 100644
+index b9c546a305a4..e96c2975af4f 100644
 --- a/arch/x86/Kconfig
 +++ b/arch/x86/Kconfig
 @@ -17,6 +17,7 @@ config X86_64
@@ -2014,10 +2040,10 @@ index edba8606b99a..4a3389535fc6 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 ef766a358b37..28401f826ab1 100644
+index e7b0e7ff4c58..65916d49dbc9 100644
 --- a/arch/x86/entry/entry_64.S
 +++ b/arch/x86/entry/entry_64.S
-@@ -546,7 +546,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)
@@ -2041,7 +2067,7 @@ index ef766a358b37..28401f826ab1 100644
        call    preempt_schedule_irq
        jmp     0b
  1:
-@@ -894,6 +910,7 @@ EXPORT_SYMBOL(native_load_gs_index)
+@@ -894,6 +910,7 @@ bad_gs:
        jmp     2b
        .previous
  
@@ -2255,7 +2281,7 @@ index 57ab86d94d64..35d25e27180f 100644
  }
  
 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
-index 931ced8ca345..167975ac8af7 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;
@@ -2269,7 +2295,7 @@ index 931ced8ca345..167975ac8af7 100644
  /* --------------------------------------------------------------------------
                                Boot-time Configuration
 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
-index d1e25564b3c1..67e585fa801f 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)
@@ -2301,7 +2327,7 @@ index c62e015b126c..0cc71257fca6 100644
 +      DEFINE(_PREEMPT_ENABLED, PREEMPT_ENABLED);
  }
 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
-index a7fdf453d895..e3a0e969a66e 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 @@
@@ -2313,7 +2339,7 @@ index a7fdf453d895..e3a0e969a66e 100644
  #include <linux/jump_label.h>
  
  #include <asm/processor.h>
-@@ -1317,7 +1319,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 */
@@ -2322,7 +2348,7 @@ index a7fdf453d895..e3a0e969a66e 100644
  
  static unsigned long mce_adjust_timer_default(unsigned long interval)
  {
-@@ -1326,32 +1328,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;
  
@@ -2361,7 +2387,7 @@ index a7fdf453d895..e3a0e969a66e 100644
        iv = __this_cpu_read(mce_next_interval);
  
        if (mce_available(this_cpu_ptr(&cpu_info))) {
-@@ -1374,7 +1362,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);
@@ -2370,7 +2396,7 @@ index a7fdf453d895..e3a0e969a66e 100644
  }
  
  /*
-@@ -1382,7 +1370,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)
  {
@@ -2379,7 +2405,7 @@ index a7fdf453d895..e3a0e969a66e 100644
        unsigned long iv = __this_cpu_read(mce_next_interval);
  
        __restart_timer(t, interval);
-@@ -1397,7 +1385,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)
@@ -2388,7 +2414,7 @@ index a7fdf453d895..e3a0e969a66e 100644
  }
  
  static void mce_do_trigger(struct work_struct *work)
-@@ -1407,6 +1395,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);
  
@@ -2445,7 +2471,7 @@ index a7fdf453d895..e3a0e969a66e 100644
  /*
   * Notify the user(s) about new machine check events.
   * Can be called from interrupt context, but not from machine check/NMI
-@@ -1414,19 +1452,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)
  {
@@ -2466,7 +2492,7 @@ index a7fdf453d895..e3a0e969a66e 100644
                return 1;
        }
        return 0;
-@@ -1732,7 +1759,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)
        }
  }
  
@@ -2475,7 +2501,7 @@ index a7fdf453d895..e3a0e969a66e 100644
  {
        unsigned long iv = check_interval * HZ;
  
-@@ -1741,16 +1768,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;
  
@@ -2497,7 +2523,7 @@ index a7fdf453d895..e3a0e969a66e 100644
        mce_start_timer(cpu, t);
  }
  
-@@ -2475,6 +2503,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;
  
@@ -2506,7 +2532,7 @@ index a7fdf453d895..e3a0e969a66e 100644
        if (!(action & CPU_TASKS_FROZEN))
                cmci_clear();
  
-@@ -2497,6 +2527,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);
        }
@@ -2514,7 +2540,7 @@ index a7fdf453d895..e3a0e969a66e 100644
  }
  
  /* Get notified when a cpu comes on/off. Be hotplug friendly. */
-@@ -2504,7 +2535,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;
@@ -2522,7 +2548,7 @@ index a7fdf453d895..e3a0e969a66e 100644
  
        switch (action & ~CPU_TASKS_FROZEN) {
        case CPU_ONLINE:
-@@ -2524,11 +2554,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);
@@ -2534,7 +2560,7 @@ index a7fdf453d895..e3a0e969a66e 100644
                break;
        }
  
-@@ -2567,6 +2595,10 @@ static __init int mcheck_init_device(void)
+@@ -2556,6 +2584,10 @@ static __init int mcheck_init_device(void)
                goto err_out;
        }
  
@@ -2623,10 +2649,10 @@ index bd7be8efdc4c..b3b0a7f7b1ca 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 3f05c044720b..fe68afd37162 100644
+index b24b3c6d686e..02a062b0de5d 100644
 --- a/arch/x86/kvm/lapic.c
 +++ b/arch/x86/kvm/lapic.c
-@@ -1939,6 +1939,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;
@@ -2635,10 +2661,10 @@ index 3f05c044720b..fe68afd37162 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 731044efb195..d2905d9881f0 100644
+index 02d45296a97c..4963bd51d20b 100644
 --- a/arch/x86/kvm/x86.c
 +++ b/arch/x86/kvm/x86.c
-@@ -5933,6 +5933,13 @@ int kvm_arch_init(void *opaque)
+@@ -5966,6 +5966,13 @@ int kvm_arch_init(void *opaque)
                goto out;
        }
  
@@ -2931,7 +2957,7 @@ index b333fc45f9ec..8b85916e6986 100644
  
  /*
 diff --git a/block/blk-core.c b/block/blk-core.c
-index 14d7c0740dc0..dfd905bea77c 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)
@@ -2948,12 +2974,12 @@ index 14d7c0740dc0..dfd905bea77c 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;
  
@@ -2962,7 +2988,7 @@ index 14d7c0740dc0..dfd905bea77c 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);
  
@@ -2971,7 +2997,7 @@ index 14d7c0740dc0..dfd905bea77c 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);
  
@@ -2980,7 +3006,7 @@ index 14d7c0740dc0..dfd905bea77c 100644
  
        /*
         * Init percpu_ref in atomic mode so that it's faster to shutdown.
-@@ -3177,7 +3180,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);
@@ -2989,7 +3015,7 @@ index 14d7c0740dc0..dfd905bea77c 100644
  }
  
  static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
-@@ -3225,7 +3228,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;
@@ -2997,7 +3023,7 @@ index 14d7c0740dc0..dfd905bea77c 100644
        struct request *rq;
        LIST_HEAD(list);
        unsigned int depth;
-@@ -3245,11 +3247,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;
  
@@ -3009,7 +3035,7 @@ index 14d7c0740dc0..dfd905bea77c 100644
        while (!list_empty(&list)) {
                rq = list_entry_rq(list.next);
                list_del_init(&rq->queuelist);
-@@ -3262,7 +3259,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;
@@ -3018,7 +3044,7 @@ index 14d7c0740dc0..dfd905bea77c 100644
                }
  
                /*
-@@ -3289,8 +3286,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);
@@ -3058,7 +3084,7 @@ index 381cb50a673c..dc8785233d94 100644
                }
        }
 diff --git a/block/blk-mq.c b/block/blk-mq.c
-index 81caceb96c3c..b12b0ab005a9 100644
+index 7b597ec4e9c5..48c9652a701c 100644
 --- a/block/blk-mq.c
 +++ b/block/blk-mq.c
 @@ -72,7 +72,7 @@ EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_start);
@@ -3151,7 +3177,7 @@ index 81caceb96c3c..b12b0ab005a9 100644
  }
  
  static void __blk_mq_complete_request(struct request *rq)
-@@ -915,14 +935,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 && !(hctx->flags & BLK_MQ_F_BLOCKING)) {
@@ -3433,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;
  }
@@ -3455,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;
                }
@@ -3479,7 +3506,7 @@ 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 d2ef51ca9cf4..05e749736560 100644
+index c9914d653968..2038d138f286 100644
 --- a/drivers/block/zram/zram_drv.c
 +++ b/drivers/block/zram/zram_drv.c
 @@ -528,6 +528,8 @@ static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
@@ -3505,14 +3532,14 @@ index d2ef51ca9cf4..05e749736560 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);
 -
@@ -3654,10 +3681,18 @@ index 74fcf10da374..fd4020c99b9e 100644
 +
  #endif
 diff --git a/drivers/char/random.c b/drivers/char/random.c
-index d6876d506220..0c60b1e54579 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;
  
@@ -3666,7 +3701,7 @@ index d6876d506220..0c60b1e54579 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));
        }
@@ -3674,7 +3709,7 @@ index d6876d506220..0c60b1e54579 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++);
  }
  
@@ -3708,6 +3743,109 @@ index d6876d506220..0c60b1e54579 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
@@ -4059,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 0c400f852a76..97d5f6193751 100644
+index 2117f172d7a2..96c15501b0c8 100644
 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
-@@ -1537,7 +1537,9 @@ execbuf_submit(struct i915_execbuffer_params *params,
+@@ -1489,7 +1489,9 @@ execbuf_submit(struct i915_execbuffer_params *params,
        if (ret)
                return ret;
  
@@ -4073,7 +4211,7 @@ index 0c400f852a76..97d5f6193751 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 1c237d02f30b..9e9b4404c0d7 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)
@@ -4086,7 +4224,7 @@ index 1c237d02f30b..9e9b4404c0d7 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 3fc286cd1157..252a1117b103 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,
@@ -4106,10 +4244,10 @@ index 3fc286cd1157..252a1117b103 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 b9be8a6141d8..3162feddabe8 100644
+index ce32303b3013..c0a53bf2e952 100644
 --- a/drivers/gpu/drm/i915/intel_display.c
 +++ b/drivers/gpu/drm/i915/intel_display.c
-@@ -12141,7 +12141,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;
  
@@ -4119,7 +4257,7 @@ index b9be8a6141d8..3162feddabe8 100644
        if (crtc == NULL)
                return;
 diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c
-index dbed12c484c9..5c540b78e8b5 100644
+index 64f4e2e18594..aebf1e9eabcb 100644
 --- a/drivers/gpu/drm/i915/intel_sprite.c
 +++ b/drivers/gpu/drm/i915/intel_sprite.c
 @@ -35,6 +35,7 @@
@@ -4139,7 +4277,7 @@ index dbed12c484c9..5c540b78e8b5 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
-@@ -95,7 +98,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;
  
@@ -4148,7 +4286,7 @@ index dbed12c484c9..5c540b78e8b5 100644
  
        if (min <= 0 || max <= 0)
                return;
-@@ -125,11 +128,11 @@ void intel_pipe_update_start(struct intel_crtc *crtc)
+@@ -128,11 +131,11 @@ void intel_pipe_update_start(struct intel_crtc *crtc)
                        break;
                }
  
@@ -4162,7 +4300,7 @@ index dbed12c484c9..5c540b78e8b5 100644
        }
  
        finish_wait(wq, &wait);
-@@ -181,7 +184,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;
        }
  
@@ -4462,7 +4600,7 @@ 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 11a13b5be73a..baaed0ac274b 100644
+index 1a0b110f12c0..ff5c2424eb9e 100644
 --- a/drivers/iommu/amd_iommu.c
 +++ b/drivers/iommu/amd_iommu.c
 @@ -1923,10 +1923,10 @@ static int __attach_device(struct iommu_dev_data *dev_data,
@@ -4493,8 +4631,26 @@ index 11a13b5be73a..baaed0ac274b 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 d82637ab09fd..ebe41d30c093 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 {
@@ -4506,7 +4662,7 @@ index d82637ab09fd..ebe41d30c093 100644
  
  /* bitmap for indexing intel_iommus */
  static int g_num_of_iommus;
-@@ -3715,10 +3715,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;
@@ -4518,7 +4674,7 @@ index d82637ab09fd..ebe41d30c093 100644
  
        /* Flush all CPUs' entries to avoid deferring too much.  If
         * this becomes a bottleneck, can just flush us, and rely on
-@@ -3751,8 +3749,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);
@@ -4610,7 +4766,7 @@ 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 2c965424d383..2c8877f50626 100644
+index ba7c4c685db3..834ec328f217 100644
 --- a/drivers/md/dm-rq.c
 +++ b/drivers/md/dm-rq.c
 @@ -842,7 +842,7 @@ static void dm_old_request_fn(struct request_queue *q)
@@ -4623,10 +4779,28 @@ index 2c965424d383..2c8877f50626 100644
  }
  
 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
-index cce6057b9aca..fa2c4de32a64 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;
  
@@ -4637,7 +4811,7 @@ index cce6057b9aca..fa2c4de32a64 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);
                }
@@ -4647,7 +4821,7 @@ index cce6057b9aca..fa2c4de32a64 100644
  }
  
  static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp,
-@@ -6391,6 +6393,7 @@ static int raid456_cpu_up_prepare(unsigned int cpu, struct hlist_node *node)
+@@ -6407,6 +6409,7 @@ static int raid456_cpu_up_prepare(unsigned int cpu, struct hlist_node *node)
                       __func__, cpu);
                return -ENOMEM;
        }
@@ -4655,7 +4829,7 @@ index cce6057b9aca..fa2c4de32a64 100644
        return 0;
  }
  
-@@ -6401,7 +6404,6 @@ static int raid5_alloc_percpu(struct r5conf *conf)
+@@ -6417,7 +6420,6 @@ static int raid5_alloc_percpu(struct r5conf *conf)
        conf->percpu = alloc_percpu(struct raid5_percpu);
        if (!conf->percpu)
                return -ENOMEM;
@@ -4799,21 +4973,8 @@ index bca6935a94db..d7a35ee34d03 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 775c88303017..f8e9e1c2b2f6 100644
+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 {
@@ -4951,9 +5112,9 @@ index 775c88303017..f8e9e1c2b2f6 100644
 -      spin_lock_irqsave(&pctrl->lock, flags);
 +      raw_spin_lock_irqsave(&pctrl->lock, flags);
  
-       val = readl(pctrl->regs + g->intr_status_reg);
-       val &= ~BIT(g->intr_status_bit);
-@@ -604,7 +604,7 @@ static void msm_gpio_irq_unmask(struct irq_data *d)
+       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);
  
@@ -4962,7 +5123,7 @@ index 775c88303017..f8e9e1c2b2f6 100644
  }
  
  static void msm_gpio_irq_ack(struct irq_data *d)
-@@ -617,7 +617,7 @@ 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];
  
@@ -4971,7 +5132,7 @@ index 775c88303017..f8e9e1c2b2f6 100644
  
        val = readl(pctrl->regs + g->intr_status_reg);
        if (g->intr_ack_high)
-@@ -629,7 +629,7 @@ static void msm_gpio_irq_ack(struct irq_data *d)
+@@ -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);
  
@@ -4980,7 +5141,7 @@ index 775c88303017..f8e9e1c2b2f6 100644
  }
  
  static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
-@@ -642,7 +642,7 @@ 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];
  
@@ -4989,7 +5150,7 @@ index 775c88303017..f8e9e1c2b2f6 100644
  
        /*
         * For hw without possibility of detecting both edges
-@@ -716,7 +716,7 @@ static int msm_gpio_irq_set_type(struct irq_data *d, unsigned int type)
+@@ -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);
  
@@ -4998,7 +5159,7 @@ index 775c88303017..f8e9e1c2b2f6 100644
  
        if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
                irq_set_handler_locked(d, handle_level_irq);
-@@ -732,11 +732,11 @@ static int msm_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
+@@ -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;
  
@@ -5012,7 +5173,7 @@ index 775c88303017..f8e9e1c2b2f6 100644
  
        return 0;
  }
-@@ -882,7 +882,7 @@ int msm_pinctrl_probe(struct platform_device *pdev,
+@@ -878,7 +878,7 @@ int msm_pinctrl_probe(struct platform_device *pdev,
        pctrl->soc = soc_data;
        pctrl->chip = msm_gpio_template;
  
@@ -5119,7 +5280,7 @@ index 16ca31ad5ec0..c3987347e762 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)
@@ -5160,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 068c4e47fac9..a2090f640397 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);
@@ -5304,7 +5465,7 @@ index e8819aa20415..dd7f9bf45d6c 100644
  #include <asm/serial.h>
  /*
 diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
-index 080d5a59d0a7..eecc4f111473 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 @@
@@ -5315,7 +5476,7 @@ index 080d5a59d0a7..eecc4f111473 100644
  #include <linux/uaccess.h>
  #include <linux/pm_runtime.h>
  #include <linux/timer.h>
-@@ -3144,9 +3145,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);
  
@@ -5365,7 +5526,7 @@ index e2c33b9528d8..53af53c43e8c 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,
@@ -5396,10 +5557,10 @@ index a2a529994ba5..0ee7c4c518df 100644
  
  static int __init
 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
-index 479e223f9cff..3418a54b4131 100644
+index fcc7aa248ce7..fb2c38d875f9 100644
 --- a/drivers/usb/core/hcd.c
 +++ b/drivers/usb/core/hcd.c
-@@ -1761,9 +1761,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.
         */
@@ -5412,7 +5573,7 @@ index 479e223f9cff..3418a54b4131 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 8d412d8b1f29..176491dd739e 100644
+index 4fce83266926..5e902a89d8e6 100644
 --- a/drivers/usb/gadget/function/f_fs.c
 +++ b/drivers/usb/gadget/function/f_fs.c
 @@ -1593,7 +1593,7 @@ static void ffs_data_put(struct ffs_data *ffs)
@@ -5425,10 +5586,10 @@ index 8d412d8b1f29..176491dd739e 100644
                kfree(ffs);
        }
 diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
-index 1468d8f085a3..6aae3ae25c18 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)) {
@@ -5437,7 +5598,7 @@ index 1468d8f085a3..6aae3ae25c18 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);
  
@@ -5447,7 +5608,7 @@ index 1468d8f085a3..6aae3ae25c18 100644
                                        epdata->status = -EINTR;
                        } else {
 diff --git a/fs/aio.c b/fs/aio.c
-index 428484f2f841..2b02e2eb2158 100644
+index 0fcb49ad67d4..211ebc21e4db 100644
 --- a/fs/aio.c
 +++ b/fs/aio.c
 @@ -40,6 +40,7 @@
@@ -5551,7 +5712,7 @@ index d8e6d421c27f..2e689ab1306b 100644
                        }
                        spin_unlock(&p->d_lock);
 diff --git a/fs/buffer.c b/fs/buffer.c
-index b205a629001d..5646afc022ba 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)
@@ -5635,7 +5796,7 @@ index a27fc8791551..791aecb7c1ac 100644
        cifs_dbg(FYI, "%s: for %s\n", __func__, name->name);
  
 diff --git a/fs/dcache.c b/fs/dcache.c
-index 4485a48f4091..691039a6a872 100644
+index 67957f5b325c..f0719b2f1be5 100644
 --- a/fs/dcache.c
 +++ b/fs/dcache.c
 @@ -19,6 +19,7 @@
@@ -5646,7 +5807,7 @@ index 4485a48f4091..691039a6a872 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)
  {
@@ -5655,7 +5816,7 @@ index 4485a48f4091..691039a6a872 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:
@@ -5677,7 +5838,7 @@ index 4485a48f4091..691039a6a872 100644
                goto repeat;
        }
  }
-@@ -2324,7 +2336,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);
@@ -5686,7 +5847,27 @@ index 4485a48f4091..691039a6a872 100644
                        goto again;
                }
                dentry->d_flags &= ~DCACHE_CANT_MOUNT;
-@@ -2384,21 +2396,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)
  {
@@ -5722,7 +5903,25 @@ index 4485a48f4091..691039a6a872 100644
  {
        unsigned int hash = name->hash;
        struct hlist_bl_head *b = in_lookup_hash(parent, hash);
-@@ -2507,7 +2522,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);
@@ -5731,7 +5930,7 @@ index 4485a48f4091..691039a6a872 100644
        dentry->d_wait = NULL;
        hlist_bl_unlock(b);
        INIT_HLIST_NODE(&dentry->d_u.d_alias);
-@@ -3604,6 +3619,11 @@ EXPORT_SYMBOL(d_genocide);
+@@ -3632,6 +3649,11 @@ EXPORT_SYMBOL(d_genocide);
  
  void __init vfs_caches_init_early(void)
  {
@@ -5744,7 +5943,7 @@ index 4485a48f4091..691039a6a872 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)
@@ -5763,10 +5962,10 @@ 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 67e86571685a..fe14cdd84016 100644
+index b8c43be24751..71f4c6ec2bb8 100644
 --- a/fs/exec.c
 +++ b/fs/exec.c
-@@ -1017,12 +1017,14 @@ static int exec_mmap(struct mm_struct *mm)
+@@ -1038,12 +1038,14 @@ static int exec_mmap(struct mm_struct *mm)
                }
        }
        task_lock(tsk);
@@ -5781,8 +5980,32 @@ index 67e86571685a..fe14cdd84016 100644
        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 642c57b8de7b..8494b9308333 100644
+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,
@@ -5794,19 +6017,51 @@ index 642c57b8de7b..8494b9308333 100644
  
        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);
+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
@@ -5952,10 +6207,10 @@ index 22c5b4aa4961..269c6a44449a 100644
        locks_dispose_list(&dispose);
  }
 diff --git a/fs/namei.c b/fs/namei.c
-index 5b4eed221530..9c8dd3c83a80 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;
@@ -5964,7 +6219,7 @@ index 5b4eed221530..9c8dd3c83a80 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;
@@ -5974,7 +6229,7 @@ index 5b4eed221530..9c8dd3c83a80 100644
        if (unlikely(IS_DEADDIR(dir_inode)))
                return -ENOENT;
 diff --git a/fs/namespace.c b/fs/namespace.c
-index 7cea503ae06d..cb15f5397991 100644
+index d7360f9897b4..da188c6966a3 100644
 --- a/fs/namespace.c
 +++ b/fs/namespace.c
 @@ -14,6 +14,7 @@
@@ -5985,7 +6240,7 @@ index 7cea503ae06d..cb15f5397991 100644
  #include <linux/security.h>
  #include <linux/idr.h>
  #include <linux/init.h>               /* init_rootfs */
-@@ -356,8 +357,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();
@@ -6018,7 +6273,7 @@ index dff600ae0d74..d726d2e09353 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 53e02b8bd9bd..a66e7d77cfbb 100644
+index 65566d5fcf39..5f08183dddcd 100644
 --- a/fs/nfs/dir.c
 +++ b/fs/nfs/dir.c
 @@ -485,7 +485,7 @@ static
@@ -6030,7 +6285,7 @@ index 53e02b8bd9bd..a66e7d77cfbb 100644
        struct dentry *dentry;
        struct dentry *alias;
        struct inode *dir = d_inode(parent);
-@@ -1487,7 +1487,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)
  {
@@ -6039,7 +6294,7 @@ index 53e02b8bd9bd..a66e7d77cfbb 100644
        struct nfs_open_context *ctx;
        struct dentry *res;
        struct iattr attr = { .ia_valid = ATTR_OPEN };
-@@ -1802,7 +1802,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)) {
@@ -6051,7 +6306,7 @@ index 53e02b8bd9bd..a66e7d77cfbb 100644
                error = NFS_PROTO(dir)->rmdir(dir, &dentry->d_name);
                /* Ensure the VFS deletes this inode */
                switch (error) {
-@@ -1812,7 +1816,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);
                }
@@ -6064,7 +6319,7 @@ index 53e02b8bd9bd..a66e7d77cfbb 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)
@@ -6093,10 +6348,10 @@ index 1452177c822d..f43b01d54c59 100644
  };
  
 diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
-index 78ff8b63d5f7..3573653fd5cc 100644
+index 4638654e26f3..5dd6fd555c72 100644
 --- a/fs/nfs/nfs4proc.c
 +++ b/fs/nfs/nfs4proc.c
-@@ -2698,7 +2698,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;
  
@@ -6105,8 +6360,8 @@ index 78ff8b63d5f7..3573653fd5cc 100644
  
        ret = _nfs4_proc_open(opendata);
        if (ret != 0)
-@@ -2736,7 +2736,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))
@@ -6115,7 +6370,7 @@ index 78ff8b63d5f7..3573653fd5cc 100644
        }
  out:
 diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
-index 0959c9661662..dabd834d7686 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,
@@ -6127,7 +6382,7 @@ index 0959c9661662..dabd834d7686 100644
        mutex_init(&sp->so_delegreturn_mutex);
        return sp;
  }
-@@ -1497,8 +1497,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.
         */
@@ -6141,7 +6396,7 @@ index 0959c9661662..dabd834d7686 100644
  restart:
        list_for_each_entry(state, &sp->so_states, open_states) {
                if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
-@@ -1567,14 +1571,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;
        }
@@ -6317,7 +6572,7 @@ index fe251f187ff8..e89da4fb14c2 100644
  
  /**
 diff --git a/fs/proc/base.c b/fs/proc/base.c
-index ca651ac00660..41d9dc789285 100644
+index e67fec3c9856..0edc16f95596 100644
 --- a/fs/proc/base.c
 +++ b/fs/proc/base.c
 @@ -1834,7 +1834,7 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx,
@@ -6343,10 +6598,10 @@ index d4e37acd4821..000cea46434a 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);
@@ -6358,6 +6613,30 @@ 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 e861a24f06f2..b5c97d3059c7 100644
 --- a/include/acpi/platform/aclinux.h
@@ -6502,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 {
@@ -6557,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 @@
@@ -6568,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;
@@ -6636,7 +6915,7 @@ index e571128ad99a..5e52d28c20c1 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 5beed7b30561..61cab7ef458e 100644
+index ff295e166b2c..d532c60f3fb5 100644
 --- a/include/linux/dcache.h
 +++ b/include/linux/dcache.h
 @@ -11,6 +11,7 @@
@@ -6680,6 +6959,19 @@ index a6ecb34cf547..37caab306336 100644
 +#endif
 +
  #endif /* defined(_LINUX_DELAY_H) */
+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;
+       };
+       __u32                   i_generation;
 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
 index bb3f3297062a..a117a33ef72c 100644
 --- a/include/linux/highmem.h
@@ -6890,7 +7182,7 @@ 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 325f649d77ff..8af70bcc799b 100644
+index 325f649d77ff..a56e263f5005 100644
 --- a/include/linux/init_task.h
 +++ b/include/linux/init_task.h
 @@ -150,6 +150,12 @@ extern struct task_group root_task_group;
@@ -6906,7 +7198,15 @@ index 325f649d77ff..8af70bcc799b 100644
  #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  # define INIT_VTIME(tsk)                                              \
        .vtime_seqcount = SEQCNT_ZERO(tsk.vtime_seqcount),      \
-@@ -250,6 +256,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 */            \
@@ -7402,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
 +
@@ -7485,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;
 +}
@@ -7658,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()
@@ -7685,7 +7994,7 @@ index 000000000000..845c77f1a5ca
 +
 +#endif
 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
-index 08d947fc4c59..705fb564a605 100644
+index e8471c2ca83a..08bde1a7a987 100644
 --- a/include/linux/mm_types.h
 +++ b/include/linux/mm_types.h
 @@ -11,6 +11,7 @@
@@ -7696,8 +8005,8 @@ index 08d947fc4c59..705fb564a605 100644
  #include <linux/page-flags-layout.h>
  #include <linux/workqueue.h>
  #include <asm/page.h>
-@@ -509,6 +510,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
@@ -7871,7 +8180,7 @@ index 000000000000..e0284edec655
 +
 +#endif
 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
-index bb9b102c15cd..a5b12b8ad196 100644
+index 47c7f5b8f675..85fc72b8a92b 100644
 --- a/include/linux/netdevice.h
 +++ b/include/linux/netdevice.h
 @@ -396,7 +396,19 @@ typedef enum rx_handler_result rx_handler_result_t;
@@ -7894,7 +8203,7 @@ index bb9b102c15cd..a5b12b8ad196 100644
  
  static inline bool napi_disable_pending(struct napi_struct *n)
  {
-@@ -2463,14 +2475,53 @@ void netdev_freemem(struct net_device *dev);
+@@ -2464,14 +2476,53 @@ void netdev_freemem(struct net_device *dev);
  void synchronize_net(void);
  int init_dummy_netdev(struct net_device *dev);
  
@@ -7949,7 +8258,7 @@ index bb9b102c15cd..a5b12b8ad196 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);
-@@ -2855,6 +2906,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;
@@ -8013,7 +8322,7 @@ 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 beb1e10f446e..ebaf2e7bfe29 100644
+index 3bf867a0c3b3..71c6bdd14c8a 100644
 --- a/include/linux/nfs_xdr.h
 +++ b/include/linux/nfs_xdr.h
 @@ -1490,7 +1490,7 @@ struct nfs_unlinkdata {
@@ -8242,7 +8551,7 @@ index 56939d3f6e53..b988bf40ad3e 100644
  
  #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 @@
@@ -8254,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 @@
@@ -8287,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()
   */
@@ -8307,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)
  
@@ -8328,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)
  
@@ -8355,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)
  
@@ -8369,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()
@@ -8377,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 { \
@@ -8452,7 +8761,7 @@ index af3581b8a451..277295039c8f 100644
   * struct radix_tree_iter - radix tree iterator state
   *
 diff --git a/include/linux/random.h b/include/linux/random.h
-index 7bd2403e4fef..b2df7148a42b 100644
+index 16ab429735a7..9d0fecb5b6c2 100644
 --- a/include/linux/random.h
 +++ b/include/linux/random.h
 @@ -31,7 +31,7 @@ static inline void add_latent_entropy(void) {}
@@ -8764,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 @@
@@ -8833,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,
@@ -9001,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 @@
@@ -9015,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
 +
@@ -9035,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 75d9a57e212e..8cb7df0f56e3 100644
+index a4d0afc009a7..e775696b480a 100644
 --- a/include/linux/sched.h
 +++ b/include/linux/sched.h
 @@ -26,6 +26,7 @@ struct sched_param {
@@ -9207,7 +9425,14 @@ index 75d9a57e212e..8cb7df0f56e3 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)
  
@@ -9218,7 +9443,7 @@ index 75d9a57e212e..8cb7df0f56e3 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
  
@@ -9230,13 +9455,27 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  /* Task command name length */
  #define TASK_COMM_LEN 16
  
-@@ -1013,8 +1016,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)
@@ -9251,7 +9490,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  
  /*
   * sched-domains (multiprocessor balancing) declarations:
-@@ -1481,6 +1494,7 @@ 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 */
@@ -9259,12 +9498,13 @@ index 75d9a57e212e..8cb7df0f56e3 100644
        void *stack;
        atomic_t usage;
        unsigned int flags;     /* per process flags, defined below */
-@@ -1520,6 +1534,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
@@ -9272,7 +9512,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
        int nr_cpus_allowed;
        cpumask_t cpus_allowed;
  
-@@ -1654,6 +1674,9 @@ struct task_struct {
+@@ -1668,6 +1700,9 @@ struct task_struct {
  
        struct task_cputime cputime_expires;
        struct list_head cpu_timers[3];
@@ -9282,7 +9522,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  
  /* process credentials */
        const struct cred __rcu *ptracer_cred; /* Tracer's credentials at attach */
-@@ -1685,10 +1708,15 @@ struct task_struct {
+@@ -1699,10 +1734,15 @@ struct task_struct {
  /* signal handlers */
        struct signal_struct *signal;
        struct sighand_struct *sighand;
@@ -9298,7 +9538,22 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  
        unsigned long sas_ss_sp;
        size_t sas_ss_size;
-@@ -1917,6 +1945,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 */
@@ -9311,7 +9566,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  #ifdef CONFIG_KCOV
        /* Coverage collection mode enabled for this task (0 if disabled). */
        enum kcov_mode kcov_mode;
-@@ -1942,9 +1976,23 @@ struct task_struct {
+@@ -1956,9 +2005,23 @@ struct task_struct {
        unsigned int    sequential_io;
        unsigned int    sequential_io_avg;
  #endif
@@ -9335,7 +9590,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
        int pagefault_disabled;
  #ifdef CONFIG_MMU
        struct task_struct *oom_reaper_list;
-@@ -1984,14 +2032,6 @@ static inline struct vm_struct *task_stack_vm_area(const struct task_struct *t)
+@@ -1998,14 +2061,6 @@ static inline struct vm_struct *task_stack_vm_area(const struct task_struct *t)
  }
  #endif
  
@@ -9350,7 +9605,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  #define TNF_MIGRATED  0x01
  #define TNF_NO_GROUP  0x02
  #define TNF_SHARED    0x04
-@@ -2207,6 +2247,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)
  
@@ -9366,7 +9621,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  extern void __put_task_struct(struct task_struct *t);
  
  static inline void put_task_struct(struct task_struct *t)
-@@ -2214,6 +2263,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);
  }
@@ -9374,7 +9629,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  
  struct task_struct *task_rcu_dereference(struct task_struct **ptask);
  struct task_struct *try_get_task_struct(struct task_struct **ptask);
-@@ -2255,6 +2305,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
   */
@@ -9382,7 +9637,7 @@ index 75d9a57e212e..8cb7df0f56e3 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 */
-@@ -2423,6 +2474,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);
@@ -9393,7 +9648,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  #else
  static inline void do_set_cpus_allowed(struct task_struct *p,
                                      const struct cpumask *new_mask)
-@@ -2435,6 +2490,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;
  }
@@ -9403,7 +9658,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  #endif
  
  #ifdef CONFIG_NO_HZ_COMMON
-@@ -2673,6 +2731,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);
@@ -9411,7 +9666,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  extern void wake_up_new_task(struct task_struct *tsk);
  #ifdef CONFIG_SMP
   extern void kick_process(struct task_struct *tsk);
-@@ -2881,6 +2940,17 @@ static inline void mmdrop(struct mm_struct *mm)
+@@ -2899,6 +2973,17 @@ static inline void mmdrop(struct mm_struct *mm)
                __mmdrop(mm);
  }
  
@@ -9429,7 +9684,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  static inline void mmdrop_async_fn(struct work_struct *work)
  {
        struct mm_struct *mm = container_of(work, struct mm_struct, async_put_work);
-@@ -3273,6 +3343,43 @@ static inline int test_tsk_need_resched(struct task_struct *tsk)
+@@ -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));
  }
  
@@ -9473,7 +9728,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  static inline int restart_syscall(void)
  {
        set_tsk_thread_flag(current, TIF_SIGPENDING);
-@@ -3304,6 +3411,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);
  }
  
@@ -9525,7 +9780,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  /*
   * cond_resched() and cond_resched_lock(): latency reduction via
   * explicit rescheduling in places that are safe. The return
-@@ -3329,12 +3481,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);                              \
  })
  
@@ -9542,7 +9797,7 @@ index 75d9a57e212e..8cb7df0f56e3 100644
  
  static inline void cond_resched_rcu(void)
  {
-@@ -3509,6 +3665,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 */
  
@@ -9574,6 +9829,46 @@ index 75d9a57e212e..8cb7df0f56e3 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
@@ -9729,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 32810f279f8e..0db6e31161f6 100644
+index 601dfa849d30..dca387a8fa6b 100644
 --- a/include/linux/skbuff.h
 +++ b/include/linux/skbuff.h
 @@ -284,6 +284,7 @@ struct sk_buff_head {
@@ -9754,10 +10049,36 @@ index 32810f279f8e..0db6e31161f6 100644
                struct lock_class_key *class)
  {
 diff --git a/include/linux/smp.h b/include/linux/smp.h
-index 8e0cb7a0f836..b16ca967ad80 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()
  
@@ -9768,7 +10089,7 @@ index 8e0cb7a0f836..b16ca967ad80 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)
@@ -9795,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))
  
@@ -9831,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..3534cff3dd08
+index 000000000000..43ca841b913a
 --- /dev/null
 +++ b/include/linux/spinlock_rt.h
-@@ -0,0 +1,164 @@
+@@ -0,0 +1,162 @@
 +#ifndef __LINUX_SPINLOCK_RT_H
 +#define __LINUX_SPINLOCK_RT_H
 +
@@ -9863,7 +10171,6 @@ index 000000000000..3534cff3dd08
 +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);
@@ -9949,7 +10256,6 @@ index 000000000000..3534cff3dd08
 +#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 {                                            \
@@ -10009,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 {
@@ -10046,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,  \
@@ -10399,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 {
@@ -10481,10 +10786,10 @@ index 2408e8d5c05c..db50d6609195 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)
  {
@@ -10592,7 +10897,7 @@ index 7adf4386ac8f..d3fd5c357268 100644
        int sysctl_icmp_ratelimit;
        int sysctl_icmp_ratemask;
 diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h
-index e6aa0a249672..b57736f2a8a3 100644
+index f18fc1a0321f..5d2c9b89c168 100644
 --- a/include/net/sch_generic.h
 +++ b/include/net/sch_generic.h
 @@ -10,6 +10,7 @@
@@ -10776,6 +11081,76 @@ 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 34407f15e6d3..2ce33a32e65d 100644
 --- a/init/Kconfig
@@ -10864,17 +11239,17 @@ diff --git a/init/Makefile b/init/Makefile
 index c4fb45525d08..821190dfaa75 100644
 --- a/init/Makefile
 +++ b/init/Makefile
-@@ -35,4 +35,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 2858be732f6d..3c97c3c91d88 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();
@@ -10999,10 +11374,10 @@ index 3f9c97419f02..11dbe26a8279 100644
  
  config PREEMPT_COUNT
 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
-index 4e2f3de0e40b..6401eb5fe140 100644
+index 4c233437ee1a..6c3c9f298f22 100644
 --- a/kernel/cgroup.c
 +++ b/kernel/cgroup.c
-@@ -5040,10 +5040,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);
  }
  
@@ -11015,7 +11390,7 @@ index 4e2f3de0e40b..6401eb5fe140 100644
        struct cgroup_subsys *ss = css->ss;
        struct cgroup *cgrp = css->cgroup;
  
-@@ -5086,8 +5086,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);
  
@@ -11026,7 +11401,7 @@ index 4e2f3de0e40b..6401eb5fe140 100644
  }
  
  static void init_and_link_css(struct cgroup_subsys_state *css,
-@@ -5739,6 +5739,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);
@@ -11035,7 +11410,7 @@ index 4e2f3de0e40b..6401eb5fe140 100644
        /*
         * Used to destroy pidlists and separate to serve as flush domain.
 diff --git a/kernel/cpu.c b/kernel/cpu.c
-index 217fd2e7f435..69444f1bc924 100644
+index 26a4f74bff83..010db3c943cd 100644
 --- a/kernel/cpu.c
 +++ b/kernel/cpu.c
 @@ -239,6 +239,289 @@ static struct {
@@ -11328,7 +11703,7 @@ index 217fd2e7f435..69444f1bc924 100644
  
  void get_online_cpus(void)
  {
-@@ -789,10 +1072,14 @@ static int takedown_cpu(unsigned int cpu)
+@@ -802,10 +1085,14 @@ static int takedown_cpu(unsigned int cpu)
        struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
        int err;
  
@@ -11343,7 +11718,7 @@ index 217fd2e7f435..69444f1bc924 100644
        /*
         * Prevent irq alloc/free while the dying cpu reorganizes the
         * interrupt affinities.
-@@ -877,6 +1164,9 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
+@@ -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;
@@ -11353,7 +11728,7 @@ index 217fd2e7f435..69444f1bc924 100644
  
        if (num_online_cpus() == 1)
                return -EBUSY;
-@@ -884,7 +1174,34 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
+@@ -897,7 +1187,34 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
        if (!cpu_present(cpu))
                return -EINVAL;
  
@@ -11388,7 +11763,7 @@ index 217fd2e7f435..69444f1bc924 100644
  
        cpuhp_tasks_frozen = tasks_frozen;
  
-@@ -923,10 +1240,15 @@ static int __ref _cpu_down(unsigned int cpu, int 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:
@@ -11404,11 +11779,154 @@ index 217fd2e7f435..69444f1bc924 100644
        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 29f815d2ef7e..341b17f24f95 100644
+index 511b1dd8ff09..1dd63833ecdc 100644
 --- a/kernel/cpuset.c
 +++ b/kernel/cpuset.c
-@@ -284,7 +284,7 @@ static struct cpuset top_cpuset = {
+@@ -285,7 +285,7 @@ static struct cpuset top_cpuset = {
   */
  
  static DEFINE_MUTEX(cpuset_mutex);
@@ -11417,7 +11935,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
  static struct workqueue_struct *cpuset_migrate_mm_wq;
  
-@@ -907,9 +907,9 @@ static void update_cpumasks_hier(struct cpuset *cs, struct cpumask *new_cpus)
+@@ -908,9 +908,9 @@ static void update_cpumasks_hier(struct cpuset *cs, struct cpumask *new_cpus)
                        continue;
                rcu_read_unlock();
  
@@ -11429,7 +11947,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
                WARN_ON(!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
                        !cpumask_equal(cp->cpus_allowed, cp->effective_cpus));
-@@ -974,9 +974,9 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
+@@ -975,9 +975,9 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
        if (retval < 0)
                return retval;
  
@@ -11441,7 +11959,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
        /* use trialcs->cpus_allowed as a temp variable */
        update_cpumasks_hier(cs, trialcs->cpus_allowed);
-@@ -1176,9 +1176,9 @@ static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
+@@ -1177,9 +1177,9 @@ static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
                        continue;
                rcu_read_unlock();
  
@@ -11453,7 +11971,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
                WARN_ON(!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
                        !nodes_equal(cp->mems_allowed, cp->effective_mems));
-@@ -1246,9 +1246,9 @@ static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs,
+@@ -1247,9 +1247,9 @@ static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs,
        if (retval < 0)
                goto done;
  
@@ -11465,7 +11983,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
        /* use trialcs->mems_allowed as a temp variable */
        update_nodemasks_hier(cs, &trialcs->mems_allowed);
-@@ -1339,9 +1339,9 @@ static int update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
+@@ -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)));
  
@@ -11477,7 +11995,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
        if (!cpumask_empty(trialcs->cpus_allowed) && balance_flag_changed)
                rebuild_sched_domains_locked();
-@@ -1756,7 +1756,7 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
+@@ -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;
  
@@ -11486,7 +12004,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
        switch (type) {
        case FILE_CPULIST:
-@@ -1775,7 +1775,7 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
+@@ -1776,7 +1776,7 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v)
                ret = -EINVAL;
        }
  
@@ -11495,7 +12013,7 @@ index 29f815d2ef7e..341b17f24f95 100644
        return ret;
  }
  
-@@ -1989,12 +1989,12 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
+@@ -1991,12 +1991,12 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
  
        cpuset_inc();
  
@@ -11510,7 +12028,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
        if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags))
                goto out_unlock;
-@@ -2021,12 +2021,12 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
+@@ -2023,12 +2023,12 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
        }
        rcu_read_unlock();
  
@@ -11525,7 +12043,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  out_unlock:
        mutex_unlock(&cpuset_mutex);
        return 0;
-@@ -2065,7 +2065,7 @@ static void cpuset_css_free(struct cgroup_subsys_state *css)
+@@ -2067,7 +2067,7 @@ static void cpuset_css_free(struct cgroup_subsys_state *css)
  static void cpuset_bind(struct cgroup_subsys_state *root_css)
  {
        mutex_lock(&cpuset_mutex);
@@ -11534,7 +12052,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
        if (cgroup_subsys_on_dfl(cpuset_cgrp_subsys)) {
                cpumask_copy(top_cpuset.cpus_allowed, cpu_possible_mask);
-@@ -2076,7 +2076,7 @@ static void cpuset_bind(struct cgroup_subsys_state *root_css)
+@@ -2078,7 +2078,7 @@ static void cpuset_bind(struct cgroup_subsys_state *root_css)
                top_cpuset.mems_allowed = top_cpuset.effective_mems;
        }
  
@@ -11543,7 +12061,7 @@ index 29f815d2ef7e..341b17f24f95 100644
        mutex_unlock(&cpuset_mutex);
  }
  
-@@ -2177,12 +2177,12 @@ hotplug_update_tasks_legacy(struct cpuset *cs,
+@@ -2179,12 +2179,12 @@ hotplug_update_tasks_legacy(struct cpuset *cs,
  {
        bool is_empty;
  
@@ -11558,7 +12076,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
        /*
         * Don't call update_tasks_cpumask() if the cpuset becomes empty,
-@@ -2219,10 +2219,10 @@ hotplug_update_tasks(struct cpuset *cs,
+@@ -2221,10 +2221,10 @@ hotplug_update_tasks(struct cpuset *cs,
        if (nodes_empty(*new_mems))
                *new_mems = parent_cs(cs)->effective_mems;
  
@@ -11571,7 +12089,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
        if (cpus_updated)
                update_tasks_cpumask(cs);
-@@ -2308,21 +2308,21 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
+@@ -2317,21 +2317,21 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
  
        /* synchronize cpus_allowed to cpu_active_mask */
        if (cpus_updated) {
@@ -11597,7 +12115,7 @@ index 29f815d2ef7e..341b17f24f95 100644
                update_tasks_nodemask(&top_cpuset);
        }
  
-@@ -2420,11 +2420,11 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
+@@ -2436,11 +2436,11 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
  {
        unsigned long flags;
  
@@ -11611,7 +12129,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  }
  
  void cpuset_cpus_allowed_fallback(struct task_struct *tsk)
-@@ -2472,11 +2472,11 @@ nodemask_t cpuset_mems_allowed(struct task_struct *tsk)
+@@ -2488,11 +2488,11 @@ nodemask_t cpuset_mems_allowed(struct task_struct *tsk)
        nodemask_t mask;
        unsigned long flags;
  
@@ -11625,7 +12143,7 @@ index 29f815d2ef7e..341b17f24f95 100644
  
        return mask;
  }
-@@ -2568,14 +2568,14 @@ bool __cpuset_node_allowed(int node, gfp_t gfp_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 */
@@ -11684,7 +12202,7 @@ index fc1ef736253c..83c666537a7a 100644
        return r;
  }
 diff --git a/kernel/events/core.c b/kernel/events/core.c
-index 4b3323151a2f..e89a1a4d59cd 100644
+index 13b9784427b0..f74fbfe5465c 100644
 --- a/kernel/events/core.c
 +++ b/kernel/events/core.c
 @@ -1050,6 +1050,7 @@ static void __perf_mux_hrtimer_init(struct perf_cpu_context *cpuctx, int cpu)
@@ -11695,7 +12213,7 @@ index 4b3323151a2f..e89a1a4d59cd 100644
  }
  
  static int perf_mux_hrtimer_restart(struct perf_cpu_context *cpuctx)
-@@ -8363,6 +8364,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;
@@ -11717,7 +12235,7 @@ index 3076f3089919..fb2ebcf3ca7c 100644
        spin_unlock(&sighand->siglock);
  
 diff --git a/kernel/fork.c b/kernel/fork.c
-index ba8a01564985..47784f8aed37 100644
+index 9321b1ad3335..276acd8acf0a 100644
 --- a/kernel/fork.c
 +++ b/kernel/fork.c
 @@ -76,6 +76,7 @@
@@ -11773,7 +12291,15 @@ index ba8a01564985..47784f8aed37 100644
  
  void __init __weak arch_task_cache_init(void) { }
  
-@@ -852,6 +875,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);
  
@@ -11793,7 +12319,15 @@ index ba8a01564985..47784f8aed37 100644
  static inline void __mmput(struct mm_struct *mm)
  {
        VM_BUG_ON(atomic_read(&mm->mm_users));
-@@ -1426,6 +1462,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)
  {
@@ -11803,7 +12337,7 @@ index ba8a01564985..47784f8aed37 100644
        tsk->cputime_expires.prof_exp = 0;
        tsk->cputime_expires.virt_exp = 0;
        tsk->cputime_expires.sched_exp = 0;
-@@ -1552,6 +1591,7 @@ static __latent_entropy struct task_struct *copy_process(
+@@ -1561,6 +1602,7 @@ static __latent_entropy struct task_struct *copy_process(
        spin_lock_init(&p->alloc_lock);
  
        init_sigpending(&p->pending);
@@ -11812,10 +12346,40 @@ index ba8a01564985..47784f8aed37 100644
        p->utime = p->stime = p->gtime = 0;
        p->utimescaled = p->stimescaled = 0;
 diff --git a/kernel/futex.c b/kernel/futex.c
-index 38b68c2735c5..6450a8d81667 100644
+index 88bad86180ac..2e074d63e8fa 100644
 --- a/kernel/futex.c
 +++ b/kernel/futex.c
-@@ -904,7 +904,9 @@ void exit_pi_state_list(struct task_struct *curr)
+@@ -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) {
@@ -11825,36 +12389,398 @@ index 38b68c2735c5..6450a8d81667 100644
                        continue;
                }
  
-@@ -1299,6 +1301,7 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
-       struct futex_pi_state *pi_state = this->pi_state;
+@@ -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;
+       /*
+@@ -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);
+       /*
+        * 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);
+ }
+-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;
  
-@@ -1365,7 +1368,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
-@@ -1373,8 +1377,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);
+               }
  
-@@ -1924,6 +1929,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;
@@ -11871,32 +12797,499 @@ index 38b68c2735c5..6450a8d81667 100644
                        } else if (ret) {
                                /*
                                 * rt_mutex_start_proxy_lock() detected a
-@@ -2814,7 +2829,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
-       struct hrtimer_sleeper timeout, *to = 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;
-@@ -2839,10 +2854,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.
-        */
--      debug_rt_mutex_init_waiter(&rt_waiter);
--      RB_CLEAR_NODE(&rt_waiter.pi_tree_entry);
--      RB_CLEAR_NODE(&rt_waiter.tree_entry);
--      rt_waiter.task = NULL;
-+      rt_mutex_init_waiter(&rt_waiter, false);
+@@ -2008,20 +2108,7 @@ queue_unlock(struct futex_hash_bucket *hb)
+       hb_waiters_dec(hb);
+ }
  
-       ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, VERIFY_WRITE);
-       if (unlikely(ret != 0))
-@@ -2873,20 +2885,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);
+-/**
+- * 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;
  
--      spin_lock(&hb->lock);
+@@ -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 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;
+@@ -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.
+        */
+-      debug_rt_mutex_init_waiter(&rt_waiter);
+-      RB_CLEAR_NODE(&rt_waiter.pi_tree_entry);
+-      RB_CLEAR_NODE(&rt_waiter.tree_entry);
+-      rt_waiter.task = NULL;
++      rt_mutex_init_waiter(&rt_waiter, false);
+       ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, VERIFY_WRITE);
+       if (unlikely(ret != 0))
+@@ -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);
+-      spin_lock(&hb->lock);
 -      ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
 -      spin_unlock(&hb->lock);
 -      if (ret)
@@ -11959,7 +13352,7 @@ index 38b68c2735c5..6450a8d81667 100644
  
        /* Check if the requeue code acquired the second futex for us. */
        if (!q.rt_waiter) {
-@@ -2895,14 +2942,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)) {
@@ -11967,6 +13360,12 @@ index 38b68c2735c5..6450a8d81667 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.
@@ -11976,17 +13375,48 @@ index 38b68c2735c5..6450a8d81667 100644
 +                      spin_unlock(&hb2->lock);
                }
        } else {
-               /*
-@@ -2915,7 +2963,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
@@ -12010,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 6b669593e7eb..e357bf6c59d5 100644
+index ea41820ab12e..5994867526f3 100644
 --- a/kernel/irq/manage.c
 +++ b/kernel/irq/manage.c
 @@ -22,6 +22,7 @@
@@ -12133,7 +13563,7 @@ index 6b669593e7eb..e357bf6c59d5 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);
                }
  
@@ -12143,7 +13573,7 @@ index 6b669593e7eb..e357bf6c59d5 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.
   *
@@ -12371,7 +13801,7 @@ index ee1bc1bb8feb..ddef07958840 100644
  };
  
 diff --git a/kernel/locking/Makefile b/kernel/locking/Makefile
-index 6f88e352cd4f..5e27fb1079e7 100644
+index 6f88e352cd4f..6ff9e8011dd0 100644
 --- a/kernel/locking/Makefile
 +++ b/kernel/locking/Makefile
 @@ -2,7 +2,7 @@
@@ -12390,8 +13820,8 @@ index 6f88e352cd4f..5e27fb1079e7 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
@@ -12403,11 +13833,11 @@ index 6f88e352cd4f..5e27fb1079e7 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/lockdep.c b/kernel/locking/lockdep.c
-index 4d7ffc0a0d00..3d157b3128eb 100644
+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)
@@ -12477,7 +13907,7 @@ index 4d7ffc0a0d00..3d157b3128eb 100644
                return NULL;
        }
  
-@@ -3410,7 +3423,7 @@ static int match_held_lock(struct held_lock *hlock, struct lockdep_map *lock)
+@@ -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.
                 */
@@ -12486,7 +13916,7 @@ index 4d7ffc0a0d00..3d157b3128eb 100644
                        return 0;
  
                /*
-@@ -3689,6 +3702,7 @@ static void check_flags(unsigned long flags)
+@@ -3696,6 +3709,7 @@ static void check_flags(unsigned long flags)
                }
        }
  
@@ -12494,7 +13924,7 @@ index 4d7ffc0a0d00..3d157b3128eb 100644
        /*
         * We dont accurately track softirq state in e.g.
         * hardirq contexts (such as on 4KSTACKS), so only
-@@ -3703,6 +3717,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);
                }
        }
@@ -12502,7 +13932,7 @@ index 4d7ffc0a0d00..3d157b3128eb 100644
  
        if (!debug_locks)
                print_irqtrace_events(current);
-@@ -4159,7 +4174,7 @@ void lockdep_reset_lock(struct lockdep_map *lock)
+@@ -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);
@@ -12512,7 +13942,7 @@ index 4d7ffc0a0d00..3d157b3128eb 100644
        }
        /*
 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 @@
@@ -12556,10 +13986,10 @@ index ce182599cf2e..2ad3a1e8344c 100644
  
 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
 + *
@@ -12868,234 +14298,245 @@ index 000000000000..665754c00e1e
 +}
 +EXPORT_SYMBOL(__rt_rwlock_init);
 +
-+/*
-+ * rw_semaphores
++/**
++ * atomic_dec_and_mutex_lock - return holding mutex if we dec to 0
++ * @cnt: the atomic which we are to dec
++ * @lock: the mutex to return holding if we dec to 0
++ *
++ * return true and hold lock if we dec to 0, return false otherwise
 + */
-+
-+void  rt_up_write(struct rw_semaphore *rwsem)
++int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock)
 +{
-+      rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
-+      rt_mutex_unlock(&rwsem->lock);
++      /* dec if we can't possibly hit 0 */
++      if (atomic_add_unless(cnt, -1, 1))
++              return 0;
++      /* we might hit 0, so take the lock */
++      mutex_lock(lock);
++      if (!atomic_dec_and_test(cnt)) {
++              /* when we actually did the dec, we didn't hit 0 */
++              mutex_unlock(lock);
++              return 0;
++      }
++      /* we hit 0, and we hold the lock */
++      return 1;
 +}
-+EXPORT_SYMBOL(rt_up_write);
-+
-+void __rt_up_read(struct rw_semaphore *rwsem)
++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 2c49d76f96c3..3a8b5d44aaf8 100644
+--- a/kernel/locking/rtmutex.c
++++ b/kernel/locking/rtmutex.c
+@@ -7,6 +7,11 @@
+  *  Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
+  *  Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
+  *  Copyright (C) 2006 Esben Nielsen
++ *  Adaptive Spinlocks:
++ *  Copyright (C) 2008 Novell, Inc., Gregory Haskins, Sven Dietrich,
++ *                                 and Peter Morreale,
++ * Adaptive Spinlocks simplification:
++ *  Copyright (C) 2008 Red Hat, Inc., Steven Rostedt <srostedt@redhat.com>
+  *
+  *  See Documentation/locking/rt-mutex-design.txt for details.
+  */
+@@ -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)
 +{
-+      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);
++      return waiter && waiter != PI_WAKEUP_INPROGRESS &&
++              waiter != PI_REQUEUE_INPROGRESS;
 +}
-+EXPORT_SYMBOL(rt_up_read);
 +
+ /*
+  * 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
 +/*
-+ * downgrade a write lock into a read lock
-+ * - just wake up any readers at the front of the queue
++ * Only use with rt_mutex_waiter_{less,equal}()
 + */
-+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);
++#define task_to_waiter(p) &(struct rt_mutex_waiter) \
++      { .prio = (p)->prio, .deadline = (p)->dl.deadline, .task = (p) }
 +
-+int rt__down_read_trylock(struct rw_semaphore *rwsem)
+ 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)
 +{
-+      struct rt_mutex *lock = &rwsem->lock;
-+      int ret = 1;
++      if (left->prio != right->prio)
++              return 0;
 +
 +      /*
-+       * recursive read locks succeed when current owns the rwsem,
-+       * but not when read_depth == 0 which means that the rwsem is
-+       * write locked.
++       * 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 (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 (dl_prio(left->prio))
++              return left->deadline == right->deadline;
 +
-+      if (rt_mutex_owner(lock) != current)
-+              rt_mutex_lock(&rwsem->lock);
-+      rwsem->read_depth++;
++      return 1;
 +}
-+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);
-+}
++#define STEAL_NORMAL  0
++#define STEAL_LATERAL 1
 +
-+void  rt_down_read(struct rw_semaphore *rwsem)
++static inline int
++rt_mutex_steal(struct rt_mutex *lock, struct rt_mutex_waiter *waiter, int mode)
 +{
-+      __rt_down_read(rwsem, 0);
-+}
-+EXPORT_SYMBOL(rt_down_read);
++      struct rt_mutex_waiter *top_waiter = rt_mutex_top_waiter(lock);
 +
-+void  rt_down_read_nested(struct rw_semaphore *rwsem, int subclass)
-+{
-+      __rt_down_read(rwsem, subclass);
-+}
-+EXPORT_SYMBOL(rt_down_read_nested);
++      if (waiter == top_waiter || rt_mutex_waiter_less(waiter, top_waiter))
++              return 1;
 +
-+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:
++       * Note that RT tasks are excluded from lateral-steals
++       * to prevent the introduction of an unbounded latency.
 +       */
-+      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
-+ * @lock: the mutex to return holding if we dec to 0
-+ *
-+ * return true and hold lock if we dec to 0, return false otherwise
-+ */
-+int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock)
-+{
-+      /* dec if we can't possibly hit 0 */
-+      if (atomic_add_unless(cnt, -1, 1))
-+              return 0;
-+      /* we might hit 0, so take the lock */
-+      mutex_lock(lock);
-+      if (!atomic_dec_and_test(cnt)) {
-+              /* when we actually did the dec, we didn't hit 0 */
-+              mutex_unlock(lock);
++      if (mode == STEAL_NORMAL || rt_task(waiter->task))
 +              return 0;
-+      }
-+      /* we hit 0, and we hold the lock */
-+      return 1;
++
++      return rt_mutex_waiter_equal(waiter, top_waiter);
 +}
-+EXPORT_SYMBOL(atomic_dec_and_mutex_lock);
-diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
-index 2c49d76f96c3..4f1a7663c34d 100644
---- a/kernel/locking/rtmutex.c
-+++ b/kernel/locking/rtmutex.c
-@@ -7,6 +7,11 @@
-  *  Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
-  *  Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
-  *  Copyright (C) 2006 Esben Nielsen
-+ *  Adaptive Spinlocks:
-+ *  Copyright (C) 2008 Novell, Inc., Gregory Haskins, Sven Dietrich,
-+ *                                 and Peter Morreale,
-+ * Adaptive Spinlocks simplification:
-+ *  Copyright (C) 2008 Red Hat, Inc., Steven Rostedt <srostedt@redhat.com>
-  *
-  *  See Documentation/locking/rt-mutex-design.txt for details.
-  */
-@@ -16,6 +21,7 @@
- #include <linux/sched/rt.h>
- #include <linux/sched/deadline.h>
- #include <linux/timer.h>
-+#include <linux/ww_mutex.h>
++
+ 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);
+ }
  
- #include "rtmutex_common.h"
+-/*
+- * 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;
  
-@@ -133,6 +139,12 @@ static void fixup_rt_mutex_waiters(struct rt_mutex *lock)
-               WRITE_ONCE(*p, owner & ~RT_MUTEX_HAS_WAITERS);
+-      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;
+-      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.
-@@ -414,6 +426,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);
  }
  
@@ -13110,7 +14551,7 @@ index 2c49d76f96c3..4f1a7663c34d 100644
  /*
   * Max number of times we'll walk the boosting chain:
   */
-@@ -421,7 +441,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)
  {
@@ -13120,7 +14561,7 @@ index 2c49d76f96c3..4f1a7663c34d 100644
  }
  
  /*
-@@ -557,7 +578,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.
         */
@@ -13129,7 +14570,43 @@ index 2c49d76f96c3..4f1a7663c34d 100644
                goto out_unlock_pi;
  
        /*
-@@ -719,13 +740,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)) {
@@ -13148,35 +14625,37 @@ index 2c49d76f96c3..4f1a7663c34d 100644
                raw_spin_unlock_irq(&lock->wait_lock);
                return 0;
        }
-@@ -818,6 +842,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
   *
-@@ -828,8 +871,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)
@@ -13184,70 +14663,114 @@ index 2c49d76f96c3..4f1a7663c34d 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
-@@ -866,8 +910,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
-@@ -885,14 +931,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
-@@ -941,6 +983,433 @@ 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
 +/*
@@ -13258,7 +14781,8 @@ index 2c49d76f96c3..4f1a7663c34d 100644
 +                       struct task_struct *owner)
 +{
 +      int res = 0;
-+
+-      task->pi_blocked_on = waiter;
 +      rcu_read_lock();
 +      for (;;) {
 +              if (owner != rt_mutex_owner(lock))
@@ -13284,7 +14808,8 @@ index 2c49d76f96c3..4f1a7663c34d 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,
@@ -13303,44 +14828,85 @@ index 2c49d76f96c3..4f1a7663c34d 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();
@@ -13348,127 +14914,129 @@ index 2c49d76f96c3..4f1a7663c34d 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)
 +{
@@ -13477,7 +15045,8 @@ index 2c49d76f96c3..4f1a7663c34d 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 */
@@ -13485,7 +15054,8 @@ index 2c49d76f96c3..4f1a7663c34d 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 */
@@ -13495,17 +15065,6 @@ index 2c49d76f96c3..4f1a7663c34d 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);
@@ -13647,13 +15206,38 @@ index 2c49d76f96c3..4f1a7663c34d 100644
 +      return __try_to_take_rt_mutex(lock, task, waiter, STEAL_NORMAL);
 +}
 +
- /*
-  * Task blocks on lock.
-  *
-@@ -971,6 +1440,23 @@ static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
-               return -EDEADLK;
-       raw_spin_lock(&task->pi_lock);
++/*
++ * 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;
++
++      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
@@ -13671,64 +15255,173 @@ index 2c49d76f96c3..4f1a7663c34d 100644
 +
 +      BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on));
 +
-       __rt_mutex_adjust_prio(task);
-       waiter->task = task;
-       waiter->lock = lock;
-@@ -994,7 +1480,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;
-@@ -1036,6 +1522,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;
-@@ -1064,7 +1551,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);
- }
- /*
-@@ -1078,7 +1568,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);
-@@ -1102,7 +1592,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);
-@@ -1138,17 +1629,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;
        }
@@ -13742,7 +15435,20 @@ index 2c49d76f96c3..4f1a7663c34d 100644
        rt_mutex_adjust_prio_chain(task, RT_MUTEX_MIN_CHAINWALK, NULL,
                                   next_lock, NULL, task);
  }
-@@ -1166,7 +1657,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,
@@ -13752,23 +15458,45 @@ index 2c49d76f96c3..4f1a7663c34d 100644
  {
        int ret = 0;
  
-@@ -1189,6 +1681,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);
-@@ -1223,21 +1721,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)
 +{
@@ -13812,21 +15540,34 @@ index 2c49d76f96c3..4f1a7663c34d 100644
 +#ifdef CONFIG_PREEMPT_RT_FULL
 +static void ww_mutex_account_lock(struct rt_mutex *lock,
 +                                struct ww_acquire_ctx *ww_ctx)
-+{
-+      struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
+ {
+-      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 */
@@ -13845,44 +15586,36 @@ index 2c49d76f96c3..4f1a7663c34d 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
-@@ -1251,6 +1824,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;
        }
-@@ -1265,13 +1840,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);
@@ -13891,18 +15624,61 @@ index 2c49d76f96c3..4f1a7663c34d 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);
        }
  
        /*
-@@ -1331,7 +1916,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)
@@ -13911,16 +15687,31 @@ index 2c49d76f96c3..4f1a7663c34d 100644
  {
        unsigned long flags;
  
-@@ -1387,7 +1973,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);
  
-@@ -1403,31 +1989,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,
@@ -13931,13 +15722,23 @@ index 2c49d76f96c3..4f1a7663c34d 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
@@ -13952,16 +15753,45 @@ index 2c49d76f96c3..4f1a7663c34d 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
-@@ -1444,17 +2035,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,
@@ -13972,46 +15802,68 @@ index 2c49d76f96c3..4f1a7663c34d 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);
-+              wake_up_q_sleeper(&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();
  
-               /* Undo pi boosting if necessary: */
-               if (deboost)
-@@ -1471,7 +2065,7 @@ void __sched rt_mutex_lock(struct rt_mutex *lock)
- {
-       might_sleep();
+-              /* Undo pi boosting if necessary: */
+-              if (deboost)
+-                      rt_mutex_adjust_prio(current);
+-      }
++      return rt_mutex_fastlock(lock, state, NULL, rt_mutex_slowlock);
+ }
  
+ /**
+@@ -1469,15 +2059,13 @@ rt_mutex_fastunlock(struct rt_mutex *lock,
+  */
+ void __sched rt_mutex_lock(struct rt_mutex *lock)
+ {
+-      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);
  
-@@ -1488,7 +2082,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);
  
-@@ -1501,11 +2095,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
@@ -14020,21 +15872,29 @@ index 2c49d76f96c3..4f1a7663c34d 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
-@@ -1525,6 +2138,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,
@@ -14042,7 +15902,7 @@ index 2c49d76f96c3..4f1a7663c34d 100644
                                       rt_mutex_slowlock);
  }
  EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
-@@ -1542,7 +2156,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)
  {
@@ -14054,24 +15914,73 @@ index 2c49d76f96c3..4f1a7663c34d 100644
                return 0;
  
        return rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
-@@ -1568,13 +2186,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);
  }
  
  /**
-@@ -1607,13 +2226,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;
@@ -14086,7 +15995,7 @@ index 2c49d76f96c3..4f1a7663c34d 100644
  
  /**
   * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
-@@ -1628,7 +2246,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)
  {
@@ -14094,11 +16003,44 @@ index 2c49d76f96c3..4f1a7663c34d 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);
-@@ -1676,6 +2294,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.
@@ -14121,17 +16063,15 @@ index 2c49d76f96c3..4f1a7663c34d 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);
-@@ -1690,7 +2337,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;
        }
  
@@ -14139,20 +16079,165 @@ index 2c49d76f96c3..4f1a7663c34d 100644
 +      if (ret && rt_mutex_has_waiters(lock))
                remove_waiter(lock, waiter);
  
-       raw_spin_unlock_irq(&lock->wait_lock);
-@@ -1746,7 +2393,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);
-@@ -1761,3 +2408,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)
@@ -14186,106 +16271,418 @@ index 2c49d76f96c3..4f1a7663c34d 100644
 +{
 +      int ret;
 +
-+      might_sleep();
++      might_sleep();
++
++      mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
++      ret = rt_mutex_slowlock(&lock->base.lock, TASK_INTERRUPTIBLE, NULL, 0, ww_ctx);
++      if (ret)
++              mutex_release(&lock->base.dep_map, 1, _RET_IP_);
++      else if (!ret && ww_ctx->acquired > 1)
++              return ww_mutex_deadlock_injection(lock, ww_ctx);
++
++      return ret;
++}
++EXPORT_SYMBOL_GPL(__ww_mutex_lock_interruptible);
++
++int __sched
++__ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx)
++{
++      int ret;
++
++      might_sleep();
++
++      mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
++      ret = rt_mutex_slowlock(&lock->base.lock, TASK_UNINTERRUPTIBLE, NULL, 0, ww_ctx);
++      if (ret)
++              mutex_release(&lock->base.dep_map, 1, _RET_IP_);
++      else if (!ret && ww_ctx->acquired > 1)
++              return ww_mutex_deadlock_injection(lock, ww_ctx);
++
+       return ret;
+ }
++EXPORT_SYMBOL_GPL(__ww_mutex_lock);
++
++void __sched ww_mutex_unlock(struct ww_mutex *lock)
++{
++      int nest = !!lock->ctx;
++
++      /*
++       * The unlocking fastpath is the 0->1 transition from 'locked'
++       * into 'unlocked' state:
++       */
++      if (nest) {
++#ifdef CONFIG_DEBUG_MUTEXES
++              DEBUG_LOCKS_WARN_ON(!lock->ctx->acquired);
++#endif
++              if (lock->ctx->acquired > 0)
++                      lock->ctx->acquired--;
++              lock->ctx = NULL;
++      }
++
++      mutex_release(&lock->base.dep_map, nest, _RET_IP_);
++      rt_mutex_unlock(&lock->base.lock);
++}
++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 e317e1cbb3eb..64d89d780059 100644
+--- a/kernel/locking/rtmutex_common.h
++++ b/kernel/locking/rtmutex_common.h
+@@ -27,12 +27,14 @@ struct rt_mutex_waiter {
+       struct rb_node          pi_tree_entry;
+       struct task_struct      *task;
+       struct rt_mutex         *lock;
++      bool                    savestate;
+ #ifdef CONFIG_DEBUG_RT_MUTEXES
+       unsigned long           ip;
+       struct pid              *deadlock_task_pid;
+       struct rt_mutex         *deadlock_lock;
+ #endif
+       int prio;
++      u64 deadline;
+ };
+ /*
+@@ -98,21 +100,45 @@ enum rtmutex_chainwalk {
+ /*
+  * PI-futex support (proxy locking functions, etc.):
+  */
++#define PI_WAKEUP_INPROGRESS  ((struct rt_mutex_waiter *) 1)
++#define PI_REQUEUE_INPROGRESS ((struct rt_mutex_waiter *) 2)
++
+ 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);
+ 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);
+-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
+ # 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);
++              }
++      }
++}
 +
-+      mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
-+      ret = rt_mutex_slowlock(&lock->base.lock, TASK_INTERRUPTIBLE, NULL, 0, ww_ctx);
-+      if (ret)
-+              mutex_release(&lock->base.dep_map, 1, _RET_IP_);
-+      else if (!ret && ww_ctx->acquired > 1)
-+              return ww_mutex_deadlock_injection(lock, ww_ctx);
++void __sched __down_write(struct rw_semaphore *sem)
++{
++      __down_write_common(sem, TASK_UNINTERRUPTIBLE);
++}
 +
-+      return ret;
++int __sched __down_write_killable(struct rw_semaphore *sem)
++{
++      return __down_write_common(sem, TASK_KILLABLE);
 +}
-+EXPORT_SYMBOL_GPL(__ww_mutex_lock_interruptible);
 +
-+int __sched
-+__ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx)
++int __down_write_trylock(struct rw_semaphore *sem)
 +{
-+      int ret;
++      struct rt_mutex *m = &sem->rtmutex;
++      unsigned long flags;
 +
-+      might_sleep();
++      if (!rt_mutex_trylock(m))
++              return 0;
 +
-+      mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
-+      ret = rt_mutex_slowlock(&lock->base.lock, TASK_UNINTERRUPTIBLE, NULL, 0, ww_ctx);
-+      if (ret)
-+              mutex_release(&lock->base.dep_map, 1, _RET_IP_);
-+      else if (!ret && ww_ctx->acquired > 1)
-+              return ww_mutex_deadlock_injection(lock, ww_ctx);
++      atomic_sub(READER_BIAS, &sem->readers);
 +
-+      return ret;
++      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;
 +}
-+EXPORT_SYMBOL_GPL(__ww_mutex_lock);
 +
-+void __sched ww_mutex_unlock(struct ww_mutex *lock)
++void __up_write(struct rw_semaphore *sem)
 +{
-+      int nest = !!lock->ctx;
-+
-+      /*
-+       * The unlocking fastpath is the 0->1 transition from 'locked'
-+       * into 'unlocked' state:
-+       */
-+      if (nest) {
-+#ifdef CONFIG_DEBUG_MUTEXES
-+              DEBUG_LOCKS_WARN_ON(!lock->ctx->acquired);
-+#endif
-+              if (lock->ctx->acquired > 0)
-+                      lock->ctx->acquired--;
-+              lock->ctx = NULL;
-+      }
++      struct rt_mutex *m = &sem->rtmutex;
++      unsigned long flags;
 +
-+      mutex_release(&lock->base.dep_map, nest, _RET_IP_);
-+      rt_mutex_unlock(&lock->base.lock);
++      raw_spin_lock_irqsave(&m->wait_lock, flags);
++      __up_write_unlock(sem, WRITER_BIAS, flags);
 +}
-+EXPORT_SYMBOL(ww_mutex_unlock);
-+#endif
-diff --git a/kernel/locking/rtmutex_common.h b/kernel/locking/rtmutex_common.h
-index e317e1cbb3eb..f457c7574920 100644
---- a/kernel/locking/rtmutex_common.h
-+++ b/kernel/locking/rtmutex_common.h
-@@ -27,6 +27,7 @@ struct rt_mutex_waiter {
-       struct rb_node          pi_tree_entry;
-       struct task_struct      *task;
-       struct rt_mutex         *lock;
-+      bool                    savestate;
- #ifdef CONFIG_DEBUG_RT_MUTEXES
-       unsigned long           ip;
-       struct pid              *deadlock_task_pid;
-@@ -98,6 +99,9 @@ enum rtmutex_chainwalk {
- /*
-  * PI-futex support (proxy locking functions, etc.):
-  */
-+#define PI_WAKEUP_INPROGRESS  ((struct rt_mutex_waiter *) 1)
-+#define PI_REQUEUE_INPROGRESS ((struct rt_mutex_waiter *) 2)
 +
- 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);
-@@ -111,7 +115,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,
--                                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);
- #ifdef CONFIG_DEBUG_RT_MUTEXES
-@@ -120,4 +125,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)
++void __downgrade_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;
 +
- #endif
++      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
@@ -14321,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,
@@ -14340,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);
  }
  
@@ -14348,14 +16745,14 @@ 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..3483a3743b44 100644
+index 0e54d5bf0097..f27764fbfa24 100644
 --- a/kernel/module.c
 +++ b/kernel/module.c
 @@ -660,16 +660,7 @@ static void percpu_modcopy(struct module *mod,
@@ -14376,21 +16773,26 @@ index 0e54d5bf0097..3483a3743b44 100644
  {
        struct module *mod;
        unsigned int cpu;
-@@ -683,9 +674,11 @@ bool is_module_percpu_address(unsigned long addr)
+@@ -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);
-+                      void *va = (void *)addr;
+-
 -                      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)
++                              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 +689,20 @@ bool is_module_percpu_address(unsigned long addr)
+@@ -696,6 +693,20 @@ bool is_module_percpu_address(unsigned long addr)
        return false;
  }
  
@@ -14411,7 +16813,7 @@ index 0e54d5bf0097..3483a3743b44 100644
  #else /* ... !CONFIG_SMP */
  
  static inline void __percpu *mod_percpu(struct module *mod)
-@@ -727,6 +734,11 @@ bool is_module_percpu_address(unsigned long addr)
+@@ -727,6 +738,11 @@ bool is_module_percpu_address(unsigned long addr)
        return false;
  }
  
@@ -14424,7 +16826,7 @@ index 0e54d5bf0097..3483a3743b44 100644
  
  #define MODINFO_ATTR(field)   \
 diff --git a/kernel/panic.c b/kernel/panic.c
-index e6480e20379e..7e9c1918a94e 100644
+index dbec387099b1..b67a4803ff2b 100644
 --- a/kernel/panic.c
 +++ b/kernel/panic.c
 @@ -482,9 +482,11 @@ static u64 oops_id;
@@ -14835,10 +17237,10 @@ index 9c5b231684d0..cf15bdb6855b 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 49ba7c1ade9d..44f44b47ec07 100644
+index f39a7be98fc1..583ce3aad891 100644
 --- a/kernel/ptrace.c
 +++ b/kernel/ptrace.c
-@@ -166,7 +166,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)) {
@@ -14880,7 +17282,7 @@ index bf08fee53dc7..eeb8ce4ad7b6 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 10f62c6f48e7..dbee19478f09 100644
+index d1a02877a42c..a7b11a29e03a 100644
 --- a/kernel/rcu/tree.c
 +++ b/kernel/rcu/tree.c
 @@ -55,6 +55,11 @@
@@ -14987,7 +17389,7 @@ index 10f62c6f48e7..dbee19478f09 100644
        case RCU_SCHED_FLAVOR:
                rsp = &rcu_sched_state;
                break;
-@@ -3016,18 +3049,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.
   */
@@ -15008,7 +17410,7 @@ index 10f62c6f48e7..dbee19478f09 100644
  /*
   * Schedule RCU callback invocation.  If the specified type of RCU
   * does not support RCU priority boosting, just do a direct call,
-@@ -3039,19 +3071,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;
@@ -15018,8 +17420,8 @@ index 10f62c6f48e7..dbee19478f09 100644
 -      }
 -      invoke_rcu_callbacks_kthread();
 +      rcu_do_batch(rsp, rdp);
- }
++}
++
 +static void rcu_wake_cond(struct task_struct *t, int status)
 +{
 +      /*
@@ -15028,8 +17430,8 @@ index 10f62c6f48e7..dbee19478f09 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.
 + */
@@ -15048,8 +17450,8 @@ index 10f62c6f48e7..dbee19478f09 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;
@@ -15058,9 +17460,9 @@ index 10f62c6f48e7..dbee19478f09 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.
@@ -15119,10 +17521,11 @@ index 10f62c6f48e7..dbee19478f09 100644
 +}
 +early_initcall(rcu_spawn_core_kthreads);
 +
- /*
++/*
   * Handle any core-RCU processing required by a call_rcu() invocation.
   */
-@@ -3195,6 +3314,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);
  
@@ -15130,7 +17533,7 @@ index 10f62c6f48e7..dbee19478f09 100644
  /*
   * Queue an RCU callback for invocation after a quicker grace period.
   */
-@@ -3203,6 +3323,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);
@@ -15138,7 +17541,7 @@ index 10f62c6f48e7..dbee19478f09 100644
  
  /*
   * Queue an RCU callback for lazy invocation after a grace period.
-@@ -3294,6 +3415,7 @@ void synchronize_sched(void)
+@@ -3304,6 +3425,7 @@ void synchronize_sched(void)
  }
  EXPORT_SYMBOL_GPL(synchronize_sched);
  
@@ -15146,7 +17549,7 @@ index 10f62c6f48e7..dbee19478f09 100644
  /**
   * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
   *
-@@ -3320,6 +3442,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);
@@ -15154,7 +17557,7 @@ index 10f62c6f48e7..dbee19478f09 100644
  
  /**
   * get_state_synchronize_rcu - Snapshot current RCU state
-@@ -3698,6 +3821,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);
  }
  
@@ -15162,7 +17565,7 @@ index 10f62c6f48e7..dbee19478f09 100644
  /**
   * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
   */
-@@ -3706,6 +3830,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);
@@ -15170,7 +17573,7 @@ index 10f62c6f48e7..dbee19478f09 100644
  
  /**
   * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
-@@ -4227,12 +4352,13 @@ void __init rcu_init(void)
+@@ -4237,12 +4362,13 @@ void __init rcu_init(void)
  
        rcu_bootup_announce();
        rcu_init_geometry();
@@ -15223,7 +17626,7 @@ index e99a5234d9ed..958ac107062c 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 56583e764ebf..7c656f8e192f 100644
+index e3944c4b072d..be12d1aac840 100644
 --- a/kernel/rcu/tree_plugin.h
 +++ b/kernel/rcu/tree_plugin.h
 @@ -24,25 +24,10 @@
@@ -15653,7 +18056,7 @@ index 8d0f35debf35..b62cf6400fe0 100644
  }
  EXPORT_SYMBOL(completion_done);
 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
-index 154fd689fe02..a6aa5801b21e 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 =
@@ -15676,7 +18079,25 @@ index 154fd689fe02..a6aa5801b21e 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;
  }
  
@@ -15685,7 +18106,24 @@ index 154fd689fe02..a6aa5801b21e 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.
                 */
@@ -15697,7 +18135,7 @@ index 154fd689fe02..a6aa5801b21e 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);
  }
  
@@ -15736,7 +18174,7 @@ index 154fd689fe02..a6aa5801b21e 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)
  {
@@ -15753,7 +18191,7 @@ index 154fd689fe02..a6aa5801b21e 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();
@@ -15762,22 +18200,34 @@ index 154fd689fe02..a6aa5801b21e 100644
        return cpu;
  }
  /*
-@@ -1100,6 +1145,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);
-@@ -1122,6 +1172,84 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
-               set_curr_task(rq, p);
- }
 +static DEFINE_PER_CPU(struct cpumask, sched_cpumasks);
 +static DEFINE_MUTEX(sched_down_mutex);
 +static cpumask_t sched_down_cpumask;
@@ -15859,7 +18309,7 @@ index 154fd689fe02..a6aa5801b21e 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
-@@ -1179,7 +1307,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 */
@@ -15868,7 +18318,7 @@ index 154fd689fe02..a6aa5801b21e 100644
                goto out;
  
        dest_cpu = cpumask_any_and(cpu_valid_mask, new_mask);
-@@ -1366,6 +1494,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;
  }
  
@@ -15887,7 +18337,7 @@ index 154fd689fe02..a6aa5801b21e 100644
  /*
   * wait_task_inactive - wait for a thread to unschedule.
   *
-@@ -1410,7 +1550,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)) {
@@ -15896,7 +18346,7 @@ index 154fd689fe02..a6aa5801b21e 100644
                                return 0;
                        cpu_relax();
                }
-@@ -1425,7 +1565,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;
@@ -15906,7 +18356,7 @@ index 154fd689fe02..a6aa5801b21e 100644
                        ncsw = p->nvcsw | LONG_MIN; /* sets MSB */
                task_rq_unlock(rq, p, &rf);
  
-@@ -1680,10 +1821,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;
@@ -15917,7 +18367,7 @@ index 154fd689fe02..a6aa5801b21e 100644
  }
  
  /*
-@@ -2018,8 +2155,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);
@@ -15946,7 +18396,7 @@ index 154fd689fe02..a6aa5801b21e 100644
  
        trace_sched_waking(p);
  
-@@ -2102,53 +2258,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)
  }
  
  /**
@@ -16000,7 +18450,7 @@ index 154fd689fe02..a6aa5801b21e 100644
   * wake_up_process - Wake up a specific process
   * @p: The process to be woken up.
   *
-@@ -2166,6 +2275,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);
  
@@ -16013,13 +18463,13 @@ index 154fd689fe02..a6aa5801b21e 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);
-@@ -2442,6 +2563,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);
@@ -16029,7 +18479,7 @@ index 154fd689fe02..a6aa5801b21e 100644
  #ifdef CONFIG_SMP
        plist_node_init(&p->pushable_tasks, MAX_PRIO);
        RB_CLEAR_NODE(&p->pushable_dl_tasks);
-@@ -2770,21 +2894,16 @@ 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);
@@ -16056,7 +18506,7 @@ index 154fd689fe02..a6aa5801b21e 100644
                put_task_struct(prev);
        }
  
-@@ -3252,6 +3371,77 @@ static inline void schedule_debug(struct task_struct *prev)
+@@ -3252,6 +3393,114 @@ static inline void schedule_debug(struct task_struct *prev)
        schedstat_inc(this_rq()->sched_count);
  }
  
@@ -16124,6 +18574,43 @@ index 154fd689fe02..a6aa5801b21e 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();
@@ -16134,7 +18621,7 @@ index 154fd689fe02..a6aa5801b21e 100644
  /*
   * Pick up the highest-prio task:
   */
-@@ -3368,19 +3558,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;
@@ -16154,7 +18641,7 @@ index 154fd689fe02..a6aa5801b21e 100644
                }
                switch_count = &prev->nvcsw;
        }
-@@ -3390,6 +3567,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);
@@ -16162,7 +18649,7 @@ index 154fd689fe02..a6aa5801b21e 100644
        clear_preempt_need_resched();
        rq->clock_skip_update = 0;
  
-@@ -3437,9 +3615,20 @@ void __noreturn do_task_dead(void)
+@@ -3437,9 +3674,20 @@ void __noreturn do_task_dead(void)
  
  static inline void sched_submit_work(struct task_struct *tsk)
  {
@@ -16184,7 +18671,7 @@ index 154fd689fe02..a6aa5801b21e 100644
         * If we are going to sleep and we have plugged IO queued,
         * make sure to submit it to avoid deadlocks.
         */
-@@ -3447,6 +3636,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);
  }
  
@@ -16197,7 +18684,7 @@ index 154fd689fe02..a6aa5801b21e 100644
  asmlinkage __visible void __sched schedule(void)
  {
        struct task_struct *tsk = current;
-@@ -3457,6 +3652,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());
@@ -16205,7 +18692,7 @@ index 154fd689fe02..a6aa5801b21e 100644
  }
  EXPORT_SYMBOL(schedule);
  
-@@ -3520,6 +3716,30 @@ static void __sched notrace preempt_schedule_common(void)
+@@ -3520,6 +3775,30 @@ static void __sched notrace preempt_schedule_common(void)
        } while (need_resched());
  }
  
@@ -16236,7 +18723,7 @@ index 154fd689fe02..a6aa5801b21e 100644
  #ifdef CONFIG_PREEMPT
  /*
   * this is the entry point to schedule() from in-kernel preemption
-@@ -3534,7 +3754,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;
@@ -16246,7 +18733,7 @@ index 154fd689fe02..a6aa5801b21e 100644
        preempt_schedule_common();
  }
  NOKPROBE_SYMBOL(preempt_schedule);
-@@ -3561,6 +3782,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;
  
@@ -16256,7 +18743,7 @@ index 154fd689fe02..a6aa5801b21e 100644
        do {
                /*
                 * Because the function tracer can trace preempt_count_sub()
-@@ -3583,7 +3807,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();
@@ -16273,7 +18760,130 @@ index 154fd689fe02..a6aa5801b21e 100644
                exception_exit(prev_ctx);
  
                preempt_latency_stop(1);
-@@ -4939,6 +5172,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);
  
@@ -16281,7 +18891,7 @@ index 154fd689fe02..a6aa5801b21e 100644
  int __sched __cond_resched_softirq(void)
  {
        BUG_ON(!in_softirq());
-@@ -4952,6 +5186,7 @@ int __sched __cond_resched_softirq(void)
+@@ -4952,6 +5287,7 @@ int __sched __cond_resched_softirq(void)
        return 0;
  }
  EXPORT_SYMBOL(__cond_resched_softirq);
@@ -16289,7 +18899,7 @@ index 154fd689fe02..a6aa5801b21e 100644
  
  /**
   * yield - yield the current processor to other threads.
-@@ -5315,7 +5550,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);
@@ -16300,7 +18910,7 @@ index 154fd689fe02..a6aa5801b21e 100644
        /*
         * The idle tasks have their own, simple scheduling class:
         */
-@@ -5458,6 +5695,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
@@ -16309,8 +18919,8 @@ index 154fd689fe02..a6aa5801b21e 100644
  /*
   * Ensures that the idle task is using init_mm right before its cpu goes
   * offline.
-@@ -5472,7 +5711,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);
@@ -16323,7 +18933,15 @@ index 154fd689fe02..a6aa5801b21e 100644
  }
  
  /*
-@@ -7418,6 +7662,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);
@@ -16334,7 +18952,7 @@ index 154fd689fe02..a6aa5801b21e 100644
        return 0;
  }
  #endif
-@@ -7698,7 +7946,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)
  {
@@ -16344,7 +18962,7 @@ index 154fd689fe02..a6aa5801b21e 100644
        return (nested == preempt_offset);
  }
 diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
-index 37e2449186c4..e00accf92a4b 100644
+index c95c5122b105..e00accf92a4b 100644
 --- a/kernel/sched/deadline.c
 +++ b/kernel/sched/deadline.c
 @@ -687,6 +687,7 @@ void init_dl_task_timer(struct sched_dl_entity *dl_se)
@@ -16355,20 +18973,6 @@ index 37e2449186c4..e00accf92a4b 100644
  }
  
  static
-@@ -1729,12 +1730,11 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
- #ifdef CONFIG_SMP
-               if (tsk_nr_cpus_allowed(p) > 1 && rq->dl.overloaded)
-                       queue_push_tasks(rq);
--#else
-+#endif
-               if (dl_task(rq->curr))
-                       check_preempt_curr_dl(rq, p, 0);
-               else
-                       resched_curr(rq);
--#endif
-       }
- }
 diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
 index fa178b62ea79..935224123441 100644
 --- a/kernel/sched/debug.c
@@ -16395,7 +18999,7 @@ index fa178b62ea79..935224123441 100644
  #undef PN
  #undef __PN
 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
-index c242944f5cbd..4aeb2e2e41bc 100644
+index 7a68c631d5b5..f9189909640b 100644
 --- a/kernel/sched/fair.c
 +++ b/kernel/sched/fair.c
 @@ -3518,7 +3518,7 @@ check_preempt_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
@@ -16443,7 +19047,7 @@ index c242944f5cbd..4aeb2e2e41bc 100644
                        return;
                }
                hrtick_start(rq, delta);
-@@ -5905,7 +5905,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:
@@ -16452,7 +19056,7 @@ index c242944f5cbd..4aeb2e2e41bc 100644
        /*
         * Only set the backward buddy when the current task is still
         * on the rq. This can happen when a wakeup gets interleaved
-@@ -8631,7 +8631,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);
@@ -16461,7 +19065,7 @@ index c242944f5cbd..4aeb2e2e41bc 100644
        }
  
        se->vruntime -= cfs_rq->min_vruntime;
-@@ -8655,7 +8655,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)
@@ -16495,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 2516b8df6dbb..b0691f4e7d49 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)
@@ -16506,31 +19110,11 @@ index 2516b8df6dbb..b0691f4e7d49 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 */
-@@ -2198,10 +2200,9 @@ static void switched_to_rt(struct rq *rq, struct task_struct *p)
- #ifdef CONFIG_SMP
-               if (tsk_nr_cpus_allowed(p) > 1 && rq->rt.overloaded)
-                       queue_push_tasks(rq);
--#else
-+#endif /* CONFIG_SMP */
-               if (p->prio < rq->curr->prio)
-                       resched_curr(rq);
--#endif /* CONFIG_SMP */
-       }
- }
 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
-index 055f935d4421..19324ac27026 100644
+index cff985feb6e7..280c7d5a7657 100644
 --- a/kernel/sched/sched.h
 +++ b/kernel/sched/sched.h
-@@ -1163,6 +1163,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 */
@@ -16538,7 +19122,7 @@ index 055f935d4421..19324ac27026 100644
  
  /*
   * To aid in avoiding the subversion of "niceness" due to uneven distribution
-@@ -1346,6 +1347,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);
  
@@ -16779,7 +19363,7 @@ index 000000000000..1950f40ca725
 +}
 +EXPORT_SYMBOL_GPL(swork_put);
 diff --git a/kernel/signal.c b/kernel/signal.c
-index 75761acc77cf..ae0773c76bb0 100644
+index e48668c3c972..99918dcd836f 100644
 --- a/kernel/signal.c
 +++ b/kernel/signal.c
 @@ -14,6 +14,7 @@
@@ -16892,17 +19476,17 @@ index 75761acc77cf..ae0773c76bb0 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);
@@ -16910,7 +19494,7 @@ index 75761acc77cf..ae0773c76bb0 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.
   */
@@ -16921,7 +19505,7 @@ index 75761acc77cf..ae0773c76bb0 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;
  }
  
@@ -16961,7 +19545,7 @@ index 75761acc77cf..ae0773c76bb0 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.
                 */
@@ -16976,7 +19560,7 @@ index 75761acc77cf..ae0773c76bb0 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();
@@ -16985,7 +19569,7 @@ index 75761acc77cf..ae0773c76bb0 100644
        }
  
        return sighand;
-@@ -1485,7 +1578,8 @@ EXPORT_SYMBOL(kill_pid);
+@@ -1493,7 +1586,8 @@ EXPORT_SYMBOL(kill_pid);
   */
  struct sigqueue *sigqueue_alloc(void)
  {
@@ -16995,7 +19579,7 @@ index 75761acc77cf..ae0773c76bb0 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);
  
@@ -17865,12 +20449,11 @@ index 744fa611cae0..819bd7cf5ad0 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)) {
@@ -17884,7 +20467,8 @@ index 744fa611cae0..819bd7cf5ad0 100644
 -                      }
 -                      tasklet_unlock(t);
 -              }
--
++      local_irq_enable();
 -              local_irq_disable();
 -              t->next = NULL;
 -              *__this_cpu_read(tasklet_hi_vec.tail) = t;
@@ -17909,24 +20493,9 @@ index 744fa611cae0..819bd7cf5ad0 100644
        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();
 -}
@@ -17935,16 +20504,29 @@ index 744fa611cae0..819bd7cf5ad0 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();
  }
  
@@ -18081,7 +20663,7 @@ index ec9ab2f01489..8b89dbedeaff 100644
        }
  
 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
-index bb5ec425dfe0..8338b14ed3a3 100644
+index eeb7f2f5698d..369203af6406 100644
 --- a/kernel/time/hrtimer.c
 +++ b/kernel/time/hrtimer.c
 @@ -53,6 +53,7 @@
@@ -18092,7 +20674,7 @@ index bb5ec425dfe0..8338b14ed3a3 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);
  }
  
@@ -18122,7 +20704,7 @@ index bb5ec425dfe0..8338b14ed3a3 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);
  }
@@ -18130,7 +20712,7 @@ index bb5ec425dfe0..8338b14ed3a3 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) { }
@@ -18144,7 +20726,7 @@ index bb5ec425dfe0..8338b14ed3a3 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);
  
@@ -18177,7 +20759,7 @@ index bb5ec425dfe0..8338b14ed3a3 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;
  
@@ -18189,7 +20771,7 @@ index bb5ec425dfe0..8338b14ed3a3 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);
@@ -18206,7 +20788,7 @@ index bb5ec425dfe0..8338b14ed3a3 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;
@@ -18215,7 +20797,7 @@ index bb5ec425dfe0..8338b14ed3a3 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];
@@ -18223,7 +20805,7 @@ index bb5ec425dfe0..8338b14ed3a3 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 ||
@@ -18231,10 +20813,11 @@ index bb5ec425dfe0..8338b14ed3a3 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)
@@ -18336,7 +20919,7 @@ index bb5ec425dfe0..8338b14ed3a3 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;
@@ -18344,7 +20927,7 @@ index bb5ec425dfe0..8338b14ed3a3 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);
  
@@ -18360,7 +20943,7 @@ index bb5ec425dfe0..8338b14ed3a3 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;
  
@@ -18371,12 +20954,57 @@ index bb5ec425dfe0..8338b14ed3a3 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;
@@ -18397,7 +21025,7 @@ index bb5ec425dfe0..8338b14ed3a3 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);
  
@@ -18407,7 +21035,7 @@ index bb5ec425dfe0..8338b14ed3a3 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;
  }
  
@@ -18420,7 +21048,7 @@ index bb5ec425dfe0..8338b14ed3a3 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);
@@ -18429,7 +21057,7 @@ index bb5ec425dfe0..8338b14ed3a3 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;
  }
  
@@ -18442,7 +21070,7 @@ index bb5ec425dfe0..8338b14ed3a3 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);
  }
  
@@ -18469,7 +21097,7 @@ index bb5ec425dfe0..8338b14ed3a3 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);
@@ -18484,7 +21112,56 @@ index bb5ec425dfe0..8338b14ed3a3 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 */
  
@@ -18918,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();
@@ -19071,10 +21747,10 @@ index 3bcb61b52f6c..66d85482a96e 100644
  
        /* Get the next period (per-CPU) */
 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
-index 46e312e9be38..fa75cf5d9253 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)
  {
@@ -19102,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 c611c47de884..cdff4411f8f6 100644
+index 7d670362891a..31703677505f 100644
 --- a/kernel/time/timer.c
 +++ b/kernel/time/timer.c
 @@ -193,8 +193,11 @@ EXPORT_SYMBOL(jiffies_64);
@@ -19118,16 +21794,7 @@ index c611c47de884..cdff4411f8f6 100644
        unsigned long           clk;
        unsigned long           next_expiry;
        unsigned int            cpu;
-@@ -203,6 +206,8 @@ struct timer_base {
-       bool                    is_idle;
-       DECLARE_BITMAP(pending_map, WHEEL_SIZE);
-       struct hlist_head       vectors[WHEEL_SIZE];
-+      struct hlist_head       expired_lists[LVL_DEPTH];
-+      int                     expired_count;
- } ____cacheline_aligned;
- static DEFINE_PER_CPU(struct timer_base, timer_bases[NR_BASES]);
-@@ -948,10 +953,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);
@@ -19140,7 +21807,7 @@ index c611c47de884..cdff4411f8f6 100644
                }
                cpu_relax();
        }
-@@ -1023,9 +1028,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;
  
@@ -19151,8 +21818,8 @@ index c611c47de884..cdff4411f8f6 100644
 +                      raw_spin_lock(&base->lock);
                        WRITE_ONCE(timer->flags,
                                   (timer->flags & ~TIMER_BASEMASK) | base->cpu);
-               }
-@@ -1050,7 +1055,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:
@@ -19161,7 +21828,7 @@ index c611c47de884..cdff4411f8f6 100644
  
        return ret;
  }
-@@ -1144,19 +1149,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;
  
@@ -19173,6 +21840,7 @@ index c611c47de884..cdff4411f8f6 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);
@@ -19211,7 +21879,7 @@ index c611c47de884..cdff4411f8f6 100644
  /**
   * del_timer - deactive a timer.
   * @timer: the timer to be deactivated
-@@ -1180,7 +1212,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);
@@ -19220,7 +21888,7 @@ index c611c47de884..cdff4411f8f6 100644
        }
  
        return ret;
-@@ -1208,13 +1240,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);
        }
@@ -19236,7 +21904,7 @@ index c611c47de884..cdff4411f8f6 100644
  /**
   * del_timer_sync - deactivate a timer and wait for the handler to finish.
   * @timer: the timer to be deactivated
-@@ -1274,7 +1306,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;
@@ -19245,17 +21913,7 @@ index c611c47de884..cdff4411f8f6 100644
        }
  }
  EXPORT_SYMBOL(del_timer_sync);
-@@ -1323,7 +1355,8 @@ static void call_timer_fn(struct timer_list *timer, void (*fn)(unsigned long),
-       }
- }
--static void expire_timers(struct timer_base *base, struct hlist_head *head)
-+static inline void __expire_timers(struct timer_base *base,
-+                                 struct hlist_head *head)
- {
-       while (!hlist_empty(head)) {
-               struct timer_list *timer;
-@@ -1339,33 +1372,53 @@ 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;
  
@@ -19278,56 +21936,7 @@ index c611c47de884..cdff4411f8f6 100644
                }
        }
  }
--static int __collect_expired_timers(struct timer_base *base,
--                                  struct hlist_head *heads)
-+static void expire_timers(struct timer_base *base)
-+{
-+      struct hlist_head *head;
-+
-+      while (base->expired_count--) {
-+              head = base->expired_lists + base->expired_count;
-+              __expire_timers(base, head);
-+      }
-+      base->expired_count = 0;
-+}
-+
-+static void __collect_expired_timers(struct timer_base *base)
- {
-       unsigned long clk = base->clk;
-       struct hlist_head *vec;
--      int i, levels = 0;
-+      int i;
-       unsigned int idx;
-+      /*
-+       * expire_timers() must be called at least once before we can
-+       * collect more timers
-+       */
-+      if (WARN_ON(base->expired_count))
-+              return;
-+
-       for (i = 0; i < LVL_DEPTH; i++) {
-               idx = (clk & LVL_MASK) + i * LVL_SIZE;
-               if (__test_and_clear_bit(idx, base->pending_map)) {
-                       vec = base->vectors + idx;
--                      hlist_move_list(vec, heads++);
--                      levels++;
-+                      hlist_move_list(vec,
-+                              &base->expired_lists[base->expired_count++]);
-               }
-               /* Is it time to look at the next level? */
-               if (clk & LVL_CLK_MASK)
-@@ -1373,7 +1426,6 @@ static int __collect_expired_timers(struct timer_base *base,
-               /* Shift clock for the next level granularity */
-               clk >>= LVL_CLK_SHIFT;
-       }
--      return levels;
- }
- #ifdef CONFIG_NO_HZ_COMMON
-@@ -1515,7 +1567,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;
  
@@ -19336,81 +21945,16 @@ index c611c47de884..cdff4411f8f6 100644
        nextevt = __next_timer_interrupt(base);
        is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA);
        base->next_expiry = nextevt;
-@@ -1543,7 +1595,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);
  }
-@@ -1566,8 +1618,7 @@ void timer_clear_idle(void)
-       base->is_idle = false;
- }
--static int collect_expired_timers(struct timer_base *base,
--                                struct hlist_head *heads)
-+static void collect_expired_timers(struct timer_base *base)
- {
-       /*
-        * NOHZ optimization. After a long idle sleep we need to forward the
-@@ -1584,20 +1635,49 @@ static int collect_expired_timers(struct timer_base *base,
-               if (time_after(next, jiffies)) {
-                       /* The call site will increment clock! */
-                       base->clk = jiffies - 1;
--                      return 0;
-+                      return;
-               }
-               base->clk = next;
-       }
--      return __collect_expired_timers(base, heads);
-+      __collect_expired_timers(base);
- }
- #else
--static inline int collect_expired_timers(struct timer_base *base,
--                                       struct hlist_head *heads)
-+static inline void collect_expired_timers(struct timer_base *base)
- {
--      return __collect_expired_timers(base, heads);
-+      __collect_expired_timers(base);
- }
- #endif
-+static int find_expired_timers(struct timer_base *base)
-+{
-+      const unsigned long int end_clk = jiffies;
-+
-+      while (!base->expired_count && time_after_eq(end_clk, base->clk)) {
-+              collect_expired_timers(base);
-+              base->clk++;
-+      }
-+
-+      return base->expired_count;
-+}
-+
-+/* Called from CPU tick routine to quickly collect expired timers */
-+static int tick_find_expired(struct timer_base *base)
-+{
-+      int count;
-+
-+      raw_spin_lock(&base->lock);
-+
-+      if (unlikely(time_after(jiffies, base->clk + HZ))) {
-+              /* defer to ktimersoftd; don't spend too long in irq context */
-+              count = -1;
-+      } else
-+              count = find_expired_timers(base);
-+
-+      raw_spin_unlock(&base->lock);
-+
-+      return count;
-+}
-+
- /*
-  * Called from the timer interrupt handler to charge one tick to the current
-  * process.  user_tick is 1 if the tick is user time, 0 for system.
-@@ -1608,13 +1688,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);
@@ -19426,29 +21970,19 @@ index c611c47de884..cdff4411f8f6 100644
        run_posix_cpu_timers(p);
  }
  
-@@ -1624,24 +1704,13 @@ void update_process_times(int user_tick)
-  */
- static inline void __run_timers(struct timer_base *base)
- {
--      struct hlist_head heads[LVL_DEPTH];
--      int levels;
+@@ -1649,7 +1682,7 @@ static inline void __run_timers(struct timer_base *base)
+       if (!time_after_eq(jiffies, base->clk))
+               return;
+-      spin_lock_irq(&base->lock);
 +      raw_spin_lock_irq(&base->lock);
  
--      if (!time_after_eq(jiffies, base->clk))
--              return;
-+      while (find_expired_timers(base))
-+              expire_timers(base);
+       while (time_after_eq(jiffies, base->clk)) {
  
--      spin_lock_irq(&base->lock);
--
--      while (time_after_eq(jiffies, base->clk)) {
--
--              levels = collect_expired_timers(base, heads);
--              base->clk++;
--
--              while (levels--)
--                      expire_timers(base, heads + levels);
--      }
+@@ -1659,8 +1692,8 @@ static inline void __run_timers(struct timer_base *base)
+               while (levels--)
+                       expire_timers(base, heads + levels);
+       }
 -      base->running_timer = NULL;
 -      spin_unlock_irq(&base->lock);
 +      raw_spin_unlock_irq(&base->lock);
@@ -19456,31 +21990,16 @@ index c611c47de884..cdff4411f8f6 100644
  }
  
  /*
-@@ -1651,6 +1720,8 @@ static __latent_entropy 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]));
-@@ -1665,12 +1736,12 @@ void run_local_timers(void)
-       hrtimer_run_queues();
-       /* Raise the softirq only if required. */
--      if (time_before(jiffies, base->clk)) {
-+      if (time_before(jiffies, base->clk) || !tick_find_expired(base)) {
-               if (!IS_ENABLED(CONFIG_NO_HZ_COMMON) || !base->nohz_active)
-                       return;
-               /* CPU is awake, so check the deferrable base. */
-               base++;
--              if (time_before(jiffies, base->clk))
-+              if (time_before(jiffies, base->clk) || !tick_find_expired(base))
-                       return;
-       }
-       raise_softirq(TIMER_SOFTIRQ);
-@@ -1836,16 +1907,17 @@ 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.
                 */
@@ -19490,7 +22009,6 @@ index c611c47de884..cdff4411f8f6 100644
 +              raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
  
                BUG_ON(old_base->running_timer);
-+              BUG_ON(old_base->expired_count);
  
                for (i = 0; i < WHEEL_SIZE; i++)
                        migrate_timer_list(new_base, old_base->vectors + i);
@@ -19502,7 +22020,7 @@ index c611c47de884..cdff4411f8f6 100644
                put_cpu_ptr(&timer_bases);
        }
        return 0;
-@@ -1861,8 +1933,12 @@ 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;
@@ -19512,7 +22030,6 @@ index c611c47de884..cdff4411f8f6 100644
 +#ifdef CONFIG_PREEMPT_RT_FULL
 +              init_swait_queue_head(&base->wait_for_running_timer);
 +#endif
-+              base->expired_count = 0;
        }
  }
  
@@ -20845,7 +23362,7 @@ index 000000000000..7f6ee70dea41
 +
 +device_initcall(latency_hist_init);
 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
-index 8696ce6bf2f6..277f048a4695 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,
@@ -20859,7 +23376,7 @@ index 8696ce6bf2f6..277f048a4695 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) |
@@ -20869,7 +23386,7 @@ index 8696ce6bf2f6..277f048a4695 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)
  {
@@ -20895,7 +23412,7 @@ index 8696ce6bf2f6..277f048a4695 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"
@@ -20916,7 +23433,7 @@ index 8696ce6bf2f6..277f048a4695 100644
  
  void
 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
-index fd24b1f9ac43..852b2c81be25 100644
+index b0d8576c27ae..702b9376b278 100644
 --- a/kernel/trace/trace.h
 +++ b/kernel/trace/trace.h
 @@ -124,6 +124,7 @@ struct kretprobe_trace_entry_head {
@@ -21104,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 6d1020c03d41..70c6a2f79f7e 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,
-@@ -348,6 +350,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;
@@ -21130,7 +23658,7 @@ index 6d1020c03d41..70c6a2f79f7e 100644
  
                pr_emerg("Watchdog detected hard LOCKUP on cpu %d", this_cpu);
                print_modules();
-@@ -365,6 +374,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();
  
@@ -21138,16 +23666,8 @@ index 6d1020c03d41..70c6a2f79f7e 100644
                if (hardlockup_panic)
                        nmi_panic(regs, "Hard LOCKUP");
  
-@@ -512,6 +522,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 479d840db286..24eba6620a45 100644
+index 296dcca77f33..beee8ad4b9ea 100644
 --- a/kernel/workqueue.c
 +++ b/kernel/workqueue.c
 @@ -48,6 +48,8 @@
@@ -21159,7 +23679,7 @@ index 479d840db286..24eba6620a45 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.
   *
@@ -21177,7 +23697,7 @@ index 479d840db286..24eba6620a45 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.
   *
@@ -21204,7 +23724,7 @@ index 479d840db286..24eba6620a45 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);
  
@@ -21213,7 +23733,7 @@ index 479d840db286..24eba6620a45 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()                                    \
@@ -21240,7 +23760,7 @@ index 479d840db286..24eba6620a45 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
   *
@@ -21249,7 +23769,7 @@ index 479d840db286..24eba6620a45 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
   *
@@ -21258,7 +23778,7 @@ index 479d840db286..24eba6620a45 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
  
@@ -21290,7 +23810,7 @@ index 479d840db286..24eba6620a45 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
   *
@@ -21299,7 +23819,7 @@ index 479d840db286..24eba6620a45 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
@@ -21310,7 +23830,7 @@ index 479d840db286..24eba6620a45 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)
  {
@@ -21379,7 +23899,7 @@ index 479d840db286..24eba6620a45 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)
@@ -21419,7 +23939,7 @@ index 479d840db286..24eba6620a45 100644
  }
  
  /**
-@@ -1098,12 +1124,14 @@ static void put_pwq_unlocked(struct pool_workqueue *pwq)
+@@ -1099,12 +1125,14 @@ static void put_pwq_unlocked(struct pool_workqueue *pwq)
  {
        if (pwq) {
                /*
@@ -21437,7 +23957,7 @@ index 479d840db286..24eba6620a45 100644
        }
  }
  
-@@ -1207,7 +1235,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;
  
@@ -21446,7 +23966,7 @@ index 479d840db286..24eba6620a45 100644
  
        /* try to steal the timer if it exists */
        if (is_dwork) {
-@@ -1226,6 +1254,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;
  
@@ -21454,7 +23974,7 @@ index 479d840db286..24eba6620a45 100644
        /*
         * The queueing is in progress, or it is already queued. Try to
         * steal it from ->worklist without clearing WORK_STRUCT_PENDING.
-@@ -1264,14 +1293,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);
@@ -21473,7 +23993,7 @@ index 479d840db286..24eba6620a45 100644
        return -EAGAIN;
  }
  
-@@ -1373,7 +1404,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.
         */
@@ -21482,7 +24002,7 @@ index 479d840db286..24eba6620a45 100644
  
        debug_work_activate(work);
  
-@@ -1381,6 +1412,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;
@@ -21490,7 +24010,7 @@ index 479d840db286..24eba6620a45 100644
  retry:
        if (req_cpu == WORK_CPU_UNBOUND)
                cpu = wq_select_unbound_cpu(raw_smp_processor_id());
-@@ -1437,10 +1469,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);
  
@@ -21503,7 +24023,7 @@ index 479d840db286..24eba6620a45 100644
  
        pwq->nr_in_flight[pwq->work_color]++;
        work_flags = work_color_to_flags(pwq->work_color);
-@@ -1458,7 +1488,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);
  
@@ -21513,7 +24033,7 @@ index 479d840db286..24eba6620a45 100644
  }
  
  /**
-@@ -1478,14 +1510,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;
  
@@ -21530,7 +24050,7 @@ index 479d840db286..24eba6620a45 100644
        return ret;
  }
  EXPORT_SYMBOL(queue_work_on);
-@@ -1552,14 +1584,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() */
@@ -21547,7 +24067,7 @@ index 479d840db286..24eba6620a45 100644
        return ret;
  }
  EXPORT_SYMBOL(queue_delayed_work_on);
-@@ -1594,7 +1626,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);
@@ -21556,7 +24076,7 @@ index 479d840db286..24eba6620a45 100644
        }
  
        /* -ENOENT from try_to_grab_pending() becomes %true */
-@@ -1627,7 +1659,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 */
@@ -21566,7 +24086,7 @@ index 479d840db286..24eba6620a45 100644
  
        if (too_many_workers(pool) && !timer_pending(&pool->idle_timer))
                mod_timer(&pool->idle_timer, jiffies + IDLE_WORKER_TIMEOUT);
-@@ -1660,7 +1694,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--;
@@ -21576,7 +24096,7 @@ index 479d840db286..24eba6620a45 100644
  }
  
  static struct worker *alloc_worker(int node)
-@@ -1826,7 +1862,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--;
  
@@ -21586,7 +24106,7 @@ index 479d840db286..24eba6620a45 100644
        worker->flags |= WORKER_DIE;
        wake_up_process(worker->task);
  }
-@@ -2785,14 +2823,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();
  
@@ -21604,7 +24124,7 @@ index 479d840db286..24eba6620a45 100644
        /* see the comment in try_to_grab_pending() with the same code */
        pwq = get_work_pwq(work);
        if (pwq) {
-@@ -2821,10 +2859,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);
@@ -21617,7 +24137,7 @@ index 479d840db286..24eba6620a45 100644
        return false;
  }
  
-@@ -2911,7 +2950,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);
@@ -21626,7 +24146,7 @@ index 479d840db286..24eba6620a45 100644
  
        flush_work(work);
        clear_work_data(work);
-@@ -2966,10 +3005,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)
  {
@@ -21639,7 +24159,7 @@ index 479d840db286..24eba6620a45 100644
        return flush_work(&dwork->work);
  }
  EXPORT_SYMBOL(flush_delayed_work);
-@@ -2987,7 +3026,7 @@ static bool __cancel_work(struct work_struct *work, bool is_dwork)
+@@ -2981,7 +3020,7 @@ static bool __cancel_work(struct work_struct *work, bool is_dwork)
                return false;
  
        set_work_pool_and_clear_pending(work, get_work_pool_id(work));
@@ -21648,7 +24168,7 @@ index 479d840db286..24eba6620a45 100644
        return ret;
  }
  
-@@ -3245,7 +3284,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
   *
@@ -21657,7 +24177,7 @@ index 479d840db286..24eba6620a45 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().
-@@ -3299,8 +3338,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);
  
@@ -21668,7 +24188,7 @@ index 479d840db286..24eba6620a45 100644
  }
  
  /**
-@@ -3407,14 +3446,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);
  
@@ -21685,7 +24205,7 @@ index 479d840db286..24eba6620a45 100644
  }
  
  /**
-@@ -4064,7 +4103,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.
                 */
@@ -21694,7 +24214,7 @@ index 479d840db286..24eba6620a45 100644
        } else {
                /*
                 * We're the sole accessor of @wq at this point.  Directly
-@@ -4157,7 +4196,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;
  
@@ -21704,7 +24224,7 @@ index 479d840db286..24eba6620a45 100644
  
        if (cpu == WORK_CPU_UNBOUND)
                cpu = smp_processor_id();
-@@ -4168,7 +4208,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);
@@ -21714,7 +24234,7 @@ index 479d840db286..24eba6620a45 100644
  
        return ret;
  }
-@@ -4194,15 +4235,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;
  
@@ -21734,7 +24254,7 @@ index 479d840db286..24eba6620a45 100644
  
        return ret;
  }
-@@ -4391,7 +4432,7 @@ void show_workqueue_state(void)
+@@ -4399,7 +4440,7 @@ void show_workqueue_state(void)
        unsigned long flags;
        int pi;
  
@@ -21743,7 +24263,7 @@ index 479d840db286..24eba6620a45 100644
  
        pr_info("Showing busy workqueues and worker pools:\n");
  
-@@ -4444,7 +4485,7 @@ void show_workqueue_state(void)
+@@ -4452,7 +4493,7 @@ void show_workqueue_state(void)
                spin_unlock_irqrestore(&pool->lock, flags);
        }
  
@@ -21752,7 +24272,7 @@ index 479d840db286..24eba6620a45 100644
  }
  
  /*
-@@ -4782,16 +4823,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.
                 */
@@ -21772,7 +24292,7 @@ index 479d840db286..24eba6620a45 100644
        }
  out_unlock:
        mutex_unlock(&wq_pool_mutex);
-@@ -4981,7 +5022,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;
  
@@ -21782,7 +24302,7 @@ index 479d840db286..24eba6620a45 100644
        for_each_node(node) {
                written += scnprintf(buf + written, PAGE_SIZE - written,
                                     "%s%d:%d", delim, node,
-@@ -4989,7 +5031,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");
@@ -21793,10 +24313,10 @@ index 479d840db286..24eba6620a45 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 */
@@ -21804,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.
   */
@@ -22361,11 +24881,11 @@ index 1afec32de6f2..11fa431046a8 100644
        dump_stack();
 diff --git a/localversion-rt b/localversion-rt
 new file mode 100644
-index 000000000000..6e44e540b927
+index 000000000000..66fa05e70f29
 --- /dev/null
 +++ b/localversion-rt
 @@ -0,0 +1 @@
-+-rt12
++-rt60
 diff --git a/mm/Kconfig b/mm/Kconfig
 index 86e3e0e74d20..77e5862a1ed2 100644
 --- a/mm/Kconfig
@@ -22415,7 +24935,7 @@ index 70e6bec46dc2..6678ed58b7c6 100644
                                cc->last_migrated_pfn = 0;
                        }
 diff --git a/mm/filemap.c b/mm/filemap.c
-index d8d7df82c69a..0eac87a07892 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,
@@ -22475,7 +24995,7 @@ index 50b4ca6787f0..77518a3b35a1 100644
  unsigned int nr_free_highpages (void)
  {
 diff --git a/mm/memcontrol.c b/mm/memcontrol.c
-index 4c6ade54d833..ba29283aa43d 100644
+index 2a800c4a39bd..c04403033aec 100644
 --- a/mm/memcontrol.c
 +++ b/mm/memcontrol.c
 @@ -67,6 +67,7 @@
@@ -22495,67 +25015,7 @@ index 4c6ade54d833..ba29283aa43d 100644
  /* Whether legacy memory+swap accounting is active */
  static bool do_memsw_account(void)
  {
-@@ -1692,6 +1695,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);
- /**
-@@ -1714,7 +1718,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) {
-@@ -1722,7 +1726,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;
- }
-@@ -1749,13 +1753,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);
- }
- /*
-@@ -1767,7 +1771,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 */
-@@ -1776,7 +1780,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);
- }
- /*
-@@ -1792,7 +1796,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();
@@ -22564,7 +25024,7 @@ index 4c6ade54d833..ba29283aa43d 100644
        for_each_online_cpu(cpu) {
                struct memcg_stock_pcp *stock = &per_cpu(memcg_stock, cpu);
                struct mem_cgroup *memcg;
-@@ -1809,7 +1813,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);
                }
        }
@@ -22573,7 +25033,7 @@ index 4c6ade54d833..ba29283aa43d 100644
        put_online_cpus();
        mutex_unlock(&percpu_charge_mutex);
  }
-@@ -4548,12 +4552,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;
  
@@ -22588,7 +25048,7 @@ index 4c6ade54d833..ba29283aa43d 100644
  out_unlock:
        unlock_page(page);
  out:
-@@ -5428,10 +5432,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);
  
@@ -22601,7 +25061,7 @@ index 4c6ade54d833..ba29283aa43d 100644
  
        if (do_memsw_account() && PageSwapCache(page)) {
                swp_entry_t entry = { .val = page_private(page) };
-@@ -5487,14 +5491,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);
        }
  
@@ -22618,7 +25078,7 @@ index 4c6ade54d833..ba29283aa43d 100644
  
        if (!mem_cgroup_is_root(memcg))
                css_put_many(&memcg->css, nr_pages);
-@@ -5649,10 +5653,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);
  
@@ -22631,7 +25091,7 @@ index 4c6ade54d833..ba29283aa43d 100644
  }
  
  DEFINE_STATIC_KEY_FALSE(memcg_sockets_enabled_key);
-@@ -5832,6 +5836,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;
@@ -22639,7 +25099,7 @@ index 4c6ade54d833..ba29283aa43d 100644
  
        VM_BUG_ON_PAGE(PageLRU(page), page);
        VM_BUG_ON_PAGE(page_count(page), page);
-@@ -5872,12 +5877,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.
         */
@@ -22677,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 f4a02e240fb6..2e73f8cfde74 100644
+index fbc38888252b..1cb08e1406ea 100644
 --- a/mm/page_alloc.c
 +++ b/mm/page_alloc.c
 @@ -61,6 +61,7 @@
@@ -22707,7 +25167,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
  int page_group_by_mobility_disabled __read_mostly;
  
  #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
-@@ -1072,7 +1085,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 */
  
  /*
@@ -22716,7 +25176,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
   * Assumes all pages on list are in same zone, and of same order.
   * count is the number of pages to free.
   *
-@@ -1083,19 +1096,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,
@@ -22779,7 +25239,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
        while (count) {
                struct page *page;
                struct list_head *list;
-@@ -1111,7 +1163,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;
@@ -22788,7 +25248,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
                } while (list_empty(list));
  
                /* This is the only non-empty list. Free them all. */
-@@ -1119,27 +1171,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 {
@@ -22817,7 +25277,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
  }
  
  static void free_one_page(struct zone *zone,
-@@ -1148,7 +1185,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;
@@ -22828,7 +25288,7 @@ index f4a02e240fb6..2e73f8cfde74 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);
-@@ -1158,7 +1197,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);
@@ -22837,7 +25297,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
  }
  
  static void __meminit __init_single_page(struct page *page, unsigned long pfn,
-@@ -1244,10 +1283,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);
@@ -22850,7 +25310,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
  }
  
  static void __init __free_pages_boot_core(struct page *page, unsigned int order)
-@@ -2246,16 +2285,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;
@@ -22872,7 +25332,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
  }
  #endif
  
-@@ -2271,16 +2312,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;
@@ -22898,7 +25358,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
  }
  
  /*
-@@ -2366,8 +2412,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);
        }
@@ -22916,7 +25376,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
  }
  
  #ifdef CONFIG_HIBERNATION
-@@ -2427,7 +2482,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);
@@ -22925,7 +25385,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
        __count_vm_event(PGFREE);
  
        /*
-@@ -2453,12 +2508,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);
@@ -22945,7 +25405,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
  }
  
  /*
-@@ -2600,7 +2660,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;
  
@@ -22954,7 +25414,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
                do {
                        pcp = &this_cpu_ptr(zone->pageset)->pcp;
                        list = &pcp->lists[migratetype];
-@@ -2627,7 +2687,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));
@@ -22963,7 +25423,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
  
                do {
                        page = NULL;
-@@ -2639,22 +2699,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));
@@ -22992,7 +25452,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
        return NULL;
  }
  
-@@ -6531,7 +6593,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) {
@@ -23002,7 +25462,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
                drain_pages(cpu);
  
                /*
-@@ -6557,6 +6621,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);
@@ -23010,7 +25470,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
  }
  
  /*
-@@ -7385,7 +7450,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()  */
@@ -23019,7 +25479,7 @@ index f4a02e240fb6..2e73f8cfde74 100644
        if (zone->pageset != &boot_pageset) {
                for_each_online_cpu(cpu) {
                        pset = per_cpu_ptr(zone->pageset, cpu);
-@@ -7394,7 +7459,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;
        }
@@ -23029,62 +25489,73 @@ index f4a02e240fb6..2e73f8cfde74 100644
  
  #ifdef CONFIG_MEMORY_HOTREMOVE
 diff --git a/mm/percpu.c b/mm/percpu.c
-index 255714302394..59b529b944a9 100644
+index f014cebbf405..4e739fcf91bf 100644
 --- a/mm/percpu.c
 +++ b/mm/percpu.c
-@@ -1280,6 +1280,28 @@ void free_percpu(void __percpu *ptr)
+@@ -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;
-+      void __percpu *base = __addr_to_pcpu_ptr(pcpu_base_addr);
-+      unsigned int cpu;
-+
-+      for_each_possible_cpu(cpu) {
-+              void *start = per_cpu_ptr(base, cpu);
+ {
+ #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)
++                      if (can_addr) {
 +                              *can_addr = (unsigned long) (va - start);
-+                      return true;
++                              *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
-@@ -1293,20 +1315,7 @@ EXPORT_SYMBOL_GPL(free_percpu);
-  */
- bool is_kernel_percpu_address(unsigned long addr)
- {
--#ifdef CONFIG_SMP
--      const size_t static_size = __per_cpu_end - __per_cpu_start;
--      void __percpu *base = __addr_to_pcpu_ptr(pcpu_base_addr);
--      unsigned int cpu;
--
--      for_each_possible_cpu(cpu) {
--              void *start = per_cpu_ptr(base, cpu);
--
--              if ((void *)addr >= start && (void *)addr < start + static_size)
--                      return true;
--        }
--#endif
--      /* on UP, can't distinguish from other static vars, always false */
--      return false;
-+      return __is_kernel_percpu_address(addr, NULL);
+ #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 bc05fdc3edce..610cf61634f0 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,
@@ -23100,10 +25571,10 @@ index bc05fdc3edce..610cf61634f0 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 7aa0e97af928..35c873f09201 100644
+index edc79ca3c6d5..67eb368b9314 100644
 --- a/mm/slub.c
 +++ b/mm/slub.c
-@@ -1141,7 +1141,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;
  
@@ -23112,7 +25583,7 @@ index 7aa0e97af928..35c873f09201 100644
        slab_lock(page);
  
        if (s->flags & SLAB_CONSISTENCY_CHECKS) {
-@@ -1176,7 +1176,7 @@ static noinline int free_debug_processing(
+@@ -1179,7 +1179,7 @@ static noinline int free_debug_processing(
                         bulk_cnt, cnt);
  
        slab_unlock(page);
@@ -23121,7 +25592,7 @@ index 7aa0e97af928..35c873f09201 100644
        if (!ret)
                slab_fix(s, "Object at 0x%p not freed", object);
        return ret;
-@@ -1304,6 +1304,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 */
  
@@ -23134,7 +25605,7 @@ index 7aa0e97af928..35c873f09201 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;
@@ -23152,7 +25623,7 @@ index 7aa0e97af928..35c873f09201 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:
@@ -23161,7 +25632,7 @@ index 7aa0e97af928..35c873f09201 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);
  }
  
@@ -23178,7 +25649,7 @@ index 7aa0e97af928..35c873f09201 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);
@@ -23191,7 +25662,7 @@ index 7aa0e97af928..35c873f09201 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;
  
@@ -23200,7 +25671,7 @@ index 7aa0e97af928..35c873f09201 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;
  
        }
@@ -23209,7 +25680,7 @@ index 7aa0e97af928..35c873f09201 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
                         */
@@ -23218,7 +25689,7 @@ index 7aa0e97af928..35c873f09201 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.
                         */
@@ -23227,7 +25698,7 @@ index 7aa0e97af928..35c873f09201 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)
@@ -23236,7 +25707,7 @@ index 7aa0e97af928..35c873f09201 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)
@@ -23249,7 +25720,7 @@ index 7aa0e97af928..35c873f09201 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)
@@ -23258,7 +25729,7 @@ index 7aa0e97af928..35c873f09201 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) {
@@ -23280,7 +25751,7 @@ index 7aa0e97af928..35c873f09201 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)
  {
@@ -23303,7 +25774,7 @@ index 7aa0e97af928..35c873f09201 100644
  }
  
  /*
-@@ -2356,10 +2407,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;
  
@@ -23316,7 +25787,7 @@ index 7aa0e97af928..35c873f09201 100644
        return x;
  }
  #endif /* CONFIG_SLUB_DEBUG || CONFIG_SYSFS */
-@@ -2497,8 +2548,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,
@@ -23328,7 +25799,7 @@ index 7aa0e97af928..35c873f09201 100644
        void *freelist;
        struct page *page;
  
-@@ -2558,6 +2611,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);
@@ -23342,7 +25813,7 @@ index 7aa0e97af928..35c873f09201 100644
        return freelist;
  
  new_slab:
-@@ -2589,7 +2649,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;
@@ -23351,7 +25822,7 @@ index 7aa0e97af928..35c873f09201 100644
  }
  
  /*
-@@ -2601,6 +2661,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;
@@ -23359,7 +25830,7 @@ index 7aa0e97af928..35c873f09201 100644
  
        local_irq_save(flags);
  #ifdef CONFIG_PREEMPT
-@@ -2612,8 +2673,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
  
@@ -23370,7 +25841,7 @@ index 7aa0e97af928..35c873f09201 100644
        return p;
  }
  
-@@ -2799,7 +2861,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)) {
@@ -23379,7 +25850,7 @@ index 7aa0e97af928..35c873f09201 100644
                        n = NULL;
                }
                prior = page->freelist;
-@@ -2831,7 +2893,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.
                                 */
@@ -23388,7 +25859,7 @@ index 7aa0e97af928..35c873f09201 100644
  
                        }
                }
-@@ -2873,7 +2935,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);
        }
@@ -23397,7 +25868,7 @@ index 7aa0e97af928..35c873f09201 100644
        return;
  
  slab_empty:
-@@ -2888,7 +2950,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);
        }
  
@@ -23406,7 +25877,7 @@ index 7aa0e97af928..35c873f09201 100644
        stat(s, FREE_SLAB);
        discard_slab(s, page);
  }
-@@ -3093,6 +3155,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;
@@ -23414,7 +25885,7 @@ index 7aa0e97af928..35c873f09201 100644
        int i;
  
        /* memcg and kmem_cache debug support */
-@@ -3116,7 +3179,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,
@@ -23423,7 +25894,7 @@ index 7aa0e97af928..35c873f09201 100644
                        if (unlikely(!p[i]))
                                goto error;
  
-@@ -3128,6 +3191,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();
@@ -23431,7 +25902,7 @@ index 7aa0e97af928..35c873f09201 100644
  
        /* Clear memory outside IRQ disabled fastpath loop */
        if (unlikely(flags & __GFP_ZERO)) {
-@@ -3275,7 +3339,7 @@ static void
+@@ -3278,7 +3342,7 @@ static void
  init_kmem_cache_node(struct kmem_cache_node *n)
  {
        n->nr_partial = 0;
@@ -23440,7 +25911,7 @@ index 7aa0e97af928..35c873f09201 100644
        INIT_LIST_HEAD(&n->partial);
  #ifdef CONFIG_SLUB_DEBUG
        atomic_long_set(&n->nr_slabs, 0);
-@@ -3619,6 +3683,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
@@ -23451,7 +25922,7 @@ index 7aa0e97af928..35c873f09201 100644
        void *addr = page_address(page);
        void *p;
        unsigned long *map = kzalloc(BITS_TO_LONGS(page->objects) *
-@@ -3639,6 +3707,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
@@ -23459,7 +25930,7 @@ index 7aa0e97af928..35c873f09201 100644
  }
  
  /*
-@@ -3652,7 +3721,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());
@@ -23468,7 +25939,7 @@ index 7aa0e97af928..35c873f09201 100644
        list_for_each_entry_safe(page, h, &n->partial, lru) {
                if (!page->inuse) {
                        remove_partial(n, page);
-@@ -3662,7 +3731,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()");
                }
        }
@@ -23477,7 +25948,7 @@ index 7aa0e97af928..35c873f09201 100644
  
        list_for_each_entry_safe(page, h, &discard, lru)
                discard_slab(s, page);
-@@ -3920,7 +3989,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);
  
@@ -23486,7 +25957,7 @@ index 7aa0e97af928..35c873f09201 100644
  
                /*
                 * Build lists of slabs to discard or promote.
-@@ -3951,7 +4020,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);
  
@@ -23495,7 +25966,7 @@ index 7aa0e97af928..35c873f09201 100644
  
                /* Release empty slabs */
                list_for_each_entry_safe(page, t, &discard, lru)
-@@ -4127,6 +4196,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;
@@ -23508,7 +25979,7 @@ index 7aa0e97af928..35c873f09201 100644
  
        if (debug_guardpage_minorder())
                slub_max_order = 0;
-@@ -4335,7 +4410,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;
  
@@ -23517,7 +25988,7 @@ index 7aa0e97af928..35c873f09201 100644
  
        list_for_each_entry(page, &n->partial, lru) {
                validate_slab_slab(s, page, map);
-@@ -4357,7 +4432,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:
@@ -23526,7 +25997,7 @@ index 7aa0e97af928..35c873f09201 100644
        return count;
  }
  
-@@ -4545,12 +4620,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;
  
@@ -23747,7 +26218,7 @@ index 4dcf852e1e6d..69c3a5b24060 100644
        put_online_cpus();
        mutex_unlock(&lock);
 diff --git a/mm/truncate.c b/mm/truncate.c
-index 8d8c62d89e6d..5bf1bd25d077 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,
@@ -23766,10 +26237,10 @@ index 8d8c62d89e6d..5bf1bd25d077 100644
  unlock:
        spin_unlock_irq(&mapping->tree_lock);
 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
-index f2481cb4e6b2..db4de08fa97c 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;
@@ -23778,7 +26249,7 @@ index f2481cb4e6b2..db4de08fa97c 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();
  
@@ -23793,7 +26264,7 @@ index f2481cb4e6b2..db4de08fa97c 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;
@@ -23801,7 +26272,7 @@ index f2481cb4e6b2..db4de08fa97c 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();
@@ -23811,7 +26282,7 @@ index f2481cb4e6b2..db4de08fa97c 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;
        }
  
@@ -23921,7 +26392,7 @@ index 604f26a4f696..312006d2db50 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 fb1f9183d89a..7e6ef1a48cd3 100644
+index 4c4f05655e6e..b97b1e87b54c 100644
 --- a/mm/workingset.c
 +++ b/mm/workingset.c
 @@ -334,7 +334,8 @@ void workingset_activation(struct page *page)
@@ -23977,8 +26448,8 @@ index fb1f9183d89a..7e6ef1a48cd3 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);
@@ -23992,7 +26463,7 @@ index fb1f9183d89a..7e6ef1a48cd3 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 @@
@@ -24172,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 60b0a6049e72..660ca3b9c60b 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;
@@ -24276,7 +26794,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  }
  
  /**
-@@ -2258,6 +2264,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);
@@ -24284,7 +26802,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  }
  
  void __netif_schedule(struct Qdisc *q)
-@@ -2339,6 +2346,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);
@@ -24292,7 +26810,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  }
  EXPORT_SYMBOL(__dev_kfree_skb_irq);
  
-@@ -3073,7 +3081,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.
         */
@@ -24304,7 +26822,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
        if (unlikely(contended))
                spin_lock(&q->busylock);
  
-@@ -3136,8 +3148,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
  
@@ -24315,7 +26833,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  
  /**
   *    dev_loopback_xmit - loop back @skb
-@@ -3371,8 +3385,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) {
@@ -24325,7 +26843,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
                                goto recursion_alert;
  
                        skb = validate_xmit_skb(skb, dev);
-@@ -3382,9 +3395,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)) {
@@ -24337,7 +26855,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
                                if (dev_xmit_complete(rc)) {
                                        HARD_TX_UNLOCK(dev, txq);
                                        goto out;
-@@ -3758,6 +3771,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);
@@ -24345,7 +26863,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  
        atomic_long_inc(&skb->dev->rx_dropped);
        kfree_skb(skb);
-@@ -3776,7 +3790,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;
  
@@ -24354,7 +26872,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
                rcu_read_lock();
  
                cpu = get_rps_cpu(skb->dev, skb, &rflow);
-@@ -3786,13 +3800,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();
@@ -24371,7 +26889,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
        }
        return ret;
  }
-@@ -3826,11 +3840,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);
  
@@ -24385,7 +26903,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  
        return err;
  }
-@@ -4309,7 +4321,7 @@ static void flush_backlog(struct work_struct *work)
+@@ -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->reg_state == NETREG_UNREGISTERING) {
                        __skb_unlink(skb, &sd->input_pkt_queue);
@@ -24394,7 +26912,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
                        input_queue_head_incr(sd);
                }
        }
-@@ -4319,11 +4331,14 @@ static void flush_backlog(struct work_struct *work)
+@@ -4357,11 +4369,14 @@ static void flush_backlog(struct work_struct *work)
        skb_queue_walk_safe(&sd->process_queue, skb, tmp) {
                if (skb->dev->reg_state == NETREG_UNREGISTERING) {
                        __skb_unlink(skb, &sd->process_queue);
@@ -24410,7 +26928,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  }
  
  static void flush_all_backlogs(void)
-@@ -4804,6 +4819,7 @@ static void net_rps_action_and_irq_enable(struct softnet_data *sd)
+@@ -4852,6 +4867,7 @@ static void net_rps_action_and_irq_enable(struct softnet_data *sd)
                sd->rps_ipi_list = NULL;
  
                local_irq_enable();
@@ -24418,7 +26936,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  
                /* Send pending IPI's to kick RPS processing on remote cpus. */
                while (remsd) {
-@@ -4817,6 +4833,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();
@@ -24426,7 +26944,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  }
  
  static bool sd_has_rps_ipi_waiting(struct softnet_data *sd)
-@@ -4846,7 +4863,9 @@ static int process_backlog(struct napi_struct *napi, int quota)
+@@ -4894,7 +4911,9 @@ static int process_backlog(struct napi_struct *napi, int quota)
        while (again) {
                struct sk_buff *skb;
  
@@ -24436,7 +26954,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
                        rcu_read_lock();
                        __netif_receive_skb(skb);
                        rcu_read_unlock();
-@@ -4854,9 +4873,9 @@ static int process_backlog(struct napi_struct *napi, int quota)
+@@ -4902,9 +4921,9 @@ static int process_backlog(struct napi_struct *napi, int quota)
                        if (++work >= quota)
                                return work;
  
@@ -24447,7 +26965,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
                rps_lock(sd);
                if (skb_queue_empty(&sd->input_pkt_queue)) {
                        /*
-@@ -4894,9 +4913,11 @@ void __napi_schedule(struct napi_struct *n)
+@@ -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);
@@ -24459,7 +26977,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  /**
   * __napi_schedule_irqoff - schedule for receive
   * @n: entry to schedule
-@@ -4908,6 +4929,7 @@ void __napi_schedule_irqoff(struct napi_struct *n)
+@@ -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);
@@ -24467,7 +26985,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  
  void __napi_complete(struct napi_struct *n)
  {
-@@ -5197,13 +5219,21 @@ static __latent_entropy void net_rx_action(struct softirq_action *h)
+@@ -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;
@@ -24489,7 +27007,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
        for (;;) {
                struct napi_struct *n;
  
-@@ -5234,7 +5264,7 @@ static __latent_entropy void net_rx_action(struct softirq_action *h)
+@@ -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))
@@ -24498,7 +27016,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  
        net_rps_action_and_irq_enable(sd);
  }
-@@ -7995,16 +8025,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();
@@ -24520,7 +27038,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
  
        return NOTIFY_OK;
  }
-@@ -8309,8 +8343,9 @@ static int __init net_dev_init(void)
+@@ -8358,8 +8392,9 @@ static int __init net_dev_init(void)
  
                INIT_WORK(flush, flush_backlog);
  
@@ -24533,7 +27051,7 @@ index 60b0a6049e72..660ca3b9c60b 100644
                sd->output_queue_tailp = &sd->output_queue;
  #ifdef CONFIG_RPS
 diff --git a/net/core/filter.c b/net/core/filter.c
-index b391209838ef..b86e9681a88e 100644
+index 4eb4ce0aeef4..4f09d6a57217 100644
 --- a/net/core/filter.c
 +++ b/net/core/filter.c
 @@ -1645,7 +1645,7 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)
@@ -24624,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 1e3e0087245b..1077b39db717 100644
+index aec5605944d3..d4cb8bfdb83c 100644
 --- a/net/core/skbuff.c
 +++ b/net/core/skbuff.c
 @@ -64,6 +64,7 @@
@@ -24759,10 +27277,10 @@ index 1e3e0087245b..1077b39db717 100644
  void __kfree_skb_defer(struct sk_buff *skb)
  {
 diff --git a/net/core/sock.c b/net/core/sock.c
-index bc6543f7de36..2c32ee79620f 100644
+index e3b60460dc9c..8d15848c3a22 100644
 --- a/net/core/sock.c
 +++ b/net/core/sock.c
-@@ -2488,12 +2488,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;
@@ -24777,7 +27295,7 @@ index bc6543f7de36..2c32ee79620f 100644
  EXPORT_SYMBOL(lock_sock_nested);
  
 diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
-index 48734ee6293f..e6864ff11352 100644
+index 48734ee6293f..330224ef4174 100644
 --- a/net/ipv4/icmp.c
 +++ b/net/ipv4/icmp.c
 @@ -69,6 +69,7 @@
@@ -24805,11 +27323,15 @@ index 48734ee6293f..e6864ff11352 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))) {
@@ -24820,7 +27342,7 @@ index 48734ee6293f..e6864ff11352 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);
@@ -24828,7 +27350,7 @@ index 48734ee6293f..e6864ff11352 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;
  
@@ -24836,7 +27358,7 @@ index 48734ee6293f..e6864ff11352 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);
        }
@@ -24844,7 +27366,7 @@ index 48734ee6293f..e6864ff11352 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)
  }
  
  /*
@@ -24875,7 +27397,7 @@ index 48734ee6293f..e6864ff11352 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);
@@ -24888,7 +27410,7 @@ index 48734ee6293f..e6864ff11352 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 80bc36b25de2..215b90adfb05 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[] = {
@@ -24906,7 +27428,7 @@ index 80bc36b25de2..215b90adfb05 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 2259114c7242..829e60985a81 100644
+index d577ec07a0d8..3b7298459c87 100644
 --- a/net/ipv4/tcp_ipv4.c
 +++ b/net/ipv4/tcp_ipv4.c
 @@ -62,6 +62,7 @@
@@ -24917,7 +27439,7 @@ index 2259114c7242..829e60985a81 100644
  
  #include <net/net_namespace.h>
  #include <net/icmp.h>
-@@ -564,6 +565,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);
  
@@ -24925,44 +27447,44 @@ index 2259114c7242..829e60985a81 100644
  /*
   *    This routine will send an RST to the other tcp.
   *
-@@ -691,6 +693,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,
-@@ -700,6 +704,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:
-@@ -775,6 +780,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,
-@@ -783,6 +789,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 2384b4aae064..bf7ab51d7035 100644
+index 439e597fd374..ca0daeaff370 100644
 --- a/net/mac80211/rx.c
 +++ b/net/mac80211/rx.c
-@@ -4166,7 +4166,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);
  
@@ -24995,7 +27517,7 @@ index 004af030ef1a..b64f751bda45 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 34de326b4f09..fe9597af0840 100644
+index e7f6657269e0..f635b773d28f 100644
 --- a/net/packet/af_packet.c
 +++ b/net/packet/af_packet.c
 @@ -63,6 +63,7 @@
@@ -25060,10 +27582,10 @@ index 7d921e56e715..13df56a738e5 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 206dc24add3a..00ea9bde5bb3 100644
+index ea13df1be067..76c20745b502 100644
 --- a/net/sched/sch_api.c
 +++ b/net/sched/sch_api.c
-@@ -981,7 +981,7 @@ static struct Qdisc *qdisc_create(struct net_device *dev,
+@@ -980,7 +980,7 @@ static struct Qdisc *qdisc_create(struct net_device *dev,
                        rcu_assign_pointer(sch->stab, stab);
                }
                if (tca[TCA_RATE]) {
@@ -25073,7 +27595,7 @@ index 206dc24add3a..00ea9bde5bb3 100644
                        err = -EOPNOTSUPP;
                        if (sch->flags & TCQ_F_MQROOT)
 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
-index 6cfb6e9038c2..20727e1347de 100644
+index 9016c8baf2aa..d925f0e63679 100644
 --- a/net/sched/sch_generic.c
 +++ b/net/sched/sch_generic.c
 @@ -425,7 +425,11 @@ struct Qdisc noop_qdisc = {
@@ -25106,7 +27628,7 @@ index 6cfb6e9038c2..20727e1347de 100644
  
        sch->ops = ops;
        sch->enqueue = ops->enqueue;
-@@ -925,7 +937,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))
This page took 0.626057 seconds and 4 git commands to generate.