[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250516164522.51905-1-jacob.pan@linux.microsoft.com>
Date: Fri, 16 May 2025 09:45:21 -0700
From: Jacob Pan <jacob.pan@...ux.microsoft.com>
To: linux-kernel@...r.kernel.org,
"iommu@...ts.linux.dev" <iommu@...ts.linux.dev>,
Alex Williamson <alex.williamson@...hat.com>,
"Liu, Yi L" <yi.l.liu@...el.com>,
"jgg@...dia.com" <jgg@...dia.com>,
Jacob Pan <jacob.pan@...ux.microsoft.com>
Cc: Zhang Yu <zhangyu1@...rosoft.com>,
Easwar Hariharan <eahariha@...ux.microsoft.com>
Subject: [PATCH 1/2] vfio: Fix unbalanced vfio_df_close call in no-iommu mode
For no-iommu enabled devices working under IOMMUFD VFIO compat mode, the
group open path does not call vfio_df_open() and the open_count is 0. So
calling vfio_df_close() in the group close path will trigger warning in
vfio_assert_device_open(device);
E.g. The following warning can be seen by running VFIO test.
https://github.com/awilliam/tests/blob/master/vfio-noiommu-pci-device-open.c
CONFIG_VFIO_CONTAINER = n
[ 29.094781] vfio-pci 0000:02:01.0: vfio-noiommu device opened by user (vfio-noiommu-pc:164)
Failed to get device info
[ 29.096540] ------------[ cut here ]------------
[ 29.096616] WARNING: CPU: 1 PID: 164 at drivers/vfio/vfio_main.c:487 vfio_df_close+0xac/0xb4
This patch adds checks for no-iommu mode and open_count to skip calling vfio_df_close.
Signed-off-by: Jacob Pan <jacob.pan@...ux.microsoft.com>
---
drivers/vfio/group.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c
index c321d442f0da..834421149ffe 100644
--- a/drivers/vfio/group.c
+++ b/drivers/vfio/group.c
@@ -238,12 +238,13 @@ void vfio_df_group_close(struct vfio_device_file *df)
mutex_lock(&device->group->group_lock);
mutex_lock(&device->dev_set->lock);
- vfio_df_close(df);
- df->iommufd = NULL;
-
if (device->open_count == 0)
vfio_device_put_kvm(device);
+ if (!vfio_device_is_noiommu(device))
+ vfio_df_close(df);
+
+ df->iommufd = NULL;
mutex_unlock(&device->dev_set->lock);
mutex_unlock(&device->group->group_lock);
}
--
2.34.1
Powered by blists - more mailing lists