* [PATCH 1/5] s390/vfio-ap: Prevent passing unreset queues
2026-12-03 21:45 [PATCH 0/5] s390/vfio-ap: Fixes for queue reset and AQIC handling Jason J. Herne
@ 2026-12-03 21:45 ` Jason J. Herne
2026-12-03 21:45 ` [PATCH 2/5] s390/vfio-ap: bound the wait for queue reset verification Jason J. Herne
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Jason J. Herne @ 2026-12-03 21:45 UTC (permalink / raw)
To: linux-s390
Cc: linux-kernel, akrowiak, borntraeger, agordeev, gor, hca,
mjrosato, frankja, imbrenda, jrossi, stable
vfio_ap_mdev_reset_queues() and _queue_passable() use q->reset_status
to decide whether a queue was reset and may be passed to a guest.
apq_reset_check() can leave the status from the initial ZAPQ (usually
AP_RESPONSE_NORMAL) in place when the reset is not confirmed, so an
unreset queue looks reset. Fix the cases where this happens:
- TAPQ returns an invalid response code (-EIO), or
AP_RESPONSE_Q_NOT_AVAIL (-ENODEV, e.g. ZAPQ rc 00 then TAPQ rc 01):
the worker returns without saving the TAPQ status. Save it. In the
-EIO case the AQIC resources are still intentionally leaked, since
it is unknown whether the queue can still write to the NIB. Not
saving the status on -EIO predates the DECONFIGURED and
CHECKSTOPPED handling below.
- AP_RESPONSE_DECONFIGURED and AP_RESPONSE_CHECKSTOPPED are treated
as success by apq_status_check(), but neither confirms a zeroize:
all status bits are zero for these codes and a checkstop resets the
queue rather than zeroizing it. Return -ENODEV for them so the
worker frees the AQIC resources (the queue can no longer write to
the NIB) and saves the status.
Make _queue_passable() accept only AP_RESPONSE_NORMAL, so deconfigured
and checkstopped queues are no longer passed to a guest. This drops
the earlier policy of passing such queues through to avoid possible
data leaks.
Fixes: c51f8c6bb5c8 ("s390/vfio-ap: allow deconfigured queue to be passed through to a guest")
Fixes: dd174833e44e ("s390/vfio-ap: remove upper limit on wait for queue reset to complete")
Fixes: a681226c675c ("s390/vfio-ap: handle hardware checkstop state on queue reset operation")
Cc: stable@vger.kernel.org
Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
---
drivers/s390/crypto/vfio_ap_ops.c | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index 373ce574c431..10430b9446db 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -694,8 +694,6 @@ static bool _queue_passable(struct vfio_ap_queue *q)
switch (q->reset_status.response_code) {
case AP_RESPONSE_NORMAL:
- case AP_RESPONSE_DECONFIGURED:
- case AP_RESPONSE_CHECKSTOPPED:
return true;
default:
return false;
@@ -1927,9 +1925,20 @@ static int apq_status_check(int apqn, struct ap_queue_status *status)
{
switch (status->response_code) {
case AP_RESPONSE_NORMAL:
+ /* TAPQ => AP_RESPONSE_NORMAL means reset/zero complete. */
+ return 0;
case AP_RESPONSE_DECONFIGURED:
case AP_RESPONSE_CHECKSTOPPED:
- return 0;
+ /*
+ * The queue is non-operational: interrupts are not possible so
+ * AQIC resources can be safely freed. However, zeroization
+ * cannot be confirmed because all status bits are zeroed when
+ * these response codes are returned. There is no way to
+ * distinguish a zeroized queue from one that has not been
+ * zeroized. Return -ENODEV to signal that AQIC resources should
+ * be freed but that zeroization has not been confirmed.
+ */
+ return -ENODEV;
case AP_RESPONSE_RESET_IN_PROGRESS:
case AP_RESPONSE_BUSY:
return -EBUSY;
@@ -1969,9 +1978,19 @@ static void apq_reset_check(struct work_struct *reset_work)
elapsed += AP_RESET_INTERVAL;
status = ap_tapq(q->apqn, NULL);
ret = apq_status_check(q->apqn, &status);
- if (ret == -EIO)
+ if (ret == -EIO) {
+ /*
+ * Invalid TAPQ response code. It is unknown whether the
+ * queue can still write to the NIB, so leak the AQIC
+ * resources rather than let the NIB page be reused.
+ * Record the status so the queue is not passable.
+ */
+ memcpy(&q->reset_status, &status, sizeof(status));
return;
+ }
if (ret == -ENODEV) {
+ /* Record the status so the queue is not passable. */
+ memcpy(&q->reset_status, &status, sizeof(status));
vfio_ap_free_aqic_resources(q);
return;
}
--
2.56.1
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 2/5] s390/vfio-ap: bound the wait for queue reset verification
2026-12-03 21:45 [PATCH 0/5] s390/vfio-ap: Fixes for queue reset and AQIC handling Jason J. Herne
2026-12-03 21:45 ` [PATCH 1/5] s390/vfio-ap: Prevent passing unreset queues Jason J. Herne
@ 2026-12-03 21:45 ` Jason J. Herne
2026-12-03 21:45 ` [PATCH 3/5] s390/vfio-ap: Hold a private NIB page reference when a reset is unconfirmed Jason J. Herne
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Jason J. Herne @ 2026-12-03 21:45 UTC (permalink / raw)
To: linux-s390
Cc: linux-kernel, akrowiak, borntraeger, agordeev, gor, hca,
mjrosato, frankja, imbrenda, jrossi, stable
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@vger.kernel.org
Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
---
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
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 3/5] s390/vfio-ap: Hold a private NIB page reference when a reset is unconfirmed
2026-12-03 21:45 [PATCH 0/5] s390/vfio-ap: Fixes for queue reset and AQIC handling Jason J. Herne
2026-12-03 21:45 ` [PATCH 1/5] s390/vfio-ap: Prevent passing unreset queues Jason J. Herne
2026-12-03 21:45 ` [PATCH 2/5] s390/vfio-ap: bound the wait for queue reset verification Jason J. Herne
@ 2026-12-03 21:45 ` Jason J. Herne
2026-12-03 21:45 ` [PATCH 4/5] s390/vfio-ap: clear matrix_mdev link for queues not reset on unassign Jason J. Herne
2026-12-03 21:45 ` [PATCH 5/5] s390/vfio-ap: Fix resource handling for rejected AQIC enable requests Jason J. Herne
4 siblings, 0 replies; 6+ messages in thread
From: Jason J. Herne @ 2026-12-03 21:45 UTC (permalink / raw)
To: linux-s390
Cc: linux-kernel, akrowiak, borntraeger, agordeev, gor, hca,
mjrosato, frankja, imbrenda, jrossi, stable
When a queue reset times out or returns an unrecognized TAPQ or ZAPQ
response, the hardware may still write to the NIB. Previous behavior
left the NIB pinned in VFIO to protect the page, but VFIO requires
drivers to unpin on a DMA unmap callback. The pin is also orphaned when
the queue is freed. A later VFIO_IOMMU_UNMAP_DMA of that range then makes
type1 loop until BUG_ON(++retries > 10), which panics the host if
panic_on_oops is set or hangs the container otherwise.
Take a reference of our own on the NIB page before unpinning it from
VFIO, and never drop it. VFIO gets its unpin, and the page cannot be
freed and reused while the hardware might still write to it. The cost is a
leaked page (the whole folio if the page is part of a large one) per
distinct NIB on an unconfirmed reset.
Use this in apq_reset_check() for the timeout and invalid-TAPQ-response
cases that previously skipped the free. Also use it in
vfio_ap_mdev_reset_queue() for an invalid ZAPQ response. That case queues
no reset work and previously left the NIB pinned, so the pin was orphaned
when vfio_ap_mdev_remove_queue() freed the queue.
Also use it in vfio_ap_irq_disable() when AQIC still returns BUSY or
RESET_IN_PROGRESS after the last retry. That path used to free the
resources, including the unpin, even though interruption may still be
enabled.
Fixes: ec89b55e3bce ("s390: ap: implement PAPQ AQIC interception in kernel")
Cc: stable@vger.kernel.org # 6.6.x
Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
---
drivers/s390/crypto/vfio_ap_ops.c | 45 +++++++++++++++++++++++----
drivers/s390/crypto/vfio_ap_private.h | 2 ++
2 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index fba6f256ce77..d460337e365f 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -272,7 +272,7 @@ static void vfio_ap_wait_for_irqclear(int apqn)
*
* Unregisters the ISC in the GIB when the saved ISC not invalid.
* Unpins the guest's page holding the NIB when it exists.
- * Resets the saved_iova and saved_isc to invalid values.
+ * Resets saved_iova, saved_isc, saved_page.
*/
static void vfio_ap_free_aqic_resources(struct vfio_ap_queue *q)
{
@@ -286,9 +286,32 @@ static void vfio_ap_free_aqic_resources(struct vfio_ap_queue *q)
if (q->saved_iova && !WARN_ON(!q->matrix_mdev)) {
vfio_unpin_pages(&q->matrix_mdev->vdev, q->saved_iova, 1);
q->saved_iova = 0;
+ q->saved_page = NULL;
}
}
+/**
+ * vfio_ap_leak_aqic_resources - release the AQIC resources of a queue that may
+ * still be able to store to the NIB
+ * @q: The vfio_ap_queue
+ *
+ * VFIO requires the driver to unpin pages when it is told to invalidate a DMA
+ * mapping, so the NIB page cannot stay pinned by VFIO. Take a reference of our
+ * own on the page before it is unpinned and never drop it. The page can then
+ * not be freed and reused for something else while the queue may still write
+ * to it. This leaks the page (the whole folio if it is a large one).
+ */
+static void vfio_ap_leak_aqic_resources(struct vfio_ap_queue *q)
+{
+ if (q->saved_page) {
+ pr_warn_ratelimited("vfio_ap: APQN %02x.%04x: leaking NIB page to prevent reuse while the queue may still write to it\n",
+ AP_QID_CARD(q->apqn), AP_QID_QUEUE(q->apqn));
+ get_page(q->saved_page);
+ q->saved_page = NULL;
+ }
+ vfio_ap_free_aqic_resources(q);
+}
+
/**
* vfio_ap_irq_disable - disables and clears an ap_queue interrupt
* @q: The vfio_ap_queue
@@ -300,7 +323,9 @@ static void vfio_ap_free_aqic_resources(struct vfio_ap_queue *q)
* with the AP interrupt handling.
*
* In the case the AP is busy, or a reset is in progress,
- * retries after 20ms, up to 5 times.
+ * retries after 20ms, up to 5 times. If the queue is still busy or resetting
+ * after the last retry, the interrupt may still be enabled, so the NIB page is
+ * leaked by vfio_ap_leak_aqic_resources() instead of being released.
*
* Returns if ap_aqic function failed with invalid, deconfigured or
* checkstopped AP.
@@ -338,6 +363,8 @@ static struct ap_queue_status vfio_ap_irq_disable(struct vfio_ap_queue *q)
WARN_ONCE(1, "%s: ap_aqic status %d\n", __func__,
status.response_code);
+ vfio_ap_leak_aqic_resources(q);
+ return status;
end_free:
vfio_ap_free_aqic_resources(q);
return status;
@@ -493,6 +520,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q,
/* See if we did clear older IRQ configuration */
vfio_ap_free_aqic_resources(q);
q->saved_iova = nib;
+ q->saved_page = h_page;
q->saved_isc = isc;
break;
case AP_RESPONSE_OTHERWISE_CHANGED:
@@ -1978,15 +2006,17 @@ static void apq_reset_check(struct work_struct *reset_work)
if (elapsed >= VFIOAP_RESET_TIMEOUT) {
/*
* Reset timed out. The queue could still be active so
- * leak AQIC resources rather than risk wild DMA write.
+ * leak the NIB page rather than risk a write to memory
+ * that has been reused.
*/
- pr_warn_ratelimited("Reset timed out for APQN %02x.%04x: leaking NIB page to prevent host crash\n",
+ pr_warn_ratelimited("Reset timed out for APQN %02x.%04x\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;
+ vfio_ap_leak_aqic_resources(q);
return;
}
msleep(AP_RESET_INTERVAL);
@@ -1996,11 +2026,12 @@ static void apq_reset_check(struct work_struct *reset_work)
if (ret == -EIO) {
/*
* Invalid TAPQ response code. It is unknown whether the
- * queue can still write to the NIB, so leak the AQIC
- * resources rather than let the NIB page be reused.
+ * queue can still write to the NIB, so leak the NIB page
+ * rather than let it be reused.
* Record the status so the queue is not passable.
*/
memcpy(&q->reset_status, &status, sizeof(status));
+ vfio_ap_leak_aqic_resources(q);
return;
}
if (ret == -ENODEV) {
@@ -2060,6 +2091,8 @@ static void vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q)
"PQAP/ZAPQ for %02x.%04x failed with invalid rc=%u\n",
AP_QID_CARD(q->apqn), AP_QID_QUEUE(q->apqn),
status.response_code);
+ /* Unknown whether queue was reset, it may still write the NIB */
+ vfio_ap_leak_aqic_resources(q);
}
}
diff --git a/drivers/s390/crypto/vfio_ap_private.h b/drivers/s390/crypto/vfio_ap_private.h
index 9bff666b0b35..cd8fc1fba151 100644
--- a/drivers/s390/crypto/vfio_ap_private.h
+++ b/drivers/s390/crypto/vfio_ap_private.h
@@ -132,6 +132,7 @@ struct ap_matrix_mdev {
* vfio_ap device driver
* @matrix_mdev: the matrix mediated device
* @saved_iova: the notification indicator byte (nib) address
+ * @saved_page: the host page holding the nib while it is pinned by VFIO
* @apqn: the APQN of the AP queue device
* @saved_isc: the guest ISC registered with the GIB interface
* @mdev_qnode: allows the vfio_ap_queue struct to be added to a hashtable
@@ -143,6 +144,7 @@ struct ap_matrix_mdev {
struct vfio_ap_queue {
struct ap_matrix_mdev *matrix_mdev;
dma_addr_t saved_iova;
+ struct page *saved_page;
int apqn;
#define VFIO_AP_ISC_INVALID 0xff
unsigned char saved_isc;
--
2.56.1
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 4/5] s390/vfio-ap: clear matrix_mdev link for queues not reset on unassign
2026-12-03 21:45 [PATCH 0/5] s390/vfio-ap: Fixes for queue reset and AQIC handling Jason J. Herne
` (2 preceding siblings ...)
2026-12-03 21:45 ` [PATCH 3/5] s390/vfio-ap: Hold a private NIB page reference when a reset is unconfirmed Jason J. Herne
@ 2026-12-03 21:45 ` Jason J. Herne
2026-12-03 21:45 ` [PATCH 5/5] s390/vfio-ap: Fix resource handling for rejected AQIC enable requests Jason J. Herne
4 siblings, 0 replies; 6+ messages in thread
From: Jason J. Herne @ 2026-12-03 21:45 UTC (permalink / raw)
To: linux-s390
Cc: linux-kernel, akrowiak, borntraeger, agordeev, gor, hca,
mjrosato, frankja, imbrenda, jrossi, stable
When an adapter or domain is unassigned from a matrix mdev,
vfio_ap_mdev_unlink_adapter() and vfio_ap_mdev_unlink_domain() remove
each affected queue from the mdev's hash table. Only queues that are in
the guest's APCB are added to the reset list. A queue that was already
filtered from the APCB is unlinked but never added to that list, so
vfio_ap_unlink_mdev_fr_queue() is never called for it. Its
q->matrix_mdev keeps pointing at the mdev.
The mdev's matrix.apm/aqm no longer include the adapter or domain at
this point, so vfio_ap_mdev_unlink_fr_queues() called from
vfio_ap_mdev_remove() will not visit the queue either. When the mdev is
freed, q->matrix_mdev is left dangling. Later paths that dereference it,
such as vfio_ap_mdev_remove_queue(), can then access freed memory.
Clear the link for these queues in an else branch. Queues that are added
to the reset list keep their link until the reset completes, as before.
Clearing the link has a side effect. vfio_ap_free_aqic_resources()
needs q->matrix_mdev to unpin the NIB page and unregister the ISC, and
vfio_ap_mdev_remove_queue() calls it for queues that are no longer in
the host's AP configuration. Such a queue can still hold AQIC resources.
This happens when the adapter or domain is removed from the host
configuration while a guest is using AP interrupts. That path only
clears the shadow APCB bits and does not reset the queue. If the
adapter or domain is then unassigned before the AP bus removes the
queue device, the link is cleared first. The later cleanup hits
WARN_ON(!q->matrix_mdev) and leaks the pinned page and the ISC
registration.
A queue outside the host configuration is deconfigured, so it cannot
write to the NIB. Release its AQIC resources before clearing the link.
Queues still in the host configuration that were filtered from the APCB
have already been reset, or had their resources released or leaked by
the reset, so they have nothing left to free here.
Also drop the "qlist" NULL check. Both helpers have a single caller, and
that caller always passes a freshly initialized list.
Fixes: 70aeefe574cb ("s390/vfio-ap: reset queues after adapter/domain unassignment")
Cc: stable@vger.kernel.org
Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
---
drivers/s390/crypto/vfio_ap_ops.c | 40 +++++++++++++++++++++++--------
1 file changed, 30 insertions(+), 10 deletions(-)
diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
index d460337e365f..836551e9f65b 100644
--- a/drivers/s390/crypto/vfio_ap_ops.c
+++ b/drivers/s390/crypto/vfio_ap_ops.c
@@ -1173,6 +1173,22 @@ static struct vfio_ap_queue
return q;
}
+/*
+ * Unlink a queue that is not being reset. If it is no longer in the host's AP
+ * configuration it is gone, but vfio_ap_mdev_remove_queue() can't release its
+ * AQIC resources once the mdev link is cleared, so release them here.
+ */
+static void vfio_ap_unlink_mdev_fr_unreset_queue(struct vfio_ap_queue *q)
+{
+ if (!test_bit_inv(AP_QID_CARD(q->apqn),
+ (unsigned long *)matrix_dev->info.apm) ||
+ !test_bit_inv(AP_QID_QUEUE(q->apqn),
+ (unsigned long *)matrix_dev->info.aqm))
+ vfio_ap_free_aqic_resources(q);
+
+ vfio_ap_unlink_mdev_fr_queue(q);
+}
+
/**
* vfio_ap_mdev_unlink_adapter - unlink all queues associated with unassigned
* adapter from the matrix mdev to which the
@@ -1191,12 +1207,14 @@ static void vfio_ap_mdev_unlink_adapter(struct ap_matrix_mdev *matrix_mdev,
for_each_set_bit_inv(apqi, matrix_mdev->matrix.aqm, AP_DOMAINS) {
q = vfio_ap_unlink_apqn_fr_mdev(matrix_mdev, apid, apqi);
+ if (!q)
+ continue;
- if (q && qlist) {
- if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) &&
- test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm))
- list_add_tail(&q->reset_qnode, qlist);
- }
+ if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) &&
+ test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm))
+ list_add_tail(&q->reset_qnode, qlist);
+ else
+ vfio_ap_unlink_mdev_fr_unreset_queue(q);
}
}
@@ -1392,12 +1410,14 @@ static void vfio_ap_mdev_unlink_domain(struct ap_matrix_mdev *matrix_mdev,
for_each_set_bit_inv(apid, matrix_mdev->matrix.apm, AP_DEVICES) {
q = vfio_ap_unlink_apqn_fr_mdev(matrix_mdev, apid, apqi);
+ if (!q)
+ continue;
- if (q && qlist) {
- if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) &&
- test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm))
- list_add_tail(&q->reset_qnode, qlist);
- }
+ if (test_bit_inv(apid, matrix_mdev->shadow_apcb.apm) &&
+ test_bit_inv(apqi, matrix_mdev->shadow_apcb.aqm))
+ list_add_tail(&q->reset_qnode, qlist);
+ else
+ vfio_ap_unlink_mdev_fr_unreset_queue(q);
}
}
--
2.56.1
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 5/5] s390/vfio-ap: Fix resource handling for rejected AQIC enable requests
2026-12-03 21:45 [PATCH 0/5] s390/vfio-ap: Fixes for queue reset and AQIC handling Jason J. Herne
` (3 preceding siblings ...)
2026-12-03 21:45 ` [PATCH 4/5] s390/vfio-ap: clear matrix_mdev link for queues not reset on unassign Jason J. Herne
@ 2026-12-03 21:45 ` Jason J. Herne
4 siblings, 0 replies; 6+ messages in thread
From: Jason J. Herne @ 2026-12-03 21:45 UTC (permalink / raw)
To: linux-s390
Cc: linux-kernel, akrowiak, borntraeger, agordeev, gor, hca,
mjrosato, frankja, imbrenda, jrossi, stable
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@vger.kernel.org
Signed-off-by: Jason J. Herne <jjherne@linux.ibm.com>
---
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
^ permalink raw reply [flat|nested] 6+ messages in thread