121ebbedaSXiao Guangrong #ifndef _ASM_X86_KVM_PAGE_TRACK_H 221ebbedaSXiao Guangrong #define _ASM_X86_KVM_PAGE_TRACK_H 321ebbedaSXiao Guangrong 421ebbedaSXiao Guangrong enum kvm_page_track_mode { 521ebbedaSXiao Guangrong KVM_PAGE_TRACK_WRITE, 621ebbedaSXiao Guangrong KVM_PAGE_TRACK_MAX, 721ebbedaSXiao Guangrong }; 821ebbedaSXiao Guangrong 90eb05bf2SXiao Guangrong /* 100eb05bf2SXiao Guangrong * The notifier represented by @kvm_page_track_notifier_node is linked into 110eb05bf2SXiao Guangrong * the head which will be notified when guest is triggering the track event. 120eb05bf2SXiao Guangrong * 130eb05bf2SXiao Guangrong * Write access on the head is protected by kvm->mmu_lock, read access 140eb05bf2SXiao Guangrong * is protected by track_srcu. 150eb05bf2SXiao Guangrong */ 160eb05bf2SXiao Guangrong struct kvm_page_track_notifier_head { 170eb05bf2SXiao Guangrong struct srcu_struct track_srcu; 180eb05bf2SXiao Guangrong struct hlist_head track_notifier_list; 190eb05bf2SXiao Guangrong }; 200eb05bf2SXiao Guangrong 210eb05bf2SXiao Guangrong struct kvm_page_track_notifier_node { 220eb05bf2SXiao Guangrong struct hlist_node node; 230eb05bf2SXiao Guangrong 240eb05bf2SXiao Guangrong /* 250eb05bf2SXiao Guangrong * It is called when guest is writing the write-tracked page 260eb05bf2SXiao Guangrong * and write emulation is finished at that time. 270eb05bf2SXiao Guangrong * 280eb05bf2SXiao Guangrong * @vcpu: the vcpu where the write access happened. 290eb05bf2SXiao Guangrong * @gpa: the physical address written by guest. 300eb05bf2SXiao Guangrong * @new: the data was written to the address. 310eb05bf2SXiao Guangrong * @bytes: the written length. 320eb05bf2SXiao Guangrong */ 330eb05bf2SXiao Guangrong void (*track_write)(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new, 340eb05bf2SXiao Guangrong int bytes); 350eb05bf2SXiao Guangrong }; 360eb05bf2SXiao Guangrong 370eb05bf2SXiao Guangrong void kvm_page_track_init(struct kvm *kvm); 380eb05bf2SXiao Guangrong 3921ebbedaSXiao Guangrong void kvm_page_track_free_memslot(struct kvm_memory_slot *free, 4021ebbedaSXiao Guangrong struct kvm_memory_slot *dont); 4121ebbedaSXiao Guangrong int kvm_page_track_create_memslot(struct kvm_memory_slot *slot, 4221ebbedaSXiao Guangrong unsigned long npages); 43f29d4d78SXiao Guangrong 44f29d4d78SXiao Guangrong void kvm_slot_page_track_add_page(struct kvm *kvm, 45f29d4d78SXiao Guangrong struct kvm_memory_slot *slot, gfn_t gfn, 46f29d4d78SXiao Guangrong enum kvm_page_track_mode mode); 47f29d4d78SXiao Guangrong void kvm_slot_page_track_remove_page(struct kvm *kvm, 48f29d4d78SXiao Guangrong struct kvm_memory_slot *slot, gfn_t gfn, 49f29d4d78SXiao Guangrong enum kvm_page_track_mode mode); 503d0c27adSXiao Guangrong bool kvm_page_track_is_active(struct kvm_vcpu *vcpu, gfn_t gfn, 513d0c27adSXiao Guangrong enum kvm_page_track_mode mode); 520eb05bf2SXiao Guangrong 530eb05bf2SXiao Guangrong void 540eb05bf2SXiao Guangrong kvm_page_track_register_notifier(struct kvm *kvm, 550eb05bf2SXiao Guangrong struct kvm_page_track_notifier_node *n); 560eb05bf2SXiao Guangrong void 570eb05bf2SXiao Guangrong kvm_page_track_unregister_notifier(struct kvm *kvm, 580eb05bf2SXiao Guangrong struct kvm_page_track_notifier_node *n); 590eb05bf2SXiao Guangrong void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new, 600eb05bf2SXiao Guangrong int bytes); 6121ebbedaSXiao Guangrong #endif 62