• Catalin Marinas's avatar
    arm64: mte: Add PROT_MTE support to mmap() and mprotect() · 9f341931
    Catalin Marinas authored
    To enable tagging on a memory range, the user must explicitly opt in via
    a new PROT_MTE flag passed to mmap() or mprotect(). Since this is a new
    memory type in the AttrIndx field of a pte, simplify the or'ing of these
    bits over the protection_map[] attributes by making MT_NORMAL index 0.
    
    There are two conditions for arch_vm_get_page_prot() to return the
    MT_NORMAL_TAGGED memory type: (1) the user requested it via PROT_MTE,
    registered as VM_MTE in the vm_flags, and (2) the vma supports MTE,
    decided during the mmap() call (only) and registered as VM_MTE_ALLOWED.
    
    arch_calc_vm_prot_bits() is responsible for registering the user request
    as VM_MTE. The newly introduced arch_calc_vm_flag_bits() sets
    VM_MTE_ALLOWED if the mapping is MAP_ANONYMOUS. An MTE-capable
    filesystem (RAM-based) may be able to set VM_MTE_ALLOWED during its
    mmap() file ops call.
    
    In addition, update VM_DATA_DEFAULT_FLAGS to allow mprotect(PROT_MTE) on
    stack or brk area.
    
    The Linux mmap() syscall currently ignores unknown PROT_* flags. In the
    presence of MTE, an mmap(PROT_MTE) on a file which does not support MTE
    will not report an error and the memory will not be mapped as Normal
    Tagged. For consistency, mprotect(PROT_MTE) will not report an error
    either if the memory range does not support MTE. Two subsequent patches
    in the series will propose tightening of this behaviour.
    Co-developed-by: default avatarVincenzo Frascino <vincenzo.frascino@arm.com>
    Signed-off-by: default avatarVincenzo Frascino <vincenzo.frascino@arm.com>
    Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
    Cc: Will Deacon <will@kernel.org>
    9f341931
mman.h 278 Bytes