gmap.h 4.9 KB

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