Skip to content

Commit fc62a4e

Browse files
committed
KVM: Explicitly disallow activatating a gfn_to_pfn_cache with INVALID_GPA
Explicit disallow activating a gfn_to_pfn_cache with an error gpa, i.e. INVALID_GPA, to ensure that KVM doesn't mistake a GPA-based cache for an HVA-based cache (KVM uses INVALID_GPA as a magic value to differentiate between GPA-based and HVA-based caches). WARN if KVM attempts to activate a cache with INVALID_GPA, purely so that new caches need to at least consider what to do with a "bad" GPA, as all existing usage of kvm_gpc_activate() guarantees gpa != INVALID_GPA. I.e. removing the WARN in the future is completely reasonable if doing so would yield cleaner/better code overall. Reviewed-by: David Woodhouse <[email protected]> Reviewed-by: Paul Durrant <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 5c9ca4e commit fc62a4e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

virt/kvm/pfncache.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,13 @@ static int __kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned
418418

419419
int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)
420420
{
421+
/*
422+
* Explicitly disallow INVALID_GPA so that the magic value can be used
423+
* by KVM to differentiate between GPA-based and HVA-based caches.
424+
*/
425+
if (WARN_ON_ONCE(kvm_is_error_gpa(gpa)))
426+
return -EINVAL;
427+
421428
return __kvm_gpc_activate(gpc, gpa, KVM_HVA_ERR_BAD, len);
422429
}
423430

0 commit comments

Comments
 (0)