From: sashiko-bot@kernel.org
To: "Samiullah Khawaja" <skhawaja@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v8 18/18] iommufd/selftest: Add test to verify iommufd preservation
Date: Mon, 23 Nov 2026 05:11:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-228705@kernel.org> (raw)
In-Reply-To: <20261123044949.3610702-19-skhawaja@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] iommufd: race between iommufd_test_liveupdate_preserve_dev()
and detach
--
commit f9841f2ccd5ea9e7ec8822d894220423dd77c296
Author: Samiullah Khawaja <skhawaja@google.com>
iommufd/selftest: Add test to verify iommufd preservation
This commit adds a kexec selftest to verify iommufd preservation across
live update, along with an IOMMU_TEST_OP_LIVEUPDATE_PRESERVE_DEV test
operation to preserve an iommufd device.
> diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
> index 037e54f3d2ba6..d904482124e1f 100644
> --- a/drivers/iommu/iommufd/selftest.c
> +++ b/drivers/iommu/iommufd/selftest.c
> @@ -2115,6 +2115,33 @@ static int iommufd_test_dmabuf_revoke(struct iommufd_ucmd *ucmd, int fd,
> return rc;
> }
>
> +/*
> + * Preserve the IOMMU state of a device bound to this iommufd, as a vfio cdev
> + * preserved in the same live update session would. The iommufd must already
> + * be preserved, so the HWPT of the device is preserved.
> + */
> +static int iommufd_test_liveupdate_preserve_dev(struct iommufd_ucmd *ucmd,
> + u32 dev_id)
> +{
> +#ifdef CONFIG_IOMMU_LIVEUPDATE
> + struct iommufd_device *idev;
> + int rc;
> +
> + idev = iommufd_get_device(ucmd, dev_id);
> + if (IS_ERR(idev))
> + return PTR_ERR(idev);
> +
> + mutex_lock(&ucmd->ictx->liveupdate_mutex);
> + rc = __iommufd_device_preserve(idev, 0);
> + mutex_unlock(&ucmd->ictx->liveupdate_mutex);
[Severity: Medium]
Can iommufd_test_liveupdate_preserve_dev() race with a concurrent
iommufd_device_detach() and leave idev preserved after its attachment is
removed?
In iommufd_device_detach(), igroup->lock is dropped between
iommufd_device_unpreserve() and iommufd_hw_pagetable_detach():
drivers/iommu/iommufd/device.c:iommufd_device_detach() {
if (pasid == IOMMU_NO_PASID)
iommufd_device_unpreserve(idev);
hwpt = iommufd_hw_pagetable_detach(idev, pasid);
if (!hwpt)
return;
...
}
Because IOMMU_TEST_OP_LIVEUPDATE_PRESERVE_DEV runs on the iommufd file
descriptor without the VFIO device lock that serializes detach and close,
the two paths can interleave:
CPU0 CPU1
iommufd_device_detach(idev, ...)
iommufd_device_unpreserve(idev)
mutex_lock(&igroup->lock)
/* !idev->liveupdate_preserved */
mutex_unlock(&igroup->lock)
iommufd_test_liveupdate_preserve_dev()
__iommufd_device_preserve(idev, 0)
mutex_lock(&igroup->lock)
iommu_preserve_device(...)
idev->liveupdate_preserved = true
mutex_unlock(&igroup->lock)
iommufd_hw_pagetable_detach(...)
mutex_lock(&igroup->lock)
xa_erase(&igroup->pasid_attach,
IOMMU_NO_PASID)
mutex_unlock(&igroup->lock)
When the liveupdate session closes (or idev is later unpreserved),
iommufd_device_unpreserve() sees no IOMMU_NO_PASID attachment in
igroup->pasid_attach, triggers WARN(1, "IOMMU_NO_PASID attachment not
found"), and skips iommu_unpreserve_device(), leaking the preserved IOMMU
device state.
Unpreserving the device inside iommufd_hw_pagetable_detach() under the
same igroup->lock critical section that removes the IOMMU_NO_PASID
attachment would close this window.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123044949.3610702-1-skhawaja@google.com?part=18
prev parent reply other threads:[~2026-11-23 5:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 4:49 [PATCH v8 00/18] iommu: Add live update state preservation Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 01/18] liveupdate: Export symbols needed by modules Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 02/18] iommu: Implement IOMMU Live update FLB callbacks Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 03/18] iommu/pages: Add APIs to preserve/unpreserve/restore iommu pages Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 04/18] iommupt: Implement preserve/unpreserve/restore callbacks Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 05/18] iommu: Implement IOMMU domain preservation Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 06/18] iommu: Implement device and IOMMU HW preservation Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 07/18] iommu/vt-d: Implement device and iommu preserve/unpreserve ops Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 08/18] iommu/vt-d: Clear unpreserved context entries during shutdown Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 09/18] iommu: Add APIs to get iommu and device restored state Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 10/18] iommu/vt-d: Combine disable_dmar_iommu() and free_dmar_iommu() Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 11/18] iommu/vt-d: Restore IOMMU state and reclaimed domain ids Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 12/18] iommu/vt-d: Preserve PASID table of preserved device Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 13/18] iommu: Restore and reattach preserved domains to devices Samiullah Khawaja
2026-11-23 5:18 ` sashiko-bot
2026-11-23 4:49 ` [PATCH v8 14/18] iommu/vt-d: Handle reattach of the restored domain Samiullah Khawaja
2026-11-23 5:03 ` sashiko-bot
2026-11-23 4:49 ` [PATCH v8 15/18] iommufd: Implement ioctl to mark HWPT for preservation Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 16/18] iommufd: Persist iommu hardware pagetables for live update Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 17/18] iommufd: Add APIs to preserve/unpreserve a vfio cdev Samiullah Khawaja
2026-11-23 4:49 ` [PATCH v8 18/18] iommufd/selftest: Add test to verify iommufd preservation Samiullah Khawaja
2026-11-23 5:11 ` sashiko-bot [this message]
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-228705@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=skhawaja@google.com \
/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