Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 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 | |
Janosch Frank | 2c46e97 | 2018-07-13 11:28:18 +0100 | [diff] [blame] | 12 | /* Generic bits for GMAP notification on DAT table entry changes. */ |
| 13 | #define GMAP_NOTIFY_SHADOW 0x2 |
| 14 | #define GMAP_NOTIFY_MPROT 0x1 |
| 15 | |
Janosch Frank | 7c4b13a | 2018-07-13 11:28:21 +0100 | [diff] [blame] | 16 | /* Status bits only for huge segment entries */ |
| 17 | #define _SEGMENT_ENTRY_GMAP_IN 0x8000 /* invalidation notify bit */ |
Janosch Frank | 0959e16 | 2018-07-17 13:21:22 +0100 | [diff] [blame] | 18 | #define _SEGMENT_ENTRY_GMAP_UC 0x4000 /* dirty (migration) */ |
Janosch Frank | 7c4b13a | 2018-07-13 11:28:21 +0100 | [diff] [blame] | 19 | |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 20 | /** |
| 21 | * struct gmap_struct - guest address space |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 22 | * @list: list head for the mm->context gmap list |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 23 | * @crst_list: list of all crst tables used in the guest address space |
| 24 | * @mm: pointer to the parent mm_struct |
| 25 | * @guest_to_host: radix tree with guest to host address translation |
| 26 | * @host_to_guest: radix tree with pointer to segment table entries |
| 27 | * @guest_table_lock: spinlock to protect all entries in the guest page table |
Martin Schwidefsky | 6ea427b | 2016-03-08 11:55:04 +0100 | [diff] [blame] | 28 | * @ref_count: reference counter for the gmap structure |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 29 | * @table: pointer to the page directory |
| 30 | * @asce: address space control element for gmap page table |
| 31 | * @pfault_enabled: defines if pfaults are applicable for the guest |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 32 | * @host_to_rmap: radix tree with gmap_rmap lists |
| 33 | * @children: list of shadow gmap structures |
| 34 | * @pt_list: list of all page tables used in the shadow guest address space |
| 35 | * @shadow_lock: spinlock to protect the shadow gmap list |
| 36 | * @parent: pointer to the parent gmap for shadow guest address spaces |
| 37 | * @orig_asce: ASCE for which the shadow page table has been created |
David Hildenbrand | 5b062bd | 2016-03-08 12:17:40 +0100 | [diff] [blame] | 38 | * @edat_level: edat level to be used for the shadow translation |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 39 | * @removed: flag to indicate if a shadow guest address space has been removed |
David Hildenbrand | 0f7f848 | 2016-03-08 12:30:46 +0100 | [diff] [blame] | 40 | * @initialized: flag to indicate if a shadow guest address space can be used |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 41 | */ |
| 42 | struct gmap { |
| 43 | struct list_head list; |
| 44 | struct list_head crst_list; |
| 45 | struct mm_struct *mm; |
| 46 | struct radix_tree_root guest_to_host; |
| 47 | struct radix_tree_root host_to_guest; |
| 48 | spinlock_t guest_table_lock; |
Martin Schwidefsky | 6ea427b | 2016-03-08 11:55:04 +0100 | [diff] [blame] | 49 | atomic_t ref_count; |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 50 | unsigned long *table; |
| 51 | unsigned long asce; |
| 52 | unsigned long asce_end; |
| 53 | void *private; |
| 54 | bool pfault_enabled; |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 55 | /* Additional data for shadow guest address spaces */ |
| 56 | struct radix_tree_root host_to_rmap; |
| 57 | struct list_head children; |
| 58 | struct list_head pt_list; |
| 59 | spinlock_t shadow_lock; |
| 60 | struct gmap *parent; |
| 61 | unsigned long orig_asce; |
David Hildenbrand | 5b062bd | 2016-03-08 12:17:40 +0100 | [diff] [blame] | 62 | int edat_level; |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 63 | bool removed; |
David Hildenbrand | 0f7f848 | 2016-03-08 12:30:46 +0100 | [diff] [blame] | 64 | bool initialized; |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | /** |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 68 | * struct gmap_rmap - reverse mapping for shadow page table entries |
| 69 | * @next: pointer to next rmap in the list |
| 70 | * @raddr: virtual rmap address in the shadow guest address space |
| 71 | */ |
| 72 | struct gmap_rmap { |
| 73 | struct gmap_rmap *next; |
| 74 | unsigned long raddr; |
| 75 | }; |
| 76 | |
| 77 | #define gmap_for_each_rmap(pos, head) \ |
| 78 | for (pos = (head); pos; pos = pos->next) |
| 79 | |
| 80 | #define gmap_for_each_rmap_safe(pos, n, head) \ |
| 81 | for (pos = (head); n = pos ? pos->next : NULL, pos; pos = n) |
| 82 | |
| 83 | /** |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 84 | * struct gmap_notifier - notify function block for page invalidation |
| 85 | * @notifier_call: address of callback function |
| 86 | */ |
| 87 | struct gmap_notifier { |
| 88 | struct list_head list; |
Martin Schwidefsky | 8ecb1a5 | 2016-03-08 11:54:14 +0100 | [diff] [blame] | 89 | struct rcu_head rcu; |
Martin Schwidefsky | 414d3b0 | 2016-03-08 11:52:54 +0100 | [diff] [blame] | 90 | void (*notifier_call)(struct gmap *gmap, unsigned long start, |
| 91 | unsigned long end); |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 92 | }; |
| 93 | |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 94 | static inline int gmap_is_shadow(struct gmap *gmap) |
| 95 | { |
| 96 | return !!gmap->parent; |
| 97 | } |
| 98 | |
Martin Schwidefsky | 6ea427b | 2016-03-08 11:55:04 +0100 | [diff] [blame] | 99 | struct gmap *gmap_create(struct mm_struct *mm, unsigned long limit); |
| 100 | void gmap_remove(struct gmap *gmap); |
| 101 | struct gmap *gmap_get(struct gmap *gmap); |
| 102 | void gmap_put(struct gmap *gmap); |
| 103 | |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 104 | void gmap_enable(struct gmap *gmap); |
| 105 | void gmap_disable(struct gmap *gmap); |
David Hildenbrand | 37d9df9 | 2015-03-11 16:47:33 +0100 | [diff] [blame] | 106 | struct gmap *gmap_get_enabled(void); |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 107 | int gmap_map_segment(struct gmap *gmap, unsigned long from, |
| 108 | unsigned long to, unsigned long len); |
| 109 | int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len); |
| 110 | unsigned long __gmap_translate(struct gmap *, unsigned long gaddr); |
| 111 | unsigned long gmap_translate(struct gmap *, unsigned long gaddr); |
| 112 | int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr); |
| 113 | int gmap_fault(struct gmap *, unsigned long gaddr, unsigned int fault_flags); |
| 114 | void gmap_discard(struct gmap *, unsigned long from, unsigned long to); |
| 115 | void __gmap_zap(struct gmap *, unsigned long gaddr); |
| 116 | void gmap_unlink(struct mm_struct *, unsigned long *table, unsigned long vmaddr); |
| 117 | |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 118 | int gmap_read_table(struct gmap *gmap, unsigned long gaddr, unsigned long *val); |
| 119 | |
David Hildenbrand | 5b062bd | 2016-03-08 12:17:40 +0100 | [diff] [blame] | 120 | struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce, |
| 121 | int edat_level); |
David Hildenbrand | 5b6c963 | 2016-05-27 18:57:33 +0200 | [diff] [blame] | 122 | int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level); |
David Hildenbrand | 3218f70 | 2016-04-18 16:22:24 +0200 | [diff] [blame] | 123 | int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t, |
| 124 | int fake); |
| 125 | int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t, |
| 126 | int fake); |
David Hildenbrand | 18b8980 | 2016-04-18 13:42:05 +0200 | [diff] [blame] | 127 | int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt, |
| 128 | int fake); |
David Hildenbrand | fd8d4e3 | 2016-04-18 13:24:52 +0200 | [diff] [blame] | 129 | int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt, |
| 130 | int fake); |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 131 | int gmap_shadow_pgt_lookup(struct gmap *sg, unsigned long saddr, |
David Hildenbrand | fd8d4e3 | 2016-04-18 13:24:52 +0200 | [diff] [blame] | 132 | unsigned long *pgt, int *dat_protection, int *fake); |
David Hildenbrand | a9d23e7 | 2016-03-08 12:21:41 +0100 | [diff] [blame] | 133 | int gmap_shadow_page(struct gmap *sg, unsigned long saddr, pte_t pte); |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 134 | |
Martin Schwidefsky | b2d73b2 | 2016-03-08 11:54:42 +0100 | [diff] [blame] | 135 | void gmap_register_pte_notifier(struct gmap_notifier *); |
| 136 | void gmap_unregister_pte_notifier(struct gmap_notifier *); |
Martin Schwidefsky | 4be130a | 2016-03-08 12:12:18 +0100 | [diff] [blame] | 137 | void gmap_pte_notify(struct mm_struct *, unsigned long addr, pte_t *, |
| 138 | unsigned long bits); |
Martin Schwidefsky | b2d73b2 | 2016-03-08 11:54:42 +0100 | [diff] [blame] | 139 | |
| 140 | int gmap_mprotect_notify(struct gmap *, unsigned long start, |
| 141 | unsigned long len, int prot); |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 142 | |
Janosch Frank | 0959e16 | 2018-07-17 13:21:22 +0100 | [diff] [blame] | 143 | void gmap_sync_dirty_log_pmd(struct gmap *gmap, unsigned long dirty_bitmap[4], |
| 144 | unsigned long gaddr, unsigned long vmaddr); |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 145 | #endif /* _ASM_S390_GMAP_H */ |