From 004af73a3efa45de153d15145dfa294c6e356513 Mon Sep 17 00:00:00 2001 From: Mostafa Saleh Date: Mon, 24 Feb 2025 18:59:43 +0000 Subject: [PATCH] ANDROID: iommu/io-pgtable-arm: Fix existing/missing mapping hooks Fix one hook that is called in the wrong place and add 2 missing calls, also remove the return from arm_lpae_unmap_empty() as it is not used. Bug: 357781595 Bug: 384432312 Change-Id: I62cb848b0421c295a144660511bf4389f4e6ffd6 Signed-off-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/pkvm/io-pgtable-arm.c | 3 +-- drivers/iommu/io-pgtable-arm-common.c | 10 +++++++--- drivers/iommu/io-pgtable-arm.c | 3 +-- include/linux/io-pgtable-arm.h | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/pkvm/io-pgtable-arm.c b/drivers/iommu/arm/arm-smmu-v3/pkvm/io-pgtable-arm.c index b9e66c728648..348b83bd7d48 100644 --- a/drivers/iommu/arm/arm-smmu-v3/pkvm/io-pgtable-arm.c +++ b/drivers/iommu/arm/arm-smmu-v3/pkvm/io-pgtable-arm.c @@ -25,9 +25,8 @@ int arm_lpae_map_exists(void) return -EEXIST; } -int arm_lpae_unmap_empty(void) +void arm_lpae_unmap_empty(void) { - return -EEXIST; } void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp, diff --git a/drivers/iommu/io-pgtable-arm-common.c b/drivers/iommu/io-pgtable-arm-common.c index 23c01e4d8a41..4fee3985c647 100644 --- a/drivers/iommu/io-pgtable-arm-common.c +++ b/drivers/iommu/io-pgtable-arm-common.c @@ -231,7 +231,7 @@ static int __arm_lpae_map(struct arm_lpae_io_pgtable *data, unsigned long iova, cptep = iopte_deref(pte, data); } else if (iopte_valid(pte)) { /* We require an unmap first */ - return arm_lpae_unmap_empty(); + return arm_lpae_map_exists(); } /* Rinse, repeat */ @@ -428,8 +428,10 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, unmap_idx_start = ARM_LPAE_LVL_IDX(iova, lvl, data); ptep += unmap_idx_start; pte = READ_ONCE(*ptep); - if (WARN_ON(!iopte_valid(pte))) + if (!iopte_valid(pte)) { + arm_lpae_unmap_empty(); return 0; + } /* If the size matches this level, we're in the right place */ if (size == ARM_LPAE_BLOCK_SIZE(lvl, data)) { @@ -439,8 +441,10 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, /* Find and handle non-leaf entries */ for (i = 0; i < num_entries; i++) { pte = READ_ONCE(ptep[i]); - if (WARN_ON(!iopte_valid(pte))) + if (!iopte_valid(pte)) { + arm_lpae_unmap_empty(); break; + } if (!iopte_leaf(pte, lvl, iop->fmt)) { __arm_lpae_clear_pte(&ptep[i], &iop->cfg, 1); diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index e8d7a8bbf116..d40d8ff56407 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -31,10 +31,9 @@ int arm_lpae_map_exists(void) return -EEXIST; } -int arm_lpae_unmap_empty(void) +void arm_lpae_unmap_empty(void) { WARN_ON(!selftest_running); - return -EEXIST; } static dma_addr_t __arm_lpae_dma_addr(void *pages) diff --git a/include/linux/io-pgtable-arm.h b/include/linux/io-pgtable-arm.h index 94c4eeea23a9..52722b7decda 100644 --- a/include/linux/io-pgtable-arm.h +++ b/include/linux/io-pgtable-arm.h @@ -233,5 +233,5 @@ void __arm_lpae_free_pages(void *pages, size_t size, struct io_pgtable_cfg *cfg, void __arm_lpae_sync_pte(arm_lpae_iopte *ptep, int num_entries, struct io_pgtable_cfg *cfg); int arm_lpae_map_exists(void); -int arm_lpae_unmap_empty(void); +void arm_lpae_unmap_empty(void); #endif /* IO_PGTABLE_H_ */