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 #include <linux/kvm_types.h> 6 7 enum kvm_page_track_mode { 8 KVM_PAGE_TRACK_WRITE, 9 KVM_PAGE_TRACK_MAX, 10 }; 11 12 void kvm_slot_page_track_add_page(struct kvm *kvm, 13 struct kvm_memory_slot *slot, gfn_t gfn, 14 enum kvm_page_track_mode mode); 15 void kvm_slot_page_track_remove_page(struct kvm *kvm, 16 struct kvm_memory_slot *slot, gfn_t gfn, 17 enum kvm_page_track_mode mode); 18 19 #ifdef CONFIG_KVM_EXTERNAL_WRITE_TRACKING 20 /* 21 * The notifier represented by @kvm_page_track_notifier_node is linked into 22 * the head which will be notified when guest is triggering the track event. 23 * 24 * Write access on the head is protected by kvm->mmu_lock, read access 25 * is protected by track_srcu. 26 */ 27 struct kvm_page_track_notifier_head { 28 struct srcu_struct track_srcu; 29 struct hlist_head track_notifier_list; 30 }; 31 32 struct kvm_page_track_notifier_node { 33 struct hlist_node node; 34 35 /* 36 * It is called when guest is writing the write-tracked page 37 * and write emulation is finished at that time. 38 * 39 * @gpa: the physical address written by guest. 40 * @new: the data was written to the address. 41 * @bytes: the written length. 42 * @node: this node 43 */ 44 void (*track_write)(gpa_t gpa, const u8 *new, int bytes, 45 struct kvm_page_track_notifier_node *node); 46 47 /* 48 * Invoked when a memory region is removed from the guest. Or in KVM 49 * terms, when a memslot is deleted. 50 * 51 * @gfn: base gfn of the region being removed 52 * @nr_pages: number of pages in the to-be-removed region 53 * @node: this node 54 */ 55 void (*track_remove_region)(gfn_t gfn, unsigned long nr_pages, 56 struct kvm_page_track_notifier_node *node); 57 }; 58 59 void 60 kvm_page_track_register_notifier(struct kvm *kvm, 61 struct kvm_page_track_notifier_node *n); 62 void 63 kvm_page_track_unregister_notifier(struct kvm *kvm, 64 struct kvm_page_track_notifier_node *n); 65 #else 66 /* 67 * Allow defining a node in a structure even if page tracking is disabled, e.g. 68 * to play nice with testing headers via direct inclusion from the command line. 69 */ 70 struct kvm_page_track_notifier_node {}; 71 #endif /* CONFIG_KVM_EXTERNAL_WRITE_TRACKING */ 72 73 #endif 74