radix/kfence: map __kfence_pool at page granularity
PATCH v3 1/1 radix/kfence: map __kfence_pool at page granularity
When KFENCE is enabled, total system memory is mapped at page level granularity. But in radix MMU mode, ~3GB additional memory is needed to map 100GB of system memory at page level granularity when compared to using 2MB direct mapping. This is not desired considering KFENCE is designed to be enabled in production kernels [1]. Also, mapping only the memory allocated for KFENCE pool at page granularity is sufficient to enable KFENCE support. So, allocate __kfence_pool during bootup and map it at page granularity instead of mapping all system memory at page granularity.
Without patch:
# cat /proc/meminfo
MemTotal: 101201920 kBWith patch:
# cat /proc/meminfo
MemTotal: 104483904 kBNote that enabling KFENCE at runtime is disabled for radix MMU for now, as it depends on the ability to split page table mappings and such APIs are not currently implemented for radix MMU.
All kfence_test.c testcases passed with this patch.
[1] https://lore.kernel.org/all/[email protected]/
---
Changes in v3:
* Updated the changelog and contained changes relevant for radix MMU within radix-pgtable.c as suggested by mpe.
Changes in v2:
* Dropped the patch that adds support to enable KFENCE after startup.
* Added changes to avoid KFENCE enablement after system startup.
* Also, added a TODO explaining why KFENCE enablement after startup is not supported for now.
* Functions to alloc/map __kfence_pool as suggested by Ritesh.
* Moved changes that apply to ppc32 as well to common file as suggested by Christophe.
arch/powerpc/include/asm/kfence.h | 11 +++- arch/powerpc/mm/book3s64/radix_pgtable.c | 84 ++++++++++++++++++++++-- arch/powerpc/mm/init-common.c | 3 + 3 files changed, 93 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/kfence.h +10 -1
@@ -15,10 +15,19 @@#define ARCH_FUNC_PREFIX "."#endif +#ifdef CONFIG_KFENCE +extern bool kfence_disabled; + +static inline void disable_kfence (void ) +{ + kfence_disabled = true; +} +static inline bool arch_kfence_init_pool (void ) { -return true; +return !kfence_disabled; } +#endif #ifdef CONFIG_PPC64 static inline bool kfence_protect_page (unsigned long addr,bool protect)
arch/powerpc/mm/book3s64/radix_pgtable.c +80 -4
136 lines not on this page · raw message
arch/powerpc/mm/init-common.c +3 -0
@@ -31,6 +31,9 @@ EXPORT_SYMBOL_GPL(kernstart_virt_addr);bool disable_kuep = !IS_ENABLED (CONFIG_PPC_KUEP );bool disable_kuap = !IS_ENABLED (CONFIG_PPC_KUAP ); +#ifdef CONFIG_KFENCE +bool __ro_after_init kfence_disabled; +#endif static int __init parse_nosmep (char *p) {
Signature · 1 line
2.45.1
Michael Ellerman
AppliedQuoted 11 lines · Hari Bathini
When KFENCE is enabled, total system memory is mapped at page level granularity. But in radix MMU mode, ~3GB additional memory is needed to map 100GB of system memory at page level granularity when compared to using 2MB direct mapping. This is not desired considering KFENCE is designed to be enabled in production kernels [1]. Also, mapping only the memory allocated for KFENCE pool at page granularity is sufficient to enable KFENCE support. So, allocate
__kfence_poolduring bootup and map it at page granularity instead of mapping all system memory at page granularity.[...]
Applied to powerpc/next.
[1/1] radix/kfence: map __kfence_pool at page granularity
https://git.kernel.org/powerpc/c/353d7a84c214f184d5a6b62acdec8b4424159b7c
cheers