···261261}262262#endif263263264264+/*265265+ * Handle a vmalloc fault, copying the non-leaf page table entries from266266+ * init_mm.pgd. Any kernel context can trigger this, so we must not sleep267267+ * or enable interrupts. Having two CPUs execute this for the same page is268268+ * no problem, we'll just copy the same data twice.269269+ *270270+ * Returns false on failure.271271+ */272272+static bool __kprobes __maybe_unused vmalloc_fault(unsigned long addr)273273+{274274+ unsigned int index;275275+ pgd_t *pgd, *pgd_k;276276+ p4d_t *p4d, *p4d_k;277277+ pud_t *pud, *pud_k;278278+ pmd_t *pmd, *pmd_k;279279+280280+ index = pgd_index(addr);281281+282282+ pgd = cpu_get_pgd() + index;283283+ pgd_k = init_mm.pgd + index;284284+285285+ p4d = p4d_offset(pgd, addr);286286+ p4d_k = p4d_offset(pgd_k, addr);287287+288288+ if (p4d_none(*p4d_k))289289+ return false;290290+ if (!p4d_present(*p4d))291291+ set_p4d(p4d, *p4d_k);292292+293293+ pud = pud_offset(p4d, addr);294294+ pud_k = pud_offset(p4d_k, addr);295295+296296+ if (pud_none(*pud_k))297297+ return false;298298+ if (!pud_present(*pud))299299+ set_pud(pud, *pud_k);300300+301301+ pmd = pmd_offset(pud, addr);302302+ pmd_k = pmd_offset(pud_k, addr);303303+304304+#ifdef CONFIG_ARM_LPAE305305+ /*306306+ * Only one hardware entry per PMD with LPAE.307307+ */308308+ index = 0;309309+#else310310+ /*311311+ * On ARM one Linux PGD entry contains two hardware entries (see page312312+ * tables layout in pgtable.h). We normally guarantee that we always313313+ * fill both L1 entries. But create_mapping() doesn't follow the rule.314314+ * It can create inidividual L1 entries, so here we have to call315315+ * pmd_none() check for the entry really corresponded to address, not316316+ * for the first of pair.317317+ */318318+ index = (addr >> SECTION_SHIFT) & 1;319319+#endif320320+ if (pmd_none(pmd_k[index]))321321+ return false;322322+323323+ copy_pmd(pmd, pmd_k);324324+325325+ return true;326326+}327327+264328static int __kprobes265329do_kernel_address_page_fault(struct mm_struct *mm, unsigned long addr,266330 unsigned int fsr, struct pt_regs *regs)···560496 * directly to do_kernel_address_page_fault() to handle.561497 *562498 * Otherwise, we're probably faulting in the vmalloc() area, so try to fix563563- * that up. Note that we must not take any locks or enable interrupts in564564- * this case.499499+ * that up via vmalloc_fault().565500 *566566- * If vmalloc() fixup fails, that means the non-leaf page tables did not501501+ * If vmalloc_fault() fails, that means the non-leaf page tables did not567502 * contain an entry for this address, so handle this via568503 * do_kernel_address_page_fault().569504 */···571508do_translation_fault(unsigned long addr, unsigned int fsr,572509 struct pt_regs *regs)573510{574574- unsigned int index;575575- pgd_t *pgd, *pgd_k;576576- p4d_t *p4d, *p4d_k;577577- pud_t *pud, *pud_k;578578- pmd_t *pmd, *pmd_k;579579-580511 if (addr < TASK_SIZE)581512 return do_page_fault(addr, fsr, regs);582513583583- if (user_mode(regs))584584- goto bad_area;514514+ if (!user_mode(regs) && vmalloc_fault(addr))515515+ return 0;585516586586- index = pgd_index(addr);587587-588588- pgd = cpu_get_pgd() + index;589589- pgd_k = init_mm.pgd + index;590590-591591- p4d = p4d_offset(pgd, addr);592592- p4d_k = p4d_offset(pgd_k, addr);593593-594594- if (p4d_none(*p4d_k))595595- goto bad_area;596596- if (!p4d_present(*p4d))597597- set_p4d(p4d, *p4d_k);598598-599599- pud = pud_offset(p4d, addr);600600- pud_k = pud_offset(p4d_k, addr);601601-602602- if (pud_none(*pud_k))603603- goto bad_area;604604- if (!pud_present(*pud))605605- set_pud(pud, *pud_k);606606-607607- pmd = pmd_offset(pud, addr);608608- pmd_k = pmd_offset(pud_k, addr);609609-610610-#ifdef CONFIG_ARM_LPAE611611- /*612612- * Only one hardware entry per PMD with LPAE.613613- */614614- index = 0;615615-#else616616- /*617617- * On ARM one Linux PGD entry contains two hardware entries (see page618618- * tables layout in pgtable.h). We normally guarantee that we always619619- * fill both L1 entries. But create_mapping() doesn't follow the rule.620620- * It can create inidividual L1 entries, so here we have to call621621- * pmd_none() check for the entry really corresponded to address, not622622- * for the first of pair.623623- */624624- index = (addr >> SECTION_SHIFT) & 1;625625-#endif626626- if (pmd_none(pmd_k[index]))627627- goto bad_area;628628-629629- copy_pmd(pmd, pmd_k);630630- return 0;631631-632632-bad_area:633517 do_kernel_address_page_fault(current->mm, addr, fsr, regs);634518635519 return 0;