From: Yang Shi <yang@os.amperecomputing.com>
To: Ryan Roberts <ryan.roberts@arm.com>,
catalin.marinas@arm.com, will@kernel.org, david@redhat.com,
ardb@kernel.org, dev.jain@arm.com, scott@os.amperecomputing.com,
cl@gentwo.org
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
David Hildenbrand <david@kernel.org>
Subject: Re: [PATCH v2 3/3] arm64: mm: Tidy up force_pte_mapping()
Date: Thu, 6 Nov 2025 12:51:41 -0800 [thread overview]
Message-ID: <7fce52b9-5c4e-4214-afe2-c1607285aa27@os.amperecomputing.com> (raw)
In-Reply-To: <20251106160945.3182799-4-ryan.roberts@arm.com>
On 11/6/25 8:09 AM, Ryan Roberts wrote:
> 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: Yang Shi <yang@os.amperecomputing.com>
Thanks,
Yang
> ---
> arch/arm64/mm/mmu.c | 43 +++++++++++++++++++++++--------------------
> 1 file changed, 23 insertions(+), 20 deletions(-)
>
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index 652bb8c14035..2ba01dc8ef82 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -710,12 +710,26 @@ static int split_kernel_leaf_mapping_locked(unsigned long addr)
>
> static inline bool force_pte_mapping(void)
> {
> - bool bbml2 = system_capabilities_finalized() ?
> + const bool bbml2 = system_capabilities_finalized() ?
> system_supports_bbml2_noabort() : cpu_supports_bbml2_noabort();
>
> - return (!bbml2 && (rodata_full || arm64_kfence_can_set_direct_map() ||
> - is_realm_world())) ||
> - debug_pagealloc_enabled();
> + if (debug_pagealloc_enabled())
> + return true;
> + if (bbml2)
> + return false;
> + return rodata_full || arm64_kfence_can_set_direct_map() || is_realm_world();
> +}
> +
> +static inline bool split_leaf_mapping_possible(void)
> +{
> + /*
> + * !BBML2_NOABORT systems should never run into scenarios where we would
> + * have to split. So exit early and let calling code detect it and raise
> + * a warning.
> + */
> + if (!system_supports_bbml2_noabort())
> + return false;
> + return !force_pte_mapping();
> }
>
> static DEFINE_MUTEX(pgtable_split_lock);
> @@ -725,22 +739,11 @@ int split_kernel_leaf_mapping(unsigned long start, unsigned long end)
> int ret;
>
> /*
> - * !BBML2_NOABORT systems should not be trying to change permissions on
> - * anything that is not pte-mapped in the first place. Just return early
> - * and let the permission change code raise a warning if not already
> - * pte-mapped.
> - */
> - if (!system_supports_bbml2_noabort())
> - return 0;
> -
> - /*
> - * If the region is within a pte-mapped area, there is no need to try to
> - * split. Additionally, CONFIG_DEBUG_PAGEALLOC and CONFIG_KFENCE may
> - * change permissions from atomic context so for those cases (which are
> - * always pte-mapped), we must not go any further because taking the
> - * mutex below may sleep.
> + * Exit early if the region is within a pte-mapped area or if we can't
> + * split. For the latter case, the permission change code will raise a
> + * warning if not already pte-mapped.
> */
> - if (force_pte_mapping() || is_kfence_address((void *)start))
> + if (!split_leaf_mapping_possible() || is_kfence_address((void *)start))
> return 0;
>
> /*
> @@ -1039,7 +1042,7 @@ bool arch_kfence_init_pool(void)
> int ret;
>
> /* Exit early if we know the linear map is already pte-mapped. */
> - if (!system_supports_bbml2_noabort() || force_pte_mapping())
> + if (!split_leaf_mapping_possible())
> return true;
>
> /* Kfence pool is already pte-mapped for the early init case. */
next prev parent reply other threads:[~2025-11-06 20:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-06 16:09 [PATCH v2 0/3] Don't sleep in split_kernel_leaf_mapping() when in atomic context Ryan Roberts
2025-11-06 16:09 ` [PATCH v2 1/3] arm64: mm: " Ryan Roberts
2025-11-06 20:46 ` Yang Shi
2025-11-07 12:10 ` Ryan Roberts
2025-11-06 21:08 ` David Hildenbrand (Red Hat)
2025-11-06 16:09 ` [PATCH v2 2/3] arm64: mm: Optimize range_split_to_ptes() Ryan Roberts
2025-11-06 20:47 ` Yang Shi
2025-11-06 16:09 ` [PATCH v2 3/3] arm64: mm: Tidy up force_pte_mapping() Ryan Roberts
2025-11-06 20:51 ` Yang Shi [this message]
2025-11-06 21:08 ` David Hildenbrand (Red Hat)
2025-11-07 15:53 ` [PATCH v2 0/3] Don't sleep in split_kernel_leaf_mapping() when in atomic context Will Deacon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7fce52b9-5c4e-4214-afe2-c1607285aa27@os.amperecomputing.com \
--to=yang@os.amperecomputing.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=cl@gentwo.org \
--cc=david@kernel.org \
--cc=david@redhat.com \
--cc=dev.jain@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ryan.roberts@arm.com \
--cc=scott@os.amperecomputing.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®