gmap.h 5.1 KB

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