KVM: arm64: Drop last page ref in kvm_pgtable_stage2_free_removed()
authorOliver Upton <oliver.upton@linux.dev>
Tue, 30 May 2023 19:32:13 +0000 (19:32 +0000)
committerMarc Zyngier <maz@kernel.org>
Wed, 31 May 2023 07:02:21 +0000 (08:02 +0100)
commitf6a27d6dc51b288106adaf053cff9c9b9cc12c4e
tree3df9b9c30b6c53cfb038014fa6d98b7753230611
parent811154e234db72f0a11557a84ba9640f8b3bc823
KVM: arm64: Drop last page ref in kvm_pgtable_stage2_free_removed()

The reference count on page table allocations is increased for every
'counted' PTE (valid or donated) in the table in addition to the initial
reference from ->zalloc_page(). kvm_pgtable_stage2_free_removed() fails
to drop the last reference on the root of the table walk, meaning we
leak memory.

Fix it by dropping the last reference after the free walker returns,
at which point all references for 'counted' PTEs have been released.

Cc: stable@vger.kernel.org
Fixes: 5c359cca1faf ("KVM: arm64: Tear down unlinked stage-2 subtree after break-before-make")
Reported-by: Yu Zhao <yuzhao@google.com>
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Tested-by: Yu Zhao <yuzhao@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230530193213.1663411-1-oliver.upton@linux.dev
arch/arm64/kvm/hyp/pgtable.c