On Fri, Aug 25, 2023 at 02:46:07PM -0700, Sean Christopherson wrote: > On Fri, Jul 14, 2023, Yan Zhao wrote: > > Centralize the code to get cache disabled memtype when guest MTRRs are > > honored. If a TDP honors guest MTRRs, it is required to call the provided > > API to get the memtype for CR0.CD=1. > > > > This is the preparation patch for later implementation of fine-grained gfn > > zap for CR0.CD toggles when guest MTRRs are honored. > > > > No functional change intended. > > > > Signed-off-by: Yan Zhao <yan.y.zhao@xxxxxxxxx> > > --- > > arch/x86/kvm/mtrr.c | 16 ++++++++++++++++ > > arch/x86/kvm/vmx/vmx.c | 10 +++++----- > > arch/x86/kvm/x86.h | 2 ++ > > 3 files changed, 23 insertions(+), 5 deletions(-) > > > > diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c > > index 3ce58734ad22..64c6daa659c8 100644 > > --- a/arch/x86/kvm/mtrr.c > > +++ b/arch/x86/kvm/mtrr.c > > @@ -721,3 +721,19 @@ bool kvm_mtrr_check_gfn_range_consistency(struct kvm_vcpu *vcpu, gfn_t gfn, > > > > return type == mtrr_default_type(mtrr_state); > > } > > + > > +/* > > + * this routine is supposed to be called when guest mtrrs are honored > > + */ > > +void kvm_honors_guest_mtrrs_get_cd_memtype(struct kvm_vcpu *vcpu, > > + u8 *type, bool *ipat) > > I really don't like this helper. IMO it's a big net negative for the readability > of vmx_get_mt_mask(). As I said in the previous version, I agree that splitting > logic is generally undesirable, but in this case I strongly believe it's the > lesser evil. > Ok, will drop this helper in the next version :)