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