Am 18.08.21 um 15:26 schrieb Claudio Imbrenda: > Use the is_protected field as a counter instead of a flag. This will > be used in upcoming patches. Maybe it should also be renamed to reflect that? > > Increment the counter when a secure configuration is created, and > decrement it when it is destroyed. Previously the flag was set when the > set secure parameters UVC was performed. > > Signed-off-by: Claudio Imbrenda <imbrenda@xxxxxxxxxxxxx> > Acked-by: Janosch Frank <frankja@xxxxxxxxxxxxx> > --- > arch/s390/kvm/pv.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c > index 47db80003ea0..ee11ff6afc4f 100644 > --- a/arch/s390/kvm/pv.c > +++ b/arch/s390/kvm/pv.c > @@ -173,7 +173,8 @@ int kvm_s390_pv_deinit_vm(struct kvm *kvm, u16 *rc, u16 *rrc) > cc = uv_cmd_nodata(kvm_s390_pv_get_handle(kvm), > UVC_CMD_DESTROY_SEC_CONF, rc, rrc); > WRITE_ONCE(kvm->arch.gmap->guest_handle, 0); > - atomic_set(&kvm->mm->context.is_protected, 0); > + if (!cc) > + atomic_dec(&kvm->mm->context.is_protected); > KVM_UV_EVENT(kvm, 3, "PROTVIRT DESTROY VM: rc %x rrc %x", *rc, *rrc); > WARN_ONCE(cc, "protvirt destroy vm failed rc %x rrc %x", *rc, *rrc); > /* Intended memory leak on "impossible" error */ > @@ -214,11 +215,14 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc) > /* Outputs */ > kvm->arch.pv.handle = uvcb.guest_handle; > > + atomic_inc(&kvm->mm->context.is_protected); > if (cc) { > - if (uvcb.header.rc & UVC_RC_NEED_DESTROY) > + if (uvcb.header.rc & UVC_RC_NEED_DESTROY) { > kvm_s390_pv_deinit_vm(kvm, &dummy, &dummy); > - else > + } else { > + atomic_dec(&kvm->mm->context.is_protected); > kvm_s390_pv_dealloc_vm(kvm); > + } > return -EIO; > } > kvm->arch.gmap->guest_handle = uvcb.guest_handle; > @@ -241,8 +245,6 @@ int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc, > *rrc = uvcb.header.rrc; > KVM_UV_EVENT(kvm, 3, "PROTVIRT VM SET PARMS: rc %x rrc %x", > *rc, *rrc); > - if (!cc) > - atomic_set(&kvm->mm->context.is_protected, 1); > return cc ? -EINVAL : 0; > } >