Skip to content

Commit 46a7263

Browse files
Tony Krowiakborntraeger
authored andcommitted
s390: vfio-ap: zeroize the AP queues
Let's call PAPQ(ZAPQ) to zeroize a queue for each queue configured for a mediated matrix device when it is released. Zeroizing a queue resets the queue, clears all pending messages for the queue entries and disables adapter interruptions associated with the queue. Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com> Reviewed-by: Halil Pasic <pasic@linux.ibm.com> Tested-by: Michael Mueller <mimu@linux.ibm.com> Tested-by: Farhan Ali <alifm@linux.ibm.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Message-Id: <20180925231641.4954-14-akrowiak@linux.vnet.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
1 parent e06670c commit 46a7263

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

drivers/s390/crypto/vfio_ap_ops.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,54 @@ static int vfio_ap_mdev_group_notifier(struct notifier_block *nb,
819819
return NOTIFY_OK;
820820
}
821821

822+
static int vfio_ap_mdev_reset_queue(unsigned int apid, unsigned int apqi,
823+
unsigned int retry)
824+
{
825+
struct ap_queue_status status;
826+
827+
do {
828+
status = ap_zapq(AP_MKQID(apid, apqi));
829+
switch (status.response_code) {
830+
case AP_RESPONSE_NORMAL:
831+
return 0;
832+
case AP_RESPONSE_RESET_IN_PROGRESS:
833+
case AP_RESPONSE_BUSY:
834+
msleep(20);
835+
break;
836+
default:
837+
/* things are really broken, give up */
838+
return -EIO;
839+
}
840+
} while (retry--);
841+
842+
return -EBUSY;
843+
}
844+
845+
static int vfio_ap_mdev_reset_queues(struct mdev_device *mdev)
846+
{
847+
int ret;
848+
int rc = 0;
849+
unsigned long apid, apqi;
850+
struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
851+
852+
for_each_set_bit_inv(apid, matrix_mdev->matrix.apm,
853+
matrix_mdev->matrix.apm_max + 1) {
854+
for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm,
855+
matrix_mdev->matrix.aqm_max + 1) {
856+
ret = vfio_ap_mdev_reset_queue(apid, apqi, 1);
857+
/*
858+
* Regardless whether a queue turns out to be busy, or
859+
* is not operational, we need to continue resetting
860+
* the remaining queues.
861+
*/
862+
if (ret)
863+
rc = ret;
864+
}
865+
}
866+
867+
return rc;
868+
}
869+
822870
static int vfio_ap_mdev_open(struct mdev_device *mdev)
823871
{
824872
struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev);
@@ -849,6 +897,7 @@ static void vfio_ap_mdev_release(struct mdev_device *mdev)
849897
if (matrix_mdev->kvm)
850898
kvm_arch_crypto_clear_masks(matrix_mdev->kvm);
851899

900+
vfio_ap_mdev_reset_queues(mdev);
852901
vfio_unregister_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
853902
&matrix_mdev->group_notifier);
854903
matrix_mdev->kvm = NULL;

0 commit comments

Comments
 (0)