KVM: ARM: move struct pt_regs back to usr regs

This partially reverts commit f7c6882646ebd12ee0daab1055cd38c23f47c610:
ARM: KVM: move usr regs to struct pt_regs

The kvm_regs struct is part of the user space ABI to provide an index
for which registers are get/set using the corresponding ioctl's and
should really be explicitly typed in line with the remaining KVM code.

If we want to move away from that we should provide fixed indices for
the registers, but I've never been a fan of hiding the pc and cpsr under
the usr_regs field in the first place.

This (once again) breaks compatibility with QEMU, and I will update the
kvm-arm branch on git://github.com/virtualopensystems/qemu.git
accordingly.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
ARM: KVM: move MMIO handling to its own files

MMIO handling is currently tangled between mmu.c and emulate.c.

Move HSR based handling to mmio.c, and anything related to emulation
(including the readback from memory) into emulate.c.

In the end:
- mmu.c: only deals with page tables and defers to mmio.c for anything
  else
- mmio.c: only deals with valid HSR faults, and defers to emulate.c
  for anything else
- emulate.c only cares about instruction emulation

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Check for overlaps of mapped io addresses

When calling stage2_set_pte from kvm_phys_addr_ioremap we pass an
argument to say that this is an IO mapping, and that we expect the
adress range to be free, otherwise return an error.

This should catch errors earlier when user space supplies guest physical
addresses that overlap.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Introduce KVM_SET_DEVICE_ADDRESS ioctl

On ARM (and possibly other architectures) some bits are specific to the
model being emulated for the guest and user space needs a way to tell
the kernel about those bits.  An example is mmio device base addresses,
where KVM must know the base address for a given device to properly
emulate mmio accesses within a certain address range or directly map a
device with virtualiation extensions into the guest address space.

We try to make this API slightly more generic than for our specific use,
but so far only the VGIC uses this feature.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Defer parts of the vgic init until first KVM_RUN

The vgic virtual cpu and emulated distributor interfaces must
be mapped at a given physical address in the guest.  This address is
provided through the KVM_SET_DEVICE_ADDRESS ioctl, which happens after
the KVM_CREATE_IRQCHIP ioctl is called, but before the first VCPU is
excuted thorugh KVM_RUN.  We create the vgic on KVM_CREATE_IRQCHIP, but
query kvm_vgic_ready(kvm), which checks if the vgic.vctrl_base field has
been set, before we execute a VCPU, and if it has not been set, we call
kvm_vgic_init, which takes care of the remaining setup.

We use the IS_VGIC_ADDR_UNDEF() macro, which compares to the
VGIC_ADDR_UNDEF constant, to check if an address has been set;  it's
unlikely that a device will sit on address 0, but since this is a part
of main kernel boot procedure if this stuff is enabled in the config,
I'm being paranoid.

The distributor and vcpu base addresses used to be a per-host setting
global for all VMs, but this is not a requirement and when we want to
emulate several boards on a single host, we need the flexibility of
storing these guest addresses on a per-VM basis.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Fix incorrect scaled register mask

SCALE_SHIFT_MASK is used by the fuction : ls_word_calc_offset, but since
the addressing mode defines the bits as such:

...|    imm5    |type |0 |   Rm   |
...|11 10 9 8 7 |6 5  |4 |3 2 1 0 |

The mask should be 0x60 and not 0x10.

Reported-by: Haibin Wang <wanghaibin202@gmail.com>
Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>