Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1211414pxb; Wed, 10 Feb 2021 03:00:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIYtjPz/c2NbZmKgdRu6A9J/VDFN9/adexpdicmlN/5L2NZDeUB60J8aADiAVclMBpGS5N X-Received: by 2002:a50:fb14:: with SMTP id d20mr2468894edq.375.1612954849022; Wed, 10 Feb 2021 03:00:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612954849; cv=none; d=google.com; s=arc-20160816; b=YQMiSg+jN2z98ZEr1BgpoQV6XOXXICRIxzefCrM8yTcoJSy5VBwMl0V/d64Txt4/hF TjCiUjPozh660qj54sFxP+45HqtfMNgneRbFK30t+k+/3VkPaN7s+mnsuUUAvzDOg+08 cBWs/FMOSTIYLHMKFiHp7G7oB8x5flnRXsoqVbrkW+ckPZJabfA0pFAYsFq+J8UaW/4y 3fxFch6upygitsg5pCtIu3zX7iMZrJ1YtkyP81Y79q3sSuNq1oGB/a7N+1FXEFjWLQsC u+4qKPrvsAaGqogUU550sL2Ud8SHvgdccSbn1YG1IMTSNS/1qAuC7gUf4Cbeq/ZVhqeQ 92pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=UEBDm7SunPwkF3BoWeRyw0Tj/EvMcHXNW6J7Hdf+1LU=; b=P0KuD//lSnSwp/NnO/u5jjk1/8NeffRy20EiewpsJgccmkwLMNAM1ztwvPtM9feCva mdt6b+x6GDoau5zr6f8NWp8VVLyB4tZxqhRBFh75ifZVVaXMCwHn184MLFrHs9bfCYd8 KEKP7V0vnA3/Dv5Myu2zK6rV+M70/oWKAL726iegKCyEfuewk1KKeGqllFXTHWF/qED6 OnvYLIXYIZMHoWcEYPRd0wDFyKOFYVPug1O3cWNhblxu4MuYL7kz49iZtCoPKiiaVRFQ tC3AUPYC6ruYLR9l52UEunwwE05iZ61iYOKecKszgA0y42FNfAMffa7C9ysxOK4WKFMv lraQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="A/FkpYPu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr22si1111542ejc.388.2021.02.10.03.00.23; Wed, 10 Feb 2021 03:00:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="A/FkpYPu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbhBJK7V (ORCPT + 99 others); Wed, 10 Feb 2021 05:59:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29030 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231553AbhBJKzL (ORCPT ); Wed, 10 Feb 2021 05:55:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612954425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UEBDm7SunPwkF3BoWeRyw0Tj/EvMcHXNW6J7Hdf+1LU=; b=A/FkpYPuv6kU7owQmlZfDS1t8XmBumYRiI/3S92uMwEgKibQlNStQmQ1xuBw0C0K7vnEWn yKMKvu4eyefNGYhmZKaVL/Rrjs+bc+uRFwV/HzcdjOrtDr0kprfF2AJEtwlh8HiF4L5G0A LU9hkWosqlGUEwYe1Y5DrdWTXeOiQt8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-121-FZDUxRX4OaKcuyzYEPpJlQ-1; Wed, 10 Feb 2021 05:53:43 -0500 X-MC-Unique: FZDUxRX4OaKcuyzYEPpJlQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B3D6107ACC7; Wed, 10 Feb 2021 10:53:42 +0000 (UTC) Received: from gondolin (ovpn-113-113.ams2.redhat.com [10.36.113.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0345C627DA; Wed, 10 Feb 2021 10:53:36 +0000 (UTC) Date: Wed, 10 Feb 2021 11:53:34 +0100 From: Cornelia Huck To: Tony Krowiak Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, stable@vger.kernel.org, borntraeger@de.ibm.com, kwankhede@nvidia.com, pbonzini@redhat.com, alex.williamson@redhat.com, pasic@linux.vnet.ibm.com Subject: Re: [PATCH 1/1] s390/vfio-ap: fix circular lockdep when setting/clearing crypto masks Message-ID: <20210210115334.46635966.cohuck@redhat.com> In-Reply-To: <20210209194830.20271-2-akrowiak@linux.ibm.com> References: <20210209194830.20271-1-akrowiak@linux.ibm.com> <20210209194830.20271-2-akrowiak@linux.ibm.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 9 Feb 2021 14:48:30 -0500 Tony Krowiak wrote: > This patch fixes a circular locking dependency in the CI introduced by > commit f21916ec4826 ("s390/vfio-ap: clean up vfio_ap resources when KVM > pointer invalidated"). The lockdep only occurs when starting a Secure > Execution guest. Crypto virtualization (vfio_ap) is not yet supported for > SE guests; however, in order to avoid CI errors, this fix is being > provided. > > The circular lockdep was introduced when the masks in the guest's APCB > were taken under the matrix_dev->lock. While the lock is definitely > needed to protect the setting/unsetting of the KVM pointer, it is not > necessarily critical for setting the masks, so this will not be done under > protection of the matrix_dev->lock. > > Fixes: f21916ec4826 ("s390/vfio-ap: clean up vfio_ap resources when KVM pointer invalidated") > Cc: stable@vger.kernel.org > Signed-off-by: Tony Krowiak > --- > drivers/s390/crypto/vfio_ap_ops.c | 75 ++++++++++++++++++------------- > 1 file changed, 45 insertions(+), 30 deletions(-) > > static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev) > { > - kvm_arch_crypto_clear_masks(matrix_mdev->kvm); > - matrix_mdev->kvm->arch.crypto.pqap_hook = NULL; > - vfio_ap_mdev_reset_queues(matrix_mdev->mdev); > - kvm_put_kvm(matrix_mdev->kvm); > - matrix_mdev->kvm = NULL; > + if (matrix_mdev->kvm) { If you're doing setting/unsetting under matrix_dev->lock, is it possible that matrix_mdev->kvm gets unset between here and the next line, as you don't hold the lock? Maybe you could - grab a reference to kvm while holding the lock - call the mask handling functions with that kvm reference - lock again, drop the reference, and do the rest of the processing? > + kvm_arch_crypto_clear_masks(matrix_mdev->kvm); > + mutex_lock(&matrix_dev->lock); > + matrix_mdev->kvm->arch.crypto.pqap_hook = NULL; > + vfio_ap_mdev_reset_queues(matrix_mdev->mdev); > + kvm_put_kvm(matrix_mdev->kvm); > + matrix_mdev->kvm = NULL; > + mutex_unlock(&matrix_dev->lock); > + } > }