• Linus Torvalds's avatar
    kvmalloc: use vmalloc_huge for vmalloc allocations · 9becb688
    Linus Torvalds authored
    Since commit 559089e0 ("vmalloc: replace VM_NO_HUGE_VMAP with
    VM_ALLOW_HUGE_VMAP"), the use of hugepage mappings for vmalloc is an
    opt-in strategy, because it caused a number of problems that weren't
    noticed until x86 enabled it too.
    
    One of the issues was fixed by Nick Piggin in commit 3b8000ae
    ("mm/vmalloc: huge vmalloc backing pages should be split rather than
    compound"), but I'm still worried about page protection issues, and
    VM_FLUSH_RESET_PERMS in particular.
    
    However, like the hash table allocation case (commit f2edd118:
    "page_alloc: use vmalloc_huge for large system hash"), the use of
    kvmalloc() should be safe from any such games, since the returned
    pointer might be a SLUB allocation, and as such no user should
    reasonably be using it in any odd ways.
    
    We also know that the allocations are fairly large, since it falls back
    to the vmalloc case only when a kmalloc() fails.  So using a hugepage
    mapping seems both safe and relevant.
    
    This patch does show a weakness in the opt-in strategy: since the opt-in
    flag is in the 'vm_flags', not the usual gfp_t allocation flags, very
    few of the usual interfaces actually expose it.
    
    That's not much of an issue in this case that already used one of the
    fairly specialized low-level vmalloc interfaces for the allocation, but
    for a lot of other vmalloc() users that might want to opt in, it's going
    to be very inconvenient.
    
    We'll either have to fix any compatibility problems, or expose it in the
    gfp flags (__GFP_COMP would have made a lot of sense) to allow normal
    vmalloc() users to use hugepage mappings.  That said, the cases that
    really matter were probably already taken care of by the hash tabel
    allocation.
    
    Link: https://lore.kernel.org/all/20220415164413.2727220-1-song@kernel.org/
    Link: https://lore.kernel.org/all/CAHk-=whao=iosX1s5Z4SF-ZGa-ebAukJoAdUJFk5SPwnofV+Vg@mail.gmail.com/
    Cc: Nicholas Piggin <npiggin@gmail.com>
    Cc: Paul Menzel <pmenzel@molgen.mpg.de>
    Cc: Song Liu <songliubraving@fb.com>
    Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    9becb688
util.c 29.6 KB