xref: /openbmc/linux/arch/x86/kvm/mmu/page_track.h (revision f2a55d08)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __KVM_X86_PAGE_TRACK_H
3 #define __KVM_X86_PAGE_TRACK_H
4 
5 #include <linux/kvm_host.h>
6 
7 #include <asm/kvm_page_track.h>
8 
9 
10 bool kvm_page_track_write_tracking_enabled(struct kvm *kvm);
11 int kvm_page_track_write_tracking_alloc(struct kvm_memory_slot *slot);
12 
13 void kvm_page_track_free_memslot(struct kvm_memory_slot *slot);
14 int kvm_page_track_create_memslot(struct kvm *kvm,
15 				  struct kvm_memory_slot *slot,
16 				  unsigned long npages);
17 
18 void __kvm_write_track_add_gfn(struct kvm *kvm, struct kvm_memory_slot *slot,
19 			       gfn_t gfn);
20 void __kvm_write_track_remove_gfn(struct kvm *kvm,
21 				  struct kvm_memory_slot *slot, gfn_t gfn);
22 
23 bool kvm_gfn_is_write_tracked(struct kvm *kvm,
24 			      const struct kvm_memory_slot *slot, gfn_t gfn);
25 
26 #ifdef CONFIG_KVM_EXTERNAL_WRITE_TRACKING
27 int kvm_page_track_init(struct kvm *kvm);
28 void kvm_page_track_cleanup(struct kvm *kvm);
29 
30 void __kvm_page_track_write(struct kvm *kvm, gpa_t gpa, const u8 *new, int bytes);
31 void kvm_page_track_delete_slot(struct kvm *kvm, struct kvm_memory_slot *slot);
32 
33 static inline bool kvm_page_track_has_external_user(struct kvm *kvm)
34 {
35 	return !hlist_empty(&kvm->arch.track_notifier_head.track_notifier_list);
36 }
37 #else
38 static inline int kvm_page_track_init(struct kvm *kvm) { return 0; }
39 static inline void kvm_page_track_cleanup(struct kvm *kvm) { }
40 
41 static inline void __kvm_page_track_write(struct kvm *kvm, gpa_t gpa,
42 					  const u8 *new, int bytes) { }
43 static inline void kvm_page_track_delete_slot(struct kvm *kvm,
44 					      struct kvm_memory_slot *slot) { }
45 
46 static inline bool kvm_page_track_has_external_user(struct kvm *kvm) { return false; }
47 
48 #endif /* CONFIG_KVM_EXTERNAL_WRITE_TRACKING */
49 
50 static inline void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa,
51 					const u8 *new, int bytes)
52 {
53 	__kvm_page_track_write(vcpu->kvm, gpa, new, bytes);
54 
55 	kvm_mmu_track_write(vcpu, gpa, new, bytes);
56 }
57 
58 #endif /* __KVM_X86_PAGE_TRACK_H */
59