diff mbox series

xen/arm: Enclose all iommu related access within CONFIG_HAS_PASSTHROUGH

Message ID 20241111180635.1198552-1-ayan.kumar.halder@amd.com (mailing list archive)
State New
Headers show
Series xen/arm: Enclose all iommu related access within CONFIG_HAS_PASSTHROUGH | expand

Commit Message

Ayan Kumar Halder Nov. 11, 2024, 6:06 p.m. UTC
As CONFIG_HAS_PASSTHROUGH is enabled only for MMU, thus any common code
accessing iommu needs to be enclosed within CONFIG_HAS_PASSTHROUGH.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
---
 xen/arch/arm/Kconfig          | 4 ++--
 xen/arch/arm/device.c         | 2 ++
 xen/arch/arm/dom0less-build.c | 6 ++++++
 xen/arch/arm/domain.c         | 6 ++++++
 xen/arch/arm/domain_build.c   | 2 ++
 xen/arch/arm/p2m.c            | 2 ++
 xen/arch/arm/setup.c          | 2 ++
 7 files changed, 22 insertions(+), 2 deletions(-)

Comments

Jan Beulich Nov. 12, 2024, 9:45 a.m. UTC | #1
On 11.11.2024 19:06, Ayan Kumar Halder wrote:
> As CONFIG_HAS_PASSTHROUGH is enabled only for MMU, thus any common code
> accessing iommu needs to be enclosed within CONFIG_HAS_PASSTHROUGH.

I'm not an Arm maintainer, so my opinion may not count much, but that's
quite a bit of #ifdef-ary. In at least some of the cases using stubs instead
may result in better legibility ...

Jan
diff mbox series

Patch

diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index 701b2aa76b..4833f12d2a 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -14,9 +14,7 @@  config ARM
 	select FUNCTION_ALIGNMENT_4B
 	select HAS_ALTERNATIVE if HAS_VMAP
 	select HAS_DEVICE_TREE
-	select HAS_PASSTHROUGH
 	select HAS_UBSAN
-	select IOMMU_FORCE_PT_SHARE if MMU
 
 config ARCH_DEFCONFIG
 	string
@@ -77,8 +75,10 @@  choice
 config MMU
 	bool "MMU"
 	select HAS_PAGING_MEMPOOL
+	select HAS_PASSTHROUGH
 	select HAS_PMAP
 	select HAS_VMAP
+	select IOMMU_FORCE_PT_SHARE
 	help
 	  Select it if you plan to run Xen on A-profile Armv7+
 
diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c
index 5610cddcba..9805bc7742 100644
--- a/xen/arch/arm/device.c
+++ b/xen/arch/arm/device.c
@@ -279,6 +279,7 @@  int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt,
     dt_dprintk("%s passthrough = %d naddr = %u\n",
                dt_node_full_name(dev), own_device, naddr);
 
+#ifdef CONFIG_HAS_PASSTHROUGH
     if ( own_device )
     {
         dt_dprintk("Check if %s is behind the IOMMU and add it\n",
@@ -304,6 +305,7 @@  int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt,
             }
         }
     }
+#endif
 
     res = map_device_irqs_to_domain(d, dev, own_device, irq_ranges);
     if ( res < 0 )
diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c
index 9575769b25..ecf81f5748 100644
--- a/xen/arch/arm/dom0less-build.c
+++ b/xen/arch/arm/dom0less-build.c
@@ -368,15 +368,21 @@  static int __init handle_passthrough_prop(struct kernel_info *kinfo,
     if ( res < 0 )
         return res;
 
+#ifdef CONFIG_HAS_PASSTHROUGH
     res = iommu_add_dt_device(node);
     if ( res < 0 )
         return res;
+#endif
 
     /* If xen_force, we allow assignment of devices without IOMMU protection. */
     if ( xen_force && !dt_device_is_protected(node) )
         return 0;
 
+#ifdef CONFIG_HAS_PASSTHROUGH
     return iommu_assign_dt_device(kinfo->d, node);
+#else
+    return res;
+#endif
 }
 
 static int __init handle_prop_pfdt(struct kernel_info *kinfo,
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index 3ba959f866..2da8eaed01 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -710,9 +710,11 @@  int arch_domain_create(struct domain *d,
     ioreq_domain_init(d);
 #endif
 
+#ifdef CONFIG_HAS_PASSTHROUGH
     /* p2m_init relies on some value initialized by the IOMMU subsystem */
     if ( (rc = iommu_domain_init(d, config->iommu_opts)) != 0 )
         goto fail;
+#endif
 
     if ( (rc = p2m_init(d)) != 0 )
         goto fail;
@@ -841,7 +843,9 @@  void arch_domain_destroy(struct domain *d)
     /* IOMMU page table is shared with P2M, always call
      * iommu_domain_destroy() before p2m_final_teardown().
      */
+#ifdef CONFIG_HAS_PASSTHROUGH
     iommu_domain_destroy(d);
+#endif
     p2m_final_teardown(d);
     domain_vgic_free(d);
     domain_vuart_free(d);
@@ -1059,9 +1063,11 @@  int domain_relinquish_resources(struct domain *d)
     switch ( d->arch.rel_priv )
     {
     case 0:
+#ifdef CONFIG_HAS_PASSTHROUGH
         ret = iommu_release_dt_devices(d);
         if ( ret )
             return ret;
+#endif
 
         /*
          * Release the resources allocated for vpl011 which were
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 2c30792de8..2b41a3c926 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2137,7 +2137,9 @@  static int __init construct_dom0(struct domain *d)
         dom0_mem = MB(512);
     }
 
+#ifdef CONFIG_HAS_PASSTHROUGH
     iommu_hwdom_init(d);
+#endif
 
     d->max_pages = dom0_mem >> PAGE_SHIFT;
 
diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index 65b70955e3..343d5b857c 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -434,6 +434,7 @@  void p2m_set_way_flush(struct vcpu *v, struct cpu_user_regs *regs,
     /* This function can only work with the current vCPU. */
     ASSERT(v == current);
 
+#ifdef CONFIG_HAS_PASSTHROUGH
     if ( iommu_use_hap_pt(current->domain) )
     {
         gprintk(XENLOG_ERR,
@@ -441,6 +442,7 @@  void p2m_set_way_flush(struct vcpu *v, struct cpu_user_regs *regs,
         inject_undef_exception(regs, hsr);
         return;
     }
+#endif
 
     if ( !(v->arch.hcr_el2 & HCR_TVM) )
     {
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 4b52fc314a..bdc0d810ee 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -419,6 +419,7 @@  void asmlinkage __init start_xen(unsigned long fdt_paddr)
     /* This should be done in a vpmu driver but we do not have one yet. */
     vpmu_is_available = cpu_has_pmu;
 
+#ifdef CONFIG_HAS_PASSTHROUGH
     /*
      * The IOMMU subsystem must be initialized before P2M as we need
      * to gather requirements regarding the maximum IPA bits supported by
@@ -427,6 +428,7 @@  void asmlinkage __init start_xen(unsigned long fdt_paddr)
     rc = iommu_setup();
     if ( !iommu_enabled && rc != -ENODEV )
         panic("Couldn't configure correctly all the IOMMUs.\n");
+#endif
 
     setup_virt_paging();