Re: [PATCH v1 6/7] vfio: ap: register guest ISC with GISA and GIB

From: Pierre Morel
Date: Wed Nov 07 2018 - 17:40:53 EST


On 06/11/2018 21:21, Tony Krowiak wrote:
On 10/31/18 2:12 PM, Pierre Morel wrote:
Register to the GIB Alert list and retrieve the GAL_ISC
to pass to the GISA registration.

Unregister on error and when clearing the interrupt.

Signed-off-by: Pierre Morel <pmorel@xxxxxxxxxxxxx>
Signed-off-by: Michael Mueller <mimu@xxxxxxxxxxxxx>
---
 drivers/s390/crypto/vfio_ap_ops.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index f68102163bf4..232168797fb8 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -903,16 +903,20 @@ static int ap_ioctl_setirq(struct ap_matrix_mdev *matrix_mdev,
ÂÂÂÂÂ struct ap_status ap_status = reg2status(0);
ÂÂÂÂÂ unsigned long p;
ÂÂÂÂÂ int ret = -1;
-ÂÂÂ int apqn;
+ÂÂÂ int apqn, gal_isc;
ÂÂÂÂÂ uint32_t gd;
+ÂÂÂ gal_isc = kvm_s390_gisc_register(matrix_mdev->kvm, matrix_mdev->gisc);
+ÂÂÂ if (gal_isc < 0)
+ÂÂÂÂÂÂÂ return -EIO;
+
ÂÂÂÂÂ apqn = (int)(parm->cmd & 0xffff);
ÂÂÂÂÂ gd = matrix_mdev->kvm->vcpus[0]->arch.sie_block->gd;
ÂÂÂÂÂ if (gd & 0x01)
ÂÂÂÂÂÂÂÂÂ aqic_gisa.f = 1;
ÂÂÂÂÂ aqic_gisa.gisc = matrix_mdev->gisc;
-ÂÂÂ aqic_gisa.isc = GAL_ISC;
+ÂÂÂ aqic_gisa.isc = gal_isc;
ÂÂÂÂÂ aqic_gisa.ir = 1;
ÂÂÂÂÂ aqic_gisa.gisao = gisa->next_alert >> 4;
@@ -923,7 +927,11 @@ static int ap_ioctl_setirq(struct ap_matrix_mdev *matrix_mdev,
ÂÂÂÂÂ parm->status = ret;
ÂÂÂÂÂ ap_status = reg2status(ret);
-ÂÂÂ return (ap_status.rc) ? -EIO : 0;
+ÂÂÂ if (ap_status.rc) {
+ÂÂÂÂÂÂÂ kvm_s390_gisc_unregister(matrix_mdev->kvm, matrix_mdev->gisc);
+ÂÂÂÂÂÂÂ return -EIO;
+ÂÂÂ }
+ÂÂÂ return 0;
 }
 static int ap_ioctl_clrirq(struct ap_matrix_mdev *matrix_mdev,
@@ -946,6 +954,8 @@ static int ap_ioctl_clrirq(struct ap_matrix_mdev *matrix_mdev,
ÂÂÂÂÂ parm->status = retval;
ÂÂÂÂÂ ap_status = reg2status(retval);
+ÂÂÂ /* unregister the IAM from the GIB anyway! */
+ÂÂÂ kvm_s390_gisc_unregister(matrix_mdev->kvm, matrix_mdev->gisc);

The case statement in patch 4 does not set mdev->gisc, so the
presumption here is that VFIO_AP_SET_IRQ has been previously called and
has set the value for matrix_mdev->gisc. Is it possible for
VFIO_AP_CLEAR_IRQ to get invoked without a prior call to

right, I will check this.

However if the IRQ is not registered there is no problem as we will get an error when unregistering the IRQ
and unregistering the gisc 0 which was not registered will fail too.

But I think we better check before in case these functions change.

VFIO_AP_SET_IRQ? In any case, shouldn't the GISC value be taken from
bits 61-63 of 'parm'?

No this is not possible, the ISC field is not relevant when clearing interrupts.


ÂÂÂÂÂ return (ap_status.rc) ? -EIO : 0;
 }




--
Pierre Morel
Linux/KVM/QEMU in BÃblingen - Germany