[PATCH 07/20] xen/arm: vIOMMU: Add cmdline boot option "viommu = <boolean>"

Milan Djokic posted 20 patches 4 months, 1 week ago
[PATCH 07/20] xen/arm: vIOMMU: Add cmdline boot option "viommu = <boolean>"
Posted by Milan Djokic 4 months, 1 week ago
From: Rahul Singh <rahul.singh@arm.com>

Add cmdline boot option "viommu = <boolean>" to enable or disable the
virtual iommu support for guests on ARM.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Signed-off-by: Milan Djokic <milan_djokic@epam.com>
---
 docs/misc/xen-command-line.pandoc      |  7 +++++++
 xen/arch/arm/include/asm/viommu.h      | 11 +++++++++++
 xen/drivers/passthrough/arm/viommu.c   |  9 +++++++++
 xen/drivers/passthrough/arm/vsmmu-v3.c |  3 +++
 4 files changed, 30 insertions(+)

diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc
index 6865a61220..d6a2a6fbdd 100644
--- a/docs/misc/xen-command-line.pandoc
+++ b/docs/misc/xen-command-line.pandoc
@@ -2058,6 +2058,13 @@ This option can be specified more than once (up to 8 times at present).
 
 Flag to enable or disable support for PCI passthrough
 
+### viommu (arm)
+> `= <boolean>`
+
+> Default: `false`
+
+Flag to enable or disable support for Virtual IOMMU for guests.
+
 ### pcid (x86)
 > `= <boolean> | xpti=<bool>`
 
diff --git a/xen/arch/arm/include/asm/viommu.h b/xen/arch/arm/include/asm/viommu.h
index 4785877e2a..4de4cceeda 100644
--- a/xen/arch/arm/include/asm/viommu.h
+++ b/xen/arch/arm/include/asm/viommu.h
@@ -10,6 +10,7 @@
 #include <public/xen.h>
 
 extern struct list_head host_iommu_list;
+extern bool viommu_enabled;
 
 /* data structure for each hardware IOMMU */
 struct host_iommu {
@@ -50,6 +51,11 @@ uint16_t viommu_get_type(void);
 void add_to_host_iommu_list(paddr_t addr, paddr_t size,
                             const struct dt_device_node *node);
 
+static always_inline bool is_viommu_enabled(void)
+{
+    return viommu_enabled;
+}
+
 #else
 
 static inline uint8_t viommu_get_type(void)
@@ -76,6 +82,11 @@ static inline void add_to_host_iommu_list(paddr_t addr, paddr_t size,
     return;
 }
 
+static always_inline bool is_viommu_enabled(void)
+{
+    return false;
+}
+
 #endif /* CONFIG_VIRTUAL_IOMMU */
 
 #endif /* __ARCH_ARM_VIOMMU_H__ */
diff --git a/xen/drivers/passthrough/arm/viommu.c b/xen/drivers/passthrough/arm/viommu.c
index 53ae46349a..a1d6a04ba9 100644
--- a/xen/drivers/passthrough/arm/viommu.c
+++ b/xen/drivers/passthrough/arm/viommu.c
@@ -3,6 +3,7 @@
 #include <xen/errno.h>
 #include <xen/init.h>
 #include <xen/irq.h>
+#include <xen/param.h>
 #include <xen/types.h>
 
 #include <asm/viommu.h>
@@ -38,8 +39,16 @@ void add_to_host_iommu_list(paddr_t addr, paddr_t size,
     list_add_tail(&iommu_data->entry, &host_iommu_list);
 }
 
+/* By default viommu is disabled. */
+bool __read_mostly viommu_enabled;
+boolean_param("viommu", viommu_enabled);
+
 int domain_viommu_init(struct domain *d, uint16_t viommu_type)
 {
+    /* Enable viommu when it has been enabled explicitly (viommu=on). */
+    if ( !viommu_enabled )
+        return 0;
+
     if ( viommu_type == XEN_DOMCTL_CONFIG_VIOMMU_NONE )
         return 0;
 
diff --git a/xen/drivers/passthrough/arm/vsmmu-v3.c b/xen/drivers/passthrough/arm/vsmmu-v3.c
index 6b4009e5ef..e36f200ba5 100644
--- a/xen/drivers/passthrough/arm/vsmmu-v3.c
+++ b/xen/drivers/passthrough/arm/vsmmu-v3.c
@@ -105,6 +105,9 @@ void __init vsmmuv3_set_type(void)
 {
     const struct viommu_desc *desc = &vsmmuv3_desc;
 
+    if ( !is_viommu_enabled() )
+        return;
+
     if ( cur_viommu && (cur_viommu != desc) )
     {
         printk("WARNING: Cannot set vIOMMU, already set to a different value\n");
-- 
2.43.0
Re: [PATCH 07/20] xen/arm: vIOMMU: Add cmdline boot option "viommu = <boolean>"
Posted by Jan Beulich 4 months, 1 week ago
On 07.08.2025 18:59, Milan Djokic wrote:
> --- a/docs/misc/xen-command-line.pandoc
> +++ b/docs/misc/xen-command-line.pandoc
> @@ -2058,6 +2058,13 @@ This option can be specified more than once (up to 8 times at present).
>  
>  Flag to enable or disable support for PCI passthrough
>  
> +### viommu (arm)
> +> `= <boolean>`
> +
> +> Default: `false`
> +
> +Flag to enable or disable support for Virtual IOMMU for guests.

Isn't this too coarse-grained? IOW don't you want to specify the kind of IOMMU
to use, even if right now only one is being implemented? Also - why on the
command line? Isn't this rather a per-guest setting?

>  ### pcid (x86)
>  > `= <boolean> | xpti=<bool>`

Also, seeing this adjacent entry, you're inserting in the wrong place. The
options are supposed to be alphabetically sorted.

Jan
Re: [PATCH 07/20] xen/arm: vIOMMU: Add cmdline boot option "viommu = <boolean>"
Posted by Milan Djokic 4 months ago
Hello Jan,

On 8/8/25 08:20, Jan Beulich wrote:
> On 07.08.2025 18:59, Milan Djokic wrote:
>> --- a/docs/misc/xen-command-line.pandoc
>> +++ b/docs/misc/xen-command-line.pandoc
>> @@ -2058,6 +2058,13 @@ This option can be specified more than once (up to 8 times at present).
>>   
>>   Flag to enable or disable support for PCI passthrough
>>   
>> +### viommu (arm)
>> +> `= <boolean>`
>> +
>> +> Default: `false`
>> +
>> +Flag to enable or disable support for Virtual IOMMU for guests.
> 
> Isn't this too coarse-grained? IOW don't you want to specify the kind of IOMMU
> to use, even if right now only one is being implemented? Also - why on the
> command line? Isn't this rather a per-guest setting?
>
Yes, it would make more sense to specify IOMMU kind instead of plain 
enable/disable parameter. Updated in new patch series version.
As for reasons to have this parameter in xen command line, it is needed 
for xen smmuv3 driver initialization, where viommu initialization is 
done if 'viommu' is enabled. Also, for dom0less mode and dom0 itself, 
viommu for domain is enabled while domain is created based on this 
argument. We do have per-guest viommu enablement option for guests 
created with xl, but this does not cover dom0 (and dom0-less).

>>   ### pcid (x86)
>>   > `= <boolean> | xpti=<bool>`
> 
> Also, seeing this adjacent entry, you're inserting in the wrong place. The
> options are supposed to be alphabetically sorted.
>
We'll fix this in the new version with other suggested changes included.

> Jan

BR,
Milan