blob: 752cf47a81abf3a68f871a604fbb5e17b5556570 [file] [log] [blame]
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +01001/*
2 * KVM guest address space mapping code
3 *
4 * Copyright IBM Corp. 2007, 2016
5 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
6 */
7
8#ifndef _ASM_S390_GMAP_H
9#define _ASM_S390_GMAP_H
10
11/**
12 * struct gmap_struct - guest address space
Martin Schwidefsky4be130a2016-03-08 12:12:18 +010013 * @list: list head for the mm->context gmap list
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +010014 * @crst_list: list of all crst tables used in the guest address space
15 * @mm: pointer to the parent mm_struct
16 * @guest_to_host: radix tree with guest to host address translation
17 * @host_to_guest: radix tree with pointer to segment table entries
18 * @guest_table_lock: spinlock to protect all entries in the guest page table
Martin Schwidefsky6ea427b2016-03-08 11:55:04 +010019 * @ref_count: reference counter for the gmap structure
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +010020 * @table: pointer to the page directory
21 * @asce: address space control element for gmap page table
22 * @pfault_enabled: defines if pfaults are applicable for the guest
Martin Schwidefsky4be130a2016-03-08 12:12:18 +010023 * @host_to_rmap: radix tree with gmap_rmap lists
24 * @children: list of shadow gmap structures
25 * @pt_list: list of all page tables used in the shadow guest address space
26 * @shadow_lock: spinlock to protect the shadow gmap list
27 * @parent: pointer to the parent gmap for shadow guest address spaces
28 * @orig_asce: ASCE for which the shadow page table has been created
David Hildenbrand5b062bd2016-03-08 12:17:40 +010029 * @edat_level: edat level to be used for the shadow translation
Martin Schwidefsky4be130a2016-03-08 12:12:18 +010030 * @removed: flag to indicate if a shadow guest address space has been removed
David Hildenbrand0f7f8482016-03-08 12:30:46 +010031 * @initialized: flag to indicate if a shadow guest address space can be used
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +010032 */
33struct gmap {
34 struct list_head list;
35 struct list_head crst_list;
36 struct mm_struct *mm;
37 struct radix_tree_root guest_to_host;
38 struct radix_tree_root host_to_guest;
39 spinlock_t guest_table_lock;
Martin Schwidefsky6ea427b2016-03-08 11:55:04 +010040 atomic_t ref_count;
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +010041 unsigned long *table;
42 unsigned long asce;
43 unsigned long asce_end;
44 void *private;
45 bool pfault_enabled;
Martin Schwidefsky4be130a2016-03-08 12:12:18 +010046 /* Additional data for shadow guest address spaces */
47 struct radix_tree_root host_to_rmap;
48 struct list_head children;
49 struct list_head pt_list;
50 spinlock_t shadow_lock;
51 struct gmap *parent;
52 unsigned long orig_asce;
David Hildenbrand5b062bd2016-03-08 12:17:40 +010053 int edat_level;
Martin Schwidefsky4be130a2016-03-08 12:12:18 +010054 bool removed;
David Hildenbrand0f7f8482016-03-08 12:30:46 +010055 bool initialized;
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +010056};
57
58/**
Martin Schwidefsky4be130a2016-03-08 12:12:18 +010059 * struct gmap_rmap - reverse mapping for shadow page table entries
60 * @next: pointer to next rmap in the list
61 * @raddr: virtual rmap address in the shadow guest address space
62 */
63struct gmap_rmap {
64 struct gmap_rmap *next;
65 unsigned long raddr;
66};
67
68#define gmap_for_each_rmap(pos, head) \
69 for (pos = (head); pos; pos = pos->next)
70
71#define gmap_for_each_rmap_safe(pos, n, head) \
72 for (pos = (head); n = pos ? pos->next : NULL, pos; pos = n)
73
74/**
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +010075 * struct gmap_notifier - notify function block for page invalidation
76 * @notifier_call: address of callback function
77 */
78struct gmap_notifier {
79 struct list_head list;
Martin Schwidefsky8ecb1a52016-03-08 11:54:14 +010080 struct rcu_head rcu;
Martin Schwidefsky414d3b02016-03-08 11:52:54 +010081 void (*notifier_call)(struct gmap *gmap, unsigned long start,
82 unsigned long end);
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +010083};
84
Martin Schwidefsky4be130a2016-03-08 12:12:18 +010085static inline int gmap_is_shadow(struct gmap *gmap)
86{
87 return !!gmap->parent;
88}
89
Martin Schwidefsky6ea427b2016-03-08 11:55:04 +010090struct gmap *gmap_create(struct mm_struct *mm, unsigned long limit);
91void gmap_remove(struct gmap *gmap);
92struct gmap *gmap_get(struct gmap *gmap);
93void gmap_put(struct gmap *gmap);
94
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +010095void gmap_enable(struct gmap *gmap);
96void gmap_disable(struct gmap *gmap);
97int gmap_map_segment(struct gmap *gmap, unsigned long from,
98 unsigned long to, unsigned long len);
99int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
100unsigned long __gmap_translate(struct gmap *, unsigned long gaddr);
101unsigned long gmap_translate(struct gmap *, unsigned long gaddr);
102int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr);
103int gmap_fault(struct gmap *, unsigned long gaddr, unsigned int fault_flags);
104void gmap_discard(struct gmap *, unsigned long from, unsigned long to);
105void __gmap_zap(struct gmap *, unsigned long gaddr);
106void gmap_unlink(struct mm_struct *, unsigned long *table, unsigned long vmaddr);
107
Martin Schwidefsky4be130a2016-03-08 12:12:18 +0100108int gmap_read_table(struct gmap *gmap, unsigned long gaddr, unsigned long *val);
109
David Hildenbrand5b062bd2016-03-08 12:17:40 +0100110struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce,
111 int edat_level);
David Hildenbrand3218f702016-04-18 16:22:24 +0200112int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t,
113 int fake);
114int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t,
115 int fake);
David Hildenbrand18b89802016-04-18 13:42:05 +0200116int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt,
117 int fake);
David Hildenbrandfd8d4e32016-04-18 13:24:52 +0200118int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt,
119 int fake);
Martin Schwidefsky4be130a2016-03-08 12:12:18 +0100120int gmap_shadow_pgt_lookup(struct gmap *sg, unsigned long saddr,
David Hildenbrandfd8d4e32016-04-18 13:24:52 +0200121 unsigned long *pgt, int *dat_protection, int *fake);
David Hildenbranda9d23e72016-03-08 12:21:41 +0100122int gmap_shadow_page(struct gmap *sg, unsigned long saddr, pte_t pte);
Martin Schwidefsky4be130a2016-03-08 12:12:18 +0100123
Martin Schwidefskyb2d73b22016-03-08 11:54:42 +0100124void gmap_register_pte_notifier(struct gmap_notifier *);
125void gmap_unregister_pte_notifier(struct gmap_notifier *);
Martin Schwidefsky4be130a2016-03-08 12:12:18 +0100126void gmap_pte_notify(struct mm_struct *, unsigned long addr, pte_t *,
127 unsigned long bits);
Martin Schwidefskyb2d73b22016-03-08 11:54:42 +0100128
129int gmap_mprotect_notify(struct gmap *, unsigned long start,
130 unsigned long len, int prot);
Martin Schwidefsky1e133ab2016-03-08 11:49:57 +0100131
132#endif /* _ASM_S390_GMAP_H */