Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1e133ab2 MS |
2 | /* |
3 | * KVM guest address space mapping code | |
4 | * | |
5 | * Copyright IBM Corp. 2007, 2016 | |
6 | * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com> | |
7 | */ | |
8 | ||
9 | #ifndef _ASM_S390_GMAP_H | |
10 | #define _ASM_S390_GMAP_H | |
11 | ||
12 | /** | |
13 | * struct gmap_struct - guest address space | |
4be130a0 | 14 | * @list: list head for the mm->context gmap list |
1e133ab2 MS |
15 | * @crst_list: list of all crst tables used in the guest address space |
16 | * @mm: pointer to the parent mm_struct | |
17 | * @guest_to_host: radix tree with guest to host address translation | |
18 | * @host_to_guest: radix tree with pointer to segment table entries | |
19 | * @guest_table_lock: spinlock to protect all entries in the guest page table | |
6ea427bb | 20 | * @ref_count: reference counter for the gmap structure |
1e133ab2 MS |
21 | * @table: pointer to the page directory |
22 | * @asce: address space control element for gmap page table | |
23 | * @pfault_enabled: defines if pfaults are applicable for the guest | |
4be130a0 MS |
24 | * @host_to_rmap: radix tree with gmap_rmap lists |
25 | * @children: list of shadow gmap structures | |
26 | * @pt_list: list of all page tables used in the shadow guest address space | |
27 | * @shadow_lock: spinlock to protect the shadow gmap list | |
28 | * @parent: pointer to the parent gmap for shadow guest address spaces | |
29 | * @orig_asce: ASCE for which the shadow page table has been created | |
5b062bd4 | 30 | * @edat_level: edat level to be used for the shadow translation |
4be130a0 | 31 | * @removed: flag to indicate if a shadow guest address space has been removed |
0f7f8489 | 32 | * @initialized: flag to indicate if a shadow guest address space can be used |
1e133ab2 MS |
33 | */ |
34 | struct gmap { | |
35 | struct list_head list; | |
36 | struct list_head crst_list; | |
37 | struct mm_struct *mm; | |
38 | struct radix_tree_root guest_to_host; | |
39 | struct radix_tree_root host_to_guest; | |
40 | spinlock_t guest_table_lock; | |
6ea427bb | 41 | atomic_t ref_count; |
1e133ab2 MS |
42 | unsigned long *table; |
43 | unsigned long asce; | |
44 | unsigned long asce_end; | |
45 | void *private; | |
46 | bool pfault_enabled; | |
4be130a0 MS |
47 | /* Additional data for shadow guest address spaces */ |
48 | struct radix_tree_root host_to_rmap; | |
49 | struct list_head children; | |
50 | struct list_head pt_list; | |
51 | spinlock_t shadow_lock; | |
52 | struct gmap *parent; | |
53 | unsigned long orig_asce; | |
5b062bd4 | 54 | int edat_level; |
4be130a0 | 55 | bool removed; |
0f7f8489 | 56 | bool initialized; |
1e133ab2 MS |
57 | }; |
58 | ||
4be130a0 MS |
59 | /** |
60 | * struct gmap_rmap - reverse mapping for shadow page table entries | |
61 | * @next: pointer to next rmap in the list | |
62 | * @raddr: virtual rmap address in the shadow guest address space | |
63 | */ | |
64 | struct gmap_rmap { | |
65 | struct gmap_rmap *next; | |
66 | unsigned long raddr; | |
67 | }; | |
68 | ||
69 | #define gmap_for_each_rmap(pos, head) \ | |
70 | for (pos = (head); pos; pos = pos->next) | |
71 | ||
72 | #define gmap_for_each_rmap_safe(pos, n, head) \ | |
73 | for (pos = (head); n = pos ? pos->next : NULL, pos; pos = n) | |
74 | ||
1e133ab2 MS |
75 | /** |
76 | * struct gmap_notifier - notify function block for page invalidation | |
77 | * @notifier_call: address of callback function | |
78 | */ | |
79 | struct gmap_notifier { | |
80 | struct list_head list; | |
8ecb1a59 | 81 | struct rcu_head rcu; |
414d3b07 MS |
82 | void (*notifier_call)(struct gmap *gmap, unsigned long start, |
83 | unsigned long end); | |
1e133ab2 MS |
84 | }; |
85 | ||
4be130a0 MS |
86 | static inline int gmap_is_shadow(struct gmap *gmap) |
87 | { | |
88 | return !!gmap->parent; | |
89 | } | |
90 | ||
6ea427bb MS |
91 | struct gmap *gmap_create(struct mm_struct *mm, unsigned long limit); |
92 | void gmap_remove(struct gmap *gmap); | |
93 | struct gmap *gmap_get(struct gmap *gmap); | |
94 | void gmap_put(struct gmap *gmap); | |
95 | ||
1e133ab2 MS |
96 | void gmap_enable(struct gmap *gmap); |
97 | void gmap_disable(struct gmap *gmap); | |
37d9df98 | 98 | struct gmap *gmap_get_enabled(void); |
1e133ab2 MS |
99 | int gmap_map_segment(struct gmap *gmap, unsigned long from, |
100 | unsigned long to, unsigned long len); | |
101 | int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len); | |
102 | unsigned long __gmap_translate(struct gmap *, unsigned long gaddr); | |
103 | unsigned long gmap_translate(struct gmap *, unsigned long gaddr); | |
104 | int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr); | |
105 | int gmap_fault(struct gmap *, unsigned long gaddr, unsigned int fault_flags); | |
106 | void gmap_discard(struct gmap *, unsigned long from, unsigned long to); | |
107 | void __gmap_zap(struct gmap *, unsigned long gaddr); | |
108 | void gmap_unlink(struct mm_struct *, unsigned long *table, unsigned long vmaddr); | |
109 | ||
4be130a0 MS |
110 | int gmap_read_table(struct gmap *gmap, unsigned long gaddr, unsigned long *val); |
111 | ||
5b062bd4 DH |
112 | struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce, |
113 | int edat_level); | |
5b6c963b | 114 | int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level); |
3218f709 DH |
115 | int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t, |
116 | int fake); | |
117 | int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t, | |
118 | int fake); | |
18b89809 DH |
119 | int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt, |
120 | int fake); | |
fd8d4e3a DH |
121 | int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt, |
122 | int fake); | |
4be130a0 | 123 | int gmap_shadow_pgt_lookup(struct gmap *sg, unsigned long saddr, |
fd8d4e3a | 124 | unsigned long *pgt, int *dat_protection, int *fake); |
a9d23e71 | 125 | int gmap_shadow_page(struct gmap *sg, unsigned long saddr, pte_t pte); |
4be130a0 | 126 | |
b2d73b2a MS |
127 | void gmap_register_pte_notifier(struct gmap_notifier *); |
128 | void gmap_unregister_pte_notifier(struct gmap_notifier *); | |
4be130a0 MS |
129 | void gmap_pte_notify(struct mm_struct *, unsigned long addr, pte_t *, |
130 | unsigned long bits); | |
b2d73b2a MS |
131 | |
132 | int gmap_mprotect_notify(struct gmap *, unsigned long start, | |
133 | unsigned long len, int prot); | |
1e133ab2 MS |
134 | |
135 | #endif /* _ASM_S390_GMAP_H */ |