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