public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PATCH 0/2] iommufd: give hints to user about kernel support
@ 2026-03-17 22:57 Pierrick Bouvier
  2026-03-17 22:57 ` [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available Pierrick Bouvier
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Pierrick Bouvier @ 2026-03-17 22:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Cédric Le Goater, Zhenzhong Duan, Yi Liu, Alex Williamson,
	Eric Auger, philmd, Pierrick Bouvier

Using iommufd requires two different kernel config:
CONFIG_IOMMUFD and CONFIG_VFIO_DEVICE_CDEV
https://docs.kernel.org/driver-api/vfio.html#vfio-device-cdev

It can be complex to identify what is missing when trying to use it. This series
gives hints to user about it.

Suggested on:
https://lore.kernel.org/qemu-devel/0cc139d6-9289-44a0-9122-d701426dae0c@linaro.org/

Tested using a cross compiled QEMU and a custom kernel + debian rootfs [1].

[1] https://github.com/p-b-o/qemu-linux-stack/tree/device_passthrough

Pierrick Bouvier (2):
  backends/iommufd.c: report error when /dev/iommu is not available
  hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is
    missing

 backends/iommufd.c | 5 +++++
 hw/vfio/iommufd.c  | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

-- 
2.47.3



^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available
  2026-03-17 22:57 [PATCH 0/2] iommufd: give hints to user about kernel support Pierrick Bouvier
@ 2026-03-17 22:57 ` Pierrick Bouvier
  2026-03-18  6:45   ` Philippe Mathieu-Daudé
  2026-03-18  7:36   ` Duan, Zhenzhong
  2026-03-17 22:57 ` [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing Pierrick Bouvier
  2026-03-18 18:13 ` [PATCH 0/2] iommufd: give hints to user about kernel support Pierrick Bouvier
  2 siblings, 2 replies; 14+ messages in thread
From: Pierrick Bouvier @ 2026-03-17 22:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Cédric Le Goater, Zhenzhong Duan, Yi Liu, Alex Williamson,
	Eric Auger, philmd, Pierrick Bouvier

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 initializing iommufd object, to
inform user that kernel does not support it, with a hint about missing
CONFIG_IOMMUFD.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 backends/iommufd.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/backends/iommufd.c b/backends/iommufd.c
index acfab907c03..c4eb3de1307 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -32,6 +32,11 @@ static void iommufd_backend_init(Object *obj)
 {
     IOMMUFDBackend *be = IOMMUFD_BACKEND(obj);
 
+    if (!g_file_test("/dev/iommu", G_FILE_TEST_EXISTS)) {
+        error_setg(&error_fatal, "/dev/iommu does not exist"
+                                 " (is your kernel config missing CONFIG_IOMMUFD?)");
+    }
+
     be->fd = -1;
     be->users = 0;
     be->owned = true;
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing
  2026-03-17 22:57 [PATCH 0/2] iommufd: give hints to user about kernel support Pierrick Bouvier
  2026-03-17 22:57 ` [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available Pierrick Bouvier
@ 2026-03-17 22:57 ` Pierrick Bouvier
  2026-03-18  6:44   ` Philippe Mathieu-Daudé
                     ` (3 more replies)
  2026-03-18 18:13 ` [PATCH 0/2] iommufd: give hints to user about kernel support Pierrick Bouvier
  2 siblings, 4 replies; 14+ messages in thread
From: Pierrick Bouvier @ 2026-03-17 22:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Cédric Le Goater, Zhenzhong Duan, Yi Liu, Alex Williamson,
	Eric Auger, philmd, Pierrick Bouvier

Give a hint about missing kernel config CONFIG_VFIO_DEVICE_CDEV.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 hw/vfio/iommufd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 131612eb836..3e33dfbb356 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -274,7 +274,10 @@ static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp)
     }
 
     if (!g_file_get_contents(vfio_dev_path, &contents, &length, NULL)) {
-        error_setg(errp, "failed to load \"%s\"", vfio_dev_path);
+        error_setg(errp,
+                   "failed to load \"%s\""
+                   " (is your kernel config missing CONFIG_VFIO_DEVICE_CDEV?)",
+                   vfio_dev_path);
         goto out_close_dir;
     }
 
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing
  2026-03-17 22:57 ` [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing Pierrick Bouvier
@ 2026-03-18  6:44   ` Philippe Mathieu-Daudé
  2026-03-18  8:10   ` Cédric Le Goater
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-03-18  6:44 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Cédric Le Goater, Zhenzhong Duan, Yi Liu, Alex Williamson,
	Eric Auger

On 17/3/26 23:57, Pierrick Bouvier wrote:
> Give a hint about missing kernel config CONFIG_VFIO_DEVICE_CDEV.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   hw/vfio/iommufd.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available
  2026-03-17 22:57 ` [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available Pierrick Bouvier
@ 2026-03-18  6:45   ` Philippe Mathieu-Daudé
  2026-03-18  7:36   ` Duan, Zhenzhong
  1 sibling, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-03-18  6:45 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Cédric Le Goater, Zhenzhong Duan, Yi Liu, Alex Williamson,
	Eric Auger

On 17/3/26 23:57, 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 initializing iommufd object, to
> inform user that kernel does not support it, with a hint about missing
> CONFIG_IOMMUFD.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   backends/iommufd.c | 5 +++++
>   1 file changed, 5 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available
  2026-03-17 22:57 ` [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available Pierrick Bouvier
  2026-03-18  6:45   ` Philippe Mathieu-Daudé
@ 2026-03-18  7:36   ` Duan, Zhenzhong
  2026-03-18  8:08     ` Cédric Le Goater
  1 sibling, 1 reply; 14+ messages in thread
From: Duan, Zhenzhong @ 2026-03-18  7:36 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel@nongnu.org
  Cc: Cédric Le Goater, Liu, Yi L, Alex Williamson, Eric Auger,
	philmd@linaro.org



>-----Original Message-----
>From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>Subject: [PATCH 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 initializing iommufd object, to
>inform user that kernel does not support it, with a hint about missing
>CONFIG_IOMMUFD.
>
>Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>---
> backends/iommufd.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
>diff --git a/backends/iommufd.c b/backends/iommufd.c
>index acfab907c03..c4eb3de1307 100644
>--- a/backends/iommufd.c
>+++ b/backends/iommufd.c
>@@ -32,6 +32,11 @@ static void iommufd_backend_init(Object *obj)
> {
>     IOMMUFDBackend *be = IOMMUFD_BACKEND(obj);
>
>+    if (!g_file_test("/dev/iommu", G_FILE_TEST_EXISTS)) {
>+        error_setg(&error_fatal, "/dev/iommu does not exist"
>+                                 " (is your kernel config missing CONFIG_IOMMUFD?)");

If hot add an iommufd object with object_add QMP, may this kill QEMU instance?

Thanks
Zhenzhong

>+    }
>+
>     be->fd = -1;
>     be->users = 0;
>     be->owned = true;
>--
>2.47.3



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available
  2026-03-18  7:36   ` Duan, Zhenzhong
@ 2026-03-18  8:08     ` Cédric Le Goater
  2026-03-18  8:37       ` Duan, Zhenzhong
  0 siblings, 1 reply; 14+ messages in thread
From: Cédric Le Goater @ 2026-03-18  8:08 UTC (permalink / raw)
  To: Duan, Zhenzhong, Pierrick Bouvier, qemu-devel@nongnu.org
  Cc: Liu, Yi L, Alex Williamson, Eric Auger, philmd@linaro.org

On 3/18/26 08:36, Duan, Zhenzhong wrote:
> 
> 
>> -----Original Message-----
>> From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> Subject: [PATCH 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 initializing iommufd object, to
>> inform user that kernel does not support it, with a hint about missing
>> CONFIG_IOMMUFD.
>>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>> backends/iommufd.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/backends/iommufd.c b/backends/iommufd.c
>> index acfab907c03..c4eb3de1307 100644
>> --- a/backends/iommufd.c
>> +++ b/backends/iommufd.c
>> @@ -32,6 +32,11 @@ static void iommufd_backend_init(Object *obj)
>> {
>>      IOMMUFDBackend *be = IOMMUFD_BACKEND(obj);
>>
>> +    if (!g_file_test("/dev/iommu", G_FILE_TEST_EXISTS)) {
>> +        error_setg(&error_fatal, "/dev/iommu does not exist"
>> +                                 " (is your kernel config missing CONFIG_IOMMUFD?)");
> 
> If hot add an iommufd object with object_add QMP, may this kill QEMU instance?

yes.


Unfortunately, backends are Objects. So we don't have a realize
handler and a 'Error **' parameter :/

Thanks,

C.



> 
> Thanks
> Zhenzhong
> 
>> +    }
>> +
>>      be->fd = -1;
>>      be->users = 0;
>>      be->owned = true;
>> --
>> 2.47.3
> 



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing
  2026-03-17 22:57 ` [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing Pierrick Bouvier
  2026-03-18  6:44   ` Philippe Mathieu-Daudé
@ 2026-03-18  8:10   ` Cédric Le Goater
  2026-03-18  8:41   ` Duan, Zhenzhong
  2026-03-18 12:45   ` Yi Liu
  3 siblings, 0 replies; 14+ messages in thread
From: Cédric Le Goater @ 2026-03-18  8:10 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Zhenzhong Duan, Yi Liu, Alex Williamson, Eric Auger, philmd

On 3/17/26 23:57, Pierrick Bouvier wrote:
> Give a hint about missing kernel config CONFIG_VFIO_DEVICE_CDEV.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   hw/vfio/iommufd.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 131612eb836..3e33dfbb356 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -274,7 +274,10 @@ static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp)
>       }
>   
>       if (!g_file_get_contents(vfio_dev_path, &contents, &length, NULL)) {
> -        error_setg(errp, "failed to load \"%s\"", vfio_dev_path);
> +        error_setg(errp,
> +                   "failed to load \"%s\""
> +                   " (is your kernel config missing CONFIG_VFIO_DEVICE_CDEV?)",
> +                   vfio_dev_path);
>           goto out_close_dir;
>       }
>   

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

Thanks,

C.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available
  2026-03-18  8:08     ` Cédric Le Goater
@ 2026-03-18  8:37       ` Duan, Zhenzhong
  2026-03-18 12:18         ` Cédric Le Goater
  0 siblings, 1 reply; 14+ messages in thread
From: Duan, Zhenzhong @ 2026-03-18  8:37 UTC (permalink / raw)
  To: Cédric Le Goater, Pierrick Bouvier, qemu-devel@nongnu.org
  Cc: Liu, Yi L, Alex Williamson, Eric Auger, philmd@linaro.org



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: Re: [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is
>not available
>
>On 3/18/26 08:36, Duan, Zhenzhong wrote:
>>
>>
>>> -----Original Message-----
>>> From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>> Subject: [PATCH 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 initializing iommufd object, to
>>> inform user that kernel does not support it, with a hint about missing
>>> CONFIG_IOMMUFD.
>>>
>>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>> ---
>>> backends/iommufd.c | 5 +++++
>>> 1 file changed, 5 insertions(+)
>>>
>>> diff --git a/backends/iommufd.c b/backends/iommufd.c
>>> index acfab907c03..c4eb3de1307 100644
>>> --- a/backends/iommufd.c
>>> +++ b/backends/iommufd.c
>>> @@ -32,6 +32,11 @@ static void iommufd_backend_init(Object *obj)
>>> {
>>>      IOMMUFDBackend *be = IOMMUFD_BACKEND(obj);
>>>
>>> +    if (!g_file_test("/dev/iommu", G_FILE_TEST_EXISTS)) {
>>> +        error_setg(&error_fatal, "/dev/iommu does not exist"
>>> +                                 " (is your kernel config missing CONFIG_IOMMUFD?)");
>>
>> If hot add an iommufd object with object_add QMP, may this kill QEMU
>instance?
>
>yes.
>
>
>Unfortunately, backends are Objects. So we don't have a realize
>handler and a 'Error **' parameter :/

Maybe do it in iommufd_backend_complete()?

Thanks
Zhenzhong

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing
  2026-03-17 22:57 ` [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing Pierrick Bouvier
  2026-03-18  6:44   ` Philippe Mathieu-Daudé
  2026-03-18  8:10   ` Cédric Le Goater
@ 2026-03-18  8:41   ` Duan, Zhenzhong
  2026-03-18 12:45   ` Yi Liu
  3 siblings, 0 replies; 14+ messages in thread
From: Duan, Zhenzhong @ 2026-03-18  8:41 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel@nongnu.org
  Cc: Cédric Le Goater, Liu, Yi L, Alex Williamson, Eric Auger,
	philmd@linaro.org



>-----Original Message-----
>From: Pierrick Bouvier <pierrick.bouvier@linaro.org>

>Subject: [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-
>dev/vfio*/dev is missing
>
>Give a hint about missing kernel config CONFIG_VFIO_DEVICE_CDEV.
>
>Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>

Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>

Zhenzhong


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available
  2026-03-18  8:37       ` Duan, Zhenzhong
@ 2026-03-18 12:18         ` Cédric Le Goater
  2026-03-18 18:08           ` Pierrick Bouvier
  0 siblings, 1 reply; 14+ messages in thread
From: Cédric Le Goater @ 2026-03-18 12:18 UTC (permalink / raw)
  To: Duan, Zhenzhong, Pierrick Bouvier, qemu-devel@nongnu.org
  Cc: Liu, Yi L, Alex Williamson, Eric Auger, philmd@linaro.org

On 3/18/26 09:37, Duan, Zhenzhong wrote:
> 
> 
>> -----Original Message-----
>> From: Cédric Le Goater <clg@redhat.com>
>> Subject: Re: [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is
>> not available
>>
>> On 3/18/26 08:36, Duan, Zhenzhong wrote:
>>>
>>>
>>>> -----Original Message-----
>>>> From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>>> Subject: [PATCH 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 initializing iommufd object, to
>>>> inform user that kernel does not support it, with a hint about missing
>>>> CONFIG_IOMMUFD.
>>>>
>>>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>>> ---
>>>> backends/iommufd.c | 5 +++++
>>>> 1 file changed, 5 insertions(+)
>>>>
>>>> diff --git a/backends/iommufd.c b/backends/iommufd.c
>>>> index acfab907c03..c4eb3de1307 100644
>>>> --- a/backends/iommufd.c
>>>> +++ b/backends/iommufd.c
>>>> @@ -32,6 +32,11 @@ static void iommufd_backend_init(Object *obj)
>>>> {
>>>>       IOMMUFDBackend *be = IOMMUFD_BACKEND(obj);
>>>>
>>>> +    if (!g_file_test("/dev/iommu", G_FILE_TEST_EXISTS)) {
>>>> +        error_setg(&error_fatal, "/dev/iommu does not exist"
>>>> +                                 " (is your kernel config missing CONFIG_IOMMUFD?)");
>>>
>>> If hot add an iommufd object with object_add QMP, may this kill QEMU
>> instance?
>>
>> yes.
>>
>>
>> Unfortunately, backends are Objects. So we don't have a realize
>> handler and a 'Error **' parameter :/
> 
> Maybe do it in iommufd_backend_complete()?
Yep. Perfect.

Pierrick,

Can you please move the test under the complete handler ?
May be add a  #define for "/dev/iommu" while at it.

Thanks,

C.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing
  2026-03-17 22:57 ` [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing Pierrick Bouvier
                     ` (2 preceding siblings ...)
  2026-03-18  8:41   ` Duan, Zhenzhong
@ 2026-03-18 12:45   ` Yi Liu
  3 siblings, 0 replies; 14+ messages in thread
From: Yi Liu @ 2026-03-18 12:45 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: Cédric Le Goater, Zhenzhong Duan, Alex Williamson,
	Eric Auger, philmd

On 3/18/26 06:57, Pierrick Bouvier wrote:
> Give a hint about missing kernel config CONFIG_VFIO_DEVICE_CDEV.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   hw/vfio/iommufd.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 131612eb836..3e33dfbb356 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -274,7 +274,10 @@ static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp)
>       }
>   
>       if (!g_file_get_contents(vfio_dev_path, &contents, &length, NULL)) {
> -        error_setg(errp, "failed to load \"%s\"", vfio_dev_path);
> +        error_setg(errp,
> +                   "failed to load \"%s\""
> +                   " (is your kernel config missing CONFIG_VFIO_DEVICE_CDEV?)",
> +                   vfio_dev_path);
>           goto out_close_dir;
>       }
>   

Reviewed-by: Yi Liu <yi.l.liu@intel.com>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available
  2026-03-18 12:18         ` Cédric Le Goater
@ 2026-03-18 18:08           ` Pierrick Bouvier
  0 siblings, 0 replies; 14+ messages in thread
From: Pierrick Bouvier @ 2026-03-18 18:08 UTC (permalink / raw)
  To: Cédric Le Goater, Duan, Zhenzhong, qemu-devel@nongnu.org
  Cc: Liu, Yi L, Alex Williamson, Eric Auger, philmd@linaro.org

On 3/18/26 5:18 AM, Cédric Le Goater wrote:
> On 3/18/26 09:37, Duan, Zhenzhong wrote:
>>
>>
>>> -----Original Message-----
>>> From: Cédric Le Goater <clg@redhat.com>
>>> Subject: Re: [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is
>>> not available
>>>
>>> On 3/18/26 08:36, Duan, Zhenzhong wrote:
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>>>> Subject: [PATCH 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 initializing iommufd object, to
>>>>> inform user that kernel does not support it, with a hint about missing
>>>>> CONFIG_IOMMUFD.
>>>>>
>>>>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>>>> ---
>>>>> backends/iommufd.c | 5 +++++
>>>>> 1 file changed, 5 insertions(+)
>>>>>
>>>>> diff --git a/backends/iommufd.c b/backends/iommufd.c
>>>>> index acfab907c03..c4eb3de1307 100644
>>>>> --- a/backends/iommufd.c
>>>>> +++ b/backends/iommufd.c
>>>>> @@ -32,6 +32,11 @@ static void iommufd_backend_init(Object *obj)
>>>>> {
>>>>>        IOMMUFDBackend *be = IOMMUFD_BACKEND(obj);
>>>>>
>>>>> +    if (!g_file_test("/dev/iommu", G_FILE_TEST_EXISTS)) {
>>>>> +        error_setg(&error_fatal, "/dev/iommu does not exist"
>>>>> +                                 " (is your kernel config missing CONFIG_IOMMUFD?)");
>>>>
>>>> If hot add an iommufd object with object_add QMP, may this kill QEMU
>>> instance?
>>>
>>> yes.
>>>

Good point, I didn't think about it.

>>>
>>> Unfortunately, backends are Objects. So we don't have a realize
>>> handler and a 'Error **' parameter :/
>>
>> Maybe do it in iommufd_backend_complete()?
> Yep. Perfect.
> 
> Pierrick,
> 
> Can you please move the test under the complete handler ?
> May be add a  #define for "/dev/iommu" while at it.
> 

Yes, it works as expected.
I was not sure when the "complete" phase would be called, but it's still 
triggered before trying to open vfio-dev/vfio*/dev, so all good for me!

> Thanks,
> 
> C.
> 
> 
> 

Regards,
Pierrick


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/2] iommufd: give hints to user about kernel support
  2026-03-17 22:57 [PATCH 0/2] iommufd: give hints to user about kernel support Pierrick Bouvier
  2026-03-17 22:57 ` [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available Pierrick Bouvier
  2026-03-17 22:57 ` [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing Pierrick Bouvier
@ 2026-03-18 18:13 ` Pierrick Bouvier
  2 siblings, 0 replies; 14+ messages in thread
From: Pierrick Bouvier @ 2026-03-18 18:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Cédric Le Goater, Zhenzhong Duan, Yi Liu, Alex Williamson,
	Eric Auger, philmd

On 3/17/26 3:57 PM, Pierrick Bouvier wrote:
> Using iommufd requires two different kernel config:
> CONFIG_IOMMUFD and CONFIG_VFIO_DEVICE_CDEV
> https://docs.kernel.org/driver-api/vfio.html#vfio-device-cdev
> 
> It can be complex to identify what is missing when trying to use it. This series
> gives hints to user about it.
> 
> Suggested on:
> https://lore.kernel.org/qemu-devel/0cc139d6-9289-44a0-9122-d701426dae0c@linaro.org/
> 
> Tested using a cross compiled QEMU and a custom kernel + debian rootfs [1].
> 
> [1] https://github.com/p-b-o/qemu-linux-stack/tree/device_passthrough
> 
> Pierrick Bouvier (2):
>    backends/iommufd.c: report error when /dev/iommu is not available
>    hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is
>      missing
> 
>   backends/iommufd.c | 5 +++++
>   hw/vfio/iommufd.c  | 5 ++++-
>   2 files changed, 9 insertions(+), 1 deletion(-)
> 

Sent v2, moving the /dev/iommu check to iommu_backend_complete:
https://lore.kernel.org/qemu-devel/20260318180641.1797902-1-pierrick.bouvier@linaro.org/T/#t

Regards,
Pierrick


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-03-18 18:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17 22:57 [PATCH 0/2] iommufd: give hints to user about kernel support Pierrick Bouvier
2026-03-17 22:57 ` [PATCH 1/2] backends/iommufd.c: report error when /dev/iommu is not available Pierrick Bouvier
2026-03-18  6:45   ` Philippe Mathieu-Daudé
2026-03-18  7:36   ` Duan, Zhenzhong
2026-03-18  8:08     ` Cédric Le Goater
2026-03-18  8:37       ` Duan, Zhenzhong
2026-03-18 12:18         ` Cédric Le Goater
2026-03-18 18:08           ` Pierrick Bouvier
2026-03-17 22:57 ` [PATCH 2/2] hw/vfio/iommufd.c: report hint to user when vfio-dev/vfio*/dev is missing Pierrick Bouvier
2026-03-18  6:44   ` Philippe Mathieu-Daudé
2026-03-18  8:10   ` Cédric Le Goater
2026-03-18  8:41   ` Duan, Zhenzhong
2026-03-18 12:45   ` Yi Liu
2026-03-18 18:13 ` [PATCH 0/2] iommufd: give hints to user about kernel support Pierrick Bouvier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox