[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260129212510.967611-22-dmatlack@google.com>
Date: Thu, 29 Jan 2026 21:25:08 +0000
From: David Matlack <dmatlack@...gle.com>
To: Alex Williamson <alex@...zbot.org>
Cc: Adithya Jayachandran <ajayachandra@...dia.com>, Alexander Graf <graf@...zon.com>,
Alex Mastro <amastro@...com>, Alistair Popple <apopple@...dia.com>,
Andrew Morton <akpm@...ux-foundation.org>, Ankit Agrawal <ankita@...dia.com>,
Bjorn Helgaas <bhelgaas@...gle.com>, Chris Li <chrisl@...nel.org>,
David Matlack <dmatlack@...gle.com>, David Rientjes <rientjes@...gle.com>,
Jacob Pan <jacob.pan@...ux.microsoft.com>, Jason Gunthorpe <jgg@...dia.com>,
Jason Gunthorpe <jgg@...pe.ca>, Jonathan Corbet <corbet@....net>, Josh Hilke <jrhilke@...gle.com>,
Kevin Tian <kevin.tian@...el.com>, kexec@...ts.infradead.org, kvm@...r.kernel.org,
Leon Romanovsky <leon@...nel.org>, Leon Romanovsky <leonro@...dia.com>, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
linux-mm@...ck.org, linux-pci@...r.kernel.org, Lukas Wunner <lukas@...ner.de>,
"Michał Winiarski" <michal.winiarski@...el.com>, Mike Rapoport <rppt@...nel.org>,
Parav Pandit <parav@...dia.com>, Pasha Tatashin <pasha.tatashin@...een.com>,
Pranjal Shrivastava <praan@...gle.com>, Pratyush Yadav <pratyush@...nel.org>,
Raghavendra Rao Ananta <rananta@...gle.com>, Rodrigo Vivi <rodrigo.vivi@...el.com>,
Saeed Mahameed <saeedm@...dia.com>, Samiullah Khawaja <skhawaja@...gle.com>,
Shuah Khan <skhan@...uxfoundation.org>,
"Thomas Hellström" <thomas.hellstrom@...ux.intel.com>, Tomita Moeko <tomitamoeko@...il.com>,
Vipin Sharma <vipinsh@...gle.com>, Vivek Kasireddy <vivek.kasireddy@...el.com>,
William Tu <witu@...dia.com>, Yi Liu <yi.l.liu@...el.com>, Zhu Yanjun <yanjun.zhu@...ux.dev>
Subject: [PATCH v2 21/22] vfio: selftests: Verify that opening VFIO device
fails during Live Update
Verify that opening a VFIO device through its cdev file and via
VFIO_GROUP_GET_DEVICE_FD both fail with -EBUSY if the device was
preserved across a Live Update. When a device file is preserve across a
Live Update, the file must be retrieved from /dev/liveupdate, not from
VFIO directly.
Signed-off-by: David Matlack <dmatlack@...gle.com>
---
.../vfio/vfio_pci_liveupdate_kexec_test.c | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c b/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c
index 15b3e3af91d1..65c48196e44e 100644
--- a/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c
+++ b/tools/testing/selftests/vfio/vfio_pci_liveupdate_kexec_test.c
@@ -36,6 +36,42 @@ static void before_kexec(int luo_fd)
daemonize_and_wait();
}
+static void check_open_vfio_device_fails(void)
+{
+ const char *cdev_path = vfio_pci_get_cdev_path(device_bdf);
+ struct vfio_pci_device *device;
+ struct iommu *iommu;
+ int ret, i;
+
+ printf("Checking open(%s) fails\n", cdev_path);
+ ret = open(cdev_path, O_RDWR);
+ VFIO_ASSERT_EQ(ret, -1);
+ VFIO_ASSERT_EQ(errno, EBUSY);
+ free((void *)cdev_path);
+
+ for (i = 0; i < nr_iommu_modes; i++) {
+ if (!iommu_modes[i].container_path)
+ continue;
+
+ iommu = iommu_init(iommu_modes[i].name);
+
+ device = vfio_pci_device_alloc(device_bdf, iommu);
+ vfio_pci_group_setup(device);
+ vfio_pci_iommu_setup(device);
+
+ printf("Checking ioctl(group_fd, VFIO_GROUP_GET_DEVICE_FD, \"%s\") fails (%s)\n",
+ device_bdf, iommu_modes[i].name);
+
+ ret = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, device->bdf);
+ VFIO_ASSERT_EQ(ret, -1);
+ VFIO_ASSERT_EQ(errno, EBUSY);
+
+ close(device->group_fd);
+ free(device);
+ iommu_cleanup(iommu);
+ }
+}
+
static void after_kexec(int luo_fd, int state_session_fd)
{
struct vfio_pci_device *device;
@@ -44,6 +80,8 @@ static void after_kexec(int luo_fd, int state_session_fd)
int device_fd;
int stage;
+ check_open_vfio_device_fails();
+
restore_and_read_stage(state_session_fd, STATE_TOKEN, &stage);
VFIO_ASSERT_EQ(stage, 2);
--
2.53.0.rc1.225.gd81095ad13-goog
Powered by blists - more mailing lists