Add a function to check whether an IOVA domain currently caches a given upper IOVA len exactly. Signed-off-by: John Garry <john.garry@xxxxxxxxxx> --- drivers/iommu/iova.c | 11 +++++++++++ include/linux/iova.h | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 0e4c0e55178a..95892a0433cc 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -872,6 +872,17 @@ static void iova_magazine_push(struct iova_magazine *mag, unsigned long pfn) mag->pfns[mag->size++] = pfn; } +static unsigned long iova_len_to_rcache_max(unsigned long iova_len) +{ + return order_base_2(iova_len) + 1; +} + +/* Test if iova_len range cached upper limit matches that of IOVA domain */ +bool iova_domain_len_is_cached(struct iova_domain *iovad, unsigned long iova_len) +{ + return iova_len_to_rcache_max(iova_len) == iovad->rcache_max_size; +} + static void init_iova_rcaches(struct iova_domain *iovad) { struct iova_cpu_rcache *cpu_rcache; diff --git a/include/linux/iova.h b/include/linux/iova.h index 9974e1d3e2bc..04cc8eb6de38 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -136,7 +136,8 @@ static inline unsigned long iova_pfn(struct iova_domain *iovad, dma_addr_t iova) #if IS_ENABLED(CONFIG_IOMMU_IOVA) int iova_cache_get(void); void iova_cache_put(void); - +bool iova_domain_len_is_cached(struct iova_domain *iovad, + unsigned long iova_len); void free_iova(struct iova_domain *iovad, unsigned long pfn); void __free_iova(struct iova_domain *iovad, struct iova *iova); struct iova *alloc_iova(struct iova_domain *iovad, unsigned long size, @@ -158,6 +159,11 @@ int init_iova_flush_queue(struct iova_domain *iovad, struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn); void put_iova_domain(struct iova_domain *iovad); #else +static inline bool iova_domain_len_is_cached(struct iova_domain *iovad, + unsigned long iova_len) +{ + return false; +} static inline int iova_cache_get(void) { return -ENOTSUPP; -- 2.26.2