[PATCH v2 1/2] backends/iommufd.c: report error when /dev/iommu is not available

Pierrick Bouvier posted 2 patches 2 weeks, 4 days ago
Maintainers: Yi Liu <yi.l.liu@intel.com>, Eric Auger <eric.auger@redhat.com>, Zhenzhong Duan <zhenzhong.duan@intel.com>, Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>
There is a newer version of this series
[PATCH v2 1/2] backends/iommufd.c: report error when /dev/iommu is not available
Posted by Pierrick Bouvier 2 weeks, 4 days ago
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é <philmd@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 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


RE: [PATCH v2 1/2] backends/iommufd.c: report error when /dev/iommu is not available
Posted by Duan, Zhenzhong 2 weeks, 4 days ago

>-----Original Message-----
>From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>Subject: [PATCH v2 1/2] backends/iommufd.c: report error when /dev/iommu is
>not available
>
>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é <philmd@linaro.org>
>Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>---
> 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);

I think more accurately it could be:

@@ -82,7 +82,12 @@ static void iommufd_backend_complete(UserCreatable *uc, Error **errp)
         } else {
             cpr_save_fd(name, 0, be->fd);
         }
+    } else 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;
     }
+
 }

Thanks
Zhenzhong
Re: [PATCH v2 1/2] backends/iommufd.c: report error when /dev/iommu is not available
Posted by Pierrick Bouvier 2 weeks, 3 days ago
On 3/19/26 1:35 AM, Duan, Zhenzhong wrote:
> 
> 
>> -----Original Message-----
>> From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> Subject: [PATCH v2 1/2] backends/iommufd.c: report error when /dev/iommu is
>> not available
>>
>> 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é <philmd@linaro.org>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>> 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);
> 
> I think more accurately it could be:
> 
> @@ -82,7 +82,12 @@ static void iommufd_backend_complete(UserCreatable *uc, Error **errp)
>           } else {
>               cpr_save_fd(name, 0, be->fd);
>           }
> +    } else 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;
>       }
> +
>   }
> 
> Thanks
> Zhenzhong

Good for me, will send v3.

Regards,
Pierrick

Re: [PATCH v2 1/2] backends/iommufd.c: report error when /dev/iommu is not available
Posted by Cédric Le Goater 2 weeks, 4 days ago
On 3/18/26 19:06, Pierrick Bouvier wrote:
> 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é <philmd@linaro.org>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   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);
>   

Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.