/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*13* From i386 code copyright (C) 1995 Linus Torvalds14*/1516#include <linux/signal.h>17#include <linux/sched.h>18#include <linux/kernel.h>19#include <linux/errno.h>20#include <linux/string.h>21#include <linux/types.h>22#include <linux/ptrace.h>23#include <linux/mman.h>24#include <linux/mm.h>25#include <linux/smp.h>26#include <linux/interrupt.h>27#include <linux/init.h>28#include <linux/tty.h>29#include <linux/vt_kern.h> /* For unblank_screen() */30#include <linux/highmem.h>31#include <linux/module.h>32#include <linux/kprobes.h>33#include <linux/hugetlb.h>34#include <linux/syscalls.h>35#include <linux/uaccess.h>3637#include <asm/system.h>38#include <asm/pgalloc.h>39#include <asm/sections.h>40#include <asm/traps.h>41#include <asm/syscalls.h>4243#include <arch/interrupts.h>4445static noinline void force_sig_info_fault(const char *type, int si_signo,46int si_code, unsigned long address,47int fault_num,48struct task_struct *tsk,49struct pt_regs *regs)50{51siginfo_t info;5253if (unlikely(tsk->pid < 2)) {54panic("Signal %d (code %d) at %#lx sent to %s!",55si_signo, si_code & 0xffff, address,56tsk->pid ? "init" : "the idle task");57}5859info.si_signo = si_signo;60info.si_errno = 0;61info.si_code = si_code;62info.si_addr = (void __user *)address;63info.si_trapno = fault_num;64trace_unhandled_signal(type, regs, address, si_signo);65force_sig_info(si_signo, &info, tsk);66}6768#ifndef __tilegx__69/*70* Synthesize the fault a PL0 process would get by doing a word-load of71* an unaligned address or a high kernel address.72*/73SYSCALL_DEFINE2(cmpxchg_badaddr, unsigned long, address,74struct pt_regs *, regs)75{76if (address >= PAGE_OFFSET)77force_sig_info_fault("atomic segfault", SIGSEGV, SEGV_MAPERR,78address, INT_DTLB_MISS, current, regs);79else80force_sig_info_fault("atomic alignment fault", SIGBUS,81BUS_ADRALN, address,82INT_UNALIGN_DATA, current, regs);8384/*85* Adjust pc to point at the actual instruction, which is unusual86* for syscalls normally, but is appropriate when we are claiming87* that a syscall swint1 caused a page fault or bus error.88*/89regs->pc -= 8;9091/*92* Mark this as a caller-save interrupt, like a normal page fault,93* so that when we go through the signal handler path we will94* properly restore r0, r1, and r2 for the signal handler arguments.95*/96regs->flags |= PT_FLAGS_CALLER_SAVES;9798return 0;99}100#endif101102static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)103{104unsigned index = pgd_index(address);105pgd_t *pgd_k;106pud_t *pud, *pud_k;107pmd_t *pmd, *pmd_k;108109pgd += index;110pgd_k = init_mm.pgd + index;111112if (!pgd_present(*pgd_k))113return NULL;114115pud = pud_offset(pgd, address);116pud_k = pud_offset(pgd_k, address);117if (!pud_present(*pud_k))118return NULL;119120pmd = pmd_offset(pud, address);121pmd_k = pmd_offset(pud_k, address);122if (!pmd_present(*pmd_k))123return NULL;124if (!pmd_present(*pmd)) {125set_pmd(pmd, *pmd_k);126arch_flush_lazy_mmu_mode();127} else128BUG_ON(pmd_ptfn(*pmd) != pmd_ptfn(*pmd_k));129return pmd_k;130}131132/*133* Handle a fault on the vmalloc or module mapping area134*/135static inline int vmalloc_fault(pgd_t *pgd, unsigned long address)136{137pmd_t *pmd_k;138pte_t *pte_k;139140/* Make sure we are in vmalloc area */141if (!(address >= VMALLOC_START && address < VMALLOC_END))142return -1;143144/*145* Synchronize this task's top level page-table146* with the 'reference' page table.147*/148pmd_k = vmalloc_sync_one(pgd, address);149if (!pmd_k)150return -1;151if (pmd_huge(*pmd_k))152return 0; /* support TILE huge_vmap() API */153pte_k = pte_offset_kernel(pmd_k, address);154if (!pte_present(*pte_k))155return -1;156return 0;157}158159/* Wait until this PTE has completed migration. */160static void wait_for_migration(pte_t *pte)161{162if (pte_migrating(*pte)) {163/*164* Wait until the migrater fixes up this pte.165* We scale the loop count by the clock rate so we'll wait for166* a few seconds here.167*/168int retries = 0;169int bound = get_clock_rate();170while (pte_migrating(*pte)) {171barrier();172if (++retries > bound)173panic("Hit migrating PTE (%#llx) and"174" page PFN %#lx still migrating",175pte->val, pte_pfn(*pte));176}177}178}179180/*181* It's not generally safe to use "current" to get the page table pointer,182* since we might be running an oprofile interrupt in the middle of a183* task switch.184*/185static pgd_t *get_current_pgd(void)186{187HV_Context ctx = hv_inquire_context();188unsigned long pgd_pfn = ctx.page_table >> PAGE_SHIFT;189struct page *pgd_page = pfn_to_page(pgd_pfn);190BUG_ON(PageHighMem(pgd_page)); /* oops, HIGHPTE? */191return (pgd_t *) __va(ctx.page_table);192}193194/*195* We can receive a page fault from a migrating PTE at any time.196* Handle it by just waiting until the fault resolves.197*198* It's also possible to get a migrating kernel PTE that resolves199* itself during the downcall from hypervisor to Linux. We just check200* here to see if the PTE seems valid, and if so we retry it.201*202* NOTE! We MUST NOT take any locks for this case. We may be in an203* interrupt or a critical region, and must do as little as possible.204* Similarly, we can't use atomic ops here, since we may be handling a205* fault caused by an atomic op access.206*/207static int handle_migrating_pte(pgd_t *pgd, int fault_num,208unsigned long address,209int is_kernel_mode, int write)210{211pud_t *pud;212pmd_t *pmd;213pte_t *pte;214pte_t pteval;215216if (pgd_addr_invalid(address))217return 0;218219pgd += pgd_index(address);220pud = pud_offset(pgd, address);221if (!pud || !pud_present(*pud))222return 0;223pmd = pmd_offset(pud, address);224if (!pmd || !pmd_present(*pmd))225return 0;226pte = pmd_huge_page(*pmd) ? ((pte_t *)pmd) :227pte_offset_kernel(pmd, address);228pteval = *pte;229if (pte_migrating(pteval)) {230wait_for_migration(pte);231return 1;232}233234if (!is_kernel_mode || !pte_present(pteval))235return 0;236if (fault_num == INT_ITLB_MISS) {237if (pte_exec(pteval))238return 1;239} else if (write) {240if (pte_write(pteval))241return 1;242} else {243if (pte_read(pteval))244return 1;245}246247return 0;248}249250/*251* This routine is responsible for faulting in user pages.252* It passes the work off to one of the appropriate routines.253* It returns true if the fault was successfully handled.254*/255static int handle_page_fault(struct pt_regs *regs,256int fault_num,257int is_page_fault,258unsigned long address,259int write)260{261struct task_struct *tsk;262struct mm_struct *mm;263struct vm_area_struct *vma;264unsigned long stack_offset;265int fault;266int si_code;267int is_kernel_mode;268pgd_t *pgd;269270/* on TILE, protection faults are always writes */271if (!is_page_fault)272write = 1;273274is_kernel_mode = (EX1_PL(regs->ex1) != USER_PL);275276tsk = validate_current();277278/*279* Check to see if we might be overwriting the stack, and bail280* out if so. The page fault code is a relatively likely281* place to get trapped in an infinite regress, and once we282* overwrite the whole stack, it becomes very hard to recover.283*/284stack_offset = stack_pointer & (THREAD_SIZE-1);285if (stack_offset < THREAD_SIZE / 8) {286pr_alert("Potential stack overrun: sp %#lx\n",287stack_pointer);288show_regs(regs);289pr_alert("Killing current process %d/%s\n",290tsk->pid, tsk->comm);291do_group_exit(SIGKILL);292}293294/*295* Early on, we need to check for migrating PTE entries;296* see homecache.c. If we find a migrating PTE, we wait until297* the backing page claims to be done migrating, then we proceed.298* For kernel PTEs, we rewrite the PTE and return and retry.299* Otherwise, we treat the fault like a normal "no PTE" fault,300* rather than trying to patch up the existing PTE.301*/302pgd = get_current_pgd();303if (handle_migrating_pte(pgd, fault_num, address,304is_kernel_mode, write))305return 1;306307si_code = SEGV_MAPERR;308309/*310* We fault-in kernel-space virtual memory on-demand. The311* 'reference' page table is init_mm.pgd.312*313* NOTE! We MUST NOT take any locks for this case. We may314* be in an interrupt or a critical region, and should315* only copy the information from the master page table,316* nothing more.317*318* This verifies that the fault happens in kernel space319* and that the fault was not a protection fault.320*/321if (unlikely(address >= TASK_SIZE &&322!is_arch_mappable_range(address, 0))) {323if (is_kernel_mode && is_page_fault &&324vmalloc_fault(pgd, address) >= 0)325return 1;326/*327* Don't take the mm semaphore here. If we fixup a prefetch328* fault we could otherwise deadlock.329*/330mm = NULL; /* happy compiler */331vma = NULL;332goto bad_area_nosemaphore;333}334335/*336* If we're trying to touch user-space addresses, we must337* be either at PL0, or else with interrupts enabled in the338* kernel, so either way we can re-enable interrupts here.339*/340local_irq_enable();341342mm = tsk->mm;343344/*345* If we're in an interrupt, have no user context or are running in an346* atomic region then we must not take the fault.347*/348if (in_atomic() || !mm) {349vma = NULL; /* happy compiler */350goto bad_area_nosemaphore;351}352353/*354* When running in the kernel we expect faults to occur only to355* addresses in user space. All other faults represent errors in the356* kernel and should generate an OOPS. Unfortunately, in the case of an357* erroneous fault occurring in a code path which already holds mmap_sem358* we will deadlock attempting to validate the fault against the359* address space. Luckily the kernel only validly references user360* space from well defined areas of code, which are listed in the361* exceptions table.362*363* As the vast majority of faults will be valid we will only perform364* the source reference check when there is a possibility of a deadlock.365* Attempt to lock the address space, if we cannot we then validate the366* source. If this is invalid we can skip the address space check,367* thus avoiding the deadlock.368*/369if (!down_read_trylock(&mm->mmap_sem)) {370if (is_kernel_mode &&371!search_exception_tables(regs->pc)) {372vma = NULL; /* happy compiler */373goto bad_area_nosemaphore;374}375down_read(&mm->mmap_sem);376}377378vma = find_vma(mm, address);379if (!vma)380goto bad_area;381if (vma->vm_start <= address)382goto good_area;383if (!(vma->vm_flags & VM_GROWSDOWN))384goto bad_area;385if (regs->sp < PAGE_OFFSET) {386/*387* accessing the stack below sp is always a bug.388*/389if (address < regs->sp)390goto bad_area;391}392if (expand_stack(vma, address))393goto bad_area;394395/*396* Ok, we have a good vm_area for this memory access, so397* we can handle it..398*/399good_area:400si_code = SEGV_ACCERR;401if (fault_num == INT_ITLB_MISS) {402if (!(vma->vm_flags & VM_EXEC))403goto bad_area;404} else if (write) {405#ifdef TEST_VERIFY_AREA406if (!is_page_fault && regs->cs == KERNEL_CS)407pr_err("WP fault at "REGFMT"\n", regs->eip);408#endif409if (!(vma->vm_flags & VM_WRITE))410goto bad_area;411} else {412if (!is_page_fault || !(vma->vm_flags & VM_READ))413goto bad_area;414}415416survive:417/*418* If for any reason at all we couldn't handle the fault,419* make sure we exit gracefully rather than endlessly redo420* the fault.421*/422fault = handle_mm_fault(mm, vma, address, write);423if (unlikely(fault & VM_FAULT_ERROR)) {424if (fault & VM_FAULT_OOM)425goto out_of_memory;426else if (fault & VM_FAULT_SIGBUS)427goto do_sigbus;428BUG();429}430if (fault & VM_FAULT_MAJOR)431tsk->maj_flt++;432else433tsk->min_flt++;434435#if CHIP_HAS_TILE_DMA() || CHIP_HAS_SN_PROC()436/*437* If this was an asynchronous fault,438* restart the appropriate engine.439*/440switch (fault_num) {441#if CHIP_HAS_TILE_DMA()442case INT_DMATLB_MISS:443case INT_DMATLB_MISS_DWNCL:444case INT_DMATLB_ACCESS:445case INT_DMATLB_ACCESS_DWNCL:446__insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__REQUEST_MASK);447break;448#endif449#if CHIP_HAS_SN_PROC()450case INT_SNITLB_MISS:451case INT_SNITLB_MISS_DWNCL:452__insn_mtspr(SPR_SNCTL,453__insn_mfspr(SPR_SNCTL) &454~SPR_SNCTL__FRZPROC_MASK);455break;456#endif457}458#endif459460up_read(&mm->mmap_sem);461return 1;462463/*464* Something tried to access memory that isn't in our memory map..465* Fix it, but check if it's kernel or user first..466*/467bad_area:468up_read(&mm->mmap_sem);469470bad_area_nosemaphore:471/* User mode accesses just cause a SIGSEGV */472if (!is_kernel_mode) {473/*474* It's possible to have interrupts off here.475*/476local_irq_enable();477478force_sig_info_fault("segfault", SIGSEGV, si_code, address,479fault_num, tsk, regs);480return 0;481}482483no_context:484/* Are we prepared to handle this kernel fault? */485if (fixup_exception(regs))486return 0;487488/*489* Oops. The kernel tried to access some bad page. We'll have to490* terminate things with extreme prejudice.491*/492493bust_spinlocks(1);494495/* FIXME: no lookup_address() yet */496#ifdef SUPPORT_LOOKUP_ADDRESS497if (fault_num == INT_ITLB_MISS) {498pte_t *pte = lookup_address(address);499500if (pte && pte_present(*pte) && !pte_exec_kernel(*pte))501pr_crit("kernel tried to execute"502" non-executable page - exploit attempt?"503" (uid: %d)\n", current->uid);504}505#endif506if (address < PAGE_SIZE)507pr_alert("Unable to handle kernel NULL pointer dereference\n");508else509pr_alert("Unable to handle kernel paging request\n");510pr_alert(" at virtual address "REGFMT", pc "REGFMT"\n",511address, regs->pc);512513show_regs(regs);514515if (unlikely(tsk->pid < 2)) {516panic("Kernel page fault running %s!",517tsk->pid ? "init" : "the idle task");518}519520/*521* More FIXME: we should probably copy the i386 here and522* implement a generic die() routine. Not today.523*/524#ifdef SUPPORT_DIE525die("Oops", regs);526#endif527bust_spinlocks(1);528529do_group_exit(SIGKILL);530531/*532* We ran out of memory, or some other thing happened to us that made533* us unable to handle the page fault gracefully.534*/535out_of_memory:536up_read(&mm->mmap_sem);537if (is_global_init(tsk)) {538yield();539down_read(&mm->mmap_sem);540goto survive;541}542pr_alert("VM: killing process %s\n", tsk->comm);543if (!is_kernel_mode)544do_group_exit(SIGKILL);545goto no_context;546547do_sigbus:548up_read(&mm->mmap_sem);549550/* Kernel mode? Handle exceptions or die */551if (is_kernel_mode)552goto no_context;553554force_sig_info_fault("bus error", SIGBUS, BUS_ADRERR, address,555fault_num, tsk, regs);556return 0;557}558559#ifndef __tilegx__560561/* We must release ICS before panicking or we won't get anywhere. */562#define ics_panic(fmt, ...) do { \563__insn_mtspr(SPR_INTERRUPT_CRITICAL_SECTION, 0); \564panic(fmt, __VA_ARGS__); \565} while (0)566567/*568* When we take an ITLB or DTLB fault or access violation in the569* supervisor while the critical section bit is set, the hypervisor is570* reluctant to write new values into the EX_CONTEXT_K_x registers,571* since that might indicate we have not yet squirreled the SPR572* contents away and can thus safely take a recursive interrupt.573* Accordingly, the hypervisor passes us the PC via SYSTEM_SAVE_K_2.574*575* Note that this routine is called before homecache_tlb_defer_enter(),576* which means that we can properly unlock any atomics that might577* be used there (good), but also means we must be very sensitive578* to not touch any data structures that might be located in memory579* that could migrate, as we could be entering the kernel on a dataplane580* cpu that has been deferring kernel TLB updates. This means, for581* example, that we can't migrate init_mm or its pgd.582*/583struct intvec_state do_page_fault_ics(struct pt_regs *regs, int fault_num,584unsigned long address,585unsigned long info)586{587unsigned long pc = info & ~1;588int write = info & 1;589pgd_t *pgd = get_current_pgd();590591/* Retval is 1 at first since we will handle the fault fully. */592struct intvec_state state = {593do_page_fault, fault_num, address, write, 1594};595596/* Validate that we are plausibly in the right routine. */597if ((pc & 0x7) != 0 || pc < PAGE_OFFSET ||598(fault_num != INT_DTLB_MISS &&599fault_num != INT_DTLB_ACCESS)) {600unsigned long old_pc = regs->pc;601regs->pc = pc;602ics_panic("Bad ICS page fault args:"603" old PC %#lx, fault %d/%d at %#lx\n",604old_pc, fault_num, write, address);605}606607/* We might be faulting on a vmalloc page, so check that first. */608if (fault_num != INT_DTLB_ACCESS && vmalloc_fault(pgd, address) >= 0)609return state;610611/*612* If we faulted with ICS set in sys_cmpxchg, we are providing613* a user syscall service that should generate a signal on614* fault. We didn't set up a kernel stack on initial entry to615* sys_cmpxchg, but instead had one set up by the fault, which616* (because sys_cmpxchg never releases ICS) came to us via the617* SYSTEM_SAVE_K_2 mechanism, and thus EX_CONTEXT_K_[01] are618* still referencing the original user code. We release the619* atomic lock and rewrite pt_regs so that it appears that we620* came from user-space directly, and after we finish the621* fault we'll go back to user space and re-issue the swint.622* This way the backtrace information is correct if we need to623* emit a stack dump at any point while handling this.624*625* Must match register use in sys_cmpxchg().626*/627if (pc >= (unsigned long) sys_cmpxchg &&628pc < (unsigned long) __sys_cmpxchg_end) {629#ifdef CONFIG_SMP630/* Don't unlock before we could have locked. */631if (pc >= (unsigned long)__sys_cmpxchg_grab_lock) {632int *lock_ptr = (int *)(regs->regs[ATOMIC_LOCK_REG]);633__atomic_fault_unlock(lock_ptr);634}635#endif636regs->sp = regs->regs[27];637}638639/*640* We can also fault in the atomic assembly, in which641* case we use the exception table to do the first-level fixup.642* We may re-fixup again in the real fault handler if it643* turns out the faulting address is just bad, and not,644* for example, migrating.645*/646else if (pc >= (unsigned long) __start_atomic_asm_code &&647pc < (unsigned long) __end_atomic_asm_code) {648const struct exception_table_entry *fixup;649#ifdef CONFIG_SMP650/* Unlock the atomic lock. */651int *lock_ptr = (int *)(regs->regs[ATOMIC_LOCK_REG]);652__atomic_fault_unlock(lock_ptr);653#endif654fixup = search_exception_tables(pc);655if (!fixup)656ics_panic("ICS atomic fault not in table:"657" PC %#lx, fault %d", pc, fault_num);658regs->pc = fixup->fixup;659regs->ex1 = PL_ICS_EX1(KERNEL_PL, 0);660}661662/*663* Now that we have released the atomic lock (if necessary),664* it's safe to spin if the PTE that caused the fault was migrating.665*/666if (fault_num == INT_DTLB_ACCESS)667write = 1;668if (handle_migrating_pte(pgd, fault_num, address, 1, write))669return state;670671/* Return zero so that we continue on with normal fault handling. */672state.retval = 0;673return state;674}675676#endif /* !__tilegx__ */677678/*679* This routine handles page faults. It determines the address, and the680* problem, and then passes it handle_page_fault() for normal DTLB and681* ITLB issues, and for DMA or SN processor faults when we are in user682* space. For the latter, if we're in kernel mode, we just save the683* interrupt away appropriately and return immediately. We can't do684* page faults for user code while in kernel mode.685*/686void do_page_fault(struct pt_regs *regs, int fault_num,687unsigned long address, unsigned long write)688{689int is_page_fault;690691/* This case should have been handled by do_page_fault_ics(). */692BUG_ON(write & ~1);693694#if CHIP_HAS_TILE_DMA()695/*696* If it's a DMA fault, suspend the transfer while we're697* handling the miss; we'll restart after it's handled. If we698* don't suspend, it's possible that this process could swap699* out and back in, and restart the engine since the DMA is700* still 'running'.701*/702if (fault_num == INT_DMATLB_MISS ||703fault_num == INT_DMATLB_ACCESS ||704fault_num == INT_DMATLB_MISS_DWNCL ||705fault_num == INT_DMATLB_ACCESS_DWNCL) {706__insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__SUSPEND_MASK);707while (__insn_mfspr(SPR_DMA_USER_STATUS) &708SPR_DMA_STATUS__BUSY_MASK)709;710}711#endif712713/* Validate fault num and decide if this is a first-time page fault. */714switch (fault_num) {715case INT_ITLB_MISS:716case INT_DTLB_MISS:717#if CHIP_HAS_TILE_DMA()718case INT_DMATLB_MISS:719case INT_DMATLB_MISS_DWNCL:720#endif721#if CHIP_HAS_SN_PROC()722case INT_SNITLB_MISS:723case INT_SNITLB_MISS_DWNCL:724#endif725is_page_fault = 1;726break;727728case INT_DTLB_ACCESS:729#if CHIP_HAS_TILE_DMA()730case INT_DMATLB_ACCESS:731case INT_DMATLB_ACCESS_DWNCL:732#endif733is_page_fault = 0;734break;735736default:737panic("Bad fault number %d in do_page_fault", fault_num);738}739740#if CHIP_HAS_TILE_DMA() || CHIP_HAS_SN_PROC()741if (EX1_PL(regs->ex1) != USER_PL) {742struct async_tlb *async;743switch (fault_num) {744#if CHIP_HAS_TILE_DMA()745case INT_DMATLB_MISS:746case INT_DMATLB_ACCESS:747case INT_DMATLB_MISS_DWNCL:748case INT_DMATLB_ACCESS_DWNCL:749async = ¤t->thread.dma_async_tlb;750break;751#endif752#if CHIP_HAS_SN_PROC()753case INT_SNITLB_MISS:754case INT_SNITLB_MISS_DWNCL:755async = ¤t->thread.sn_async_tlb;756break;757#endif758default:759async = NULL;760}761if (async) {762763/*764* No vmalloc check required, so we can allow765* interrupts immediately at this point.766*/767local_irq_enable();768769set_thread_flag(TIF_ASYNC_TLB);770if (async->fault_num != 0) {771panic("Second async fault %d;"772" old fault was %d (%#lx/%ld)",773fault_num, async->fault_num,774address, write);775}776BUG_ON(fault_num == 0);777async->fault_num = fault_num;778async->is_fault = is_page_fault;779async->is_write = write;780async->address = address;781return;782}783}784#endif785786handle_page_fault(regs, fault_num, is_page_fault, address, write);787}788789790#if CHIP_HAS_TILE_DMA() || CHIP_HAS_SN_PROC()791/*792* Check an async_tlb structure to see if a deferred fault is waiting,793* and if so pass it to the page-fault code.794*/795static void handle_async_page_fault(struct pt_regs *regs,796struct async_tlb *async)797{798if (async->fault_num) {799/*800* Clear async->fault_num before calling the page-fault801* handler so that if we re-interrupt before returning802* from the function we have somewhere to put the803* information from the new interrupt.804*/805int fault_num = async->fault_num;806async->fault_num = 0;807handle_page_fault(regs, fault_num, async->is_fault,808async->address, async->is_write);809}810}811812/*813* This routine effectively re-issues asynchronous page faults814* when we are returning to user space.815*/816void do_async_page_fault(struct pt_regs *regs)817{818/*819* Clear thread flag early. If we re-interrupt while processing820* code here, we will reset it and recall this routine before821* returning to user space.822*/823clear_thread_flag(TIF_ASYNC_TLB);824825#if CHIP_HAS_TILE_DMA()826handle_async_page_fault(regs, ¤t->thread.dma_async_tlb);827#endif828#if CHIP_HAS_SN_PROC()829handle_async_page_fault(regs, ¤t->thread.sn_async_tlb);830#endif831}832#endif /* CHIP_HAS_TILE_DMA() || CHIP_HAS_SN_PROC() */833834835void vmalloc_sync_all(void)836{837#ifdef __tilegx__838/* Currently all L1 kernel pmd's are static and shared. */839BUG_ON(pgd_index(VMALLOC_END) != pgd_index(VMALLOC_START));840#else841/*842* Note that races in the updates of insync and start aren't843* problematic: insync can only get set bits added, and updates to844* start are only improving performance (without affecting correctness845* if undone).846*/847static DECLARE_BITMAP(insync, PTRS_PER_PGD);848static unsigned long start = PAGE_OFFSET;849unsigned long address;850851BUILD_BUG_ON(PAGE_OFFSET & ~PGDIR_MASK);852for (address = start; address >= PAGE_OFFSET; address += PGDIR_SIZE) {853if (!test_bit(pgd_index(address), insync)) {854unsigned long flags;855struct list_head *pos;856857spin_lock_irqsave(&pgd_lock, flags);858list_for_each(pos, &pgd_list)859if (!vmalloc_sync_one(list_to_pgd(pos),860address)) {861/* Must be at first entry in list. */862BUG_ON(pos != pgd_list.next);863break;864}865spin_unlock_irqrestore(&pgd_lock, flags);866if (pos != pgd_list.next)867set_bit(pgd_index(address), insync);868}869if (address == start && test_bit(pgd_index(address), insync))870start = address + PGDIR_SIZE;871}872#endif873}874875876