KVM: arm64: Move hyp_pool locking out of refcount helpers
authorQuentin Perret <qperret@google.com>
Tue, 8 Jun 2021 11:45:12 +0000 (11:45 +0000)
committerMarc Zyngier <maz@kernel.org>
Fri, 11 Jun 2021 12:24:11 +0000 (13:24 +0100)
commit6cbf874e51b68e5b2eb0cc50be3676f5d5601dab
treeee0511d3ff420301db4ac10b0e206c503117311d
parent8124c8a6b35386f73523d27eacb71b5364a68c4c
KVM: arm64: Move hyp_pool locking out of refcount helpers

The hyp_page refcount helpers currently rely on the hyp_pool lock for
serialization. However, this means the refcounts can't be changed from
the buddy allocator core as it already holds the lock, which means pages
have to go through odd transient states.

For example, when a page is freed, its refcount is set to 0, and the
lock is transiently released before the page can be attached to a free
list in the buddy tree. This is currently harmless as the allocator
checks the list node of each page to see if it is available for
allocation or not, but it means the page refcount can't be trusted to
represent the state of the page even if the pool lock is held.

In order to fix this, remove the pool locking from the refcount helpers,
and move all the logic to the buddy allocator. This will simplify the
removal of the list node from struct hyp_page in a later patch.

Signed-off-by: Quentin Perret <qperret@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210608114518.748712-2-qperret@google.com
arch/arm64/kvm/hyp/include/nvhe/gfp.h
arch/arm64/kvm/hyp/nvhe/page_alloc.c