From nobody Thu Apr 2 20:27:00 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1774580022; cv=none; d=zohomail.com; s=zohoarc; b=jtATERTqHyzxsAH1a10xarPfuuMhmHlcslaRahrc3Ypkgx07XFOCS+WiocVdenSgySeCosiB+GRQsv+oqSHPpfqgQN4O/3ynL+3M8RcVQ0Ixxq9GB9yscjXgoF72KRKb4NPPPjI3SBZ5R4pJSkzECpMeGac7mZCuVGgXYuHfu1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774580022; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=17/j1L52tQaXekv5R0nNi+AE8bKxbaWpVcVYLKcCXJ0=; b=lrFPynXPfj+OcJbzaxeOFxtCSxc6q8VCZvVPrGgsXVvArZotMNtI+32GlJO/4qbo8EQdHWVwz5jGggDVIs3bODjYK6eoISIklsL6OBN5j60EK744n6f1F05O+kHH3WeCmLLPoSoIT9qSSsrMBpwtZ8RRQI5OXl0a3V4PoAxxvZU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774580022094739.2673504124348; Thu, 26 Mar 2026 19:53:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5xJk-0005b5-Hx; Thu, 26 Mar 2026 22:53:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5xJi-0005ax-Ng for qemu-devel@nongnu.org; Thu, 26 Mar 2026 22:52:58 -0400 Received: from mgamail.intel.com ([192.198.163.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5xJg-00084r-PF for qemu-devel@nongnu.org; Thu, 26 Mar 2026 22:52:58 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2026 19:52:56 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2026 19:52:53 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774579977; x=1806115977; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gk5YKDTXHBRElQkSDgWIK91hDMH8PgkY/KFjKATXZEI=; b=LwR7h1Q4ceHX+luppnq4l39936UNYUIiSf70avJjZF6nng+eVqx4Sfu0 JrjULOMSQ7nrmRlBWzPatZptiOmrXxM+xAfbeG4QN3jvBS+QeYNV3/aFp iLdIELGeaDTzOmUWGDnlZkvWjaDgWx31X1rpcGOdakVrK4qJsTJ/QJ0yM hBPBwomF1ODQIpEhvisFOO6fJ1Ryd221sW2XzACdbfWR1jS+MFI+u0drx GuNKYzf8ZcjgpKD9mRChgA1hQwEG4IBD1ujmaVwm2/t0vH+DYXOYxUFAo e2+F0LsE6WeKXiaF27Qt6KMlbVYTGu8vpzDXp1VwcF0d9Z+8z9HKG6wnd Q==; X-CSE-ConnectionGUID: CYfhNV8hTuWX3nCydpZ1xg== X-CSE-MsgGUID: HbBaUWXXSdGXhKhYRphHgA== X-IronPort-AV: E=McAfee;i="6800,10657,11741"; a="75719916" X-IronPort-AV: E=Sophos;i="6.23,143,1770624000"; d="scan'208";a="75719916" X-CSE-ConnectionGUID: I+Me9fTLR9aAjQ582pARFQ== X-CSE-MsgGUID: eLxTD4IHTxCeN0RKJXe8cQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,143,1770624000"; d="scan'208";a="221874395" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH 5/5] intel_iommu_accel: teardown FAULTQ resources in bottom half Date: Thu, 26 Mar 2026 22:52:27 -0400 Message-ID: <20260327025228.474257-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260327025228.474257-1-zhenzhong.duan@intel.com> References: <20260327025228.474257-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.198.163.14; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1774580023343158500 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_accel.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 44af534c55..fdc376c070 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -267,16 +267,43 @@ free_faultq: return false; } =20 +typedef struct IOMMUFaultQueue { + IOMMUFDBackend *iommufd; + uint32_t id; + int fd; +} IOMMUFaultQueue; + +static void faultq_teardown_bh(void *opaque) +{ + IOMMUFaultQueue *fq =3D opaque; + + qemu_set_fd_handler(fq->fd, NULL, NULL, NULL); + close(fq->fd); + iommufd_backend_free_id(fq->iommufd, fq->id); + + g_free(fq); +} + + static void vtd_destroy_old_fs_faultq(VTDHostIOMMUDevice *vtd_hiod, VTDAccelPASIDCacheEntry *vtd_pce) { + HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->h= iod); + if (!vtd_pce->fault_id) { return; } =20 vtd_pce->pri_notifier =3D NULL; - qemu_set_fd_handler(vtd_pce->fault_fd, NULL, NULL, NULL); - vtd_destroy_fs_faultq(vtd_hiod, vtd_pce->fault_id, vtd_pce->fault_fd); + + IOMMUFaultQueue *fq =3D g_malloc(sizeof(IOMMUFaultQueue)); + fq->iommufd =3D idev->iommufd; + fq->fd =3D vtd_pce->fault_fd; + fq->id =3D vtd_pce->fault_id; + + aio_bh_schedule_oneshot(iohandler_get_aio_context(), + faultq_teardown_bh, fq); + vtd_pce->fault_id =3D 0; vtd_pce->fault_fd =3D -1; } --=20 2.47.3