On 8/4/23 11:53, Paolo Bonzini wrote: > On 8/3/23 23:15, Michal Luczaj wrote: >>> *mmu_reset_needed |= kvm_read_cr0(vcpu) != sregs->cr0; >>> >>> with a call to the function just before __set_sregs_common returns. >> What about kvm_post_set_cr4() then? Should it be introduced to >> __set_sregs_common() as well? > > Yes, indeed, but it starts getting a bit unwieldy. > > If we decide not to particularly optimize KVM_SYNC_X86_SREGS, however, > we can just chuck a KVM_REQ_TLB_FLUSH_GUEST request after __set_sregs > and __set_sregs2 call kvm_mmu_reset_context(). Something like this? @@ -11562,8 +11562,10 @@ static int __set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) if (ret) return ret; - if (mmu_reset_needed) + if (mmu_reset_needed) { kvm_mmu_reset_context(vcpu); + kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); + } max_bits = KVM_NR_INTERRUPTS; pending_vec = find_first_bit( @@ -11604,8 +11606,10 @@ static int __set_sregs2(struct kvm_vcpu *vcpu, struct kvm_sregs2 *sregs2) mmu_reset_needed = 1; vcpu->arch.pdptrs_from_userspace = true; } - if (mmu_reset_needed) + if (mmu_reset_needed) { kvm_mmu_reset_context(vcpu); + kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu); + } return 0; }