2009-04-03 09:49:22 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*
|
2006-03-28 03:52:14 +08:00
|
|
|
* Copyright (C) 1999-2006 Helge Deller <deller@gmx.de> (07-13-1999)
|
2005-04-17 06:20:36 +08:00
|
|
|
* Copyright (C) 1999 SuSE GmbH Nuernberg
|
|
|
|
* Copyright (C) 2000 Philipp Rumpf (prumpf@tux.org)
|
|
|
|
*
|
|
|
|
* Cache and TLB management
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/pagemap.h>
|
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-21 05:22:52 +08:00
|
|
|
#include <linux/sched.h>
|
2017-02-09 01:51:31 +08:00
|
|
|
#include <linux/sched/mm.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/pdc.h>
|
|
|
|
#include <asm/cache.h>
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/processor.h>
|
2005-10-22 10:44:14 +08:00
|
|
|
#include <asm/sections.h>
|
2010-12-23 00:22:11 +08:00
|
|
|
#include <asm/shmparam.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-11 09:35:03 +08:00
|
|
|
int split_tlb __read_mostly;
|
|
|
|
int dcache_stride __read_mostly;
|
|
|
|
int icache_stride __read_mostly;
|
2005-04-17 06:20:36 +08:00
|
|
|
EXPORT_SYMBOL(dcache_stride);
|
|
|
|
|
2010-12-23 00:22:11 +08:00
|
|
|
void flush_dcache_page_asm(unsigned long phys_addr, unsigned long vaddr);
|
|
|
|
EXPORT_SYMBOL(flush_dcache_page_asm);
|
|
|
|
void flush_icache_page_asm(unsigned long phys_addr, unsigned long vaddr);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* On some machines (e.g. ones with the Merced bus), there can be
|
|
|
|
* only a single PxTLB broadcast at a time; this must be guaranteed
|
|
|
|
* by software. We put a spinlock around all TLB flushes to
|
|
|
|
* ensure this.
|
|
|
|
*/
|
|
|
|
DEFINE_SPINLOCK(pa_tlb_lock);
|
|
|
|
|
2006-01-11 09:35:03 +08:00
|
|
|
struct pdc_cache_info cache_info __read_mostly;
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifndef CONFIG_PA20
|
2006-01-11 09:35:03 +08:00
|
|
|
static struct pdc_btlb_info btlb_info __read_mostly;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
void
|
|
|
|
flush_data_cache(void)
|
|
|
|
{
|
2008-05-09 15:39:44 +08:00
|
|
|
on_each_cpu(flush_data_cache_local, NULL, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
void
|
|
|
|
flush_instruction_cache(void)
|
|
|
|
{
|
2008-05-09 15:39:44 +08:00
|
|
|
on_each_cpu(flush_instruction_cache_local, NULL, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
flush_cache_all_local(void)
|
|
|
|
{
|
2006-01-11 09:47:49 +08:00
|
|
|
flush_instruction_cache_local(NULL);
|
|
|
|
flush_data_cache_local(NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(flush_cache_all_local);
|
|
|
|
|
2013-07-24 00:27:52 +08:00
|
|
|
/* Virtual address of pfn. */
|
|
|
|
#define pfn_va(pfn) __va(PFN_PHYS(pfn))
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void
|
MM: Pass a PTE pointer to update_mmu_cache() rather than the PTE itself
On VIVT ARM, when we have multiple shared mappings of the same file
in the same MM, we need to ensure that we have coherency across all
copies. We do this via make_coherent() by making the pages
uncacheable.
This used to work fine, until we allowed highmem with highpte - we
now have a page table which is mapped as required, and is not available
for modification via update_mmu_cache().
Ralf Beache suggested getting rid of the PTE value passed to
update_mmu_cache():
On MIPS update_mmu_cache() calls __update_tlb() which walks pagetables
to construct a pointer to the pte again. Passing a pte_t * is much
more elegant. Maybe we might even replace the pte argument with the
pte_t?
Ben Herrenschmidt would also like the pte pointer for PowerPC:
Passing the ptep in there is exactly what I want. I want that
-instead- of the PTE value, because I have issue on some ppc cases,
for I$/D$ coherency, where set_pte_at() may decide to mask out the
_PAGE_EXEC.
So, pass in the mapped page table pointer into update_mmu_cache(), and
remove the PTE value, updating all implementations and call sites to
suit.
Includes a fix from Stephen Rothwell:
sparc: fix fallout from update_mmu_cache API change
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-12-19 00:40:18 +08:00
|
|
|
update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-07-24 00:27:52 +08:00
|
|
|
unsigned long pfn = pte_pfn(*ptep);
|
|
|
|
struct page *page;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-07-24 00:27:52 +08:00
|
|
|
/* We don't have pte special. As a result, we can be called with
|
|
|
|
an invalid pfn and we don't need to flush the kernel dcache page.
|
|
|
|
This occurs with FireGL card in C8000. */
|
|
|
|
if (!pfn_valid(pfn))
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-07-24 00:27:52 +08:00
|
|
|
page = pfn_to_page(pfn);
|
|
|
|
if (page_mapping(page) && test_bit(PG_dcache_dirty, &page->flags)) {
|
|
|
|
flush_kernel_dcache_page_addr(pfn_va(pfn));
|
2005-04-17 06:20:36 +08:00
|
|
|
clear_bit(PG_dcache_dirty, &page->flags);
|
2006-08-24 00:00:04 +08:00
|
|
|
} else if (parisc_requires_coherency())
|
2013-07-24 00:27:52 +08:00
|
|
|
flush_kernel_dcache_page_addr(pfn_va(pfn));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
show_cache_info(struct seq_file *m)
|
|
|
|
{
|
2006-06-15 04:26:25 +08:00
|
|
|
char buf[32];
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
seq_printf(m, "I-cache\t\t: %ld KB\n",
|
|
|
|
cache_info.ic_size/1024 );
|
2007-01-24 04:24:20 +08:00
|
|
|
if (cache_info.dc_loop != 1)
|
2006-06-15 04:26:25 +08:00
|
|
|
snprintf(buf, 32, "%lu-way associative", cache_info.dc_loop);
|
|
|
|
seq_printf(m, "D-cache\t\t: %ld KB (%s%s, %s)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
cache_info.dc_size/1024,
|
|
|
|
(cache_info.dc_conf.cc_wt ? "WT":"WB"),
|
|
|
|
(cache_info.dc_conf.cc_sh ? ", shared I/D":""),
|
2006-06-15 04:26:25 +08:00
|
|
|
((cache_info.dc_loop == 1) ? "direct mapped" : buf));
|
2005-04-17 06:20:36 +08:00
|
|
|
seq_printf(m, "ITLB entries\t: %ld\n" "DTLB entries\t: %ld%s\n",
|
|
|
|
cache_info.it_size,
|
|
|
|
cache_info.dt_size,
|
|
|
|
cache_info.dt_conf.tc_sh ? " - shared with ITLB":""
|
|
|
|
);
|
|
|
|
|
|
|
|
#ifndef CONFIG_PA20
|
|
|
|
/* BTLB - Block TLB */
|
|
|
|
if (btlb_info.max_size==0) {
|
|
|
|
seq_printf(m, "BTLB\t\t: not supported\n" );
|
|
|
|
} else {
|
|
|
|
seq_printf(m,
|
|
|
|
"BTLB fixed\t: max. %d pages, pagesize=%d (%dMB)\n"
|
|
|
|
"BTLB fix-entr.\t: %d instruction, %d data (%d combined)\n"
|
|
|
|
"BTLB var-entr.\t: %d instruction, %d data (%d combined)\n",
|
|
|
|
btlb_info.max_size, (int)4096,
|
|
|
|
btlb_info.max_size>>8,
|
|
|
|
btlb_info.fixed_range_info.num_i,
|
|
|
|
btlb_info.fixed_range_info.num_d,
|
|
|
|
btlb_info.fixed_range_info.num_comb,
|
|
|
|
btlb_info.variable_range_info.num_i,
|
|
|
|
btlb_info.variable_range_info.num_d,
|
|
|
|
btlb_info.variable_range_info.num_comb
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init
|
|
|
|
parisc_cache_init(void)
|
|
|
|
{
|
|
|
|
if (pdc_cache_info(&cache_info) < 0)
|
|
|
|
panic("parisc_cache_init: pdc_cache_info failed");
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
printk("ic_size %lx dc_size %lx it_size %lx\n",
|
|
|
|
cache_info.ic_size,
|
|
|
|
cache_info.dc_size,
|
|
|
|
cache_info.it_size);
|
|
|
|
|
|
|
|
printk("DC base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx\n",
|
|
|
|
cache_info.dc_base,
|
|
|
|
cache_info.dc_stride,
|
|
|
|
cache_info.dc_count,
|
|
|
|
cache_info.dc_loop);
|
|
|
|
|
|
|
|
printk("dc_conf = 0x%lx alias %d blk %d line %d shift %d\n",
|
|
|
|
*(unsigned long *) (&cache_info.dc_conf),
|
|
|
|
cache_info.dc_conf.cc_alias,
|
|
|
|
cache_info.dc_conf.cc_block,
|
|
|
|
cache_info.dc_conf.cc_line,
|
|
|
|
cache_info.dc_conf.cc_shift);
|
2006-06-15 04:26:25 +08:00
|
|
|
printk(" wt %d sh %d cst %d hv %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
cache_info.dc_conf.cc_wt,
|
|
|
|
cache_info.dc_conf.cc_sh,
|
|
|
|
cache_info.dc_conf.cc_cst,
|
2006-06-15 04:26:25 +08:00
|
|
|
cache_info.dc_conf.cc_hv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
printk("IC base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx\n",
|
|
|
|
cache_info.ic_base,
|
|
|
|
cache_info.ic_stride,
|
|
|
|
cache_info.ic_count,
|
|
|
|
cache_info.ic_loop);
|
|
|
|
|
2015-11-26 05:43:45 +08:00
|
|
|
printk("IT base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx off_base 0x%lx off_stride 0x%lx off_count 0x%lx\n",
|
|
|
|
cache_info.it_sp_base,
|
|
|
|
cache_info.it_sp_stride,
|
|
|
|
cache_info.it_sp_count,
|
|
|
|
cache_info.it_loop,
|
|
|
|
cache_info.it_off_base,
|
|
|
|
cache_info.it_off_stride,
|
|
|
|
cache_info.it_off_count);
|
|
|
|
|
|
|
|
printk("DT base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx off_base 0x%lx off_stride 0x%lx off_count 0x%lx\n",
|
|
|
|
cache_info.dt_sp_base,
|
|
|
|
cache_info.dt_sp_stride,
|
|
|
|
cache_info.dt_sp_count,
|
|
|
|
cache_info.dt_loop,
|
|
|
|
cache_info.dt_off_base,
|
|
|
|
cache_info.dt_off_stride,
|
|
|
|
cache_info.dt_off_count);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("ic_conf = 0x%lx alias %d blk %d line %d shift %d\n",
|
|
|
|
*(unsigned long *) (&cache_info.ic_conf),
|
|
|
|
cache_info.ic_conf.cc_alias,
|
|
|
|
cache_info.ic_conf.cc_block,
|
|
|
|
cache_info.ic_conf.cc_line,
|
|
|
|
cache_info.ic_conf.cc_shift);
|
2006-06-15 04:26:25 +08:00
|
|
|
printk(" wt %d sh %d cst %d hv %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
cache_info.ic_conf.cc_wt,
|
|
|
|
cache_info.ic_conf.cc_sh,
|
|
|
|
cache_info.ic_conf.cc_cst,
|
2006-06-15 04:26:25 +08:00
|
|
|
cache_info.ic_conf.cc_hv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-11-26 05:43:45 +08:00
|
|
|
printk("D-TLB conf: sh %d page %d cst %d aid %d sr %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
cache_info.dt_conf.tc_sh,
|
|
|
|
cache_info.dt_conf.tc_page,
|
|
|
|
cache_info.dt_conf.tc_cst,
|
|
|
|
cache_info.dt_conf.tc_aid,
|
2015-11-26 05:43:45 +08:00
|
|
|
cache_info.dt_conf.tc_sr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-11-26 05:43:45 +08:00
|
|
|
printk("I-TLB conf: sh %d page %d cst %d aid %d sr %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
cache_info.it_conf.tc_sh,
|
|
|
|
cache_info.it_conf.tc_page,
|
|
|
|
cache_info.it_conf.tc_cst,
|
|
|
|
cache_info.it_conf.tc_aid,
|
2015-11-26 05:43:45 +08:00
|
|
|
cache_info.it_conf.tc_sr);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
split_tlb = 0;
|
|
|
|
if (cache_info.dt_conf.tc_sh == 0 || cache_info.dt_conf.tc_sh == 2) {
|
|
|
|
if (cache_info.dt_conf.tc_sh == 2)
|
|
|
|
printk(KERN_WARNING "Unexpected TLB configuration. "
|
|
|
|
"Will flush I/D separately (could be optimized).\n");
|
|
|
|
|
|
|
|
split_tlb = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "New and Improved" version from Jim Hull
|
|
|
|
* (1 << (cc_block-1)) * (cc_line << (4 + cnf.cc_shift))
|
2005-10-22 10:44:14 +08:00
|
|
|
* The following CAFL_STRIDE is an optimized version, see
|
|
|
|
* http://lists.parisc-linux.org/pipermail/parisc-linux/2004-June/023625.html
|
|
|
|
* http://lists.parisc-linux.org/pipermail/parisc-linux/2004-June/023671.html
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
#define CAFL_STRIDE(cnf) (cnf.cc_line << (3 + cnf.cc_block + cnf.cc_shift))
|
|
|
|
dcache_stride = CAFL_STRIDE(cache_info.dc_conf);
|
|
|
|
icache_stride = CAFL_STRIDE(cache_info.ic_conf);
|
|
|
|
#undef CAFL_STRIDE
|
|
|
|
|
|
|
|
#ifndef CONFIG_PA20
|
|
|
|
if (pdc_btlb_info(&btlb_info) < 0) {
|
|
|
|
memset(&btlb_info, 0, sizeof btlb_info);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((boot_cpu_data.pdc.capabilities & PDC_MODEL_NVA_MASK) ==
|
|
|
|
PDC_MODEL_NVA_UNSUPPORTED) {
|
|
|
|
printk(KERN_WARNING "parisc_cache_init: Only equivalent aliasing supported!\n");
|
|
|
|
#if 0
|
|
|
|
panic("SMP kernel required to avoid non-equivalent aliasing");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void disable_sr_hashing(void)
|
|
|
|
{
|
2006-06-17 06:20:00 +08:00
|
|
|
int srhash_type, retval;
|
|
|
|
unsigned long space_bits;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (boot_cpu_data.cpu_type) {
|
|
|
|
case pcx: /* We shouldn't get this far. setup.c should prevent it. */
|
|
|
|
BUG();
|
|
|
|
return;
|
|
|
|
|
|
|
|
case pcxs:
|
|
|
|
case pcxt:
|
|
|
|
case pcxt_:
|
|
|
|
srhash_type = SRHASH_PCXST;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case pcxl:
|
|
|
|
srhash_type = SRHASH_PCXL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case pcxl2: /* pcxl2 doesn't support space register hashing */
|
|
|
|
return;
|
|
|
|
|
|
|
|
default: /* Currently all PA2.0 machines use the same ins. sequence */
|
|
|
|
srhash_type = SRHASH_PA20;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
disable_sr_hashing_asm(srhash_type);
|
2006-06-17 06:20:00 +08:00
|
|
|
|
|
|
|
retval = pdc_spaceid_bits(&space_bits);
|
|
|
|
/* If this procedure isn't implemented, don't panic. */
|
|
|
|
if (retval < 0 && retval != PDC_BAD_OPTION)
|
|
|
|
panic("pdc_spaceid_bits call failed.\n");
|
|
|
|
if (space_bits != 0)
|
|
|
|
panic("SpaceID hashing is still on!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-12-12 21:51:54 +08:00
|
|
|
static inline void
|
2010-12-23 00:22:11 +08:00
|
|
|
__flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr,
|
|
|
|
unsigned long physaddr)
|
2006-12-12 21:51:54 +08:00
|
|
|
{
|
2013-02-03 07:41:24 +08:00
|
|
|
preempt_disable();
|
2010-12-23 00:22:11 +08:00
|
|
|
flush_dcache_page_asm(physaddr, vmaddr);
|
|
|
|
if (vma->vm_flags & VM_EXEC)
|
|
|
|
flush_icache_page_asm(physaddr, vmaddr);
|
2013-02-03 07:41:24 +08:00
|
|
|
preempt_enable();
|
2006-12-12 21:51:54 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void flush_dcache_page(struct page *page)
|
|
|
|
{
|
|
|
|
struct address_space *mapping = page_mapping(page);
|
|
|
|
struct vm_area_struct *mpnt;
|
|
|
|
unsigned long offset;
|
2010-12-23 00:22:11 +08:00
|
|
|
unsigned long addr, old_addr = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
pgoff_t pgoff;
|
|
|
|
|
|
|
|
if (mapping && !mapping_mapped(mapping)) {
|
|
|
|
set_bit(PG_dcache_dirty, &page->flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-23 00:42:04 +08:00
|
|
|
flush_kernel_dcache_page(page);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!mapping)
|
|
|
|
return;
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
pgoff = page->index;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* We have carefully arranged in arch_get_unmapped_area() that
|
|
|
|
* *any* mappings of a file are always congruently mapped (whether
|
|
|
|
* declared as MAP_PRIVATE or MAP_SHARED), so we only need
|
|
|
|
* to flush one address here for them all to become coherent */
|
|
|
|
|
|
|
|
flush_dcache_mmap_lock(mapping);
|
2012-10-09 07:31:25 +08:00
|
|
|
vma_interval_tree_foreach(mpnt, &mapping->i_mmap, pgoff, pgoff) {
|
2005-04-17 06:20:36 +08:00
|
|
|
offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT;
|
|
|
|
addr = mpnt->vm_start + offset;
|
|
|
|
|
2011-04-16 01:37:22 +08:00
|
|
|
/* The TLB is the engine of coherence on parisc: The
|
|
|
|
* CPU is entitled to speculate any page with a TLB
|
|
|
|
* mapping, so here we kill the mapping then flush the
|
|
|
|
* page along a special flush only alias mapping.
|
|
|
|
* This guarantees that the page is no-longer in the
|
|
|
|
* cache for any process and nor may it be
|
|
|
|
* speculatively read in (until the user or kernel
|
|
|
|
* specifically accesses it, of course) */
|
|
|
|
|
|
|
|
flush_tlb_page(mpnt, addr);
|
2014-04-10 01:49:28 +08:00
|
|
|
if (old_addr == 0 || (old_addr & (SHM_COLOUR - 1))
|
|
|
|
!= (addr & (SHM_COLOUR - 1))) {
|
2010-12-23 00:22:11 +08:00
|
|
|
__flush_cache_page(mpnt, addr, page_to_phys(page));
|
|
|
|
if (old_addr)
|
2016-08-08 00:23:38 +08:00
|
|
|
printk(KERN_ERR "INEQUIVALENT ALIASES 0x%lx and 0x%lx in file %pD\n", old_addr, addr, mpnt->vm_file);
|
2010-12-23 00:22:11 +08:00
|
|
|
old_addr = addr;
|
2005-10-30 09:16:36 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
flush_dcache_mmap_unlock(mapping);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(flush_dcache_page);
|
|
|
|
|
|
|
|
/* Defined in arch/parisc/kernel/pacache.S */
|
|
|
|
EXPORT_SYMBOL(flush_kernel_dcache_range_asm);
|
2006-03-23 00:42:04 +08:00
|
|
|
EXPORT_SYMBOL(flush_kernel_dcache_page_asm);
|
2005-04-17 06:20:36 +08:00
|
|
|
EXPORT_SYMBOL(flush_data_cache_local);
|
|
|
|
EXPORT_SYMBOL(flush_kernel_icache_range_asm);
|
|
|
|
|
|
|
|
#define FLUSH_THRESHOLD 0x80000 /* 0.5MB */
|
2015-07-02 05:18:37 +08:00
|
|
|
static unsigned long parisc_cache_flush_threshold __read_mostly = FLUSH_THRESHOLD;
|
|
|
|
|
|
|
|
#define FLUSH_TLB_THRESHOLD (2*1024*1024) /* 2MB initial TLB threshold */
|
|
|
|
static unsigned long parisc_tlb_flush_threshold __read_mostly = FLUSH_TLB_THRESHOLD;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-12 21:51:54 +08:00
|
|
|
void __init parisc_setup_cache_timing(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long rangetime, alltime;
|
2015-07-02 05:18:37 +08:00
|
|
|
unsigned long size, start;
|
parisc: Fix races in parisc_setup_cache_timing()
Helge reported to me the following startup crash:
[ 0.000000] Linux version 4.8.0-1-parisc64-smp (debian-kernel@lists.debian.org) (gcc version 5.4.1 20161019 (GCC) ) #1 SMP Debian 4.8.7-1 (2016-11-13)
[ 0.000000] The 64-bit Kernel has started...
[ 0.000000] Kernel default page size is 4 KB. Huge pages enabled with 1 MB physical and 2 MB virtual size.
[ 0.000000] Determining PDC firmware type: System Map.
[ 0.000000] model 9000/785/J5000
[ 0.000000] Total Memory: 2048 MB
[ 0.000000] Memory: 2018528K/2097152K available (9272K kernel code, 3053K rwdata, 1319K rodata, 1024K init, 840K bss, 78624K reserved, 0K cma-reserved)
[ 0.000000] virtual kernel memory layout:
[ 0.000000] vmalloc : 0x0000000000008000 - 0x000000003f000000 (1007 MB)
[ 0.000000] memory : 0x0000000040000000 - 0x00000000c0000000 (2048 MB)
[ 0.000000] .init : 0x0000000040100000 - 0x0000000040200000 (1024 kB)
[ 0.000000] .data : 0x0000000040b0e000 - 0x0000000040f533e0 (4372 kB)
[ 0.000000] .text : 0x0000000040200000 - 0x0000000040b0e000 (9272 kB)
[ 0.768910] Brought up 1 CPUs
[ 0.992465] NET: Registered protocol family 16
[ 2.429981] Releasing cpu 1 now, hpa=fffffffffffa2000
[ 2.635751] CPU(s): 2 out of 2 PA8500 (PCX-W) at 440.000000 MHz online
[ 2.726692] Setting cache flush threshold to 1024 kB
[ 2.729932] Not-handled unaligned insn 0x43ffff80
[ 2.798114] Setting TLB flush threshold to 140 kB
[ 2.928039] Unaligned handler failed, ret = -1
[ 3.000419] _______________________________
[ 3.000419] < Your System ate a SPARC! Gah! >
[ 3.000419] -------------------------------
[ 3.000419] \ ^__^
[ 3.000419] (__)\ )\/\
[ 3.000419] U ||----w |
[ 3.000419] || ||
[ 9.340055] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-1-parisc64-smp #1 Debian 4.8.7-1
[ 9.448082] task: 00000000bfd48060 task.stack: 00000000bfd50000
[ 9.528040]
[ 10.760029] IASQ: 0000000000000000 0000000000000000 IAOQ: 000000004025d154 000000004025d158
[ 10.868052] IIR: 43ffff80 ISR: 0000000000340000 IOR: 000001ff54150960
[ 10.960029] CPU: 1 CR30: 00000000bfd50000 CR31: 0000000011111111
[ 11.052057] ORIG_R28: 000000004021e3b4
[ 11.100045] IAOQ[0]: irq_exit+0x94/0x120
[ 11.152062] IAOQ[1]: irq_exit+0x98/0x120
[ 11.208031] RP(r2): irq_exit+0xb8/0x120
[ 11.256074] Backtrace:
[ 11.288067] [<00000000402cd944>] cpu_startup_entry+0x1e4/0x598
[ 11.368058] [<0000000040109528>] smp_callin+0x2c0/0x2f0
[ 11.436308] [<00000000402b53fc>] update_curr+0x18c/0x2d0
[ 11.508055] [<00000000402b73b8>] dequeue_entity+0x2c0/0x1030
[ 11.584040] [<00000000402b3cc0>] set_next_entity+0x80/0xd30
[ 11.660069] [<00000000402c1594>] pick_next_task_fair+0x614/0x720
[ 11.740085] [<000000004020dd34>] __schedule+0x394/0xa60
[ 11.808054] [<000000004020e488>] schedule+0x88/0x118
[ 11.876039] [<0000000040283d3c>] rescuer_thread+0x4d4/0x5b0
[ 11.948090] [<000000004028fc4c>] kthread+0x1ec/0x248
[ 12.016053] [<0000000040205020>] end_fault_vector+0x20/0xc0
[ 12.092239] [<00000000402050c0>] _switch_to_ret+0x0/0xf40
[ 12.164044]
[ 12.184036] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-1-parisc64-smp #1 Debian 4.8.7-1
[ 12.244040] Backtrace:
[ 12.244040] [<000000004021c480>] show_stack+0x68/0x80
[ 12.244040] [<00000000406f332c>] dump_stack+0xec/0x168
[ 12.244040] [<000000004021c74c>] die_if_kernel+0x25c/0x430
[ 12.244040] [<000000004022d320>] handle_unaligned+0xb48/0xb50
[ 12.244040]
[ 12.632066] ---[ end trace 9ca05a7215c7bbb2 ]---
[ 12.692036] Kernel panic - not syncing: Attempted to kill the idle task!
We have the insn 0x43ffff80 in IIR but from IAOQ we should have:
4025d150: 0f f3 20 df ldd,s r19(r31),r31
4025d154: 0f 9f 00 9c ldw r31(ret0),ret0
4025d158: bf 80 20 58 cmpb,*<> r0,ret0,4025d18c <irq_exit+0xcc>
Cpu0 has just completed running parisc_setup_cache_timing:
[ 2.429981] Releasing cpu 1 now, hpa=fffffffffffa2000
[ 2.635751] CPU(s): 2 out of 2 PA8500 (PCX-W) at 440.000000 MHz online
[ 2.726692] Setting cache flush threshold to 1024 kB
[ 2.729932] Not-handled unaligned insn 0x43ffff80
[ 2.798114] Setting TLB flush threshold to 140 kB
[ 2.928039] Unaligned handler failed, ret = -1
From the backtrace, cpu1 is in smp_callin:
void __init smp_callin(void)
{
int slave_id = cpu_now_booting;
smp_cpu_init(slave_id);
preempt_disable();
flush_cache_all_local(); /* start with known state */
flush_tlb_all_local(NULL);
local_irq_enable(); /* Interrupts have been off until now */
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
So, it has just flushed its caches and the TLB. It would seem either the
flushes in parisc_setup_cache_timing or smp_callin have corrupted kernel
memory.
The attached patch reworks parisc_setup_cache_timing to remove the races
in setting the cache and TLB flush thresholds. It also corrects the
number of bytes flushed in the TLB calculation.
The patch flushes the cache and TLB on cpu0 before starting the
secondary processors so that they are started from a known state.
Tested with a few reboots on c8000.
Signed-off-by: John David Anglin <dave.anglin@bell.net>
Cc: <stable@vger.kernel.org> # v3.18+
Signed-off-by: Helge Deller <deller@gmx.de>
2016-11-21 10:12:36 +08:00
|
|
|
unsigned long threshold;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
alltime = mfctl(16);
|
|
|
|
flush_data_cache();
|
|
|
|
alltime = mfctl(16) - alltime;
|
|
|
|
|
2005-10-22 10:44:14 +08:00
|
|
|
size = (unsigned long)(_end - _text);
|
2005-04-17 06:20:36 +08:00
|
|
|
rangetime = mfctl(16);
|
2005-10-22 10:44:14 +08:00
|
|
|
flush_kernel_dcache_range((unsigned long)_text, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
rangetime = mfctl(16) - rangetime;
|
|
|
|
|
|
|
|
printk(KERN_DEBUG "Whole cache flush %lu cycles, flushing %lu bytes %lu cycles\n",
|
|
|
|
alltime, size, rangetime);
|
|
|
|
|
parisc: Fix races in parisc_setup_cache_timing()
Helge reported to me the following startup crash:
[ 0.000000] Linux version 4.8.0-1-parisc64-smp (debian-kernel@lists.debian.org) (gcc version 5.4.1 20161019 (GCC) ) #1 SMP Debian 4.8.7-1 (2016-11-13)
[ 0.000000] The 64-bit Kernel has started...
[ 0.000000] Kernel default page size is 4 KB. Huge pages enabled with 1 MB physical and 2 MB virtual size.
[ 0.000000] Determining PDC firmware type: System Map.
[ 0.000000] model 9000/785/J5000
[ 0.000000] Total Memory: 2048 MB
[ 0.000000] Memory: 2018528K/2097152K available (9272K kernel code, 3053K rwdata, 1319K rodata, 1024K init, 840K bss, 78624K reserved, 0K cma-reserved)
[ 0.000000] virtual kernel memory layout:
[ 0.000000] vmalloc : 0x0000000000008000 - 0x000000003f000000 (1007 MB)
[ 0.000000] memory : 0x0000000040000000 - 0x00000000c0000000 (2048 MB)
[ 0.000000] .init : 0x0000000040100000 - 0x0000000040200000 (1024 kB)
[ 0.000000] .data : 0x0000000040b0e000 - 0x0000000040f533e0 (4372 kB)
[ 0.000000] .text : 0x0000000040200000 - 0x0000000040b0e000 (9272 kB)
[ 0.768910] Brought up 1 CPUs
[ 0.992465] NET: Registered protocol family 16
[ 2.429981] Releasing cpu 1 now, hpa=fffffffffffa2000
[ 2.635751] CPU(s): 2 out of 2 PA8500 (PCX-W) at 440.000000 MHz online
[ 2.726692] Setting cache flush threshold to 1024 kB
[ 2.729932] Not-handled unaligned insn 0x43ffff80
[ 2.798114] Setting TLB flush threshold to 140 kB
[ 2.928039] Unaligned handler failed, ret = -1
[ 3.000419] _______________________________
[ 3.000419] < Your System ate a SPARC! Gah! >
[ 3.000419] -------------------------------
[ 3.000419] \ ^__^
[ 3.000419] (__)\ )\/\
[ 3.000419] U ||----w |
[ 3.000419] || ||
[ 9.340055] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-1-parisc64-smp #1 Debian 4.8.7-1
[ 9.448082] task: 00000000bfd48060 task.stack: 00000000bfd50000
[ 9.528040]
[ 10.760029] IASQ: 0000000000000000 0000000000000000 IAOQ: 000000004025d154 000000004025d158
[ 10.868052] IIR: 43ffff80 ISR: 0000000000340000 IOR: 000001ff54150960
[ 10.960029] CPU: 1 CR30: 00000000bfd50000 CR31: 0000000011111111
[ 11.052057] ORIG_R28: 000000004021e3b4
[ 11.100045] IAOQ[0]: irq_exit+0x94/0x120
[ 11.152062] IAOQ[1]: irq_exit+0x98/0x120
[ 11.208031] RP(r2): irq_exit+0xb8/0x120
[ 11.256074] Backtrace:
[ 11.288067] [<00000000402cd944>] cpu_startup_entry+0x1e4/0x598
[ 11.368058] [<0000000040109528>] smp_callin+0x2c0/0x2f0
[ 11.436308] [<00000000402b53fc>] update_curr+0x18c/0x2d0
[ 11.508055] [<00000000402b73b8>] dequeue_entity+0x2c0/0x1030
[ 11.584040] [<00000000402b3cc0>] set_next_entity+0x80/0xd30
[ 11.660069] [<00000000402c1594>] pick_next_task_fair+0x614/0x720
[ 11.740085] [<000000004020dd34>] __schedule+0x394/0xa60
[ 11.808054] [<000000004020e488>] schedule+0x88/0x118
[ 11.876039] [<0000000040283d3c>] rescuer_thread+0x4d4/0x5b0
[ 11.948090] [<000000004028fc4c>] kthread+0x1ec/0x248
[ 12.016053] [<0000000040205020>] end_fault_vector+0x20/0xc0
[ 12.092239] [<00000000402050c0>] _switch_to_ret+0x0/0xf40
[ 12.164044]
[ 12.184036] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-1-parisc64-smp #1 Debian 4.8.7-1
[ 12.244040] Backtrace:
[ 12.244040] [<000000004021c480>] show_stack+0x68/0x80
[ 12.244040] [<00000000406f332c>] dump_stack+0xec/0x168
[ 12.244040] [<000000004021c74c>] die_if_kernel+0x25c/0x430
[ 12.244040] [<000000004022d320>] handle_unaligned+0xb48/0xb50
[ 12.244040]
[ 12.632066] ---[ end trace 9ca05a7215c7bbb2 ]---
[ 12.692036] Kernel panic - not syncing: Attempted to kill the idle task!
We have the insn 0x43ffff80 in IIR but from IAOQ we should have:
4025d150: 0f f3 20 df ldd,s r19(r31),r31
4025d154: 0f 9f 00 9c ldw r31(ret0),ret0
4025d158: bf 80 20 58 cmpb,*<> r0,ret0,4025d18c <irq_exit+0xcc>
Cpu0 has just completed running parisc_setup_cache_timing:
[ 2.429981] Releasing cpu 1 now, hpa=fffffffffffa2000
[ 2.635751] CPU(s): 2 out of 2 PA8500 (PCX-W) at 440.000000 MHz online
[ 2.726692] Setting cache flush threshold to 1024 kB
[ 2.729932] Not-handled unaligned insn 0x43ffff80
[ 2.798114] Setting TLB flush threshold to 140 kB
[ 2.928039] Unaligned handler failed, ret = -1
From the backtrace, cpu1 is in smp_callin:
void __init smp_callin(void)
{
int slave_id = cpu_now_booting;
smp_cpu_init(slave_id);
preempt_disable();
flush_cache_all_local(); /* start with known state */
flush_tlb_all_local(NULL);
local_irq_enable(); /* Interrupts have been off until now */
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
So, it has just flushed its caches and the TLB. It would seem either the
flushes in parisc_setup_cache_timing or smp_callin have corrupted kernel
memory.
The attached patch reworks parisc_setup_cache_timing to remove the races
in setting the cache and TLB flush thresholds. It also corrects the
number of bytes flushed in the TLB calculation.
The patch flushes the cache and TLB on cpu0 before starting the
secondary processors so that they are started from a known state.
Tested with a few reboots on c8000.
Signed-off-by: John David Anglin <dave.anglin@bell.net>
Cc: <stable@vger.kernel.org> # v3.18+
Signed-off-by: Helge Deller <deller@gmx.de>
2016-11-21 10:12:36 +08:00
|
|
|
threshold = L1_CACHE_ALIGN(size * alltime / rangetime);
|
|
|
|
if (threshold > cache_info.dc_size)
|
|
|
|
threshold = cache_info.dc_size;
|
|
|
|
if (threshold)
|
|
|
|
parisc_cache_flush_threshold = threshold;
|
|
|
|
printk(KERN_INFO "Cache flush threshold set to %lu KiB\n",
|
2015-07-02 05:18:37 +08:00
|
|
|
parisc_cache_flush_threshold/1024);
|
|
|
|
|
|
|
|
/* calculate TLB flush threshold */
|
|
|
|
|
2016-12-09 04:00:46 +08:00
|
|
|
/* On SMP machines, skip the TLB measure of kernel text which
|
|
|
|
* has been mapped as huge pages. */
|
|
|
|
if (num_online_cpus() > 1 && !parisc_requires_coherency()) {
|
|
|
|
threshold = max(cache_info.it_size, cache_info.dt_size);
|
|
|
|
threshold *= PAGE_SIZE;
|
|
|
|
threshold /= num_online_cpus();
|
|
|
|
goto set_tlb_threshold;
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:18:37 +08:00
|
|
|
alltime = mfctl(16);
|
|
|
|
flush_tlb_all();
|
|
|
|
alltime = mfctl(16) - alltime;
|
|
|
|
|
parisc: Fix races in parisc_setup_cache_timing()
Helge reported to me the following startup crash:
[ 0.000000] Linux version 4.8.0-1-parisc64-smp (debian-kernel@lists.debian.org) (gcc version 5.4.1 20161019 (GCC) ) #1 SMP Debian 4.8.7-1 (2016-11-13)
[ 0.000000] The 64-bit Kernel has started...
[ 0.000000] Kernel default page size is 4 KB. Huge pages enabled with 1 MB physical and 2 MB virtual size.
[ 0.000000] Determining PDC firmware type: System Map.
[ 0.000000] model 9000/785/J5000
[ 0.000000] Total Memory: 2048 MB
[ 0.000000] Memory: 2018528K/2097152K available (9272K kernel code, 3053K rwdata, 1319K rodata, 1024K init, 840K bss, 78624K reserved, 0K cma-reserved)
[ 0.000000] virtual kernel memory layout:
[ 0.000000] vmalloc : 0x0000000000008000 - 0x000000003f000000 (1007 MB)
[ 0.000000] memory : 0x0000000040000000 - 0x00000000c0000000 (2048 MB)
[ 0.000000] .init : 0x0000000040100000 - 0x0000000040200000 (1024 kB)
[ 0.000000] .data : 0x0000000040b0e000 - 0x0000000040f533e0 (4372 kB)
[ 0.000000] .text : 0x0000000040200000 - 0x0000000040b0e000 (9272 kB)
[ 0.768910] Brought up 1 CPUs
[ 0.992465] NET: Registered protocol family 16
[ 2.429981] Releasing cpu 1 now, hpa=fffffffffffa2000
[ 2.635751] CPU(s): 2 out of 2 PA8500 (PCX-W) at 440.000000 MHz online
[ 2.726692] Setting cache flush threshold to 1024 kB
[ 2.729932] Not-handled unaligned insn 0x43ffff80
[ 2.798114] Setting TLB flush threshold to 140 kB
[ 2.928039] Unaligned handler failed, ret = -1
[ 3.000419] _______________________________
[ 3.000419] < Your System ate a SPARC! Gah! >
[ 3.000419] -------------------------------
[ 3.000419] \ ^__^
[ 3.000419] (__)\ )\/\
[ 3.000419] U ||----w |
[ 3.000419] || ||
[ 9.340055] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-1-parisc64-smp #1 Debian 4.8.7-1
[ 9.448082] task: 00000000bfd48060 task.stack: 00000000bfd50000
[ 9.528040]
[ 10.760029] IASQ: 0000000000000000 0000000000000000 IAOQ: 000000004025d154 000000004025d158
[ 10.868052] IIR: 43ffff80 ISR: 0000000000340000 IOR: 000001ff54150960
[ 10.960029] CPU: 1 CR30: 00000000bfd50000 CR31: 0000000011111111
[ 11.052057] ORIG_R28: 000000004021e3b4
[ 11.100045] IAOQ[0]: irq_exit+0x94/0x120
[ 11.152062] IAOQ[1]: irq_exit+0x98/0x120
[ 11.208031] RP(r2): irq_exit+0xb8/0x120
[ 11.256074] Backtrace:
[ 11.288067] [<00000000402cd944>] cpu_startup_entry+0x1e4/0x598
[ 11.368058] [<0000000040109528>] smp_callin+0x2c0/0x2f0
[ 11.436308] [<00000000402b53fc>] update_curr+0x18c/0x2d0
[ 11.508055] [<00000000402b73b8>] dequeue_entity+0x2c0/0x1030
[ 11.584040] [<00000000402b3cc0>] set_next_entity+0x80/0xd30
[ 11.660069] [<00000000402c1594>] pick_next_task_fair+0x614/0x720
[ 11.740085] [<000000004020dd34>] __schedule+0x394/0xa60
[ 11.808054] [<000000004020e488>] schedule+0x88/0x118
[ 11.876039] [<0000000040283d3c>] rescuer_thread+0x4d4/0x5b0
[ 11.948090] [<000000004028fc4c>] kthread+0x1ec/0x248
[ 12.016053] [<0000000040205020>] end_fault_vector+0x20/0xc0
[ 12.092239] [<00000000402050c0>] _switch_to_ret+0x0/0xf40
[ 12.164044]
[ 12.184036] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-1-parisc64-smp #1 Debian 4.8.7-1
[ 12.244040] Backtrace:
[ 12.244040] [<000000004021c480>] show_stack+0x68/0x80
[ 12.244040] [<00000000406f332c>] dump_stack+0xec/0x168
[ 12.244040] [<000000004021c74c>] die_if_kernel+0x25c/0x430
[ 12.244040] [<000000004022d320>] handle_unaligned+0xb48/0xb50
[ 12.244040]
[ 12.632066] ---[ end trace 9ca05a7215c7bbb2 ]---
[ 12.692036] Kernel panic - not syncing: Attempted to kill the idle task!
We have the insn 0x43ffff80 in IIR but from IAOQ we should have:
4025d150: 0f f3 20 df ldd,s r19(r31),r31
4025d154: 0f 9f 00 9c ldw r31(ret0),ret0
4025d158: bf 80 20 58 cmpb,*<> r0,ret0,4025d18c <irq_exit+0xcc>
Cpu0 has just completed running parisc_setup_cache_timing:
[ 2.429981] Releasing cpu 1 now, hpa=fffffffffffa2000
[ 2.635751] CPU(s): 2 out of 2 PA8500 (PCX-W) at 440.000000 MHz online
[ 2.726692] Setting cache flush threshold to 1024 kB
[ 2.729932] Not-handled unaligned insn 0x43ffff80
[ 2.798114] Setting TLB flush threshold to 140 kB
[ 2.928039] Unaligned handler failed, ret = -1
From the backtrace, cpu1 is in smp_callin:
void __init smp_callin(void)
{
int slave_id = cpu_now_booting;
smp_cpu_init(slave_id);
preempt_disable();
flush_cache_all_local(); /* start with known state */
flush_tlb_all_local(NULL);
local_irq_enable(); /* Interrupts have been off until now */
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
So, it has just flushed its caches and the TLB. It would seem either the
flushes in parisc_setup_cache_timing or smp_callin have corrupted kernel
memory.
The attached patch reworks parisc_setup_cache_timing to remove the races
in setting the cache and TLB flush thresholds. It also corrects the
number of bytes flushed in the TLB calculation.
The patch flushes the cache and TLB on cpu0 before starting the
secondary processors so that they are started from a known state.
Tested with a few reboots on c8000.
Signed-off-by: John David Anglin <dave.anglin@bell.net>
Cc: <stable@vger.kernel.org> # v3.18+
Signed-off-by: Helge Deller <deller@gmx.de>
2016-11-21 10:12:36 +08:00
|
|
|
size = 0;
|
2015-07-02 05:18:37 +08:00
|
|
|
start = (unsigned long) _text;
|
|
|
|
rangetime = mfctl(16);
|
|
|
|
while (start < (unsigned long) _end) {
|
|
|
|
flush_tlb_kernel_range(start, start + PAGE_SIZE);
|
|
|
|
start += PAGE_SIZE;
|
|
|
|
size += PAGE_SIZE;
|
|
|
|
}
|
|
|
|
rangetime = mfctl(16) - rangetime;
|
|
|
|
|
|
|
|
printk(KERN_DEBUG "Whole TLB flush %lu cycles, flushing %lu bytes %lu cycles\n",
|
|
|
|
alltime, size, rangetime);
|
|
|
|
|
parisc: Fix races in parisc_setup_cache_timing()
Helge reported to me the following startup crash:
[ 0.000000] Linux version 4.8.0-1-parisc64-smp (debian-kernel@lists.debian.org) (gcc version 5.4.1 20161019 (GCC) ) #1 SMP Debian 4.8.7-1 (2016-11-13)
[ 0.000000] The 64-bit Kernel has started...
[ 0.000000] Kernel default page size is 4 KB. Huge pages enabled with 1 MB physical and 2 MB virtual size.
[ 0.000000] Determining PDC firmware type: System Map.
[ 0.000000] model 9000/785/J5000
[ 0.000000] Total Memory: 2048 MB
[ 0.000000] Memory: 2018528K/2097152K available (9272K kernel code, 3053K rwdata, 1319K rodata, 1024K init, 840K bss, 78624K reserved, 0K cma-reserved)
[ 0.000000] virtual kernel memory layout:
[ 0.000000] vmalloc : 0x0000000000008000 - 0x000000003f000000 (1007 MB)
[ 0.000000] memory : 0x0000000040000000 - 0x00000000c0000000 (2048 MB)
[ 0.000000] .init : 0x0000000040100000 - 0x0000000040200000 (1024 kB)
[ 0.000000] .data : 0x0000000040b0e000 - 0x0000000040f533e0 (4372 kB)
[ 0.000000] .text : 0x0000000040200000 - 0x0000000040b0e000 (9272 kB)
[ 0.768910] Brought up 1 CPUs
[ 0.992465] NET: Registered protocol family 16
[ 2.429981] Releasing cpu 1 now, hpa=fffffffffffa2000
[ 2.635751] CPU(s): 2 out of 2 PA8500 (PCX-W) at 440.000000 MHz online
[ 2.726692] Setting cache flush threshold to 1024 kB
[ 2.729932] Not-handled unaligned insn 0x43ffff80
[ 2.798114] Setting TLB flush threshold to 140 kB
[ 2.928039] Unaligned handler failed, ret = -1
[ 3.000419] _______________________________
[ 3.000419] < Your System ate a SPARC! Gah! >
[ 3.000419] -------------------------------
[ 3.000419] \ ^__^
[ 3.000419] (__)\ )\/\
[ 3.000419] U ||----w |
[ 3.000419] || ||
[ 9.340055] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-1-parisc64-smp #1 Debian 4.8.7-1
[ 9.448082] task: 00000000bfd48060 task.stack: 00000000bfd50000
[ 9.528040]
[ 10.760029] IASQ: 0000000000000000 0000000000000000 IAOQ: 000000004025d154 000000004025d158
[ 10.868052] IIR: 43ffff80 ISR: 0000000000340000 IOR: 000001ff54150960
[ 10.960029] CPU: 1 CR30: 00000000bfd50000 CR31: 0000000011111111
[ 11.052057] ORIG_R28: 000000004021e3b4
[ 11.100045] IAOQ[0]: irq_exit+0x94/0x120
[ 11.152062] IAOQ[1]: irq_exit+0x98/0x120
[ 11.208031] RP(r2): irq_exit+0xb8/0x120
[ 11.256074] Backtrace:
[ 11.288067] [<00000000402cd944>] cpu_startup_entry+0x1e4/0x598
[ 11.368058] [<0000000040109528>] smp_callin+0x2c0/0x2f0
[ 11.436308] [<00000000402b53fc>] update_curr+0x18c/0x2d0
[ 11.508055] [<00000000402b73b8>] dequeue_entity+0x2c0/0x1030
[ 11.584040] [<00000000402b3cc0>] set_next_entity+0x80/0xd30
[ 11.660069] [<00000000402c1594>] pick_next_task_fair+0x614/0x720
[ 11.740085] [<000000004020dd34>] __schedule+0x394/0xa60
[ 11.808054] [<000000004020e488>] schedule+0x88/0x118
[ 11.876039] [<0000000040283d3c>] rescuer_thread+0x4d4/0x5b0
[ 11.948090] [<000000004028fc4c>] kthread+0x1ec/0x248
[ 12.016053] [<0000000040205020>] end_fault_vector+0x20/0xc0
[ 12.092239] [<00000000402050c0>] _switch_to_ret+0x0/0xf40
[ 12.164044]
[ 12.184036] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-1-parisc64-smp #1 Debian 4.8.7-1
[ 12.244040] Backtrace:
[ 12.244040] [<000000004021c480>] show_stack+0x68/0x80
[ 12.244040] [<00000000406f332c>] dump_stack+0xec/0x168
[ 12.244040] [<000000004021c74c>] die_if_kernel+0x25c/0x430
[ 12.244040] [<000000004022d320>] handle_unaligned+0xb48/0xb50
[ 12.244040]
[ 12.632066] ---[ end trace 9ca05a7215c7bbb2 ]---
[ 12.692036] Kernel panic - not syncing: Attempted to kill the idle task!
We have the insn 0x43ffff80 in IIR but from IAOQ we should have:
4025d150: 0f f3 20 df ldd,s r19(r31),r31
4025d154: 0f 9f 00 9c ldw r31(ret0),ret0
4025d158: bf 80 20 58 cmpb,*<> r0,ret0,4025d18c <irq_exit+0xcc>
Cpu0 has just completed running parisc_setup_cache_timing:
[ 2.429981] Releasing cpu 1 now, hpa=fffffffffffa2000
[ 2.635751] CPU(s): 2 out of 2 PA8500 (PCX-W) at 440.000000 MHz online
[ 2.726692] Setting cache flush threshold to 1024 kB
[ 2.729932] Not-handled unaligned insn 0x43ffff80
[ 2.798114] Setting TLB flush threshold to 140 kB
[ 2.928039] Unaligned handler failed, ret = -1
From the backtrace, cpu1 is in smp_callin:
void __init smp_callin(void)
{
int slave_id = cpu_now_booting;
smp_cpu_init(slave_id);
preempt_disable();
flush_cache_all_local(); /* start with known state */
flush_tlb_all_local(NULL);
local_irq_enable(); /* Interrupts have been off until now */
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
So, it has just flushed its caches and the TLB. It would seem either the
flushes in parisc_setup_cache_timing or smp_callin have corrupted kernel
memory.
The attached patch reworks parisc_setup_cache_timing to remove the races
in setting the cache and TLB flush thresholds. It also corrects the
number of bytes flushed in the TLB calculation.
The patch flushes the cache and TLB on cpu0 before starting the
secondary processors so that they are started from a known state.
Tested with a few reboots on c8000.
Signed-off-by: John David Anglin <dave.anglin@bell.net>
Cc: <stable@vger.kernel.org> # v3.18+
Signed-off-by: Helge Deller <deller@gmx.de>
2016-11-21 10:12:36 +08:00
|
|
|
threshold = PAGE_ALIGN(num_online_cpus() * size * alltime / rangetime);
|
2016-12-09 04:00:46 +08:00
|
|
|
|
|
|
|
set_tlb_threshold:
|
parisc: Fix races in parisc_setup_cache_timing()
Helge reported to me the following startup crash:
[ 0.000000] Linux version 4.8.0-1-parisc64-smp (debian-kernel@lists.debian.org) (gcc version 5.4.1 20161019 (GCC) ) #1 SMP Debian 4.8.7-1 (2016-11-13)
[ 0.000000] The 64-bit Kernel has started...
[ 0.000000] Kernel default page size is 4 KB. Huge pages enabled with 1 MB physical and 2 MB virtual size.
[ 0.000000] Determining PDC firmware type: System Map.
[ 0.000000] model 9000/785/J5000
[ 0.000000] Total Memory: 2048 MB
[ 0.000000] Memory: 2018528K/2097152K available (9272K kernel code, 3053K rwdata, 1319K rodata, 1024K init, 840K bss, 78624K reserved, 0K cma-reserved)
[ 0.000000] virtual kernel memory layout:
[ 0.000000] vmalloc : 0x0000000000008000 - 0x000000003f000000 (1007 MB)
[ 0.000000] memory : 0x0000000040000000 - 0x00000000c0000000 (2048 MB)
[ 0.000000] .init : 0x0000000040100000 - 0x0000000040200000 (1024 kB)
[ 0.000000] .data : 0x0000000040b0e000 - 0x0000000040f533e0 (4372 kB)
[ 0.000000] .text : 0x0000000040200000 - 0x0000000040b0e000 (9272 kB)
[ 0.768910] Brought up 1 CPUs
[ 0.992465] NET: Registered protocol family 16
[ 2.429981] Releasing cpu 1 now, hpa=fffffffffffa2000
[ 2.635751] CPU(s): 2 out of 2 PA8500 (PCX-W) at 440.000000 MHz online
[ 2.726692] Setting cache flush threshold to 1024 kB
[ 2.729932] Not-handled unaligned insn 0x43ffff80
[ 2.798114] Setting TLB flush threshold to 140 kB
[ 2.928039] Unaligned handler failed, ret = -1
[ 3.000419] _______________________________
[ 3.000419] < Your System ate a SPARC! Gah! >
[ 3.000419] -------------------------------
[ 3.000419] \ ^__^
[ 3.000419] (__)\ )\/\
[ 3.000419] U ||----w |
[ 3.000419] || ||
[ 9.340055] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-1-parisc64-smp #1 Debian 4.8.7-1
[ 9.448082] task: 00000000bfd48060 task.stack: 00000000bfd50000
[ 9.528040]
[ 10.760029] IASQ: 0000000000000000 0000000000000000 IAOQ: 000000004025d154 000000004025d158
[ 10.868052] IIR: 43ffff80 ISR: 0000000000340000 IOR: 000001ff54150960
[ 10.960029] CPU: 1 CR30: 00000000bfd50000 CR31: 0000000011111111
[ 11.052057] ORIG_R28: 000000004021e3b4
[ 11.100045] IAOQ[0]: irq_exit+0x94/0x120
[ 11.152062] IAOQ[1]: irq_exit+0x98/0x120
[ 11.208031] RP(r2): irq_exit+0xb8/0x120
[ 11.256074] Backtrace:
[ 11.288067] [<00000000402cd944>] cpu_startup_entry+0x1e4/0x598
[ 11.368058] [<0000000040109528>] smp_callin+0x2c0/0x2f0
[ 11.436308] [<00000000402b53fc>] update_curr+0x18c/0x2d0
[ 11.508055] [<00000000402b73b8>] dequeue_entity+0x2c0/0x1030
[ 11.584040] [<00000000402b3cc0>] set_next_entity+0x80/0xd30
[ 11.660069] [<00000000402c1594>] pick_next_task_fair+0x614/0x720
[ 11.740085] [<000000004020dd34>] __schedule+0x394/0xa60
[ 11.808054] [<000000004020e488>] schedule+0x88/0x118
[ 11.876039] [<0000000040283d3c>] rescuer_thread+0x4d4/0x5b0
[ 11.948090] [<000000004028fc4c>] kthread+0x1ec/0x248
[ 12.016053] [<0000000040205020>] end_fault_vector+0x20/0xc0
[ 12.092239] [<00000000402050c0>] _switch_to_ret+0x0/0xf40
[ 12.164044]
[ 12.184036] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.8.0-1-parisc64-smp #1 Debian 4.8.7-1
[ 12.244040] Backtrace:
[ 12.244040] [<000000004021c480>] show_stack+0x68/0x80
[ 12.244040] [<00000000406f332c>] dump_stack+0xec/0x168
[ 12.244040] [<000000004021c74c>] die_if_kernel+0x25c/0x430
[ 12.244040] [<000000004022d320>] handle_unaligned+0xb48/0xb50
[ 12.244040]
[ 12.632066] ---[ end trace 9ca05a7215c7bbb2 ]---
[ 12.692036] Kernel panic - not syncing: Attempted to kill the idle task!
We have the insn 0x43ffff80 in IIR but from IAOQ we should have:
4025d150: 0f f3 20 df ldd,s r19(r31),r31
4025d154: 0f 9f 00 9c ldw r31(ret0),ret0
4025d158: bf 80 20 58 cmpb,*<> r0,ret0,4025d18c <irq_exit+0xcc>
Cpu0 has just completed running parisc_setup_cache_timing:
[ 2.429981] Releasing cpu 1 now, hpa=fffffffffffa2000
[ 2.635751] CPU(s): 2 out of 2 PA8500 (PCX-W) at 440.000000 MHz online
[ 2.726692] Setting cache flush threshold to 1024 kB
[ 2.729932] Not-handled unaligned insn 0x43ffff80
[ 2.798114] Setting TLB flush threshold to 140 kB
[ 2.928039] Unaligned handler failed, ret = -1
From the backtrace, cpu1 is in smp_callin:
void __init smp_callin(void)
{
int slave_id = cpu_now_booting;
smp_cpu_init(slave_id);
preempt_disable();
flush_cache_all_local(); /* start with known state */
flush_tlb_all_local(NULL);
local_irq_enable(); /* Interrupts have been off until now */
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
So, it has just flushed its caches and the TLB. It would seem either the
flushes in parisc_setup_cache_timing or smp_callin have corrupted kernel
memory.
The attached patch reworks parisc_setup_cache_timing to remove the races
in setting the cache and TLB flush thresholds. It also corrects the
number of bytes flushed in the TLB calculation.
The patch flushes the cache and TLB on cpu0 before starting the
secondary processors so that they are started from a known state.
Tested with a few reboots on c8000.
Signed-off-by: John David Anglin <dave.anglin@bell.net>
Cc: <stable@vger.kernel.org> # v3.18+
Signed-off-by: Helge Deller <deller@gmx.de>
2016-11-21 10:12:36 +08:00
|
|
|
if (threshold)
|
|
|
|
parisc_tlb_flush_threshold = threshold;
|
|
|
|
printk(KERN_INFO "TLB flush threshold set to %lu KiB\n",
|
2015-07-02 05:18:37 +08:00
|
|
|
parisc_tlb_flush_threshold/1024);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-08-24 00:00:04 +08:00
|
|
|
|
2013-02-04 06:59:09 +08:00
|
|
|
extern void purge_kernel_dcache_page_asm(unsigned long);
|
|
|
|
extern void clear_user_page_asm(void *, unsigned long);
|
|
|
|
extern void copy_user_page_asm(void *, void *, unsigned long);
|
2006-08-24 00:00:04 +08:00
|
|
|
|
|
|
|
void flush_kernel_dcache_page_addr(void *addr)
|
|
|
|
{
|
2009-06-17 04:51:48 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2006-08-24 00:00:04 +08:00
|
|
|
flush_kernel_dcache_page_asm(addr);
|
2009-06-17 04:51:48 +08:00
|
|
|
purge_tlb_start(flags);
|
2006-08-24 00:00:04 +08:00
|
|
|
pdtlb_kernel(addr);
|
2009-06-17 04:51:48 +08:00
|
|
|
purge_tlb_end(flags);
|
2006-08-24 00:00:04 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(flush_kernel_dcache_page_addr);
|
|
|
|
|
2014-02-01 04:33:17 +08:00
|
|
|
void copy_user_page(void *vto, void *vfrom, unsigned long vaddr,
|
|
|
|
struct page *pg)
|
|
|
|
{
|
|
|
|
/* Copy using kernel mapping. No coherency is needed (all in
|
|
|
|
kunmap) for the `to' page. However, the `from' page needs to
|
|
|
|
be flushed through a mapping equivalent to the user mapping
|
|
|
|
before it can be accessed through the kernel mapping. */
|
|
|
|
preempt_disable();
|
|
|
|
flush_dcache_page_asm(__pa(vfrom), vaddr);
|
|
|
|
preempt_enable();
|
|
|
|
copy_page_asm(vto, vfrom);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(copy_user_page);
|
|
|
|
|
2015-07-02 05:18:37 +08:00
|
|
|
/* __flush_tlb_range()
|
|
|
|
*
|
|
|
|
* returns 1 if all TLBs were flushed.
|
|
|
|
*/
|
|
|
|
int __flush_tlb_range(unsigned long sid, unsigned long start,
|
|
|
|
unsigned long end)
|
2006-12-12 21:51:54 +08:00
|
|
|
{
|
2015-07-02 05:18:37 +08:00
|
|
|
unsigned long flags, size;
|
2006-12-12 21:51:54 +08:00
|
|
|
|
2015-07-02 05:18:37 +08:00
|
|
|
size = (end - start);
|
|
|
|
if (size >= parisc_tlb_flush_threshold) {
|
2006-12-12 21:51:54 +08:00
|
|
|
flush_tlb_all();
|
2015-07-02 05:18:37 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2009-06-17 04:51:48 +08:00
|
|
|
|
2015-07-02 05:18:37 +08:00
|
|
|
/* Purge TLB entries for small ranges using the pdtlb and
|
|
|
|
pitlb instructions. These instructions execute locally
|
|
|
|
but cause a purge request to be broadcast to other TLBs. */
|
|
|
|
if (likely(!split_tlb)) {
|
|
|
|
while (start < end) {
|
|
|
|
purge_tlb_start(flags);
|
|
|
|
mtsp(sid, 1);
|
|
|
|
pdtlb(start);
|
|
|
|
purge_tlb_end(flags);
|
|
|
|
start += PAGE_SIZE;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* split TLB case */
|
|
|
|
while (start < end) {
|
2009-06-17 04:51:48 +08:00
|
|
|
purge_tlb_start(flags);
|
2013-06-30 04:42:12 +08:00
|
|
|
mtsp(sid, 1);
|
2015-07-02 05:18:37 +08:00
|
|
|
pdtlb(start);
|
|
|
|
pitlb(start);
|
2009-06-17 04:51:48 +08:00
|
|
|
purge_tlb_end(flags);
|
2015-07-02 05:18:37 +08:00
|
|
|
start += PAGE_SIZE;
|
2006-12-12 21:51:54 +08:00
|
|
|
}
|
2015-07-02 05:18:37 +08:00
|
|
|
return 0;
|
2006-12-12 21:51:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cacheflush_h_tmp_function(void *dummy)
|
|
|
|
{
|
|
|
|
flush_cache_all_local();
|
|
|
|
}
|
|
|
|
|
|
|
|
void flush_cache_all(void)
|
|
|
|
{
|
2008-05-09 15:39:44 +08:00
|
|
|
on_each_cpu(cacheflush_h_tmp_function, NULL, 1);
|
2006-12-12 21:51:54 +08:00
|
|
|
}
|
|
|
|
|
2013-02-04 07:01:47 +08:00
|
|
|
static inline unsigned long mm_total_size(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
struct vm_area_struct *vma;
|
|
|
|
unsigned long usize = 0;
|
|
|
|
|
|
|
|
for (vma = mm->mmap; vma; vma = vma->vm_next)
|
|
|
|
usize += vma->vm_end - vma->vm_start;
|
|
|
|
return usize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline pte_t *get_ptep(pgd_t *pgd, unsigned long addr)
|
|
|
|
{
|
|
|
|
pte_t *ptep = NULL;
|
|
|
|
|
|
|
|
if (!pgd_none(*pgd)) {
|
|
|
|
pud_t *pud = pud_offset(pgd, addr);
|
|
|
|
if (!pud_none(*pud)) {
|
|
|
|
pmd_t *pmd = pmd_offset(pud, addr);
|
|
|
|
if (!pmd_none(*pmd))
|
|
|
|
ptep = pte_offset_map(pmd, addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ptep;
|
|
|
|
}
|
|
|
|
|
2006-12-12 21:51:54 +08:00
|
|
|
void flush_cache_mm(struct mm_struct *mm)
|
|
|
|
{
|
2013-07-24 00:27:52 +08:00
|
|
|
struct vm_area_struct *vma;
|
|
|
|
pgd_t *pgd;
|
|
|
|
|
2013-02-04 07:01:47 +08:00
|
|
|
/* Flushing the whole cache on each cpu takes forever on
|
|
|
|
rp3440, etc. So, avoid it if the mm isn't too big. */
|
2013-07-24 00:27:52 +08:00
|
|
|
if (mm_total_size(mm) >= parisc_cache_flush_threshold) {
|
|
|
|
flush_cache_all();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mm->context == mfsp(3)) {
|
|
|
|
for (vma = mm->mmap; vma; vma = vma->vm_next) {
|
|
|
|
flush_user_dcache_range_asm(vma->vm_start, vma->vm_end);
|
|
|
|
if ((vma->vm_flags & VM_EXEC) == 0)
|
|
|
|
continue;
|
|
|
|
flush_user_icache_range_asm(vma->vm_start, vma->vm_end);
|
2013-02-04 07:01:47 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-24 00:27:52 +08:00
|
|
|
pgd = mm->pgd;
|
|
|
|
for (vma = mm->mmap; vma; vma = vma->vm_next) {
|
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
for (addr = vma->vm_start; addr < vma->vm_end;
|
|
|
|
addr += PAGE_SIZE) {
|
|
|
|
unsigned long pfn;
|
|
|
|
pte_t *ptep = get_ptep(pgd, addr);
|
|
|
|
if (!ptep)
|
|
|
|
continue;
|
|
|
|
pfn = pte_pfn(*ptep);
|
|
|
|
if (!pfn_valid(pfn))
|
|
|
|
continue;
|
|
|
|
__flush_cache_page(vma, addr, PFN_PHYS(pfn));
|
|
|
|
}
|
|
|
|
}
|
2006-12-12 21:51:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void flush_cache_range(struct vm_area_struct *vma,
|
|
|
|
unsigned long start, unsigned long end)
|
|
|
|
{
|
2013-07-24 00:27:52 +08:00
|
|
|
unsigned long addr;
|
|
|
|
pgd_t *pgd;
|
|
|
|
|
2009-01-06 19:57:01 +08:00
|
|
|
BUG_ON(!vma->vm_mm->context);
|
2006-12-12 21:51:54 +08:00
|
|
|
|
2013-07-24 00:27:52 +08:00
|
|
|
if ((end - start) >= parisc_cache_flush_threshold) {
|
2006-12-12 21:51:54 +08:00
|
|
|
flush_cache_all();
|
2013-07-24 00:27:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vma->vm_mm->context == mfsp(3)) {
|
|
|
|
flush_user_dcache_range_asm(start, end);
|
|
|
|
if (vma->vm_flags & VM_EXEC)
|
|
|
|
flush_user_icache_range_asm(start, end);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pgd = vma->vm_mm->pgd;
|
|
|
|
for (addr = start & PAGE_MASK; addr < end; addr += PAGE_SIZE) {
|
|
|
|
unsigned long pfn;
|
|
|
|
pte_t *ptep = get_ptep(pgd, addr);
|
|
|
|
if (!ptep)
|
|
|
|
continue;
|
|
|
|
pfn = pte_pfn(*ptep);
|
|
|
|
if (pfn_valid(pfn))
|
|
|
|
__flush_cache_page(vma, addr, PFN_PHYS(pfn));
|
2006-12-12 21:51:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
|
|
|
|
{
|
|
|
|
BUG_ON(!vma->vm_mm->context);
|
|
|
|
|
2013-07-24 00:27:52 +08:00
|
|
|
if (pfn_valid(pfn)) {
|
|
|
|
flush_tlb_page(vma, vmaddr);
|
|
|
|
__flush_cache_page(vma, vmaddr, PFN_PHYS(pfn));
|
|
|
|
}
|
2006-12-12 21:51:54 +08:00
|
|
|
}
|
2017-03-12 07:03:34 +08:00
|
|
|
|
|
|
|
void flush_kernel_vmap_range(void *vaddr, int size)
|
|
|
|
{
|
|
|
|
unsigned long start = (unsigned long)vaddr;
|
|
|
|
|
|
|
|
if ((unsigned long)size > parisc_cache_flush_threshold)
|
|
|
|
flush_data_cache();
|
|
|
|
else
|
|
|
|
flush_kernel_dcache_range_asm(start, start + size);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(flush_kernel_vmap_range);
|
|
|
|
|
|
|
|
void invalidate_kernel_vmap_range(void *vaddr, int size)
|
|
|
|
{
|
|
|
|
unsigned long start = (unsigned long)vaddr;
|
|
|
|
|
|
|
|
if ((unsigned long)size > parisc_cache_flush_threshold)
|
|
|
|
flush_data_cache();
|
|
|
|
else
|
|
|
|
flush_kernel_dcache_range_asm(start, start + size);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(invalidate_kernel_vmap_range);
|