Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  KVM guest address space mapping code
0004  *
0005  *    Copyright IBM Corp. 2007, 2016
0006  *    Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
0007  */
0008 
0009 #ifndef _ASM_S390_GMAP_H
0010 #define _ASM_S390_GMAP_H
0011 
0012 #include <linux/radix-tree.h>
0013 #include <linux/refcount.h>
0014 
0015 /* Generic bits for GMAP notification on DAT table entry changes. */
0016 #define GMAP_NOTIFY_SHADOW  0x2
0017 #define GMAP_NOTIFY_MPROT   0x1
0018 
0019 /* Status bits only for huge segment entries */
0020 #define _SEGMENT_ENTRY_GMAP_IN      0x8000  /* invalidation notify bit */
0021 #define _SEGMENT_ENTRY_GMAP_UC      0x4000  /* dirty (migration) */
0022 
0023 /**
0024  * struct gmap_struct - guest address space
0025  * @list: list head for the mm->context gmap list
0026  * @crst_list: list of all crst tables used in the guest address space
0027  * @mm: pointer to the parent mm_struct
0028  * @guest_to_host: radix tree with guest to host address translation
0029  * @host_to_guest: radix tree with pointer to segment table entries
0030  * @guest_table_lock: spinlock to protect all entries in the guest page table
0031  * @ref_count: reference counter for the gmap structure
0032  * @table: pointer to the page directory
0033  * @asce: address space control element for gmap page table
0034  * @pfault_enabled: defines if pfaults are applicable for the guest
0035  * @guest_handle: protected virtual machine handle for the ultravisor
0036  * @host_to_rmap: radix tree with gmap_rmap lists
0037  * @children: list of shadow gmap structures
0038  * @pt_list: list of all page tables used in the shadow guest address space
0039  * @shadow_lock: spinlock to protect the shadow gmap list
0040  * @parent: pointer to the parent gmap for shadow guest address spaces
0041  * @orig_asce: ASCE for which the shadow page table has been created
0042  * @edat_level: edat level to be used for the shadow translation
0043  * @removed: flag to indicate if a shadow guest address space has been removed
0044  * @initialized: flag to indicate if a shadow guest address space can be used
0045  */
0046 struct gmap {
0047     struct list_head list;
0048     struct list_head crst_list;
0049     struct mm_struct *mm;
0050     struct radix_tree_root guest_to_host;
0051     struct radix_tree_root host_to_guest;
0052     spinlock_t guest_table_lock;
0053     refcount_t ref_count;
0054     unsigned long *table;
0055     unsigned long asce;
0056     unsigned long asce_end;
0057     void *private;
0058     bool pfault_enabled;
0059     /* only set for protected virtual machines */
0060     unsigned long guest_handle;
0061     /* Additional data for shadow guest address spaces */
0062     struct radix_tree_root host_to_rmap;
0063     struct list_head children;
0064     struct list_head pt_list;
0065     spinlock_t shadow_lock;
0066     struct gmap *parent;
0067     unsigned long orig_asce;
0068     int edat_level;
0069     bool removed;
0070     bool initialized;
0071 };
0072 
0073 /**
0074  * struct gmap_rmap - reverse mapping for shadow page table entries
0075  * @next: pointer to next rmap in the list
0076  * @raddr: virtual rmap address in the shadow guest address space
0077  */
0078 struct gmap_rmap {
0079     struct gmap_rmap *next;
0080     unsigned long raddr;
0081 };
0082 
0083 #define gmap_for_each_rmap(pos, head) \
0084     for (pos = (head); pos; pos = pos->next)
0085 
0086 #define gmap_for_each_rmap_safe(pos, n, head) \
0087     for (pos = (head); n = pos ? pos->next : NULL, pos; pos = n)
0088 
0089 /**
0090  * struct gmap_notifier - notify function block for page invalidation
0091  * @notifier_call: address of callback function
0092  */
0093 struct gmap_notifier {
0094     struct list_head list;
0095     struct rcu_head rcu;
0096     void (*notifier_call)(struct gmap *gmap, unsigned long start,
0097                   unsigned long end);
0098 };
0099 
0100 static inline int gmap_is_shadow(struct gmap *gmap)
0101 {
0102     return !!gmap->parent;
0103 }
0104 
0105 struct gmap *gmap_create(struct mm_struct *mm, unsigned long limit);
0106 void gmap_remove(struct gmap *gmap);
0107 struct gmap *gmap_get(struct gmap *gmap);
0108 void gmap_put(struct gmap *gmap);
0109 
0110 void gmap_enable(struct gmap *gmap);
0111 void gmap_disable(struct gmap *gmap);
0112 struct gmap *gmap_get_enabled(void);
0113 int gmap_map_segment(struct gmap *gmap, unsigned long from,
0114              unsigned long to, unsigned long len);
0115 int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
0116 unsigned long __gmap_translate(struct gmap *, unsigned long gaddr);
0117 unsigned long gmap_translate(struct gmap *, unsigned long gaddr);
0118 int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr);
0119 int gmap_fault(struct gmap *, unsigned long gaddr, unsigned int fault_flags);
0120 void gmap_discard(struct gmap *, unsigned long from, unsigned long to);
0121 void __gmap_zap(struct gmap *, unsigned long gaddr);
0122 void gmap_unlink(struct mm_struct *, unsigned long *table, unsigned long vmaddr);
0123 
0124 int gmap_read_table(struct gmap *gmap, unsigned long gaddr, unsigned long *val);
0125 
0126 struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce,
0127              int edat_level);
0128 int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level);
0129 int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t,
0130             int fake);
0131 int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t,
0132             int fake);
0133 int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt,
0134             int fake);
0135 int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt,
0136             int fake);
0137 int gmap_shadow_pgt_lookup(struct gmap *sg, unsigned long saddr,
0138                unsigned long *pgt, int *dat_protection, int *fake);
0139 int gmap_shadow_page(struct gmap *sg, unsigned long saddr, pte_t pte);
0140 
0141 void gmap_register_pte_notifier(struct gmap_notifier *);
0142 void gmap_unregister_pte_notifier(struct gmap_notifier *);
0143 
0144 int gmap_mprotect_notify(struct gmap *, unsigned long start,
0145              unsigned long len, int prot);
0146 
0147 void gmap_sync_dirty_log_pmd(struct gmap *gmap, unsigned long dirty_bitmap[4],
0148                  unsigned long gaddr, unsigned long vmaddr);
0149 int gmap_mark_unmergeable(void);
0150 void s390_unlist_old_asce(struct gmap *gmap);
0151 int s390_replace_asce(struct gmap *gmap);
0152 void s390_uv_destroy_pfns(unsigned long count, unsigned long *pfns);
0153 int __s390_uv_destroy_range(struct mm_struct *mm, unsigned long start,
0154                 unsigned long end, bool interruptible);
0155 
0156 /**
0157  * s390_uv_destroy_range - Destroy a range of pages in the given mm.
0158  * @mm: the mm on which to operate on
0159  * @start: the start of the range
0160  * @end: the end of the range
0161  *
0162  * This function will call cond_sched, so it should not generate stalls, but
0163  * it will otherwise only return when it completed.
0164  */
0165 static inline void s390_uv_destroy_range(struct mm_struct *mm, unsigned long start,
0166                      unsigned long end)
0167 {
0168     (void)__s390_uv_destroy_range(mm, start, end, false);
0169 }
0170 
0171 /**
0172  * s390_uv_destroy_range_interruptible - Destroy a range of pages in the
0173  * given mm, but stop when a fatal signal is received.
0174  * @mm: the mm on which to operate on
0175  * @start: the start of the range
0176  * @end: the end of the range
0177  *
0178  * This function will call cond_sched, so it should not generate stalls. If
0179  * a fatal signal is received, it will return with -EINTR immediately,
0180  * without finishing destroying the whole range. Upon successful
0181  * completion, 0 is returned.
0182  */
0183 static inline int s390_uv_destroy_range_interruptible(struct mm_struct *mm, unsigned long start,
0184                               unsigned long end)
0185 {
0186     return __s390_uv_destroy_range(mm, start, end, true);
0187 }
0188 #endif /* _ASM_S390_GMAP_H */