Re: [PATCH] KVM: x86: revalidate steal time cache if MSR value changes

From: Sean Christopherson
Date: Thu Aug 04 2022 - 13:42:21 EST


On Thu, Aug 04, 2022, Dr. David Alan Gilbert wrote:
> * Vitaly Kuznetsov (vkuznets@xxxxxxxxxx) wrote:
> > Paolo Bonzini <pbonzini@xxxxxxxxxx> writes:
> > > - gfn_t gfn = vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS;
> > > -
> > > /* We rely on the fact that it fits in a single page. */
> > > BUILD_BUG_ON((sizeof(*st) - 1) & KVM_STEAL_VALID_BITS);
> > >
> > > - if (kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, gfn, sizeof(*st)) ||
> > > + if (kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, gpa, sizeof(*st)) ||
> >
> > (It would be nice to somehow get at least a warning when 'gfn_t' is used
> > instead of 'gpa_t' and vice versa)
>
> Can't sparse be taught to do that?

Hmm, it probably could, but the result would likely be a mess. E.g. anything that
shifts the GPA on-demand will require explicit casts to make sparse happy.

This particular case is solvable without sparse, e.g. WARN if gpa[11:0]!=0, or
even better rework the function to actually take a @gfn and then WARN if the
incoming gfn would yield an illegal gpa.