All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Alexander Popov <alpopov@ptsecurity.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Andrey Konovalov <adech.fo@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andrey Ryabinin <a.ryabinin@samsung.com>,
	Andy Lutomirski <luto@kernel.org>,
	Alexander Kuleshov <kuleshovmail@gmail.com>,
	Denys Vlasenko <dvlasenk@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Kees Cook <keescook@chromium.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 1/2] x86_64: remove not needed clear_page for init_level4_page
Date: Tue, 16 Jun 2015 13:16:32 +0200	[thread overview]
Message-ID: <20150616111632.GF17786@pd.tnic> (raw)
In-Reply-To: <1433842921-18055-2-git-send-email-alpopov@ptsecurity.com>

On Tue, Jun 09, 2015 at 12:42:00PM +0300, Alexander Popov wrote:
> From: Andrey Ryabinin <a.ryabinin@samsung.com>
> 
> Commit 8170e6bed465 ("x86, 64bit: Use a #PF handler to materialize
> early mappings on demand") introduced clear_page(init_level4_pgt);
> call in x86_64_start_kernel(). However, this clear_page is useless
> because init_level4_page already filled with zeroes in head_64.S

I really doubt that, see below:

> Commit message in 8170e6bed465 says that this clear_page() was
> dropped in v7, but it accidentally reappeared in later versions
> of that patchset.
> 
> Signed-off-by: Andrey Ryabinin <a.ryabinin@samsung.com>
> ---
>  arch/x86/kernel/head64.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
> index 5a46681..6a6eefd 100644
> --- a/arch/x86/kernel/head64.c
> +++ b/arch/x86/kernel/head64.c
> @@ -177,7 +177,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
>  	 */
>  	load_ucode_bsp();
>  
> -	clear_page(init_level4_pgt);
>  	/* set init_level4_pgt kernel high mapping*/
>  	init_level4_pgt[511] = early_level4_pgt[511];

vmlinux has:

ffffffff81a00000 <init_level4_pgt>:
ffffffff81a00000:       63 10                   movslq (%rax),%edx
ffffffff81a00002:       a0 01 00 00 00 00 00    movabs 0x1,%al
ffffffff81a00009:       00 00 
        ...
ffffffff81a0087f:       00 63 10                add    %ah,0x10(%rbx)
ffffffff81a00882:       a0 01 00 00 00 00 00    movabs 0x1,%al
ffffffff81a00889:       00 00 
        ...
ffffffff81a00ff7:       00 67 30                add    %ah,0x30(%rdi)
ffffffff81a00ffa:       a0 01 00 00 00 00 63    movabs 0xa020630000000001,%al
ffffffff81a01001:       20 a0 

ffffffff81a01000 <level3_ident_pgt>:
ffffffff81a01000:       63 20                   movslq (%rax),%esp
ffffffff81a01002:       a0 01 00 00 00 00 00    movabs 0x1,%al
ffffffff81a01009:       00 00 
        ...

Booting a kvm quest and halting it before the clear_page:

---
        /*
         * Load microcode early on BSP.
         */
        load_ucode_bsp();

//      clear_page(init_level4_pgt);

        while(1)
                cpu_relax();

	/* set init_level4_pgt kernel high mapping*/
	init_level4_pgt[511] = early_level4_pgt[511];
---

and dumping the memory at ffffffff81a00000 gives:

---
00000000  63 10 a0 01 00 00 00 00  00 00 00 00 00 00 00 00  |c...............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000880  63 10 a0 01 00 00 00 00  00 00 00 00 00 00 00 00  |c...............|
00000890  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000ff0  00 00 00 00 00 00 00 00  67 30 a0 01 00 00 00 00  |........g0......|
00001000
---

These are basically the PTE entries it gets for the CONFIG_XEN case
which we clear because we're on baremetal.

Now my hunch is that those entries get overwritten later but I wouldn't
want to debug any strange bugs from leftovers in init_level4_pgt so
having the clear_page() is actually a good thing.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

  reply	other threads:[~2015-06-16 11:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-09  9:41 [PATCH v5 0/2] x86_64: fix KASan shadow region page tables Alexander Popov
2015-06-09  9:42 ` [PATCH v5 1/2] x86_64: remove not needed clear_page for init_level4_page Alexander Popov
2015-06-16 11:16   ` Borislav Petkov [this message]
2015-06-16 11:34     ` Borislav Petkov
2015-06-16 11:45       ` Andrey Ryabinin
2015-06-16 15:46         ` Borislav Petkov
2015-06-17 11:43           ` Alexander Popov
2015-06-09  9:42 ` [PATCH v5 2/2] x86_64: fix KASan shadow region page tables Alexander Popov
2015-06-12 17:13   ` Andrey Ryabinin

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=20150616111632.GF17786@pd.tnic \
    --to=bp@alien8.de \
    --cc=a.ryabinin@samsung.com \
    --cc=adech.fo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alpopov@ptsecurity.com \
    --cc=dvlasenk@redhat.com \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=kuleshovmail@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --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.