android_kernel_samsung_msm8976/arch/arm/kvm
Marc Zyngier aeea6f0c5d KVM: arm/arm64: Close VMID generation race
commit f0cf47d939d0b4b4f660c5aaa4276fa3488f3391 upstream.

Before entering the guest, we check whether our VMID is still
part of the current generation. In order to avoid taking a lock,
we start with checking that the generation is still current, and
only if not current do we take the lock, recheck, and update the
generation and VMID.

This leaves open a small race: A vcpu can bump up the global
generation number as well as the VM's, but has not updated
the VMID itself yet.

At that point another vcpu from the same VM comes in, checks
the generation (and finds it not needing anything), and jumps
into the guest. At this point, we end-up with two vcpus belonging
to the same VM running with two different VMIDs. Eventually, the
VMID used by the second vcpu will get reassigned, and things will
really go wrong...

A simple solution would be to drop this initial check, and always take
the lock. This is likely to cause performance issues. A middle ground
is to convert the spinlock to a rwlock, and only take the read lock
on the fast path. If the check fails at that point, drop it and
acquire the write lock, rechecking the condition.

This ensures that the above scenario doesn't occur.

Reported-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Shannon Zhao <zhaoshenglong@huawei.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
[bwh: Backported to 3.16: adjust filename, context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
2019-07-27 21:52:17 +02:00
..
Kconfig
Makefile
arm.c KVM: arm/arm64: Close VMID generation race 2019-07-27 21:52:17 +02:00
coproc.c
coproc.h
coproc_a15.c
emulate.c
guest.c
handle_exit.c ARM/ARM64: KVM: Make kvm_psci_call() return convention more flexible 2014-08-15 11:45:45 -07:00
init.S
interrupts.S This is the 3.10.84 stable release 2015-09-30 13:25:40 +05:30
interrupts_head.S arm: KVM: force execution of HCPTR access on VM exit 2015-07-10 10:40:21 -07:00
mmio.c
mmu.c arm64: KVM: flush VM pages before letting the guest enable caches 2014-08-15 11:41:27 -07:00
perf.c
psci.c ARM/ARM64: KVM: Make kvm_psci_call() return convention more flexible 2014-08-15 11:45:45 -07:00
reset.c
trace.h