linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 4/9] arm64: kpti: Add ->enable callback to remap swapper using nG mappings
Date: Tue, 30 Jan 2018 10:30:41 +0000	[thread overview]
Message-ID: <20180130103041.GA29693@arm.com> (raw)
In-Reply-To: <1517227200-20412-5-git-send-email-will.deacon@arm.com>

On Mon, Jan 29, 2018 at 11:59:55AM +0000, Will Deacon wrote:
> Defaulting to global mappings for kernel space is generally good for
> performance and appears to be necessary for Cavium ThunderX. If we
> subsequently decide that we need to enable kpti, then we need to rewrite
> our existing page table entries to be non-global. This is fiddly, and
> made worse by the possible use of contiguous mappings, which require
> a strict break-before-make sequence.
> 
> Since the enable callback runs on each online CPU from stop_machine
> context, we can have all CPUs enter the idmap, where secondaries can
> wait for the primary CPU to rewrite swapper with its MMU off. It's all
> fairly horrible, but at least it only runs once.
> 
> Tested-by: Marc Zyngier <marc.zyngier@arm.com>
> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
> Signed-off-by: Will Deacon <will.deacon@arm.com>
> ---
>  arch/arm64/include/asm/assembler.h |  10 ++
>  arch/arm64/kernel/cpufeature.c     |  25 +++++
>  arch/arm64/mm/proc.S               | 204 +++++++++++++++++++++++++++++++++++--
>  3 files changed, 231 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
> index 3873dd7b5a32..23251eae6e8a 100644
> --- a/arch/arm64/include/asm/assembler.h
> +++ b/arch/arm64/include/asm/assembler.h
> @@ -523,6 +523,16 @@ alternative_endif
>  #endif
>  	.endm
>  
> +	.macro	pte_to_phys, phys, pte
> +#ifdef CONFIG_ARM64_PA_BITS_52
> +	ror	\phys, \pte, #16
> +	bfi	\phys, \phys, #(16 + 12), #32
> +	lsr	\phys, \phys, #12

I spun this up on a model with 52-bit PA support and it doesn't work,
unfortunately, because the lsr of #12 leaves 4 bits of the OA in the bottom
nybble. Instead, we need the following on top:

diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
index f311a1ed34d0..f4f3350f697e 100644
--- a/arch/arm64/include/asm/assembler.h
+++ b/arch/arm64/include/asm/assembler.h
@@ -539,9 +539,9 @@ alternative_endif
 
 	.macro	pte_to_phys, phys, pte
 #ifdef CONFIG_ARM64_PA_BITS_52
-	ror	\phys, \pte, #16
-	bfi	\phys, \phys, #(16 + 12), #32
-	lsr	\phys, \phys, #12
+	ubfiz	\phys, \pte, #(48 - 16 - 12), #16
+	bfxil	\phys, \pte, #16, #32
+	lsl	\phys, \phys, #16
 #else
 	and	\phys, \pte, #PTE_ADDR_MASK
 #endif

Will

  reply	other threads:[~2018-01-30 10:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-29 11:59 [PATCH v2 0/9] Fix kpti-enabled kernels for Cavium ThunderX Will Deacon
2018-01-29 11:59 ` [PATCH v2 1/9] arm64: Add software workaround for Falkor erratum 1041 Will Deacon
2018-01-29 11:59 ` [PATCH v2 2/9] arm64: kpti: Make use of nG dependent on arm64_kernel_unmapped_at_el0() Will Deacon
2018-01-29 11:59 ` [PATCH v2 3/9] arm64: mm: Permit transitioning from Global to Non-Global without BBM Will Deacon
2018-01-29 11:59 ` [PATCH v2 4/9] arm64: kpti: Add ->enable callback to remap swapper using nG mappings Will Deacon
2018-01-30 10:30   ` Will Deacon [this message]
2018-01-29 11:59 ` [PATCH v2 5/9] arm64: Force KPTI to be disabled on Cavium ThunderX Will Deacon
2018-01-29 11:59 ` [PATCH v2 6/9] arm64: assembler: Change order of macro arguments in phys_to_ttbr Will Deacon
2018-01-29 11:59 ` [PATCH v2 7/9] arm64: entry: Reword comment about post_ttbr_update_workaround Will Deacon
2018-02-03 11:15   ` Ard Biesheuvel
2018-02-05 16:41     ` Will Deacon
2018-01-29 11:59 ` [PATCH v2 8/9] arm64: assembler: Align phys_to_pte with pte_to_phys Will Deacon
2018-01-29 12:00 ` [PATCH v2 9/9] arm64: idmap: Use "awx" flags for .idmap.text .pushsection directives Will Deacon
2018-02-03 11:36 ` [PATCH v2 0/9] Fix kpti-enabled kernels for Cavium ThunderX Ard Biesheuvel
2018-02-05 16:41   ` Will Deacon
2018-02-05 19:21     ` Ard Biesheuvel
2018-02-06 22:31 ` 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=20180130103041.GA29693@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 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).