2019-05-29 21:12:40 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2013-01-21 06:28:06 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 - Virtual Open Systems and Columbia University
|
|
|
|
* Author: Christoffer Dall <c.dall@virtualopensystems.com>
|
|
|
|
*/
|
2013-01-21 06:28:06 +07:00
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
2014-06-30 22:29:12 +07:00
|
|
|
#include <asm/assembler.h>
|
2013-01-21 06:28:06 +07:00
|
|
|
#include <asm/unified.h>
|
2013-01-21 06:28:06 +07:00
|
|
|
#include <asm/asm-offsets.h>
|
|
|
|
#include <asm/kvm_asm.h>
|
2013-01-21 06:28:06 +07:00
|
|
|
#include <asm/kvm_arm.h>
|
ARM: KVM: switch to a dual-step HYP init code
Our HYP init code suffers from two major design issues:
- it cannot support CPU hotplug, as we tear down the idmap very early
- it cannot perform a TLB invalidation when switching from init to
runtime mappings, as pages are manipulated from PL1 exclusively
The hotplug problem mandates that we keep two sets of page tables
(boot and runtime). The TLB problem mandates that we're able to
transition from one PGD to another while in HYP, invalidating the TLBs
in the process.
To be able to do this, we need to share a page between the two page
tables. A page that will have the same VA in both configurations. All we
need is a VA that has the following properties:
- This VA can't be used to represent a kernel mapping.
- This VA will not conflict with the physical address of the kernel text
The vectors page seems to satisfy this requirement:
- The kernel never maps anything else there
- The kernel text being copied at the beginning of the physical memory,
it is unlikely to use the last 64kB (I doubt we'll ever support KVM
on a system with something like 4MB of RAM, but patches are very
welcome).
Let's call this VA the trampoline VA.
Now, we map our init page at 3 locations:
- idmap in the boot pgd
- trampoline VA in the boot pgd
- trampoline VA in the runtime pgd
The init scenario is now the following:
- We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd,
runtime stack, runtime vectors
- Enable the MMU with the boot pgd
- Jump to a target into the trampoline page (remember, this is the same
physical page!)
- Now switch to the runtime pgd (same VA, and still the same physical
page!)
- Invalidate TLBs
- Set stack and vectors
- Profit! (or eret, if you only care about the code).
Note that we keep the boot mapping permanently (it is not strictly an
idmap anymore) to allow for CPU hotplug in later patches.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
2013-04-13 01:12:06 +07:00
|
|
|
#include <asm/kvm_mmu.h>
|
2017-04-04 01:37:53 +07:00
|
|
|
#include <asm/virt.h>
|
2013-01-21 06:28:06 +07:00
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Hypervisor initialization
|
|
|
|
* - should be called with:
|
ARM: KVM: switch to a dual-step HYP init code
Our HYP init code suffers from two major design issues:
- it cannot support CPU hotplug, as we tear down the idmap very early
- it cannot perform a TLB invalidation when switching from init to
runtime mappings, as pages are manipulated from PL1 exclusively
The hotplug problem mandates that we keep two sets of page tables
(boot and runtime). The TLB problem mandates that we're able to
transition from one PGD to another while in HYP, invalidating the TLBs
in the process.
To be able to do this, we need to share a page between the two page
tables. A page that will have the same VA in both configurations. All we
need is a VA that has the following properties:
- This VA can't be used to represent a kernel mapping.
- This VA will not conflict with the physical address of the kernel text
The vectors page seems to satisfy this requirement:
- The kernel never maps anything else there
- The kernel text being copied at the beginning of the physical memory,
it is unlikely to use the last 64kB (I doubt we'll ever support KVM
on a system with something like 4MB of RAM, but patches are very
welcome).
Let's call this VA the trampoline VA.
Now, we map our init page at 3 locations:
- idmap in the boot pgd
- trampoline VA in the boot pgd
- trampoline VA in the runtime pgd
The init scenario is now the following:
- We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd,
runtime stack, runtime vectors
- Enable the MMU with the boot pgd
- Jump to a target into the trampoline page (remember, this is the same
physical page!)
- Now switch to the runtime pgd (same VA, and still the same physical
page!)
- Invalidate TLBs
- Set stack and vectors
- Profit! (or eret, if you only care about the code).
Note that we keep the boot mapping permanently (it is not strictly an
idmap anymore) to allow for CPU hotplug in later patches.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
2013-04-13 01:12:06 +07:00
|
|
|
* r0 = top of Hyp stack (kernel VA)
|
|
|
|
* r1 = pointer to hyp vectors
|
|
|
|
* r2,r3 = Hypervisor pgd pointer
|
|
|
|
*
|
|
|
|
* The init scenario is:
|
2016-07-01 00:40:47 +07:00
|
|
|
* - We jump in HYP with 3 parameters: runtime HYP pgd, runtime stack,
|
|
|
|
* runtime vectors
|
ARM: KVM: switch to a dual-step HYP init code
Our HYP init code suffers from two major design issues:
- it cannot support CPU hotplug, as we tear down the idmap very early
- it cannot perform a TLB invalidation when switching from init to
runtime mappings, as pages are manipulated from PL1 exclusively
The hotplug problem mandates that we keep two sets of page tables
(boot and runtime). The TLB problem mandates that we're able to
transition from one PGD to another while in HYP, invalidating the TLBs
in the process.
To be able to do this, we need to share a page between the two page
tables. A page that will have the same VA in both configurations. All we
need is a VA that has the following properties:
- This VA can't be used to represent a kernel mapping.
- This VA will not conflict with the physical address of the kernel text
The vectors page seems to satisfy this requirement:
- The kernel never maps anything else there
- The kernel text being copied at the beginning of the physical memory,
it is unlikely to use the last 64kB (I doubt we'll ever support KVM
on a system with something like 4MB of RAM, but patches are very
welcome).
Let's call this VA the trampoline VA.
Now, we map our init page at 3 locations:
- idmap in the boot pgd
- trampoline VA in the boot pgd
- trampoline VA in the runtime pgd
The init scenario is now the following:
- We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd,
runtime stack, runtime vectors
- Enable the MMU with the boot pgd
- Jump to a target into the trampoline page (remember, this is the same
physical page!)
- Now switch to the runtime pgd (same VA, and still the same physical
page!)
- Invalidate TLBs
- Set stack and vectors
- Profit! (or eret, if you only care about the code).
Note that we keep the boot mapping permanently (it is not strictly an
idmap anymore) to allow for CPU hotplug in later patches.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
2013-04-13 01:12:06 +07:00
|
|
|
* - Invalidate TLBs
|
|
|
|
* - Set stack and vectors
|
2016-07-01 00:40:47 +07:00
|
|
|
* - Setup the page tables
|
|
|
|
* - Enable the MMU
|
ARM: KVM: switch to a dual-step HYP init code
Our HYP init code suffers from two major design issues:
- it cannot support CPU hotplug, as we tear down the idmap very early
- it cannot perform a TLB invalidation when switching from init to
runtime mappings, as pages are manipulated from PL1 exclusively
The hotplug problem mandates that we keep two sets of page tables
(boot and runtime). The TLB problem mandates that we're able to
transition from one PGD to another while in HYP, invalidating the TLBs
in the process.
To be able to do this, we need to share a page between the two page
tables. A page that will have the same VA in both configurations. All we
need is a VA that has the following properties:
- This VA can't be used to represent a kernel mapping.
- This VA will not conflict with the physical address of the kernel text
The vectors page seems to satisfy this requirement:
- The kernel never maps anything else there
- The kernel text being copied at the beginning of the physical memory,
it is unlikely to use the last 64kB (I doubt we'll ever support KVM
on a system with something like 4MB of RAM, but patches are very
welcome).
Let's call this VA the trampoline VA.
Now, we map our init page at 3 locations:
- idmap in the boot pgd
- trampoline VA in the boot pgd
- trampoline VA in the runtime pgd
The init scenario is now the following:
- We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd,
runtime stack, runtime vectors
- Enable the MMU with the boot pgd
- Jump to a target into the trampoline page (remember, this is the same
physical page!)
- Now switch to the runtime pgd (same VA, and still the same physical
page!)
- Invalidate TLBs
- Set stack and vectors
- Profit! (or eret, if you only care about the code).
Note that we keep the boot mapping permanently (it is not strictly an
idmap anymore) to allow for CPU hotplug in later patches.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
2013-04-13 01:12:06 +07:00
|
|
|
* - Profit! (or eret, if you only care about the code).
|
2017-04-04 01:37:53 +07:00
|
|
|
*
|
|
|
|
* Another possibility is to get a HYP stub hypercall.
|
|
|
|
* We discriminate between the two by checking if r0 contains a value
|
|
|
|
* that is less than HVC_STUB_HCALL_NR.
|
2013-01-21 06:28:06 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
.text
|
|
|
|
.pushsection .hyp.idmap.text,"ax"
|
|
|
|
.align 5
|
|
|
|
__kvm_hyp_init:
|
|
|
|
.globl __kvm_hyp_init
|
|
|
|
|
|
|
|
@ Hyp-mode exception vector
|
|
|
|
W(b) .
|
|
|
|
W(b) .
|
|
|
|
W(b) .
|
|
|
|
W(b) .
|
|
|
|
W(b) .
|
|
|
|
W(b) __do_hyp_init
|
|
|
|
W(b) .
|
|
|
|
W(b) .
|
|
|
|
|
|
|
|
__do_hyp_init:
|
2017-04-04 01:37:53 +07:00
|
|
|
@ Check for a stub hypercall
|
|
|
|
cmp r0, #HVC_STUB_HCALL_NR
|
|
|
|
blo __kvm_handle_stub_hvc
|
|
|
|
|
2016-07-01 00:40:47 +07:00
|
|
|
@ Set stack pointer
|
|
|
|
mov sp, r0
|
|
|
|
|
|
|
|
@ Set HVBAR to point to the HYP vectors
|
|
|
|
mcr p15, 4, r1, c12, c0, 0 @ HVBAR
|
ARM: KVM: switch to a dual-step HYP init code
Our HYP init code suffers from two major design issues:
- it cannot support CPU hotplug, as we tear down the idmap very early
- it cannot perform a TLB invalidation when switching from init to
runtime mappings, as pages are manipulated from PL1 exclusively
The hotplug problem mandates that we keep two sets of page tables
(boot and runtime). The TLB problem mandates that we're able to
transition from one PGD to another while in HYP, invalidating the TLBs
in the process.
To be able to do this, we need to share a page between the two page
tables. A page that will have the same VA in both configurations. All we
need is a VA that has the following properties:
- This VA can't be used to represent a kernel mapping.
- This VA will not conflict with the physical address of the kernel text
The vectors page seems to satisfy this requirement:
- The kernel never maps anything else there
- The kernel text being copied at the beginning of the physical memory,
it is unlikely to use the last 64kB (I doubt we'll ever support KVM
on a system with something like 4MB of RAM, but patches are very
welcome).
Let's call this VA the trampoline VA.
Now, we map our init page at 3 locations:
- idmap in the boot pgd
- trampoline VA in the boot pgd
- trampoline VA in the runtime pgd
The init scenario is now the following:
- We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd,
runtime stack, runtime vectors
- Enable the MMU with the boot pgd
- Jump to a target into the trampoline page (remember, this is the same
physical page!)
- Now switch to the runtime pgd (same VA, and still the same physical
page!)
- Invalidate TLBs
- Set stack and vectors
- Profit! (or eret, if you only care about the code).
Note that we keep the boot mapping permanently (it is not strictly an
idmap anymore) to allow for CPU hotplug in later patches.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
2013-04-13 01:12:06 +07:00
|
|
|
|
2013-01-21 06:28:06 +07:00
|
|
|
@ Set the HTTBR to point to the hypervisor PGD pointer passed
|
2014-06-12 23:30:02 +07:00
|
|
|
mcrr p15, 4, rr_lo_hi(r2, r3), c2
|
2013-01-21 06:28:06 +07:00
|
|
|
|
|
|
|
@ Set the HTCR and VTCR to the same shareability and cacheability
|
|
|
|
@ settings as the non-secure TTBCR and with T0SZ == 0.
|
|
|
|
mrc p15, 4, r0, c2, c0, 2 @ HTCR
|
ARM: KVM: switch to a dual-step HYP init code
Our HYP init code suffers from two major design issues:
- it cannot support CPU hotplug, as we tear down the idmap very early
- it cannot perform a TLB invalidation when switching from init to
runtime mappings, as pages are manipulated from PL1 exclusively
The hotplug problem mandates that we keep two sets of page tables
(boot and runtime). The TLB problem mandates that we're able to
transition from one PGD to another while in HYP, invalidating the TLBs
in the process.
To be able to do this, we need to share a page between the two page
tables. A page that will have the same VA in both configurations. All we
need is a VA that has the following properties:
- This VA can't be used to represent a kernel mapping.
- This VA will not conflict with the physical address of the kernel text
The vectors page seems to satisfy this requirement:
- The kernel never maps anything else there
- The kernel text being copied at the beginning of the physical memory,
it is unlikely to use the last 64kB (I doubt we'll ever support KVM
on a system with something like 4MB of RAM, but patches are very
welcome).
Let's call this VA the trampoline VA.
Now, we map our init page at 3 locations:
- idmap in the boot pgd
- trampoline VA in the boot pgd
- trampoline VA in the runtime pgd
The init scenario is now the following:
- We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd,
runtime stack, runtime vectors
- Enable the MMU with the boot pgd
- Jump to a target into the trampoline page (remember, this is the same
physical page!)
- Now switch to the runtime pgd (same VA, and still the same physical
page!)
- Invalidate TLBs
- Set stack and vectors
- Profit! (or eret, if you only care about the code).
Note that we keep the boot mapping permanently (it is not strictly an
idmap anymore) to allow for CPU hotplug in later patches.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
2013-04-13 01:12:06 +07:00
|
|
|
ldr r2, =HTCR_MASK
|
|
|
|
bic r0, r0, r2
|
2013-01-21 06:28:06 +07:00
|
|
|
mrc p15, 0, r1, c2, c0, 2 @ TTBCR
|
|
|
|
and r1, r1, #(HTCR_MASK & ~TTBCR_T0SZ)
|
|
|
|
orr r0, r0, r1
|
|
|
|
mcr p15, 4, r0, c2, c0, 2 @ HTCR
|
|
|
|
|
|
|
|
@ Use the same memory attributes for hyp. accesses as the kernel
|
|
|
|
@ (copy MAIRx ro HMAIRx).
|
|
|
|
mrc p15, 0, r0, c10, c2, 0
|
|
|
|
mcr p15, 4, r0, c10, c2, 0
|
|
|
|
mrc p15, 0, r0, c10, c2, 1
|
|
|
|
mcr p15, 4, r0, c10, c2, 1
|
|
|
|
|
2014-07-31 13:53:23 +07:00
|
|
|
@ Invalidate the stale TLBs from Bootloader
|
|
|
|
mcr p15, 4, r0, c8, c7, 0 @ TLBIALLH
|
|
|
|
dsb ish
|
|
|
|
|
2013-01-21 06:28:06 +07:00
|
|
|
@ Set the HSCTLR to:
|
|
|
|
@ - ARM/THUMB exceptions: Kernel config (Thumb-2 kernel)
|
|
|
|
@ - Endianness: Kernel config
|
|
|
|
@ - Fast Interrupt Features: Kernel config
|
|
|
|
@ - Write permission implies XN: disabled
|
|
|
|
@ - Instruction cache: enabled
|
|
|
|
@ - Data/Unified cache: enabled
|
|
|
|
@ - MMU: enabled (this code must be run from an identity mapping)
|
|
|
|
mrc p15, 4, r0, c1, c0, 0 @ HSCR
|
ARM: KVM: switch to a dual-step HYP init code
Our HYP init code suffers from two major design issues:
- it cannot support CPU hotplug, as we tear down the idmap very early
- it cannot perform a TLB invalidation when switching from init to
runtime mappings, as pages are manipulated from PL1 exclusively
The hotplug problem mandates that we keep two sets of page tables
(boot and runtime). The TLB problem mandates that we're able to
transition from one PGD to another while in HYP, invalidating the TLBs
in the process.
To be able to do this, we need to share a page between the two page
tables. A page that will have the same VA in both configurations. All we
need is a VA that has the following properties:
- This VA can't be used to represent a kernel mapping.
- This VA will not conflict with the physical address of the kernel text
The vectors page seems to satisfy this requirement:
- The kernel never maps anything else there
- The kernel text being copied at the beginning of the physical memory,
it is unlikely to use the last 64kB (I doubt we'll ever support KVM
on a system with something like 4MB of RAM, but patches are very
welcome).
Let's call this VA the trampoline VA.
Now, we map our init page at 3 locations:
- idmap in the boot pgd
- trampoline VA in the boot pgd
- trampoline VA in the runtime pgd
The init scenario is now the following:
- We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd,
runtime stack, runtime vectors
- Enable the MMU with the boot pgd
- Jump to a target into the trampoline page (remember, this is the same
physical page!)
- Now switch to the runtime pgd (same VA, and still the same physical
page!)
- Invalidate TLBs
- Set stack and vectors
- Profit! (or eret, if you only care about the code).
Note that we keep the boot mapping permanently (it is not strictly an
idmap anymore) to allow for CPU hotplug in later patches.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
2013-04-13 01:12:06 +07:00
|
|
|
ldr r2, =HSCTLR_MASK
|
|
|
|
bic r0, r0, r2
|
2013-01-21 06:28:06 +07:00
|
|
|
mrc p15, 0, r1, c1, c0, 0 @ SCTLR
|
ARM: KVM: switch to a dual-step HYP init code
Our HYP init code suffers from two major design issues:
- it cannot support CPU hotplug, as we tear down the idmap very early
- it cannot perform a TLB invalidation when switching from init to
runtime mappings, as pages are manipulated from PL1 exclusively
The hotplug problem mandates that we keep two sets of page tables
(boot and runtime). The TLB problem mandates that we're able to
transition from one PGD to another while in HYP, invalidating the TLBs
in the process.
To be able to do this, we need to share a page between the two page
tables. A page that will have the same VA in both configurations. All we
need is a VA that has the following properties:
- This VA can't be used to represent a kernel mapping.
- This VA will not conflict with the physical address of the kernel text
The vectors page seems to satisfy this requirement:
- The kernel never maps anything else there
- The kernel text being copied at the beginning of the physical memory,
it is unlikely to use the last 64kB (I doubt we'll ever support KVM
on a system with something like 4MB of RAM, but patches are very
welcome).
Let's call this VA the trampoline VA.
Now, we map our init page at 3 locations:
- idmap in the boot pgd
- trampoline VA in the boot pgd
- trampoline VA in the runtime pgd
The init scenario is now the following:
- We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd,
runtime stack, runtime vectors
- Enable the MMU with the boot pgd
- Jump to a target into the trampoline page (remember, this is the same
physical page!)
- Now switch to the runtime pgd (same VA, and still the same physical
page!)
- Invalidate TLBs
- Set stack and vectors
- Profit! (or eret, if you only care about the code).
Note that we keep the boot mapping permanently (it is not strictly an
idmap anymore) to allow for CPU hotplug in later patches.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
2013-04-13 01:12:06 +07:00
|
|
|
ldr r2, =(HSCTLR_EE | HSCTLR_FI | HSCTLR_I | HSCTLR_C)
|
|
|
|
and r1, r1, r2
|
2017-06-07 01:08:35 +07:00
|
|
|
ARM( ldr r2, =(HSCTLR_M) )
|
|
|
|
THUMB( ldr r2, =(HSCTLR_M | HSCTLR_TE) )
|
ARM: KVM: switch to a dual-step HYP init code
Our HYP init code suffers from two major design issues:
- it cannot support CPU hotplug, as we tear down the idmap very early
- it cannot perform a TLB invalidation when switching from init to
runtime mappings, as pages are manipulated from PL1 exclusively
The hotplug problem mandates that we keep two sets of page tables
(boot and runtime). The TLB problem mandates that we're able to
transition from one PGD to another while in HYP, invalidating the TLBs
in the process.
To be able to do this, we need to share a page between the two page
tables. A page that will have the same VA in both configurations. All we
need is a VA that has the following properties:
- This VA can't be used to represent a kernel mapping.
- This VA will not conflict with the physical address of the kernel text
The vectors page seems to satisfy this requirement:
- The kernel never maps anything else there
- The kernel text being copied at the beginning of the physical memory,
it is unlikely to use the last 64kB (I doubt we'll ever support KVM
on a system with something like 4MB of RAM, but patches are very
welcome).
Let's call this VA the trampoline VA.
Now, we map our init page at 3 locations:
- idmap in the boot pgd
- trampoline VA in the boot pgd
- trampoline VA in the runtime pgd
The init scenario is now the following:
- We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd,
runtime stack, runtime vectors
- Enable the MMU with the boot pgd
- Jump to a target into the trampoline page (remember, this is the same
physical page!)
- Now switch to the runtime pgd (same VA, and still the same physical
page!)
- Invalidate TLBs
- Set stack and vectors
- Profit! (or eret, if you only care about the code).
Note that we keep the boot mapping permanently (it is not strictly an
idmap anymore) to allow for CPU hotplug in later patches.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
2013-04-13 01:12:06 +07:00
|
|
|
orr r1, r1, r2
|
2013-01-21 06:28:06 +07:00
|
|
|
orr r0, r0, r1
|
|
|
|
mcr p15, 4, r0, c1, c0, 0 @ HSCR
|
ARM: KVM: switch to a dual-step HYP init code
Our HYP init code suffers from two major design issues:
- it cannot support CPU hotplug, as we tear down the idmap very early
- it cannot perform a TLB invalidation when switching from init to
runtime mappings, as pages are manipulated from PL1 exclusively
The hotplug problem mandates that we keep two sets of page tables
(boot and runtime). The TLB problem mandates that we're able to
transition from one PGD to another while in HYP, invalidating the TLBs
in the process.
To be able to do this, we need to share a page between the two page
tables. A page that will have the same VA in both configurations. All we
need is a VA that has the following properties:
- This VA can't be used to represent a kernel mapping.
- This VA will not conflict with the physical address of the kernel text
The vectors page seems to satisfy this requirement:
- The kernel never maps anything else there
- The kernel text being copied at the beginning of the physical memory,
it is unlikely to use the last 64kB (I doubt we'll ever support KVM
on a system with something like 4MB of RAM, but patches are very
welcome).
Let's call this VA the trampoline VA.
Now, we map our init page at 3 locations:
- idmap in the boot pgd
- trampoline VA in the boot pgd
- trampoline VA in the runtime pgd
The init scenario is now the following:
- We jump in HYP with four parameters: boot HYP pgd, runtime HYP pgd,
runtime stack, runtime vectors
- Enable the MMU with the boot pgd
- Jump to a target into the trampoline page (remember, this is the same
physical page!)
- Now switch to the runtime pgd (same VA, and still the same physical
page!)
- Invalidate TLBs
- Set stack and vectors
- Profit! (or eret, if you only care about the code).
Note that we keep the boot mapping permanently (it is not strictly an
idmap anymore) to allow for CPU hotplug in later patches.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
2013-04-13 01:12:06 +07:00
|
|
|
isb
|
|
|
|
|
2013-01-21 06:28:06 +07:00
|
|
|
eret
|
|
|
|
|
2017-04-04 01:37:53 +07:00
|
|
|
ENTRY(__kvm_handle_stub_hvc)
|
2017-04-04 01:38:03 +07:00
|
|
|
cmp r0, #HVC_SOFT_RESTART
|
2017-04-04 01:37:57 +07:00
|
|
|
bne 1f
|
|
|
|
|
|
|
|
/* The target is expected in r1 */
|
|
|
|
msr ELR_hyp, r1
|
|
|
|
mrs r0, cpsr
|
|
|
|
bic r0, r0, #MODE_MASK
|
|
|
|
orr r0, r0, #HYP_MODE
|
|
|
|
THUMB( orr r0, r0, #PSR_T_BIT )
|
|
|
|
msr spsr_cxsf, r0
|
|
|
|
b reset
|
|
|
|
|
2017-04-04 01:37:54 +07:00
|
|
|
1: cmp r0, #HVC_RESET_VECTORS
|
2017-04-04 01:37:53 +07:00
|
|
|
bne 1f
|
2017-04-04 01:37:57 +07:00
|
|
|
|
|
|
|
reset:
|
2016-07-01 00:40:48 +07:00
|
|
|
/* We're now in idmap, disable MMU */
|
|
|
|
mrc p15, 4, r1, c1, c0, 0 @ HSCTLR
|
2017-04-04 01:37:53 +07:00
|
|
|
ldr r0, =(HSCTLR_M | HSCTLR_A | HSCTLR_C | HSCTLR_I)
|
|
|
|
bic r1, r1, r0
|
2016-07-01 00:40:48 +07:00
|
|
|
mcr p15, 4, r1, c1, c0, 0 @ HSCTLR
|
|
|
|
|
2017-04-04 01:37:53 +07:00
|
|
|
/*
|
|
|
|
* Install stub vectors, using ardb's VA->PA trick.
|
|
|
|
*/
|
|
|
|
0: adr r0, 0b @ PA(0)
|
|
|
|
movw r1, #:lower16:__hyp_stub_vectors - 0b @ VA(stub) - VA(0)
|
|
|
|
movt r1, #:upper16:__hyp_stub_vectors - 0b
|
|
|
|
add r1, r1, r0 @ PA(stub)
|
|
|
|
mcr p15, 4, r1, c12, c0, 0 @ HVBAR
|
|
|
|
b exit
|
|
|
|
|
|
|
|
1: ldr r0, =HVC_STUB_ERR
|
2017-04-04 01:38:06 +07:00
|
|
|
eret
|
2016-07-01 00:40:48 +07:00
|
|
|
|
2017-04-04 01:37:53 +07:00
|
|
|
exit:
|
2017-04-04 01:38:06 +07:00
|
|
|
mov r0, #0
|
2016-07-01 00:40:48 +07:00
|
|
|
eret
|
2017-04-04 01:37:53 +07:00
|
|
|
ENDPROC(__kvm_handle_stub_hvc)
|
2016-07-01 00:40:48 +07:00
|
|
|
|
2013-01-21 06:28:06 +07:00
|
|
|
.ltorg
|
|
|
|
|
|
|
|
.globl __kvm_hyp_init_end
|
|
|
|
__kvm_hyp_init_end:
|
|
|
|
|
|
|
|
.popsection
|