On Tue, May 25, 2021 at 11:08:22AM -0400, Tony Krowiak wrote: > > Why can't you put the locks in the right order? It looked trivial, I'm confused. > > Because the handle_pqap() function in priv.c does not have access to the > matrix_dev lock. Based on the sketch made the handle_pqap() should only handle the arch.crypto.rwsem. When it calls the hook it gets the matrix dev This sets the lock order as always: rwsem then matrix_dev Of the other two places: @@ -352,8 +352,7 @@ static int vfio_ap_mdev_create(struct mdev_device *mdev) + down_write(&&vcpu->kvm->arch.crypto.rwsem); mutex_lock(&matrix_dev->lock); Obviously correct @@ -1202,7 +1203,9 @@ static void vfio_ap_mdev_unset_kvm(struct ap_matrix_mdev *matrix_mdev) mutex_lock(&matrix_dev->lock); vfio_ap_mdev_reset_queues(matrix_mdev->mdev); + down_write(&matrix_mdev->kvm->arch.crypto.rwsem); matrix_mdev->kvm->arch.crypto.pqap_hook = NULL; + up_write(&matrix_mdev->kvm->arch.crypto.rwsem); This is inverted Just move the down_write up two lines What is missing? Jason