2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/mm/fault-armv.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995 Linus Torvalds
|
|
|
|
* Modifications for ARM processor (c) 1995-2002 Russell King
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
|
2008-09-05 21:08:44 +08:00
|
|
|
#include <asm/bugs.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/cacheflush.h>
|
2008-08-11 01:10:19 +08:00
|
|
|
#include <asm/cachetype.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
|
2009-10-24 21:11:59 +08:00
|
|
|
#include "mm.h"
|
|
|
|
|
2008-09-07 03:04:59 +08:00
|
|
|
static unsigned long shared_pte_mask = L_PTE_MT_BUFFERABLE;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We take the easy way out of this problem - we make the
|
|
|
|
* PTE uncacheable. However, we leave the write buffer on.
|
[PATCH] mm: arm ready for split ptlock
Prepare arm for the split page_table_lock: three issues.
Signal handling's preserve and restore of iwmmxt context currently involves
reading and writing that context to and from user space, while holding
page_table_lock to secure the user page(s) against kswapd. If we split the
lock, then the structure might span two pages, secured by to read into and
write from a kernel stack buffer, copying that out and in without locking (the
structure is 160 bytes in size, and here we're near the top of the kernel
stack). Or would the overhead be noticeable?
arm_syscall's cmpxchg emulation use pte_offset_map_lock, instead of
pte_offset_map and mm-wide page_table_lock; and strictly, it should now also
take mmap_sem before descending to pmd, to guard against another thread
munmapping, and the page table pulled out beneath this thread.
Updated two comments in fault-armv.c. adjust_pte is interesting, since its
modification of a pte in one part of the mm depends on the lock held when
calling update_mmu_cache for a pte in some other part of that mm. This can't
be done with a split page_table_lock (and we've already taken the lowest lock
in the hierarchy here): so we'll have to disable split on arm, unless
CONFIG_CPU_CACHE_VIPT to ensures adjust_pte never used.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-10-30 09:16:36 +08:00
|
|
|
*
|
|
|
|
* Note that the pte lock held when calling update_mmu_cache must also
|
|
|
|
* guard the pte (somewhere else in the same mm) that we modify here.
|
|
|
|
* Therefore those configurations which might call adjust_pte (those
|
|
|
|
* without CONFIG_CPU_CACHE_VIPT) cannot support split page_table_lock.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-12-19 00:21:35 +08:00
|
|
|
static int do_adjust_pte(struct vm_area_struct *vma, unsigned long address,
|
2009-12-19 00:31:38 +08:00
|
|
|
unsigned long pfn, pte_t *ptep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-12-19 00:21:35 +08:00
|
|
|
pte_t entry = *ptep;
|
2008-07-27 17:35:54 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-27 17:35:54 +08:00
|
|
|
/*
|
|
|
|
* If this page is present, it's actually being shared.
|
|
|
|
*/
|
|
|
|
ret = pte_present(entry);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* If this page isn't present, or is already setup to
|
|
|
|
* fault (ie, is old), we can safely ignore any issues.
|
|
|
|
*/
|
2008-09-07 03:04:59 +08:00
|
|
|
if (ret && (pte_val(entry) & L_PTE_MT_MASK) != shared_pte_mask) {
|
2009-01-17 06:02:54 +08:00
|
|
|
flush_cache_page(vma, address, pfn);
|
|
|
|
outer_flush_range((pfn << PAGE_SHIFT),
|
|
|
|
(pfn << PAGE_SHIFT) + PAGE_SIZE);
|
2008-09-07 03:04:59 +08:00
|
|
|
pte_val(entry) &= ~L_PTE_MT_MASK;
|
|
|
|
pte_val(entry) |= shared_pte_mask;
|
2009-12-19 00:21:35 +08:00
|
|
|
set_pte_at(vma->vm_mm, address, ptep, entry);
|
2005-04-17 06:20:36 +08:00
|
|
|
flush_tlb_page(vma, address);
|
|
|
|
}
|
2009-12-19 00:21:35 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-19 00:31:38 +08:00
|
|
|
static int adjust_pte(struct vm_area_struct *vma, unsigned long address,
|
|
|
|
unsigned long pfn)
|
2009-12-19 00:21:35 +08:00
|
|
|
{
|
2009-12-19 00:24:34 +08:00
|
|
|
spinlock_t *ptl;
|
2009-12-19 00:21:35 +08:00
|
|
|
pgd_t *pgd;
|
|
|
|
pmd_t *pmd;
|
|
|
|
pte_t *pte;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pgd = pgd_offset(vma->vm_mm, address);
|
2009-12-19 00:23:44 +08:00
|
|
|
if (pgd_none_or_clear_bad(pgd))
|
|
|
|
return 0;
|
2009-12-19 00:21:35 +08:00
|
|
|
|
|
|
|
pmd = pmd_offset(pgd, address);
|
2009-12-19 00:23:44 +08:00
|
|
|
if (pmd_none_or_clear_bad(pmd))
|
|
|
|
return 0;
|
2009-12-19 00:21:35 +08:00
|
|
|
|
2009-12-19 00:24:34 +08:00
|
|
|
/*
|
|
|
|
* This is called while another page table is mapped, so we
|
|
|
|
* must use the nested version. This also means we need to
|
|
|
|
* open-code the spin-locking.
|
|
|
|
*/
|
|
|
|
ptl = pte_lockptr(vma->vm_mm, pmd);
|
|
|
|
pte = pte_offset_map_nested(pmd, address);
|
|
|
|
spin_lock(ptl);
|
2009-12-19 00:21:35 +08:00
|
|
|
|
2009-12-19 00:31:38 +08:00
|
|
|
ret = do_adjust_pte(vma, address, pfn, pte);
|
2009-12-19 00:21:35 +08:00
|
|
|
|
2009-12-19 00:24:34 +08:00
|
|
|
spin_unlock(ptl);
|
|
|
|
pte_unmap_nested(pte);
|
2009-12-19 00:21:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-19 00:43:57 +08:00
|
|
|
make_coherent(struct address_space *mapping, struct vm_area_struct *vma,
|
|
|
|
unsigned long addr, pte_t *ptep, unsigned long pfn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct mm_struct *mm = vma->vm_mm;
|
|
|
|
struct vm_area_struct *mpnt;
|
|
|
|
struct prio_tree_iter iter;
|
|
|
|
unsigned long offset;
|
|
|
|
pgoff_t pgoff;
|
|
|
|
int aliases = 0;
|
|
|
|
|
|
|
|
pgoff = vma->vm_pgoff + ((addr - vma->vm_start) >> PAGE_SHIFT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have any shared mappings that are in the same mm
|
|
|
|
* space, then we need to handle them specially to maintain
|
|
|
|
* cache coherency.
|
|
|
|
*/
|
|
|
|
flush_dcache_mmap_lock(mapping);
|
|
|
|
vma_prio_tree_foreach(mpnt, &iter, &mapping->i_mmap, pgoff, pgoff) {
|
|
|
|
/*
|
|
|
|
* If this VMA is not in our MM, we can ignore it.
|
|
|
|
* Note that we intentionally mask out the VMA
|
|
|
|
* that we are fixing up.
|
|
|
|
*/
|
|
|
|
if (mpnt->vm_mm != mm || mpnt == vma)
|
|
|
|
continue;
|
|
|
|
if (!(mpnt->vm_flags & VM_MAYSHARE))
|
|
|
|
continue;
|
|
|
|
offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT;
|
2009-12-19 00:31:38 +08:00
|
|
|
aliases += adjust_pte(mpnt, mpnt->vm_start + offset, pfn);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
flush_dcache_mmap_unlock(mapping);
|
|
|
|
if (aliases)
|
2009-12-19 00:43:57 +08:00
|
|
|
do_adjust_pte(vma, addr, pfn, ptep);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2005-06-20 16:51:03 +08:00
|
|
|
flush_cache_page(vma, addr, pfn);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take care of architecture specific things when placing a new PTE into
|
|
|
|
* a page table, or changing an existing PTE. Basically, there are two
|
|
|
|
* things that we need to take care of:
|
|
|
|
*
|
|
|
|
* 1. If PG_dcache_dirty is set for the page, we need to ensure
|
|
|
|
* that any cache entries for the kernels virtual memory
|
|
|
|
* range are written back to the page.
|
|
|
|
* 2. If we have multiple shared mappings of the same space in
|
|
|
|
* an object, we need to deal with the cache aliasing issues.
|
|
|
|
*
|
[PATCH] mm: arm ready for split ptlock
Prepare arm for the split page_table_lock: three issues.
Signal handling's preserve and restore of iwmmxt context currently involves
reading and writing that context to and from user space, while holding
page_table_lock to secure the user page(s) against kswapd. If we split the
lock, then the structure might span two pages, secured by to read into and
write from a kernel stack buffer, copying that out and in without locking (the
structure is 160 bytes in size, and here we're near the top of the kernel
stack). Or would the overhead be noticeable?
arm_syscall's cmpxchg emulation use pte_offset_map_lock, instead of
pte_offset_map and mm-wide page_table_lock; and strictly, it should now also
take mmap_sem before descending to pmd, to guard against another thread
munmapping, and the page table pulled out beneath this thread.
Updated two comments in fault-armv.c. adjust_pte is interesting, since its
modification of a pte in one part of the mm depends on the lock held when
calling update_mmu_cache for a pte in some other part of that mm. This can't
be done with a split page_table_lock (and we've already taken the lowest lock
in the hierarchy here): so we'll have to disable split on arm, unless
CONFIG_CPU_CACHE_VIPT to ensures adjust_pte never used.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-10-30 09:16:36 +08:00
|
|
|
* Note that the pte lock will be held.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
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
|
|
|
void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr,
|
|
|
|
pte_t *ptep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
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
|
|
|
unsigned long pfn = pte_pfn(*ptep);
|
2005-06-20 16:51:03 +08:00
|
|
|
struct address_space *mapping;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
if (!pfn_valid(pfn))
|
|
|
|
return;
|
2005-06-20 16:51:03 +08:00
|
|
|
|
2009-10-25 18:23:04 +08:00
|
|
|
/*
|
|
|
|
* The zero page is never written to, so never has any dirty
|
|
|
|
* cache lines, and therefore never needs to be flushed.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
page = pfn_to_page(pfn);
|
2009-10-25 18:23:04 +08:00
|
|
|
if (page == ZERO_PAGE(0))
|
|
|
|
return;
|
|
|
|
|
2005-06-20 16:51:03 +08:00
|
|
|
mapping = page_mapping(page);
|
2008-06-13 17:28:36 +08:00
|
|
|
#ifndef CONFIG_SMP
|
2009-10-12 16:50:23 +08:00
|
|
|
if (test_and_clear_bit(PG_dcache_dirty, &page->flags))
|
|
|
|
__flush_dcache_page(mapping, page);
|
2008-06-13 17:28:36 +08:00
|
|
|
#endif
|
2009-10-12 16:50:23 +08:00
|
|
|
if (mapping) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cache_is_vivt())
|
2009-12-19 00:43:57 +08:00
|
|
|
make_coherent(mapping, vma, addr, ptep, pfn);
|
2008-06-13 17:28:36 +08:00
|
|
|
else if (vma->vm_flags & VM_EXEC)
|
|
|
|
__flush_icache_all();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether the write buffer has physical address aliasing
|
|
|
|
* issues. If it has, we need to avoid them for the case where
|
|
|
|
* we have several shared mappings of the same object in user
|
|
|
|
* space.
|
|
|
|
*/
|
|
|
|
static int __init check_writebuffer(unsigned long *p1, unsigned long *p2)
|
|
|
|
{
|
|
|
|
register unsigned long zero = 0, one = 1, val;
|
|
|
|
|
|
|
|
local_irq_disable();
|
|
|
|
mb();
|
|
|
|
*p1 = one;
|
|
|
|
mb();
|
|
|
|
*p2 = zero;
|
|
|
|
mb();
|
|
|
|
val = *p1;
|
|
|
|
mb();
|
|
|
|
local_irq_enable();
|
|
|
|
return val != zero;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init check_writebuffer_bugs(void)
|
|
|
|
{
|
|
|
|
struct page *page;
|
|
|
|
const char *reason;
|
|
|
|
unsigned long v = 1;
|
|
|
|
|
|
|
|
printk(KERN_INFO "CPU: Testing write buffer coherency: ");
|
|
|
|
|
|
|
|
page = alloc_page(GFP_KERNEL);
|
|
|
|
if (page) {
|
|
|
|
unsigned long *p1, *p2;
|
2009-12-24 03:54:31 +08:00
|
|
|
pgprot_t prot = __pgprot_modify(PAGE_KERNEL,
|
|
|
|
L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
p1 = vmap(&page, 1, VM_IOREMAP, prot);
|
|
|
|
p2 = vmap(&page, 1, VM_IOREMAP, prot);
|
|
|
|
|
|
|
|
if (p1 && p2) {
|
|
|
|
v = check_writebuffer(p1, p2);
|
|
|
|
reason = "enabling work-around";
|
|
|
|
} else {
|
|
|
|
reason = "unable to map memory\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
vunmap(p1);
|
|
|
|
vunmap(p2);
|
|
|
|
put_page(page);
|
|
|
|
} else {
|
|
|
|
reason = "unable to grab page\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v) {
|
|
|
|
printk("failed, %s\n", reason);
|
2008-09-07 03:04:59 +08:00
|
|
|
shared_pte_mask = L_PTE_MT_UNCACHED;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
printk("ok\n");
|
|
|
|
}
|
|
|
|
}
|