Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jason J. Herne" <jjherne@linux.ibm.com>, linux-s390@vger.kernel.org
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH 2/5] s390/vfio-ap: bound the wait for queue reset verification
Date: Thu, 03 Dec 2026 22:08:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-248731@kernel.org> (raw)
In-Reply-To: <20261203214531.1395796-3-jjherne@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] s390/vfio-ap: timed-out unreset queue still passed to next
  guest
- [High] s390/vfio-ap: sie_page2 GISA freed while unreset queue still
  references it
- [Low] s390/vfio-ap: final ap_zapq() retry leaks NIB on non-operational
  status
--

commit b0dd58c5d0782ca7241d08c5695985f4c6e563d9
Author: Jason J. Herne <jjherne@linux.ibm.com>

s390/vfio-ap: bound the wait for queue reset verification

This commit adds a 2-second timeout to apq_reset_check() so that
verification of an AP queue reset does not loop indefinitely, leaking
AQIC resources and recording a non-zero reset_status on timeout.

> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
> index 10430b9446dbb..fba6f256ce77a 100644
> --- a/drivers/s390/crypto/vfio_ap_ops.c
> +++ b/drivers/s390/crypto/vfio_ap_ops.c

[ ... ]

> @@ -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) {

[Severity: Low]
Can this timeout check leak the NIB page if the final ap_zapq() retry
returns a non-operational status?

When elapsed reaches VFIOAP_RESET_TIMEOUT, the ap_zapq() retry path
continues straight into this check without inspecting
status.response_code.

If that ap_zapq() returned AP_RESPONSE_DECONFIGURED,
AP_RESPONSE_CHECKSTOPPED, or AP_RESPONSE_Q_NOT_AVAIL, this logs a
spurious timeout warning and leaks the NIB page instead of freeing AQIC
resources via the -ENODEV path.

> +			/*
> +			 * 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));

[Severity: High]
What prevents the unreset AP queue from writing to a freed GISA page
after VM teardown?

vfio_ap_irq_enable() programs the queue hardware with both h_nib and the
physical address of kvm->arch.sie_page2->gisa via ap_aqic().  When this
timeout lets vfio_ap_mdev_unset_kvm() return, KVM proceeds to
kvm_arch_destroy_vm() and calls kfree(kvm->arch.sie_page2).

If the still-active queue later raises an interrupt, hardware can write
to the freed and reused host kernel page, causing host memory
corruption.  (Because saved_isc is not unregistered here, this also
triggers WARN(gi->alert.mask != 0x00) in kvm_s390_gisa_destroy().)

> +			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;
> +		}

[Severity: High]
Does recording a non-zero reset_status actually prevent the unreset
queue from being passed to the next guest?

_queue_passable() is only checked inside vfio_ap_mdev_filter_matrix(),
which is not called when detaching or attaching a guest.  During VM
teardown, vfio_ap_mdev_unset_kvm() ignores the -EIO return from
vfio_ap_mdev_reset_queues() and leaves matrix_mdev->shadow_apcb intact.

When another guest later opens the same mdev, vfio_ap_mdev_set_kvm()
calls vfio_ap_mdev_update_guest_apcb() directly with that stale
shadow_apcb.  The new guest then gets access to the unreset, unzeroized
queue, breaking guest-to-guest isolation.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203214531.1395796-1-jjherne@linux.ibm.com?part=2

  reply	other threads:[~2026-12-03 22:08 UTC|newest]

Thread overview: 11+ 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-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 [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=sashiko-outbox-248731@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=jjherne@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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