[PATCH 5/5] s390/vfio-ap: Fix resource handling for rejected AQIC enable requests
From: Jason J. Herne
Date: Thu Dec 03 2026 - 16:45:58 EST
When the guest enables interrupts, vfio_ap_irq_enable() pins the new NIB
page and registers the guest ISC, then issues PQAP(AQIC). The resources
are kept only if the hardware accepts the new NIB. Two cases are
handled wrongly:
* For any response other than NORMAL or OTHERWISE_CHANGED, the code
warned and called vfio_ap_irq_disable(). That issued PQAP(AQIC) with
ir=0 to the hardware, switching off the guest's working interrupts
even though only the new enable request had failed, and then freed
the previously saved NIB page and ISC. It also never released the
newly pinned page and registered ISC, so they leak.
* OTHERWISE_CHANGED (interrupts already enabled, or a prior
asynchronous request still completing) is not a failure, but was
logged as one.
Handle every response other than NORMAL the same way: release the newly
pinned NIB page and the newly registered ISC, and leave the previously
saved resources untouched. Do not disable interrupts in the hardware.
Log a failure only for responses other than NORMAL and
OTHERWISE_CHANGED. The status from PQAP(AQIC) is still returned to the
guest as is.
Also update the function and case comments to describe this.
Fixes: ec89b55e3bce ("s390: ap: implement PAPQ AQIC interception in kernel")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jason J. Herne <jjherne@xxxxxxxxxxxxx>
---
drivers/s390/crypto/vfio_ap_ops.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index 836551e9f65b..3a09a93c09eb 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -440,6 +440,10 @@ static int ensure_nib_shared(unsigned long addr)
* Register the guest ISC to GIB interface and retrieve the
* host ISC to issue the host side PQAP/AQIC
*
+ * The newly pinned NIB and registered ISC are saved in *q only if ap_aqic()
+ * returns AP_RESPONSE_NORMAL. Otherwise they are released and the previously
+ * saved NIB and ISC are left untouched.
+ *
* status.response_code may be set to AP_RESPONSE_INVALID_ADDRESS in case the
* vfio_pin_pages or kvm_s390_gisc_register failed.
*
@@ -524,21 +528,24 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
q->saved_isc = isc;
break;
case AP_RESPONSE_OTHERWISE_CHANGED:
- /* We could not modify IRQ settings: clear new configuration */
+ default:
+ /*
+ * We could not modify IRQ settings: release the new configuration.
+ * Keep the previously saved configuration: for most responses the
+ * queue is still operational and the hardware may still be using it.
+ * If the queue is not operational the saved resources are released
+ * by the reset/unassign/remove paths.
+ */
ret = kvm_s390_gisc_unregister(kvm, isc);
if (ret)
VFIO_AP_DBF_WARN("%s: kvm_s390_gisc_unregister: rc=%d isc=%d, apqn=%#04x\n",
__func__, ret, isc, q->apqn);
vfio_unpin_pages(&q->matrix_mdev->vdev, nib, 1);
break;
- default:
- pr_warn("%s: apqn %04x: response: %02x\n", __func__, q->apqn,
- status.response_code);
- vfio_ap_irq_disable(q);
- break;
}
- if (status.response_code != AP_RESPONSE_NORMAL) {
+ if (status.response_code != AP_RESPONSE_NORMAL &&
+ status.response_code != AP_RESPONSE_OTHERWISE_CHANGED) {
VFIO_AP_DBF_WARN("%s: PQAP(AQIC) failed with status=%#02x: "
"zone=%#x, ir=%#x, gisc=%#x, f=%#x,"
"gisa=%#x, isc=%#x, apqn=%#04x\n",
--
2.56.1