From 8fda1979fd77996ec048d18764a0c62aa5b76081 Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Wed, 6 Apr 2022 16:19:58 +0100 Subject: [PATCH] ANDROID: KVM: arm64: iommu: Fix upper bound of PT walk The second argument of the kvm_pgtable_walker callback was misinterpreted as the end of the current entry, where in fact it is the end of the walked memory region. Fix this by computing the end of the current entry from the start and the level. This did not affect correctness, as the code iterates linarly over the entire address space, but it did affect boot time. Bug: 190463801 Bug: 218012133 Signed-off-by: David Brazdil Change-Id: I6d189b87645f47cd215a783c1bc9e1f032ff8c62 (cherry picked from commit 58f8121600276e32e0c91d075f273b836360b27a) Signed-off-by: Mostafa Saleh Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/nvhe/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/iommu.c b/arch/arm64/kvm/hyp/nvhe/iommu.c index 630b5e1a643a..3a56ea453745 100644 --- a/arch/arm64/kvm/hyp/nvhe/iommu.c +++ b/arch/arm64/kvm/hyp/nvhe/iommu.c @@ -174,12 +174,13 @@ static bool is_mmio_range(phys_addr_t base, size_t size) return true; } -static int __snapshot_host_stage2(u64 start, u64 end, u32 level, +static int __snapshot_host_stage2(u64 start, u64 pa_max, u32 level, kvm_pte_t *ptep, enum kvm_pgtable_walk_flags flags, void * const arg) { struct pkvm_iommu_driver * const drv = arg; + u64 end = start + kvm_granule_size(level); enum kvm_pgtable_prot prot; kvm_pte_t pte = *ptep;