void migrate_disable(void)
 {
-       if (current->migration_disabled++)
+       struct task_struct *p = current;
+
+       if (p->migration_disabled) {
+               p->migration_disabled++;
                return;
+       }
 
-       barrier();
+       preempt_disable();
+       this_rq()->nr_pinned++;
+       p->migration_disabled = 1;
+       preempt_enable();
 }
 EXPORT_SYMBOL_GPL(migrate_disable);
 
         */
        barrier();
        p->migration_disabled = 0;
+       this_rq()->nr_pinned--;
        preempt_enable();
 }
 EXPORT_SYMBOL_GPL(migrate_enable);
        return p->migration_disabled;
 }
 
+static inline bool rq_has_pinned_tasks(struct rq *rq)
+{
+       return rq->nr_pinned;
+}
+
 #endif
 
 /*
        return false;
 }
 
+static inline bool rq_has_pinned_tasks(struct rq *rq)
+{
+       return false;
+}
+
 #endif
 
 static void
         * Both the cpu-hotplug and stop task are in this case and are
         * required to complete the hotplug process.
         */
-       if (is_per_cpu_kthread(push_task)) {
+       if (is_per_cpu_kthread(push_task) || is_migration_disabled(push_task)) {
                /*
                 * If this is the idle task on the outgoing CPU try to wake
                 * up the hotplug control thread which might wait for the
                 * last task to vanish. The rcuwait_active() check is
                 * accurate here because the waiter is pinned on this CPU
                 * and can't obviously be running in parallel.
+                *
+                * On RT kernels this also has to check whether there are
+                * pinned and scheduled out tasks on the runqueue. They
+                * need to leave the migrate disabled section first.
                 */
-               if (!rq->nr_running && rcuwait_active(&rq->hotplug_wait)) {
+               if (!rq->nr_running && !rq_has_pinned_tasks(rq) &&
+                   rcuwait_active(&rq->hotplug_wait)) {
                        raw_spin_unlock(&rq->lock);
                        rcuwait_wake_up(&rq->hotplug_wait);
                        raw_spin_lock(&rq->lock);
 {
        struct rq *rq = this_rq();
 
-       rcuwait_wait_event(&rq->hotplug_wait, rq->nr_running == 1,
+       rcuwait_wait_event(&rq->hotplug_wait,
+                          rq->nr_running == 1 && !rq_has_pinned_tasks(rq),
                           TASK_UNINTERRUPTIBLE);
 }
 
        sched_tick_stop(cpu);
 
        rq_lock_irqsave(rq, &rf);
-       BUG_ON(rq->nr_running != 1);
+       BUG_ON(rq->nr_running != 1 || rq_has_pinned_tasks(rq));
        rq_unlock_irqrestore(rq, &rf);
 
        calc_load_migrate(rq);