Re: [PATCH v13 09/21] KVM: pfncache: allow a cache to be activated with a fixed (userspace) HVA

Sean Christopherson
2024-02-19T21:49:28Z

On Thu, Feb 15, 2024, Paul Durrant wrote:
> @@ -319,7 +340,16 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa,
>
> int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len)
> {
> - return __kvm_gpc_refresh(gpc, gpc->gpa, len);
> + unsigned long uhva = gpc->uhva;
> +
> + /*
> + * If the GPA is valid then invalidate the HVA, otherwise
> + * __kvm_gpc_refresh() will fail its strict either/or address check.
> + */

It's not just to make the strict check happy, though that's obviously the direct
motivation, it's so that there's one root of truth. The strict check is there to
enforce that behavior and to make it more clear to readers that it's an either/or
situation.

> + if (!kvm_is_error_gpa(gpc->gpa))
> + uhva = KVM_HVA_ERR_BAD;

This would be a good time to use a ternary operator.

/*
* If the GPA is valid then ignore the HVA, as a cache can be GPA-based
* or HVA-based, not both. For GPA-based caches, the HVA will be
* recomputed during refresh if necessary.
*/
unsigned long uhva = kvm_is_error_gpa(gpc->gpa) ? gpc->uhva :
KVM_HVA_ERR_BAD;