From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B991739934C for ; Fri, 15 May 2026 07:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=198.175.65.19 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778828845; cv=fail; b=UcgK+MVZFdnR11csSqDMEQkc+spLmzug6n0uM0hWdkEIOKjiBu25umu5i7ewaiHJm1jKVhPqzVE7iuKbmRkmhPFLiLyDy/kvq65K/tKDZoWnUB4oWfZ+Cp7pzCt+9IRROp7uJLdVXLeFCoyFnvOhHwXyajcPJRsBpQ4j7gMawMM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778828845; c=relaxed/simple; bh=97zxOY3A02fHvfaWfB2zo0Oads74lI7i6ufIZhpNVD8=; h=Date:From:To:CC:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=NKra6Qmd7o3afFwD1bf8W430UjNrl9vi8/x2HcNXbQSaGSJzc+XWplrv/qSo2GkwNNmdFs07q1I7eotzZNAwBTtPqOuNAt6O3YzSwgH/0KkXSbplf8dXzxjjz7e3XHG7X11Xrl79FxB9OdQcvgwTv4n1+zYaco/31Qy1L59yags= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=haDKS1dr; arc=fail smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="haDKS1dr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778828843; x=1810364843; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=97zxOY3A02fHvfaWfB2zo0Oads74lI7i6ufIZhpNVD8=; b=haDKS1drZ6bQdAllr5Sc3U+TzVTb/b2VfW2kgWLokvY2ukKYnx4Fdga+ ePaxtuH2gKSweXoG4A1syQzT2njMUpcgx48U9WI31qXKCh7hjQlgraXS9 0vCjIGe0Q7mvJl8HWkYKyM9YQywMcZLOtXqQFyyooXx1GoF8fXx/wydCw kDysnJ2/DJjTkwm+h6ZG/pRmIirI0DntyedxZQFMXgzV0VoKec+mQiQMp mL8fqCgoLAt5WEO40mW+ps7nB0wLEru5AnudTOrlEanVVDlKZDyzLm59i NzWL2cA/bRva4IeO0XOkF3GIld1RelAVvv6+825LNn7Npa4POsPBAEbQv w==; X-CSE-ConnectionGUID: UQ92qzzvQdyRzp/3fCS/XA== X-CSE-MsgGUID: cAYypIQvST2IqkyyENnMFg== X-IronPort-AV: E=McAfee;i="6800,10657,11786"; a="79741939" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79741939" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 00:07:22 -0700 X-CSE-ConnectionGUID: eH7Kdeb8TqS7kZZKiW5rOw== X-CSE-MsgGUID: KFROgGeZRZeL4tKYZX6jtg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="234185725" Received: from fmsmsx903.amr.corp.intel.com ([10.18.126.92]) by fmviesa006.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 00:07:22 -0700 Received: from FMSMSX903.amr.corp.intel.com (10.18.126.92) by fmsmsx903.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 15 May 2026 00:07:21 -0700 Received: from fmsedg902.ED.cps.intel.com (10.1.192.144) by FMSMSX903.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37 via Frontend Transport; Fri, 15 May 2026 00:07:21 -0700 Received: from BN8PR05CU002.outbound.protection.outlook.com (52.101.57.8) by edgegateway.intel.com (192.55.55.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 15 May 2026 00:07:20 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gVR1gJ0Y1jCujLl3eB6Whifez8Osa81ZplMYPHgsgd5D2RTkxADlV+rOqvemZmu41yS0zo2TOB17dYDriFFSCnR1OGgOvGK99TMjwMnMDqzVfG1flZHTydCOBEIIsNO2BCpCB+StyDTJdxB12vXRq63N9Z0O0TC3wkAumfhm6FGV9iBrV7ziMh3bWODFFShwe+gQybtWi5qey877DtX+DwzWfyYqzAZSvQJGlZgkiG71bW0y3fJX5ulV3/HuRO0krRP44CYVeL7sL/0dKl4RWFkSZYrcaGBgPO3TRxAOeo/vinSLfV5JLsCmkOYF1YHGzbZ7RDhV+QykfcfWXQPiFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RhLlOX28yM8OTKnURqNOp4YT1qs3w95mMZwU6BJBHqU=; b=APtdyr7yMaeEkiEYeaxKEFy1KedEOWucJkxdTrZaWdx+b7eOsOhZ42opURClNoicFRFvYlmfYftI493tD9+B7IMAE/8XbEPqljy7JtOhLdYogyJms95rqH2XzI8FjQnhOIknvR2Bt+IxiuMg34gBtCHySf1rQL+1xXPcR7yySZR8clq1iyTxkIioF1Q2DZzKK72vKxQ+Qe/+k8GDudzOfjU2H6xvJZk5SWU8mZAUhxHWy9tzwLF0b6OnglVhwj4nR3whbGS1TCMIoVeGUCviw5Eq/UqWm5L8wuvrmXq+GvTuIPmLCVjAUe3fQW5z1ESVOoC3fVs/QMQUdObKdTHuOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from SJ1PR11MB6153.namprd11.prod.outlook.com (2603:10b6:a03:488::18) by IA4PR11MB9178.namprd11.prod.outlook.com (2603:10b6:208:569::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9913.12; Fri, 15 May 2026 07:07:17 +0000 Received: from SJ1PR11MB6153.namprd11.prod.outlook.com ([fe80::d6e0:baf2:d31d:c812]) by SJ1PR11MB6153.namprd11.prod.outlook.com ([fe80::d6e0:baf2:d31d:c812%4]) with mapi id 15.20.9913.009; Fri, 15 May 2026 07:07:17 +0000 Date: Fri, 15 May 2026 15:06:03 +0800 From: Fei Li To: Sicong Huang CC: , , , Subject: Re: [PATCH v1] virt: acrn: Fix irqfd use-after-free during async shutdown Message-ID: References: <20260511135737.2285411-1-congei42@163.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20260511135737.2285411-1-congei42@163.com> X-ClientProxiedBy: TP0P295CA0015.TWNP295.PROD.OUTLOOK.COM (2603:1096:910:2::13) To SJ1PR11MB6153.namprd11.prod.outlook.com (2603:10b6:a03:488::18) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PR11MB6153:EE_|IA4PR11MB9178:EE_ X-MS-Office365-Filtering-Correlation-Id: 95ade267-367f-413c-498d-08deb250996c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|42112799006|376014|11063799003|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: QuZn50kFmSXyxuVu3OOBvNGQ87DGyv7VYvHsOsSJwuPo+xebOokoSNRyHRGWdglUMeZNuClX1DJgLlPcOkDH4zbG+iPVOiBU4RFzAEq53EuUH0WZCVomyeq15gRF7WMmqUbApWpNWwfPiZF08Ljj5sxifbaJ68UEOfTwwcNJVQ7Auz8JHRayEE/KQsGjtVwR23kNhs/oV+S7hAXd9m+HBEIDaNKYxORUcpwCru5fX7E6/UtbnhZ3woajzgMxCUzkx81dym+e5TZWSQxyj2C/SfyDaArUSZ8aSX9y9gGqJRACPEvEdwxcJqPjB+heypuQ0Pt1019siAoU1Rc26mdn0/JcwrrT65d0+mcx7tVMQ3fg0MbnLmpdxo6fCwE1eFEceHDB9UUFIJ0MEj/LMYtGsVtuD/GnmQW2k4b7Nzgh9/nn2lbAuI8TGwtdG+Hmysj9xILkhce38JFtqqSGYuC8c7CU0U+8nQf7TmfeHHgPPnXVoDWMbXHMdETGLu9AcJQbDRa0jOIP+OZERUPQpyNtAYessU6D/CwChwzZlqmEPlIIOUKod9HEDNF/XMVKJ+80tio/eX5wV+QYCB40QjrfZ5yKu3B6svPzCEiNGa/w2zDkmuAp+xRBKp+bEjM8bGQvD0U3Dfw5LXDLzAQlIPugPYHT6f1kRIxKOWps1puK5zjIL81dpbJ9zBnTN7bZyYke X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ1PR11MB6153.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(42112799006)(376014)(11063799003)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?1JQYt+u1vSavgOtT9MJHJnSTKXYnV6IqkXwQBsT8xPDgI0TmAx6+LABgnJ6x?= =?us-ascii?Q?t7eVzm0xB7Kdcko1yXQKaIcOF26VdOnrEGUuJDQG7ZiXXQ4ZY6/kOggeY0HY?= =?us-ascii?Q?rSxqbPbtFqAOKj7vUNmN/weZC5w+z5+TjyAhX/UH2WC309TQNSYZycKnE7Rb?= =?us-ascii?Q?McgLlnemffFqNhlMJsCFXxJ/6nv6I53YZSnvaAjcCimyIXJWd+ndxzUZBtLf?= =?us-ascii?Q?Gti1e2lcodmyagfSrY7NkkjwS1v9sVXwWQvbtVtlSRHHZlHhcDucDrN99Y8l?= =?us-ascii?Q?a4PhBklVsBkg73OfAvs1NiMq1beWmHzlc9qjgIVtQDWPmLYd3dJ63oqmf0s3?= =?us-ascii?Q?o5pVrBFqED3FoQ4ajFfoCji5Nk+5E8d4KIMKJwf1tyD9j7g3xr73WnAUBook?= =?us-ascii?Q?8ZkHUhBL+6oilim8Itc+zXMjtX976uFZj7nvbLV52UdJjkqNRZlHSfsuqhFn?= =?us-ascii?Q?WRzslnuA+blSfKPU3qil9p396M499ZtYmew6ADTYIbQP0FxW0IpsejT4ziKi?= =?us-ascii?Q?fkRtOrEBOdhVojymFspN4JMFIH8xC0j/6WUZpjZXwqlqqTAHA7rw8SZ6JwtC?= =?us-ascii?Q?W4VbGE2GAkjOfi6Tl1zSqA0ckPwylw48VN52g/8HKrmAsrpY0HSTRT5Iyg+5?= =?us-ascii?Q?amTWBTh1GaF2gBo+HGwMkBxZAH7VN7BIgaNsxg42dEL3eQIzA2dF30JAUbxz?= =?us-ascii?Q?7+ytY2XSaHUk8sJaAKhPU5eLeuGbmU/8eRbjvEcxrMPPpyA3+/E8nqGpX/Tq?= =?us-ascii?Q?FJwHWVOaLr06v0AUbENTLKKeEzJ4qUZ67xtY+6B6vD7PYk0w/wXR3yRkt1T4?= =?us-ascii?Q?xGVl2kN+EJC6w9TjLcyDsRyv7Fhj0Ki+nOLgHHhj5pVzpQemg1wefk839zV1?= =?us-ascii?Q?Y0OIr0KUNxWrCdAWlztfWj9cMK4a23bUmhrL0YZjte4yNdz6ZcvkufWJIfLp?= =?us-ascii?Q?YvmcOjFwvIZ43tmSQGdWFML+zm0jsUDo/Sjx1RtO/N5/7GirnRJeLLRobilI?= =?us-ascii?Q?kCiz10W6W1d6OdcfPDbfiMgG8wtb6U0hVB0LSzl56QM90wTKpLcWGqdFTBN4?= =?us-ascii?Q?GJh53ZyMigmo7JLqQwXUMVABImEPbCG4zeR8fkwhBQpP+FHUYDLCAGin4S/Z?= =?us-ascii?Q?90QKRF+rWxOKmJ8uYsiX7Q93yocNBVRV3s/7tOhwulXu3yebhFJp/8izzbUr?= =?us-ascii?Q?7P7UyIh+dgnlCWZ+aO2fbhK+vw8/o5+YeRDZE2T+gWqldEeOLb181lf1Nn2D?= =?us-ascii?Q?gWyfJu9tWvqhmZ1WycxdEh+c6kS1jMVENNKqHQ3pMeRAGFufCrRlC6QsIc0O?= =?us-ascii?Q?SmMIS/kiKsQBlu831lQzB5b+TOoeaa/xLrYKG4mu0omIwAb1Xlnt8PDZ28YK?= =?us-ascii?Q?KxLh/SEOLsBpuAOR3+PVLfQEF75eBtFW/EsB8DLHkW6ssq4Zce9EoYeV2Id5?= =?us-ascii?Q?WvIO9YJIm01zfhZo3x700DXrHAtI3+ojCHIVaARtIJWEgCPPWRAV7Ls4Ng4+?= =?us-ascii?Q?ioGZPXPs8uPElxhFzlU60M1EXA4S1MqjNZUodvI7AUCI0jTqKzzzVx+04vLc?= =?us-ascii?Q?tJk9EA0xyZ2OPIPK9a0LcSaN0ySZzb1cPOElxdsP1PHfJcxxoQLAgoKURNHU?= =?us-ascii?Q?/aUpaGwrbsvKATDv/25wOVBnX8+goFrcIqpDeGoJKjyNrOu0g1xEVF2DPUCe?= =?us-ascii?Q?81lrnuhdxuqKbXMwUB/r8a404/Dan6FGQQR8ZjMHGZabQVLr/+EDPYf2CWk4?= =?us-ascii?Q?+rLTC/CQqQ=3D=3D?= X-Exchange-RoutingPolicyChecked: OrSCH2Sul/eFNM/Lj1feFHYeJ9JMrzCjJc7LOclLcg+5kF8njmnQqvQw7tkx27Gqiv49Da8bprk/1DmNIkM7qTE/fXu1cFK+EsZWU7F244TgqUjw2tEPXj46P0SZUgZzzBnlXD46i0YJt0UDtjolAhjSasjOpNuxML9qZitXK/tlGnU8VzecN4E6eRYv8waC12/2MFI05n93uLXKu4M0f88IhMR/8ydT1kCEDpiM6DGhh7dXlHEujjQd8KMTyVYKzLkJCb9Q3mTjiI5NpYsJ/S+PZSsbwHXoPY0G1YHKE6gjCA8sa1t9Y4tfQIIi+XcOPK4y2/f8s+DySdEUY7FASw== X-MS-Exchange-CrossTenant-Network-Message-Id: 95ade267-367f-413c-498d-08deb250996c X-MS-Exchange-CrossTenant-AuthSource: SJ1PR11MB6153.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2026 07:07:17.5554 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mNaBIEpoBMpMhfDReTPyVyTglrDk3/fwlpayHzRGUQhyFHpc6Y145znvkXFC8/QCxRf7hHsckvYxLonEjQ7P3A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR11MB9178 X-OriginatorOrg: intel.com On 2026-05-11 at 21:57:37 +0800, Sicong Huang wrote: > ACRN irqfd registers a custom waitqueue callback on the eventfd. When the > eventfd is released, eventfd_release() wakes the waitqueue with EPOLLHUP, > and hsm_irqfd_wakeup() queues irqfd->shutdown on vm->irqfd_wq. > > The irqfd object can also be removed by ACRN_IOCTL_IRQFD with > ACRN_IRQFD_FLAG_DEASSIGN. In that path, acrn_irqfd_deassign() removes the > waitqueue entry and frees the hsm_irqfd object. > > These two paths can race. If EPOLLHUP queues the shutdown work before > deassign frees the object, the work item may run after kfree() and recover > the freed hsm_irqfd via container_of(). It then dereferences irqfd->vm while > taking irqfds_lock. > > A possible race is: > CPU0 CPU1 > eventfd_release() > wake_up_poll(EPOLLHUP) > hsm_irqfd_wakeup() > queue_work(&irqfd->shutdown) > acrn_irqfd_deassign() > hsm_irqfd_shutdown() > list_del_init() > eventfd_ctx_remove_wait_queue() > kfree(irqfd) //free here! > hsm_irqfd_shutdown_work() > irqfd = container_of(work, ...) > vm = irqfd->vm //UAF! > > Fix this by separating logical shutdown from object release. First remove > the irqfd from the VM list and eventfd waitqueue, then synchronously > cancel any pending/running shutdown work before freeing the object. > Also tear down irqfds before destroying the irqfd workqueue, so > eventfd wakeups cannot queue work after the workqueue has been destroyed. > > Signed-off-by: Sicong Huang Hi Sicong, Thanks for fixing this. The race looks real to me: `EPOLLHUP` can queue `irqfd->shutdown`, while the deassign path can remove the waitqueue entry and free the same irqfd before the work item runs. The direction is good, but I think the lifetime rules can be made simpler. In this version the final `kfree()` can still come from several places, with `list_empty()` and `cancel_work_sync()` deciding who wins. That may work, but it is harder to audit than necessary. Could this follow the KVM irqfd pattern more closely? Deassign/deinit would only deactivate the irqfd, i.e. remove it from the active list and queue cleanup once. The cleanup work would then be the only place that removes the eventfd waitqueue entry, drops the eventfd ref, and frees `struct hsm_irqfd`. The synchronous paths can still flush the workqueue before returning or before destroying `vm->irqfd_wq`. Two smaller comments: - `next` is left unused in `acrn_irqfd_deinit()` after this change. - It may be worth tightening the assign path too, so an irqfd is not visible on `vm->irqfds` before its eventfd waitqueue entry has been installed. Thanks, Fei > --- > drivers/virt/acrn/irqfd.c | 47 ++++++++++++++++++++++++++++++--------- > 1 file changed, 37 insertions(+), 10 deletions(-) > > diff --git a/drivers/virt/acrn/irqfd.c b/drivers/virt/acrn/irqfd.c > index acf8cd5f8f8c..659fd40d9aa5 100644 > --- a/drivers/virt/acrn/irqfd.c > +++ b/drivers/virt/acrn/irqfd.c > @@ -44,30 +44,37 @@ static void acrn_irqfd_inject(struct hsm_irqfd *irqfd) > irqfd->msi.msi_data); > } > > -static void hsm_irqfd_shutdown(struct hsm_irqfd *irqfd) > +static bool hsm_irqfd_shutdown(struct hsm_irqfd *irqfd) > { > u64 cnt; > > lockdep_assert_held(&irqfd->vm->irqfds_lock); > > + if (list_empty(&irqfd->list)) > + return false; > + > /* remove from wait queue */ > list_del_init(&irqfd->list); > eventfd_ctx_remove_wait_queue(irqfd->eventfd, &irqfd->wait, &cnt); > eventfd_ctx_put(irqfd->eventfd); > - kfree(irqfd); > + > + return true; > } > > static void hsm_irqfd_shutdown_work(struct work_struct *work) > { > struct hsm_irqfd *irqfd; > struct acrn_vm *vm; > + bool free; > > irqfd = container_of(work, struct hsm_irqfd, shutdown); > vm = irqfd->vm; > mutex_lock(&vm->irqfds_lock); > - if (!list_empty(&irqfd->list)) > - hsm_irqfd_shutdown(irqfd); > + free = hsm_irqfd_shutdown(irqfd); > mutex_unlock(&vm->irqfds_lock); > + > + if (free) > + kfree(irqfd); > } > > /* Called with wqh->lock held and interrupts disabled */ > @@ -170,7 +177,7 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args) > static int acrn_irqfd_deassign(struct acrn_vm *vm, > struct acrn_irqfd *args) > { > - struct hsm_irqfd *irqfd, *tmp; > + struct hsm_irqfd *irqfd, *tmp, *to_free = NULL; > struct eventfd_ctx *eventfd; > > eventfd = eventfd_ctx_fdget(args->fd); > @@ -180,13 +187,19 @@ static int acrn_irqfd_deassign(struct acrn_vm *vm, > mutex_lock(&vm->irqfds_lock); > list_for_each_entry_safe(irqfd, tmp, &vm->irqfds, list) { > if (irqfd->eventfd == eventfd) { > - hsm_irqfd_shutdown(irqfd); > + if (hsm_irqfd_shutdown(irqfd)) > + to_free = irqfd; > break; > } > } > mutex_unlock(&vm->irqfds_lock); > eventfd_ctx_put(eventfd); > > + if (to_free) { > + cancel_work_sync(&to_free->shutdown); > + kfree(to_free); > + } > + > return 0; > } > > @@ -219,9 +232,23 @@ void acrn_irqfd_deinit(struct acrn_vm *vm) > struct hsm_irqfd *irqfd, *next; > > dev_dbg(acrn_dev.this_device, "VM %u irqfd deinit.\n", vm->vmid); > + > + for (;;) { > + irqfd = NULL; > + > + mutex_lock(&vm->irqfds_lock); > + if (!list_empty(&vm->irqfds)) { > + irqfd = list_first_entry(&vm->irqfds, struct hsm_irqfd, list); > + hsm_irqfd_shutdown(irqfd); > + } > + mutex_unlock(&vm->irqfds_lock); > + > + if (!irqfd) > + break; > + > + cancel_work_sync(&irqfd->shutdown); > + kfree(irqfd); > + } > + > destroy_workqueue(vm->irqfd_wq); > - mutex_lock(&vm->irqfds_lock); > - list_for_each_entry_safe(irqfd, next, &vm->irqfds, list) > - hsm_irqfd_shutdown(irqfd); > - mutex_unlock(&vm->irqfds_lock); > } > -- > 2.34.1 >