From 4315d00d671b3e1a8de79dfb782609b3f242868f Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Wed, 19 Aug 2020 10:00:34 -0700 Subject: [PATCH] iommu/io-pgtable: Add support for io-pgtable accounting The operations for managing io-pgtable memory were recently updated, and do not account for io-pgtable memory accounting. Add support to the new operations, so that the amount of io-pgtable memory in use can be tracked. Also, the amount of overhead that the io-pgtable accounting feature adds is negligible, so enable it in the consolidate defconfig, as opposed to the debug defconfig. Change-Id: I79d9ec2b5196096c4961e4d902c2f0e9a5ccd909 Signed-off-by: Isaac J. Manjarres --- .../configs/vendor/lahaina_consolidate.config | 1 + arch/arm64/configs/vendor/lahaina_debug.config | 1 - drivers/iommu/io-pgtable.c | 14 ++++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/arm64/configs/vendor/lahaina_consolidate.config b/arch/arm64/configs/vendor/lahaina_consolidate.config index 81774c4ac977..e264ad16b0b0 100644 --- a/arch/arm64/configs/vendor/lahaina_consolidate.config +++ b/arch/arm64/configs/vendor/lahaina_consolidate.config @@ -2,6 +2,7 @@ CONFIG_LOCALVERSION="-qgki-consolidate" CONFIG_IOMMU_TLBSYNC_DEBUG=y CONFIG_IOMMU_DEBUG=y CONFIG_IOMMU_TESTS=y +CONFIG_IO_PGTABLE_PAGE_ACCOUNTING=y CONFIG_CMA_DEBUGFS=y CONFIG_CMA_DEBUG=y CONFIG_DEBUG_PAGEALLOC=y diff --git a/arch/arm64/configs/vendor/lahaina_debug.config b/arch/arm64/configs/vendor/lahaina_debug.config index 4924a555cee7..ffc9ff156cc8 100644 --- a/arch/arm64/configs/vendor/lahaina_debug.config +++ b/arch/arm64/configs/vendor/lahaina_debug.config @@ -1,6 +1,5 @@ CONFIG_LOCALVERSION="-qgki-debug" CONFIG_SLUB_DEBUG_PANIC_ON=y -CONFIG_IO_PGTABLE_PAGE_ACCOUNTING=y CONFIG_SLUB_DEBUG_ON=y CONFIG_DEBUG_KMEMLEAK=y CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=4000 diff --git a/drivers/iommu/io-pgtable.c b/drivers/iommu/io-pgtable.c index 9bb837bb8927..b44d52e9e59d 100644 --- a/drivers/iommu/io-pgtable.c +++ b/drivers/iommu/io-pgtable.c @@ -149,19 +149,27 @@ void *io_pgtable_alloc_pages(struct io_pgtable_cfg *cfg, void *cookie, { struct device *dev; struct page *p; + void *page_addr; if (!cfg) return NULL; - if (cfg->iommu_pgtable_ops && cfg->iommu_pgtable_ops->alloc_pgtable) - return cfg->iommu_pgtable_ops->alloc_pgtable(cookie, order, + if (cfg->iommu_pgtable_ops && cfg->iommu_pgtable_ops->alloc_pgtable) { + page_addr = cfg->iommu_pgtable_ops->alloc_pgtable(cookie, order, gfp_mask); + if (likely(page_addr)) + mod_pages_allocated(1 << order); + + return page_addr; + } dev = cfg->iommu_dev; p = alloc_pages_node(dev ? dev_to_node(dev) : NUMA_NO_NODE, gfp_mask, order); if (!p) return NULL; + + mod_pages_allocated(1 << order); return page_address(p); } @@ -175,4 +183,6 @@ void io_pgtable_free_pages(struct io_pgtable_cfg *cfg, void *cookie, void *virt, cfg->iommu_pgtable_ops->free_pgtable(cookie, virt, order); else free_pages((unsigned long)virt, order); + + mod_pages_allocated(-(1 << order)); }