Skip to content

Commit 53357f1

Browse files
ryanhrobwilldeacon
authored andcommitted
arm64: mm: Tidy up force_pte_mapping()
Tidy up the implementation of force_pte_mapping() to make it easier to read and introduce the split_leaf_mapping_possible() helper to reduce code duplication in split_kernel_leaf_mapping() and arch_kfence_init_pool(). Suggested-by: David Hildenbrand (Red Hat) <david@kernel.org> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> Reviewed-by: David Hildenbrand (Red Hat) <david@kernel.org> Reviewed-by: Yang Shi <yang@os.amperecomputing.com> Signed-off-by: Will Deacon <will@kernel.org>
1 parent 40a292f commit 53357f1

1 file changed

Lines changed: 23 additions & 20 deletions

File tree

arch/arm64/mm/mmu.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -710,12 +710,26 @@ static int split_kernel_leaf_mapping_locked(unsigned long addr)
710710

711711
static inline bool force_pte_mapping(void)
712712
{
713-
bool bbml2 = system_capabilities_finalized() ?
713+
const bool bbml2 = system_capabilities_finalized() ?
714714
system_supports_bbml2_noabort() : cpu_supports_bbml2_noabort();
715715

716-
return (!bbml2 && (rodata_full || arm64_kfence_can_set_direct_map() ||
717-
is_realm_world())) ||
718-
debug_pagealloc_enabled();
716+
if (debug_pagealloc_enabled())
717+
return true;
718+
if (bbml2)
719+
return false;
720+
return rodata_full || arm64_kfence_can_set_direct_map() || is_realm_world();
721+
}
722+
723+
static inline bool split_leaf_mapping_possible(void)
724+
{
725+
/*
726+
* !BBML2_NOABORT systems should never run into scenarios where we would
727+
* have to split. So exit early and let calling code detect it and raise
728+
* a warning.
729+
*/
730+
if (!system_supports_bbml2_noabort())
731+
return false;
732+
return !force_pte_mapping();
719733
}
720734

721735
static DEFINE_MUTEX(pgtable_split_lock);
@@ -725,22 +739,11 @@ int split_kernel_leaf_mapping(unsigned long start, unsigned long end)
725739
int ret;
726740

727741
/*
728-
* !BBML2_NOABORT systems should not be trying to change permissions on
729-
* anything that is not pte-mapped in the first place. Just return early
730-
* and let the permission change code raise a warning if not already
731-
* pte-mapped.
732-
*/
733-
if (!system_supports_bbml2_noabort())
734-
return 0;
735-
736-
/*
737-
* If the region is within a pte-mapped area, there is no need to try to
738-
* split. Additionally, CONFIG_DEBUG_PAGEALLOC and CONFIG_KFENCE may
739-
* change permissions from atomic context so for those cases (which are
740-
* always pte-mapped), we must not go any further because taking the
741-
* mutex below may sleep.
742+
* Exit early if the region is within a pte-mapped area or if we can't
743+
* split. For the latter case, the permission change code will raise a
744+
* warning if not already pte-mapped.
742745
*/
743-
if (force_pte_mapping() || is_kfence_address((void *)start))
746+
if (!split_leaf_mapping_possible() || is_kfence_address((void *)start))
744747
return 0;
745748

746749
/*
@@ -1039,7 +1042,7 @@ bool arch_kfence_init_pool(void)
10391042
int ret;
10401043

10411044
/* Exit early if we know the linear map is already pte-mapped. */
1042-
if (!system_supports_bbml2_noabort() || force_pte_mapping())
1045+
if (!split_leaf_mapping_possible())
10431046
return true;
10441047

10451048
/* Kfence pool is already pte-mapped for the early init case. */

0 commit comments

Comments
 (0)