On 2/16/2023 5:52 AM, Sean Christopherson wrote: > On Wed, Feb 15, 2023, Sean Christopherson wrote: >> On Tue, Feb 14, 2023, Santosh Shukla wrote: >>> " >>> V_NMI_MASK: Indicates whether virtual NMIs are masked. The processor will set V_NMI_MASK >>> once it takes the virtual NMI. V_NMI_MASK is cleared when the guest successfully completes an >>> IRET instruction or #VMEXIT occurs while delivering the virtual NMI >>> " >>> >>> In my initial implementation I had changed V_NMI_MASK for the SMM scenario [1], >>> This is also not required as HW will save the V_NMI/V_NMI_MASK on >>> SMM entry and restore them on RSM. >>> >>> That said the svm_{get,set}_nmi_mask will look something like: > > ... > >>> static void svm_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked) >>> { >>> struct vcpu_svm *svm = to_svm(vcpu); >>> >>> + if (is_vnmi_enabled(svm)) >>> + return; >>> + >>> if (masked) { >>> svm->nmi_masked = true; >>> svm_set_iret_intercept(svm); >>> >>> is there any inputs on above approach? >> >> What happens if software clears the "NMIs are blocked" flag? If KVM can't clear >> the flag, then we've got problems. E.g. if KVM emulates IRET or SMI+RSM. And I >> I believe there are use cases that use KVM to snapshot and reload vCPU state, >> e.g. record+replay?, in which case KVM_SET_VCPU_EVENTS needs to be able to adjust >> NMI blocking too. > > Actually, what am I thinking. Any type of state save/restore will need to stuff > NMI blocking. E.g. live migration of a VM that is handling an NMI (V_NMI_MASK=1) > _and_ has a pending NMI (V_NMI=1) absolutely needs to set V_NMI_MASK=1 on the dest, > otherwise the pending NMI will get serviced when the guest expects NMIs to be blocked. Sure, Make sense. Will include V_NMI_BLOCKING_MASK set/clear in svm_set_nmi_mask() in v3 and will soon share patches for review. Thanks.