2008-12-18 22:13:24 +03:00
|
|
|
/*
|
|
|
|
* This file contains the routines for handling the MMU on those
|
|
|
|
* PowerPC implementations where the MMU is not using the hash
|
|
|
|
* table, such as 8xx, 4xx, BookE's etc...
|
|
|
|
*
|
|
|
|
* Copyright 2008 Ben Herrenschmidt <benh@kernel.crashing.org>
|
|
|
|
* IBM Corp.
|
|
|
|
*
|
|
|
|
* Derived from previous arch/powerpc/mm/mmu_context.c
|
|
|
|
* and arch/powerpc/include/asm/mmu_context.h
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
2008-12-18 22:13:29 +03:00
|
|
|
* TODO:
|
|
|
|
*
|
|
|
|
* - The global context lock will not scale very well
|
|
|
|
* - The maps should be dynamically allocated to allow for processors
|
|
|
|
* that support more PID bits at runtime
|
|
|
|
* - Implement flush_tlb_mm() by making the context stale and picking
|
|
|
|
* a new one
|
|
|
|
* - More aggressively clear stale map bits and maybe find some way to
|
|
|
|
* also clear mm->cpu_vm_mask bits when processes are migrated
|
2008-12-18 22:13:24 +03:00
|
|
|
*/
|
|
|
|
|
2009-11-04 16:39:52 +03:00
|
|
|
//#define DEBUG_MAP_CONSISTENCY
|
|
|
|
//#define DEBUG_CLAMP_LAST_CONTEXT 31
|
2009-07-24 03:15:10 +04:00
|
|
|
//#define DEBUG_HARDER
|
|
|
|
|
|
|
|
/* We don't use DEBUG because it tends to be compiled in always nowadays
|
|
|
|
* and this would generate way too much output
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG_HARDER
|
|
|
|
#define pr_hard(args...) printk(KERN_DEBUG args)
|
|
|
|
#define pr_hardcont(args...) printk(KERN_CONT args)
|
|
|
|
#else
|
|
|
|
#define pr_hard(args...) do { } while(0)
|
|
|
|
#define pr_hardcont(args...) do { } while(0)
|
|
|
|
#endif
|
2008-12-18 22:13:29 +03:00
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2008-12-18 22:13:24 +03:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/init.h>
|
2008-12-18 22:13:48 +03:00
|
|
|
#include <linux/spinlock.h>
|
2018-10-31 01:09:49 +03:00
|
|
|
#include <linux/memblock.h>
|
2008-12-18 22:13:48 +03:00
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/cpu.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2008-12-18 22:13:24 +03:00
|
|
|
|
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
#include "mmu_decl.h"
|
|
|
|
|
2018-03-21 17:07:51 +03:00
|
|
|
/*
|
|
|
|
* The MPC8xx has only 16 contexts. We rotate through them on each task switch.
|
|
|
|
* A better way would be to keep track of tasks that own contexts, and implement
|
|
|
|
* an LRU usage. That way very active tasks don't always have to pay the TLB
|
|
|
|
* reload overhead. The kernel pages are mapped shared, so the kernel can run on
|
|
|
|
* behalf of any task that makes a kernel entry. Shared does not mean they are
|
|
|
|
* not protected, just that the ASID comparison is not performed. -- Dan
|
|
|
|
*
|
|
|
|
* The IBM4xx has 256 contexts, so we can just rotate through these as a way of
|
|
|
|
* "switching" contexts. If the TID of the TLB is zero, the PID/TID comparison
|
|
|
|
* is disabled, so we can use a TID of zero to represent all kernel pages as
|
|
|
|
* shared among all contexts. -- Dan
|
|
|
|
*
|
|
|
|
* The IBM 47x core supports 16-bit PIDs, thus 65535 contexts. We should
|
|
|
|
* normally never have to steal though the facility is present if needed.
|
|
|
|
* -- BenH
|
|
|
|
*/
|
2018-03-21 17:07:47 +03:00
|
|
|
#define FIRST_CONTEXT 1
|
2018-03-21 17:07:51 +03:00
|
|
|
#ifdef DEBUG_CLAMP_LAST_CONTEXT
|
|
|
|
#define LAST_CONTEXT DEBUG_CLAMP_LAST_CONTEXT
|
|
|
|
#elif defined(CONFIG_PPC_8xx)
|
|
|
|
#define LAST_CONTEXT 16
|
|
|
|
#elif defined(CONFIG_PPC_47x)
|
|
|
|
#define LAST_CONTEXT 65535
|
|
|
|
#else
|
|
|
|
#define LAST_CONTEXT 255
|
|
|
|
#endif
|
2018-03-21 17:07:47 +03:00
|
|
|
|
2008-12-18 22:13:29 +03:00
|
|
|
static unsigned int next_context, nr_free_contexts;
|
2008-12-18 22:13:48 +03:00
|
|
|
static unsigned long *context_map;
|
2018-03-21 17:07:53 +03:00
|
|
|
#ifdef CONFIG_SMP
|
2008-12-18 22:13:48 +03:00
|
|
|
static unsigned long *stale_map[NR_CPUS];
|
2018-03-21 17:07:53 +03:00
|
|
|
#endif
|
2008-12-18 22:13:48 +03:00
|
|
|
static struct mm_struct **context_mm;
|
2010-02-18 05:22:39 +03:00
|
|
|
static DEFINE_RAW_SPINLOCK(context_lock);
|
2008-12-18 22:13:24 +03:00
|
|
|
|
2008-12-18 22:13:48 +03:00
|
|
|
#define CTX_MAP_SIZE \
|
2018-03-21 17:07:51 +03:00
|
|
|
(sizeof(unsigned long) * (LAST_CONTEXT / BITS_PER_LONG + 1))
|
2008-12-18 22:13:48 +03:00
|
|
|
|
|
|
|
|
2008-12-18 22:13:24 +03:00
|
|
|
/* Steal a context from a task that has one at the moment.
|
2008-12-18 22:13:29 +03:00
|
|
|
*
|
|
|
|
* This is used when we are running out of available PID numbers
|
|
|
|
* on the processors.
|
|
|
|
*
|
2008-12-18 22:13:24 +03:00
|
|
|
* This isn't an LRU system, it just frees up each context in
|
|
|
|
* turn (sort-of pseudo-random replacement :). This would be the
|
|
|
|
* place to implement an LRU scheme if anyone was motivated to do it.
|
|
|
|
* -- paulus
|
2008-12-18 22:13:29 +03:00
|
|
|
*
|
|
|
|
* For context stealing, we use a slightly different approach for
|
|
|
|
* SMP and UP. Basically, the UP one is simpler and doesn't use
|
|
|
|
* the stale map as we can just flush the local CPU
|
|
|
|
* -- benh
|
2008-12-18 22:13:24 +03:00
|
|
|
*/
|
2008-12-18 22:13:29 +03:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
static unsigned int steal_context_smp(unsigned int id)
|
2008-12-18 22:13:24 +03:00
|
|
|
{
|
|
|
|
struct mm_struct *mm;
|
2009-07-24 03:15:10 +04:00
|
|
|
unsigned int cpu, max, i;
|
2008-12-18 22:13:24 +03:00
|
|
|
|
2018-03-21 17:07:51 +03:00
|
|
|
max = LAST_CONTEXT - FIRST_CONTEXT;
|
2008-12-18 22:13:24 +03:00
|
|
|
|
2008-12-18 22:13:29 +03:00
|
|
|
/* Attempt to free next_context first and then loop until we manage */
|
|
|
|
while (max--) {
|
|
|
|
/* Pick up the victim mm */
|
|
|
|
mm = context_mm[id];
|
2008-12-18 22:13:24 +03:00
|
|
|
|
2008-12-18 22:13:29 +03:00
|
|
|
/* We have a candidate victim, check if it's active, on SMP
|
|
|
|
* we cannot steal active contexts
|
|
|
|
*/
|
|
|
|
if (mm->context.active) {
|
|
|
|
id++;
|
2018-03-21 17:07:51 +03:00
|
|
|
if (id > LAST_CONTEXT)
|
2018-03-21 17:07:47 +03:00
|
|
|
id = FIRST_CONTEXT;
|
2008-12-18 22:13:29 +03:00
|
|
|
continue;
|
|
|
|
}
|
2009-07-24 03:15:10 +04:00
|
|
|
pr_hardcont(" | steal %d from 0x%p", id, mm);
|
2008-12-18 22:13:29 +03:00
|
|
|
|
|
|
|
/* Mark this mm has having no context anymore */
|
|
|
|
mm->context.id = MMU_NO_CONTEXT;
|
|
|
|
|
2009-07-24 03:15:10 +04:00
|
|
|
/* Mark it stale on all CPUs that used this mm. For threaded
|
|
|
|
* implementations, we set it on all threads on each core
|
|
|
|
* represented in the mask. A future implementation will use
|
|
|
|
* a core map instead but this will do for now.
|
|
|
|
*/
|
|
|
|
for_each_cpu(cpu, mm_cpumask(mm)) {
|
2010-10-06 12:36:59 +04:00
|
|
|
for (i = cpu_first_thread_sibling(cpu);
|
2013-03-21 04:06:12 +04:00
|
|
|
i <= cpu_last_thread_sibling(cpu); i++) {
|
|
|
|
if (stale_map[i])
|
|
|
|
__set_bit(id, stale_map[i]);
|
|
|
|
}
|
2009-07-24 03:15:10 +04:00
|
|
|
cpu = i - 1;
|
|
|
|
}
|
2008-12-18 22:13:29 +03:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This will happen if you have more CPUs than available contexts,
|
|
|
|
* all we can do here is wait a bit and try again
|
|
|
|
*/
|
2010-02-18 05:22:39 +03:00
|
|
|
raw_spin_unlock(&context_lock);
|
2008-12-18 22:13:29 +03:00
|
|
|
cpu_relax();
|
2010-02-18 05:22:39 +03:00
|
|
|
raw_spin_lock(&context_lock);
|
2009-05-19 20:56:42 +04:00
|
|
|
|
|
|
|
/* This will cause the caller to try again */
|
|
|
|
return MMU_NO_CONTEXT;
|
2008-12-18 22:13:29 +03:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
static unsigned int steal_all_contexts(void)
|
|
|
|
{
|
|
|
|
struct mm_struct *mm;
|
2018-03-21 17:07:53 +03:00
|
|
|
#ifdef CONFIG_SMP
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
int cpu = smp_processor_id();
|
2018-03-21 17:07:53 +03:00
|
|
|
#endif
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
unsigned int id;
|
|
|
|
|
2018-03-21 17:07:51 +03:00
|
|
|
for (id = FIRST_CONTEXT; id <= LAST_CONTEXT; id++) {
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
/* Pick up the victim mm */
|
|
|
|
mm = context_mm[id];
|
|
|
|
|
|
|
|
pr_hardcont(" | steal %d from 0x%p", id, mm);
|
|
|
|
|
|
|
|
/* Mark this mm as having no context anymore */
|
|
|
|
mm->context.id = MMU_NO_CONTEXT;
|
2018-03-21 17:07:47 +03:00
|
|
|
if (id != FIRST_CONTEXT) {
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
context_mm[id] = NULL;
|
|
|
|
__clear_bit(id, context_map);
|
|
|
|
#ifdef DEBUG_MAP_CONSISTENCY
|
|
|
|
mm->context.active = 0;
|
|
|
|
#endif
|
|
|
|
}
|
2018-03-21 17:07:53 +03:00
|
|
|
#ifdef CONFIG_SMP
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
__clear_bit(id, stale_map[cpu]);
|
2018-03-21 17:07:53 +03:00
|
|
|
#endif
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Flush the TLB for all contexts (not to be used on SMP) */
|
|
|
|
_tlbil_all();
|
|
|
|
|
2018-03-21 17:07:51 +03:00
|
|
|
nr_free_contexts = LAST_CONTEXT - FIRST_CONTEXT;
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
|
2018-03-21 17:07:47 +03:00
|
|
|
return FIRST_CONTEXT;
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
}
|
|
|
|
|
2008-12-18 22:13:29 +03:00
|
|
|
/* Note that this will also be called on SMP if all other CPUs are
|
|
|
|
* offlined, which means that it may be called for cpu != 0. For
|
|
|
|
* this to work, we somewhat assume that CPUs that are onlined
|
|
|
|
* come up with a fully clean TLB (or are cleaned when offlined)
|
2008-12-18 22:13:24 +03:00
|
|
|
*/
|
2008-12-18 22:13:29 +03:00
|
|
|
static unsigned int steal_context_up(unsigned int id)
|
2008-12-18 22:13:24 +03:00
|
|
|
{
|
2008-12-18 22:13:29 +03:00
|
|
|
struct mm_struct *mm;
|
2018-03-21 17:07:53 +03:00
|
|
|
#ifdef CONFIG_SMP
|
2008-12-18 22:13:29 +03:00
|
|
|
int cpu = smp_processor_id();
|
2018-03-21 17:07:53 +03:00
|
|
|
#endif
|
2008-12-18 22:13:24 +03:00
|
|
|
|
2008-12-18 22:13:29 +03:00
|
|
|
/* Pick up the victim mm */
|
|
|
|
mm = context_mm[id];
|
|
|
|
|
2009-07-24 03:15:10 +04:00
|
|
|
pr_hardcont(" | steal %d from 0x%p", id, mm);
|
2008-12-18 22:13:24 +03:00
|
|
|
|
2008-12-18 22:13:29 +03:00
|
|
|
/* Flush the TLB for that context */
|
|
|
|
local_flush_tlb_mm(mm);
|
|
|
|
|
2009-05-24 19:33:34 +04:00
|
|
|
/* Mark this mm has having no context anymore */
|
|
|
|
mm->context.id = MMU_NO_CONTEXT;
|
|
|
|
|
2008-12-18 22:13:29 +03:00
|
|
|
/* XXX This clear should ultimately be part of local_flush_tlb_mm */
|
2018-03-21 17:07:53 +03:00
|
|
|
#ifdef CONFIG_SMP
|
2008-12-18 22:13:29 +03:00
|
|
|
__clear_bit(id, stale_map[cpu]);
|
2018-03-21 17:07:53 +03:00
|
|
|
#endif
|
2008-12-18 22:13:29 +03:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_MAP_CONSISTENCY
|
|
|
|
static void context_check_map(void)
|
|
|
|
{
|
|
|
|
unsigned int id, nrf, nact;
|
|
|
|
|
|
|
|
nrf = nact = 0;
|
2018-03-21 17:07:51 +03:00
|
|
|
for (id = FIRST_CONTEXT; id <= LAST_CONTEXT; id++) {
|
2008-12-18 22:13:29 +03:00
|
|
|
int used = test_bit(id, context_map);
|
|
|
|
if (!used)
|
|
|
|
nrf++;
|
|
|
|
if (used != (context_mm[id] != NULL))
|
|
|
|
pr_err("MMU: Context %d is %s and MM is %p !\n",
|
|
|
|
id, used ? "used" : "free", context_mm[id]);
|
|
|
|
if (context_mm[id] != NULL)
|
|
|
|
nact += context_mm[id]->context.active;
|
2008-12-18 22:13:24 +03:00
|
|
|
}
|
2008-12-18 22:13:29 +03:00
|
|
|
if (nrf != nr_free_contexts) {
|
|
|
|
pr_err("MMU: Free context count out of sync ! (%d vs %d)\n",
|
|
|
|
nr_free_contexts, nrf);
|
|
|
|
nr_free_contexts = nrf;
|
|
|
|
}
|
|
|
|
if (nact > num_online_cpus())
|
|
|
|
pr_err("MMU: More active contexts than CPUs ! (%d vs %d)\n",
|
|
|
|
nact, num_online_cpus());
|
2018-03-21 17:07:47 +03:00
|
|
|
if (FIRST_CONTEXT > 0 && !test_bit(0, context_map))
|
2008-12-18 22:13:48 +03:00
|
|
|
pr_err("MMU: Context 0 has been freed !!!\n");
|
2008-12-18 22:13:24 +03:00
|
|
|
}
|
2008-12-18 22:13:29 +03:00
|
|
|
#else
|
|
|
|
static void context_check_map(void) { }
|
|
|
|
#endif
|
2008-12-18 22:13:24 +03:00
|
|
|
|
2016-04-29 16:26:01 +03:00
|
|
|
void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next,
|
|
|
|
struct task_struct *tsk)
|
2008-12-18 22:13:24 +03:00
|
|
|
{
|
2018-03-21 17:07:53 +03:00
|
|
|
unsigned int id;
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
unsigned int i, cpu = smp_processor_id();
|
|
|
|
#endif
|
2008-12-18 22:13:29 +03:00
|
|
|
unsigned long *map;
|
2008-12-18 22:13:24 +03:00
|
|
|
|
2008-12-18 22:13:29 +03:00
|
|
|
/* No lockless fast path .. yet */
|
2010-02-18 05:22:39 +03:00
|
|
|
raw_spin_lock(&context_lock);
|
2008-12-18 22:13:29 +03:00
|
|
|
|
2009-07-24 03:15:10 +04:00
|
|
|
pr_hard("[%d] activating context for mm @%p, active=%d, id=%d",
|
|
|
|
cpu, next, next->context.active, next->context.id);
|
2008-12-18 22:13:29 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Mark us active and the previous one not anymore */
|
|
|
|
next->context.active++;
|
|
|
|
if (prev) {
|
2009-07-24 03:15:10 +04:00
|
|
|
pr_hardcont(" (old=0x%p a=%d)", prev, prev->context.active);
|
2008-12-18 22:13:29 +03:00
|
|
|
WARN_ON(prev->context.active < 1);
|
|
|
|
prev->context.active--;
|
|
|
|
}
|
2009-05-19 20:56:42 +04:00
|
|
|
|
|
|
|
again:
|
2008-12-18 22:13:29 +03:00
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
|
|
|
/* If we already have a valid assigned context, skip all that */
|
|
|
|
id = next->context.id;
|
2009-07-24 03:15:10 +04:00
|
|
|
if (likely(id != MMU_NO_CONTEXT)) {
|
|
|
|
#ifdef DEBUG_MAP_CONSISTENCY
|
|
|
|
if (context_mm[id] != next)
|
|
|
|
pr_err("MMU: mm 0x%p has id %d but context_mm[%d] says 0x%p\n",
|
|
|
|
next, id, id, context_mm[id]);
|
|
|
|
#endif
|
2008-12-18 22:13:29 +03:00
|
|
|
goto ctxt_ok;
|
2009-07-24 03:15:10 +04:00
|
|
|
}
|
2008-12-18 22:13:29 +03:00
|
|
|
|
|
|
|
/* We really don't have a context, let's try to acquire one */
|
|
|
|
id = next_context;
|
2018-03-21 17:07:51 +03:00
|
|
|
if (id > LAST_CONTEXT)
|
2018-03-21 17:07:47 +03:00
|
|
|
id = FIRST_CONTEXT;
|
2008-12-18 22:13:29 +03:00
|
|
|
map = context_map;
|
|
|
|
|
|
|
|
/* No more free contexts, let's try to steal one */
|
|
|
|
if (nr_free_contexts == 0) {
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
if (num_online_cpus() > 1) {
|
|
|
|
id = steal_context_smp(id);
|
2009-05-19 20:56:42 +04:00
|
|
|
if (id == MMU_NO_CONTEXT)
|
|
|
|
goto again;
|
2009-07-30 08:04:25 +04:00
|
|
|
goto stolen;
|
2008-12-18 22:13:29 +03:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_SMP */
|
2018-03-21 17:07:49 +03:00
|
|
|
if (IS_ENABLED(CONFIG_PPC_8xx))
|
powerpc/8xx: reduce pressure on TLB due to context switches
For nohash powerpc, when we run out of contexts, contexts are freed by stealing
used contexts in-turn. When a victim has been selected, the associated TLB
entries are freed using _tlbil_pid(). Unfortunatly, on the PPC 8xx, _tlbil_pid()
does a tlbia, hence flushes ALL TLB entries and not only the one linked to the
stolen context. Therefore, as implented today, at each task switch requiring a
new context, all entries are flushed.
This patch modifies the implementation so that when running out of contexts, all
contexts get freed at once, hence dividing the number of calls to tlbia by 16.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Scott Wood <scottwood@freescale.com>
2015-01-19 18:44:42 +03:00
|
|
|
id = steal_all_contexts();
|
|
|
|
else
|
|
|
|
id = steal_context_up(id);
|
2008-12-18 22:13:29 +03:00
|
|
|
goto stolen;
|
|
|
|
}
|
|
|
|
nr_free_contexts--;
|
|
|
|
|
|
|
|
/* We know there's at least one free context, try to find it */
|
|
|
|
while (__test_and_set_bit(id, map)) {
|
2018-03-21 17:07:51 +03:00
|
|
|
id = find_next_zero_bit(map, LAST_CONTEXT+1, id);
|
|
|
|
if (id > LAST_CONTEXT)
|
2018-03-21 17:07:47 +03:00
|
|
|
id = FIRST_CONTEXT;
|
2008-12-18 22:13:29 +03:00
|
|
|
}
|
|
|
|
stolen:
|
|
|
|
next_context = id + 1;
|
|
|
|
context_mm[id] = next;
|
|
|
|
next->context.id = id;
|
2009-07-24 03:15:10 +04:00
|
|
|
pr_hardcont(" | new id=%d,nrf=%d", id, nr_free_contexts);
|
2008-12-18 22:13:29 +03:00
|
|
|
|
|
|
|
context_check_map();
|
|
|
|
ctxt_ok:
|
|
|
|
|
|
|
|
/* If that context got marked stale on this CPU, then flush the
|
|
|
|
* local TLB for it and unmark it before we use it
|
|
|
|
*/
|
2018-03-21 17:07:53 +03:00
|
|
|
#ifdef CONFIG_SMP
|
2008-12-18 22:13:29 +03:00
|
|
|
if (test_bit(id, stale_map[cpu])) {
|
2009-07-24 03:15:10 +04:00
|
|
|
pr_hardcont(" | stale flush %d [%d..%d]",
|
2010-10-06 12:36:59 +04:00
|
|
|
id, cpu_first_thread_sibling(cpu),
|
|
|
|
cpu_last_thread_sibling(cpu));
|
2009-07-24 03:15:10 +04:00
|
|
|
|
2008-12-18 22:13:29 +03:00
|
|
|
local_flush_tlb_mm(next);
|
|
|
|
|
|
|
|
/* XXX This clear should ultimately be part of local_flush_tlb_mm */
|
2010-10-06 12:36:59 +04:00
|
|
|
for (i = cpu_first_thread_sibling(cpu);
|
|
|
|
i <= cpu_last_thread_sibling(cpu); i++) {
|
2013-03-21 04:06:12 +04:00
|
|
|
if (stale_map[i])
|
|
|
|
__clear_bit(id, stale_map[i]);
|
2009-08-05 07:33:32 +04:00
|
|
|
}
|
2008-12-18 22:13:29 +03:00
|
|
|
}
|
2018-03-21 17:07:53 +03:00
|
|
|
#endif
|
2008-12-18 22:13:29 +03:00
|
|
|
|
|
|
|
/* Flick the MMU and release lock */
|
2009-07-24 03:15:10 +04:00
|
|
|
pr_hardcont(" -> %d\n", id);
|
2008-12-18 22:13:29 +03:00
|
|
|
set_context(id, next->pgd);
|
2010-02-18 05:22:39 +03:00
|
|
|
raw_spin_unlock(&context_lock);
|
2008-12-18 22:13:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the context for a new address space.
|
|
|
|
*/
|
|
|
|
int init_new_context(struct task_struct *t, struct mm_struct *mm)
|
|
|
|
{
|
2009-07-24 03:15:10 +04:00
|
|
|
pr_hard("initing context for mm @%p\n", mm);
|
|
|
|
|
powerpc/mm/slice: Fix hugepage allocation at hint address on 8xx
On the 8xx, the page size is set in the PMD entry and applies to
all pages of the page table pointed by the said PMD entry.
When an app has some regular pages allocated (e.g. see below) and tries
to mmap() a huge page at a hint address covered by the same PMD entry,
the kernel accepts the hint allthough the 8xx cannot handle different
page sizes in the same PMD entry.
10000000-10001000 r-xp 00000000 00:0f 2597 /root/malloc
10010000-10011000 rwxp 00000000 00:0f 2597 /root/malloc
mmap(0x10080000, 524288, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS|0x40000, -1, 0) = 0x10080000
This results the app remaining forever in do_page_fault()/hugetlb_fault()
and when interrupting that app, we get the following warning:
[162980.035629] WARNING: CPU: 0 PID: 2777 at arch/powerpc/mm/hugetlbpage.c:354 hugetlb_free_pgd_range+0xc8/0x1e4
[162980.035699] CPU: 0 PID: 2777 Comm: malloc Tainted: G W 4.14.6 #85
[162980.035744] task: c67e2c00 task.stack: c668e000
[162980.035783] NIP: c000fe18 LR: c00e1eec CTR: c00f90c0
[162980.035830] REGS: c668fc20 TRAP: 0700 Tainted: G W (4.14.6)
[162980.035854] MSR: 00029032 <EE,ME,IR,DR,RI> CR: 24044224 XER: 20000000
[162980.036003]
[162980.036003] GPR00: c00e1eec c668fcd0 c67e2c00 00000010 c6869410 10080000 00000000 77fb4000
[162980.036003] GPR08: ffff0001 0683c001 00000000 ffffff80 44028228 10018a34 00004008 418004fc
[162980.036003] GPR16: c668e000 00040100 c668e000 c06c0000 c668fe78 c668e000 c6835ba0 c668fd48
[162980.036003] GPR24: 00000000 73ffffff 74000000 00000001 77fb4000 100fffff 10100000 10100000
[162980.036743] NIP [c000fe18] hugetlb_free_pgd_range+0xc8/0x1e4
[162980.036839] LR [c00e1eec] free_pgtables+0x12c/0x150
[162980.036861] Call Trace:
[162980.036939] [c668fcd0] [c00f0774] unlink_anon_vmas+0x1c4/0x214 (unreliable)
[162980.037040] [c668fd10] [c00e1eec] free_pgtables+0x12c/0x150
[162980.037118] [c668fd40] [c00eabac] exit_mmap+0xe8/0x1b4
[162980.037210] [c668fda0] [c0019710] mmput.part.9+0x20/0xd8
[162980.037301] [c668fdb0] [c001ecb0] do_exit+0x1f0/0x93c
[162980.037386] [c668fe00] [c001f478] do_group_exit+0x40/0xcc
[162980.037479] [c668fe10] [c002a76c] get_signal+0x47c/0x614
[162980.037570] [c668fe70] [c0007840] do_signal+0x54/0x244
[162980.037654] [c668ff30] [c0007ae8] do_notify_resume+0x34/0x88
[162980.037744] [c668ff40] [c000dae8] do_user_signal+0x74/0xc4
[162980.037781] Instruction dump:
[162980.037821] 7fdff378 81370000 54a3463a 80890020 7d24182e 7c841a14 712a0004 4082ff94
[162980.038014] 2f890000 419e0010 712a0ff0 408200e0 <0fe00000> 54a9000a 7f984840 419d0094
[162980.038216] ---[ end trace c0ceeca8e7a5800a ]---
[162980.038754] BUG: non-zero nr_ptes on freeing mm: 1
[162985.363322] BUG: non-zero nr_ptes on freeing mm: -1
In order to fix this, this patch uses the address space "slices"
implemented for BOOK3S/64 and enhanced to support PPC32 by the
preceding patch.
This patch modifies the context.id on the 8xx to be in the range
[1:16] instead of [0:15] in order to identify context.id == 0 as
not initialised contexts as done on BOOK3S
This patch activates CONFIG_PPC_MM_SLICES when CONFIG_HUGETLB_PAGE is
selected for the 8xx
Alltough we could in theory have as many slices as PMD entries, the
current slices implementation limits the number of low slices to 16.
This limitation is not preventing us to fix the initial issue allthough
it is suboptimal. It will be cured in a subsequent patch.
Fixes: 4b91428699477 ("powerpc/8xx: Implement support of hugepages")
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-02-22 17:27:26 +03:00
|
|
|
#ifdef CONFIG_PPC_MM_SLICES
|
|
|
|
/*
|
|
|
|
* We have MMU_NO_CONTEXT set to be ~0. Hence check
|
|
|
|
* explicitly against context.id == 0. This ensures that we properly
|
|
|
|
* initialize context slice details for newly allocated mm's (which will
|
|
|
|
* have id == 0) and don't alter context slice inherited via fork (which
|
|
|
|
* will have id != 0).
|
|
|
|
*/
|
|
|
|
if (mm->context.id == 0)
|
2018-03-07 04:37:09 +03:00
|
|
|
slice_init_new_context_exec(mm);
|
powerpc/mm/slice: Fix hugepage allocation at hint address on 8xx
On the 8xx, the page size is set in the PMD entry and applies to
all pages of the page table pointed by the said PMD entry.
When an app has some regular pages allocated (e.g. see below) and tries
to mmap() a huge page at a hint address covered by the same PMD entry,
the kernel accepts the hint allthough the 8xx cannot handle different
page sizes in the same PMD entry.
10000000-10001000 r-xp 00000000 00:0f 2597 /root/malloc
10010000-10011000 rwxp 00000000 00:0f 2597 /root/malloc
mmap(0x10080000, 524288, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS|0x40000, -1, 0) = 0x10080000
This results the app remaining forever in do_page_fault()/hugetlb_fault()
and when interrupting that app, we get the following warning:
[162980.035629] WARNING: CPU: 0 PID: 2777 at arch/powerpc/mm/hugetlbpage.c:354 hugetlb_free_pgd_range+0xc8/0x1e4
[162980.035699] CPU: 0 PID: 2777 Comm: malloc Tainted: G W 4.14.6 #85
[162980.035744] task: c67e2c00 task.stack: c668e000
[162980.035783] NIP: c000fe18 LR: c00e1eec CTR: c00f90c0
[162980.035830] REGS: c668fc20 TRAP: 0700 Tainted: G W (4.14.6)
[162980.035854] MSR: 00029032 <EE,ME,IR,DR,RI> CR: 24044224 XER: 20000000
[162980.036003]
[162980.036003] GPR00: c00e1eec c668fcd0 c67e2c00 00000010 c6869410 10080000 00000000 77fb4000
[162980.036003] GPR08: ffff0001 0683c001 00000000 ffffff80 44028228 10018a34 00004008 418004fc
[162980.036003] GPR16: c668e000 00040100 c668e000 c06c0000 c668fe78 c668e000 c6835ba0 c668fd48
[162980.036003] GPR24: 00000000 73ffffff 74000000 00000001 77fb4000 100fffff 10100000 10100000
[162980.036743] NIP [c000fe18] hugetlb_free_pgd_range+0xc8/0x1e4
[162980.036839] LR [c00e1eec] free_pgtables+0x12c/0x150
[162980.036861] Call Trace:
[162980.036939] [c668fcd0] [c00f0774] unlink_anon_vmas+0x1c4/0x214 (unreliable)
[162980.037040] [c668fd10] [c00e1eec] free_pgtables+0x12c/0x150
[162980.037118] [c668fd40] [c00eabac] exit_mmap+0xe8/0x1b4
[162980.037210] [c668fda0] [c0019710] mmput.part.9+0x20/0xd8
[162980.037301] [c668fdb0] [c001ecb0] do_exit+0x1f0/0x93c
[162980.037386] [c668fe00] [c001f478] do_group_exit+0x40/0xcc
[162980.037479] [c668fe10] [c002a76c] get_signal+0x47c/0x614
[162980.037570] [c668fe70] [c0007840] do_signal+0x54/0x244
[162980.037654] [c668ff30] [c0007ae8] do_notify_resume+0x34/0x88
[162980.037744] [c668ff40] [c000dae8] do_user_signal+0x74/0xc4
[162980.037781] Instruction dump:
[162980.037821] 7fdff378 81370000 54a3463a 80890020 7d24182e 7c841a14 712a0004 4082ff94
[162980.038014] 2f890000 419e0010 712a0ff0 408200e0 <0fe00000> 54a9000a 7f984840 419d0094
[162980.038216] ---[ end trace c0ceeca8e7a5800a ]---
[162980.038754] BUG: non-zero nr_ptes on freeing mm: 1
[162985.363322] BUG: non-zero nr_ptes on freeing mm: -1
In order to fix this, this patch uses the address space "slices"
implemented for BOOK3S/64 and enhanced to support PPC32 by the
preceding patch.
This patch modifies the context.id on the 8xx to be in the range
[1:16] instead of [0:15] in order to identify context.id == 0 as
not initialised contexts as done on BOOK3S
This patch activates CONFIG_PPC_MM_SLICES when CONFIG_HUGETLB_PAGE is
selected for the 8xx
Alltough we could in theory have as many slices as PMD entries, the
current slices implementation limits the number of low slices to 16.
This limitation is not preventing us to fix the initial issue allthough
it is suboptimal. It will be cured in a subsequent patch.
Fixes: 4b91428699477 ("powerpc/8xx: Implement support of hugepages")
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-02-22 17:27:26 +03:00
|
|
|
#endif
|
2008-12-18 22:13:29 +03:00
|
|
|
mm->context.id = MMU_NO_CONTEXT;
|
|
|
|
mm->context.active = 0;
|
2008-12-18 22:13:24 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We're finished using the context for an address space.
|
|
|
|
*/
|
|
|
|
void destroy_context(struct mm_struct *mm)
|
|
|
|
{
|
2009-06-02 22:53:37 +04:00
|
|
|
unsigned long flags;
|
2008-12-18 22:13:29 +03:00
|
|
|
unsigned int id;
|
|
|
|
|
|
|
|
if (mm->context.id == MMU_NO_CONTEXT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
WARN_ON(mm->context.active != 0);
|
|
|
|
|
2010-02-18 05:22:39 +03:00
|
|
|
raw_spin_lock_irqsave(&context_lock, flags);
|
2008-12-18 22:13:29 +03:00
|
|
|
id = mm->context.id;
|
|
|
|
if (id != MMU_NO_CONTEXT) {
|
|
|
|
__clear_bit(id, context_map);
|
|
|
|
mm->context.id = MMU_NO_CONTEXT;
|
|
|
|
#ifdef DEBUG_MAP_CONSISTENCY
|
|
|
|
mm->context.active = 0;
|
|
|
|
#endif
|
2009-05-19 20:56:42 +04:00
|
|
|
context_mm[id] = NULL;
|
2008-12-18 22:13:29 +03:00
|
|
|
nr_free_contexts++;
|
2008-12-18 22:13:24 +03:00
|
|
|
}
|
2010-02-18 05:22:39 +03:00
|
|
|
raw_spin_unlock_irqrestore(&context_lock, flags);
|
2008-12-18 22:13:24 +03:00
|
|
|
}
|
|
|
|
|
2008-12-18 22:13:48 +03:00
|
|
|
#ifdef CONFIG_SMP
|
2016-08-18 15:57:31 +03:00
|
|
|
static int mmu_ctx_cpu_prepare(unsigned int cpu)
|
2008-12-18 22:13:48 +03:00
|
|
|
{
|
|
|
|
/* We don't touch CPU 0 map, it's allocated at aboot and kept
|
|
|
|
* around forever
|
|
|
|
*/
|
2010-08-31 17:24:44 +04:00
|
|
|
if (cpu == boot_cpuid)
|
2016-08-18 15:57:31 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
pr_devel("MMU: Allocating stale context map for CPU %d\n", cpu);
|
|
|
|
stale_map[cpu] = kzalloc(CTX_MAP_SIZE, GFP_KERNEL);
|
|
|
|
return 0;
|
2008-12-18 22:13:48 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 15:57:31 +03:00
|
|
|
static int mmu_ctx_cpu_dead(unsigned int cpu)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
if (cpu == boot_cpuid)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pr_devel("MMU: Freeing stale context map for CPU %d\n", cpu);
|
|
|
|
kfree(stale_map[cpu]);
|
|
|
|
stale_map[cpu] = NULL;
|
|
|
|
|
|
|
|
/* We also clear the cpu_vm_mask bits of CPUs going away */
|
|
|
|
clear_tasks_mm_cpumask(cpu);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
2008-12-18 22:13:48 +03:00
|
|
|
|
|
|
|
#endif /* CONFIG_SMP */
|
2008-12-18 22:13:24 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the context management stuff.
|
|
|
|
*/
|
|
|
|
void __init mmu_context_init(void)
|
|
|
|
{
|
2008-12-18 22:13:29 +03:00
|
|
|
/* Mark init_mm as being active on all possible CPUs since
|
|
|
|
* we'll get called with prev == init_mm the first time
|
|
|
|
* we schedule on a given CPU
|
|
|
|
*/
|
|
|
|
init_mm.context.active = NR_CPUS;
|
|
|
|
|
2008-12-18 22:13:48 +03:00
|
|
|
/*
|
|
|
|
* Allocate the maps used by context management
|
|
|
|
*/
|
memblock: stop using implicit alignment to SMP_CACHE_BYTES
When a memblock allocation APIs are called with align = 0, the alignment
is implicitly set to SMP_CACHE_BYTES.
Implicit alignment is done deep in the memblock allocator and it can
come as a surprise. Not that such an alignment would be wrong even
when used incorrectly but it is better to be explicit for the sake of
clarity and the prinicple of the least surprise.
Replace all such uses of memblock APIs with the 'align' parameter
explicitly set to SMP_CACHE_BYTES and stop implicit alignment assignment
in the memblock internal allocation functions.
For the case when memblock APIs are used via helper functions, e.g. like
iommu_arena_new_node() in Alpha, the helper functions were detected with
Coccinelle's help and then manually examined and updated where
appropriate.
The direct memblock APIs users were updated using the semantic patch below:
@@
expression size, min_addr, max_addr, nid;
@@
(
|
- memblock_alloc_try_nid_raw(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_raw(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid_nopanic(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_nopanic(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, nid)
|
- memblock_alloc(size, 0)
+ memblock_alloc(size, SMP_CACHE_BYTES)
|
- memblock_alloc_raw(size, 0)
+ memblock_alloc_raw(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from(size, 0, min_addr)
+ memblock_alloc_from(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_nopanic(size, 0)
+ memblock_alloc_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low(size, 0)
+ memblock_alloc_low(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low_nopanic(size, 0)
+ memblock_alloc_low_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from_nopanic(size, 0, min_addr)
+ memblock_alloc_from_nopanic(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_node(size, 0, nid)
+ memblock_alloc_node(size, SMP_CACHE_BYTES, nid)
)
[mhocko@suse.com: changelog update]
[akpm@linux-foundation.org: coding-style fixes]
[rppt@linux.ibm.com: fix missed uses of implicit alignment]
Link: http://lkml.kernel.org/r/20181016133656.GA10925@rapoport-lnx
Link: http://lkml.kernel.org/r/1538687224-17535-1-git-send-email-rppt@linux.vnet.ibm.com
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Suggested-by: Michal Hocko <mhocko@suse.com>
Acked-by: Paul Burton <paul.burton@mips.com> [MIPS]
Acked-by: Michael Ellerman <mpe@ellerman.id.au> [powerpc]
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Richard Weinberger <richard@nod.at>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-31 01:09:57 +03:00
|
|
|
context_map = memblock_alloc(CTX_MAP_SIZE, SMP_CACHE_BYTES);
|
|
|
|
context_mm = memblock_alloc(sizeof(void *) * (LAST_CONTEXT + 1),
|
|
|
|
SMP_CACHE_BYTES);
|
2018-03-21 17:07:53 +03:00
|
|
|
#ifdef CONFIG_SMP
|
memblock: stop using implicit alignment to SMP_CACHE_BYTES
When a memblock allocation APIs are called with align = 0, the alignment
is implicitly set to SMP_CACHE_BYTES.
Implicit alignment is done deep in the memblock allocator and it can
come as a surprise. Not that such an alignment would be wrong even
when used incorrectly but it is better to be explicit for the sake of
clarity and the prinicple of the least surprise.
Replace all such uses of memblock APIs with the 'align' parameter
explicitly set to SMP_CACHE_BYTES and stop implicit alignment assignment
in the memblock internal allocation functions.
For the case when memblock APIs are used via helper functions, e.g. like
iommu_arena_new_node() in Alpha, the helper functions were detected with
Coccinelle's help and then manually examined and updated where
appropriate.
The direct memblock APIs users were updated using the semantic patch below:
@@
expression size, min_addr, max_addr, nid;
@@
(
|
- memblock_alloc_try_nid_raw(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_raw(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid_nopanic(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid_nopanic(size, SMP_CACHE_BYTES, min_addr, max_addr,
nid)
|
- memblock_alloc_try_nid(size, 0, min_addr, max_addr, nid)
+ memblock_alloc_try_nid(size, SMP_CACHE_BYTES, min_addr, max_addr, nid)
|
- memblock_alloc(size, 0)
+ memblock_alloc(size, SMP_CACHE_BYTES)
|
- memblock_alloc_raw(size, 0)
+ memblock_alloc_raw(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from(size, 0, min_addr)
+ memblock_alloc_from(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_nopanic(size, 0)
+ memblock_alloc_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low(size, 0)
+ memblock_alloc_low(size, SMP_CACHE_BYTES)
|
- memblock_alloc_low_nopanic(size, 0)
+ memblock_alloc_low_nopanic(size, SMP_CACHE_BYTES)
|
- memblock_alloc_from_nopanic(size, 0, min_addr)
+ memblock_alloc_from_nopanic(size, SMP_CACHE_BYTES, min_addr)
|
- memblock_alloc_node(size, 0, nid)
+ memblock_alloc_node(size, SMP_CACHE_BYTES, nid)
)
[mhocko@suse.com: changelog update]
[akpm@linux-foundation.org: coding-style fixes]
[rppt@linux.ibm.com: fix missed uses of implicit alignment]
Link: http://lkml.kernel.org/r/20181016133656.GA10925@rapoport-lnx
Link: http://lkml.kernel.org/r/1538687224-17535-1-git-send-email-rppt@linux.vnet.ibm.com
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Suggested-by: Michal Hocko <mhocko@suse.com>
Acked-by: Paul Burton <paul.burton@mips.com> [MIPS]
Acked-by: Michael Ellerman <mpe@ellerman.id.au> [powerpc]
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Richard Weinberger <richard@nod.at>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-31 01:09:57 +03:00
|
|
|
stale_map[boot_cpuid] = memblock_alloc(CTX_MAP_SIZE, SMP_CACHE_BYTES);
|
2008-12-18 22:13:48 +03:00
|
|
|
|
2016-08-18 15:57:31 +03:00
|
|
|
cpuhp_setup_state_nocalls(CPUHP_POWERPC_MMU_CTX_PREPARE,
|
|
|
|
"powerpc/mmu/ctx:prepare",
|
|
|
|
mmu_ctx_cpu_prepare, mmu_ctx_cpu_dead);
|
2008-12-18 22:13:48 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
printk(KERN_INFO
|
2009-03-19 22:34:13 +03:00
|
|
|
"MMU: Allocated %zu bytes of context maps for %d contexts\n",
|
2018-03-21 17:07:51 +03:00
|
|
|
2 * CTX_MAP_SIZE + (sizeof(void *) * (LAST_CONTEXT + 1)),
|
|
|
|
LAST_CONTEXT - FIRST_CONTEXT + 1);
|
2008-12-18 22:13:48 +03:00
|
|
|
|
2008-12-18 22:13:24 +03:00
|
|
|
/*
|
|
|
|
* Some processors have too few contexts to reserve one for
|
|
|
|
* init_mm, and require using context 0 for a normal task.
|
|
|
|
* Other processors reserve the use of context zero for the kernel.
|
2018-03-21 17:07:47 +03:00
|
|
|
* This code assumes FIRST_CONTEXT < 32.
|
2008-12-18 22:13:24 +03:00
|
|
|
*/
|
2018-03-21 17:07:47 +03:00
|
|
|
context_map[0] = (1 << FIRST_CONTEXT) - 1;
|
|
|
|
next_context = FIRST_CONTEXT;
|
2018-03-21 17:07:51 +03:00
|
|
|
nr_free_contexts = LAST_CONTEXT - FIRST_CONTEXT + 1;
|
2008-12-18 22:13:24 +03:00
|
|
|
}
|
|
|
|
|