summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorClaudio Imbrenda <imbrenda@linux.ibm.com>2023-07-05 14:19:36 +0300
committerClaudio Imbrenda <imbrenda@linux.ibm.com>2023-07-18 12:21:51 +0300
commit5ff92181577a89ed12ad4e0e5813751faf16a139 (patch)
tree473e3642300005f46841a559417d39cabdf9ca04 /arch
parentfdf0eaf11452d72945af31804e2a1048ee1b574c (diff)
downloadlinux-5ff92181577a89ed12ad4e0e5813751faf16a139.tar.xz
KVM: s390: pv: simplify shutdown and fix race
Simplify the shutdown of non-protected VMs. There is no need to do complex manipulations of the counter if it was zero. This also fixes a very rare race which caused pages to be torn down from the address space with a non-zero counter even on older machines that don't support the UVC instruction, causing a crash. Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com> Fixes: fb491d5500a7 ("KVM: s390: pv: asynchronous destroy for reboot") Reviewed-by: Nico Boehr <nrb@linux.ibm.com> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20230705111937.33472-2-imbrenda@linux.ibm.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/s390/kvm/pv.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c
index 2f34c7c3c5ab..bf1fdc7bf89e 100644
--- a/arch/s390/kvm/pv.c
+++ b/arch/s390/kvm/pv.c
@@ -411,8 +411,12 @@ int kvm_s390_pv_deinit_cleanup_all(struct kvm *kvm, u16 *rc, u16 *rrc)
u16 _rc, _rrc;
int cc = 0;
- /* Make sure the counter does not reach 0 before calling s390_uv_destroy_range */
- atomic_inc(&kvm->mm->context.protected_count);
+ /*
+ * Nothing to do if the counter was already 0. Otherwise make sure
+ * the counter does not reach 0 before calling s390_uv_destroy_range.
+ */
+ if (!atomic_inc_not_zero(&kvm->mm->context.protected_count))
+ return 0;
*rc = 1;
/* If the current VM is protected, destroy it */