All of lore.kernel.org
 help / color / mirror / Atom feed
From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/8] arm64: kernel: use literal for relocated address of __secondary_switched
Date: Mon, 18 Apr 2016 16:57:33 +0100	[thread overview]
Message-ID: <20160418155733.GB7521@leverpostej> (raw)
In-Reply-To: <1460992188-23295-3-git-send-email-ard.biesheuvel@linaro.org>

On Mon, Apr 18, 2016 at 05:09:42PM +0200, Ard Biesheuvel wrote:
> We can simply use a relocated 64-bit literal to store the address of
> __secondary_switched(), and the relocation code will ensure that it
> holds the correct value at secondary entry time, as long as we make sure
> that the literal is not dereferenced until after we have enabled the MMU.
> 
> So jump via a small __secondary_switch() function covered by the ID map
> that performs the literal load and branch-to-register.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Neat!

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/arm64/kernel/head.S | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> index ac27d8d937b2..f13276d4ca91 100644
> --- a/arch/arm64/kernel/head.S
> +++ b/arch/arm64/kernel/head.S
> @@ -468,9 +468,7 @@ __mmap_switched:
>  	str	x15, [x11, x23]
>  	b	0b
>  
> -2:	adr_l	x8, kimage_vaddr		// make relocated kimage_vaddr
> -	dc	cvac, x8			// value visible to secondaries
> -	dsb	sy				// with MMU off
> +2:
>  #endif
>  
>  	adr_l	sp, initial_sp, x4
> @@ -699,12 +697,9 @@ secondary_startup:
>  	adrp	x26, swapper_pg_dir
>  	bl	__cpu_setup			// initialise processor
>  
> -	ldr	x8, kimage_vaddr
> -	ldr	w9, 0f
> -	sub	x27, x8, w9, sxtw		// address to jump to after enabling the MMU
> +	adr_l	x27, __secondary_switch		// address to jump to after enabling the MMU
>  	b	__enable_mmu
>  ENDPROC(secondary_startup)
> -0:	.long	(_text - TEXT_OFFSET) - __secondary_switched
>  
>  __secondary_switched:
>  	adr_l	x5, vectors
> @@ -806,3 +801,8 @@ __no_granule_support:
>  	wfi
>  	b 1b
>  ENDPROC(__no_granule_support)
> +
> +__secondary_switch:
> +	ldr	x8, =__secondary_switched
> +	br	x8
> +ENDPROC(__secondary_switch)
> -- 
> 2.5.0
> 

WARNING: multiple messages have this Message-ID (diff)
From: Mark Rutland <mark.rutland@arm.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, will.deacon@arm.com,
	james.morse@arm.com, catalin.marinas@arm.com
Subject: Re: [PATCH 2/8] arm64: kernel: use literal for relocated address of __secondary_switched
Date: Mon, 18 Apr 2016 16:57:33 +0100	[thread overview]
Message-ID: <20160418155733.GB7521@leverpostej> (raw)
In-Reply-To: <1460992188-23295-3-git-send-email-ard.biesheuvel@linaro.org>

On Mon, Apr 18, 2016 at 05:09:42PM +0200, Ard Biesheuvel wrote:
> We can simply use a relocated 64-bit literal to store the address of
> __secondary_switched(), and the relocation code will ensure that it
> holds the correct value at secondary entry time, as long as we make sure
> that the literal is not dereferenced until after we have enabled the MMU.
> 
> So jump via a small __secondary_switch() function covered by the ID map
> that performs the literal load and branch-to-register.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Neat!

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/arm64/kernel/head.S | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> index ac27d8d937b2..f13276d4ca91 100644
> --- a/arch/arm64/kernel/head.S
> +++ b/arch/arm64/kernel/head.S
> @@ -468,9 +468,7 @@ __mmap_switched:
>  	str	x15, [x11, x23]
>  	b	0b
>  
> -2:	adr_l	x8, kimage_vaddr		// make relocated kimage_vaddr
> -	dc	cvac, x8			// value visible to secondaries
> -	dsb	sy				// with MMU off
> +2:
>  #endif
>  
>  	adr_l	sp, initial_sp, x4
> @@ -699,12 +697,9 @@ secondary_startup:
>  	adrp	x26, swapper_pg_dir
>  	bl	__cpu_setup			// initialise processor
>  
> -	ldr	x8, kimage_vaddr
> -	ldr	w9, 0f
> -	sub	x27, x8, w9, sxtw		// address to jump to after enabling the MMU
> +	adr_l	x27, __secondary_switch		// address to jump to after enabling the MMU
>  	b	__enable_mmu
>  ENDPROC(secondary_startup)
> -0:	.long	(_text - TEXT_OFFSET) - __secondary_switched
>  
>  __secondary_switched:
>  	adr_l	x5, vectors
> @@ -806,3 +801,8 @@ __no_granule_support:
>  	wfi
>  	b 1b
>  ENDPROC(__no_granule_support)
> +
> +__secondary_switch:
> +	ldr	x8, =__secondary_switched
> +	br	x8
> +ENDPROC(__secondary_switch)
> -- 
> 2.5.0
> 

  reply	other threads:[~2016-04-18 15:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-18 15:09 [PATCH 0/8] arm64: kaslr cleanups and improvements Ard Biesheuvel
2016-04-18 15:09 ` Ard Biesheuvel
2016-04-18 15:09 ` [PATCH 1/8] arm64: kernel: don't export local symbols from head.S Ard Biesheuvel
2016-04-18 15:09   ` Ard Biesheuvel
2016-04-18 15:35   ` Mark Rutland
2016-04-18 15:35     ` Mark Rutland
2016-04-18 15:09 ` [PATCH 2/8] arm64: kernel: use literal for relocated address of __secondary_switched Ard Biesheuvel
2016-04-18 15:09   ` Ard Biesheuvel
2016-04-18 15:57   ` Mark Rutland [this message]
2016-04-18 15:57     ` Mark Rutland
2016-04-18 15:09 ` [PATCH 3/8] arm64: kernel: perform relocation processing from ID map Ard Biesheuvel
2016-04-18 15:09   ` Ard Biesheuvel
2016-04-18 15:09 ` [PATCH 4/8] arm64: introduce mov_q macro to move a constant into a 64-bit register Ard Biesheuvel
2016-04-18 15:09   ` Ard Biesheuvel
2016-04-18 15:09 ` [PATCH 5/8] arm64: kernel: replace early 64-bit literal loads with move-immediates Ard Biesheuvel
2016-04-18 15:09   ` Ard Biesheuvel
2016-04-19 14:29   ` Laurentiu Tudor
2016-04-19 14:29     ` Laurentiu Tudor
2016-04-18 15:09 ` [PATCH 6/8] arm64: don't map TEXT_OFFSET bytes below the kernel if we can avoid it Ard Biesheuvel
2016-04-18 15:09   ` Ard Biesheuvel
2016-04-18 15:09 ` [PATCH 7/8] arm64: relocatable: deal with physically misaligned kernel images Ard Biesheuvel
2016-04-18 15:09   ` Ard Biesheuvel
2016-04-18 15:09 ` [PATCH 8/8] arm64: kaslr: increase randomization granularity Ard Biesheuvel
2016-04-18 15:09   ` Ard Biesheuvel
2016-04-26 11:27   ` Will Deacon
2016-04-26 11:27     ` Will Deacon
2016-04-26 15:27     ` Matt Fleming
2016-04-26 15:27       ` Matt Fleming
2016-04-25 16:38 ` [PATCH 0/8] arm64: kaslr cleanups and improvements Catalin Marinas
2016-04-25 16:38   ` 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=20160418155733.GB7521@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 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.