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