···6666 printk(KERN_ALERT "pgd = %p\n", pgd);6767 pgd += pgd_index(addr);6868 printk(KERN_ALERT "[%08lx] *pgd=%0*Lx", addr,6969- sizeof(*pgd) * 2, (u64)pgd_val(*pgd));6969+ (u32)(sizeof(*pgd) * 2), (u64)pgd_val(*pgd));70707171 do {7272 pud_t *pud;···83838484 pud = pud_offset(pgd, addr);8585 if (PTRS_PER_PUD != 1)8686- printk(", *pud=%0*Lx", sizeof(*pud) * 2,8686+ printk(", *pud=%0*Lx", (u32)(sizeof(*pud) * 2),8787 (u64)pud_val(*pud));88888989 if (pud_none(*pud))···96969797 pmd = pmd_offset(pud, addr);9898 if (PTRS_PER_PMD != 1)9999- printk(", *pmd=%0*Lx", sizeof(*pmd) * 2,9999+ printk(", *pmd=%0*Lx", (u32)(sizeof(*pmd) * 2),100100 (u64)pmd_val(*pmd));101101102102 if (pmd_none(*pmd))···112112 break;113113114114 pte = pte_offset_kernel(pmd, addr);115115- printk(", *pte=%0*Lx", sizeof(*pte) * 2, (u64)pte_val(*pte));115115+ printk(", *pte=%0*Lx", (u32)(sizeof(*pte) * 2),116116+ (u64)pte_val(*pte));116117 } while (0);117118118119 printk("\n");···355354 return 1;356355}357356358358-static inline int access_error(int write, struct vm_area_struct *vma)357357+static inline int access_error(int error_code, struct vm_area_struct *vma)359358{360360- if (write) {359359+ if (error_code & FAULT_CODE_WRITE) {361360 /* write, present and write, not present: */362361 if (unlikely(!(vma->vm_flags & VM_WRITE)))363362 return 1;364363 return 0;365364 }365365+366366+ /* ITLB miss on NX page */367367+ if (unlikely((error_code & FAULT_CODE_ITLB) &&368368+ !(vma->vm_flags & VM_EXEC)))369369+ return 1;366370367371 /* read, not present: */368372 if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))))···505499 }506500507501 up_read(&mm->mmap_sem);508508-}509509-510510-/*511511- * Called with interrupts disabled.512512- */513513-asmlinkage int __kprobes514514-handle_tlbmiss(struct pt_regs *regs, unsigned long error_code,515515- unsigned long address)516516-{517517- pgd_t *pgd;518518- pud_t *pud;519519- pmd_t *pmd;520520- pte_t *pte;521521- pte_t entry;522522-523523- /*524524- * We don't take page faults for P1, P2, and parts of P4, these525525- * are always mapped, whether it be due to legacy behaviour in526526- * 29-bit mode, or due to PMB configuration in 32-bit mode.527527- */528528- if (address >= P3SEG && address < P3_ADDR_MAX) {529529- pgd = pgd_offset_k(address);530530- } else {531531- if (unlikely(address >= TASK_SIZE || !current->mm))532532- return 1;533533-534534- pgd = pgd_offset(current->mm, address);535535- }536536-537537- pud = pud_offset(pgd, address);538538- if (pud_none_or_clear_bad(pud))539539- return 1;540540- pmd = pmd_offset(pud, address);541541- if (pmd_none_or_clear_bad(pmd))542542- return 1;543543- pte = pte_offset_kernel(pmd, address);544544- entry = *pte;545545- if (unlikely(pte_none(entry) || pte_not_present(entry)))546546- return 1;547547- if (unlikely(error_code && !pte_write(entry)))548548- return 1;549549-550550- if (error_code)551551- entry = pte_mkdirty(entry);552552- entry = pte_mkyoung(entry);553553-554554- set_pte(pte, entry);555555-556556-#if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SMP)557557- /*558558- * SH-4 does not set MMUCR.RC to the corresponding TLB entry in559559- * the case of an initial page write exception, so we need to560560- * flush it in order to avoid potential TLB entry duplication.561561- */562562- if (error_code == FAULT_CODE_INITIAL)563563- local_flush_tlb_one(get_asid(), address & PAGE_MASK);564564-#endif565565-566566- set_thread_fault_code(error_code);567567- update_mmu_cache(NULL, address, pte);568568-569569- return 0;570502}
+1-1
arch/sh/mm/fault_64.c
arch/sh/mm/tlbex_64.c
···246246 tsk = current;247247 mm = tsk->mm;248248249249- if ((address >= VMALLOC_START && address < VMALLOC_END)) {249249+ if (is_vmalloc_addr((void *)address)) {250250 if (ssr_md)251251 /*252252 * Process-contexts can never have this address
+78
arch/sh/mm/tlbex_32.c
···11+/*22+ * TLB miss handler for SH with an MMU.33+ *44+ * Copyright (C) 1999 Niibe Yutaka55+ * Copyright (C) 2003 - 2012 Paul Mundt66+ *77+ * This file is subject to the terms and conditions of the GNU General Public88+ * License. See the file "COPYING" in the main directory of this archive99+ * for more details.1010+ */1111+#include <linux/kernel.h>1212+#include <linux/mm.h>1313+#include <linux/kprobes.h>1414+#include <linux/kdebug.h>1515+#include <asm/mmu_context.h>1616+#include <asm/thread_info.h>1717+1818+/*1919+ * Called with interrupts disabled.2020+ */2121+asmlinkage int __kprobes2222+handle_tlbmiss(struct pt_regs *regs, unsigned long error_code,2323+ unsigned long address)2424+{2525+ pgd_t *pgd;2626+ pud_t *pud;2727+ pmd_t *pmd;2828+ pte_t *pte;2929+ pte_t entry;3030+3131+ /*3232+ * We don't take page faults for P1, P2, and parts of P4, these3333+ * are always mapped, whether it be due to legacy behaviour in3434+ * 29-bit mode, or due to PMB configuration in 32-bit mode.3535+ */3636+ if (address >= P3SEG && address < P3_ADDR_MAX) {3737+ pgd = pgd_offset_k(address);3838+ } else {3939+ if (unlikely(address >= TASK_SIZE || !current->mm))4040+ return 1;4141+4242+ pgd = pgd_offset(current->mm, address);4343+ }4444+4545+ pud = pud_offset(pgd, address);4646+ if (pud_none_or_clear_bad(pud))4747+ return 1;4848+ pmd = pmd_offset(pud, address);4949+ if (pmd_none_or_clear_bad(pmd))5050+ return 1;5151+ pte = pte_offset_kernel(pmd, address);5252+ entry = *pte;5353+ if (unlikely(pte_none(entry) || pte_not_present(entry)))5454+ return 1;5555+ if (unlikely(error_code && !pte_write(entry)))5656+ return 1;5757+5858+ if (error_code)5959+ entry = pte_mkdirty(entry);6060+ entry = pte_mkyoung(entry);6161+6262+ set_pte(pte, entry);6363+6464+#if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SMP)6565+ /*6666+ * SH-4 does not set MMUCR.RC to the corresponding TLB entry in6767+ * the case of an initial page write exception, so we need to6868+ * flush it in order to avoid potential TLB entry duplication.6969+ */7070+ if (error_code == FAULT_CODE_INITIAL)7171+ local_flush_tlb_one(get_asid(), address & PAGE_MASK);7272+#endif7373+7474+ set_thread_fault_code(error_code);7575+ update_mmu_cache(NULL, address, pte);7676+7777+ return 0;7878+}
-243
arch/sh/mm/tlbflush_64.c
···2828#include <asm/pgalloc.h>2929#include <asm/mmu_context.h>30303131-static pte_t *lookup_pte(struct mm_struct *mm, unsigned long address)3232-{3333- pgd_t *dir;3434- pud_t *pud;3535- pmd_t *pmd;3636- pte_t *pte;3737- pte_t entry;3838-3939- dir = pgd_offset(mm, address);4040- if (pgd_none(*dir))4141- return NULL;4242-4343- pud = pud_offset(dir, address);4444- if (pud_none(*pud))4545- return NULL;4646-4747- pmd = pmd_offset(pud, address);4848- if (pmd_none(*pmd))4949- return NULL;5050-5151- pte = pte_offset_kernel(pmd, address);5252- entry = *pte;5353- if (pte_none(entry) || !pte_present(entry))5454- return NULL;5555-5656- return pte;5757-}5858-5959-/*6060- * This routine handles page faults. It determines the address,6161- * and the problem, and then passes it off to one of the appropriate6262- * routines.6363- */6464-asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code,6565- unsigned long address)6666-{6767- struct task_struct *tsk;6868- struct mm_struct *mm;6969- struct vm_area_struct * vma;7070- const struct exception_table_entry *fixup;7171- int write = error_code & FAULT_CODE_WRITE;7272- int textaccess = error_code & FAULT_CODE_ITLB;7373- unsigned int flags = (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |7474- (write ? FAULT_FLAG_WRITE : 0));7575- pte_t *pte;7676- int fault;7777-7878- /* SIM7979- * Note this is now called with interrupts still disabled8080- * This is to cope with being called for a missing IO port8181- * address with interrupts disabled. This should be fixed as8282- * soon as we have a better 'fast path' miss handler.8383- *8484- * Plus take care how you try and debug this stuff.8585- * For example, writing debug data to a port which you8686- * have just faulted on is not going to work.8787- */8888-8989- tsk = current;9090- mm = tsk->mm;9191-9292- /* Not an IO address, so reenable interrupts */9393- local_irq_enable();9494-9595- perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);9696-9797- /*9898- * If we're in an interrupt or have no user9999- * context, we must not take the fault..100100- */101101- if (in_atomic() || !mm)102102- goto no_context;103103-104104-retry:105105- /* TLB misses upon some cache flushes get done under cli() */106106- down_read(&mm->mmap_sem);107107-108108- vma = find_vma(mm, address);109109- if (!vma)110110- goto bad_area;111111- if (vma->vm_start <= address)112112- goto good_area;113113- if (!(vma->vm_flags & VM_GROWSDOWN))114114- goto bad_area;115115- if (expand_stack(vma, address))116116- goto bad_area;117117-118118-/*119119- * Ok, we have a good vm_area for this memory access, so120120- * we can handle it..121121- */122122-good_area:123123- if (textaccess) {124124- if (!(vma->vm_flags & VM_EXEC))125125- goto bad_area;126126- } else {127127- if (write) {128128- if (!(vma->vm_flags & VM_WRITE))129129- goto bad_area;130130- } else {131131- if (!(vma->vm_flags & VM_READ))132132- goto bad_area;133133- }134134- }135135-136136- /*137137- * If for any reason at all we couldn't handle the fault,138138- * make sure we exit gracefully rather than endlessly redo139139- * the fault.140140- */141141- fault = handle_mm_fault(mm, vma, address, flags);142142-143143- if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))144144- return;145145-146146- if (unlikely(fault & VM_FAULT_ERROR)) {147147- if (fault & VM_FAULT_OOM)148148- goto out_of_memory;149149- else if (fault & VM_FAULT_SIGBUS)150150- goto do_sigbus;151151- BUG();152152- }153153-154154- if (flags & FAULT_FLAG_ALLOW_RETRY) {155155- if (fault & VM_FAULT_MAJOR) {156156- tsk->maj_flt++;157157- perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1,158158- regs, address);159159- } else {160160- tsk->min_flt++;161161- perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1,162162- regs, address);163163- }164164-165165- if (fault & VM_FAULT_RETRY) {166166- flags &= ~FAULT_FLAG_ALLOW_RETRY;167167-168168- /*169169- * No need to up_read(&mm->mmap_sem) as we would170170- * have already released it in __lock_page_or_retry171171- * in mm/filemap.c.172172- */173173- goto retry;174174- }175175- }176176-177177- /* If we get here, the page fault has been handled. Do the TLB refill178178- now from the newly-setup PTE, to avoid having to fault again right179179- away on the same instruction. */180180- pte = lookup_pte (mm, address);181181- if (!pte) {182182- /* From empirical evidence, we can get here, due to183183- !pte_present(pte). (e.g. if a swap-in occurs, and the page184184- is swapped back out again before the process that wanted it185185- gets rescheduled?) */186186- goto no_pte;187187- }188188-189189- __do_tlb_refill(address, textaccess, pte);190190-191191-no_pte:192192-193193- up_read(&mm->mmap_sem);194194- return;195195-196196-/*197197- * Something tried to access memory that isn't in our memory map..198198- * Fix it, but check if it's kernel or user first..199199- */200200-bad_area:201201- up_read(&mm->mmap_sem);202202-203203- if (user_mode(regs)) {204204- static int count=0;205205- siginfo_t info;206206- if (count < 4) {207207- /* This is really to help debug faults when starting208208- * usermode, so only need a few */209209- count++;210210- printk("user mode bad_area address=%08lx pid=%d (%s) pc=%08lx\n",211211- address, task_pid_nr(current), current->comm,212212- (unsigned long) regs->pc);213213- }214214- if (is_global_init(tsk)) {215215- panic("INIT had user mode bad_area\n");216216- }217217- tsk->thread.address = address;218218- info.si_signo = SIGSEGV;219219- info.si_errno = 0;220220- info.si_addr = (void *) address;221221- force_sig_info(SIGSEGV, &info, tsk);222222- return;223223- }224224-225225-no_context:226226- /* Are we prepared to handle this kernel fault? */227227- fixup = search_exception_tables(regs->pc);228228- if (fixup) {229229- regs->pc = fixup->fixup;230230- return;231231- }232232-233233-/*234234- * Oops. The kernel tried to access some bad page. We'll have to235235- * terminate things with extreme prejudice.236236- *237237- */238238- if (address < PAGE_SIZE)239239- printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");240240- else241241- printk(KERN_ALERT "Unable to handle kernel paging request");242242- printk(" at virtual address %08lx\n", address);243243- printk(KERN_ALERT "pc = %08Lx%08Lx\n", regs->pc >> 32, regs->pc & 0xffffffff);244244- die("Oops", regs, error_code);245245- do_exit(SIGKILL);246246-247247-/*248248- * We ran out of memory, or some other thing happened to us that made249249- * us unable to handle the page fault gracefully.250250- */251251-out_of_memory:252252- up_read(&mm->mmap_sem);253253- if (!user_mode(regs))254254- goto no_context;255255- pagefault_out_of_memory();256256- return;257257-258258-do_sigbus:259259- printk("fault:Do sigbus\n");260260- up_read(&mm->mmap_sem);261261-262262- /*263263- * Send a sigbus, regardless of whether we were in kernel264264- * or user mode.265265- */266266- tsk->thread.address = address;267267- force_sig(SIGBUS, tsk);268268-269269- /* Kernel mode? Handle exceptions or die */270270- if (!user_mode(regs))271271- goto no_context;272272-}273273-27431void local_flush_tlb_one(unsigned long asid, unsigned long page)27532{27633 unsigned long long match, pteh=0, lpage;