linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Chao Gao <chao.gao@intel.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>,
	linux-kernel@vger.kernel.org,  kvm@vger.kernel.org,
	pbonzini@redhat.com
Subject: Re: [PATCH 1/2] KVM: x86: Deduplicate MSR interception enabling and disabling
Date: Tue, 24 Jun 2025 15:44:02 -0700	[thread overview]
Message-ID: <aFsqMnjTCZSBTO3m@google.com> (raw)
In-Reply-To: <aE9/ayZNEXoA/ZEE@intel.com>

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@linux.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.

  reply	other threads:[~2025-06-24 22:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-12  8:19 [PATCH 0/2] More cleanups to MSR interception code Chao Gao
2025-06-12  8:19 ` [PATCH 1/2] KVM: x86: Deduplicate MSR interception enabling and disabling Chao Gao
2025-06-12 11:25   ` Nikolay Borisov
2025-06-12 12:04     ` Chao Gao
2025-06-13  1:37   ` Mi, Dapeng
2025-06-16  2:20     ` Chao Gao
2025-06-24 22:44       ` Sean Christopherson [this message]
2025-06-24 22:47   ` Sean Christopherson
2025-06-25 10:57     ` Chao Gao
2025-06-12  8:19 ` [PATCH 2/2] KVM: SVM: Simplify MSR interception logic for IA32_XSS MSR Chao Gao
2025-06-13  1:39   ` Mi, Dapeng
2025-06-24 22:48   ` Sean Christopherson
2025-06-25  7:20   ` Binbin Wu
2025-06-25 22:25 ` [PATCH 0/2] More cleanups to MSR interception code Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aFsqMnjTCZSBTO3m@google.com \
    --to=seanjc@google.com \
    --cc=chao.gao@intel.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).