Re: [PATCH v8 08/11] KVM: arm64: introduce vcpu-arch.debug_ptr

2015-07-08 Thread Christoffer Dall
On Tue, Jul 07, 2015 at 05:30:00PM +0100, Alex Bennée wrote: This introduces a level of indirection for the debug registers. Instead of using the sys_regs[] directly we store registers in a structure in the vcpu. The new kvm_arm_reset_debug_ptr() sets the debug ptr to the guest context.

Re: [PATCH v3 08/11] KVM: arm: implement dirty bit mechanism for debug registers

2015-07-08 Thread Zhichao Huang
Hi, Will, Are you happy with this?: diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c +bool hw_breakpoint_enabled(void) +{ +struct perf_event **slots; +int i; + +slots = this_cpu_ptr(bp_on_reg); +for (i = 0; i core_num_brps; i++) { +if

Re: [PATCH v8 11/11] KVM: arm64: add trace points for guest_debug debug

2015-07-08 Thread Christoffer Dall
On Tue, Jul 07, 2015 at 05:30:03PM +0100, Alex Bennée wrote: This includes trace points for: kvm_arch_setup_guest_debug kvm_arch_clear_guest_debug I've also added some generic register setting trace events and also a trace point to dump the array of hardware registers. Signed-off-by:

[PATCH 00/13] arm64: Virtualization Host Extension support

2015-07-08 Thread Marc Zyngier
ARMv8.1 comes with the Virtualization Host Extension (VHE for short), which enables simpler support of Type-2 hypervisors. This extension allows the kernel to directly run at EL2, and significantly reduces the number of system registers shared between host and guest, reducing the overhead of

[PATCH 02/13] arm64: Allow the arch timer to use the HYP timer

2015-07-08 Thread Marc Zyngier
With the ARMv8.1 VHE, the kernel can run in HYP mode, and thus use the HYP timer instead of the normal guest timer in a mostly transparent way, except for the interrupt line. This patch reworks the arch timer code to allow the selection of the HYP PPI, possibly falling back to the guest timer if

[PATCH 03/13] arm64: Add ARM64_HAS_VIRT_HOST_EXTN feature

2015-07-08 Thread Marc Zyngier
Add a new ARM64_HAS_VIRT_HOST_EXTN features to indicate that the CPU has the ARMv8,1 VHE capability. This will be used to trigger kernel patching in KVM. Signed-off-by: Marc Zyngier marc.zyng...@arm.com --- arch/arm64/include/asm/cpufeature.h | 3 ++- arch/arm64/kernel/cpufeature.c | 11

[PATCH 08/13] arm64: KVM: VHE: Preserve VHE config in world switch

2015-07-08 Thread Marc Zyngier
Running the kernel in HYP mode requires the HCR_E2H bit to be set at all times, and the HCR_TGE bit to be set when running as a host (and cleared when running as a guest). Also add some cryptic macros to deal with cpp macro expansion inside asm macros... Signed-off-by: Marc Zyngier

[PATCH 01/13] arm/arm64: Add new is_kernel_in_hyp_mode predicate

2015-07-08 Thread Marc Zyngier
With ARMv8.1 VHE extension, it will be possible to run the kernel at EL2 (aka HYP mode). In order for the kernel to easily find out where it is running, add a new predicate that returns whether or not the kernel is in HYP mode. For completeness, the 32bit code also get such a predicate (always

Re: [RFC PATCH] KVM: arm/arm64: Don't let userspace update CNTVOFF once guest is running

2015-07-08 Thread Peter Maydell
On 8 July 2015 at 16:56, Marc Zyngier marc.zyng...@arm.com wrote: On 29/06/15 18:37, Peter Maydell wrote: On 29 June 2015 at 18:20, Claudio Fontana claudio.font...@huawei.com wrote: On 26.06.2015 06:49, Jan Kiszka wrote: QEMU has the concept of write-back levels: KVM_PUT_RUNTIME_STATE,

[PATCH 10/13] arm64: Add support for running Linux in EL2 mode

2015-07-08 Thread Marc Zyngier
With the ARMv8.1 VHE, the architecture is able to (almost) transparently run the kernel at EL2, despite being written for EL1. This patch takes care of the almost part, mostly preventing the kernel from dropping from EL2 to EL1, and setting up the HYP configuration. Signed-off-by: Marc Zyngier

[PATCH 07/13] arm64: KVM: VHE: Patch out use of HVC

2015-07-08 Thread Marc Zyngier
With VHE, the host never issues an HVC instruction to get into the KVM code, as we can simply branch there. Use runtime code patching to simplify things a bit. Signed-off-by: Marc Zyngier marc.zyng...@arm.com --- arch/arm64/kvm/hyp.S| 43 ---

[PATCH 11/13] arm64: Panic when VHE and non VHE CPUs coexist

2015-07-08 Thread Marc Zyngier
Having both VHE and non-VHE capable CPUs in the same system is likely to be a recipe for disaster. If the boot CPU has VHE, but a secondary is not, we won't be able to downgrade and run the kernel at EL1. Add CPU hotplug to the mix, and this produces a terrifying mess. Let's solve the problem

[PATCH 06/13] arm64: KVM: VHE: Patch out kern_hyp_va

2015-07-08 Thread Marc Zyngier
The kern_hyp_va macro is pretty meaninless with VHE, as there is only one mapping - the kernel one. In order to keep the code readable and efficient, use runtime patching to replace the 'and' instruction used to compute the VA with a 'nop'. Signed-off-by: Marc Zyngier marc.zyng...@arm.com ---

[PATCH 13/13] arm64: KVM: VHE: Early interrupt handling

2015-07-08 Thread Marc Zyngier
With VHE enabled, it is possible to let the kernel handle an interrupt without saving the full guest context, and without restoring the full host context either. This reduces the latency of handling an interrupt. When an interrupt fires we can: - save the guest's general purpose registers, shared

Re: [RFC PATCH] KVM: arm/arm64: Don't let userspace update CNTVOFF once guest is running

2015-07-08 Thread Marc Zyngier
On 08/07/15 17:06, Peter Maydell wrote: On 8 July 2015 at 16:56, Marc Zyngier marc.zyng...@arm.com wrote: On 29/06/15 18:37, Peter Maydell wrote: On 29 June 2015 at 18:20, Claudio Fontana claudio.font...@huawei.com wrote: On 26.06.2015 06:49, Jan Kiszka wrote: QEMU has the concept of

Re: [PATCH v3 08/11] KVM: arm: implement dirty bit mechanism for debug registers

2015-07-08 Thread Will Deacon
On Wed, Jul 08, 2015 at 11:50:22AM +0100, Zhichao Huang wrote: Are you happy with this?: You miss the reserved breakpoint, I think. I also still don't understand why this is preferable to trapping. Will ___ kvmarm mailing list

Re: [PATCH 07/13] arm64: KVM: VHE: Patch out use of HVC

2015-07-08 Thread Paolo Bonzini
On 08/07/2015 18:19, Marc Zyngier wrote: +/* Hack to allow stringification of macros... */ +#define __S__(a,args...) __stringify(a, ##args) +#define _S_(a,args...) __S__(a, args) + +.macro ifnvhe nonvhe vhe + alternative_insn\nonvhe, \vhe,

Re: [PATCH 01/18] ARM64: Move PMU register related defines to asm/pmu.h

2015-07-08 Thread Will Deacon
On Mon, Jul 06, 2015 at 03:17:31AM +0100, shannon.z...@linaro.org wrote: From: Shannon Zhao shannon.z...@linaro.org To use the ARMv8 PMU related register defines from the KVM code, we move the relevant definitions to asm/pmu.h header file. Signed-off-by: Anup Patel anup.pa...@linaro.org

[PATCH v2 03/10] KVM: arm/arm64: vgic: Convert struct vgic_lr to use bitfields

2015-07-08 Thread Marc Zyngier
As we're about to cram more information in the vgic_lr structure (HW interrupt number and additional state information), we switch to a layout similar to the HW's: - use bitfields to save space (we don't need more than 10 bits to represent the irq numbers) - source CPU and HW interrupt can

[PATCH v2 02/10] arm/arm64: KVM: Move vgic handling to a non-preemptible section

2015-07-08 Thread Marc Zyngier
As we're about to introduce some serious GIC-poking to the vgic code, it is important to make sure that we're going to poke the part of the GIC that belongs to the CPU we're about to run on (otherwise, we'd end up with some unexpected interrupts firing)... Introducing a non-preemptible section in

[PATCH v2 04/10] KVM: arm/arm64: vgic: Allow HW irq to be encoded in LR

2015-07-08 Thread Marc Zyngier
Now that struct vgic_lr supports the LR_HW bit and carries a hwirq field, we can encode that information into the list registers. This patch provides implementations for both GICv2 and GICv3. Signed-off-by: Marc Zyngier marc.zyng...@arm.com --- include/linux/irqchip/arm-gic-v3.h | 3 +++

Re: [PATCH 07/13] arm64: KVM: VHE: Patch out use of HVC

2015-07-08 Thread Marc Zyngier
On 08/07/15 18:14, Paolo Bonzini wrote: On 08/07/2015 18:19, Marc Zyngier wrote: +/* Hack to allow stringification of macros... */ +#define __S__(a,args...)__stringify(a, ##args) +#define _S_(a,args...) __S__(a, args) + +.macro ifnvhe nonvhe vhe +alternative_insn

[PATCH v2 01/10] arm/arm64: KVM: Fix ordering of timer/GIC on guest entry

2015-07-08 Thread Marc Zyngier
As we now inject the timer interrupt when we're about to enter the guest, it makes a lot more sense to make sure this happens before the vgic code queues the pending interrupts. Otherwise, we get the interrupt on the following exit, which is not great for latency (and leads to all kind of bizarre

[PATCH v2 09/10] KVM: arm/arm64: timer: Allow the timer to control the active state

2015-07-08 Thread Marc Zyngier
In order to remove the crude hack where we sneak the masked bit into the timer's control register, make use of the phys_irq_map API control the active state of the interrupt. Signed-off-by: Marc Zyngier marc.zyng...@arm.com --- include/kvm/arm_arch_timer.h | 3 +++ virt/kvm/arm/arch_timer.c

[PATCH v2 05/10] KVM: arm/arm64: vgic: Relax vgic_can_sample_irq for edge IRQs

2015-07-08 Thread Marc Zyngier
We only set the irq_queued flag for level interrupts, meaning that !vgic_irq_is_queued(vcpu, irq) is a good enough predicate for all interrupts. This will allow us to inject edge HW interrupts, for which the state ACTIVE+PENDING is not allowed. Signed-off-by: Marc Zyngier marc.zyng...@arm.com

Re: [PATCH 09/13] arm64: KVM: VHE: Add alternatives for VHE-enabled world-switch

2015-07-08 Thread Mario Smarduch
On 07/08/2015 09:19 AM, Marc Zyngier wrote: In order to switch between host and guest, a VHE-enabled kernel must use different accessors for certain system registers. This patch uses runtime patching to use the right instruction when required... Signed-off-by: Marc Zyngier

Re: [RFC PATCH] KVM: arm/arm64: Don't let userspace update CNTVOFF once guest is running

2015-07-08 Thread Peter Maydell
On 8 July 2015 at 17:37, Marc Zyngier marc.zyng...@arm.com wrote: On 08/07/15 17:06, Peter Maydell wrote: I'd prefer it if somebody could investigate to see why QEMU is actually doing this -- so far we just have speculation. I'd prefer that too, but so far people seem to be more comfortable