[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aFsqMnjTCZSBTO3m@google.com>
Date: Tue, 24 Jun 2025 15:44:02 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: Chao Gao <chao.gao@...el.com>
Cc: Dapeng Mi <dapeng1.mi@...ux.intel.com>, linux-kernel@...r.kernel.org,
kvm@...r.kernel.org, pbonzini@...hat.com
Subject: Re: [PATCH 1/2] KVM: x86: Deduplicate MSR interception enabling and disabling
On Mon, Jun 16, 2025, Chao Gao wrote:
> >> --- a/arch/x86/kvm/vmx/vmx.h
> >> +++ b/arch/x86/kvm/vmx/vmx.h
> >> @@ -388,21 +388,13 @@ void vmx_ept_load_pdptrs(struct kvm_vcpu *vcpu);
> >>
> >> void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type);
> >> void vmx_enable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type);
> >> +void vmx_set_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type, bool enable);
> >>
> >> u64 vmx_get_l2_tsc_offset(struct kvm_vcpu *vcpu);
> >> u64 vmx_get_l2_tsc_multiplier(struct kvm_vcpu *vcpu);
> >>
> >> gva_t vmx_get_untagged_addr(struct kvm_vcpu *vcpu, gva_t gva, unsigned int flags);
> >>
> >> -static inline void vmx_set_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr,
> >> - int type, bool value)
> >> -{
> >> - if (value)
> >> - vmx_enable_intercept_for_msr(vcpu, msr, type);
> >> - else
> >> - vmx_disable_intercept_for_msr(vcpu, msr, type);
> >> -}
> >> -
> >> void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu);
> >>
> >> /*
> >
> >The change looks good to me.
> >
> >Reviewed-by: Dapeng Mi <dapeng1.mi@...ux.intel.com>
>
> Thanks.
>
> >
> >Just curious, is there a preference on using these 3 interfaces? When
> >should we use the disable/enable interfaces? When should be we use the set
> >interface? or no preference?
>
> I think the set API is to reduce boilerplate code. So, use the set API when
> you need to perform conditional logic, such as
>
> if (/*check guest/host caps*/)
> //disable intercept
> else
> //enable intercept
>
> otherwise, use the disable/enable APIs.
Yep. The preference is to use the API that is most appropriate for the code.
E.g. if the code unconditionally enables/disables interceptions, then it should
use the appropriate wrapper.
Powered by blists - more mailing lists