mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Borislav Petkov <bp@suse.de>,
	tglx@linutronix.de, torvalds@linux-foundation.org,
	linux-kernel@vger.kernel.org, willy@infradead.org, hpa@zytor.com,
	kirill.shutemov@linux.intel.com, peterz@infradead.org,
	gorcunov@openvz.org, luto@amacapital.net,
	linux-tip-commits@vger.kernel.org
Subject: Re: [tip:x86/boot] x86/boot/compressed/64: Prepare trampoline memory
Date: Mon, 26 Feb 2018 09:47:00 +0100	[thread overview]
Message-ID: <20180226084700.vpjavqk6e4xfyapa@gmail.com> (raw)
In-Reply-To: <20180226080256.j7jzuxyokx42uytd@node.shutemov.name>


* Kirill A. Shutemov <kirill@shutemov.name> wrote:

> > Also, could do a puts() hexdump of the affected memory area _before_ we overwrite 
> > it? Is it empty? Could we add some debug warning that checks that it's all zeroes?
> 
> The problem is that we don't really have a way get a message out of there.

Is there any memory area we can write to that survives into the real kernel?

> But without a way to print address it's still a black box.

> > 1)
> > 
> >         /* Check if LA57 is desired and supported */
> >         if (IS_ENABLED(CONFIG_X86_5LEVEL) && native_cpuid_eax(0) >= 7 &&
> >                         (native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31))))
> >                 paging_config.l5_required = 1;
> > 
> > ... it isn't explained why this feature CPU check is so complex.
> 
> We check that the CPUID leaf is supported and than check the feature
> itself.
> 
> Maybe the first check is redundant, but I tried to be safe here.

So the explanation that is missing is to explain which usual primitive this is 
equivalent to. This is essentially an early boot variant of 
boot_cpu_has(X86_FEATURE_LA57), right?

> > 2)
> > 
> > +       /* Place the trampoline just below the end of low memory, aligned to 4k */
> > +       paging_config.trampoline_start = bios_start - TRAMPOLINE_32BIT_SIZE;
> > +       paging_config.trampoline_start = round_down(paging_config.trampoline_start, PAGE_SIZE);
> > 
> > placing trampolines just below or just above BIOS images is fragile. Instead a 
> > better heuristic is to use the "middle" of suspected available RAM and work from 
> > there.
> 
> It's not obvious what is lower end of available memory here. Any hints?
> 
> Realtime trampoline is allocated with top-down approach and I tried to
> mimic the approach here.

Yeah, it's all a bit weird - I'm grasping at straws really - and the large size of 
the patch doesn't help.

> > +       /* Clear trampoline memory first */
> > +       memset(trampoline, 0, TRAMPOLINE_32BIT_SIZE);
> > 
> > Memory bootup state is typically all zeroes (except maybe for kexec), so this 
> > should check that what it's clearing doesn't contain any data.
> 
> Hm. I don't see why would we expect this. Do we really have guarantee that
> bootloader would not mess with the memory?

Hm, probably not - what's the typical memory usage of GRUB for example?

> > It should probably also clear this memory _after_ use.
> 
> After use I tired to restore the original content of the memory.
> See cleanup_trampoline(). That looks safer to me.

Yeah, agreed.

BTW., it's still a possibility that we are barking up the wrong tree here: if the 
bug Boris triggered is somehow not fully deterministic (but say kernel build 
alignment dependent - which alignment your commit changed) then this might be the 
wrong commit. A split-up into several patches would help there too: for example if 
the new data structures in the kernel image trigger the bug (with nothing else in 
that commit) then it strongly suggests that it's alignment related, etc.

But it certainly 'feels' to have a chance to be related: stomping on the wrong 
piece of memory can make graphics fail.

> > Why '+ _PAGE_TABLE_NOENC', while not ' |' ?
> 
> It shouldn't really matter, but yeah, '|' is more appropriate.

Readability and using standard patterns is king.

Thanks,

	Ingo

  parent reply	other threads:[~2018-02-26  8:47 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-09 14:22 [PATCHv9 0/4] x86: 5-level related changes into decompression code Kirill A. Shutemov
2018-02-09 14:22 ` [PATCHv9 1/4] x86/boot/compressed/64: Rename pagetable.c to kaslr_64.c Kirill A. Shutemov
2018-02-11 12:18   ` [tip:x86/boot] " tip-bot for Kirill A. Shutemov
2018-02-09 14:22 ` [PATCHv9 2/4] x86/boot/compressed/64: Introduce paging_prepare() Kirill A. Shutemov
2018-02-11 12:19   ` [tip:x86/boot] " tip-bot for Kirill A. Shutemov
2018-02-09 14:22 ` [PATCHv9 3/4] x86/boot/compressed/64: Prepare trampoline memory Kirill A. Shutemov
2018-02-11 12:19   ` [tip:x86/boot] " tip-bot for Kirill A. Shutemov
2018-02-13 18:32     ` Cyrill Gorcunov
2018-02-24 21:48     ` Borislav Petkov
2018-02-25 10:52       ` Kirill A. Shutemov
2018-02-25 12:29         ` Borislav Petkov
2018-02-25 14:09           ` Kirill A. Shutemov
2018-02-26  7:35         ` Ingo Molnar
2018-02-26  7:50           ` Ingo Molnar
2018-02-26  8:04             ` Kirill A. Shutemov
2018-02-26  8:02           ` Kirill A. Shutemov
2018-02-26  8:15             ` Cyrill Gorcunov
2018-02-26  8:37               ` Kirill A. Shutemov
2018-02-26  8:49                 ` Cyrill Gorcunov
2018-02-26  8:47             ` Ingo Molnar [this message]
2018-02-26 10:54             ` Borislav Petkov
2018-02-09 14:22 ` [PATCHv9 4/4] x86/boot/compressed/64: Handle 5-level paging boot if kernel is above 4G Kirill A. Shutemov
2018-02-11 12:20   ` [tip:x86/boot] " tip-bot for Kirill A. Shutemov
2018-02-13  6:51     ` Andrei Vagin
2018-02-13  8:08       ` Kirill A. Shutemov
2018-02-13  8:41         ` Andrei Vagin
2018-02-13  9:02           ` Kirill A. Shutemov
2018-02-13  9:43             ` Ingo Molnar
2018-02-13 10:00               ` Kirill A. Shutemov
2018-02-13 11:32                 ` Ingo Molnar
2018-02-13 16:53             ` Andrei Vagin
2018-02-13 17:17               ` Ingo Molnar
2018-02-13 17:59                 ` Dmitry Safonov
2018-02-13 18:05                   ` Ingo Molnar
2018-02-13 17:21   ` tip-bot for Kirill A. Shutemov
2018-02-13 17:42     ` Kirill A. Shutemov
2018-02-13 18:09   ` tip-bot for Kirill A. Shutemov
2018-02-11 11:37 ` [PATCHv9 0/4] x86: 5-level related changes into decompression code Ingo Molnar

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=20180226084700.vpjavqk6e4xfyapa@gmail.com \
    --to=mingo@kernel.org \
    --cc=bp@suse.de \
    --cc=gorcunov@openvz.org \
    --cc=hpa@zytor.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.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®