Commit df6384e0 authored by Paul Mackerras's avatar Paul Mackerras Committed by Greg Kroah-Hartman
Browse files

KVM: PPC: Book3S HV: Don't take kvm->lock around kvm_for_each_vcpu

[ Upstream commit 5a3f4936


Currently the HV KVM code takes the kvm->lock around calls to
kvm_for_each_vcpu() and kvm_get_vcpu_by_id() (which can call
kvm_for_each_vcpu() internally).  However, that leads to a lock
order inversion problem, because these are called in contexts where
the vcpu mutex is held, but the vcpu mutexes nest within kvm->lock
according to Documentation/virtual/kvm/locking.txt.  Hence there
is a possibility of deadlock.

To fix this, we simply don't take the kvm->lock mutex around these
calls.  This is safe because the implementations of kvm_for_each_vcpu()
and kvm_get_vcpu_by_id() have been designed to be able to be called
Signed-off-by: default avatarPaul Mackerras <>
Reviewed-by: default avatarCédric Le Goater <>
Signed-off-by: default avatarPaul Mackerras <>
Signed-off-by: default avatarSasha Levin <>
parent b376683f
......@@ -426,12 +426,7 @@ static void kvmppc_dump_regs(struct kvm_vcpu *vcpu)
static struct kvm_vcpu *kvmppc_find_vcpu(struct kvm *kvm, int id)
struct kvm_vcpu *ret;
ret = kvm_get_vcpu_by_id(kvm, id);
return ret;
return kvm_get_vcpu_by_id(kvm, id);
static void init_vpa(struct kvm_vcpu *vcpu, struct lppaca *vpa)
......@@ -1309,7 +1304,6 @@ static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, u64 new_lpcr,
struct kvmppc_vcore *vc = vcpu->arch.vcore;
u64 mask;
* If ILE (interrupt little-endian) has changed, update the
......@@ -1349,7 +1343,6 @@ static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, u64 new_lpcr,
mask &= 0xFFFFFFFF;
vc->lpcr = (vc->lpcr & ~mask) | (new_lpcr & mask);
static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment