KVM: Add helpers to consolidate gfn_to_pfn_cache's page split check
authorSean Christopherson <seanjc@google.com>
Wed, 20 Mar 2024 00:15:40 +0000 (17:15 -0700)
committerSean Christopherson <seanjc@google.com>
Mon, 8 Apr 2024 20:20:23 +0000 (13:20 -0700)
commit18f06e97692516d28c3cdc577fb5c501d690b303
treeed888f96054159ed302efe112b2e11c491b9fbd2
parentfec50db7033ea478773b159e0e2efb135270e3b7
KVM: Add helpers to consolidate gfn_to_pfn_cache's page split check

Add a helper to check that the incoming length for a gfn_to_pfn_cache is
valid with respect to the cache's GPA and/or HVA.  To avoid activating a
cache with a bogus GPA, a future fix will fork the page split check in
the inner refresh path into activate() and the public rerfresh() APIs, at
which point KVM will check the length in three separate places.

Deliberately keep the "page offset" logic open coded, as the only other
path that consumes the offset, __kvm_gpc_refresh(), already needs to
differentiate between GPA-based and HVA-based caches, and it's not obvious
that using a helper is a net positive in overall code readability.

Note, for GPA-based caches, this has a subtle side effect of using the GPA
instead of the resolved HVA in the check() path, but that should be a nop
as the HVA offset is derived from the GPA, i.e. the two offsets are
identical, barring a KVM bug.

Reviewed-by: Paul Durrant <paul@xen.org>
Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
Link: https://lore.kernel.org/r/20240320001542.3203871-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
virt/kvm/pfncache.c