Skip to content

Commit dfd73e5

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64: kfence: Avoid NOMAP tricks when mapping the early pool
Now that the map_mem() routines respect existing page mappings and contiguous granule sized blocks with the contiguous bit cleared, there is no longer a reason to play tricks with the memblock NOMAP attribute. Instead, the kfence pool can be allocated and mapped with page granularity first, and this granularity will be respected when the rest of DRAM is mapped later, even if block and contiguous mappings are allowed for the remainder of those mappings. Add the NO_EXEC_MAPPINGS flag to ensure that hierarchical XN attributes are set on the intermediate page tables that are allocated when mapping the pool. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com> Signed-off-by: Will Deacon <will@kernel.org>
1 parent 05c5c31 commit dfd73e5

1 file changed

Lines changed: 6 additions & 21 deletions

File tree

arch/arm64/mm/mmu.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,36 +1083,24 @@ static int __init parse_kfence_early_init(char *arg)
10831083
}
10841084
early_param("kfence.sample_interval", parse_kfence_early_init);
10851085

1086-
static phys_addr_t __init arm64_kfence_alloc_pool(void)
1086+
static void __init arm64_kfence_map_pool(void)
10871087
{
10881088
phys_addr_t kfence_pool;
10891089

10901090
if (!kfence_early_init)
1091-
return 0;
1091+
return;
10921092

10931093
kfence_pool = memblock_phys_alloc(KFENCE_POOL_SIZE, PAGE_SIZE);
10941094
if (!kfence_pool) {
10951095
pr_err("failed to allocate kfence pool\n");
10961096
kfence_early_init = false;
1097-
return 0;
1098-
}
1099-
1100-
/* Temporarily mark as NOMAP. */
1101-
memblock_mark_nomap(kfence_pool, KFENCE_POOL_SIZE);
1102-
1103-
return kfence_pool;
1104-
}
1105-
1106-
static void __init arm64_kfence_map_pool(phys_addr_t kfence_pool)
1107-
{
1108-
if (!kfence_pool)
11091097
return;
1098+
}
11101099

11111100
/* KFENCE pool needs page-level mapping. */
11121101
__map_memblock(kfence_pool, kfence_pool + KFENCE_POOL_SIZE,
11131102
pgprot_tagged(PAGE_KERNEL),
1114-
NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS);
1115-
memblock_clear_nomap(kfence_pool, KFENCE_POOL_SIZE);
1103+
NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS | NO_EXEC_MAPPINGS);
11161104
__kfence_pool = phys_to_virt(kfence_pool);
11171105
}
11181106

@@ -1144,8 +1132,7 @@ bool arch_kfence_init_pool(void)
11441132
}
11451133
#else /* CONFIG_KFENCE */
11461134

1147-
static inline phys_addr_t arm64_kfence_alloc_pool(void) { return 0; }
1148-
static inline void arm64_kfence_map_pool(phys_addr_t kfence_pool) { }
1135+
static inline void arm64_kfence_map_pool(void) { }
11491136

11501137
#endif /* CONFIG_KFENCE */
11511138

@@ -1155,7 +1142,6 @@ static void __init map_mem(void)
11551142
phys_addr_t kernel_start = __pa_symbol(_text);
11561143
phys_addr_t kernel_end = __pa_symbol(__init_begin);
11571144
phys_addr_t start, end;
1158-
phys_addr_t early_kfence_pool;
11591145
int flags = NO_EXEC_MAPPINGS;
11601146
u64 i;
11611147

@@ -1172,7 +1158,7 @@ static void __init map_mem(void)
11721158
BUILD_BUG_ON(pgd_index(direct_map_end - 1) == pgd_index(direct_map_end) &&
11731159
pgd_index(_PAGE_OFFSET(VA_BITS_MIN)) != PTRS_PER_PGD - 1);
11741160

1175-
early_kfence_pool = arm64_kfence_alloc_pool();
1161+
arm64_kfence_map_pool();
11761162

11771163
linear_map_requires_bbml2 = !force_pte_mapping() && can_set_direct_map();
11781164

@@ -1210,7 +1196,6 @@ static void __init map_mem(void)
12101196
*/
12111197
__map_memblock(kernel_start, kernel_end, PAGE_KERNEL, NO_CONT_MAPPINGS);
12121198
memblock_clear_nomap(kernel_start, kernel_end - kernel_start);
1213-
arm64_kfence_map_pool(early_kfence_pool);
12141199
}
12151200

12161201
void mark_rodata_ro(void)

0 commit comments

Comments
 (0)