Re: [RFC 0/8] Provide the EL1 physical timer to the VM

2017-01-17 Thread Jintack Lim
On Tue, Jan 17, 2017 at 12:09 PM, Marc Zyngier wrote: > On 26/12/16 17:11, Jintack Lim wrote: >> The ARM architecture defines the EL1 physical timer and the virtual >> timer, and it is reasonable for an OS to expect to be able to access >> both. However, the current KVM im

Re: [RFC v2 10/10] KVM: arm/arm64: Emulate the EL1 phys timer register access

2017-01-30 Thread Jintack Lim
Hi Marc, On Sun, Jan 29, 2017 at 10:44 AM, Marc Zyngier wrote: > On Fri, Jan 27 2017 at 01:05:00 AM, Jintack Lim > wrote: >> Emulate read and write operations to CNTP_TVAL, CNTP_CVAL and CNTP_CTL. >> Now VMs are able to use the EL1 physical timer. >> >&

Re: [RFC v2 03/10] KVM: arm/arm64: Decouple kvm timer functions from virtual timer

2017-01-30 Thread Jintack Lim
On Sun, Jan 29, 2017 at 7:01 AM, Marc Zyngier wrote: > On Fri, Jan 27 2017 at 01:04:53 AM, Jintack Lim > wrote: >> Now that we have a separate structure for timer context, make functions >> general so that they can work with any timer context, not just the > >

Re: [RFC v2 03/10] KVM: arm/arm64: Decouple kvm timer functions from virtual timer

2017-01-30 Thread Jintack Lim
Hi Christoffer, On Mon, Jan 30, 2017 at 9:49 AM, Christoffer Dall wrote: > On Thu, Jan 26, 2017 at 08:04:53PM -0500, Jintack Lim wrote: >> Now that we have a separate structure for timer context, make functions >> general so that they can work with any timer context, not just

Re: [RFC v2 10/10] KVM: arm/arm64: Emulate the EL1 phys timer register access

2017-01-30 Thread Jintack Lim
Hi Peter, On Mon, Jan 30, 2017 at 12:26 PM, Peter Maydell wrote: > On 30 January 2017 at 17:08, Jintack Lim wrote: >> On Sun, Jan 29, 2017 at 10:44 AM, Marc Zyngier wrote: >>> Shouldn't we take the ENABLE bit into account? The ARMv8 ARM version I >>> have at ha

Re: [RFC v2 02/10] KVM: arm/arm64: Move cntvoff to each timer context

2017-01-30 Thread Jintack Lim
On Mon, Jan 30, 2017 at 9:51 AM, Marc Zyngier wrote: > On 30/01/17 14:45, Christoffer Dall wrote: >> On Sun, Jan 29, 2017 at 11:54:05AM +, Marc Zyngier wrote: >>> On Fri, Jan 27 2017 at 01:04:52 AM, Jintack Lim >>> wrote: >>>> Make cntvoff per each tim

Re: [RFC v2 02/10] KVM: arm/arm64: Move cntvoff to each timer context

2017-01-30 Thread Jintack Lim
On Sun, Jan 29, 2017 at 6:54 AM, Marc Zyngier wrote: > On Fri, Jan 27 2017 at 01:04:52 AM, Jintack Lim > wrote: >> Make cntvoff per each timer context. This is helpful to abstract kvm >> timer functions to work with timer context without considering timer >> types

Re: [RFC v2 02/10] KVM: arm/arm64: Move cntvoff to each timer context

2017-01-30 Thread Jintack Lim
On Mon, Jan 30, 2017 at 1:05 PM, Marc Zyngier wrote: > On 30/01/17 17:58, Jintack Lim wrote: >> On Sun, Jan 29, 2017 at 6:54 AM, Marc Zyngier wrote: >>> On Fri, Jan 27 2017 at 01:04:52 AM, Jintack Lim >>> wrote: >>>> Make cntvoff per each timer c

Re: [RFC v2 00/10] Provide the EL1 physical timer to the VM

2017-01-30 Thread Jintack Lim
Hi Marc, On Sun, Jan 29, 2017 at 10:55 AM, Marc Zyngier wrote: > Hi Jintack, > > On Fri, Jan 27 2017 at 01:04:50 AM, Jintack Lim > wrote: >> The ARM architecture defines the EL1 physical timer and the virtual timer, >> and it is reasonable for an OS to expect t

Re: [RFC v2 06/10] KVM: arm/arm64: Update the physical timer interrupt level

2017-02-01 Thread Jintack Lim
On Wed, Feb 1, 2017 at 3:04 AM, Christoffer Dall wrote: > On Sun, Jan 29, 2017 at 03:21:06PM +, Marc Zyngier wrote: >> On Fri, Jan 27 2017 at 01:04:56 AM, Jintack Lim >> wrote: >> > Now that we maintain the EL1 physical timer register states of VMs, >> > up

[RFC v3 00/10] Provide the EL1 physical timer to the VM

2017-02-01 Thread Jintack Lim
physical timer emulation on every entry to the VM and cancel it on exit. - Change timer_context structure to have cntvoff and restore enable field back to arch_timer_cpu structure Jintack Lim (10): KVM: arm/arm64: Abstract virtual timer context into separate structure KVM: arm/arm64: Move cntvoff

[RFC v3 01/10] KVM: arm/arm64: Abstract virtual timer context into separate structure

2017-02-01 Thread Jintack Lim
Abstract virtual timer context into a separate structure and change all callers referring to timer registers, irq state and so on. No change in functionality. This is about to become very handy when adding the EL1 physical timer. Signed-off-by: Jintack Lim Acked-by: Christoffer Dall Acked-by

[RFC v3 07/10] KVM: arm/arm64: Set a background timer to the earliest timer expiration

2017-02-01 Thread Jintack Lim
When scheduling a background timer, consider both of the virtual and physical timer and pick the earliest expiration time. Signed-off-by: Jintack Lim --- arch/arm/kvm/arm.c| 3 ++- virt/kvm/arm/arch_timer.c | 53 +++ 2 files changed, 42

[RFC v3 10/10] KVM: arm/arm64: Emulate the EL1 phys timer registers

2017-02-01 Thread Jintack Lim
Emulate read and write operations to CNTP_TVAL, CNTP_CVAL and CNTP_CTL. Now VMs are able to use the EL1 physical timer. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c| 37 ++--- include/kvm/arm_arch_timer.h | 2 ++ virt/kvm/arm/arch_timer.c| 2

[RFC v3 09/10] KVM: arm64: Add the EL1 physical timer access handler

2017-02-01 Thread Jintack Lim
KVM traps on the EL1 phys timer accesses from VMs, but it doesn't handle those traps. This results in terminating VMs. Instead, set a handler for the EL1 phys timer access, and inject an undefined exception as an intermediate step. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c

[RFC v3 04/10] KVM: arm/arm64: Add the EL1 physical timer context

2017-02-01 Thread Jintack Lim
Add the EL1 physical timer context. Signed-off-by: Jintack Lim --- include/kvm/arm_arch_timer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index f46fa3b..6445a3d 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm

[RFC v3 06/10] KVM: arm/arm64: Update the physical timer interrupt level

2017-02-01 Thread Jintack Lim
Now that we maintain the EL1 physical timer register states of VMs, update the physical timer interrupt level along with the virtual one. Signed-off-by: Jintack Lim --- virt/kvm/arm/arch_timer.c | 4 1 file changed, 4 insertions(+) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm

[RFC v3 05/10] KVM: arm/arm64: Initialize the emulated EL1 physical timer

2017-02-01 Thread Jintack Lim
Initialize the emulated EL1 physical timer with the default irq number. Signed-off-by: Jintack Lim --- arch/arm/kvm/reset.c | 9 - arch/arm64/kvm/reset.c | 9 - include/kvm/arm_arch_timer.h | 3 ++- virt/kvm/arm/arch_timer.c| 9 +++-- 4 files changed, 25

[RFC v3 08/10] KVM: arm/arm64: Set up a background timer for the physical timer emulation

2017-02-01 Thread Jintack Lim
use the virtual timer since the physical timer is always not enabled. Signed-off-by: Jintack Lim --- virt/kvm/arm/arch_timer.c | 25 - 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 89bdb79..1806e5e

[RFC v3 02/10] KVM: arm/arm64: Move cntvoff to each timer context

2017-02-01 Thread Jintack Lim
make sense. Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_host.h | 3 --- arch/arm/kvm/arm.c| 1 - arch/arm64/include/asm/kvm_host.h | 3 --- include/kvm/arm_arch_timer.h | 9 +++-- virt/kvm/arm/arch_timer.c | 31 +-- virt

[RFC v3 03/10] KVM: arm/arm64: Decouple kvm timer functions from virtual timer

2017-02-01 Thread Jintack Lim
Now that we have a separate structure for timer context, make functions generic so that they can work with any timer context, not just the virtual timer context. This does not change the virtual timer functionality. Signed-off-by: Jintack Lim Acked-by: Marc Zyngier --- arch/arm/kvm/arm.c

[RFC 06/55] KVM: arm64: Add EL2 execution context for nesting

2017-01-08 Thread Jintack Lim
registers to be able to run the guest hypervisor in EL1. Signed-off-by: Jintack Lim Signed-off-by: Christoffer Dall --- arch/arm64/include/asm/kvm_host.h | 54 +++ 1 file changed, 54 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64

[RFC 08/55] KVM: arm64: Set virtual EL2 context depending on the guest exception level

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Set up virutal EL2 context to hardware if the guest exception level is EL2. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm64/kvm/context.c | 32 ++-- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a

[RFC 07/55] KVM: arm/arm64: Add virtual EL2 state emulation framework

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Add a framework to set up the guest's context depending on the guest's exception level. A chosen context is written to hardware in the lowvisor. We don't set the virtual EL2 context yet. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- a

[RFC 12/55] KVM: arm64: Handle EL2 register access traps

2017-01-08 Thread Jintack Lim
traps. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c | 119 ++ arch/arm64/kvm/sys_regs.h | 7 +++ 2 files changed, 126 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 7cef94f..4158f2f 100644 --- a/arch

[RFC 14/55] KVM: arm64: Take account of system instruction traps

2017-01-08 Thread Jintack Lim
: Jintack Lim --- arch/arm64/include/asm/kvm_coproc.h | 2 +- arch/arm64/kvm/handle_exit.c| 2 +- arch/arm64/kvm/sys_regs.c | 49 - arch/arm64/kvm/trace.h | 2 +- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/arch

[RFC 24/55] KVM: arm64: Forward FP exceptions to the guest hypervisor

2017-01-08 Thread Jintack Lim
Forward exceptions due to floating-point register accesses to the guest hypervisor if it has set CPTR_EL2.TFP bit. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_nested.h | 1 + arch/arm64/kernel/asm-offsets.c | 1 + arch/arm64/kvm/handle_exit.c| 3 +++ arch/arm64/kvm

[RFC 23/55] KVM: arm64: Forward WFX to the guest hypervisor

2017-01-08 Thread Jintack Lim
Forward exceptions due to WFI or WFE to the guest hypervisor if the guest hypervisor has set corresponding virtual HCR_EL2.TWX bits. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_nested.h | 1 + arch/arm64/kvm/handle_exit.c| 11 ++- arch/arm64/kvm

[RFC 25/55] KVM: arm/arm64: Let vcpu thread modify its own active state

2017-01-08 Thread Jintack Lim
Currently, if a vcpu thread tries to change its own active state when the irq is already in AP list, it'll loop forever. Since the VCPU thread has already synced back LR state to the struct vgic_irq, let it modify its own state safely. Signed-off-by: Jintack Lim --- virt/kvm/arm/vgic

[RFC 26/55] KVM: arm/arm64: Add VGIC data structures for the nesting

2017-01-08 Thread Jintack Lim
Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- include/kvm/arm_vgic.h | 20 1 file changed, 20 insertions(+) diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 002f092..9a9cb27 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -

[RFC 49/55] KVM: arm64: Fixes to toggle_cache for nesting

2017-01-08 Thread Jintack Lim
scope of the flush operation to only flush shadow stage 2 page table state of the particular VCPU toggling the caches instead of the shadow stage 2 state of all possible VCPUs. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/kvm/mmu.c | 31

[RFC 52/55] KVM: arm/arm64: Create a vcpu mapping for the nested VM

2017-01-08 Thread Jintack Lim
Create a mapping from the nested VM's cpu interface to the hardware virtual cpu interface. This is to allow the nested VM to access virtual cpu interface directly. Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_mmu.h | 3 +++ arch/arm/kvm/mmu.c | 5 + arch/

[RFC 40/55] KVM: arm/arm64: Handle vttbr_el2 write operation from the guest hypervisor

2017-01-08 Thread Jintack Lim
shadow page table is not valid any more. So ummap it. Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_host.h | 1 + arch/arm/kvm/arm.c| 1 + arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/include/asm/kvm_mmu.h | 6 arch/arm64/kvm/mmu-nested.c | 71

[RFC 51/55] KVM: arm64: Expose physical address of vcpu interface

2017-01-08 Thread Jintack Lim
Expose physical address of vgic virtual cpu interface. Signed-off-by: Jintack Lim --- include/kvm/arm_vgic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 6 ++ 2 files changed, 7 insertions(+) diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 5bda20c..05c7811 100644 --- a

[RFC 50/55] KVM: arm/arm64: Abstract kvm_phys_addr_ioremap() function

2017-01-08 Thread Jintack Lim
remap calls this function with the VM's mmu context. Signed-off-by: Jintack Lim --- arch/arm/kvm/mmu.c | 18 +- arch/arm64/include/asm/kvm_mmu.h | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c ind

[RFC 47/55] KVM: arm/arm64: Forward the guest hypervisor's stage 2 permission faults

2017-01-08 Thread Jintack Lim
. Check if this is the case, and inject a fault if it is. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_mmu.h | 7 +++ arch/arm/kvm/mmu.c | 5 + arch/arm64/include/asm/kvm_mmu.h | 9 + arch/arm64/kvm/mmu-nested.c

[RFC 48/55] KVM: arm64: Emulate TLBI instruction

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Currently, we flush ALL shadow stage-2 page tables on the tlbi instruction execution. We may be able to do this more efficiently by considering the vttbr_el2 value of the guest hypervisor, but leave it for now. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim

[RFC 44/55] KVM: arm/arm64: Move kvm_is_write_fault to header file

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Move this little function to the header files for arm/arm64 so other code can make use of it directly. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_emulate.h | 8 arch/arm/kvm/mmu.c | 8

[RFC 42/55] KVM: arm64: Implement nested Stage-2 page table walk logic

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Based on the pseudo-code in the ARM ARM, implement a stage 2 software page table walker. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_mmu.h | 11 ++ arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/kvm_mmu.h

[RFC 54/55] KVM: arm/arm64: Adjust virtual offset considering nesting

2017-01-08 Thread Jintack Lim
e sum of offset the host hypervisor initially has for the VM and virtual offset the guest hypervisor sets for the nested VM. Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_emulate.h | 6 ++ arch/arm64/include/asm/kvm_emulate.h | 6 ++ virt/kvm/arm/arch_timer.c

[RFC 55/55] KVM: arm64: Enable nested virtualization

2017-01-08 Thread Jintack Lim
Now that everything is ready, we enable nested virtualization by setting the HCR NV and NV1 bit. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/kvm/hyp/switch.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm

[RFC 33/55] KVM: arm/arm64: Remove unused params in mmu functions

2017-01-08 Thread Jintack Lim
From: Christoffer Dall stage2_flush_xxx functions take a pointer to the kvm struct as the first parameter but they are never used. Clean this up before modifying mmu code for nested virtualization support. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/kvm/mmu.c | 12

[RFC 53/55] KVM: arm64: Reflect shadow VMPIDR_EL2 value to MPIDR_EL1

2017-01-08 Thread Jintack Lim
A non-secure EL0 or EL1 read of MPIDR_EL1 should return the value of VMPIDR_EL2. We emulate this by copying the virtual VMPIDR_EL2 value to MPIDR_EL1 when entering VM's EL0 or EL1. Signed-off-by: Jintack Lim --- arch/arm64/kvm/context.c | 6 ++ 1 file changed, 6 insertions(+) diff --

[RFC 41/55] KVM: arm/arm64: Unmap/flush shadow stage 2 page tables

2017-01-08 Thread Jintack Lim
shadow stage-2 table. Probably we can do smarter with some sort of rmap structure. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_mmu.h | 7 arch/arm/kvm/arm.c | 6 ++- arch/arm/kvm/mmu.c | 11 + arch/arm64/include

[RFC 46/55] KVM: arm64: Add more info to the S2 translation result

2017-01-08 Thread Jintack Lim
: Jintack Lim --- arch/arm64/include/asm/kvm_mmu.h | 3 +++ arch/arm64/kvm/mmu-nested.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index bf94f0c..2ac603d 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch

[RFC 43/55] KVM: arm/arm64: Handle shadow stage 2 page faults

2017-01-08 Thread Jintack Lim
with the existing code. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_emulate.h | 7 arch/arm/kvm/mmio.c | 12 +++--- arch/arm/kvm/mmu.c | 75 arch/arm64/include/asm

[RFC 39/55] KVM: arm/arm64: Add mmu context for the nesting

2017-01-08 Thread Jintack Lim
s from the guest hypervisor's point of view. Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_host.h | 3 ++ arch/arm/kvm/arm.c | 1 + arch/arm64/include/asm/kvm_emulate.h | 13 - arch/arm64/include/asm/kvm_host.h| 19 + arch/arm64/includ

[RFC 38/55] KVM: arm/arm64: Make mmu functions non-static

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Make mmu functions non-static so that we can reuse those functions to support mmu for the nested VMs. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/kvm/mmu.c | 90 +++- arch/arm64/include/asm

[RFC 36/55] KVM: arm64: Invalidate virtual EL2 TLB entries when needed

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Sometimes when we are invalidating the TLB for a certain S2 MMU context, this context can also have EL2 context associated with it and we have to invalidate this too. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/kvm/arm.c | 6 ++ arch

[RFC 30/55] KVM: arm/arm64: Inject irqs to the guest hypervisor

2017-01-08 Thread Jintack Lim
If we have a pending IRQ for the guest and the guest expects IRQs to be handled in its virtual EL2 mode (the virtual IMO bit is set) and it is not already running in virtual EL2 mode, then we have to emulate an IRQ exception. Signed-off-by: Jintack Lim Signed-off-by: Christoffer Dall --- virt

[RFC 28/55] KVM: arm/arm64: Prepare vgic state for the nested VM

2017-01-08 Thread Jintack Lim
real hardware irq number if there is a mapping. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_emulate.h | 5 ++ arch/arm64/include/asm/kvm_emulate.h | 5 ++ arch/arm64/kvm/context.c | 4 ++ include/kvm/arm_vgic.h | 8 +++ vir

[RFC 29/55] KVM: arm/arm64: Set up the prepared vgic state

2017-01-08 Thread Jintack Lim
Since vgic state is properly prepared and is pointed by hw_v2_cpu_if, let's use it to manipulate vgic. Signed-off-by: Jintack Lim --- virt/kvm/arm/hyp/vgic-v2-sr.c | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/virt/kvm/arm/hyp/vgic-v2-sr.c b/virt/kv

[RFC 35/55] KVM: arm/arm64: Support mmu for the virtual EL2 execution

2017-01-08 Thread Jintack Lim
Dall Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_asm.h | 6 ++-- arch/arm/include/asm/kvm_emulate.h | 4 +++ arch/arm/include/asm/kvm_host.h | 14 ++--- arch/arm/include/asm/kvm_mmu.h | 11 +++ arch/arm/kvm/arm.c

[RFC 34/55] KVM: arm/arm64: Abstract stage-2 MMU state into a separate structure

2017-01-08 Thread Jintack Lim
-by: Jintack Lim --- arch/arm/include/asm/kvm_asm.h| 7 +- arch/arm/include/asm/kvm_host.h | 26 --- arch/arm/kvm/arm.c| 34 + arch/arm/kvm/hyp/switch.c | 5 +- arch/arm/kvm/hyp/tlb.c| 18 ++--- arch/arm/kvm/mmu.c| 146

[RFC 37/55] KVM: arm64: Setup vttbr_el2 on each VM entry

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Now that the vttbr value will be different depending on the VM's exception level, we set it on each VM entry. We only have one mmu instance at this point, but there will be multiple of them when we run nested VMs. Signed-off-by: Christoffer Dall Signed-off-by: Ji

[RFC 32/55] KVM: arm/arm64: register GICH iodev for the guest hypervisor

2017-01-08 Thread Jintack Lim
Register a device for the virtual interface control block(GICH) access from the guest hypervisor. TODO: Get GICH address from DT, which is hardcoded now. Signed-off-by: Jintack Lim --- arch/arm64/include/uapi/asm/kvm.h | 6 ++ include/kvm/arm_vgic.h | 5 - virt/kvm/arm

[RFC 27/55] KVM: arm/arm64: Emulate GICH interface on GICv2

2017-01-08 Thread Jintack Lim
Emulate GICH interface accesses from the guest hypervisor. Signed-off-by: Jintack Lim Signed-off-by: Shih-Wei Li Signed-off-by: Christoffer Dall --- arch/arm64/kvm/Makefile| 1 + virt/kvm/arm/vgic/vgic-v2-nested.c | 207 + 2 files changed, 208

[RFC 45/55] KVM: arm64: KVM: Inject stage-2 page faults

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Inject stage-2 page faults to the guest hypervisor. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm64/include/asm/esr.h | 1 + arch/arm64/kvm/mmu-nested.c | 30 -- 2 files changed, 25 insertions(+), 6 deletions

[RFC 21/55] KVM: arm64: Forward HVC instruction to the guest hypervisor

2017-01-08 Thread Jintack Lim
Forward exceptions due to hvc instruction to the guest hypervisor. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_nested.h | 5 + arch/arm64/kvm/Makefile | 1 + arch/arm64/kvm/handle_exit.c| 11 +++ arch/arm64/kvm/handle_exit_nested.c | 27

[RFC 31/55] KVM: arm/arm64: Inject maintenance interrupts to the guest hypervisor

2017-01-08 Thread Jintack Lim
From: Christoffer Dall If we exit a nested VM with a pending maintenance interrupt from the GIC, then we need to forward this to the guest hypervisor so that it can re-sync the appropriate LRs and sample level triggered interrupts again. Signed-off-by: Christoffer Dall Signed-off-by: Jintack

[RFC 22/55] KVM: arm64: Handle PSCI call from the guest

2017-01-08 Thread Jintack Lim
mc for the psci call. On ARMv8.3, even if EL3 is not implemented, a smc instruction executed at non-secure EL1 is trapped to EL2 if HCR_EL2.TSC==1, rather than being treated as UNDEFINED. So, the host hypervisor can handle this psci call without any confusion. Signed-off-by: Jintack Lim --- arch

[RFC 17/55] KVM: arm64: Trap SPSR_EL1, ELR_EL1 and VBAR_EL1 in virtual EL2

2017-01-08 Thread Jintack Lim
. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c | 41 - 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 0f5d21b..19d6a6e 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64

[RFC 18/55] KVM: arm64: Forward traps due to HCR_EL2.NV1 bit to the guest hypervisor

2017-01-08 Thread Jintack Lim
Forward ELR_EL1, SPSR_EL1 and VBAR_EL1 traps to the guest hypervisor if it has set the NV1 bit to the virtual HCR_EL2. The guest hypervisor would set this NV1 bit to run a hypervisor in its VM (i.e. another level of nested hypervisor). Signed-off-by: Jintack Lim --- arch/arm64/include/asm

[RFC 19/55] KVM: arm64: Trap CPACR_EL1 access in virtual EL2

2017-01-08 Thread Jintack Lim
tware in EL0/EL1 from the guest hypervisor's perspective. Signed-off-by: Jintack Lim --- arch/arm64/kvm/hyp/switch.c | 10 +++--- arch/arm64/kvm/sys_regs.c | 10 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hy

[RFC 15/55] KVM: arm64: Trap EL1 VM register accesses in virtual EL2

2017-01-08 Thread Jintack Lim
at it believes to be a different mode's system register state (for example when preparing to switch to a VM). We can leverage the existing sysregs infrastructure to support trapped accesses to these registers. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm64/kvm/hy

[RFC 20/55] KVM: arm64: Forward CPACR_EL1 traps to the guest hypervisor

2017-01-08 Thread Jintack Lim
Forward CPACR_EL1 traps to the guest hypervisor if it has configured the virtual CPTR_EL2 to do so. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c | 5 + 1 file changed, 5 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 321ecbc..e66f40d

[RFC 11/55] KVM: arm64: Emulate taking an exception to the guest hypervisor

2017-01-08 Thread Jintack Lim
Emulate taking an exception to the guest hypervisor running in the virtual EL2 as described in ARM ARM AArch64.TakeException(). Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_emulate.h | 14 arch/arm64/include/asm/kvm_emulate.h | 19 +++ arch/arm64/kvm/Makefile

[RFC 13/55] KVM: arm64: Handle eret instruction traps

2017-01-08 Thread Jintack Lim
When HCR.NV bit is set, eret instruction execution in the guest hypervisor will trap with EC code 0x1A. Let ELR_EL2 and SPSR_EL2 state from the guest's perspective be restored to the hardware on the next guest entry. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/esr.h | 1 + arch/

[RFC 16/55] KVM: arm64: Forward VM reg traps to the guest hypervisor

2017-01-08 Thread Jintack Lim
Forward virtual memory register traps to the guest hypervisor if it has set corresponding bits to the virtual HCR_EL2. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c | 20 1 file changed, 20 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm

[RFC 09/55] KVM: arm64: Set shadow EL1 registers for virtual EL2 execution

2017-01-08 Thread Jintack Lim
Dall Signed-off-by: Jintack Lim --- arch/arm64/kvm/context.c | 71 1 file changed, 71 insertions(+) diff --git a/arch/arm64/kvm/context.c b/arch/arm64/kvm/context.c index acb4b1e..2e9e386 100644 --- a/arch/arm64/kvm/context.c +++ b/arch/arm64/kvm

[RFC 05/55] KVM: arm64: Add vcpu_mode_el2 primitive to support nesting

2017-01-08 Thread Jintack Lim
From: Christoffer Dall When running a nested hypervisor we occasionally have to figure out if the mode we are switching into is the virtual EL2 mode or a regular EL0/1 mode. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_emulate.h | 6 ++ arch

[RFC 04/55] KVM: arm64: Allow userspace to set PSR_MODE_EL2x

2017-01-08 Thread Jintack Lim
From: Christoffer Dall We were not allowing userspace to set a more privileged mode for the VCPU than EL1, but now that we support nesting with a virtual EL2 mode, do allow this! Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm64/kvm/guest.c | 2 ++ 1 file changed, 2

[RFC 00/55] Nested Virtualization on KVM/ARM

2017-01-08 Thread Jintack Lim
/arm64: Forward the guest hypervisor's stage 2 permission faults KVM: arm64: Emulate TLBI instruction KVM: arm64: Fixes to toggle_cache for nesting Jintack Lim (28): KVM: arm64: Add EL2 execution context for nesting KVM: arm64: Emulate taking an exception to the guest hypervisor KV

[RFC 01/55] arm64: Add missing TCR hw defines

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Some bits of the TCR weren't defined and since we're about to use these in KVM, add these defines. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm64/include/asm/pgtable-hwdef.h | 6 ++ 1 file changed, 6 insertions(+) diff --git a/

[RFC 03/55] KVM: arm64: Add KVM nesting feature

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Set the initial exception level of the guest to EL2 if nested virtualization feature is enabled. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/kvm/reset.c

[RFC 02/55] KVM: arm64: Add nesting config option

2017-01-08 Thread Jintack Lim
From: Christoffer Dall Add an option that allows nested hypervisor support. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm64/kvm/Kconfig | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 6eaf12c..37263ff

[RFC 10/55] KVM: arm64: Synchronize EL1 system registers on virtual EL2 entry and exit

2017-01-08 Thread Jintack Lim
registers were happening locally in the shadow array, with no benefit to software actually running in virtual EL1 at all. To fix this, simply synchronize the shadow and real EL1 state for these registers on entry/exit to/from virtual EL2 state. Signed-off-by: Christoffer Dall Signed-off-by: Jintack

Re: [RFC 00/55] Nested Virtualization on KVM/ARM

2017-01-10 Thread Jintack Lim
On Mon, Jan 9, 2017 at 10:05 AM, David Hildenbrand wrote: > >> Even though this work is not complete (see limitations below), I'd >> appreciate >> early feedback on this RFC. Specifically, I'm interested in: >> - Is it better to have a kernel config or to make it configurable at >> runtime? > > >

Re: [RFC 4/8] KVM: arm/arm64: Initialize the emulated EL1 physical timer

2017-01-10 Thread Jintack Lim
On Mon, Jan 9, 2017 at 7:02 AM, Christoffer Dall wrote: > On Mon, Dec 26, 2016 at 12:12:02PM -0500, Jintack Lim wrote: >> Initialize the emulated EL1 physical timer with the default irq number. >> >> Signed-off-by: Jintack Lim >> --- >> arch/arm/kvm/reset.c

Re: [RFC 6/8] KVM: arm/arm64: Update the physical timer interrupt level

2017-01-10 Thread Jintack Lim
On Mon, Jan 9, 2017 at 7:14 AM, Christoffer Dall wrote: > On Mon, Dec 26, 2016 at 12:12:04PM -0500, Jintack Lim wrote: >> Now that we maintain the EL1 physical timer register states of the VM, >> update the physical timer interrupt level along with the virtual one. >> >

Re: [RFC 8/8] KVM: arm/arm64: Emulate the EL1 phys timer register access

2017-01-10 Thread Jintack Lim
On Mon, Jan 9, 2017 at 7:16 AM, Christoffer Dall wrote: > On Mon, Dec 26, 2016 at 12:12:06PM -0500, Jintack Lim wrote: >> Emulate read and write operations to CNTP_TVAL, CNTP_CVAL and CNTP_CTL. >> Now the VM is able to use the EL1 physical timer. >> >> Signed-off-by: J

Re: [RFC 7/8] KVM: arm/arm64: Set up a background timer for the physical timer emulation

2017-01-10 Thread Jintack Lim
Hi Christoffer, thanks for the review! On Mon, Jan 9, 2017 at 7:13 AM, Christoffer Dall wrote: > On Mon, Dec 26, 2016 at 12:12:05PM -0500, Jintack Lim wrote: >> Set a background timer for the EL1 physical timer emulation while VMs are >> running, so that VMs get interrupts f

[RFC v2 00/10] Provide the EL1 physical timer to the VM

2017-01-26 Thread Jintack Lim
imer_cpu structure Jintack Lim (10): KVM: arm/arm64: Abstract virtual timer context into separate structure KVM: arm/arm64: Move cntvoff to each timer context KVM: arm/arm64: Decouple kvm timer functions from virtual timer KVM: arm/arm64: Add the EL1 physical timer context KVM: arm/arm64: In

[RFC v2 10/10] KVM: arm/arm64: Emulate the EL1 phys timer register access

2017-01-26 Thread Jintack Lim
Emulate read and write operations to CNTP_TVAL, CNTP_CVAL and CNTP_CTL. Now VMs are able to use the EL1 physical timer. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c| 32 +--- include/kvm/arm_arch_timer.h | 2 ++ virt/kvm/arm/arch_timer.c| 2

[RFC v2 08/10] KVM: arm/arm64: Set up a background timer for the physical timer emulation

2017-01-26 Thread Jintack Lim
use the virtual timer since the physical timer is always not enabled. Signed-off-by: Jintack Lim --- virt/kvm/arm/arch_timer.c | 26 +- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index d3925e2

[RFC v2 04/10] KVM: arm/arm64: Add the EL1 physical timer context

2017-01-26 Thread Jintack Lim
Add the EL1 physical timer context. Signed-off-by: Jintack Lim --- include/kvm/arm_arch_timer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index d921d20..69f648b 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm

[RFC v2 03/10] KVM: arm/arm64: Decouple kvm timer functions from virtual timer

2017-01-26 Thread Jintack Lim
Now that we have a separate structure for timer context, make functions general so that they can work with any timer context, not just the virtual timer context. This does not change the virtual timer functionality. Signed-off-by: Jintack Lim --- arch/arm/kvm/arm.c | 2 +- include

[RFC v2 02/10] KVM: arm/arm64: Move cntvoff to each timer context

2017-01-26 Thread Jintack Lim
make sense. Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_host.h | 6 +++--- arch/arm64/include/asm/kvm_host.h | 4 ++-- include/kvm/arm_arch_timer.h | 8 +++- virt/kvm/arm/arch_timer.c | 26 -- virt/kvm/arm/hyp/timer-sr.c | 3 +-- 5

[RFC v2 06/10] KVM: arm/arm64: Update the physical timer interrupt level

2017-01-26 Thread Jintack Lim
Now that we maintain the EL1 physical timer register states of VMs, update the physical timer interrupt level along with the virtual one. Note that the emulated EL1 physical timer is not mapped to any hardware timer, so we call a proper vgic function. Signed-off-by: Jintack Lim --- virt/kvm

[RFC v2 09/10] KVM: arm64: Add the EL1 physical timer access handler

2017-01-26 Thread Jintack Lim
KVM traps on the EL1 phys timer accesses from VMs, but it doesn't handle those traps. This results in terminating VMs. Instead, set a handler for the EL1 phys timer access, and inject an undefined exception as an intermediate step. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c

[RFC v2 07/10] KVM: arm/arm64: Set a background timer to the earliest timer expiration

2017-01-26 Thread Jintack Lim
When scheduling a background timer, consider both of the virtual and physical timer and pick the earliest expiration time. Signed-off-by: Jintack Lim --- arch/arm/kvm/arm.c| 3 ++- virt/kvm/arm/arch_timer.c | 55 --- 2 files changed, 44

[RFC v2 01/10] KVM: arm/arm64: Abstract virtual timer context into separate structure

2017-01-26 Thread Jintack Lim
Abstract virtual timer context into a separate structure and change all callers referring to timer registers, irq state and so on. No change in functionality. This is about to become very handy when adding the EL1 physical timer. Signed-off-by: Jintack Lim Acked-by: Christoffer Dall

[RFC v2 05/10] KVM: arm/arm64: Initialize the emulated EL1 physical timer

2017-01-26 Thread Jintack Lim
Initialize the emulated EL1 physical timer with the default irq number. Signed-off-by: Jintack Lim --- arch/arm/kvm/reset.c | 9 - arch/arm64/kvm/reset.c | 9 - include/kvm/arm_arch_timer.h | 3 ++- virt/kvm/arm/arch_timer.c| 9 +++-- 4 files changed, 25

[RFC 3/8] KVM: arm/arm64: Add the EL1 physical timer context

2016-12-26 Thread Jintack Lim
Add the EL1 physical timer context. Signed-off-by: Jintack Lim --- include/kvm/arm_arch_timer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index cf84145..d21652a 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm

[RFC 6/8] KVM: arm/arm64: Update the physical timer interrupt level

2016-12-26 Thread Jintack Lim
timer interrupts while they are runnable. But they won't get interrupts once vcpus go to sleep since we don't have code to wake vcpus up on the emulated physical timer expiration yet. Signed-off-by: Jintack Lim --- arch/arm/kvm/arm.c| 3 +- virt/kvm/arm/arch_ti

[RFC 7/8] KVM: arm/arm64: Set up a background timer for the physical timer emulation

2016-12-26 Thread Jintack Lim
-off-by: Jintack Lim --- virt/kvm/arm/arch_timer.c | 42 +++--- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index aa7e243..be8d953 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm

[RFC 5/8] KVM: arm64: Add the EL1 physical timer access handler

2016-12-26 Thread Jintack Lim
KVM traps on the EL1 phys timer accesses from VMs, but it doesn't handle those traps. This results in terminating VMs. Instead, set a handler for the EL1 phys timer access, and inject an undefined exception as an intermediate step. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c

[RFC 4/8] KVM: arm/arm64: Initialize the emulated EL1 physical timer

2016-12-26 Thread Jintack Lim
Initialize the emulated EL1 physical timer with the default irq number. Signed-off-by: Jintack Lim --- arch/arm/kvm/reset.c | 9 - arch/arm64/kvm/reset.c | 9 - include/kvm/arm_arch_timer.h | 3 ++- virt/kvm/arm/arch_timer.c| 12 ++-- 4 files changed

[RFC 8/8] KVM: arm/arm64: Emulate the EL1 phys timer register access

2016-12-26 Thread Jintack Lim
Emulate read and write operations to CNTP_TVAL, CNTP_CVAL and CNTP_CTL. Now the VM is able to use the EL1 physical timer. Signed-off-by: Jintack Lim --- arch/arm64/kvm/sys_regs.c| 35 --- include/kvm/arm_arch_timer.h | 3 +++ virt/kvm/arm/arch_timer.c

[RFC 0/8] Provide the EL1 physical timer to the VM

2016-12-26 Thread Jintack Lim
p-and-emulate. Jintack Lim (8): KVM: arm/arm64: Abstract virtual timer context into separate structure KVM: arm/arm64: Decouple kvm timer functions from virtual timer KVM: arm/arm64: Add the EL1 physical timer context KVM: arm/arm64: Initialize the emulated EL1 physical timer KVM: arm64: Add th

  1   2   3   >