[PATCH 2/5] s390/vfio-ap: bound the wait for queue reset verification

From: Jason J. Herne

Date: Thu Dec 03 2026 - 16:45:43 EST


apq_reset_check() TAPQ polls the queue until reset/zeroize is confirmed.
Commit dd174833e44e ("s390/vfio-ap: remove upper limit on wait for queue
reset to complete") removed the time limit, because the architecture
defines no upper bound for a RAPQ/ZAPQ and giving up early and freeing the
AQIC resources could let a still-active queue write to a reused NIB page.

That left the loop with no exit if the reset never completes. This can
happen when TAPQ keeps returning a busy/reset-in-progress response, or
when the ZAPQ is repeatedly rejected with reset-in-progress or
state-change-in-progress (or the queue keeps reporting an asynchronous
association failure) and is reissued on every pass. The work item then
spins forever, and anything that flushes it, such as
vfio_ap_mdev_reset_queues() and vfio_ap_mdev_reset_qlist(), waits
forever with it.

Give up after 2 seconds. A timeout does not confirm the queue was
reset, so do not free the AQIC resources, which leaks the pinned NIB page
rather than risk a write to memory that has been reused.
Record the last TAPQ status in q->reset_status, substituting
AP_RESPONSE_BUSY if it was AP_RESPONSE_NORMAL, so the queue is not
considered passable and the reset callers report -EIO.

This keeps the original safety property (never free resources for a queue
whose reset is unconfirmed) while removing the hang.

Fixes: dd174833e44e ("s390/vfio-ap: remove upper limit on wait for queue reset to complete")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jason J. Herne <jjherne@xxxxxxxxxxxxx>
---
drivers/s390/crypto/vfio_ap_ops.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index 10430b9446db..fba6f256ce77 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -31,6 +31,7 @@
#define AP_QUEUE_IN_USE "in use"

#define AP_RESET_INTERVAL 20 /* Reset sleep interval (20ms) */
+#define VFIOAP_RESET_TIMEOUT 2000 /* Max wait for reset to complete (2s) */

static int vfio_ap_mdev_reset_queues(struct ap_matrix_mdev *matrix_mdev);
static int vfio_ap_mdev_reset_qlist(struct list_head *qlist);
@@ -1974,6 +1975,20 @@ static void apq_reset_check(struct work_struct *reset_work)
q = container_of(reset_work, struct vfio_ap_queue, reset_work);
memcpy(&status, &q->reset_status, sizeof(status));
while (true) {
+ if (elapsed >= VFIOAP_RESET_TIMEOUT) {
+ /*
+ * Reset timed out. The queue could still be active so
+ * leak AQIC resources rather than risk wild DMA write.
+ */
+ pr_warn_ratelimited("Reset timed out for APQN %02x.%04x: leaking NIB page to prevent host crash\n",
+ AP_QID_CARD(q->apqn),
+ AP_QID_QUEUE(q->apqn));
+ memcpy(&q->reset_status, &status, sizeof(status));
+ if (!q->reset_status.response_code)
+ /* Record BUSY status so queue is not passable. */
+ q->reset_status.response_code = AP_RESPONSE_BUSY;
+ return;
+ }
msleep(AP_RESET_INTERVAL);
elapsed += AP_RESET_INTERVAL;
status = ap_tapq(q->apqn, NULL);
--
2.56.1