This patch fixes a couple of issues that can happen as a result
of steal_context() dropping the context_lock when all possible
PIDs are ineligible for stealing (hopefully an extremely hard to
hit occurence).
This case exposes the possibility of a stale context_mm[] entry
to be seen since destroy_context() doesn't clear it and the free
map isn't re-tested. It also means steal_context() will not notice
a context freed while the lock was help, thus possibly trying to
steal a context when a free one was available.
This fixes it by always returning to the caller from steal_context
when it dropped the lock with a return value that causes the
caller to re-samble the number of free contexts, along with
properly clearing the context_mm[] array for destroyed contexts.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
struct mm_struct *mm;
unsigned int cpu, max;
struct mm_struct *mm;
unsigned int cpu, max;
max = last_context - first_context;
/* Attempt to free next_context first and then loop until we manage */
max = last_context - first_context;
/* Attempt to free next_context first and then loop until we manage */
spin_unlock(&context_lock);
cpu_relax();
spin_lock(&context_lock);
spin_unlock(&context_lock);
cpu_relax();
spin_lock(&context_lock);
+
+ /* This will cause the caller to try again */
+ return MMU_NO_CONTEXT;
}
#endif /* CONFIG_SMP */
}
#endif /* CONFIG_SMP */
WARN_ON(prev->context.active < 1);
prev->context.active--;
}
WARN_ON(prev->context.active < 1);
prev->context.active--;
}
#endif /* CONFIG_SMP */
/* If we already have a valid assigned context, skip all that */
#endif /* CONFIG_SMP */
/* If we already have a valid assigned context, skip all that */
#ifdef CONFIG_SMP
if (num_online_cpus() > 1) {
id = steal_context_smp(id);
#ifdef CONFIG_SMP
if (num_online_cpus() > 1) {
id = steal_context_smp(id);
+ if (id == MMU_NO_CONTEXT)
+ goto again;
}
#endif /* CONFIG_SMP */
id = steal_context_up(id);
}
#endif /* CONFIG_SMP */
id = steal_context_up(id);
mm->context.id = MMU_NO_CONTEXT;
#ifdef DEBUG_MAP_CONSISTENCY
mm->context.active = 0;
mm->context.id = MMU_NO_CONTEXT;
#ifdef DEBUG_MAP_CONSISTENCY
mm->context.active = 0;
nr_free_contexts++;
}
spin_unlock(&context_lock);
nr_free_contexts++;
}
spin_unlock(&context_lock);