ARM: arndale: Update kvm config

Update the defconfig to actually work with smp and build a kernel that
can be used as both host and guest.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Fix build file to support separate obj directory

The build system needs this extra level of indirection, for whatever
reason.

Reported-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
Merge remote-tracking branch 'columbia/kvm-arm-master' into lue_arndale-kvm
ARM: KVM: vgic: fix kvm_vgic_vcpu_init() return value

Patch 641622d2 (KVM: ARM: Make VGIC_MAX_CPUS equal to KVM_MAX_VCPUS)
must have been tested with a very forgiving compiler, as it lacks
a return value in the normal path...

Also fix the non-vgic case, which has a different taste of brokeness.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: vgic: don't rely on vgic_hcr default value

Do not "or" vgic_hcr with VGIC_HCR_EN, just assign it.
There should be nothing we care about in there.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: vgic: fix distributor irq_cfg register accessors

The irq_cfg accessors are not properly masking top bits when
compressing/expanding the value.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: vgic: sanitize use of bitmaps

Various bits of the vgic code blindly assume that the size of u32
and unsigned long are the same. This leads to amusing side effects
on 64bit platforms, and makes the code hard to follow.

Move to proper bitmaps instead of the home grown version, and split
the vcpu specific "pending" bitmap into pending_percpu and pending_shared.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: vgic: do not use elrsr when queueing an interrupt

The elrsr registers should only be used when synchronizing the
vgic state after running. It shouldn't be trusted in another
context.

Use lr_used instead, which tracks the LR allocation.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: vgic: deassert SGIs and SPIs that have already been queued

As SGIs and PPIs are treated as edge-triggered, they must be cleared
as soon as they are queued into the list registers. Otherwise, we end-up
with spurious interrupts.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
ARM: KVM: vgic: disambiguate clearing of irq_state

The irq_state bitmap describe the input state of our virtual
distributor. Calling it "pending" in __kvm_vgic_sync_to_cpu()
does not significantly help understanding the code.

Remove the local "pending" variable and use the generic accessors
instead.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Merge remote-tracking branch 'kvm-local/kvm-arm-master' into lue_arndale-kvm
KVM: ARM: Don't use set_pte_ext (a.k.a. Fix the voodoo bug!)

The set_pte_ext function orr'ed the RDONLY bit onto the PTEs, which is
bit[7], which is HAP[1] and causes writable access to the pages.

This was unfortunate.

Cc: Nicolas Viennot <nviennot@cs.columbia.edu>
Cc: Jeremy C. Andrus <jeremya@cs.columbia.edu>
Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Fixup kvm local set_pte

Rename set_pte to kvm_set_pte to avoid name conflict with more
system-wide designs, especially on arm64.

Use pte_val around the *pte assignment to compile with strict mm type
checking enabled.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Report support of mmu notifiers to user space

This should have been added a long time ago, and is at least required
for user space to take advantage of hugetlbfs.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Fixup trace ipa printing

The arguments where shifted and printed a 64 bit integer as a 32 bit
integer.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Fix VTCR and VTTBR initialization

The mask of the T0SZ in the VTSZ was incorrect.  We never used the
VTCR_MASK that we define, and the calculation of the desired T0SZ field
was incorrect.  There is no need to save that single page for the
stage-2 PGD, so let's just support the full 40-bit input address space
to the stage-2 translation.

Also move the memory defines from kvm_mmu.h to kvm_arm.h to have a
single place where we define both the VTCR constants and the
corresponding physical memory size defines needed.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Convert stage2_clear_pte to unmap_stage2_range

Factor out parts of the functionality to make the code more readable and
rename to unmap_stage2_range while supporting unmapping ranges in one
go.  This paves the road for reusing this function to free the stage 2
page tables when destroying a VM; avoiding code duplication of all the
page refcounting on the page table pages themselves.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
KVM: ARM: Reuse unmap_stage2_range for kvm_free_stage2_pgd

kvm_free_stage2_pgd and its child functions perform the exact same job
as unmap_stage2_range, just assuming the entire range needs to be
unmapped.  Therefore, turn kvm_free_stage2_pgd into a call to
unmap_stage2_range that covers the entire physical memory space.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
Merge remote-tracking branch 'kvm-local/kvm-arm-master' into lue_arndale-kvm