drivers/xen/grant-dma-ops.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Dom0 inherit devices from the machine and is usually in PV mode.
If we are running in a virtual that has virtio devices, these devices
would be considered as using grants with Dom0 as backend, while being
the said Dom0 itself, while we want to use these devices like regular
PCI devices.
Fix this by preventing grant-dma-ops from being used when running as Dom0
(initial domain). We still keep the device-tree logic as-is.
Signed-off-by: Teddy Astie <teddy.astie@vates.tech>
Fixes: 61367688f1fb0 ("xen/virtio: enable grant based virtio on x86")
---
CC: Juergen Gross <jgross@suse.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
drivers/xen/grant-dma-ops.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c
index 14077d23f2a1..c2603e700178 100644
--- a/drivers/xen/grant-dma-ops.c
+++ b/drivers/xen/grant-dma-ops.c
@@ -366,7 +366,8 @@ static int xen_grant_init_backend_domid(struct device *dev,
if (np) {
ret = xen_dt_grant_init_backend_domid(dev, np, backend_domid);
of_node_put(np);
- } else if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) || xen_pv_domain()) {
+ } else if (!xen_initial_domain() &&
+ (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) || xen_pv_domain())) {
dev_info(dev, "Using dom0 as backend\n");
*backend_domid = 0;
ret = 0;
--
2.52.0
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
On 06.01.26 18:36, Teddy Astie wrote:
> Dom0 inherit devices from the machine and is usually in PV mode.
> If we are running in a virtual that has virtio devices, these devices
> would be considered as using grants with Dom0 as backend, while being
> the said Dom0 itself, while we want to use these devices like regular
> PCI devices.
>
> Fix this by preventing grant-dma-ops from being used when running as Dom0
> (initial domain). We still keep the device-tree logic as-is.
>
> Signed-off-by: Teddy Astie <teddy.astie@vates.tech>
> Fixes: 61367688f1fb0 ("xen/virtio: enable grant based virtio on x86")
> ---
> CC: Juergen Gross <jgross@suse.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
>
> drivers/xen/grant-dma-ops.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c
> index 14077d23f2a1..c2603e700178 100644
> --- a/drivers/xen/grant-dma-ops.c
> +++ b/drivers/xen/grant-dma-ops.c
> @@ -366,7 +366,8 @@ static int xen_grant_init_backend_domid(struct device *dev,
> if (np) {
> ret = xen_dt_grant_init_backend_domid(dev, np, backend_domid);
> of_node_put(np);
> - } else if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) || xen_pv_domain()) {
> + } else if (!xen_initial_domain() &&
> + (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) || xen_pv_domain())) {
> dev_info(dev, "Using dom0 as backend\n");
> *backend_domid = 0;
> ret = 0;
Please make this controllable, e.g. via a boot parameter.
It is completely valid to have a virtio device in dom0 with the backend in
a domU. You'll need grants in this case.
Juergen
Le 06/01/2026 à 20:06, Jürgen Groß a écrit :
> On 06.01.26 18:36, Teddy Astie wrote:
>> Dom0 inherit devices from the machine and is usually in PV mode.
>> If we are running in a virtual that has virtio devices, these devices
>> would be considered as using grants with Dom0 as backend, while being
>> the said Dom0 itself, while we want to use these devices like regular
>> PCI devices.
>>
>> Fix this by preventing grant-dma-ops from being used when running as Dom0
>> (initial domain). We still keep the device-tree logic as-is.
>>
>> Signed-off-by: Teddy Astie <teddy.astie@vates.tech>
>> Fixes: 61367688f1fb0 ("xen/virtio: enable grant based virtio on x86")
>> ---
>> CC: Juergen Gross <jgross@suse.com>
>> CC: Stefano Stabellini <sstabellini@kernel.org>
>> CC: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
>> CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
>>
>> drivers/xen/grant-dma-ops.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c
>> index 14077d23f2a1..c2603e700178 100644
>> --- a/drivers/xen/grant-dma-ops.c
>> +++ b/drivers/xen/grant-dma-ops.c
>> @@ -366,7 +366,8 @@ static int xen_grant_init_backend_domid(struct
>> device *dev,
>> if (np) {
>> ret = xen_dt_grant_init_backend_domid(dev, np, backend_domid);
>> of_node_put(np);
>> - } else if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) ||
>> xen_pv_domain()) {
>> + } else if (!xen_initial_domain() &&
>> + (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) ||
>> xen_pv_domain())) {
>> dev_info(dev, "Using dom0 as backend\n");
>> *backend_domid = 0;
>> ret = 0;
>
> Please make this controllable, e.g. via a boot parameter.
>
> It is completely valid to have a virtio device in dom0 with the backend in
> a domU. You'll need grants in this case.
>
Due to
> *backend_domid = 0
Dom0 would always be the backend, unless we introduce a new boot
parameter to select which domain will be the backend.
There is also another issue, as in the xen_initial_domain() case, all
PCI devices come from hardware. So no virtio-pci device can't come from
another domain as Linux would pick up pcifront devices only if we are
not a Dom0 (!xen_initial_domain()).
>
> Juergen
Teddy
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
On 06.01.26 23:47, Teddy Astie wrote:
> Le 06/01/2026 à 20:06, Jürgen Groß a écrit :
>> On 06.01.26 18:36, Teddy Astie wrote:
>>> Dom0 inherit devices from the machine and is usually in PV mode.
>>> If we are running in a virtual that has virtio devices, these devices
>>> would be considered as using grants with Dom0 as backend, while being
>>> the said Dom0 itself, while we want to use these devices like regular
>>> PCI devices.
>>>
>>> Fix this by preventing grant-dma-ops from being used when running as Dom0
>>> (initial domain). We still keep the device-tree logic as-is.
>>>
>>> Signed-off-by: Teddy Astie <teddy.astie@vates.tech>
>>> Fixes: 61367688f1fb0 ("xen/virtio: enable grant based virtio on x86")
>>> ---
>>> CC: Juergen Gross <jgross@suse.com>
>>> CC: Stefano Stabellini <sstabellini@kernel.org>
>>> CC: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
>>> CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
>>>
>>> drivers/xen/grant-dma-ops.c | 3 ++-
>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c
>>> index 14077d23f2a1..c2603e700178 100644
>>> --- a/drivers/xen/grant-dma-ops.c
>>> +++ b/drivers/xen/grant-dma-ops.c
>>> @@ -366,7 +366,8 @@ static int xen_grant_init_backend_domid(struct
>>> device *dev,
>>> if (np) {
>>> ret = xen_dt_grant_init_backend_domid(dev, np, backend_domid);
>>> of_node_put(np);
>>> - } else if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) ||
>>> xen_pv_domain()) {
>>> + } else if (!xen_initial_domain() &&
>>> + (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) ||
>>> xen_pv_domain())) {
>>> dev_info(dev, "Using dom0 as backend\n");
>>> *backend_domid = 0;
>>> ret = 0;
>>
>> Please make this controllable, e.g. via a boot parameter.
>>
>> It is completely valid to have a virtio device in dom0 with the backend in
>> a domU. You'll need grants in this case.
>>
> Due to
> > *backend_domid = 0
>
> Dom0 would always be the backend, unless we introduce a new boot
> parameter to select which domain will be the backend.
Ah, right. Okay, for now this is correct, so you can have my
Reviewed-by: Juergen Gross <jgross@suse.com>
In future things might change, though.
> There is also another issue, as in the xen_initial_domain() case, all
> PCI devices come from hardware. So no virtio-pci device can't come from
> another domain as Linux would pick up pcifront devices only if we are
> not a Dom0 (!xen_initial_domain()).
I think virtio devices should only be handled via pcifront in case they
are NOT implemented by a Xen backend domain.
Juergen
© 2016 - 2026 Red Hat, Inc.