1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_KVM_PAGE_TRACK_H
3 #define _ASM_X86_KVM_PAGE_TRACK_H
5 #include <linux/kvm_types.h>
7 #ifdef CONFIG_KVM_EXTERNAL_WRITE_TRACKING
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.
12 * Write access on the head is protected by kvm->mmu_lock, read access
13 * is protected by track_srcu.
15 struct kvm_page_track_notifier_head {
16 struct srcu_struct track_srcu;
17 struct hlist_head track_notifier_list;
20 struct kvm_page_track_notifier_node {
21 struct hlist_node node;
24 * It is called when guest is writing the write-tracked page
25 * and write emulation is finished at that time.
27 * @gpa: the physical address written by guest.
28 * @new: the data was written to the address.
29 * @bytes: the written length.
32 void (*track_write)(gpa_t gpa, const u8 *new, int bytes,
33 struct kvm_page_track_notifier_node *node);
36 * Invoked when a memory region is removed from the guest. Or in KVM
37 * terms, when a memslot is deleted.
39 * @gfn: base gfn of the region being removed
40 * @nr_pages: number of pages in the to-be-removed region
43 void (*track_remove_region)(gfn_t gfn, unsigned long nr_pages,
44 struct kvm_page_track_notifier_node *node);
47 int kvm_page_track_register_notifier(struct kvm *kvm,
48 struct kvm_page_track_notifier_node *n);
49 void kvm_page_track_unregister_notifier(struct kvm *kvm,
50 struct kvm_page_track_notifier_node *n);
52 int kvm_write_track_add_gfn(struct kvm *kvm, gfn_t gfn);
53 int kvm_write_track_remove_gfn(struct kvm *kvm, gfn_t gfn);
56 * Allow defining a node in a structure even if page tracking is disabled, e.g.
57 * to play nice with testing headers via direct inclusion from the command line.
59 struct kvm_page_track_notifier_node {};
60 #endif /* CONFIG_KVM_EXTERNAL_WRITE_TRACKING */