xref: /kernel/linux/linux-5.10/arch/x86/kvm/mmu/tdp_mmu.h (revision 8c2ecf20)
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
8void kvm_mmu_init_tdp_mmu(struct kvm *kvm);
9void kvm_mmu_uninit_tdp_mmu(struct kvm *kvm);
10
11bool is_tdp_mmu_root(struct kvm *kvm, hpa_t root);
12hpa_t kvm_tdp_mmu_get_vcpu_root_hpa(struct kvm_vcpu *vcpu);
13void kvm_tdp_mmu_free_root(struct kvm *kvm, struct kvm_mmu_page *root);
14
15bool __kvm_tdp_mmu_zap_gfn_range(struct kvm *kvm, gfn_t start, gfn_t end,
16				 bool can_yield);
17static inline bool kvm_tdp_mmu_zap_gfn_range(struct kvm *kvm, gfn_t start,
18					     gfn_t end)
19{
20	return __kvm_tdp_mmu_zap_gfn_range(kvm, start, end, true);
21}
22static inline bool kvm_tdp_mmu_zap_sp(struct kvm *kvm, struct kvm_mmu_page *sp)
23{
24	gfn_t end = sp->gfn + KVM_PAGES_PER_HPAGE(sp->role.level);
25
26	/*
27	 * Don't allow yielding, as the caller may have pending pages to zap
28	 * on the shadow MMU.
29	 */
30	return __kvm_tdp_mmu_zap_gfn_range(kvm, sp->gfn, end, false);
31}
32void kvm_tdp_mmu_zap_all(struct kvm *kvm);
33
34int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code,
35		    int map_writable, int max_level, kvm_pfn_t pfn,
36		    bool prefault);
37
38int kvm_tdp_mmu_zap_hva_range(struct kvm *kvm, unsigned long start,
39			      unsigned long end);
40
41int kvm_tdp_mmu_age_hva_range(struct kvm *kvm, unsigned long start,
42			      unsigned long end);
43int kvm_tdp_mmu_test_age_hva(struct kvm *kvm, unsigned long hva);
44
45int kvm_tdp_mmu_set_spte_hva(struct kvm *kvm, unsigned long address,
46			     pte_t *host_ptep);
47
48bool kvm_tdp_mmu_wrprot_slot(struct kvm *kvm, struct kvm_memory_slot *slot,
49			     int min_level);
50bool kvm_tdp_mmu_clear_dirty_slot(struct kvm *kvm,
51				  struct kvm_memory_slot *slot);
52void kvm_tdp_mmu_clear_dirty_pt_masked(struct kvm *kvm,
53				       struct kvm_memory_slot *slot,
54				       gfn_t gfn, unsigned long mask,
55				       bool wrprot);
56bool kvm_tdp_mmu_slot_set_dirty(struct kvm *kvm, struct kvm_memory_slot *slot);
57void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
58				       const struct kvm_memory_slot *slot);
59
60bool kvm_tdp_mmu_write_protect_gfn(struct kvm *kvm,
61				   struct kvm_memory_slot *slot, gfn_t gfn);
62
63int kvm_tdp_mmu_get_walk(struct kvm_vcpu *vcpu, u64 addr, u64 *sptes,
64			 int *root_level);
65
66#endif /* __KVM_X86_MMU_TDP_MMU_H */
67