Re: [PATCH v13 12/21] KVM: x86/xen: allow shared_info to be mapped by fixed HVA

Paul Durrant
2024-02-20T09:03:34Z

On 19/02/2024 21:53, Sean Christopherson wrote:
> On Thu, Feb 15, 2024, Paul Durrant wrote:
>> @@ -715,13 +731,23 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
>> break;
>>
>> case KVM_XEN_ATTR_TYPE_SHARED_INFO:
>> - if (kvm->arch.xen.shinfo_cache.active)
>> + if (kvm->arch.xen.shinfo_cache.active &&
>> + kvm->arch.xen.shinfo_cache.gpa != KVM_XEN_INVALID_GPA)
>
> This should really use INVALID_GPA when checking internal gpc state. Mostly to
> help clarify what is/isn't KVM Xen ABI, but also because I don't like the subtle
> assumption that KVM_XEN_INVALID_GPA == INVALID_GPA.
>

Sorry, yes, that was miss on my part.

> Even better, if we slot in two helpers when the HVA-based GPC support is added,
> then the Xen code doesn't need to to make assumptions about how the GPC code
> manages HVA vs. GPA internally. E.g. if we ever refactor the code again and use
> a dedicated flag instead of gpc->gpa as the implicit flag.
>
> static inline bool kvm_gpc_is_gpa_active(struct gfn_to_pfn_cache *gpc)
> {
> return gpc->active && !kvm_is_error_gpa(gpc->gpa);
> }
>
> static inline bool kvm_gpc_is_hva_active(struct gfn_to_pfn_cache *gpc)
> {
> return gpc->active && kvm_is_error_gpa(gpc->gpa);
> }

Sure, sounds good to me. I'll add those.