Re: [PATCH 15/21] arm64: KVM: Add panic handling

2015-11-16 Thread Marc Zyngier
On 16/11/15 15:53, Ard Biesheuvel wrote: > On 16 November 2015 at 14:11, Marc Zyngier wrote: >> Add the panic handler, together with the small bits of assembly >> code to call the kernel's panic implementation. >> >> Signed-off-by: Marc Zyngier >> ---

Re: [PATCH 15/21] arm64: KVM: Add panic handling

2015-11-16 Thread Marc Zyngier
On 16/11/15 14:16, Mark Rutland wrote: >> diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c >> index 06d3e20..cdc2a96 100644 >> --- a/arch/arm64/kvm/hyp/switch.c >> +++ b/arch/arm64/kvm/hyp/switch.c >> @@ -140,3 +140,38 @@ int __hyp_text __guest_run(struct kvm_vcpu *vcpu) >>

Re: [PATCH 15/21] arm64: KVM: Add panic handling

2015-11-16 Thread Ard Biesheuvel
On 16 November 2015 at 14:11, Marc Zyngier wrote: > Add the panic handler, together with the small bits of assembly > code to call the kernel's panic implementation. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/hyp/hyp-entry.S | 11

[PATCH] arm64: kvm: avoid %p in __kvm_hyp_panic

2015-11-16 Thread Mark Rutland
Currently __kvm_hyp_panic uses %p for values which are not pointers, such as the ESR value. This can confusingly lead to "(null)" being printed for the value. Use %x instead, and only use %p for host pointers. Signed-off-by: Mark Rutland Acked-by: Marc Zyngier

Re: [PATCH 15/21] arm64: KVM: Add panic handling

2015-11-16 Thread Marc Zyngier
On 16/11/15 14:32, Mark Rutland wrote: + /* Call panic for real */ + while (1) { + unsigned long str_va = (unsigned long)__hyp_panic_string; + + str_va -= HYP_PAGE_OFFSET; + str_va += PAGE_OFFSET; + __hyp_do_panic(str_va,

Re: [PATCH 17/21] arm64: KVM: Map the kernel RO section into HYP

2015-11-16 Thread Marc Zyngier
On 16/11/15 14:27, Mark Rutland wrote: > On Mon, Nov 16, 2015 at 01:11:55PM +, Marc Zyngier wrote: >> In order to run C code in HYP, we must make sure that the kernel's >> RO section in mapped into HYP (otherwise things break badly). > > Somewhat tangential, but do we have any strong

Re: [PATCH 15/21] arm64: KVM: Add panic handling

2015-11-16 Thread Mark Rutland
> diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c > index 06d3e20..cdc2a96 100644 > --- a/arch/arm64/kvm/hyp/switch.c > +++ b/arch/arm64/kvm/hyp/switch.c > @@ -140,3 +140,38 @@ int __hyp_text __guest_run(struct kvm_vcpu *vcpu) > > return exit_code; > } > + > +static

[PATCH 02/21] arm64: KVM: Add a HYP-specific header file

2015-11-16 Thread Marc Zyngier
In order to expose the various EL2 services that are private to the hypervisor, add a new hyp.h file. So far, it only contains mundane things such as section annotation and VA manipulation. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/hyp.h | 31

[PATCH 18/21] arm64: KVM: Move away from the assembly version of the world switch

2015-11-16 Thread Marc Zyngier
This is it. We remove all of the code that has now been rewritten. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/Makefile |2 - arch/arm64/kvm/hyp.S| 1071 +-- arch/arm64/kvm/vgic-v2-switch.S | 134 -

[PATCH 21/21] arm64: KVM: Remove weak attributes

2015-11-16 Thread Marc Zyngier
As we've now switched to the new world switch implementation, remove the weak attributes, as nobody is supposed to override it anymore. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/debug-sr.c | 5 ++--- arch/arm64/kvm/hyp/hyp-entry.S | 3 ---

[PATCH 12/21] arm64: KVM: Implement fpsimd save/restore

2015-11-16 Thread Marc Zyngier
Implement the fpsimd save restore, keeping the lazy part in assembler (as returning to C would be overkill). Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/Makefile | 1 + arch/arm64/kvm/hyp/entry.S | 32 +++- arch/arm64/kvm/hyp/fpsimd.S |

[PATCH 05/21] arm64: KVM: Implement timer save/restore

2015-11-16 Thread Marc Zyngier
Implement the timer save restore as a direct translation of the assembly code version. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/Makefile | 1 + arch/arm64/kvm/hyp/hyp.h | 3 ++ arch/arm64/kvm/hyp/timer-sr.c | 68

[PATCH 01/21] arm64: add macros to read/write system registers

2015-11-16 Thread Marc Zyngier
From: Mark Rutland Rather than crafting custom macros for reading/writing each system register provide generics accessors, read_sysreg and write_sysreg, for this purpose. Unlike read_cpuid, calls to read_exception_reg are never expected to be optimized away or replaced

[PATCH 07/21] arm64: KVM: Implement 32bit system register save/restore

2015-11-16 Thread Marc Zyngier
Implement the 32bit system register save restore as a direct translation of the assembly code version. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/hyp.h | 2 ++ arch/arm64/kvm/hyp/sysreg-sr.c | 41 + 2 files changed, 43

[PATCH 06/21] arm64: KVM: Implement system register save/restore

2015-11-16 Thread Marc Zyngier
Implement the system registe save restore as a direct translation of the assembly code version. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/Makefile| 1 + arch/arm64/kvm/hyp/hyp.h | 3 ++ arch/arm64/kvm/hyp/sysreg-sr.c | 90

[PATCH 00/21] arm64: KVM: world switch in C

2015-11-16 Thread Marc Zyngier
Once upon a time, the KVM/arm64 world switch was a nice, clean, lean and mean piece of hand-crafted assembly code. Over time, features have crept in, the code has become harder to maintain, and the smallest change is a pain to introduce. The VHE patches are a prime example of why this doesn't work

[PATCH 14/21] arm64: KVM: HYP mode entry points

2015-11-16 Thread Marc Zyngier
Add the entry points for HYP mode (both for hypercalls and exception handling). Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/Makefile| 1 + arch/arm64/kvm/hyp/hyp-entry.S | 189 + 2 files changed, 190 insertions(+)

[PATCH 04/21] arm64: KVM: Implement vgic-v3 save/restore

2015-11-16 Thread Marc Zyngier
Implement the vgic-v3 save restore as a direct translation of the assembly code version. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/Makefile | 1 + arch/arm64/kvm/hyp/hyp.h| 3 + arch/arm64/kvm/hyp/vgic-v3-sr.c | 222

[PATCH 20/21] arm64: KVM: Cleanup asm-offset.c

2015-11-16 Thread Marc Zyngier
As we've now rewritten most of our code-base in C, most of the KVM-specific code in asm-offset.c is useless. Delete-time again! Signed-off-by: Marc Zyngier --- arch/arm64/kernel/asm-offsets.c | 39 --- 1 file changed, 39 deletions(-)

[PATCH 10/21] arm64: KVM: Add patchable function selector

2015-11-16 Thread Marc Zyngier
KVM so far relies on code patching, and is likely to use it more in the future. The main issue is that our alternative system works at the instruction level, while we'd like to have alternatives at the function level. In order to cope with this, add the "hyp_alternate_select" macro that outputs a

[PATCH 19/21] arm64: KVM: Turn system register numbers to an enum

2015-11-16 Thread Marc Zyngier
Having the system register numbers as #defines has been a pain since day one, as the ordering is pretty fragile, and moving things around leads to renumbering and epic conflict resolutions. Now that we're mostly acessing the sysreg file in C, an enum is a much better type to use, and we can clean

[PATCH 11/21] arm64: KVM: Implement the core world switch

2015-11-16 Thread Marc Zyngier
Implement the core of the world switch in C. Not everything is there yet, and there is nothing to re-enter the world switch either. But this already outlines the code structure well enough. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/Makefile | 1 +

[PATCH 16/21] arm64: KVM: Add compatibility aliases

2015-11-16 Thread Marc Zyngier
So far, we've implemented the new world switch with a completely different namespace, so that we could have both implementation compiled in. Let's take things one step further by adding weak aliases that have the same names as the original implementation. The weak attributes allows the new

[PATCH 09/21] arm64: KVM: Implement guest entry

2015-11-16 Thread Marc Zyngier
Contrary to the previous patch, the guest entry is fairly different from its assembly counterpart, mostly because it is only concerned with saving/restoring the GP registers, and nothing else. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/Makefile | 1 +

[PATCH 15/21] arm64: KVM: Add panic handling

2015-11-16 Thread Marc Zyngier
Add the panic handler, together with the small bits of assembly code to call the kernel's panic implementation. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/hyp-entry.S | 11 ++- arch/arm64/kvm/hyp/hyp.h | 1 + arch/arm64/kvm/hyp/switch.c| 35

[PATCH 13/21] arm64: KVM: Implement TLB handling

2015-11-16 Thread Marc Zyngier
Implement the TLB handling as a direct translation of the assembly code version. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/Makefile | 1 + arch/arm64/kvm/hyp/tlb.c| 72 + 2 files changed, 73 insertions(+) create

[PATCH] arm64: kvm: report original PAR_EL1 upon panic

2015-11-16 Thread Mark Rutland
If we call __kvm_hyp_panic while a guest context is active, we call __restore_sysregs before acquiring the system register values for the panic, in the process throwing away the PAR_EL1 value at the point of the panic. This patch modifies __kvm_hyp_panic to stash the PAR_EL1 value prior to

[PATCH 2/2] arm64: KVM: Add workaround for Cortex-A57 erratum 834220

2015-11-16 Thread Marc Zyngier
Cortex-A57 parts up to r1p2 can misreport Stage 2 translation faults when a Stage 1 permission fault or device alignment fault should have been reported. This patch implements the workaround (which is to validate that the Stage-1 translation actually succeeds) by using code patching.

[PATCH 0/2] arm64: KVM: Fixes for 4.4-rc2

2015-11-16 Thread Marc Zyngier
Here's a couple of fixes for KVM/arm64: - The first one addresses a misinterpretation of the architecture spec, leading to the mishandling of I/O accesses generated from an AArch32 guest using banked registers. - The second one is a workaround for a Cortex-A57 erratum. Both patches are

[PATCH 1/2] arm64: KVM: Fix AArch32 to AArch64 register mapping

2015-11-16 Thread Marc Zyngier
When running a 32bit guest under a 64bit hypervisor, the ARMv8 architecture defines a mapping of the 32bit registers in the 64bit space. This includes banked registers that are being demultiplexed over the 64bit ones. On exception caused by an operation involving a 32bit register, the HW exposes

[PATCH 0/3] arm64: KVM: Support 16-bit VMID

2015-11-16 Thread Vladimir Murzin
Hi This series is supposed to bring support for 16-bit VMID offered by the ARMv8.1 architecture extension into KVM. The first to patches are clean-up to make kvm_arm.h fit into assembly code nicely. The third patch modifies KVM code to recognise and use 16-bit VMID. Thanks! Vladimir Murzin

[PATCH 3/3] arm64: KVM: Add support for 16-bit VMID

2015-11-16 Thread Vladimir Murzin
The ARMv8.1 architecture extension allows to choose between 8-bit and 16-bit of VMID, so use this capability for KVM. Signed-off-by: Vladimir Murzin --- arch/arm/include/asm/kvm_arm.h |2 +- arch/arm/include/asm/kvm_mmu.h |5 + arch/arm/kvm/arm.c

[PATCH 1/3] kvm: arm: arm64: remove unreferenced S2_PGD_ORDER

2015-11-16 Thread Vladimir Murzin
Since commit a987370 "arm64: KVM: Fix stage-2 PGD allocation to have per-page refcounting" there is no reference to S2_PGD_ORDER, so kill it for the good. Signed-off-by: Vladimir Murzin --- arch/arm/include/asm/kvm_arm.h |1 - arch/arm/kvm/mmu.c |

[PATCH 2/3] kvm: arm: make kvm_arm.h friendly to assembly code

2015-11-16 Thread Vladimir Murzin
kvm_arm.h is included from both C code and assembly code; however some definitions in this header supplied with U/UL/ULL suffixes which might confuse assembly once they got evaluated. We have _AC macro for such cases, so just wrap problem places with it. Signed-off-by: Vladimir Murzin