All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Brendan Jackman" <brendan.jackman@linux.dev>
To: "Brendan Jackman" <brendan.jackman@linux.dev>,
	"Dave Hansen" <dave.hansen@intel.com>,
	"Brendan Jackman" <jackmanb@google.com>,
	"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>
Subject: Re: [PATCH v2 2/3] x86/mm: simplify calculation of max_pfn_mapped
Date: Wed, 24 Jun 2026 12:36:35 +0000	[thread overview]
Message-ID: <DJHA8ZQYK3JA.T39SY4N7QTGF@linux.dev> (raw)
In-Reply-To: <DIZC7F5O5216.P7LIA8OA7QRL@linux.dev>

On Wed Jun 3, 2026 at 10:20 AM UTC, Brendan Jackman wrote:
> On Tue Jun 2, 2026 at 9:39 PM UTC, Dave Hansen wrote:
>> On 5/3/26 06:04, Brendan Jackman wrote:
>> ...
>>> 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.
>>
>> It feels like we should say something about split_mem_range() here. All
>> of the guaranteed non-fiddly behavior originates in there, right?
>
> [pasting back the conditions from the commit message for context]
>>> 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).
>
> split_mem_range() is responsible for excluding point 1, since it returns
> the correct page_size_mask. The other two are actually down to the
> callers, right? 
>
> So how about for point 1 I mention that in the commit message, then for
> points 2 and 3 maybe they should actually be code comments, i.e.
> documented as preconditions for calling init_memory_mapping()?

For posterity: I realised that treating point 2 as a separate case is
bogus here. I was looking at the e820__mapped_any() blocks in
phys_*_init() and noting that they don't update the local paddr_last.
But actualy, those blocks only run for paddr>=paddr_end, which can
already only happen in case 1 i.e. when the range is misaligned wrt
page_size_mask.

So I'm just gonna drop that bit.

This realisation is really reinforcing that removing this return value
is the right thing to do.

>>> 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;
>>> +	}
>>
>> I guess this is actually:
>>
>> 	for (i = 0; i < nr_range; i++)
>> 		kernel_physical_mapping_init(...);
>>
>> 	paddr_last = mr[nr_range-1].end;
>>
>> Right? But what you have is probably just as compact.
>
> Oh, weird. My code might be just as compact but it's confusing, it
> should be written your way for sure.


  reply	other threads:[~2026-06-24 12:36 UTC|newest]

Thread overview: 14+ 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-06-02 21:30   ` Dave Hansen
2026-06-23 14:12   ` Marcel Busch
2026-05-03 13:04 ` [PATCH v2 2/3] x86/mm: simplify calculation of max_pfn_mapped Brendan Jackman
2026-06-02 21:39   ` Dave Hansen
2026-06-03 10:20     ` Brendan Jackman
2026-06-24 12:36       ` Brendan Jackman [this message]
2026-06-23 14:17   ` Marcel Busch
2026-05-03 13:04 ` [PATCH v2 3/3] x86/mm: drop unused returns from direct map setup functions Brendan Jackman
2026-06-02 21:40   ` Dave Hansen
2026-06-23 14:18   ` Marcel Busch
2026-05-27 12:40 ` [PATCH v2 0/3] x86/mm: some cleanups for pagetable setup code Brendan Jackman
2026-06-02 21:53 ` Dave Hansen

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=DJHA8ZQYK3JA.T39SY4N7QTGF@linux.dev \
    --to=brendan.jackman@linux.dev \
    --cc=bp@alien8.de \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jackmanb@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.