From: Joerg Roedel <[email protected]> Introduce an array which keeps track of per-plane VCPU instances for a single VCPU index. This is a short-cut to not always tranverse the xarrays on plane switches.
Signed-off-by: Joerg Roedel <[email protected]> --- include/linux/kvm_host.h | 6 ++++++ virt/kvm/kvm_main.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index b8c3f8f11cb4..5c3f9dfa15ea 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -335,6 +335,8 @@ struct kvm_vcpu_common { /* Currently active VCPU */ struct kvm_vcpu *current_vcpu; + struct kvm_vcpu *vcpus[KVM_MAX_PLANES]; + /* Locks */ int ____srcu_idx; /* Don't use this directly. You've been warned. */ #ifdef CONFIG_PROVE_RCU @@ -382,6 +384,10 @@ struct kvm_vcpu_common { struct kvm_vcpu_arch_common arch; }; +#define vcpu_for_each_plane(common, i, v) \ + for ((i) = 0; (i) < KVM_MAX_PLANES; ++(i)) \ + if (((v) = common->vcpus[(i)]) != NULL) + struct kvm_vcpu { struct kvm *kvm; struct kvm_plane *plane; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 8839f91fd15e..9d30fd85ce5f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -524,6 +524,8 @@ static int kvm_vcpu_init_common(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned static void kvm_vcpu_finish_common(struct kvm_vcpu *vcpu) { + WARN_ON(vcpu->common->vcpus[vcpu->plane_level] != NULL); + vcpu->common->vcpus[vcpu->plane_level] = vcpu; smp_wmb(); if (vcpu->plane_level == 0) { /* @@ -555,6 +557,7 @@ static void kvm_vcpu_common_destroy(struct kvm_vcpu *vcpu) vcpu->common = NULL; vcpu->run = NULL; + common->vcpus[vcpu->plane_level] = NULL; if (vcpu->plane_level != 0) return; -- 2.53.0
