s390/vfio-ap: clean up irq resources if possible
authorTony Krowiak <akrowiak@linux.ibm.com>
Tue, 15 Aug 2023 18:43:23 +0000 (14:43 -0400)
committerHeiko Carstens <hca@linux.ibm.com>
Fri, 18 Aug 2023 13:09:28 +0000 (15:09 +0200)
The architecture does not specify whether interrupts are disabled as part
of the asynchronous reset or upon return from the PQAP/ZAPQ instruction.
If, however, PQAP/ZAPQ completes with APQSW response code 0 and the
interrupt bit in the status word is also 0, we know the interrupts are
disabled and we can go ahead and clean up the corresponding resources;
otherwise, we must wait until the asynchronous reset has completed.

Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
Suggested-by: Halil Pasic <pasic@linux.ibm.com>
Reviewed-by: Jason J. Herne <jjherne@linux.ibm.com>
Acked-by: Halil Pasic <pasic@linux.ibm.com>
Acked-by: Janosch Frank <frankja@linux.ibm.com>
Tested-by: Viktor Mihajlovski <mihajlov@linux.ibm.com>
Link: https://lore.kernel.org/r/20230815184333.6554-3-akrowiak@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
drivers/s390/crypto/vfio_ap_ops.c

index 3fd8053..be92ba4 100644 (file)
@@ -1654,9 +1654,13 @@ retry_zapq:
        switch (status.response_code) {
        case AP_RESPONSE_NORMAL:
                ret = 0;
-               /* if the reset has not completed, wait for it to take effect */
-               if (!status.queue_empty || status.irq_enabled)
+               if (!status.irq_enabled)
+                       vfio_ap_free_aqic_resources(q);
+               if (!status.queue_empty || status.irq_enabled) {
                        ret = apq_reset_check(q);
+                       if (status.irq_enabled && ret == 0)
+                               vfio_ap_free_aqic_resources(q);
+               }
                break;
        case AP_RESPONSE_RESET_IN_PROGRESS:
                /*
@@ -1675,6 +1679,7 @@ retry_zapq:
                 * completed successfully.
                 */
                ret = 0;
+               vfio_ap_free_aqic_resources(q);
                break;
        default:
                WARN(true,
@@ -1684,8 +1689,6 @@ retry_zapq:
                return -EIO;
        }
 
-       vfio_ap_free_aqic_resources(q);
-
        return ret;
 }