On Mon, 2021-04-05 at 15:38 +0000, Sean Christopherson wrote: > On Mon, Jan 25, 2021, Robert Hoo wrote: > > diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h > > index f6f66e5..94f1c27 100644 > > --- a/arch/x86/kvm/vmx/vmx.h > > +++ b/arch/x86/kvm/vmx/vmx.h > > @@ -373,6 +373,14 @@ static inline u8 vmx_get_rvi(void) > > BUILD_CONTROLS_SHADOW(exec, CPU_BASED_VM_EXEC_CONTROL) > > BUILD_CONTROLS_SHADOW(secondary_exec, SECONDARY_VM_EXEC_CONTROL) > > > > +static inline void tertiary_exec_controls_set(struct vcpu_vmx > > *vmx, u64 val) > > +{ > > + if (vmx->loaded_vmcs->controls_shadow.tertiary_exec != val) { > > + vmcs_write64(TERTIARY_VM_EXEC_CONTROL, val); > > + vmx->loaded_vmcs->controls_shadow.tertiary_exec = val; > > + } > > +} > > Add a "bits" param to the builder macros and use string > concatenation, then the > tertiary controls can share those macros. > > diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h > index 7886a08505cc..328039157535 100644 > --- a/arch/x86/kvm/vmx/vmx.h > +++ b/arch/x86/kvm/vmx/vmx.h > @@ -398,25 +398,25 @@ static inline u8 vmx_get_rvi(void) > return vmcs_read16(GUEST_INTR_STATUS) & 0xff; > } > > -#define BUILD_CONTROLS_SHADOW(lname, > uname) \ > -static inline void lname##_controls_set(struct vcpu_vmx *vmx, u32 > val) \ > -{ > \ > - if (vmx->loaded_vmcs->controls_shadow.lname != val) > { \ > - vmcs_write32(uname, > val); \ > - vmx->loaded_vmcs->controls_shadow.lname = > val; \ > - } > \ > -} > \ > -static inline u32 lname##_controls_get(struct vcpu_vmx > *vmx) \ > -{ > \ > - return vmx->loaded_vmcs- > >controls_shadow.lname; \ > -} > \ > -static inline void lname##_controls_setbit(struct vcpu_vmx *vmx, u32 > val) \ > -{ > \ > - lname##_controls_set(vmx, lname##_controls_get(vmx) | > val); \ > -} > \ > -static inline void lname##_controls_clearbit(struct vcpu_vmx *vmx, > u32 val) \ > -{ > \ > - lname##_controls_set(vmx, lname##_controls_get(vmx) & > ~val); \ > +#define BUILD_CONTROLS_SHADOW(lname, uname, > bits) \ > +static inline void lname##_controls_set(struct vcpu_vmx *vmx, > u##bits val) \ > +{ > \ > + if (vmx->loaded_vmcs->controls_shadow.lname != val) > { \ > + vmcs_write##bits(uname, > val); \ > + vmx->loaded_vmcs->controls_shadow.lname = > val; \ > + } > \ > +} > \ > +static inline u##bits lname##_controls_get(struct vcpu_vmx > *vmx) \ > +{ > \ > + return vmx->loaded_vmcs- > >controls_shadow.lname; \ > +} > \ > +static inline void lname##_controls_setbit(struct vcpu_vmx *vmx, > u##bits val) \ > +{ > \ > + lname##_controls_set(vmx, lname##_controls_get(vmx) | > val); \ > +} > \ > +static inline void lname##_controls_clearbit(struct vcpu_vmx *vmx, > u##bits val) \ > +{ > \ > + lname##_controls_set(vmx, lname##_controls_get(vmx) & > ~val); \ > } > BUILD_CONTROLS_SHADOW(vm_entry, VM_ENTRY_CONTROLS) > BUILD_CONTROLS_SHADOW(vm_exit, VM_EXIT_CONTROLS) > Nice. I like this. Thanks Sean. Shall I separated this hunk a patch and have your "Signed-off-by:"? > > + > > static inline void vmx_register_cache_reset(struct kvm_vcpu *vcpu) > > { > > vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << > > VCPU_REGS_RSP) > > -- > > 1.8.3.1 > >