KVM: arm/arm64: Fix handling of stage2 huge mappings
authorSuzuki K Poulose <suzuki.poulose@arm.com>
Wed, 20 Mar 2019 14:57:19 +0000 (14:57 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 4 May 2019 07:21:15 +0000 (09:21 +0200)
commit07c5093a04f824fcbee179d7c7408d47f1ac6931
treec81e50c3fdc269fd04ebcea0e2a18e7fc7637d59
parente68cc902c624d7a5cf1ebde8f27e484ab1756da6
KVM: arm/arm64: Fix handling of stage2 huge mappings

[ Upstream commit 3c3736cd32bf5197aed1410ae826d2d254a5b277 ]

We rely on the mmu_notifier call backs to handle the split/merge
of huge pages and thus we are guaranteed that, while creating a
block mapping, either the entire block is unmapped at stage2 or it
is missing permission.

However, we miss a case where the block mapping is split for dirty
logging case and then could later be made block mapping, if we cancel the
dirty logging. This not only creates inconsistent TLB entries for
the pages in the the block, but also leakes the table pages for
PMD level.

Handle this corner case for the huge mappings at stage2 by
unmapping the non-huge mapping for the block. This could potentially
release the upper level table. So we need to restart the table walk
once we unmap the range.

Fixes : ad361f093c1e31d ("KVM: ARM: Support hugetlbfs backed huge pages")
Reported-by: Zheng Xiang <zhengxiang9@huawei.com>
Cc: Zheng Xiang <zhengxiang9@huawei.com>
Cc: Zenghui Yu <yuzenghui@huawei.com>
Cc: Christoffer Dall <christoffer.dall@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Sasha Levin (Microsoft) <sashal@kernel.org>
arch/arm/include/asm/stage2_pgtable.h
virt/kvm/arm/mmu.c