Re: [PATCH 14/14] iommufd/selftest: Add test to verify iommufd preservation

Samiullah Khawaja
2026-03-27T18:40:16Z

On Fri, Mar 27, 2026 at 06:25:36PM +0000, Samiullah Khawaja wrote:
>On Wed, Mar 25, 2026 at 09:05:32PM +0000, Pranjal Shrivastava wrote:
>>On Tue, Feb 03, 2026 at 10:09:48PM +0000, Samiullah Khawaja wrote:
>>>Test iommufd preservation by setting up an iommufd and vfio cdev and
>>>preserve it across live update. Test takes VFIO cdev path of a device
>>>bound to vfio-pci driver and binds it to an iommufd being preserved. It
>>>also preserves the vfio cdev so the iommufd state associated with it is
>>>also preserved.
>>>
>>>The restore path is tested by restoring the preserved vfio cdev only.
>>>Test tries to finish the session without restoring iommufd and confirms
>>>that it fails.
>>>
>>>Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
>>>Signed-off-by: YiFei Zhu <zhuyifei@google.com>
>>>---
>>> tools/testing/selftests/iommu/Makefile | 12 +
>>> .../selftests/iommu/iommufd_liveupdate.c | 209 ++++++++++++++++++
>>> 2 files changed, 221 insertions(+)
>>> create mode 100644 tools/testing/selftests/iommu/iommufd_liveupdate.c
>>>
>>>+int main(int argc, char *argv[])
>>
>>The iommufd selftest directory heavily utilizes the standard kselftest
>>harness (TEST_F, EXPECT_EQ, ASSERT_EQ), by writing a raw main(), this
>>patch circumvents the standard test reporting structure (like returning 1
>>on argc < 2 instead of ksft_exit_skip(), and returning 0 at the end
>>instead of ksft_exit_pass() etc.). We should rewrite this cleanly
>>following the existing iommufd test infrastructure using TEST_F blocks.
>
>Agreed. Will do.

Thinking about this more, these liveupdate tests are two stage tests.
There is a run before liveupdate and there is a run after liveupdate. I
will have to use the luo_test mechanism here for this test. See example
usage in the kexec_test in the VFIO cdev preservation series:

https://lore.kernel.org/all/20260323235817.1960573-21-dmatlack@google.com
>>
>>>+{
>>>+ int iommufd, cdev_fd, memfd, luo, session, ret;
>>>+ const int token = 0x123456;
>>>+ const int cdev_token = 0x654321;
>>>+ const int hwpt_token = 0x789012;
>>>+ const int memfd_token = 0x890123;
>>
>>Shouldn't these be u64? Defining them as signed int-s undermines that
>>contract?
>
>Agreed. Will update.
>>
>>>+
>>>+ if (argc < 2) {
>>>+ printf("Usage: ./iommufd_liveupdate <vfio_cdev_path>\n");
>>>+ return 1;
>>>+ }
>>>+
>>>+ luo = luo_open_device();
>>>+ ksft_assert(luo > 0);
>>>+
>>>+ session = luo_retrieve_session(luo, "iommufd-test");
>>
>>[ ---- >8 ---- ]
>>
>>Thanks,
>>Praan
>
>Thanks,
>Sami