ARM: KVM: Change HYP ABI from continuation to function call

The current HYP ABI has the following semantics:

	<svc code>
	hvc #0 	; Enter HYP mode
	<hyp code>
	hvc #0	; Exit HYP mode
	<svc code>

This relies on the implicit assumption that you can map both SVC and
HYP code at the same virtual address so you can seamlessly carry on
executing code in sequence after switching mode.

This assumption may not be true for ARMv8, if the kernel is located
high enough to be out of reach of HTTBR.

This patch changes the ABI so the call into HYP becomes a function
call:

	<svc code>
	ldr	r0, =BSYM(my_hyp_fn)
	ldr	r1, =my_param
	hvc #0	; Call my_hyp_fn(my_param) from HYP mode
	<svc code>

This allows the HVC handler to offset the function address passed
from SVC so it can be called. The ABI only supports up to 3 32bit
parameters, and can return up to 64bits of data.

>From the host point of view, any function mapped in HYP mode can
be called using the kvm_call_hyp() helper:

	u64 kvm_call_hyp(void *hypfn, ...);

For example, calling __kvm_vcpu_run(vcpu) is replaced by:

	kvm_call_hyp(__kvm_vcpu_run, vcpu);

Tested on TC2.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
ARM: KVM: introduce {save, restore}_host_regs macros

Host and guest registers are saved/restored using the same set
of macros. This makes it quite difficult to modify the layout of
struct kvm_cpu_regs without impacting the stack layout as well
(which is where the host registers are saved).

Introduce a separate set of macros that are used to save and
restore the host registers using the stack, allowing the guest
macros to be rewritten independently in a subsequent patch.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
ARM: KVM: introduce {save, restore}_guest_regs

The current save/restore code treats the register file as a stack,
which makes the code quite hard to read, and even harder to
switch to a different layout.

Furthermore, the restore code is spread across several code paths
with a loose calling convention.

Instead, move the save/restore code to a set of macros with a defined
calling convention, taking care of all the registers in a single
location. The net result is cleaner code, and a relative independence
from the backing structure layout.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
ARM: KVM: move usr regs to struct pt_regs

Now that our world-switch is mostly layout independant, it becomes
relatively easy to move the usr_regs array to struct pt_regs.

This gives us a common abstraction with the rest of the kernel, and
makes it similar to what is being done on the arm64 side.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
ARM: KVM: unify HIFAR and HDFAR

There is strictly no reason to have two fields to describe the
faulting VA - we only get one fault at a time, and the 64bit
architecture unifies it for that very reason. We have to rely
on HSR to find out how to interpret the data anyway.

Squash the two fields into one, and perform the associated cleanup.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
ARM: KVM: simpify vcpu register access

The use of VCPU_*_MODE in register manipulation code is not really
necessary, and possibly costly (table lookup doesn't come for free).

Just use the normal *_MODE defines and some case statements. Also,
merge USR and SYS registers, which are architecturally indentical.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>
ARM: KVM: VGIC: fix edge vs level bugs

Fix a number of problems in the vgic code:
- Make sure edge interrupts are getting cleared as soon as they
  are on the CPU interface
- Make sure level interrupts get cleared after they get EOId.
  Also mark it pending again if the irq_state is still high.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@cs.columbia.edu>