mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Andy Lutomirski" <luto@kernel.org>
To: "Borislav Petkov" <bp@alien8.de>
Cc: "Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Mike Rapoport" <rppt@linux.ibm.com>,
	"Hugh Dickins" <hughd@google.com>,
	"the arch/x86 maintainers" <x86@kernel.org>
Subject: Re: [tip: x86/urgent] x86/setup: Always reserve the first 1M of RAM
Date: Thu, 02 Mar 2023 07:06:11 -0800	[thread overview]
Message-ID: <840dcfd4-0d6c-400a-9cf7-8fe56d55ac7f@app.fastmail.com> (raw)
In-Reply-To: <ZAB/b+FjHjuRqe/S@zn.tnic>



On Thu, Mar 2, 2023, at 2:50 AM, Borislav Petkov wrote:
> On Wed, Mar 01, 2023 at 07:51:43PM -0800, Andy Lutomirski wrote:
>> This is quite broken.  The comments in the patch seem to understand
>> that Linux tries twice to allocate the real mode trampoline, but the
>> code has some issues.
>> 
>> First, it actively breaks the logic here:
>> 
>> +               /*
>> +                * Don't free memory under 1M for two reasons:
>> +                * - BIOS might clobber it
>> +                * - Crash kernel needs it to be reserved
>> +                */
>> +               if (start + size < SZ_1M)
>> +                       continue;
>> +               if (start < SZ_1M) {
>> +                       size -= (SZ_1M - start);
>> +                       start = SZ_1M;
>> +               }
>> +
>
> Are you refering, per-chance, here to your comment in that same function
> a bit higher?
>
> Introduced by this thing here:
>
> 5bc653b73182 ("x86/efi: Allocate a trampoline if needed in 
> efi_free_boot_services()")
>
> ?

Yes.

>
> Also, it looks like Mike did pay attention to your commit:
>
> https://lore.kernel.org/all/YLZsEaimyAe0x6b3@kernel.org/

He definitely did.  But I'm still pretty sure the patch in question broke it :-/

>
> And then there's the whole deal with kdump kernel needing lowmem. The
> function which became obsolete and got removed by:
>
> 23721c8e92f7 ("x86/crash: Remove crash_reserve_low_1M()")
>
> So, considering how yours is the only report that breaks booting and
> this reservation of <=1M has been out there for ~2 years without any
> complaints, I'm thinking what we should do now is fix that logic.
>
> Btw, this whole effort started with
>
>   a799c2bd29d1 ("x86/setup: Consolidate early memory reservations")
>
> Also see this:
>
> ec35d1d93bf8 ("x86/setup: Document that Windows reserves the first MiB")
>
> and with shit like that, we're "piggybacking" on Windoze since there
> certification happens at least.
>
> Which begs the question: how does your laptop even boot on windoze if
> windoze reserves that 1M too?!

I haven't booted Windoze on this thing in years.  But...

There is no possible way that Windoze genuinely reserves the first 1M. It does SMP, and x86 needs <1M memory for SMP, so Windoze uses <1M memory.  QED :)

>
>> I real the commit message and the linked bug, and I'm having trouble
>> finding evidence of anything actually fixed by this patch.  Can we
>> just revert it?  If not, it would be nice to get a fixup patch that
>> genuinely cleans this up -- the whole structure of the code (first,
>> try to allocate trampoline, then free boot services, then try again)
>> isn't really conducive to a model where we *don't* free boot services
>> < 1M.
>
> Yes, I think this makes most sense. And that whole area is a minefield
> so the less we upset the current universe, the better.

I'll send a revert patch.

Thinking about this a bit more, if we actually want to "reserve" <1M, we should implement it completely differently by treating <1M as its very own special thing and teaching the memblock allocator to refuse to allocate <1M unless specifically requested.  There's only a very small number of allocations that need it (crashkernel for some reason?), and there are at least two spurious users of memblock_phys_alloc_range that curently may use <1M but have no business doing so (ramdisk code and the NUMA distance table).  But let's only do that if there's an actual problem to solve.

>
>> Discovered by my delightful laptop, which does not boot with this patch applied.
>
> How come your laptop hasn't booted new Linux since then?!? Tztztztz

Honestly, no clue.  Looking at the logs, I'm pretty sure I *did* boot an affected (6.0) kernel.  The actual problematic memory map on this laptop seems to show up a bit inconsistently as some horrible combination of firmware settings (especially SGX) and who-knows-what else.  My best guess is that a GRUB update I installed yesterday caused some tiny memory map change that triggered it.

I did install a new kernel yesterday too, but the *previous* kernel stopped booting too.

>
> Thx.
>
> -- 
> Regards/Gruss,
>     Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette

  reply	other threads:[~2023-03-02 15:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-01  7:53 [PATCH 0/3] x86/setup: always resrve " Mike Rapoport
2021-06-01  7:53 ` [PATCH 1/3] x86/setup: always reserve " Mike Rapoport
2021-06-01  9:06   ` Baoquan He
2021-06-01 17:19     ` Mike Rapoport
2021-06-03 17:57   ` Borislav Petkov
2021-06-03 18:01   ` [tip: x86/urgent] x86/setup: Always " tip-bot2 for Mike Rapoport
2023-03-02  3:51     ` Andy Lutomirski
2023-03-02 10:50       ` Borislav Petkov
2023-03-02 15:06         ` Andy Lutomirski [this message]
2023-03-02 15:22           ` Borislav Petkov
2023-03-02 16:59       ` Andy Lutomirski
2023-03-03  9:10       ` Mike Rapoport
2023-03-07  0:33         ` Andy Lutomirski
2021-07-01 17:15   ` [PATCH 1/3] x86/setup: always " Dave Hansen
2021-07-01 19:45     ` Mike Rapoport
2021-06-01  7:53 ` [PATCH 2/3] x86/setup: remove CONFIG_X86_RESERVE_LOW and reservelow options Mike Rapoport
2021-06-07 12:22   ` [tip: x86/cleanups] x86/setup: Remove CONFIG_X86_RESERVE_LOW and reservelow= options tip-bot2 for Mike Rapoport
2021-06-01  7:53 ` [PATCH 3/3] x86/crash: remove crash_reserve_low_1M() Mike Rapoport
2021-06-07 12:22   ` [tip: x86/cleanups] x86/crash: Remove crash_reserve_low_1M() tip-bot2 for Mike Rapoport
2021-06-01 18:10 ` [PATCH 0/3] x86/setup: always resrve the first 1M of RAM Hugh Dickins

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=840dcfd4-0d6c-400a-9cf7-8fe56d55ac7f@app.fastmail.com \
    --to=luto@kernel.org \
    --cc=bp@alien8.de \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rppt@linux.ibm.com \
    --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

Powered by JetHome