From: Brendan Jackman <jackmanb@google.com>
To: Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@kernel.org>
Cc: linux-kernel@vger.kernel.org, Brendan Jackman <jackmanb@google.com>
Subject: [PATCH v2 2/3] x86/mm: simplify calculation of max_pfn_mapped
Date: Sun, 03 May 2026 13:04:55 +0000 [thread overview]
Message-ID: <20260503-x86-init-cleanup-v2-2-bb690bd2477c@google.com> (raw)
In-Reply-To: <20260503-x86-init-cleanup-v2-0-bb690bd2477c@google.com>
The phys_*_init()s return the "last physical address mapped". The exact
definition of this is pretty fiddly, but only in these conditions:
1. There is a mismatch between the alignment of the requested range and
the page sizes allowed by page_size_mask
2. The range ends in a region that is not mapped according to
e820.
3. The range ends in a region that was already mapped (note this case is
particularly fiddly because the return value depends on what level
the existing mapping is at. This is probably a bug, see [0] for
discussion).
Luckily, init_memory_mapping() avoids all these conditions. In that
case, the return value is just paddr_end. And that value is already
present, no need to depend on the confusing return value.
[0]: https://lore.kernel.org/all/84b2e7a3-7115-45fe-89ff-db8ee46729f2@intel.com/
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
arch/x86/mm/init.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index ae3e9e0820153..1a6a6fc700bb5 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -544,10 +544,11 @@ void __ref init_memory_mapping(unsigned long start,
memset(mr, 0, sizeof(mr));
nr_range = split_mem_range(mr, 0, start, end);
- for (i = 0; i < nr_range; i++)
- paddr_last = kernel_physical_mapping_init(mr[i].start, mr[i].end,
- mr[i].page_size_mask,
- prot);
+ for (i = 0; i < nr_range; i++) {
+ kernel_physical_mapping_init(mr[i].start, mr[i].end,
+ mr[i].page_size_mask, prot);
+ paddr_last = mr[i].end;
+ }
add_pfn_range_mapped(start >> PAGE_SHIFT, paddr_last >> PAGE_SHIFT);
}
--
2.51.2
next prev parent reply other threads:[~2026-05-03 13:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-03 13:04 [PATCH v2 0/3] x86/mm: some cleanups for pagetable setup code Brendan Jackman
2026-05-03 13:04 ` [PATCH v2 1/3] x86/mm: drop unused return from init_memory_mapping() Brendan Jackman
2026-05-03 13:04 ` Brendan Jackman [this message]
2026-05-03 13:04 ` [PATCH v2 3/3] x86/mm: drop unused returns from direct map setup functions Brendan Jackman
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=20260503-x86-init-cleanup-v2-2-bb690bd2477c@google.com \
--to=jackmanb@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
--cc=x86@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