mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ryan Roberts <ryan.roberts@arm.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Yang Shi <yang@os.amperecomputing.com>,
	Ard Biesheuvel <ardb@kernel.org>, Dev Jain <dev.jain@arm.com>,
	scott@os.amperecomputing.com, cl@gentwo.org
Cc: Ryan Roberts <ryan.roberts@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH v7 4/6] arm64: mm: Optimize split_kernel_leaf_mapping()
Date: Fri, 29 Aug 2025 12:52:45 +0100	[thread overview]
Message-ID: <20250829115250.2395585-5-ryan.roberts@arm.com> (raw)
In-Reply-To: <20250829115250.2395585-1-ryan.roberts@arm.com>

The common case for split_kernel_leaf_mapping() is for a single page.
Let's optimize this by only calling split_kernel_leaf_mapping_locked()
once.

Since the start and end address are PAGE_SIZE apart, they must be
contained within the same contpte block. Further, if start is at the
beginning of the block or end is at the end of the block, then the other
address must be in the _middle_ of the block. So if we split on this
middle-of-the-contpte-block address, it is guaranteed that the
containing contpte block is split to ptes and both start and end are
therefore mapped by pte.

This avoids the second call to split_kernel_leaf_mapping_locked()
meaning we only have to walk the pgtable once.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
 arch/arm64/mm/mmu.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 114b88216b0c..8b5b19e1154b 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -740,9 +740,21 @@ int split_kernel_leaf_mapping(unsigned long start, unsigned long end)
 	mutex_lock(&pgtable_split_lock);
 	arch_enter_lazy_mmu_mode();
 
-	ret = split_kernel_leaf_mapping_locked(start);
-	if (!ret)
-		ret = split_kernel_leaf_mapping_locked(end);
+	/*
+	 * Optimize for the common case of splitting out a single page from a
+	 * larger mapping. Here we can just split on the "least aligned" of
+	 * start and end and this will guarantee that there must also be a split
+	 * on the more aligned address since the both addresses must be in the
+	 * same contpte block and it must have been split to ptes.
+	 */
+	if (end - start == PAGE_SIZE) {
+		start = __ffs(start) < __ffs(end) ? start : end;
+		ret = split_kernel_leaf_mapping_locked(start);
+	} else {
+		ret = split_kernel_leaf_mapping_locked(start);
+		if (!ret)
+			ret = split_kernel_leaf_mapping_locked(end);
+	}
 
 	arch_leave_lazy_mmu_mode();
 	mutex_unlock(&pgtable_split_lock);
-- 
2.43.0


  parent reply	other threads:[~2025-08-29 11:53 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-29 11:52 [PATCH v7 0/6] arm64: support FEAT_BBM level 2 and large block mapping when rodata=full Ryan Roberts
2025-08-29 11:52 ` [PATCH v7 1/6] arm64: Enable permission change on arm64 kernel block mappings Ryan Roberts
     [not found]   ` <7705c29b-4f08-4b56-aab3-024795ee9124@huawei.com>
2025-09-04 11:06     ` Ryan Roberts
     [not found]       ` <a985c9f0-1561-45d7-860f-2717a0a72d9e@huawei.com>
2025-09-04 13:21         ` Ryan Roberts
2025-09-16 21:37       ` Yang Shi
2025-08-29 11:52 ` [PATCH v7 2/6] arm64: cpufeature: add AmpereOne to BBML2 allow list Ryan Roberts
2025-08-29 22:08   ` Yang Shi
2025-09-04 11:07     ` Ryan Roberts
2025-09-03 17:24   ` Catalin Marinas
2025-09-04  0:49     ` Yang Shi
2025-08-29 11:52 ` [PATCH v7 3/6] arm64: mm: support large block mapping when rodata=full Ryan Roberts
2025-09-03 19:15   ` Catalin Marinas
2025-09-04  0:52     ` Yang Shi
2025-09-04 11:09     ` Ryan Roberts
2025-09-04 11:15   ` Ryan Roberts
2025-09-04 14:57     ` Yang Shi
2025-08-29 11:52 ` Ryan Roberts [this message]
2025-08-29 22:11   ` [PATCH v7 4/6] arm64: mm: Optimize split_kernel_leaf_mapping() Yang Shi
2025-09-03 19:20   ` Catalin Marinas
2025-09-04 11:09     ` Ryan Roberts
2025-08-29 11:52 ` [PATCH v7 5/6] arm64: mm: split linear mapping if BBML2 unsupported on secondary CPUs Ryan Roberts
2025-09-04 16:59   ` Catalin Marinas
2025-09-04 17:54     ` Yang Shi
2025-09-08 15:25     ` Ryan Roberts
2025-08-29 11:52 ` [PATCH v7 6/6] arm64: mm: Optimize linear_map_split_to_ptes() Ryan Roberts
2025-08-29 22:27   ` Yang Shi
2025-09-04 11:10     ` Ryan Roberts
2025-09-04 14:58       ` Yang Shi
2025-09-04 17:00   ` Catalin Marinas
2025-09-01  5:04 ` [PATCH v7 0/6] arm64: support FEAT_BBM level 2 and large block mapping when rodata=full Dev Jain
2025-09-01  8:03   ` Ryan Roberts
2025-09-03  0:21     ` Yang Shi
2025-09-03  0:50       ` Yang Shi
2025-09-04 13:14         ` Ryan Roberts
2025-09-04 13:16           ` Ryan Roberts
2025-09-04 17:47             ` Yang Shi
2025-09-04 21:49               ` Yang Shi
2025-09-08 16:34                 ` Ryan Roberts
2025-09-08 18:31                   ` Yang Shi
2025-09-09 14:36                     ` Ryan Roberts
2025-09-09 15:32                       ` Yang Shi
2025-09-09 16:32                         ` Ryan Roberts
2025-09-09 17:32                           ` Yang Shi
2025-09-11 22:03                             ` Yang Shi
2025-09-17 16:28                               ` Ryan Roberts
2025-09-17 17:21                                 ` Yang Shi
2025-09-17 18:58                                   ` Ryan Roberts
2025-09-17 19:15                                     ` Yang Shi
2025-09-17 19:40                                       ` Ryan Roberts
2025-09-17 19:59                                         ` Yang Shi
2025-09-16 23:44               ` Yang Shi

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=20250829115250.2395585-5-ryan.roberts@arm.com \
    --to=ryan.roberts@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=cl@gentwo.org \
    --cc=david@redhat.com \
    --cc=dev.jain@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=scott@os.amperecomputing.com \
    --cc=will@kernel.org \
    --cc=yang@os.amperecomputing.com \
    /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®