Skip to content

Commit b5aa368

Browse files
author
Marc Zyngier
committed
KVM: arm64: Merge kvm_arch_vcpu_run_pid_change() and kvm_vcpu_first_run_init()
The kvm_arch_vcpu_run_pid_change() helper gets called on each PID change. The kvm_vcpu_first_run_init() helper gets run on the... first run(!) of a vcpu. As it turns out, the first run of a vcpu also triggers a PID change event (vcpu->pid is initially NULL). Use this property to merge these two helpers and get rid of another arm64-specific oddity. Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 1408e73 commit b5aa368

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

arch/arm64/kvm/arm.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -584,22 +584,34 @@ static void update_vmid(struct kvm_vmid *vmid)
584584
spin_unlock(&kvm_vmid_lock);
585585
}
586586

587-
int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)
587+
static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu)
588588
{
589-
return kvm_arch_vcpu_run_map_fp(vcpu);
589+
return vcpu->arch.target >= 0;
590590
}
591591

592-
static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)
592+
/*
593+
* Handle both the initialisation that is being done when the vcpu is
594+
* run for the first time, as well as the updates that must be
595+
* performed each time we get a new thread dealing with this vcpu.
596+
*/
597+
int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)
593598
{
594599
struct kvm *kvm = vcpu->kvm;
595-
int ret = 0;
600+
int ret;
596601

597-
if (likely(vcpu->arch.has_run_once))
598-
return 0;
602+
if (!kvm_vcpu_initialized(vcpu))
603+
return -ENOEXEC;
599604

600605
if (!kvm_arm_vcpu_is_finalized(vcpu))
601606
return -EPERM;
602607

608+
ret = kvm_arch_vcpu_run_map_fp(vcpu);
609+
if (ret)
610+
return ret;
611+
612+
if (likely(vcpu->arch.has_run_once))
613+
return 0;
614+
603615
kvm_arm_vcpu_init_debug(vcpu);
604616

605617
if (likely(irqchip_in_kernel(kvm))) {
@@ -688,11 +700,6 @@ static void vcpu_req_sleep(struct kvm_vcpu *vcpu)
688700
smp_rmb();
689701
}
690702

691-
static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu)
692-
{
693-
return vcpu->arch.target >= 0;
694-
}
695-
696703
static void check_vcpu_requests(struct kvm_vcpu *vcpu)
697704
{
698705
if (kvm_request_pending(vcpu)) {
@@ -788,13 +795,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
788795
struct kvm_run *run = vcpu->run;
789796
int ret;
790797

791-
if (unlikely(!kvm_vcpu_initialized(vcpu)))
792-
return -ENOEXEC;
793-
794-
ret = kvm_vcpu_first_run_init(vcpu);
795-
if (ret)
796-
return ret;
797-
798798
if (run->exit_reason == KVM_EXIT_MMIO) {
799799
ret = kvm_handle_mmio_return(vcpu);
800800
if (ret)

0 commit comments

Comments
 (0)