1fe5db27dSBen Gardon // SPDX-License-Identifier: GPL-2.0 2fe5db27dSBen Gardon 3fe5db27dSBen Gardon #ifndef __KVM_X86_MMU_TDP_MMU_H 4fe5db27dSBen Gardon #define __KVM_X86_MMU_TDP_MMU_H 5fe5db27dSBen Gardon 6fe5db27dSBen Gardon #include <linux/kvm_host.h> 7fe5db27dSBen Gardon 802c00b3aSBen Gardon hpa_t kvm_tdp_mmu_get_vcpu_root_hpa(struct kvm_vcpu *vcpu); 902c00b3aSBen Gardon void kvm_tdp_mmu_free_root(struct kvm *kvm, struct kvm_mmu_page *root); 1002c00b3aSBen Gardon 11faaf05b0SBen Gardon bool kvm_tdp_mmu_zap_gfn_range(struct kvm *kvm, gfn_t start, gfn_t end); 12faaf05b0SBen Gardon void kvm_tdp_mmu_zap_all(struct kvm *kvm); 13bb18842eSBen Gardon 14bb18842eSBen Gardon int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, 15bb18842eSBen Gardon int map_writable, int max_level, kvm_pfn_t pfn, 16bb18842eSBen Gardon bool prefault); 17063afacdSBen Gardon 18063afacdSBen Gardon int kvm_tdp_mmu_zap_hva_range(struct kvm *kvm, unsigned long start, 19063afacdSBen Gardon unsigned long end); 20f8e14497SBen Gardon 21f8e14497SBen Gardon int kvm_tdp_mmu_age_hva_range(struct kvm *kvm, unsigned long start, 22f8e14497SBen Gardon unsigned long end); 23f8e14497SBen Gardon int kvm_tdp_mmu_test_age_hva(struct kvm *kvm, unsigned long hva); 241d8dd6b3SBen Gardon 251d8dd6b3SBen Gardon int kvm_tdp_mmu_set_spte_hva(struct kvm *kvm, unsigned long address, 261d8dd6b3SBen Gardon pte_t *host_ptep); 27a6a0b05dSBen Gardon 28a6a0b05dSBen Gardon bool kvm_tdp_mmu_wrprot_slot(struct kvm *kvm, struct kvm_memory_slot *slot, 29a6a0b05dSBen Gardon int min_level); 30a6a0b05dSBen Gardon bool kvm_tdp_mmu_clear_dirty_slot(struct kvm *kvm, 31a6a0b05dSBen Gardon struct kvm_memory_slot *slot); 32a6a0b05dSBen Gardon void kvm_tdp_mmu_clear_dirty_pt_masked(struct kvm *kvm, 33a6a0b05dSBen Gardon struct kvm_memory_slot *slot, 34a6a0b05dSBen Gardon gfn_t gfn, unsigned long mask, 35a6a0b05dSBen Gardon bool wrprot); 36a6a0b05dSBen Gardon bool kvm_tdp_mmu_slot_set_dirty(struct kvm *kvm, struct kvm_memory_slot *slot); 3714881998SBen Gardon void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm, 3814881998SBen Gardon const struct kvm_memory_slot *slot); 3946044f72SBen Gardon 4046044f72SBen Gardon bool kvm_tdp_mmu_write_protect_gfn(struct kvm *kvm, 4146044f72SBen Gardon struct kvm_memory_slot *slot, gfn_t gfn); 4295fb5b02SBen Gardon 4339b4d43eSSean Christopherson int kvm_tdp_mmu_get_walk(struct kvm_vcpu *vcpu, u64 addr, u64 *sptes, 4439b4d43eSSean Christopherson int *root_level); 4539b4d43eSSean Christopherson 46*897218ffSPaolo Bonzini #ifdef CONFIG_X86_64 47*897218ffSPaolo Bonzini void kvm_mmu_init_tdp_mmu(struct kvm *kvm); 48*897218ffSPaolo Bonzini void kvm_mmu_uninit_tdp_mmu(struct kvm *kvm); 49*897218ffSPaolo Bonzini static inline bool is_tdp_mmu_enabled(struct kvm *kvm) { return kvm->arch.tdp_mmu_enabled; } 50*897218ffSPaolo Bonzini static inline bool is_tdp_mmu_page(struct kvm_mmu_page *sp) { return sp->tdp_mmu_page; } 51*897218ffSPaolo Bonzini #else 52*897218ffSPaolo Bonzini static inline void kvm_mmu_init_tdp_mmu(struct kvm *kvm) {} 53*897218ffSPaolo Bonzini static inline void kvm_mmu_uninit_tdp_mmu(struct kvm *kvm) {} 54*897218ffSPaolo Bonzini static inline bool is_tdp_mmu_enabled(struct kvm *kvm) { return false; } 55*897218ffSPaolo Bonzini static inline bool is_tdp_mmu_page(struct kvm_mmu_page *sp) { return false; } 56*897218ffSPaolo Bonzini #endif 57*897218ffSPaolo Bonzini 58*897218ffSPaolo Bonzini static inline bool is_tdp_mmu_root(struct kvm *kvm, hpa_t hpa) 59*897218ffSPaolo Bonzini { 60*897218ffSPaolo Bonzini struct kvm_mmu_page *sp; 61*897218ffSPaolo Bonzini 62*897218ffSPaolo Bonzini if (!is_tdp_mmu_enabled(kvm)) 63*897218ffSPaolo Bonzini return false; 64*897218ffSPaolo Bonzini if (WARN_ON(!VALID_PAGE(hpa))) 65*897218ffSPaolo Bonzini return false; 66*897218ffSPaolo Bonzini 67*897218ffSPaolo Bonzini sp = to_shadow_page(hpa); 68*897218ffSPaolo Bonzini if (WARN_ON(!sp)) 69*897218ffSPaolo Bonzini return false; 70*897218ffSPaolo Bonzini 71*897218ffSPaolo Bonzini return is_tdp_mmu_page(sp) && sp->root_count; 72*897218ffSPaolo Bonzini } 73*897218ffSPaolo Bonzini 74fe5db27dSBen Gardon #endif /* __KVM_X86_MMU_TDP_MMU_H */ 75