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