Re: [PATCH 1/2] KVM: x86: Deduplicate MSR interception enabling and disabling
From: Chao Gao
Date: Sun Jun 15 2025 - 22:20:56 EST
>> --- 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@xxxxxxxxxxxxxxx>
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.