All of lore.kernel.org
 help / color / mirror / Atom feed
From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm64: avoid TLB conflict with CONFIG_RANDOMIZE_BASE
Date: Thu, 25 Aug 2016 10:52:33 +0100	[thread overview]
Message-ID: <20160825095233.GD6630@arm.com> (raw)
In-Reply-To: <1472058128-1216-1-git-send-email-mark.rutland@arm.com>

On Wed, Aug 24, 2016 at 06:02:08PM +0100, Mark Rutland wrote:
> When CONFIG_RANDOMIZE_BASE is selected, we modify the page tables to remap the
> kernel at a newly-chosen VA range. We do this with the MMU disabled, but do not
> invalidate TLBs prior to re-enabling the MMU with the new tables. Thus the old
> mappings entries may still live in TLBs, and we risk violating
> Break-Before-Make requirements, leading to TLB conflicts and/or other issues.
> 
> We invalidate TLBs when we uninsall the idmap in early setup code, but prior to
> this we are subject to issues relating to the Break-Before-Make violation.
> 
> Avoid these issues by invalidating the TLBs before the new mappings can be
> used by the hardware.
> 
> Fixes: f80fb3a3d50843a4 ("arm64: add support for kernel ASLR")
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: stable at vger.kernel.org
> ---
>  arch/arm64/kernel/head.S | 3 +++
>  1 file changed, 3 insertions(+)

Acked-by: Will Deacon <will.deacon@arm.com>

Although I do wonder whether it would be cleaner to do the local TLBI
in __create_page_tables after zeroing swapper, and then moving the TLBI
out of __cpu_setup and onto the secondary boot path. I suppose it doesn't
really matter...

Will

> diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> index b77f583..3e7b050 100644
> --- a/arch/arm64/kernel/head.S
> +++ b/arch/arm64/kernel/head.S
> @@ -757,6 +757,9 @@ ENTRY(__enable_mmu)
>  	isb
>  	bl	__create_page_tables		// recreate kernel mapping
>  
> +	tlbi	vmalle1				// Remove any stale TLB entries
> +	dsb	nsh
> +
>  	msr	sctlr_el1, x19			// re-enable the MMU
>  	isb
>  	ic	iallu				// flush instructions fetched
> -- 
> 2.7.4
> 

WARNING: multiple messages have this Message-ID (diff)
From: Will Deacon <will.deacon@arm.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH] arm64: avoid TLB conflict with CONFIG_RANDOMIZE_BASE
Date: Thu, 25 Aug 2016 10:52:33 +0100	[thread overview]
Message-ID: <20160825095233.GD6630@arm.com> (raw)
In-Reply-To: <1472058128-1216-1-git-send-email-mark.rutland@arm.com>

On Wed, Aug 24, 2016 at 06:02:08PM +0100, Mark Rutland wrote:
> When CONFIG_RANDOMIZE_BASE is selected, we modify the page tables to remap the
> kernel at a newly-chosen VA range. We do this with the MMU disabled, but do not
> invalidate TLBs prior to re-enabling the MMU with the new tables. Thus the old
> mappings entries may still live in TLBs, and we risk violating
> Break-Before-Make requirements, leading to TLB conflicts and/or other issues.
> 
> We invalidate TLBs when we uninsall the idmap in early setup code, but prior to
> this we are subject to issues relating to the Break-Before-Make violation.
> 
> Avoid these issues by invalidating the TLBs before the new mappings can be
> used by the hardware.
> 
> Fixes: f80fb3a3d50843a4 ("arm64: add support for kernel ASLR")
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: stable@vger.kernel.org
> ---
>  arch/arm64/kernel/head.S | 3 +++
>  1 file changed, 3 insertions(+)

Acked-by: Will Deacon <will.deacon@arm.com>

Although I do wonder whether it would be cleaner to do the local TLBI
in __create_page_tables after zeroing swapper, and then moving the TLBI
out of __cpu_setup and onto the secondary boot path. I suppose it doesn't
really matter...

Will

> diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> index b77f583..3e7b050 100644
> --- a/arch/arm64/kernel/head.S
> +++ b/arch/arm64/kernel/head.S
> @@ -757,6 +757,9 @@ ENTRY(__enable_mmu)
>  	isb
>  	bl	__create_page_tables		// recreate kernel mapping
>  
> +	tlbi	vmalle1				// Remove any stale TLB entries
> +	dsb	nsh
> +
>  	msr	sctlr_el1, x19			// re-enable the MMU
>  	isb
>  	ic	iallu				// flush instructions fetched
> -- 
> 2.7.4
> 

  parent reply	other threads:[~2016-08-25  9:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-24 17:02 [PATCH] arm64: avoid TLB conflict with CONFIG_RANDOMIZE_BASE Mark Rutland
2016-08-24 17:02 ` Mark Rutland
2016-08-24 20:41 ` Ard Biesheuvel
2016-08-24 20:41   ` Ard Biesheuvel
2016-08-25  9:52 ` Will Deacon [this message]
2016-08-25  9:52   ` Will Deacon
2016-08-25 10:14 ` Catalin Marinas
2016-08-25 10:14   ` Catalin Marinas

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=20160825095233.GD6630@arm.com \
    --to=will.deacon@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 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.