ARM: KVM: Do not trap on WFE execution

We currently trap both WFI and WFE, and treat WFE exactly as WFI.
This is not a very nice thing to do in an SMP configuration, as
any spinlock contention on the guest will result in a massive
performance degradation.

WFE is usually used for very short periods, so staying on the
physical CPU is likely to be the best choice.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: Upgrade barriers and TLB operations to inner-shareable domain.

On a SMP host, the barriers should be upgraded to the inner
shareable domain, so that the effect of the barrier can be
observed on other CPUs, in case where the virtual CPU is
migrated from a physical CPU to another.

For the same reasons, TLB operations must also be broadcast
across the inner shareable domain.

These features shouldn't have any effect on UP hosts.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: Trap guest access to ACTLR

The ACTLR is implementation dependant, and better left untouched
by the guest.

Trap the access by ignoring writes, and let reads return the host
view of the ACTLR, adjusted to reflect whether the guest is SMP
or not.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: Use bit operations when dealing with addresses

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: add page accounting and guest page table eviction

Until now, we do not track how many references the page tables
contain, which makes them impossible to free from the MMU notifiers.

By updating the page table pages' refcounts each time we fault in
or evict a page, it becomes easy to track the state of the various
page tables, and to free them when them become empty.

Only the top PGD is never freed.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: Report more details about the unsupported fault

Before returning an error when getting an unhandled fault, display
the complete EC and DFSC fields. This is very useful when debugging
mapping problems.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: add mem_type prot_pte accessor

The KVM hypervisor mmu code requires requires access to the
mem_type prot_pte field when setting up page tables pointing
to a device. Unfortunately, the mem_type structure is opaque.

Add an accessor (get_mem_type_prot_pte()) to retrieve the
prot_pte value.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: Add support for IO mapping at the HYP level

Moving to the VGIC implies giving access to some ioremapped
devices (the VGIC virtual interface control registers) to the
hypervisor.

Define create_hyp_io_mappings() as the IO aware sibling of
create_hyp_mappings(), and extend the mapping functions
to support a pte mapping backend.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: Add support for IO mapping at the guest level

Moving to the VGIC implies giving access to some io devices
(the VGIC virtual CPU interface registers) to the guest.

Define kvm_phys_addr_ioremap() to map a device at a guest IPA.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: Make kvm_hyp_pgd and kvm_hyp_pgd_mutex static

There is very little reason for kvm_hyp_pgd and kvm_hyp_pgd_mutex
to be accessed outside of mmu.c, and kvm_hyp_pgd is passed as an
argument to most functions.

Instead, define a set of function to access it, and make it private.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
KVM: use KVM_CAP_IRQ_ROUTING to protect the routing related code

The KVM code sometimes uses CONFIG_HAVE_KVM_IRQCHIP to protect
code that is related to IRQ routing, which not all in-kernel
irqchips may support.

Use KVM_CAP_IRQ_ROUTING instead.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: Initial VGIC infrastructure support

Wire the basic framework code for VGIC support. Nothing to enable
yet.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: Initial VGIC MMIO support code

Wire the initial in-kernel MMIO support code for the VGIC, used
for the distributor emulation.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: VGIC distributor handling

Add the GIC distributor emulation code. A number of the GIC features
are simply ignored as they are not required to boot a Linux guest.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: VGIC virtual CPU interface management

Add VGIC virtual CPU interface code, picking pending interrupts
from the distributor and stashing them in the VGIC control interface
list registers.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: VGIC interrupt injection

Plug the interrupt injection code. Interrupts can now be generated
from user space.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: VGIC initialisation code

Add the init code for the hypervisor, the virtual machine, and
the virtual CPUs.

An interrupt handler is also wired to allow the VGIC maintainance
interrupts, used in case of underflow.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: VGIC control interface world switch

Enable the VGIC control interface to be save-restored on world switch.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: Add VGIC configuration option

It is now possible to select the VGIC congifuration option.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: VGIC: Update KVM API documentation

Reflect the changes in the API due to the introduction of VGIC.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>