gmap.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 <schwidefsky@de.ibm.com>
  7. */
  8. #ifndef _ASM_S390_GMAP_H
  9. #define _ASM_S390_GMAP_H
  10. /* Generic bits for GMAP notification on DAT table entry changes. */
  11. #define GMAP_NOTIFY_SHADOW 0x2
  12. #define GMAP_NOTIFY_MPROT 0x1
  13. /* Status bits only for huge segment entries */
  14. #define _SEGMENT_ENTRY_GMAP_IN 0x8000 /* invalidation notify bit */
  15. #define _SEGMENT_ENTRY_GMAP_UC 0x4000 /* dirty (migration) */
  16. /**
  17. * struct gmap_struct - guest address space
  18. * @list: list head for the mm->context gmap list
  19. * @crst_list: list of all crst tables used in the guest address space
  20. * @mm: pointer to the parent mm_struct
  21. * @guest_to_host: radix tree with guest to host address translation
  22. * @host_to_guest: radix tree with pointer to segment table entries
  23. * @guest_table_lock: spinlock to protect all entries in the guest page table
  24. * @ref_count: reference counter for the gmap structure
  25. * @table: pointer to the page directory
  26. * @asce: address space control element for gmap page table
  27. * @pfault_enabled: defines if pfaults are applicable for the guest
  28. * @host_to_rmap: radix tree with gmap_rmap lists
  29. * @children: list of shadow gmap structures
  30. * @pt_list: list of all page tables used in the shadow guest address space
  31. * @shadow_lock: spinlock to protect the shadow gmap list
  32. * @parent: pointer to the parent gmap for shadow guest address spaces
  33. * @orig_asce: ASCE for which the shadow page table has been created
  34. * @edat_level: edat level to be used for the shadow translation
  35. * @removed: flag to indicate if a shadow guest address space has been removed
  36. * @initialized: flag to indicate if a shadow guest address space can be used
  37. */
  38. struct gmap {
  39. struct list_head list;
  40. struct list_head crst_list;
  41. struct mm_struct *mm;
  42. struct radix_tree_root guest_to_host;
  43. struct radix_tree_root host_to_guest;
  44. spinlock_t guest_table_lock;
  45. atomic_t ref_count;
  46. unsigned long *table;
  47. unsigned long asce;
  48. unsigned long asce_end;
  49. void *private;
  50. bool pfault_enabled;
  51. /* Additional data for shadow guest address spaces */
  52. struct radix_tree_root host_to_rmap;
  53. struct list_head children;
  54. struct list_head pt_list;
  55. spinlock_t shadow_lock;
  56. struct gmap *parent;
  57. unsigned long orig_asce;
  58. int edat_level;
  59. bool removed;
  60. bool initialized;
  61. };
  62. /**
  63. * struct gmap_rmap - reverse mapping for shadow page table entries
  64. * @next: pointer to next rmap in the list
  65. * @raddr: virtual rmap address in the shadow guest address space
  66. */
  67. struct gmap_rmap {
  68. struct gmap_rmap *next;
  69. unsigned long raddr;
  70. };
  71. #define gmap_for_each_rmap(pos, head) \
  72. for (pos = (head); pos; pos = pos->next)
  73. #define gmap_for_each_rmap_safe(pos, n, head) \
  74. for (pos = (head); n = pos ? pos->next : NULL, pos; pos = n)
  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;
  81. struct rcu_head rcu;
  82. void (*notifier_call)(struct gmap *gmap, unsigned long start,
  83. unsigned long end);
  84. };
  85. static inline int gmap_is_shadow(struct gmap *gmap)
  86. {
  87. return !!gmap->parent;
  88. }
  89. struct gmap *gmap_create(struct mm_struct *mm, unsigned long limit);
  90. void gmap_remove(struct gmap *gmap);
  91. struct gmap *gmap_get(struct gmap *gmap);
  92. void gmap_put(struct gmap *gmap);
  93. void gmap_enable(struct gmap *gmap);
  94. void gmap_disable(struct gmap *gmap);
  95. struct gmap *gmap_get_enabled(void);
  96. int gmap_map_segment(struct gmap *gmap, unsigned long from,
  97. unsigned long to, unsigned long len);
  98. int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
  99. unsigned long __gmap_translate(struct gmap *, unsigned long gaddr);
  100. unsigned long gmap_translate(struct gmap *, unsigned long gaddr);
  101. int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr);
  102. int gmap_fault(struct gmap *, unsigned long gaddr, unsigned int fault_flags);
  103. void gmap_discard(struct gmap *, unsigned long from, unsigned long to);
  104. void __gmap_zap(struct gmap *, unsigned long gaddr);
  105. void gmap_unlink(struct mm_struct *, unsigned long *table, unsigned long vmaddr);
  106. int gmap_read_table(struct gmap *gmap, unsigned long gaddr, unsigned long *val);
  107. struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce,
  108. int edat_level);
  109. int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level);
  110. int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t,
  111. int fake);
  112. int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t,
  113. int fake);
  114. int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt,
  115. int fake);
  116. int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt,
  117. int fake);
  118. int gmap_shadow_pgt_lookup(struct gmap *sg, unsigned long saddr,
  119. unsigned long *pgt, int *dat_protection, int *fake);
  120. int gmap_shadow_page(struct gmap *sg, unsigned long saddr, pte_t pte);
  121. void gmap_register_pte_notifier(struct gmap_notifier *);
  122. void gmap_unregister_pte_notifier(struct gmap_notifier *);
  123. void gmap_pte_notify(struct mm_struct *, unsigned long addr, pte_t *,
  124. unsigned long bits);
  125. int gmap_mprotect_notify(struct gmap *, unsigned long start,
  126. unsigned long len, int prot);
  127. void gmap_sync_dirty_log_pmd(struct gmap *gmap, unsigned long dirty_bitmap[4],
  128. unsigned long gaddr, unsigned long vmaddr);
  129. #endif /* _ASM_S390_GMAP_H */