Message ID | 20250212091900.1515563-2-luca.fancellu@arm.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Prerequisite patches for Arm64 MPU build | expand |
On 12/02/2025 9:18 am, Luca Fancellu wrote: > When Xen is built without HAS_PASSTHROUGH, there are some parts > in arm and x86 where iommu_* functions are called in the codebase, > but their implementation is under xen/drivers/passthrough that is > not built. > > So provide some stub for these functions in order to build Xen > when !HAS_PASSTHROUGH, which is the case for example on systems > with MPU support. > > Signed-off-by: Luca Fancellu <luca.fancellu@arm.com> > --- > xen/arch/arm/include/asm/grant_table.h | 8 ++++++ > xen/include/xen/iommu.h | 40 +++++++++++++++++++++++--- > 2 files changed, 44 insertions(+), 4 deletions(-) > > diff --git a/xen/arch/arm/include/asm/grant_table.h b/xen/arch/arm/include/asm/grant_table.h > index d3c518a926b9..e21634b752df 100644 > --- a/xen/arch/arm/include/asm/grant_table.h > +++ b/xen/arch/arm/include/asm/grant_table.h > @@ -73,9 +73,17 @@ int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame, > #define gnttab_status_gfn(d, t, i) \ > page_get_xenheap_gfn(gnttab_status_page(t, i)) > > +#ifdef CONFIG_HAS_PASSTHROUGH > + > #define gnttab_need_iommu_mapping(d) \ > (is_domain_direct_mapped(d) && is_iommu_enabled(d)) > > +#else > + > +#define gnttab_need_iommu_mapping(d) (false) This doesn't evaluate d, which can lead to other build problems. Instead of providing two, you should insert "IS_ENABLED(CONFIG_HAS_PASSTHROUGH) &&" into the existing gnttab_need_iommu_mapping(). The same applies to several other hunks too. ~Andrew
Hi Andrew, thanks for your review, > On 12 Feb 2025, at 11:50, Andrew Cooper <andrew.cooper3@citrix.com> wrote: > > On 12/02/2025 9:18 am, Luca Fancellu wrote: >> When Xen is built without HAS_PASSTHROUGH, there are some parts >> in arm and x86 where iommu_* functions are called in the codebase, >> but their implementation is under xen/drivers/passthrough that is >> not built. >> >> So provide some stub for these functions in order to build Xen >> when !HAS_PASSTHROUGH, which is the case for example on systems >> with MPU support. >> >> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com> >> --- >> xen/arch/arm/include/asm/grant_table.h | 8 ++++++ >> xen/include/xen/iommu.h | 40 +++++++++++++++++++++++--- >> 2 files changed, 44 insertions(+), 4 deletions(-) >> >> diff --git a/xen/arch/arm/include/asm/grant_table.h b/xen/arch/arm/include/asm/grant_table.h >> index d3c518a926b9..e21634b752df 100644 >> --- a/xen/arch/arm/include/asm/grant_table.h >> +++ b/xen/arch/arm/include/asm/grant_table.h >> @@ -73,9 +73,17 @@ int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame, >> #define gnttab_status_gfn(d, t, i) \ >> page_get_xenheap_gfn(gnttab_status_page(t, i)) >> >> +#ifdef CONFIG_HAS_PASSTHROUGH >> + >> #define gnttab_need_iommu_mapping(d) \ >> (is_domain_direct_mapped(d) && is_iommu_enabled(d)) >> >> +#else >> + >> +#define gnttab_need_iommu_mapping(d) (false) > > This doesn't evaluate d, which can lead to other build problems. > > Instead of providing two, you should insert > "IS_ENABLED(CONFIG_HAS_PASSTHROUGH) &&" into the existing > gnttab_need_iommu_mapping(). I’ll do that for this case, I already checked and it works well, just for my knowledge could you explain to me what build problems can happen? Is it something related to the compiler that doesn’t see a usage for d? > > The same applies to several other hunks too. Are you referring to iommu_use_hap_pt? I have to say that I’ve tried before to insert another IS_ENABLED(…) but it was failing the compilation because without HAS_PASSTHROUGH dom_iommu(d) is (&(d)->iommu), but the iommu field doesn’t exists. So I’m not sure how to proceed there, do you have any suggestions? Cheers, Luca
> On 12 Feb 2025, at 12:37, Luca Fancellu <Luca.Fancellu@arm.com> wrote: > > Hi Andrew, > > thanks for your review, > >> On 12 Feb 2025, at 11:50, Andrew Cooper <andrew.cooper3@citrix.com> wrote: >> >> On 12/02/2025 9:18 am, Luca Fancellu wrote: >>> When Xen is built without HAS_PASSTHROUGH, there are some parts >>> in arm and x86 where iommu_* functions are called in the codebase, >>> but their implementation is under xen/drivers/passthrough that is >>> not built. >>> >>> So provide some stub for these functions in order to build Xen >>> when !HAS_PASSTHROUGH, which is the case for example on systems >>> with MPU support. >>> >>> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com> >>> --- >>> xen/arch/arm/include/asm/grant_table.h | 8 ++++++ >>> xen/include/xen/iommu.h | 40 +++++++++++++++++++++++--- >>> 2 files changed, 44 insertions(+), 4 deletions(-) >>> >>> diff --git a/xen/arch/arm/include/asm/grant_table.h b/xen/arch/arm/include/asm/grant_table.h >>> index d3c518a926b9..e21634b752df 100644 >>> --- a/xen/arch/arm/include/asm/grant_table.h >>> +++ b/xen/arch/arm/include/asm/grant_table.h >>> @@ -73,9 +73,17 @@ int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame, >>> #define gnttab_status_gfn(d, t, i) \ >>> page_get_xenheap_gfn(gnttab_status_page(t, i)) >>> >>> +#ifdef CONFIG_HAS_PASSTHROUGH >>> + >>> #define gnttab_need_iommu_mapping(d) \ >>> (is_domain_direct_mapped(d) && is_iommu_enabled(d)) >>> >>> +#else >>> + >>> +#define gnttab_need_iommu_mapping(d) (false) >> >> This doesn't evaluate d, which can lead to other build problems. >> >> Instead of providing two, you should insert >> "IS_ENABLED(CONFIG_HAS_PASSTHROUGH) &&" into the existing >> gnttab_need_iommu_mapping(). > > I’ll do that for this case, I already checked and it works well, just for my knowledge could you > explain to me what build problems can happen? Is it something related to the compiler that > doesn’t see a usage for d? > > >> >> The same applies to several other hunks too. > > Are you referring to iommu_use_hap_pt? I have to say that I’ve tried before to insert another > IS_ENABLED(…) but it was failing the compilation because without HAS_PASSTHROUGH > dom_iommu(d) is (&(d)->iommu), but the iommu field doesn’t exists. > > So I’m not sure how to proceed there, do you have any suggestions? Oh sorry, nevermind this point, I see I can maybe use the same approach as need_iommu_pt_sync(d) > > Cheers, > Luca
diff --git a/xen/arch/arm/include/asm/grant_table.h b/xen/arch/arm/include/asm/grant_table.h index d3c518a926b9..e21634b752df 100644 --- a/xen/arch/arm/include/asm/grant_table.h +++ b/xen/arch/arm/include/asm/grant_table.h @@ -73,9 +73,17 @@ int replace_grant_host_mapping(uint64_t gpaddr, mfn_t frame, #define gnttab_status_gfn(d, t, i) \ page_get_xenheap_gfn(gnttab_status_page(t, i)) +#ifdef CONFIG_HAS_PASSTHROUGH + #define gnttab_need_iommu_mapping(d) \ (is_domain_direct_mapped(d) && is_iommu_enabled(d)) +#else + +#define gnttab_need_iommu_mapping(d) (false) + +#endif + #endif /* __ASM_GRANT_TABLE_H__ */ /* * Local variables: diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index b928c67e1995..0ddea755b1c0 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -110,6 +110,8 @@ extern int8_t iommu_hwdom_reserved; extern unsigned int iommu_dev_iotlb_timeout; +#ifdef CONFIG_HAS_PASSTHROUGH + int iommu_setup(void); int iommu_hardware_setup(void); @@ -122,6 +124,24 @@ int arch_iommu_domain_init(struct domain *d); void arch_iommu_check_autotranslated_hwdom(struct domain *d); void arch_iommu_hwdom_init(struct domain *d); +#else + +static inline int iommu_setup(void) +{ + return -ENODEV; +} + +static inline int iommu_domain_init(struct domain *d, unsigned int opts) +{ + return 0; +} + +static inline void iommu_hwdom_init(struct domain *d) {} + +static inline void iommu_domain_destroy(struct domain *d) {} + +#endif /* HAS_PASSTHROUGH */ + /* * The following flags are passed to map (applicable ones also to unmap) * operations, while some are passed back by lookup operations. @@ -206,7 +226,7 @@ struct msi_msg; #define PT_IRQ_TIME_OUT MILLISECS(8) #endif /* HAS_PCI */ -#ifdef CONFIG_HAS_DEVICE_TREE +#if defined(CONFIG_HAS_DEVICE_TREE) && defined(CONFIG_HAS_PASSTHROUGH) #include <xen/device_tree.h> int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev); @@ -238,7 +258,17 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, */ int iommu_remove_dt_device(struct dt_device_node *np); -#endif /* HAS_DEVICE_TREE */ +#else + +#define iommu_assign_dt_device(d, dev) (-EINVAL) +#define iommu_add_dt_device(np) (1) + +static inline int iommu_release_dt_devices(struct domain *d) +{ + return 0; +} + +#endif /* HAS_DEVICE_TREE && HAS_PASSTHROUGH */ struct page_info; @@ -381,17 +411,19 @@ struct domain_iommu { #define iommu_set_feature(d, f) set_bit(f, dom_iommu(d)->features) #define iommu_clear_feature(d, f) clear_bit(f, dom_iommu(d)->features) +/* Does the IOMMU pagetable need to be kept synchronized with the P2M */ +#ifdef CONFIG_HAS_PASSTHROUGH /* Are we using the domain P2M table as its IOMMU pagetable? */ #define iommu_use_hap_pt(d) (IS_ENABLED(CONFIG_HVM) && \ dom_iommu(d)->hap_pt_share) -/* Does the IOMMU pagetable need to be kept synchronized with the P2M */ -#ifdef CONFIG_HAS_PASSTHROUGH #define need_iommu_pt_sync(d) (dom_iommu(d)->need_sync) int iommu_do_domctl(struct xen_domctl *domctl, struct domain *d, XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl); #else +#define iommu_use_hap_pt(d) (false) + #define need_iommu_pt_sync(d) ({ (void)(d); false; }) static inline int iommu_do_domctl(struct xen_domctl *domctl, struct domain *d,
When Xen is built without HAS_PASSTHROUGH, there are some parts in arm and x86 where iommu_* functions are called in the codebase, but their implementation is under xen/drivers/passthrough that is not built. So provide some stub for these functions in order to build Xen when !HAS_PASSTHROUGH, which is the case for example on systems with MPU support. Signed-off-by: Luca Fancellu <luca.fancellu@arm.com> --- xen/arch/arm/include/asm/grant_table.h | 8 ++++++ xen/include/xen/iommu.h | 40 +++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-)