Re: [RFC PATCH 4/4] x86/mm: write protect (most) page tables

Mike Rapoport
2021-08-26T08:04:10Z

On Mon, Aug 23, 2021 at 04:50:10PM -0700, Dave Hansen wrote:
> On 8/23/21 6:25 AM, Mike Rapoport wrote:
> > void ___pte_free_tlb(struct mmu_gather *tlb, struct page *pte)
> > {
> > + enable_pgtable_write(page_address(pte));
> > pgtable_pte_page_dtor(pte);
> > paravirt_release_pte(page_to_pfn(pte));
> > paravirt_tlb_remove_table(tlb, pte);
> > @@ -69,6 +73,7 @@ void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd)
> > #ifdef CONFIG_X86_PAE
> > tlb->need_flush_all = 1;
> > #endif
> > + enable_pgtable_write(pmd);
> > pgtable_pmd_page_dtor(page);
> > paravirt_tlb_remove_table(tlb, page);
> > }
>
> I'm also cringing a bit at hacking this into the page allocator. A
> *lot* of what you're trying to do with getting large allocations out and
> splitting them up is done very well today by the slab allocators. It
> might take some rearrangement of 'struct page' metadata to be more slab
> friendly, but it does seem like a close enough fit to warrant investigating.

I thought more about using slab, but it seems to me the least suitable
option. The usecases at hand (page tables, secretmem, SEV/TDX) allocate in
page granularity and some of them use struct page metadata, so even its
rearrangement won't help. And adding support for 2M slabs to SLUB would be
quite intrusive.

I think that better options are moving such cache deeper into buddy or
using e.g. genalloc instead of a list to deal with higher order allocations.

The choice between these two will mostly depend of the API selection, i.e.
a GFP flag or a dedicated alloc/free.

--
Sincerely yours,
Mike.