[PATCH v2 7/8] arm/arm64: KVM: Rework the arch timer to use level-triggered semantics

2015-09-04 Thread Christoffer Dall
The arch timer currently uses edge-triggered semantics in the sense that the line is never sampled by the vgic and lowering the line from the timer to the vgic doesn't have any affect on the pending state of virtual interrupts in the vgic. This means that we do not support a guest with the otherwi

[PATCH v2 4/8] arm/arm64: KVM: Implement GICD_ICFGR as RO for PPIs

2015-09-04 Thread Christoffer Dall
The GICD_ICFGR allows the bits for the SGIs and PPIs to be read only. We currently simulate this behavior by writing a hardcoded value to the register for the SGIs and PPIs on every write of these bits to the register (ignoring what the guest actually wrote), and by writing the same value as the re

[PATCH v2 6/8] arm/arm64: KVM: Add forwarded physical interrupts documentation

2015-09-04 Thread Christoffer Dall
Forwarded physical interrupts on arm/arm64 is a tricky concept and the way we deal with them is not apparently easy to understand by reading various specs. Therefore, add a proper documentation file explaining the flow and rationale of the behavior of the vgic. Some of this text was contributed b

[PATCH v2 2/8] arm/arm64: KVM: arch_timer: Only schedule soft timer on vcpu_block

2015-09-04 Thread Christoffer Dall
We currently schedule a soft timer every time we exit the guest if the timer did not expire while running the guest. This is really not necessary, because the only work we do in the timer work function is to kick the vcpu. Kicking the vcpu does two things: (1) If the vpcu thread is on a waitqueue

[PATCH v2 5/8] arm/arm64: KVM: Use appropriate define in VGIC reset code

2015-09-04 Thread Christoffer Dall
We currently initialize the SGIs to be enabled in the VGIC code, but we use the VGIC_NR_PPIS define for this purpose, instead of the the more natural VGIC_NR_SGIS. Change this slightly confusing use of the defines. Note: This should have no functional change, as both names are defined to the numb

[PATCH v2 8/8] arm/arm64: KVM: Support edge-triggered forwarded interrupts

2015-09-04 Thread Christoffer Dall
We mark edge-triggered interrupts with the HW bit set as queued to prevent the VGIC code from injecting LRs with both the Active and Pending bits set at the same time while also setting the HW bit, because the hardware does not support this. However, this means that we must also clear the queued f

[PATCH v2 1/8] KVM: Add kvm_arch_vcpu_{un}blocking callbacks

2015-09-04 Thread Christoffer Dall
Some times it is useful for architecture implementations of KVM to know when the VCPU thread is about to block or when it comes back from blocking (arm/arm64 needs to know this to properly implement timers, for example). Therefore provide a generic architecture callback function in line with what

[PATCH v2 3/8] arm/arm64: KVM: vgic: Factor out level irq processing on guest exit

2015-09-04 Thread Christoffer Dall
Currently vgic_process_maintenance() processes dealing with a completed level-triggered interrupt directly, but we are soon going to reuse this logic for level-triggered mapped interrupts with the HW bit set, so move this logic into a separate static function. Probably the most scary part of this

[PATCH v2 0/8] Rework architected timer and forwarded IRQs handling

2015-09-04 Thread Christoffer Dall
The architected timer integration with the VGIC had some shortcomings in that certain guest operations weren't fully supported. This series tries to address these problems in providing level-triggered semantics for the arch timer and VGIC integration and seeks to clarify the behavior when setting/

Re: [PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores

2015-09-04 Thread Alexander Spyridakis
On 4 September 2015 at 17:54, Marc Zyngier wrote: > Seems sound to me. Out of curiosity, how was this found? Hello Mark, This issue came up when testing some basic bare metal tests with KVM, which originally were meant for the multi-threading TCG effort (https://git.virtualopensystems.com/dev/tc

Re: [PATCH 5/9] arm/arm64: KVM: Use appropriate define in VGIC reset code

2015-09-04 Thread Eric Auger
On 08/30/2015 03:54 PM, Christoffer Dall wrote: > We currently initialize the SGIs to be enabled in the VGIC code, but we > use the VGIC_NR_PPIS define for this purpose, instead of the the more s/the// Eric > natural VGIC_NR_SGIS. Change this slightly confusing use of the > defines. > > Note: Th

Re: [PATCH 6/9] arm/arm64: KVM: Add mapped interrupts documentation

2015-09-04 Thread Marc Zyngier
On 04/09/15 16:57, Christoffer Dall wrote: > On Thu, Sep 03, 2015 at 04:23:04PM +0100, Marc Zyngier wrote: >> On 30/08/15 14:54, Christoffer Dall wrote: >>> + >>> + >>> +Life Cycle for Forwarded Physical Interrupts >>> + >>> + >>> +By forwarded physical i

Re: [PATCH 6/9] arm/arm64: KVM: Add mapped interrupts documentation

2015-09-04 Thread Christoffer Dall
On Thu, Sep 03, 2015 at 04:23:04PM +0100, Marc Zyngier wrote: > On 30/08/15 14:54, Christoffer Dall wrote: > > Mapped interrupts on arm/arm64 is a tricky concept and the way we deal > > with them is not apparently easy to understand by reading various specs. > > > > Therefore, add a proper documen

Re: [PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores

2015-09-04 Thread Mark Rutland
On Fri, Sep 04, 2015 at 04:06:24PM +0100, Alexander Spyridakis wrote: > If a guest requests the affinity info for a non-existing vCPU we need to > properly return an error, instead of erroneously reporting an off state. > > Signed-off-by: Alexander Spyridakis > Signed-off-by: Alvise Rigo This l

Re: [PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores

2015-09-04 Thread Marc Zyngier
On 04/09/15 16:06, Alexander Spyridakis wrote: > If a guest requests the affinity info for a non-existing vCPU we need to > properly return an error, instead of erroneously reporting an off state. > > Signed-off-by: Alexander Spyridakis > Signed-off-by: Alvise Rigo Seems sound to me. Out of cur

Re: [PATCH 6/9] arm/arm64: KVM: Add mapped interrupts documentation

2015-09-04 Thread Christoffer Dall
On Thu, Sep 03, 2015 at 05:56:26PM +0200, Eric Auger wrote: > Hi Christoffer, > On 09/03/2015 05:23 PM, Marc Zyngier wrote: > > On 30/08/15 14:54, Christoffer Dall wrote: > >> Mapped interrupts on arm/arm64 is a tricky concept and the way we deal > >> with them is not apparently easy to understand

Re: [PATCH 6/9] arm/arm64: KVM: Add mapped interrupts documentation

2015-09-04 Thread Christoffer Dall
On Thu, Sep 03, 2015 at 04:23:04PM +0100, Marc Zyngier wrote: > On 30/08/15 14:54, Christoffer Dall wrote: > > Mapped interrupts on arm/arm64 is a tricky concept and the way we deal > > with them is not apparently easy to understand by reading various specs. > > > > Therefore, add a proper documen

Re: [PATCH 0/2] arm/arm64: KVM: Fix arthictected timer issues

2015-09-04 Thread Christoffer Dall
On Fri, Sep 04, 2015 at 04:35:20PM +0100, Marc Zyngier wrote: > Hi Christoffer, > > On 04/09/15 15:24, Christoffer Dall wrote: > > These two patches fix two separate issues with the architected timer and > > the corresponding interrupt injection to VMs on KVM/ARM. > > > > The first patch fixes an

RE: [PATCH v3 5/5] KVM: arm64: Implement vGICv3 CPU interface access

2015-09-04 Thread Pavel Fedin
Hello! > So can you model the register size according to the spec and allow > 32-bit accesses from userland? I can. But i'll have to invent my own macro for encoding register IDs into the attribute, as well as drop reusing index_to_params(). Will it be OK? Upside: i can further extend "cpu id

Re: [PATCH 0/2] arm/arm64: KVM: Fix arthictected timer issues

2015-09-04 Thread Marc Zyngier
Hi Christoffer, On 04/09/15 15:24, Christoffer Dall wrote: > These two patches fix two separate issues with the architected timer and > the corresponding interrupt injection to VMs on KVM/ARM. > > The first patch fixes an issue introduced with the active timer state > switching series recently me

RE: [PATCH v3 3/5] KVM: arm64: Refactor system register handlers

2015-09-04 Thread Pavel Fedin
Hello! > Mmmh, not sure about this, but I guess u64 would be more precise here? > With the Rt2 handling below we rely on this being 64 bits anyway. But I > guess that breaks with assigning vcpu_reg later and since this is arm64 > only, long is always 64 bits? It is because ' params.val = &val'.

RE: [PATCH v3 2/5] KVM: arm64: Implement vGICv3 distributor and redistributor access from userspace

2015-09-04 Thread Pavel Fedin
Hello! > > The access is done similar to vGICv2, using KVM_DEV_ARM_VGIC_GRP_DIST_REGS > > and KVM_DEV_ARM_VGIC_GRP_REDIST_REGS with KVM_SET_DEVICE_ATTR and > > KVM_GET_DEVICE_ATTR ioctls. Since GICv3 can handle large number of CPUs, > > KVM_DEV_ARM_VGIC_CPUID_MASK has been extended to 20 bits. Th

Re: [PATCH v2 1/5] KVM: arm/arm64: Refactor vGIC attributes handling code

2015-09-04 Thread Andre Przywara
Hi, On 04/09/15 16:11, Pavel Fedin wrote: > Hello! > >> Isn't the len parameter redundant here? I see that you don't initialize >> mmio.len (which is a bit scary, btw), so can't you just use that field? > > This was because of split below. I did not know about call_range_handler(), > and now

Re: [PATCH v3 5/5] KVM: arm64: Implement vGICv3 CPU interface access

2015-09-04 Thread Andre Przywara
Hi Pavel, On 04/09/15 13:40, Pavel Fedin wrote: > The access is done similar to GICv2, using KVM_DEV_ARM_VGIC_GRP_CPU_REGS > group, however attribute ID encodes corresponding system register. Access > size is always 64 bits. Why is this? Actually all registers in the CPU interface (except the w/o

RE: [PATCH v2 1/5] KVM: arm/arm64: Refactor vGIC attributes handling code

2015-09-04 Thread Pavel Fedin
Hello! > Isn't the len parameter redundant here? I see that you don't initialize > mmio.len (which is a bit scary, btw), so can't you just use that field? This was because of split below. I did not know about call_range_handler(), and now i will redo this. > That (and other parts of this patc

Re: [PATCH v3 4/5] KVM: arm64: Introduce find_reg_by_id()

2015-09-04 Thread Andre Przywara
On 04/09/15 13:40, Pavel Fedin wrote: > In order to implement vGICv3 CPU interface access, we will need to perform > table lookup of system registers. We would need both index_to_params() and > find_reg() exported for that purpose, but instead we export a single > function which combines them both.

Re: [PATCH v3 3/5] KVM: arm64: Refactor system register handlers

2015-09-04 Thread Andre Przywara
Hi Pavel, On 04/09/15 13:40, Pavel Fedin wrote: > Replace Rt with data pointer in struct sys_reg_params. This will allow to > reuse system register handling code in implementation of vGICv3 CPU > interface access API. Additionally, got rid of "massive hack" > in kvm_handle_cp_64(). > > Signed-off

[PATCH] KVM: arm/arm64: Fix PSCI affinity info return value for non valid cores

2015-09-04 Thread Alexander Spyridakis
If a guest requests the affinity info for a non-existing vCPU we need to properly return an error, instead of erroneously reporting an off state. Signed-off-by: Alexander Spyridakis Signed-off-by: Alvise Rigo --- arch/arm/kvm/psci.c | 12 1 file changed, 8 insertions(+), 4 deletion

Re: [PATCH 2/2] arm/arm64: KVM: arch timer: Reset CNTV_CTL to 0

2015-09-04 Thread Marc Zyngier
On 04/09/15 15:47, Christoffer Dall wrote: > On Fri, Sep 04, 2015 at 04:24:39PM +0200, Christoffer Dall wrote: >> Provide a better quality of implementation and be architecture compliant >> on ARMv7 for the architected timer by resetting the CNTV_CTL to 0 on >> reset of the timer, and call kvm_time

Re: [PATCH 1/9] KVM: Add kvm_arch_vcpu_{un}blocking callbacks

2015-09-04 Thread Christoffer Dall
On Fri, Sep 04, 2015 at 03:50:08PM +0200, Eric Auger wrote: > Hi Christoffer, > On 08/30/2015 03:54 PM, Christoffer Dall wrote: > > Some times it is useful for architecture implementations of KVM to know > > when the VCPU thread is about to block or when it comes back from > > blocking (arm/arm64 n

Re: [PATCH 2/2] arm/arm64: KVM: arch timer: Reset CNTV_CTL to 0

2015-09-04 Thread Christoffer Dall
On Fri, Sep 04, 2015 at 04:24:39PM +0200, Christoffer Dall wrote: > Provide a better quality of implementation and be architecture compliant > on ARMv7 for the architected timer by resetting the CNTV_CTL to 0 on > reset of the timer, and call kvm_timer_update_state(vcpu) at the same > time, ensurin

[PATCH 1/2] arm/arm64: KVM: vgic: Move active state handling to flush_hwstate

2015-09-04 Thread Christoffer Dall
We currently set the physical active state only when we *inject* a new pending virtual interrupt, but this is actually not correct, because we could have been preempted and run something else on the system that resets the active state to clear. This causes us to run the VM with the timer set to fi

[PATCH 0/2] arm/arm64: KVM: Fix arthictected timer issues

2015-09-04 Thread Christoffer Dall
These two patches fix two separate issues with the architected timer and the corresponding interrupt injection to VMs on KVM/ARM. The first patch fixes an issue introduced with the active timer state switching series recently merged for v4.3, which could cause a guest to loop without progress if a

[PATCH 2/2] arm/arm64: KVM: arch timer: Reset CNTV_CTL to 0

2015-09-04 Thread Christoffer Dall
Provide a better quality of implementation and be architecture compliant on ARMv7 for the architected timer by resetting the CNTV_CTL to 0 on reset of the timer, and call kvm_timer_update_state(vcpu) at the same time, ensuring the timer output is not asserted after, for example, a PSCI system reset

Re: [PATCH 12/14] arm64: Check for selected granule support

2015-09-04 Thread Catalin Marinas
On Wed, Sep 02, 2015 at 12:19:07PM +0200, Ard Biesheuvel wrote: > On 2 September 2015 at 11:48, Ard Biesheuvel > wrote: > > Couldn't we allocate some flag bits in the Image header to communicate > > the page size to the bootloader? > > Something like this perhaps? > > 8<

Re: [PATCH v3 2/5] KVM: arm64: Implement vGICv3 distributor and redistributor access from userspace

2015-09-04 Thread Andre Przywara
Hi Pavel, On 04/09/15 13:40, Pavel Fedin wrote: > The access is done similar to vGICv2, using KVM_DEV_ARM_VGIC_GRP_DIST_REGS > and KVM_DEV_ARM_VGIC_GRP_REDIST_REGS with KVM_SET_DEVICE_ATTR and > KVM_GET_DEVICE_ATTR ioctls. Since GICv3 can handle large number of CPUs, > KVM_DEV_ARM_VGIC_CPUID_MASK

Re: [PATCH 1/9] KVM: Add kvm_arch_vcpu_{un}blocking callbacks

2015-09-04 Thread Eric Auger
Hi Christoffer, On 08/30/2015 03:54 PM, Christoffer Dall wrote: > Some times it is useful for architecture implementations of KVM to know > when the VCPU thread is about to block or when it comes back from > blocking (arm/arm64 needs to know this to properly implement timers, for > example). what a

Re: [PATCH v2 1/5] KVM: arm/arm64: Refactor vGIC attributes handling code

2015-09-04 Thread Andre Przywara
Hi Pavel, On 02/09/15 09:09, Pavel Fedin wrote: > Separate all implementation-independent code in vgic_attr_regs_access() > and move it to vgic.c. This will allow to reuse this code for vGICv3 > implementation. > > Signed-off-by: Pavel Fedin > --- > virt/kvm/arm/vgic-v2-emul.c | 126 >

[PATCH v3 4/5] KVM: arm64: Introduce find_reg_by_id()

2015-09-04 Thread Pavel Fedin
In order to implement vGICv3 CPU interface access, we will need to perform table lookup of system registers. We would need both index_to_params() and find_reg() exported for that purpose, but instead we export a single function which combines them both. Signed-off-by: Pavel Fedin --- arch/arm64/

[PATCH v3 0/5] KVM: arm64: Implement API for vGICv3 live migration

2015-09-04 Thread Pavel Fedin
This patchset adds necessary userspace API in order to support vGICv3 live migration. GICv3 registers are accessed using device attribute ioctls, similar to GICv2. V2 => V3: - KVM_DEV_ARM_VGIC_CPUID_MASK enlarged to 20 bits, allowing more than 256 CPUs. - Bug fix: Correctly set mmio->private, ne

[PATCH v3 3/5] KVM: arm64: Refactor system register handlers

2015-09-04 Thread Pavel Fedin
Replace Rt with data pointer in struct sys_reg_params. This will allow to reuse system register handling code in implementation of vGICv3 CPU interface access API. Additionally, got rid of "massive hack" in kvm_handle_cp_64(). Signed-off-by: Pavel Fedin --- arch/arm64/kvm/sys_regs.c|

[PATCH v3 2/5] KVM: arm64: Implement vGICv3 distributor and redistributor access from userspace

2015-09-04 Thread Pavel Fedin
The access is done similar to vGICv2, using KVM_DEV_ARM_VGIC_GRP_DIST_REGS and KVM_DEV_ARM_VGIC_GRP_REDIST_REGS with KVM_SET_DEVICE_ATTR and KVM_GET_DEVICE_ATTR ioctls. Since GICv3 can handle large number of CPUs, KVM_DEV_ARM_VGIC_CPUID_MASK has been extended to 20 bits. This is enough for 1048576

[PATCH v3 1/5] KVM: arm/arm64: Refactor vGIC attributes handling code

2015-09-04 Thread Pavel Fedin
Separate all implementation-independent code in vgic_attr_regs_access() and move it to vgic.c. This will allow to reuse this code for vGICv3 implementation. Signed-off-by: Pavel Fedin --- virt/kvm/arm/vgic-v2-emul.c | 126 +--- virt/kvm/arm/vgic.c

[PATCH v3 5/5] KVM: arm64: Implement vGICv3 CPU interface access

2015-09-04 Thread Pavel Fedin
The access is done similar to GICv2, using KVM_DEV_ARM_VGIC_GRP_CPU_REGS group, however attribute ID encodes corresponding system register. Access size is always 64 bits. Since CPU interface state actually affects only a single vCPU, no vGIC locking is done. Just made sure that the vCPU is not run

RE: [PATCH v2 2/5] KVM: arm64: Implement vGICv3 distributor and redistributor access from userspace

2015-09-04 Thread Pavel Fedin
Hello! > > + KVM_DEV_ARM_VGIC_GRP_REDIST_REGS > > + Attributes: > > +The attr field of kvm_device_attr encodes two values: > > +bits: | 63 | 62 .. 40 | 39 .. 32 | 31 0 | > > +values: | size | reserved | cpu id | offset | > > We should avoid imp