1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_X86_KVM_PAGE_TRACK_H 3 #define _ASM_X86_KVM_PAGE_TRACK_H 4 5 enum kvm_page_track_mode { 6 KVM_PAGE_TRACK_WRITE, 7 KVM_PAGE_TRACK_MAX, 8 }; 9 10 /* 11 * The notifier represented by @kvm_page_track_notifier_node is linked into 12 * the head which will be notified when guest is triggering the track event. 13 * 14 * Write access on the head is protected by kvm->mmu_lock, read access 15 * is protected by track_srcu. 16 */ 17 struct kvm_page_track_notifier_head { 18 struct srcu_struct track_srcu; 19 struct hlist_head track_notifier_list; 20 }; 21 22 struct kvm_page_track_notifier_node { 23 struct hlist_node node; 24 25 /* 26 * It is called when guest is writing the write-tracked page 27 * and write emulation is finished at that time. 28 * 29 * @vcpu: the vcpu where the write access happened. 30 * @gpa: the physical address written by guest. 31 * @new: the data was written to the address. 32 * @bytes: the written length. 33 * @node: this node 34 */ 35 void (*track_write)(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new, 36 int bytes, struct kvm_page_track_notifier_node *node); 37 /* 38 * It is called when memory slot is being moved or removed 39 * users can drop write-protection for the pages in that memory slot 40 * 41 * @kvm: the kvm where memory slot being moved or removed 42 * @slot: the memory slot being moved or removed 43 * @node: this node 44 */ 45 void (*track_flush_slot)(struct kvm *kvm, struct kvm_memory_slot *slot, 46 struct kvm_page_track_notifier_node *node); 47 }; 48 49 int kvm_page_track_init(struct kvm *kvm); 50 void kvm_page_track_cleanup(struct kvm *kvm); 51 52 int kvm_page_track_enable_mmu_write_tracking(struct kvm *kvm); 53 54 void kvm_page_track_free_memslot(struct kvm_memory_slot *slot); 55 int kvm_page_track_create_memslot(struct kvm *kvm, 56 struct kvm_memory_slot *slot, 57 unsigned long npages); 58 59 void kvm_slot_page_track_add_page(struct kvm *kvm, 60 struct kvm_memory_slot *slot, gfn_t gfn, 61 enum kvm_page_track_mode mode); 62 void kvm_slot_page_track_remove_page(struct kvm *kvm, 63 struct kvm_memory_slot *slot, gfn_t gfn, 64 enum kvm_page_track_mode mode); 65 bool kvm_slot_page_track_is_active(struct kvm_vcpu *vcpu, 66 struct kvm_memory_slot *slot, gfn_t gfn, 67 enum kvm_page_track_mode mode); 68 69 void 70 kvm_page_track_register_notifier(struct kvm *kvm, 71 struct kvm_page_track_notifier_node *n); 72 void 73 kvm_page_track_unregister_notifier(struct kvm *kvm, 74 struct kvm_page_track_notifier_node *n); 75 void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new, 76 int bytes); 77 void kvm_page_track_flush_slot(struct kvm *kvm, struct kvm_memory_slot *slot); 78 #endif 79