Skip to content

Commit

Permalink
arm64/mm: fold check for KFENCE into can_set_direct_map()
Browse files Browse the repository at this point in the history
KFENCE requires linear map to be mapped at page granularity, so that it
is possible to protect/unprotect single pages, just like with
rodata_full and DEBUG_PAGEALLOC.

Instead of repating

	can_set_direct_map() || IS_ENABLED(CONFIG_KFENCE)

make can_set_direct_map() handle the KFENCE case.

This also prevents potential false positives in kernel_page_present()
that may return true for non-present page if CONFIG_KFENCE is enabled.

Signed-off-by: Mike Rapoport <[email protected]>
Reviewed-by: Anshuman Khandual <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Catalin Marinas <[email protected]>
  • Loading branch information
rppt authored and ctmarinas committed Sep 29, 2022
1 parent 2305b80 commit b9dd04a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 2 additions & 6 deletions arch/arm64/mm/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ static void __init map_mem(pgd_t *pgdp)
*/
BUILD_BUG_ON(pgd_index(direct_map_end - 1) == pgd_index(direct_map_end));

if (can_set_direct_map() || IS_ENABLED(CONFIG_KFENCE))
if (can_set_direct_map())
flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;

/*
Expand Down Expand Up @@ -1542,11 +1542,7 @@ int arch_add_memory(int nid, u64 start, u64 size,

VM_BUG_ON(!mhp_range_allowed(start, size, true));

/*
* KFENCE requires linear map to be mapped at page granularity, so that
* it is possible to protect/unprotect single pages in the KFENCE pool.
*/
if (can_set_direct_map() || IS_ENABLED(CONFIG_KFENCE))
if (can_set_direct_map())
flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;

__create_pgd_mapping(swapper_pg_dir, start, __phys_to_virt(start),
Expand Down
8 changes: 7 additions & 1 deletion arch/arm64/mm/pageattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ bool rodata_full __ro_after_init = IS_ENABLED(CONFIG_RODATA_FULL_DEFAULT_ENABLED

bool can_set_direct_map(void)
{
return rodata_full || debug_pagealloc_enabled();
/*
* rodata_full, DEBUG_PAGEALLOC and KFENCE require linear map to be
* mapped at page granularity, so that it is possible to
* protect/unprotect single pages.
*/
return rodata_full || debug_pagealloc_enabled() ||
IS_ENABLED(CONFIG_KFENCE);
}

static int change_page_range(pte_t *ptep, unsigned long addr, void *data)
Expand Down

0 comments on commit b9dd04a

Please sign in to comment.