Skip to content

Commit 5ff9218

Browse files
author
Claudio Imbrenda
committed
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: fb491d5 ("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>
1 parent fdf0eaf commit 5ff9218

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/s390/kvm/pv.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,12 @@ int kvm_s390_pv_deinit_cleanup_all(struct kvm *kvm, u16 *rc, u16 *rrc)
411411
u16 _rc, _rrc;
412412
int cc = 0;
413413

414-
/* Make sure the counter does not reach 0 before calling s390_uv_destroy_range */
415-
atomic_inc(&kvm->mm->context.protected_count);
414+
/*
415+
* Nothing to do if the counter was already 0. Otherwise make sure
416+
* the counter does not reach 0 before calling s390_uv_destroy_range.
417+
*/
418+
if (!atomic_inc_not_zero(&kvm->mm->context.protected_count))
419+
return 0;
416420

417421
*rc = 1;
418422
/* If the current VM is protected, destroy it */

0 commit comments

Comments
 (0)