diff options
author | Alexandru Elisei <alexandru.elisei@arm.com> | 2020-12-01 15:01:55 +0000 |
---|---|---|
committer | Marc Zyngier <maz@kernel.org> | 2020-12-23 16:43:43 +0000 |
commit | 1c91f06d296de4f0c27022f5ec464e047d471215 (patch) | |
tree | 9d5d68d11401d3e21dcbe548f9176a4ffa6dc619 /arch/arm64/kvm/arm.c | |
parent | f16570ba47ff2b3766ebeaba6f4b80ad48cfd6a1 (diff) | |
download | linux-1c91f06d296de4f0c27022f5ec464e047d471215.tar.gz linux-1c91f06d296de4f0c27022f5ec464e047d471215.tar.bz2 linux-1c91f06d296de4f0c27022f5ec464e047d471215.zip |
KVM: arm64: Move double-checked lock to kvm_vgic_map_resources()
kvm_vgic_map_resources() is called when a VCPU if first run and it maps all
the VGIC MMIO regions. To prevent double-initialization, the VGIC uses the
ready variable to keep track of the state of resources and the global KVM
mutex to protect against concurrent accesses. After the lock is taken, the
variable is checked again in case another VCPU took the lock between the
current VCPU reading ready equals false and taking the lock.
The double-checked lock pattern is spread across four different functions:
in kvm_vcpu_first_run_init(), in kvm_vgic_map_resource() and in
vgic_{v2,v3}_map_resources(), which makes it hard to reason about and
introduces minor code duplication. Consolidate the checks in
kvm_vgic_map_resources(), where the lock is taken.
No functional change intended.
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20201201150157.223625-4-alexandru.elisei@arm.com
Diffstat (limited to 'arch/arm64/kvm/arm.c')
-rw-r--r-- | arch/arm64/kvm/arm.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index e207e4541f55..ab782c480e9a 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -580,11 +580,9 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) * Map the VGIC hardware resources before running a vcpu the * first time on this VM. */ - if (unlikely(!vgic_ready(kvm))) { - ret = kvm_vgic_map_resources(kvm); - if (ret) - return ret; - } + ret = kvm_vgic_map_resources(kvm); + if (ret) + return ret; } else { /* * Tell the rest of the code that there are userspace irqchip |