Linux s390 Architecture development
 help / color / mirror / Atom feed
From: "Jason J. Herne" <jjherne@linux.ibm.com>
To: linux-s390@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, akrowiak@linux.ibm.com,
	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: [PATCH 1/5] s390/vfio-ap: Prevent passing unreset queues
Date: Thu,  3 Dec 2026 16:45:27 -0500	[thread overview]
Message-ID: <20261203214531.1395796-2-jjherne@linux.ibm.com> (raw)
In-Reply-To: <20261203214531.1395796-1-jjherne@linux.ibm.com>

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


  reply	other threads:[~2026-12-03 21:45 UTC|newest]

Thread overview: 6+ 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 ` Jason J. Herne [this message]
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 ` [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 ` [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

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=20261203214531.1395796-2-jjherne@linux.ibm.com \
    --to=jjherne@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akrowiak@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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox