Re: [PATCH v7 05/11] KVM: pfncache: allow a cache to be activated with a fixed (userspace) HVA

From: Sean Christopherson
Date: Fri Nov 03 2023 - 19:12:22 EST


On Thu, Nov 02, 2023, Paul Durrant wrote:
> On 31/10/2023 23:49, Sean Christopherson wrote:
> > On Mon, Oct 02, 2023, Paul Durrant wrote:
> > > diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
> > > index 6f4737d5046a..d49946ee7ae3 100644
> > > --- a/include/linux/kvm_types.h
> > > +++ b/include/linux/kvm_types.h
> > > @@ -64,7 +64,7 @@ struct gfn_to_hva_cache {
> > > struct gfn_to_pfn_cache {
> > > u64 generation;
> > > - gpa_t gpa;
> > > + u64 addr;
> >
> > Holy moly, we have unions for exactly this reason.
> >
> > union {
> > gpa_t gpa;
> > unsigned long addr;
> > };
> >
> > But that's also weird and silly because it's basically the exact same thing as
> > "uhva". If "uhva" stores the full address instead of the page-aligned address,
> > then I don't see a need for unionizing the gpa and uhva.
>
> Ok, I think that'll be more invasive but I'll see how it looks.

Invasive is fine. Not ideal, but fine. If the resulting code is a mess, then
that's a problem, but churn in and of itself isn't awful if the end result is a
net positive.

> > kvm_xen_vcpu_get_attr() should darn well explicitly check that the gpc stores
> > the correct type and not bleed ABI into the gfn_to_pfn_cache implementation.
>
> I guess if we leave gpa alone and make it INVALID_GPA for caches initialized
> using an HVA then that can be checked. Is that what you mean here?

Yep, that should work.