From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm64: mm: move zero page from .bss to right before swapper_pg_dir
Date: Mon, 12 Sep 2016 13:57:10 +0100 [thread overview]
Message-ID: <20160912125710.GA13899@leverpostej> (raw)
In-Reply-To: <1473604714-5512-1-git-send-email-ard.biesheuvel@linaro.org>
Hi,
On Sun, Sep 11, 2016 at 03:38:34PM +0100, Ard Biesheuvel wrote:
> Move the statically allocated zero page from the .bss section to right
> before swapper_pg_dir. This allows us to refer to its physical address
> by simply reading TTBR1_EL1 (which always points to swapper_pg_dir and
> always has its ASID field cleared), and subtracting PAGE_SIZE.
On a conflicting note, I was hoping to move the zero page into .rodata
so as to catch any erroneous modification.
Given that we can't rely on TTBR1 poiting at the swapper_pg_dir, that
leaves us with Image size reduction vs RO-ification.
Any thoughts/preference?
Thanks,
Mark,
> Inspired-by: http://marc.info/?l=linux-arm-kernel&m=147282867511801
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> arch/arm64/include/asm/mmu_context.h | 10 ++++++----
> arch/arm64/kernel/head.S | 1 -
> arch/arm64/kernel/vmlinux.lds.S | 2 ++
> arch/arm64/mm/mmu.c | 1 -
> 4 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h
> index b1892a0dbcb0..94461ba5febd 100644
> --- a/arch/arm64/include/asm/mmu_context.h
> +++ b/arch/arm64/include/asm/mmu_context.h
> @@ -49,13 +49,15 @@ static inline void contextidr_thread_switch(struct task_struct *next)
> */
> static inline void cpu_set_reserved_ttbr0(void)
> {
> - unsigned long ttbr = virt_to_phys(empty_zero_page);
> + unsigned long dummy;
>
> - asm(
> + asm volatile(
> + " mrs %0, ttbr1_el1 // get TTBR1\n"
> + " sub %0, %0, %1 // subtract PAGE_SIZE\n"
> " msr ttbr0_el1, %0 // set TTBR0\n"
> " isb"
> - :
> - : "r" (ttbr));
> + : "=&r" (dummy)
> + : "I" (PAGE_SIZE));
> }
>
> /*
> diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> index 8bc9458f9add..6020b884b076 100644
> --- a/arch/arm64/kernel/head.S
> +++ b/arch/arm64/kernel/head.S
> @@ -449,7 +449,6 @@ __primary_switched:
> adr_l x2, __bss_stop
> sub x2, x2, x0
> bl __pi_memset
> - dsb ishst // Make zero page visible to PTW
>
> #ifdef CONFIG_KASAN
> bl kasan_early_init
> diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
> index 659963d40bb4..a14eb8ff5144 100644
> --- a/arch/arm64/kernel/vmlinux.lds.S
> +++ b/arch/arm64/kernel/vmlinux.lds.S
> @@ -193,6 +193,8 @@ SECTIONS
> . = ALIGN(PAGE_SIZE);
> idmap_pg_dir = .;
> . += IDMAP_DIR_SIZE;
> + empty_zero_page = .;
> + . += PAGE_SIZE;
> swapper_pg_dir = .;
> . += SWAPPER_DIR_SIZE;
>
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index 4989948d1feb..539ce9d11325 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -53,7 +53,6 @@ EXPORT_SYMBOL(kimage_voffset);
> * Empty_zero_page is a special page that is used for zero-initialized data
> * and COW.
> */
> -unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss;
> EXPORT_SYMBOL(empty_zero_page);
>
> static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss;
> --
> 2.7.4
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
next prev parent reply other threads:[~2016-09-12 12:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-11 14:38 [PATCH] arm64: mm: move zero page from .bss to right before swapper_pg_dir Ard Biesheuvel
2016-09-11 16:40 ` Ard Biesheuvel
2016-09-12 12:57 ` Mark Rutland [this message]
2016-09-12 14:17 ` Ard Biesheuvel
2016-09-12 14:20 ` Catalin Marinas
-- strict thread matches above, loose matches on Subject: below --
2016-09-12 14:16 Ard Biesheuvel
2016-09-12 14:59 ` Mark Rutland
2016-09-12 15:12 ` Ard Biesheuvel
2016-09-12 15:40 ` Mark Rutland
2016-09-12 15:54 ` Ard Biesheuvel
2016-09-12 16:26 ` Mark Rutland
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=20160912125710.GA13899@leverpostej \
--to=mark.rutland@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).