1 /* SPDX-License-Identifier: GPL-2.0 */
3 * KVM guest address space mapping code
5 * Copyright IBM Corp. 2007, 2016
6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
9 #ifndef _ASM_S390_GMAP_H
10 #define _ASM_S390_GMAP_H
12 /* Generic bits for GMAP notification on DAT table entry changes. */
13 #define GMAP_NOTIFY_SHADOW 0x2
14 #define GMAP_NOTIFY_MPROT 0x1
16 /* Status bits only for huge segment entries */
17 #define _SEGMENT_ENTRY_GMAP_IN 0x8000 /* invalidation notify bit */
20 * struct gmap_struct - guest address space
21 * @list: list head for the mm->context gmap list
22 * @crst_list: list of all crst tables used in the guest address space
23 * @mm: pointer to the parent mm_struct
24 * @guest_to_host: radix tree with guest to host address translation
25 * @host_to_guest: radix tree with pointer to segment table entries
26 * @guest_table_lock: spinlock to protect all entries in the guest page table
27 * @ref_count: reference counter for the gmap structure
28 * @table: pointer to the page directory
29 * @asce: address space control element for gmap page table
30 * @pfault_enabled: defines if pfaults are applicable for the guest
31 * @host_to_rmap: radix tree with gmap_rmap lists
32 * @children: list of shadow gmap structures
33 * @pt_list: list of all page tables used in the shadow guest address space
34 * @shadow_lock: spinlock to protect the shadow gmap list
35 * @parent: pointer to the parent gmap for shadow guest address spaces
36 * @orig_asce: ASCE for which the shadow page table has been created
37 * @edat_level: edat level to be used for the shadow translation
38 * @removed: flag to indicate if a shadow guest address space has been removed
39 * @initialized: flag to indicate if a shadow guest address space can be used
42 struct list_head list;
43 struct list_head crst_list;
45 struct radix_tree_root guest_to_host;
46 struct radix_tree_root host_to_guest;
47 spinlock_t guest_table_lock;
51 unsigned long asce_end;
54 /* Additional data for shadow guest address spaces */
55 struct radix_tree_root host_to_rmap;
56 struct list_head children;
57 struct list_head pt_list;
58 spinlock_t shadow_lock;
60 unsigned long orig_asce;
67 * struct gmap_rmap - reverse mapping for shadow page table entries
68 * @next: pointer to next rmap in the list
69 * @raddr: virtual rmap address in the shadow guest address space
72 struct gmap_rmap *next;
76 #define gmap_for_each_rmap(pos, head) \
77 for (pos = (head); pos; pos = pos->next)
79 #define gmap_for_each_rmap_safe(pos, n, head) \
80 for (pos = (head); n = pos ? pos->next : NULL, pos; pos = n)
83 * struct gmap_notifier - notify function block for page invalidation
84 * @notifier_call: address of callback function
86 struct gmap_notifier {
87 struct list_head list;
89 void (*notifier_call)(struct gmap *gmap, unsigned long start,
93 static inline int gmap_is_shadow(struct gmap *gmap)
95 return !!gmap->parent;
98 struct gmap *gmap_create(struct mm_struct *mm, unsigned long limit);
99 void gmap_remove(struct gmap *gmap);
100 struct gmap *gmap_get(struct gmap *gmap);
101 void gmap_put(struct gmap *gmap);
103 void gmap_enable(struct gmap *gmap);
104 void gmap_disable(struct gmap *gmap);
105 struct gmap *gmap_get_enabled(void);
106 int gmap_map_segment(struct gmap *gmap, unsigned long from,
107 unsigned long to, unsigned long len);
108 int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
109 unsigned long __gmap_translate(struct gmap *, unsigned long gaddr);
110 unsigned long gmap_translate(struct gmap *, unsigned long gaddr);
111 int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr);
112 int gmap_fault(struct gmap *, unsigned long gaddr, unsigned int fault_flags);
113 void gmap_discard(struct gmap *, unsigned long from, unsigned long to);
114 void __gmap_zap(struct gmap *, unsigned long gaddr);
115 void gmap_unlink(struct mm_struct *, unsigned long *table, unsigned long vmaddr);
117 int gmap_read_table(struct gmap *gmap, unsigned long gaddr, unsigned long *val);
119 struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce,
121 int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level);
122 int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t,
124 int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t,
126 int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt,
128 int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt,
130 int gmap_shadow_pgt_lookup(struct gmap *sg, unsigned long saddr,
131 unsigned long *pgt, int *dat_protection, int *fake);
132 int gmap_shadow_page(struct gmap *sg, unsigned long saddr, pte_t pte);
134 void gmap_register_pte_notifier(struct gmap_notifier *);
135 void gmap_unregister_pte_notifier(struct gmap_notifier *);
136 void gmap_pte_notify(struct mm_struct *, unsigned long addr, pte_t *,
139 int gmap_mprotect_notify(struct gmap *, unsigned long start,
140 unsigned long len, int prot);
142 #endif /* _ASM_S390_GMAP_H */