blob: 6226cb0eca238fe9b3ddcede6268c5dbc62a4e0c [file] [log] [blame]
Xiao Guangrong21ebbed2016-02-24 17:51:09 +08001#ifndef _ASM_X86_KVM_PAGE_TRACK_H
2#define _ASM_X86_KVM_PAGE_TRACK_H
3
4enum kvm_page_track_mode {
5 KVM_PAGE_TRACK_WRITE,
6 KVM_PAGE_TRACK_MAX,
7};
8
Xiao Guangrong0eb05bf2016-02-24 17:51:13 +08009/*
10 * The notifier represented by @kvm_page_track_notifier_node is linked into
11 * the head which will be notified when guest is triggering the track event.
12 *
13 * Write access on the head is protected by kvm->mmu_lock, read access
14 * is protected by track_srcu.
15 */
16struct kvm_page_track_notifier_head {
17 struct srcu_struct track_srcu;
18 struct hlist_head track_notifier_list;
19};
20
21struct kvm_page_track_notifier_node {
22 struct hlist_node node;
23
24 /*
25 * It is called when guest is writing the write-tracked page
26 * and write emulation is finished at that time.
27 *
28 * @vcpu: the vcpu where the write access happened.
29 * @gpa: the physical address written by guest.
30 * @new: the data was written to the address.
31 * @bytes: the written length.
32 */
33 void (*track_write)(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new,
34 int bytes);
35};
36
37void kvm_page_track_init(struct kvm *kvm);
Paolo Bonzini3e8c6bd2017-03-27 17:53:50 +020038void kvm_page_track_cleanup(struct kvm *kvm);
Xiao Guangrong0eb05bf2016-02-24 17:51:13 +080039
Xiao Guangrong21ebbed2016-02-24 17:51:09 +080040void kvm_page_track_free_memslot(struct kvm_memory_slot *free,
41 struct kvm_memory_slot *dont);
42int kvm_page_track_create_memslot(struct kvm_memory_slot *slot,
43 unsigned long npages);
Xiao Guangrongf29d4d72016-02-24 17:51:10 +080044
45void kvm_slot_page_track_add_page(struct kvm *kvm,
46 struct kvm_memory_slot *slot, gfn_t gfn,
47 enum kvm_page_track_mode mode);
48void kvm_slot_page_track_remove_page(struct kvm *kvm,
49 struct kvm_memory_slot *slot, gfn_t gfn,
50 enum kvm_page_track_mode mode);
Xiao Guangrong3d0c27a2016-02-24 17:51:11 +080051bool kvm_page_track_is_active(struct kvm_vcpu *vcpu, gfn_t gfn,
52 enum kvm_page_track_mode mode);
Xiao Guangrong0eb05bf2016-02-24 17:51:13 +080053
54void
55kvm_page_track_register_notifier(struct kvm *kvm,
56 struct kvm_page_track_notifier_node *n);
57void
58kvm_page_track_unregister_notifier(struct kvm *kvm,
59 struct kvm_page_track_notifier_node *n);
60void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new,
61 int bytes);
Xiao Guangrong21ebbed2016-02-24 17:51:09 +080062#endif