From: sashiko-bot@kernel.org
To: "Anthony Krowiak" <akrowiak@linux.ibm.com>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
linux-s390@vger.kernel.org, kvm@vger.kernel.org,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH v5 03/15] s390/vfio-ap: Functions to initialize/release vfio device migration data
Date: Fri, 24 Jul 2026 17:35:07 +0000 [thread overview]
Message-ID: <20260724173508.5E7F11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724161351.1802644-4-akrowiak@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] ABBA deadlock (circular locking dependency) between `matrix_dev->mdevs_lock` and the VFIO core's `dev_set->lock`.
Pre-existing issues:
- [Critical] Failing to attach a second mdev to a KVM instance corrupts `kvm->arch.crypto.pqap_hook`, leading to a Use-After-Free.
--
--- Patch [3]: [PATCH v5 03/15] s390/vfio-ap: Functions to initialize/release vfio device migration data ---
commit ab0b2af7d9f1c49f7cea7a7d2157bcc5a0bb9b7a
Author: Anthony Krowiak <akrowiak@linux.ibm.com>
s390/vfio-ap: Functions to initialize/release vfio device migration data
Provides the functions that initialize and release the data structures
used during live guest migration:
> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
> index 71d3e2c2e07c6..47aca908701d1 100644
> --- a/drivers/s390/crypto/vfio_ap_ops.c
> +++ b/drivers/s390/crypto/vfio_ap_ops.c
[ ... ]
> @@ -797,18 +809,29 @@ static int vfio_ap_mdev_probe(struct mdev_device *mdev)
> if (IS_ERR(matrix_mdev))
> return PTR_ERR(matrix_mdev);
>
> + mutex_lock(&matrix_dev->mdevs_lock);
> +
> + /*
> + * Migration capabilities must be initialized before calling
> + * vfio_register_emulated_iommu_dev; otherwise, the VFIO core
> + * will see mig_ops as NULL during the registration. This could
> + * prevent the VFIO core from properly setting up migration
> + * infrastructure like debugfs entries.
> + */
> + vfio_ap_init_migration_capabilities(matrix_mdev);
> +
> ret = vfio_register_emulated_iommu_dev(&matrix_mdev->vdev);
[Severity: High]
Does taking mdevs_lock before calling vfio_register_emulated_iommu_dev()
introduce an ABBA deadlock?
In vfio_ap_mdev_probe(), we now hold mdevs_lock when calling
vfio_register_emulated_iommu_dev(), which takes dev_set->lock inside the VFIO
core via vfio_assign_device_set().
However, in vfio_ap_mdev_open_device() below, which is called by the VFIO core
with dev_set->lock already held, we now acquire mdevs_lock.
Will this reverse lock ordering trigger a lockdep circular dependency splat
when userspace probes and opens the device?
[ ... ]
> @@ -2052,19 +2075,39 @@ static int vfio_ap_mdev_reset_qlist(struct list_head *qlist)
>
> static int vfio_ap_mdev_open_device(struct vfio_device *vdev)
> {
> - struct ap_matrix_mdev *matrix_mdev =
> - container_of(vdev, struct ap_matrix_mdev, vdev);
> + struct ap_matrix_mdev *matrix_mdev;
> + int ret;
>
> if (!vdev->kvm)
> return -EINVAL;
>
> - return vfio_ap_mdev_set_kvm(matrix_mdev, vdev->kvm);
> + mutex_lock(&matrix_dev->mdevs_lock);
> + matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev);
> + ret = vfio_ap_init_migration_data(matrix_mdev);
> + mutex_unlock(&matrix_dev->mdevs_lock);
> +
> + if (ret)
> + return ret;
> +
> + ret = vfio_ap_mdev_set_kvm(matrix_mdev, vdev->kvm);
[Severity: Critical]
This is a pre-existing issue, but I noticed that if vfio_ap_mdev_set_kvm()
fails (for instance, returning -EPERM because another mdev is already attached
to this KVM), does it leave kvm->arch.crypto.pqap_hook pointing to the new
mdev's pqap_hook?
Looking at vfio_ap_mdev_set_kvm() in drivers/s390/crypto/vfio_ap_ops.c, it
unconditionally overwrites KVM's pqap_hook before checking if another mdev is
already attached:
down_write(&kvm->arch.crypto.pqap_hook_rwsem);
kvm->arch.crypto.pqap_hook = &matrix_mdev->pqap_hook;
up_write(&kvm->arch.crypto.pqap_hook_rwsem);
get_update_locks_for_kvm(kvm);
list_for_each_entry(m, &matrix_dev->mdev_list, node) {
if (m != matrix_mdev && m->kvm == kvm) {
release_update_locks_for_kvm(kvm);
return -EPERM;
}
}
If this fails with -EPERM, the pointer is not restored. If this new mdev is
subsequently closed and freed, could a malicious guest executing a PQAP
instruction trigger a use-after-free in the host when handle_pqap()
dereferences this freed pointer?
> + if (ret) {
> + /* Clean up migration data on failure */
> + mutex_lock(&matrix_dev->mdevs_lock);
> + vfio_ap_release_migration_data(matrix_mdev);
> + mutex_unlock(&matrix_dev->mdevs_lock);
> + }
> +
> + return ret;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724161351.1802644-1-akrowiak@linux.ibm.com?part=3
next prev parent reply other threads:[~2026-07-24 17:35 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 16:13 [PATCH v5 00/15] s390/vfio-ap: Add live guest migration support Anthony Krowiak
2026-07-24 16:13 ` [PATCH v5 01/15] s390/vfio-ap: Provide function to get the number of queues assigned to mdev Anthony Krowiak
2026-07-24 17:36 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 02/15] s390/vfio-ap: Data structures for facilitating vfio device migration Anthony Krowiak
2026-07-24 17:28 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 03/15] s390/vfio-ap: Functions to initialize/release vfio device migration data Anthony Krowiak
2026-07-24 17:35 ` sashiko-bot [this message]
2026-07-24 16:13 ` [PATCH v5 04/15] s390/vfio-ap: Reset migration state in VFIO_DEVICE_RESET ioctl handler Anthony Krowiak
2026-07-24 17:43 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 05/15] s390-vfio-ap: Callback to get/set vfio device mig state during guest migration Anthony Krowiak
2026-07-24 17:47 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 06/15] s390/vfio-ap: Transition guest migration state from STOP to STOP_COPY Anthony Krowiak
2026-07-24 17:50 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 07/15] s390/vfio-ap: File ops called to save the vfio device migration state Anthony Krowiak
2026-07-24 18:04 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 08/15] s390/vfio-ap: Transition device migration state from STOP to RESUMING Anthony Krowiak
2026-07-24 18:06 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 09/15] s390/vfio-ap: Add method to set a new guest AP configuration Anthony Krowiak
2026-07-24 18:10 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 10/15] s390/vfio-ap: File ops called to resume the vfio device migration Anthony Krowiak
2026-07-24 18:17 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 11/15] s390/vfio-ap: Transition device migration state to STOP Anthony Krowiak
2026-07-24 18:26 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 12/15] s390/vfio-ap: Transition device migration state from STOP to RUNNING and vice versa Anthony Krowiak
2026-07-24 18:29 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 13/15] s390/vfio-ap: Callback to get the size of data to be migrated during guest migration Anthony Krowiak
2026-07-24 18:27 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 14/15] s390/vfio-ap: Add 'migratable' feature to sysfs 'features' attribute Anthony Krowiak
2026-07-24 18:30 ` sashiko-bot
2026-07-24 16:13 ` [PATCH v5 15/15] s390/vfio-ap: Add live guest migration chapter to vfio-ap.rst Anthony Krowiak
2026-07-24 18:38 ` 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=20260724173508.5E7F11F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=akrowiak@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--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