On Thu, 2022-11-03 at 14:10 +1100, Benjamin Gray wrote: > On Wed, 2022-11-02 at 10:11 +0000, Christophe Leroy wrote: > > Le 25/10/2022 à 06:44, Benjamin Gray a écrit : > > > + /* > > > + * PTE allocation uses GFP_KERNEL which means we need to > > > + * pre-allocate the PTE here because we cannot do the > > > + * allocation during patching when IRQs are disabled. > > > + */ > > > + pgdp = pgd_offset(mm, addr); > > > + > > > + p4dp = p4d_alloc(mm, pgdp, addr); > > > + if (WARN_ON(!p4dp)) > > > + goto fail_no_p4d; > > > + > > > + pudp = pud_alloc(mm, p4dp, addr); > > > + if (WARN_ON(!pudp)) > > > + goto fail_no_pud; > > > + > > > + pmdp = pmd_alloc(mm, pudp, addr); > > > + if (WARN_ON(!pmdp)) > > > + goto fail_no_pmd; > > > + > > > + ptep = pte_alloc_map(mm, pmdp, addr); > > > + if (WARN_ON(!ptep)) > > > + goto fail_no_pte; > > > > Insn't there standard generic functions to do that ? > > > > For instance, __get_locked_pte() seems to do more or less the same. > > __get_locked_pte invokes walk_to_pmd, which leaks memory if the > allocation fails. This may not be a concern necessarily at boot > (though > I still don't like it), but startup is run every time a CPU comes > online, so the leak is theoretically unbounded. > > There's no need to leak it in this context, because we know that each > page is exclusively used by the corresponding patching mm.
I found tlb_gather_mmu() to initialise a struct mmu_gather, so I've removed all the open coding (it should free any partial page tables if get_locked_pte fails). Currently running it through CI before posting, will probably get the v10 out tomorrow.