]> git.baikalelectronics.ru Git - kernel.git/commit
s390/vfio-ap: fix circular lockdep when setting/clearing crypto masks
authorTony Krowiak <akrowiak@linux.ibm.com>
Thu, 25 Mar 2021 12:46:40 +0000 (08:46 -0400)
committerHeiko Carstens <hca@linux.ibm.com>
Mon, 5 Apr 2021 09:30:58 +0000 (11:30 +0200)
commit54c9e970fad9e4427a307118d4b8334a7481845e
tree223392628f21ecf86362d65215a30372c3f42b51
parente15d1a2081c73f32dd6cf183ef07f35f3d49327b
s390/vfio-ap: fix circular lockdep when setting/clearing crypto masks

This patch fixes a lockdep splat introduced by commit 26e5744fec4d
("s390/vfio-ap: clean up vfio_ap resources when KVM pointer invalidated").
The lockdep splat only occurs when starting a Secure Execution guest.
Crypto virtualization (vfio_ap) is not yet supported for SE guests;
however, in order to avoid this problem when support becomes available,
this fix is being provided.

The circular locking dependency was introduced when the setting of the
masks in the guest's APCB was executed while holding the matrix_dev->lock.
While the lock is definitely needed to protect the setting/unsetting of the
matrix_mdev->kvm pointer, it is not necessarily critical for setting the
masks; so, the matrix_dev->lock will be released while the masks are being
set or cleared.

Keep in mind, however, that another process that takes the matrix_dev->lock
can get control while the masks in the guest's APCB are being set or
cleared as a result of the driver being notified that the KVM pointer
has been set or unset. This could result in invalid access to the
matrix_mdev->kvm pointer by the intervening process. To avoid this
scenario, two new fields are being added to the ap_matrix_mdev struct:

struct ap_matrix_mdev {
...
bool kvm_busy;
wait_queue_head_t wait_for_kvm;
   ...
};

The functions that handle notification that the KVM pointer value has
been set or cleared will set the kvm_busy flag to true until they are done
processing at which time they will set it to false and wake up the tasks on
the matrix_mdev->wait_for_kvm wait queue. Functions that require
access to matrix_mdev->kvm will sleep on the wait queue until they are
awakened at which time they can safely access the matrix_mdev->kvm
field.

Fixes: 26e5744fec4d ("s390/vfio-ap: clean up vfio_ap resources when KVM pointer invalidated")
Cc: stable@vger.kernel.org
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
drivers/s390/crypto/vfio_ap_ops.c
drivers/s390/crypto/vfio_ap_private.h