Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * arch/sparc64/mm/fault.c: Page fault handlers for the 64-bit Sparc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 1997, 1999 Jakub Jelinek (jj@ultra.linux.cz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <asm/head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/extable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/kprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/kdebug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/context_tracking.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <asm/openprom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <asm/asi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <asm/lsu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) int show_unhandled_signals = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static void __kprobes unhandled_fault(unsigned long address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 				      struct task_struct *tsk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 				      struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if ((unsigned long) address < PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		printk(KERN_ALERT "Unable to handle kernel NULL "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		       "pointer dereference\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		printk(KERN_ALERT "Unable to handle kernel paging request "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		       "at virtual address %016lx\n", (unsigned long)address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	printk(KERN_ALERT "tsk->{mm,active_mm}->context = %016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	       (tsk->mm ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		CTX_HWBITS(tsk->mm->context) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		CTX_HWBITS(tsk->active_mm->context)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	printk(KERN_ALERT "tsk->{mm,active_mm}->pgd = %016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	       (tsk->mm ? (unsigned long) tsk->mm->pgd :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		          (unsigned long) tsk->active_mm->pgd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	die_if_kernel("Oops", regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	       regs->tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unhandled_fault(regs->tpc, current, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * We now make sure that mmap_lock is held in all paths that call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * this. Additionally, to prevent kswapd from ripping ptes from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * under us, raise interrupts around the time that we look at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * pte, kswapd will have to wait to get his smp ipi response from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * us. vmtruncate likewise. This saves us having to get pte lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static unsigned int get_user_insn(unsigned long tpc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	pgd_t *pgdp = pgd_offset(current->mm, tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	p4d_t *p4dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	pud_t *pudp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	pmd_t *pmdp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	pte_t *ptep, pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	unsigned long pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	u32 insn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (pgd_none(*pgdp) || unlikely(pgd_bad(*pgdp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	p4dp = p4d_offset(pgdp, tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (p4d_none(*p4dp) || unlikely(p4d_bad(*p4dp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	pudp = pud_offset(p4dp, tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (pud_none(*pudp) || unlikely(pud_bad(*pudp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	/* This disables preemption for us as well. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	pmdp = pmd_offset(pudp, tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (pmd_none(*pmdp) || unlikely(pmd_bad(*pmdp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		goto out_irq_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (is_hugetlb_pmd(*pmdp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		pa  = pmd_pfn(*pmdp) << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		pa += tpc & ~HPAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		/* Use phys bypass so we don't pollute dtlb/dcache. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		__asm__ __volatile__("lduwa [%1] %2, %0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				     : "=r" (insn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 				     : "r" (pa), "i" (ASI_PHYS_USE_EC));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		ptep = pte_offset_map(pmdp, tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		pte = *ptep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		if (pte_present(pte)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			pa  = (pte_pfn(pte) << PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			pa += (tpc & ~PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			/* Use phys bypass so we don't pollute dtlb/dcache. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			__asm__ __volatile__("lduwa [%1] %2, %0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 					     : "=r" (insn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 					     : "r" (pa), "i" (ASI_PHYS_USE_EC));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		pte_unmap(ptep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) out_irq_enable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) show_signal_msg(struct pt_regs *regs, int sig, int code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		unsigned long address, struct task_struct *tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (!unhandled_signal(tsk, sig))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	printk("%s%s[%d]: segfault at %lx ip %px (rpc %px) sp %px error %x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	       task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	       tsk->comm, task_pid_nr(tsk), address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	       (void *)regs->tpc, (void *)regs->u_regs[UREG_I7],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	       (void *)regs->u_regs[UREG_FP], code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	print_vma_addr(KERN_CONT " in ", regs->tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	printk(KERN_CONT "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			     unsigned long fault_addr, unsigned int insn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			     int fault_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (fault_code & FAULT_CODE_ITLB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		addr = regs->tpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		/* If we were able to probe the faulting instruction, use it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		 * to compute a precise fault address.  Otherwise use the fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		 * time provided address which may only have page granularity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		if (insn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			addr = compute_effective_address(regs, insn, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			addr = fault_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (unlikely(show_unhandled_signals))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		show_signal_msg(regs, sig, code, addr, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	force_sig_fault(sig, code, (void __user *) addr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static unsigned int get_fault_insn(struct pt_regs *regs, unsigned int insn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!insn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		if (!regs->tpc || (regs->tpc & 0x3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		if (regs->tstate & TSTATE_PRIV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			insn = *(unsigned int *) regs->tpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			insn = get_user_insn(regs->tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static void __kprobes do_kernel_fault(struct pt_regs *regs, int si_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				      int fault_code, unsigned int insn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				      unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	unsigned char asi = ASI_P;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if ((!insn) && (regs->tstate & TSTATE_PRIV))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		goto cannot_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	/* If user insn could be read (thus insn is zero), that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	 * is fine.  We will just gun down the process with a signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	 * in that case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (!(fault_code & (FAULT_CODE_WRITE|FAULT_CODE_ITLB)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	    (insn & 0xc0800000) == 0xc0800000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		if (insn & 0x2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			asi = (regs->tstate >> 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			asi = (insn >> 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if ((asi & 0xf2) == 0x82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			if (insn & 0x1000000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 				handle_ldf_stq(insn, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 				/* This was a non-faulting load. Just clear the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 				 * destination register(s) and continue with the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				 * instruction. -jj
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				handle_ld_nf(insn, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	/* Is this in ex_table? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (regs->tstate & TSTATE_PRIV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		const struct exception_table_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		entry = search_exception_tables(regs->tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if (entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			regs->tpc = entry->fixup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			regs->tnpc = regs->tpc + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		/* The si_code was set to make clear whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		 * this was a SEGV_MAPERR or SEGV_ACCERR fault.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		do_fault_siginfo(si_code, SIGSEGV, regs, address, insn, fault_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) cannot_handle:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	unhandled_fault (address, current, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	static int times;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (times++ < 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		printk(KERN_ERR "FAULT[%s:%d]: 32-bit process reports "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		       "64-bit TPC [%lx]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		       current->comm, current->pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		       regs->tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	show_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	enum ctx_state prev_state = exception_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct mm_struct *mm = current->mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct vm_area_struct *vma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	unsigned int insn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	int si_code, fault_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	vm_fault_t fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	unsigned long address, mm_rss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	unsigned int flags = FAULT_FLAG_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	fault_code = get_thread_fault_code();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (kprobe_page_fault(regs, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		goto exit_exception;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	si_code = SEGV_MAPERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	address = current_thread_info()->fault_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if ((fault_code & FAULT_CODE_ITLB) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	    (fault_code & FAULT_CODE_DTLB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (test_thread_flag(TIF_32BIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		if (!(regs->tstate & TSTATE_PRIV)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			if (unlikely((regs->tpc >> 32) != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 				bogus_32bit_fault_tpc(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 				goto intr_or_no_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		if (unlikely((address >> 32) != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			goto intr_or_no_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (regs->tstate & TSTATE_PRIV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		unsigned long tpc = regs->tpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		/* Sanity check the PC. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		if ((tpc >= KERNBASE && tpc < (unsigned long) __init_end) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		    (tpc >= MODULES_VADDR && tpc < MODULES_END)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			/* Valid, no problems... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			bad_kernel_pc(regs, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			goto exit_exception;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		flags |= FAULT_FLAG_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	 * If we're in an interrupt or have no user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	 * context, we must not take the fault..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (faulthandler_disabled() || !mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		goto intr_or_no_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (!mmap_read_trylock(mm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		if ((regs->tstate & TSTATE_PRIV) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		    !search_exception_tables(regs->tpc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			insn = get_fault_insn(regs, insn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			goto handle_kernel_fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		mmap_read_lock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (fault_code & FAULT_CODE_BAD_RA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		goto do_sigbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	vma = find_vma(mm, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (!vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		goto bad_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	/* Pure DTLB misses do not tell us whether the fault causing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	 * load/store/atomic was a write or not, it only says that there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	 * was no match.  So in such a case we (carefully) read the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	 * instruction to try and figure this out.  It's an optimization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	 * so it's ok if we can't do this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 * Special hack, window spill/fill knows the exact fault type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (((fault_code &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	      (FAULT_CODE_DTLB | FAULT_CODE_WRITE | FAULT_CODE_WINFIXUP)) == FAULT_CODE_DTLB) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	    (vma->vm_flags & VM_WRITE) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		insn = get_fault_insn(regs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		if (!insn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			goto continue_fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		/* All loads, stores and atomics have bits 30 and 31 both set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		 * in the instruction.  Bit 21 is set in all stores, but we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		 * have to avoid prefetches which also have bit 21 set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		if ((insn & 0xc0200000) == 0xc0200000 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		    (insn & 0x01780000) != 0x01680000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			/* Don't bother updating thread struct value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			 * because update_mmu_cache only cares which tlb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			 * the access came from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			fault_code |= FAULT_CODE_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) continue_fault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (vma->vm_start <= address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		goto good_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (!(vma->vm_flags & VM_GROWSDOWN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		goto bad_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	if (!(fault_code & FAULT_CODE_WRITE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		/* Non-faulting loads shouldn't expand stack. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		insn = get_fault_insn(regs, insn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		if ((insn & 0xc0800000) == 0xc0800000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			unsigned char asi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			if (insn & 0x2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 				asi = (regs->tstate >> 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 				asi = (insn >> 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			if ((asi & 0xf2) == 0x82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 				goto bad_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (expand_stack(vma, address))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		goto bad_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	 * Ok, we have a good vm_area for this memory access, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	 * we can handle it..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) good_area:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	si_code = SEGV_ACCERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	/* If we took a ITLB miss on a non-executable page, catch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	 * that here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if ((fault_code & FAULT_CODE_ITLB) && !(vma->vm_flags & VM_EXEC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		WARN(address != regs->tpc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		     "address (%lx) != regs->tpc (%lx)\n", address, regs->tpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		WARN_ON(regs->tstate & TSTATE_PRIV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		goto bad_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	if (fault_code & FAULT_CODE_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		if (!(vma->vm_flags & VM_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			goto bad_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		/* Spitfire has an icache which does not snoop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		 * processor stores.  Later processors do...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		if (tlb_type == spitfire &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		    (vma->vm_flags & VM_EXEC) != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		    vma->vm_file != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 			set_thread_fault_code(fault_code |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 					      FAULT_CODE_BLKCOMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		flags |= FAULT_FLAG_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		/* Allow reads even for write-only mappings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			goto bad_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	fault = handle_mm_fault(vma, address, flags, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	if (fault_signal_pending(fault, regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		goto exit_exception;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (unlikely(fault & VM_FAULT_ERROR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		if (fault & VM_FAULT_OOM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			goto out_of_memory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		else if (fault & VM_FAULT_SIGSEGV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			goto bad_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		else if (fault & VM_FAULT_SIGBUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			goto do_sigbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	if (flags & FAULT_FLAG_ALLOW_RETRY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		if (fault & VM_FAULT_RETRY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			flags |= FAULT_FLAG_TRIED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 			/* No need to mmap_read_unlock(mm) as we would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			 * have already released it in __lock_page_or_retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 			 * in mm/filemap.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 			goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	mmap_read_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	mm_rss = get_mm_rss(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) #if defined(CONFIG_TRANSPARENT_HUGEPAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	mm_rss -= (mm->context.thp_pte_count * (HPAGE_SIZE / PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	if (unlikely(mm_rss >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		     mm->context.tsb_block[MM_TSB_BASE].tsb_rss_limit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		tsb_grow(mm, MM_TSB_BASE, mm_rss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	mm_rss = mm->context.hugetlb_pte_count + mm->context.thp_pte_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	mm_rss *= REAL_HPAGE_PER_HPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	if (unlikely(mm_rss >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		     mm->context.tsb_block[MM_TSB_HUGE].tsb_rss_limit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		if (mm->context.tsb_block[MM_TSB_HUGE].tsb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			tsb_grow(mm, MM_TSB_HUGE, mm_rss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 			hugetlb_setup(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) exit_exception:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	exception_exit(prev_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	 * Something tried to access memory that isn't in our memory map..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	 * Fix it, but check if it's kernel or user first..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) bad_area:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	insn = get_fault_insn(regs, insn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	mmap_read_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) handle_kernel_fault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	do_kernel_fault(regs, si_code, fault_code, insn, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	goto exit_exception;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)  * We ran out of memory, or some other thing happened to us that made
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)  * us unable to handle the page fault gracefully.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) out_of_memory:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	insn = get_fault_insn(regs, insn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	mmap_read_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	if (!(regs->tstate & TSTATE_PRIV)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		pagefault_out_of_memory();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		goto exit_exception;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	goto handle_kernel_fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) intr_or_no_mm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	insn = get_fault_insn(regs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	goto handle_kernel_fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) do_sigbus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	insn = get_fault_insn(regs, insn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	mmap_read_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	 * Send a sigbus, regardless of whether we were in kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	 * or user mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, address, insn, fault_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	/* Kernel mode? Handle exceptions or die */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (regs->tstate & TSTATE_PRIV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		goto handle_kernel_fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }