From: yaojun8558363@gmail.com (Jun Yao)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 3/5] arm64/mm: Create initial page tables in init_pg_dir
Date: Wed, 15 Aug 2018 18:26:06 +0800 [thread overview]
Message-ID: <20180815102606.GA2274@toy> (raw)
In-Reply-To: <41a18121-c91d-f9ec-87c3-8dba7931b517@arm.com>
Hi James,
On Fri, Jul 06, 2018 at 03:41:07PM +0100, James Morse wrote:
> I missed one: head.S has a call to kasan_early_init() before start_kernel(),
> this goes messing with the page tables, and calls pgd_offset_k(), which pulls in
> swapper_pg_dir. This one is enabled by CONFIG_KASAN.
>
> Something like that same hunk [0] in kasan_early_init() fixes it. This is still
> within arch/arm64, so I still think we should get away without some #ifdeffery
> to override the core-code's initial setup of swapper_pg_dir...
I'm sorry to reply you so late, I missed this email before.
In order to ensure that pgd_offset_k() works properly, I update
init_mm.pgd by introducing set_init_mm_pgd(). And its implementation is
like this:
>diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>index 65f86271f02b..e4f0868b4cfd 100644
>--- a/arch/arm64/mm/mmu.c
>+++ b/arch/arm64/mm/mmu.c
>@@ -623,6 +623,19 @@ static void __init map_kernel(pgd_t *pgdp)
> kasan_copy_shadow(pgdp);
> }
>
>+void __init set_init_mm_pgd(pgd_t *pgd)
>+{
>+ pgd_t **addr = &(init_mm.pgd);
>+
>+ asm volatile("str %x0, [%1]\n"
>+ : : "r" (pgd), "r" (addr) : "memory");
>+}
> /*
> * paging_init() sets up the page tables, initialises the zone memory
> * maps and sets up the zero page.
The purpose of using assembly is to prevent KASAN instrumentation, as
KASAN has not been initialized when this function is called:
>diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
>index c3e4b1886cde..ede2e964592b 100644
>--- a/arch/arm64/kernel/head.S
>+++ b/arch/arm64/kernel/head.S
>@@ -439,6 +438,9 @@ __primary_switched:
> bl __pi_memset
> dsb ishst // Make zero page visible to PTW
>
>+ adrp x0, init_pg_dir
>+ bl set_init_mm_pgd
>+
> #ifdef CONFIG_KASAN
> bl kasan_early_init
> #endif
What do you think?
WARNING: multiple messages have this Message-ID (diff)
From: Jun Yao <yaojun8558363@gmail.com>
To: James Morse <james.morse@arm.com>
Cc: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com,
will.deacon@arm.com, suzuki.poulose@arm.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/5] arm64/mm: Create initial page tables in init_pg_dir
Date: Wed, 15 Aug 2018 18:26:06 +0800 [thread overview]
Message-ID: <20180815102606.GA2274@toy> (raw)
In-Reply-To: <41a18121-c91d-f9ec-87c3-8dba7931b517@arm.com>
Hi James,
On Fri, Jul 06, 2018 at 03:41:07PM +0100, James Morse wrote:
> I missed one: head.S has a call to kasan_early_init() before start_kernel(),
> this goes messing with the page tables, and calls pgd_offset_k(), which pulls in
> swapper_pg_dir. This one is enabled by CONFIG_KASAN.
>
> Something like that same hunk [0] in kasan_early_init() fixes it. This is still
> within arch/arm64, so I still think we should get away without some #ifdeffery
> to override the core-code's initial setup of swapper_pg_dir...
I'm sorry to reply you so late, I missed this email before.
In order to ensure that pgd_offset_k() works properly, I update
init_mm.pgd by introducing set_init_mm_pgd(). And its implementation is
like this:
>diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>index 65f86271f02b..e4f0868b4cfd 100644
>--- a/arch/arm64/mm/mmu.c
>+++ b/arch/arm64/mm/mmu.c
>@@ -623,6 +623,19 @@ static void __init map_kernel(pgd_t *pgdp)
> kasan_copy_shadow(pgdp);
> }
>
>+void __init set_init_mm_pgd(pgd_t *pgd)
>+{
>+ pgd_t **addr = &(init_mm.pgd);
>+
>+ asm volatile("str %x0, [%1]\n"
>+ : : "r" (pgd), "r" (addr) : "memory");
>+}
> /*
> * paging_init() sets up the page tables, initialises the zone memory
> * maps and sets up the zero page.
The purpose of using assembly is to prevent KASAN instrumentation, as
KASAN has not been initialized when this function is called:
>diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
>index c3e4b1886cde..ede2e964592b 100644
>--- a/arch/arm64/kernel/head.S
>+++ b/arch/arm64/kernel/head.S
>@@ -439,6 +438,9 @@ __primary_switched:
> bl __pi_memset
> dsb ishst // Make zero page visible to PTW
>
>+ adrp x0, init_pg_dir
>+ bl set_init_mm_pgd
>+
> #ifdef CONFIG_KASAN
> bl kasan_early_init
> #endif
What do you think?
next prev parent reply other threads:[~2018-08-15 10:26 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-02 11:16 [PATCH v3 0/5] Move {idmap_pg_dir,swapper_pg_dir} to .rodata Jun Yao
2018-07-02 11:16 ` Jun Yao
2018-07-02 11:16 ` [PATCH v3 1/5] arm64/mm: Introduce init_pg_dir Jun Yao
2018-07-02 11:16 ` Jun Yao
2018-07-06 8:56 ` James Morse
2018-07-06 8:56 ` James Morse
2018-07-02 11:16 ` [PATCH v3 2/5] arm64/mm: Make __enable_mmu() take the ttbr1 page as an argument Jun Yao
2018-07-02 11:16 ` Jun Yao
2018-07-06 8:57 ` James Morse
2018-07-06 8:57 ` James Morse
2018-07-02 11:16 ` [PATCH v3 3/5] arm64/mm: Create initial page tables in init_pg_dir Jun Yao
2018-07-02 11:16 ` Jun Yao
2018-07-06 8:58 ` James Morse
2018-07-06 8:58 ` James Morse
2018-07-06 14:41 ` James Morse
2018-07-06 14:41 ` James Morse
2018-08-15 10:26 ` Jun Yao [this message]
2018-08-15 10:26 ` Jun Yao
2018-07-02 11:16 ` [PATCH v3 4/5] arm64/mm: Make swapper_pg_dir smaller Jun Yao
2018-07-02 11:16 ` Jun Yao
2018-07-06 8:58 ` James Morse
2018-07-06 8:58 ` James Morse
2018-07-02 11:16 ` [PATCH v3 5/5] arm64/mm: Move {idmap_pg_dir, swapper_pg_dir} to .rodata section Jun Yao
2018-07-02 11:16 ` Jun Yao
2018-07-11 16:15 ` James Morse
2018-07-11 16:15 ` James Morse
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=20180815102606.GA2274@toy \
--to=yaojun8558363@gmail.com \
--cc=linux-arm-kernel@lists.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 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.