gmap.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * KVM guest address space mapping code
  4. *
  5. * Copyright IBM Corp. 2007, 2016
  6. * Author(s): Martin Schwidefsky <[email protected]>
  7. */
  8. #ifndef _ASM_S390_GMAP_H
  9. #define _ASM_S390_GMAP_H
  10. #include <linux/radix-tree.h>
  11. #include <linux/refcount.h>
  12. /* Generic bits for GMAP notification on DAT table entry changes. */
  13. #define GMAP_NOTIFY_SHADOW 0x2
  14. #define GMAP_NOTIFY_MPROT 0x1
  15. /* Status bits only for huge segment entries */
  16. #define _SEGMENT_ENTRY_GMAP_IN 0x8000 /* invalidation notify bit */
  17. #define _SEGMENT_ENTRY_GMAP_UC 0x4000 /* dirty (migration) */
  18. /**
  19. * struct gmap_struct - guest address space
  20. * @list: list head for the mm->context gmap list
  21. * @crst_list: list of all crst tables used in the guest address space
  22. * @mm: pointer to the parent mm_struct
  23. * @guest_to_host: radix tree with guest to host address translation
  24. * @host_to_guest: radix tree with pointer to segment table entries
  25. * @guest_table_lock: spinlock to protect all entries in the guest page table
  26. * @ref_count: reference counter for the gmap structure
  27. * @table: pointer to the page directory
  28. * @asce: address space control element for gmap page table
  29. * @pfault_enabled: defines if pfaults are applicable for the guest
  30. * @guest_handle: protected virtual machine handle for the ultravisor
  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
  40. */
  41. struct gmap {
  42. struct list_head list;
  43. struct list_head crst_list;
  44. struct mm_struct *mm;
  45. struct radix_tree_root guest_to_host;
  46. struct radix_tree_root host_to_guest;
  47. spinlock_t guest_table_lock;
  48. refcount_t ref_count;
  49. unsigned long *table;
  50. unsigned long asce;
  51. unsigned long asce_end;
  52. void *private;
  53. bool pfault_enabled;
  54. /* only set for protected virtual machines */
  55. unsigned long guest_handle;
  56. /* Additional data for shadow guest address spaces */
  57. struct radix_tree_root host_to_rmap;
  58. struct list_head children;
  59. struct list_head pt_list;
  60. spinlock_t shadow_lock;
  61. struct gmap *parent;
  62. unsigned long orig_asce;
  63. int edat_level;
  64. bool removed;
  65. bool initialized;
  66. };
  67. /**
  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. #define gmap_for_each_rmap(pos, head) \
  77. for (pos = (head); pos; pos = pos->next)
  78. #define gmap_for_each_rmap_safe(pos, n, head) \
  79. for (pos = (head); n = pos ? pos->next : NULL, pos; pos = n)
  80. /**
  81. * struct gmap_notifier - notify function block for page invalidation
  82. * @notifier_call: address of callback function
  83. */
  84. struct gmap_notifier {
  85. struct list_head list;
  86. struct rcu_head rcu;
  87. void (*notifier_call)(struct gmap *gmap, unsigned long start,
  88. unsigned long end);
  89. };
  90. static inline int gmap_is_shadow(struct gmap *gmap)
  91. {
  92. return !!gmap->parent;
  93. }
  94. struct gmap *gmap_create(struct mm_struct *mm, unsigned long limit);
  95. void gmap_remove(struct gmap *gmap);
  96. struct gmap *gmap_get(struct gmap *gmap);
  97. void gmap_put(struct gmap *gmap);
  98. void gmap_enable(struct gmap *gmap);
  99. void gmap_disable(struct gmap *gmap);
  100. struct gmap *gmap_get_enabled(void);
  101. int gmap_map_segment(struct gmap *gmap, unsigned long from,
  102. unsigned long to, unsigned long len);
  103. int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
  104. unsigned long __gmap_translate(struct gmap *, unsigned long gaddr);
  105. unsigned long gmap_translate(struct gmap *, unsigned long gaddr);
  106. int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr);
  107. int gmap_fault(struct gmap *, unsigned long gaddr, unsigned int fault_flags);
  108. void gmap_discard(struct gmap *, unsigned long from, unsigned long to);
  109. void __gmap_zap(struct gmap *, unsigned long gaddr);
  110. void gmap_unlink(struct mm_struct *, unsigned long *table, unsigned long vmaddr);
  111. int gmap_read_table(struct gmap *gmap, unsigned long gaddr, unsigned long *val);
  112. struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce,
  113. int edat_level);
  114. int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level);
  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);
  119. int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt,
  120. int fake);
  121. int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt,
  122. int fake);
  123. int gmap_shadow_pgt_lookup(struct gmap *sg, unsigned long saddr,
  124. unsigned long *pgt, int *dat_protection, int *fake);
  125. int gmap_shadow_page(struct gmap *sg, unsigned long saddr, pte_t pte);
  126. void gmap_register_pte_notifier(struct gmap_notifier *);
  127. void gmap_unregister_pte_notifier(struct gmap_notifier *);
  128. int gmap_mprotect_notify(struct gmap *, unsigned long start,
  129. unsigned long len, int prot);
  130. void gmap_sync_dirty_log_pmd(struct gmap *gmap, unsigned long dirty_bitmap[4],
  131. unsigned long gaddr, unsigned long vmaddr);
  132. int gmap_mark_unmergeable(void);
  133. void s390_unlist_old_asce(struct gmap *gmap);
  134. int s390_replace_asce(struct gmap *gmap);
  135. void s390_uv_destroy_pfns(unsigned long count, unsigned long *pfns);
  136. int __s390_uv_destroy_range(struct mm_struct *mm, unsigned long start,
  137. unsigned long end, bool interruptible);
  138. /**
  139. * s390_uv_destroy_range - Destroy a range of pages in the given mm.
  140. * @mm: the mm on which to operate on
  141. * @start: the start of the range
  142. * @end: the end of the range
  143. *
  144. * This function will call cond_sched, so it should not generate stalls, but
  145. * it will otherwise only return when it completed.
  146. */
  147. static inline void s390_uv_destroy_range(struct mm_struct *mm, unsigned long start,
  148. unsigned long end)
  149. {
  150. (void)__s390_uv_destroy_range(mm, start, end, false);
  151. }
  152. /**
  153. * s390_uv_destroy_range_interruptible - Destroy a range of pages in the
  154. * given mm, but stop when a fatal signal is received.
  155. * @mm: the mm on which to operate on
  156. * @start: the start of the range
  157. * @end: the end of the range
  158. *
  159. * This function will call cond_sched, so it should not generate stalls. If
  160. * a fatal signal is received, it will return with -EINTR immediately,
  161. * without finishing destroying the whole range. Upon successful
  162. * completion, 0 is returned.
  163. */
  164. static inline int s390_uv_destroy_range_interruptible(struct mm_struct *mm, unsigned long start,
  165. unsigned long end)
  166. {
  167. return __s390_uv_destroy_range(mm, start, end, true);
  168. }
  169. #endif /* _ASM_S390_GMAP_H */