In case current kernel does not support /dev/iommu, qemu will probably fail first because /sys/bus/pci/devices/*/vfio-dev/ is not present, since QEMU opens it before /dev/iommu.
Instead, report an error directly when completing an iommufd object, to inform user that kernel does not support it, with a hint about missing CONFIG_IOMMUFD. We can't do this from initialize as there is no way to return an error, and we don't want to abort at this step. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Pierrick Bouvier <[email protected]> --- backends/iommufd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backends/iommufd.c b/backends/iommufd.c index acfab907c03..2c3ca23ca0f 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -72,6 +72,12 @@ static bool iommufd_backend_can_be_deleted(UserCreatable *uc) static void iommufd_backend_complete(UserCreatable *uc, Error **errp) { + if (!g_file_test("/dev/iommu", G_FILE_TEST_EXISTS)) { + error_setg(errp, "/dev/iommu does not exist" + " (is your kernel config missing CONFIG_IOMMUFD?)"); + return; + } + IOMMUFDBackend *be = IOMMUFD_BACKEND(uc); const char *name = iommufd_fd_name(be); -- 2.47.3
