• Fabio M. De Francesco's avatar
    exec: Replace kmap{,_atomic}() with kmap_local_page() · 3a608cfe
    Fabio M. De Francesco authored
    The use of kmap() and kmap_atomic() are being deprecated in favor of
    kmap_local_page().
    
    There are two main problems with kmap(): (1) It comes with an overhead as
    mapping space is restricted and protected by a global lock for
    synchronization and (2) it also requires global TLB invalidation when the
    kmap’s pool wraps and it might block when the mapping space is fully
    utilized until a slot becomes available.
    
    With kmap_local_page() the mappings are per thread, CPU local, can take
    page faults, and can be called from any context (including interrupts).
    It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore,
    the tasks can be preempted and, when they are scheduled to run again, the
    kernel virtual addresses are restored and are still valid.
    
    Since the use of kmap_local_page() in exec.c is safe, it should be
    preferred everywhere in exec.c.
    
    As said, since kmap_local_page() can be also called from atomic context,
    and since remove_arg_zero() doesn't (and shouldn't ever) rely on an
    implicit preempt_disable(), this function can also safely replace
    kmap_atomic().
    
    Therefore, replace kmap() and kmap_atomic() with kmap_local_page() in
    fs/exec.c.
    
    Tested with xfstests on a QEMU/KVM x86_32 VM, 6GB RAM, booting a kernel
    with HIGHMEM64GB enabled.
    
    Cc: Eric W. Biederman <ebiederm@xmission.com>
    Suggested-by: default avatarIra Weiny <ira.weiny@intel.com>
    Reviewed-by: default avatarIra Weiny <ira.weiny@intel.com>
    Signed-off-by: default avatarFabio M. De Francesco <fmdefrancesco@gmail.com>
    Signed-off-by: default avatarKees Cook <keescook@chromium.org>
    Link: https://lore.kernel.org/r/20220803182856.28246-1-fmdefrancesco@gmail.com
    3a608cfe
exec.c 51 KB