Skip to content

Commit

Permalink
KVM: arm64: Resolve all pending PC updates before immediate exit
Browse files Browse the repository at this point in the history
commit e3e880b upstream.

Commit 26778aa ("KVM: arm64: Commit pending PC adjustemnts before
returning to userspace") fixed the PC updating issue by forcing an explicit
synchronisation of the exception state on vcpu exit to userspace.

However, we forgot to take into account the case where immediate_exit is
set by userspace and KVM_RUN will exit immediately. Fix it by resolving all
pending PC updates before returning to userspace.

Since __kvm_adjust_pc() relies on a loaded vcpu context, I moved the
immediate_exit checking right after vcpu_load(). We will get some overhead
if immediate_exit is true (which should hopefully be rare).

Fixes: 26778aa ("KVM: arm64: Commit pending PC adjustemnts before returning to userspace")
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210526141831.1662-1-yuzenghui@huawei.com
Cc: stable@vger.kernel.org # 5.11
[yuz: stable-5.12.y backport]
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Zenghui Yu authored and gregkh committed Jun 10, 2021
1 parent 830e765 commit 5a3d82d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions arch/arm64/kvm/arm.c
Expand Up @@ -715,11 +715,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
return ret;
}

if (run->immediate_exit)
return -EINTR;

vcpu_load(vcpu);

if (run->immediate_exit) {
ret = -EINTR;
goto out;
}

kvm_sigset_activate(vcpu);

ret = 1;
Expand Down Expand Up @@ -892,6 +894,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)

kvm_sigset_deactivate(vcpu);

out:
/*
* In the unlikely event that we are returning to userspace
* with pending exceptions or PC adjustment, commit these
Expand Down

0 comments on commit 5a3d82d

Please sign in to comment.