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 558ea7cf7SSean Christopherson #include <linux/kvm_types.h> 658ea7cf7SSean Christopherson 721ebbedaSXiao Guangrong enum kvm_page_track_mode { 821ebbedaSXiao Guangrong KVM_PAGE_TRACK_WRITE, 921ebbedaSXiao Guangrong KVM_PAGE_TRACK_MAX, 1021ebbedaSXiao Guangrong }; 1121ebbedaSXiao Guangrong 12*e998fb1aSSean Christopherson void kvm_slot_page_track_add_page(struct kvm *kvm, 13*e998fb1aSSean Christopherson struct kvm_memory_slot *slot, gfn_t gfn, 14*e998fb1aSSean Christopherson enum kvm_page_track_mode mode); 15*e998fb1aSSean Christopherson void kvm_slot_page_track_remove_page(struct kvm *kvm, 16*e998fb1aSSean Christopherson struct kvm_memory_slot *slot, gfn_t gfn, 17*e998fb1aSSean Christopherson enum kvm_page_track_mode mode); 18*e998fb1aSSean Christopherson 19*e998fb1aSSean Christopherson #ifdef CONFIG_KVM_EXTERNAL_WRITE_TRACKING 200eb05bf2SXiao Guangrong /* 210eb05bf2SXiao Guangrong * The notifier represented by @kvm_page_track_notifier_node is linked into 220eb05bf2SXiao Guangrong * the head which will be notified when guest is triggering the track event. 230eb05bf2SXiao Guangrong * 240eb05bf2SXiao Guangrong * Write access on the head is protected by kvm->mmu_lock, read access 250eb05bf2SXiao Guangrong * is protected by track_srcu. 260eb05bf2SXiao Guangrong */ 270eb05bf2SXiao Guangrong struct kvm_page_track_notifier_head { 280eb05bf2SXiao Guangrong struct srcu_struct track_srcu; 290eb05bf2SXiao Guangrong struct hlist_head track_notifier_list; 300eb05bf2SXiao Guangrong }; 310eb05bf2SXiao Guangrong 320eb05bf2SXiao Guangrong struct kvm_page_track_notifier_node { 330eb05bf2SXiao Guangrong struct hlist_node node; 340eb05bf2SXiao Guangrong 350eb05bf2SXiao Guangrong /* 360eb05bf2SXiao Guangrong * It is called when guest is writing the write-tracked page 370eb05bf2SXiao Guangrong * and write emulation is finished at that time. 380eb05bf2SXiao Guangrong * 390eb05bf2SXiao Guangrong * @gpa: the physical address written by guest. 400eb05bf2SXiao Guangrong * @new: the data was written to the address. 410eb05bf2SXiao Guangrong * @bytes: the written length. 42d126363dSJike Song * @node: this node 430eb05bf2SXiao Guangrong */ 44b271e17dSSean Christopherson void (*track_write)(gpa_t gpa, const u8 *new, int bytes, 45b271e17dSSean Christopherson struct kvm_page_track_notifier_node *node); 46b83ab124SYan Zhao 47b83ab124SYan Zhao /* 48b83ab124SYan Zhao * Invoked when a memory region is removed from the guest. Or in KVM 49b83ab124SYan Zhao * terms, when a memslot is deleted. 50b83ab124SYan Zhao * 51b83ab124SYan Zhao * @gfn: base gfn of the region being removed 52b83ab124SYan Zhao * @nr_pages: number of pages in the to-be-removed region 53b83ab124SYan Zhao * @node: this node 54b83ab124SYan Zhao */ 55b83ab124SYan Zhao void (*track_remove_region)(gfn_t gfn, unsigned long nr_pages, 56b83ab124SYan Zhao struct kvm_page_track_notifier_node *node); 570eb05bf2SXiao Guangrong }; 580eb05bf2SXiao Guangrong 590eb05bf2SXiao Guangrong void 600eb05bf2SXiao Guangrong kvm_page_track_register_notifier(struct kvm *kvm, 610eb05bf2SXiao Guangrong struct kvm_page_track_notifier_node *n); 620eb05bf2SXiao Guangrong void 630eb05bf2SXiao Guangrong kvm_page_track_unregister_notifier(struct kvm *kvm, 640eb05bf2SXiao Guangrong struct kvm_page_track_notifier_node *n); 65*e998fb1aSSean Christopherson #else 66*e998fb1aSSean Christopherson /* 67*e998fb1aSSean Christopherson * Allow defining a node in a structure even if page tracking is disabled, e.g. 68*e998fb1aSSean Christopherson * to play nice with testing headers via direct inclusion from the command line. 69*e998fb1aSSean Christopherson */ 70*e998fb1aSSean Christopherson struct kvm_page_track_notifier_node {}; 71*e998fb1aSSean Christopherson #endif /* CONFIG_KVM_EXTERNAL_WRITE_TRACKING */ 72c70934e0SSean Christopherson 7321ebbedaSXiao Guangrong #endif 74