From: Yi Liu <yi.l.liu@intel.com>
To: Zhenzhong Duan <zhenzhong.duan@intel.com>, <qemu-devel@nongnu.org>
Cc: <alex@shazbot.org>, <clg@redhat.com>, <eric.auger@redhat.com>,
<mst@redhat.com>, <jasowangio@gmail.com>, <jgg@nvidia.com>,
<nicolinc@nvidia.com>, <skolothumtho@nvidia.com>,
<joao.m.martins@oracle.com>, <clement.mathieu--drif@bull.com>,
<kevin.tian@intel.com>, Xudong Hao <xudong.hao@intel.com>
Subject: Re: [PATCH v8 6/6] intel_iommu_accel: teardown FAULTQ resources in bottom half
Date: Sun, 18 Oct 2026 22:01:03 +0800 [thread overview]
Message-ID: <d7b37c65-7234-4eb4-b960-454572f447a5@intel.com> (raw)
In-Reply-To: <20261009090737.3930000-7-zhenzhong.duan@intel.com>
On 10/9/26 17:07, Zhenzhong Duan wrote:
> When a pasid entry becomes invalid, we need to release all resources
> allocated for that entry including FAULTQ object and fault_fd.
>
> We call qemu_set_fd_handler() to detach fault_fd's io_read handler and
> wakes up main thread from poll(), but there could still be a small
> window we call iommufd_backend_free_id(fault_id) before poll() exit
> and release fault_id file reference. In this rare case, FAULTQ object
> free return -EBUSY because opened fault_id file keeps reference of
> FAULTQ object.
>
> Teardown FAULTQ resources in bottom half to ensure poll() has released
> fault_id file reference.
>
> Suggested-by: Shameer Kolothum <skolothumtho@nvidia.com>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> Tested-by: Xudong Hao <xudong.hao@intel.com>
> ---
> hw/i386/intel_iommu_accel.c | 40 ++++++++++++++++++++++++++++++++++---
> 1 file changed, 37 insertions(+), 3 deletions(-)
>
> diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c
> index cd227315da..c07ffa68e0 100644
> --- a/hw/i386/intel_iommu_accel.c
> +++ b/hw/i386/intel_iommu_accel.c
> @@ -268,17 +268,51 @@ free_faultq:
> return false;
> }
>
> +typedef struct IOMMUFaultQueue {
> + IOMMUFDBackend *iommufd;
> + uint32_t id;
> + int fd;
> + QLIST_HEAD(, VTDPRQEntry) vtd_prq_list;
> +} IOMMUFaultQueue;
> +
> +static void faultq_teardown_bh(void *opaque)
> +{
> + IOMMUFaultQueue *fq = opaque;
> + VTDPRQEntry *prqe, *next;
> +
> + QLIST_FOREACH_SAFE(prqe, &fq->vtd_prq_list, next, next) {
> + QLIST_REMOVE(prqe, next);
> + g_free(prqe);
> + }
> +
> + qemu_set_fd_handler(fq->fd, NULL, NULL, NULL);
> + close(fq->fd);
> + iommufd_backend_free_id(fq->iommufd, fq->id);
> +
a nit: any reason that you open code instead of reusing
vtd_destroy_fs_faultq() as the existing code? If no special
reason, may be better reusing it.
Other part LGTM.
Reviewed-by: Yi Liu <yi.l.liu@intel.com>
> + g_free(fq);
> +}
> +
> static void vtd_destroy_old_fs_faultq(VTDAccelPASIDCacheEntry *vtd_pce)
> {
> + HostIOMMUDeviceIOMMUFD *idev =
> + HOST_IOMMU_DEVICE_IOMMUFD(vtd_pce->vtd_hiod->hiod);
> + IOMMUFaultQueue *fq;
> +
> if (vtd_pce->fault_fd < 0) {
> return;
> }
>
> - qemu_set_fd_handler(vtd_pce->fault_fd, NULL, NULL, NULL);
> - vtd_destroy_fs_faultq(vtd_pce->vtd_hiod, vtd_pce->fault_id,
> - vtd_pce->fault_fd);
> + fq = g_malloc(sizeof(*fq));
> + fq->iommufd = idev->iommufd;
> + fq->fd = vtd_pce->fault_fd;
> + fq->id = vtd_pce->fault_id;
> vtd_pce->fault_id = 0;
> vtd_pce->fault_fd = -1;
> + fq->vtd_prq_list.lh_first = vtd_pce->vtd_prq_list.lh_first;
> + QLIST_INIT(&vtd_pce->vtd_prq_list);
> +
> + aio_bh_schedule_oneshot(iohandler_get_aio_context(),
> + faultq_teardown_bh, fq);
> }
>
> static void vtd_setup_fs_faultq(VTDAccelPASIDCacheEntry *vtd_pce,
next prev parent reply other threads:[~2026-10-18 13:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 9:07 [PATCH v8 0/6] intel_iommu: Enable PRQ support for passthrough device Zhenzhong Duan
2026-10-09 9:07 ` [PATCH v8 1/6] intel_iommu_accel: Guard VTDAccelPASIDCacheEntry definition Zhenzhong Duan
2026-10-09 9:07 ` [PATCH v8 2/6] backends/iommufd: Introduce iommufd_backend_alloc_faultq Zhenzhong Duan
2026-10-09 20:24 ` Nicolin Chen
2026-10-09 9:07 ` [PATCH v8 3/6] backends/iommufd: Extend iommufd_backend_alloc_hwpt() with fault_id Zhenzhong Duan
2026-10-09 20:26 ` Nicolin Chen
2026-10-09 9:07 ` [PATCH v8 4/6] intel_iommu_accel: Add PRQ injection for passthrough device Zhenzhong Duan
2026-10-18 14:00 ` Yi Liu
2026-10-19 9:04 ` Duan, Zhenzhong
2026-10-20 6:14 ` Yi Liu
2026-10-09 9:07 ` [PATCH v8 5/6] intel_iommu_accel: Accept PRQ response " Zhenzhong Duan
2026-10-18 14:00 ` Yi Liu
2026-10-19 10:07 ` Duan, Zhenzhong
2026-10-09 9:07 ` [PATCH v8 6/6] intel_iommu_accel: teardown FAULTQ resources in bottom half Zhenzhong Duan
2026-10-18 14:01 ` Yi Liu [this message]
2026-10-19 8:48 ` Duan, Zhenzhong
2026-10-19 9:50 ` Duan, Zhenzhong
2026-10-20 6:11 ` Yi Liu
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=d7b37c65-7234-4eb4-b960-454572f447a5@intel.com \
--to=yi.l.liu@intel.com \
--cc=alex@shazbot.org \
--cc=clement.mathieu--drif@bull.com \
--cc=clg@redhat.com \
--cc=eric.auger@redhat.com \
--cc=jasowangio@gmail.com \
--cc=jgg@nvidia.com \
--cc=joao.m.martins@oracle.com \
--cc=kevin.tian@intel.com \
--cc=mst@redhat.com \
--cc=nicolinc@nvidia.com \
--cc=qemu-devel@nongnu.org \
--cc=skolothumtho@nvidia.com \
--cc=xudong.hao@intel.com \
--cc=zhenzhong.duan@intel.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 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.