1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 221ebbedaSXiao Guangrong #ifndef _ASM_X86_KVM_PAGE_TRACK_H 321ebbedaSXiao Guangrong #define _ASM_X86_KVM_PAGE_TRACK_H 421ebbedaSXiao Guangrong 5*58ea7cf7SSean Christopherson #include <linux/kvm_types.h> 6*58ea7cf7SSean Christopherson 721ebbedaSXiao Guangrong enum kvm_page_track_mode { 821ebbedaSXiao Guangrong KVM_PAGE_TRACK_WRITE, 921ebbedaSXiao Guangrong KVM_PAGE_TRACK_MAX, 1021ebbedaSXiao Guangrong }; 1121ebbedaSXiao Guangrong 120eb05bf2SXiao Guangrong /* 130eb05bf2SXiao Guangrong * The notifier represented by @kvm_page_track_notifier_node is linked into 140eb05bf2SXiao Guangrong * the head which will be notified when guest is triggering the track event. 150eb05bf2SXiao Guangrong * 160eb05bf2SXiao Guangrong * Write access on the head is protected by kvm->mmu_lock, read access 170eb05bf2SXiao Guangrong * is protected by track_srcu. 180eb05bf2SXiao Guangrong */ 190eb05bf2SXiao Guangrong struct kvm_page_track_notifier_head { 200eb05bf2SXiao Guangrong struct srcu_struct track_srcu; 210eb05bf2SXiao Guangrong struct hlist_head track_notifier_list; 220eb05bf2SXiao Guangrong }; 230eb05bf2SXiao Guangrong 240eb05bf2SXiao Guangrong struct kvm_page_track_notifier_node { 250eb05bf2SXiao Guangrong struct hlist_node node; 260eb05bf2SXiao Guangrong 270eb05bf2SXiao Guangrong /* 280eb05bf2SXiao Guangrong * It is called when guest is writing the write-tracked page 290eb05bf2SXiao Guangrong * and write emulation is finished at that time. 300eb05bf2SXiao Guangrong * 310eb05bf2SXiao Guangrong * @gpa: the physical address written by guest. 320eb05bf2SXiao Guangrong * @new: the data was written to the address. 330eb05bf2SXiao Guangrong * @bytes: the written length. 34d126363dSJike Song * @node: this node 350eb05bf2SXiao Guangrong */ 36b271e17dSSean Christopherson void (*track_write)(gpa_t gpa, const u8 *new, int bytes, 37b271e17dSSean Christopherson struct kvm_page_track_notifier_node *node); 38b83ab124SYan Zhao 39b83ab124SYan Zhao /* 40b83ab124SYan Zhao * Invoked when a memory region is removed from the guest. Or in KVM 41b83ab124SYan Zhao * terms, when a memslot is deleted. 42b83ab124SYan Zhao * 43b83ab124SYan Zhao * @gfn: base gfn of the region being removed 44b83ab124SYan Zhao * @nr_pages: number of pages in the to-be-removed region 45b83ab124SYan Zhao * @node: this node 46b83ab124SYan Zhao */ 47b83ab124SYan Zhao void (*track_remove_region)(gfn_t gfn, unsigned long nr_pages, 48b83ab124SYan Zhao struct kvm_page_track_notifier_node *node); 490eb05bf2SXiao Guangrong }; 500eb05bf2SXiao Guangrong 51f29d4d78SXiao Guangrong void kvm_slot_page_track_add_page(struct kvm *kvm, 52f29d4d78SXiao Guangrong struct kvm_memory_slot *slot, gfn_t gfn, 53f29d4d78SXiao Guangrong enum kvm_page_track_mode mode); 54f29d4d78SXiao Guangrong void kvm_slot_page_track_remove_page(struct kvm *kvm, 55f29d4d78SXiao Guangrong struct kvm_memory_slot *slot, gfn_t gfn, 56f29d4d78SXiao Guangrong enum kvm_page_track_mode mode); 570eb05bf2SXiao Guangrong 580eb05bf2SXiao Guangrong void 590eb05bf2SXiao Guangrong kvm_page_track_register_notifier(struct kvm *kvm, 600eb05bf2SXiao Guangrong struct kvm_page_track_notifier_node *n); 610eb05bf2SXiao Guangrong void 620eb05bf2SXiao Guangrong kvm_page_track_unregister_notifier(struct kvm *kvm, 630eb05bf2SXiao Guangrong struct kvm_page_track_notifier_node *n); 64c70934e0SSean Christopherson 6521ebbedaSXiao Guangrong #endif 66