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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Page fault handler for SH with an MMU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (C) 1999  Niibe Yutaka
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2003 - 2012  Paul Mundt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Based on linux/arch/i386/mm/fault.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *   Copyright (C) 1995  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/hardirq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/kprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/kdebug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/io_trapped.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/traps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) force_sig_info_fault(int si_signo, int si_code, unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	force_sig_fault(si_signo, si_code, (void __user *)address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * This is useful to dump out the page tables associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * 'addr' in mm 'mm'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static void show_pte(struct mm_struct *mm, unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	pgd_t *pgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (mm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		pgd = mm->pgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		pgd = get_TTB();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		if (unlikely(!pgd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			pgd = swapper_pg_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	pr_alert("pgd = %p\n", pgd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	pgd += pgd_index(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	pr_alert("[%08lx] *pgd=%0*llx", addr, (u32)(sizeof(*pgd) * 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		 (u64)pgd_val(*pgd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		p4d_t *p4d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		pud_t *pud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		pmd_t *pmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		pte_t *pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		if (pgd_none(*pgd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		if (pgd_bad(*pgd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			pr_cont("(bad)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		p4d = p4d_offset(pgd, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		if (PTRS_PER_P4D != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			pr_cont(", *p4d=%0*Lx", (u32)(sizeof(*p4d) * 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			        (u64)p4d_val(*p4d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		if (p4d_none(*p4d))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		if (p4d_bad(*p4d)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			pr_cont("(bad)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		pud = pud_offset(p4d, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		if (PTRS_PER_PUD != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			pr_cont(", *pud=%0*llx", (u32)(sizeof(*pud) * 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 				(u64)pud_val(*pud));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		if (pud_none(*pud))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		if (pud_bad(*pud)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			pr_cont("(bad)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		pmd = pmd_offset(pud, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		if (PTRS_PER_PMD != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			pr_cont(", *pmd=%0*llx", (u32)(sizeof(*pmd) * 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				(u64)pmd_val(*pmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (pmd_none(*pmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (pmd_bad(*pmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			pr_cont("(bad)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		/* We must not map this if we have highmem enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		if (PageHighMem(pfn_to_page(pmd_val(*pmd) >> PAGE_SHIFT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		pte = pte_offset_kernel(pmd, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		pr_cont(", *pte=%0*llx", (u32)(sizeof(*pte) * 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			(u64)pte_val(*pte));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	} while (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	unsigned index = pgd_index(address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	pgd_t *pgd_k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	p4d_t *p4d, *p4d_k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	pud_t *pud, *pud_k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	pmd_t *pmd, *pmd_k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	pgd += index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	pgd_k = init_mm.pgd + index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (!pgd_present(*pgd_k))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	p4d = p4d_offset(pgd, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	p4d_k = p4d_offset(pgd_k, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (!p4d_present(*p4d_k))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	pud = pud_offset(p4d, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	pud_k = pud_offset(p4d_k, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (!pud_present(*pud_k))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!pud_present(*pud))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	    set_pud(pud, *pud_k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	pmd = pmd_offset(pud, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	pmd_k = pmd_offset(pud_k, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (!pmd_present(*pmd_k))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (!pmd_present(*pmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		set_pmd(pmd, *pmd_k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		 * The page tables are fully synchronised so there must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		 * be another reason for the fault. Return NULL here to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		 * signal that we have not taken care of the fault.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return pmd_k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #ifdef CONFIG_SH_STORE_QUEUES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #define __FAULT_ADDR_LIMIT	P3_ADDR_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define __FAULT_ADDR_LIMIT	VMALLOC_END
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * Handle a fault on the vmalloc or module mapping area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static noinline int vmalloc_fault(unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	pgd_t *pgd_k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	pmd_t *pmd_k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	pte_t *pte_k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	/* Make sure we are in vmalloc/module/P3 area: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (!(address >= VMALLOC_START && address < __FAULT_ADDR_LIMIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 * Synchronize this task's top level page-table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	 * with the 'reference' page table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	 * Do _not_ use "current" here. We might be inside
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	 * an interrupt in the middle of a task switch..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	pgd_k = get_TTB();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	pmd_k = vmalloc_sync_one(pgd_k, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (!pmd_k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	pte_k = pte_offset_kernel(pmd_k, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (!pte_present(*pte_k))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) show_fault_oops(struct pt_regs *regs, unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (!oops_may_print())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	pr_alert("BUG: unable to handle kernel %s at %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		 address < PAGE_SIZE ? "NULL pointer dereference"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 				     : "paging request",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		 address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	pr_alert("PC:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	printk_address(regs->pc, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	show_pte(NULL, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static noinline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) no_context(struct pt_regs *regs, unsigned long error_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	   unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	/* Are we prepared to handle this kernel fault?  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (fixup_exception(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (handle_trapped_io(regs, address))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	 * Oops. The kernel tried to access some bad page. We'll have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	 * terminate things with extreme prejudice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	bust_spinlocks(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	show_fault_oops(regs, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	die("Oops", regs, error_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	bust_spinlocks(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	do_exit(SIGKILL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		       unsigned long address, int si_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	/* User mode accesses just cause a SIGSEGV */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (user_mode(regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		 * It's possible to have interrupts off here:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		force_sig_info_fault(SIGSEGV, si_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	no_context(regs, error_code, address);
^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) static noinline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		     unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	__bad_area_nosemaphore(regs, error_code, address, SEGV_MAPERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) __bad_area(struct pt_regs *regs, unsigned long error_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	   unsigned long address, int si_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct mm_struct *mm = current->mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 * Something tried to access memory that isn't in our memory map..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	 * Fix it, but check if it's kernel or user first..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	mmap_read_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	__bad_area_nosemaphore(regs, error_code, address, si_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static noinline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) bad_area(struct pt_regs *regs, unsigned long error_code, unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	__bad_area(regs, error_code, address, SEGV_MAPERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static noinline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) bad_area_access_error(struct pt_regs *regs, unsigned long error_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		      unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	__bad_area(regs, error_code, address, SEGV_ACCERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct task_struct *tsk = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	struct mm_struct *mm = tsk->mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	mmap_read_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	/* Kernel mode? Handle exceptions or die: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (!user_mode(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		no_context(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	force_sig_info_fault(SIGBUS, BUS_ADRERR, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static noinline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) mm_fault_error(struct pt_regs *regs, unsigned long error_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	       unsigned long address, vm_fault_t fault)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	 * Pagefault was interrupted by SIGKILL. We have no reason to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	 * continue pagefault.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (fault_signal_pending(fault, regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		if (!user_mode(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			no_context(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		return 1;
^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) 	/* Release mmap_lock first if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	if (!(fault & VM_FAULT_RETRY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		mmap_read_unlock(current->mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (!(fault & VM_FAULT_ERROR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (fault & VM_FAULT_OOM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		/* Kernel mode? Handle exceptions or die: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		if (!user_mode(regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			no_context(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		 * We ran out of memory, call the OOM killer, and return the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		 * userspace (which will retry the fault, or kill us if we got
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		 * oom-killed):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		pagefault_out_of_memory();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		if (fault & VM_FAULT_SIGBUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			do_sigbus(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		else if (fault & VM_FAULT_SIGSEGV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			bad_area(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static inline int access_error(int error_code, struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	if (error_code & FAULT_CODE_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		/* write, present and write, not present: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		if (unlikely(!(vma->vm_flags & VM_WRITE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	/* ITLB miss on NX page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (unlikely((error_code & FAULT_CODE_ITLB) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		     !(vma->vm_flags & VM_EXEC)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	/* read, not present: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (unlikely(!vma_is_accessible(vma)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static int fault_in_kernel_space(unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	return address >= TASK_SIZE;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  * This routine handles page faults.  It determines the address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  * and the problem, and then passes it off to one of the appropriate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  * routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 					unsigned long error_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 					unsigned long address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	unsigned long vec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	struct task_struct *tsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	struct mm_struct *mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct vm_area_struct * vma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	vm_fault_t fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	unsigned int flags = FAULT_FLAG_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	tsk = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	mm = tsk->mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	vec = lookup_exception_vector();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	 * We fault-in kernel-space virtual memory on-demand. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	 * 'reference' page table is init_mm.pgd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	 * NOTE! We MUST NOT take any locks for this case. We may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	 * be in an interrupt or a critical region, and should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	 * only copy the information from the master page table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	 * nothing more.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (unlikely(fault_in_kernel_space(address))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		if (vmalloc_fault(address) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		if (kprobe_page_fault(regs, vec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		bad_area_nosemaphore(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		return;
^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) 	if (unlikely(kprobe_page_fault(regs, vec)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	/* Only enable interrupts if they were on before the fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if ((regs->sr & SR_IMASK) != SR_IMASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	 * If we're in an interrupt, have no user context or are running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	 * with pagefaults disabled then we must not take the fault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	if (unlikely(faulthandler_disabled() || !mm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		bad_area_nosemaphore(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	mmap_read_lock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	vma = find_vma(mm, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	if (unlikely(!vma)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		bad_area(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	if (likely(vma->vm_start <= address))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		goto good_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	if (unlikely(!(vma->vm_flags & VM_GROWSDOWN))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		bad_area(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (unlikely(expand_stack(vma, address))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		bad_area(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	 * Ok, we have a good vm_area for this memory access, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	 * we can handle it..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) good_area:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	if (unlikely(access_error(error_code, vma))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		bad_area_access_error(regs, error_code, address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		return;
^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) 	set_thread_fault_code(error_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	if (user_mode(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		flags |= FAULT_FLAG_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (error_code & FAULT_CODE_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		flags |= FAULT_FLAG_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	 * If for any reason at all we couldn't handle the fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	 * make sure we exit gracefully rather than endlessly redo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	 * the fault.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	fault = handle_mm_fault(vma, address, flags, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (unlikely(fault & (VM_FAULT_RETRY | VM_FAULT_ERROR)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		if (mm_fault_error(regs, error_code, address, fault))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	if (flags & FAULT_FLAG_ALLOW_RETRY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		if (fault & VM_FAULT_RETRY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			flags |= FAULT_FLAG_TRIED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 			 * No need to mmap_read_unlock(mm) as we would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			 * have already released it in __lock_page_or_retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 			 * in mm/filemap.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	mmap_read_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }