From 5e61bf72bab1e29a8ed038aed98287820275850a Mon Sep 17 00:00:00 2001 From: Sukadev Bhattiprolu Date: Wed, 11 Jan 2023 19:04:25 -0800 Subject: [PATCH] ANDROID: iommu: Define vendor hook to limit max alignment When the IOVA framework applies IOVA alignment it aligns all IOVAs to the smallest PAGE_SIZE order which is greater than or equal to the requested IOVA size. We support use cases that requires large buffers (> 64 MB in size) to be allocated and mapped in their stage 1 page tables. However, with this alignment scheme we find ourselves running out of IOVA space for 32 bit devices, Define a vendor hook to allow limiting the alignment value used when allocating IOVAs. We addressed this issue in Android13-5.15 with commit 989b762eb159 ("FROMLIST: iommu/iova: Add support for IOVA max alignment tuning") Bug: 190519428 Change-Id: I13032c1b440c050860109aae23f96c0b52782664 Link: https://lore.kernel.org/r/1634148667-409263-1-git-send-email-quic_c_gdjako@quicinc.com/ Signed-off-by: Sukadev Bhattiprolu --- drivers/android/vendor_hooks.c | 1 + drivers/iommu/iova.c | 8 ++++++-- include/trace/hooks/iommu.h | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index c68d5a6e345e..3b4aaf79ddf6 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -114,6 +114,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_iommu_iovad_free_iova); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_psci_tos_resident_on); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_psci_cpu_suspend); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_iommu_iovad_init_alloc_algo); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_iommu_limit_align_shift); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ptype_head); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_allow_domain_state); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpuidle_psci_enter); diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index f0617d17ff89..b2011a45d935 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -173,8 +173,12 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, unsigned long align_mask = ~0UL; unsigned long high_pfn = limit_pfn, low_pfn = iovad->start_pfn; - if (size_aligned) - align_mask <<= fls_long(size - 1); + if (size_aligned) { + unsigned long shift = fls_long(size - 1); + + trace_android_rvh_iommu_limit_align_shift(iovad, size, &shift); + align_mask <<= shift; + } /* Walk the tree backwards */ spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); diff --git a/include/trace/hooks/iommu.h b/include/trace/hooks/iommu.h index 8cbd41c97c32..41d08e8abe04 100644 --- a/include/trace/hooks/iommu.h +++ b/include/trace/hooks/iommu.h @@ -39,6 +39,11 @@ DECLARE_RESTRICTED_HOOK(android_rvh_iommu_iovad_init_alloc_algo, TP_PROTO(struct device *dev, struct iova_domain *iovad), TP_ARGS(dev, iovad), 1); +DECLARE_RESTRICTED_HOOK(android_rvh_iommu_limit_align_shift, + TP_PROTO(struct iova_domain *iovad, unsigned long size, + unsigned long *shift), + TP_ARGS(iovad, size, shift), 1); + #endif /* _TRACE_HOOK_IOMMU_H */ /* This part must be outside protection */