1 // SPDX-License-Identifier: GPL-2.0 2 3 #ifndef __KVM_X86_MMU_TDP_MMU_H 4 #define __KVM_X86_MMU_TDP_MMU_H 5 6 #include <linux/kvm_host.h> 7 8 #include "spte.h" 9 10 void kvm_mmu_init_tdp_mmu(struct kvm *kvm); 11 void kvm_mmu_uninit_tdp_mmu(struct kvm *kvm); 12 13 int kvm_tdp_mmu_alloc_root(struct kvm_vcpu *vcpu); 14 15 __must_check static inline bool kvm_tdp_mmu_get_root(struct kvm_mmu_page *root) 16 { 17 return refcount_inc_not_zero(&root->tdp_mmu_root_count); 18 } 19 20 void kvm_tdp_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *root); 21 22 bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, gfn_t start, gfn_t end, bool flush); 23 bool kvm_tdp_mmu_zap_sp(struct kvm *kvm, struct kvm_mmu_page *sp); 24 void kvm_tdp_mmu_zap_all(struct kvm *kvm); 25 void kvm_tdp_mmu_invalidate_all_roots(struct kvm *kvm); 26 void kvm_tdp_mmu_zap_invalidated_roots(struct kvm *kvm); 27 28 int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault); 29 30 bool kvm_tdp_mmu_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range, 31 bool flush); 32 bool kvm_tdp_mmu_age_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range); 33 bool kvm_tdp_mmu_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range); 34 bool kvm_tdp_mmu_set_spte_gfn(struct kvm *kvm, struct kvm_gfn_range *range); 35 36 bool kvm_tdp_mmu_wrprot_slot(struct kvm *kvm, 37 const struct kvm_memory_slot *slot, int min_level); 38 bool kvm_tdp_mmu_clear_dirty_slot(struct kvm *kvm, 39 const struct kvm_memory_slot *slot); 40 void kvm_tdp_mmu_clear_dirty_pt_masked(struct kvm *kvm, 41 struct kvm_memory_slot *slot, 42 gfn_t gfn, unsigned long mask, 43 bool wrprot); 44 void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm, 45 const struct kvm_memory_slot *slot); 46 47 bool kvm_tdp_mmu_write_protect_gfn(struct kvm *kvm, 48 struct kvm_memory_slot *slot, gfn_t gfn, 49 int min_level); 50 51 void kvm_tdp_mmu_try_split_huge_pages(struct kvm *kvm, 52 const struct kvm_memory_slot *slot, 53 gfn_t start, gfn_t end, 54 int target_level, bool shared); 55 56 static inline void kvm_tdp_mmu_walk_lockless_begin(void) 57 { 58 rcu_read_lock(); 59 } 60 61 static inline void kvm_tdp_mmu_walk_lockless_end(void) 62 { 63 rcu_read_unlock(); 64 } 65 66 int kvm_tdp_mmu_get_walk(struct kvm_vcpu *vcpu, u64 addr, u64 *sptes, 67 int *root_level); 68 u64 *kvm_tdp_mmu_fast_pf_get_last_sptep(struct kvm_vcpu *vcpu, u64 addr, 69 u64 *spte); 70 71 #ifdef CONFIG_X86_64 72 static inline bool is_tdp_mmu_page(struct kvm_mmu_page *sp) { return sp->tdp_mmu_page; } 73 #else 74 static inline bool is_tdp_mmu_page(struct kvm_mmu_page *sp) { return false; } 75 #endif 76 77 #endif /* __KVM_X86_MMU_TDP_MMU_H */ 78