KVM: arm64: Add mechanism to pin a page at hyp

The page refcount at hyp is used for two things: so the allocator
knows when to return the page to the pool and so the hypervisor
can transiently prevent a page that has been shared by the host
from being unshared, i.e., pin the page.

A pin is needed to, e.g., prevent a page holding a host vCPU
structure being donated to a guest as normal memory and then
having the hypervisor write to it as a result of a host
hypercall.

Instead of relying on the refcount for the pin, introduce and use
a mechanism to pin the page, allowing us to differentiate them
from pages with an elevated refcount.

This patch does this by overloading the page order, setting it to
HYP_NO_ORDER to mark a pinned page. The value of HYP_NO_ORDER is
much greater than any potential page order, and be used in checks
for bugs.

Suggested-by: Will Deacon <will@kernel.org>
Change-Id: I8b801682d5ca216a0dc9e62687a19237fb9a4006
Signed-off-by: Fuad Tabba <tabba@google.com>
5 files changed