Re: [PATCH v1 06/11] KVM: s390: pv: usage counter instead of flag

Janosch Frank
2021-05-27T09:29:42Z

On 5/17/21 10:07 PM, Claudio Imbrenda wrote:
> Use the is_protected field as a counter instead of a flag. This will
> be used in upcoming patches.
>
> 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@linux.ibm.com>

Acked-by: Janosch Frank <frankja@linux.ibm.com>

> ---
> 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 c3f9f30d2ed4..59039b8a7be7 100644
> --- a/arch/s390/kvm/pv.c
> +++ b/arch/s390/kvm/pv.c
> @@ -218,7 +218,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 */
> @@ -259,11 +260,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;
> @@ -286,8 +290,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;
> }
>
>