From: Anthony Krowiak <akrowiak@linux.ibm.com>
To: "Jason J. Herne" <jjherne@linux.ibm.com>, linux-s390@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, borntraeger@linux.ibm.com,
agordeev@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com,
mjrosato@linux.ibm.com, frankja@linux.ibm.com,
imbrenda@linux.ibm.com, jrossi@linux.ibm.com,
stable@vger.kernel.org
Subject: Re: [PATCH 2/5] s390/vfio-ap: bound the wait for queue reset verification
Date: Fri, 4 Dec 2026 13:12:42 -0500 [thread overview]
Message-ID: <710e7d53-901d-4408-951d-5326e16d5bbc@linux.ibm.com> (raw)
In-Reply-To: <20261203214531.1395796-3-jjherne@linux.ibm.com>
On 12/3/26 4:45 PM, Jason J. Herne wrote:
> 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));
I don't think this is necessary. In the initial call to the
function as well as all succeeding calls, the status is obtained
from the TAPQ call below.
> 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));
Since this block will be entered only after a call to TAPQ followed by a
call to apq_status_check(), we need to check the return code (ret)
from apq_status_check() to see if it returned 0 which means the ZAPQ
succeeded. If that is the case, then the AQIC resources can be freed and
the status response code can be set to or left as 0.
> + memcpy(&q->reset_status, &status, sizeof(status));
!q->reset_status.response_code indicates the ZAPQ completed
successfully. Of course, in patch 1/5, no verification was
done to determine whether the ZAPQ completed; a response code of
0 only indicates that the reset was initiated. It's an asychronous
instruction, so the following needs to be verified before we know
that ZAPQ completed:
if (status->queue_empty && !status->replies_waiting &&
!status->irq_enabled && !status->async)
return 0;
Note also that you would have to check if the return code from
TAPQ is -ENODEV in which case you can free AQIC resources.
By putting this timeout check before the TAPQ and
apq_status_check() calls, you are going to have to duplicate
some of the succeeding checks in side this block.
> + 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);
next prev parent reply other threads:[~2026-12-04 18:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 22:08 ` sashiko-bot
2026-12-04 17:08 ` Anthony Krowiak
2026-12-03 21:45 ` [PATCH 2/5] s390/vfio-ap: bound the wait for queue reset verification Jason J. Herne
2026-12-03 22:08 ` sashiko-bot
2026-12-04 18:12 ` Anthony Krowiak [this message]
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 22:14 ` sashiko-bot
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 22:02 ` sashiko-bot
2026-12-03 21:45 ` [PATCH 5/5] s390/vfio-ap: Fix resource handling for rejected AQIC enable requests Jason J. Herne
2026-12-03 22:14 ` [PATCH 0/5] s390/vfio-ap: Fixes for queue reset and AQIC handling sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=710e7d53-901d-4408-951d-5326e16d5bbc@linux.ibm.com \
--to=akrowiak@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=jjherne@linux.ibm.com \
--cc=jrossi@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.