s390/vfio-ap: use proper locking order when setting/clearing KVM pointer
authorTony Krowiak <akrowiak@linux.ibm.com>
Wed, 16 Mar 2022 21:46:38 +0000 (17:46 -0400)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Tue, 19 Jul 2022 14:18:10 +0000 (16:18 +0200)
commitb84eb8e05057f6f329e28f2563668340ea14184b
treeae7a2fa14b460e6a46b8e464f812bbdea4f21f2c
parent21195eb038bcb4c21daef761e8b18f3cc9f22020
s390/vfio-ap: use proper locking order when setting/clearing KVM pointer

The group notifier that handles the VFIO_GROUP_NOTIFY_SET_KVM event must
use the required locks in proper locking order to dynamically update the
guest's APCB. The proper locking order is:

       1. matrix_dev->guests_lock: required to use the KVM pointer to
          update a KVM guest's APCB.

       2. matrix_mdev->kvm->lock: required to update a KVM guest's APCB.

       3. matrix_dev->mdevs_lock: required to store or access the data
          stored in a struct ap_matrix_mdev instance.

Two macros are introduced to acquire and release the locks in the proper
order. These macros are now used by the group notifier functions.

Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Jason J. Herne <jjherne@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
drivers/s390/crypto/vfio_ap_ops.c