]> rtime.felk.cvut.cz Git - zynq/linux.git/blob - include/linux/mm_types.h
Apply preempt_rt patch-4.9-rt1.patch.xz
[zynq/linux.git] / include / linux / mm_types.h
1 #ifndef _LINUX_MM_TYPES_H
2 #define _LINUX_MM_TYPES_H
3
4 #include <linux/auxvec.h>
5 #include <linux/types.h>
6 #include <linux/threads.h>
7 #include <linux/list.h>
8 #include <linux/spinlock.h>
9 #include <linux/rbtree.h>
10 #include <linux/rwsem.h>
11 #include <linux/completion.h>
12 #include <linux/cpumask.h>
13 #include <linux/uprobes.h>
14 #include <linux/rcupdate.h>
15 #include <linux/page-flags-layout.h>
16 #include <linux/workqueue.h>
17 #include <asm/page.h>
18 #include <asm/mmu.h>
19
20 #ifndef AT_VECTOR_SIZE_ARCH
21 #define AT_VECTOR_SIZE_ARCH 0
22 #endif
23 #define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
24
25 struct address_space;
26 struct mem_cgroup;
27
28 #define USE_SPLIT_PTE_PTLOCKS   (NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS)
29 #define USE_SPLIT_PMD_PTLOCKS   (USE_SPLIT_PTE_PTLOCKS && \
30                 IS_ENABLED(CONFIG_ARCH_ENABLE_SPLIT_PMD_PTLOCK))
31 #define ALLOC_SPLIT_PTLOCKS     (SPINLOCK_SIZE > BITS_PER_LONG/8)
32
33 /*
34  * Each physical page in the system has a struct page associated with
35  * it to keep track of whatever it is we are using the page for at the
36  * moment. Note that we have no way to track which tasks are using
37  * a page, though if it is a pagecache page, rmap structures can tell us
38  * who is mapping it.
39  *
40  * The objects in struct page are organized in double word blocks in
41  * order to allows us to use atomic double word operations on portions
42  * of struct page. That is currently only used by slub but the arrangement
43  * allows the use of atomic double word operations on the flags/mapping
44  * and lru list pointers also.
45  */
46 struct page {
47         /* First double word block */
48         unsigned long flags;            /* Atomic flags, some possibly
49                                          * updated asynchronously */
50         union {
51                 struct address_space *mapping;  /* If low bit clear, points to
52                                                  * inode address_space, or NULL.
53                                                  * If page mapped as anonymous
54                                                  * memory, low bit is set, and
55                                                  * it points to anon_vma object:
56                                                  * see PAGE_MAPPING_ANON below.
57                                                  */
58                 void *s_mem;                    /* slab first object */
59                 atomic_t compound_mapcount;     /* first tail page */
60                 /* page_deferred_list().next     -- second tail page */
61         };
62
63         /* Second double word */
64         union {
65                 pgoff_t index;          /* Our offset within mapping. */
66                 void *freelist;         /* sl[aou]b first free object */
67                 /* page_deferred_list().prev    -- second tail page */
68         };
69
70         union {
71 #if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
72         defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
73                 /* Used for cmpxchg_double in slub */
74                 unsigned long counters;
75 #else
76                 /*
77                  * Keep _refcount separate from slub cmpxchg_double data.
78                  * As the rest of the double word is protected by slab_lock
79                  * but _refcount is not.
80                  */
81                 unsigned counters;
82 #endif
83                 struct {
84
85                         union {
86                                 /*
87                                  * Count of ptes mapped in mms, to show when
88                                  * page is mapped & limit reverse map searches.
89                                  *
90                                  * Extra information about page type may be
91                                  * stored here for pages that are never mapped,
92                                  * in which case the value MUST BE <= -2.
93                                  * See page-flags.h for more details.
94                                  */
95                                 atomic_t _mapcount;
96
97                                 unsigned int active;            /* SLAB */
98                                 struct {                        /* SLUB */
99                                         unsigned inuse:16;
100                                         unsigned objects:15;
101                                         unsigned frozen:1;
102                                 };
103                                 int units;                      /* SLOB */
104                         };
105                         /*
106                          * Usage count, *USE WRAPPER FUNCTION* when manual
107                          * accounting. See page_ref.h
108                          */
109                         atomic_t _refcount;
110                 };
111         };
112
113         /*
114          * Third double word block
115          *
116          * WARNING: bit 0 of the first word encode PageTail(). That means
117          * the rest users of the storage space MUST NOT use the bit to
118          * avoid collision and false-positive PageTail().
119          */
120         union {
121                 struct list_head lru;   /* Pageout list, eg. active_list
122                                          * protected by zone_lru_lock !
123                                          * Can be used as a generic list
124                                          * by the page owner.
125                                          */
126                 struct dev_pagemap *pgmap; /* ZONE_DEVICE pages are never on an
127                                             * lru or handled by a slab
128                                             * allocator, this points to the
129                                             * hosting device page map.
130                                             */
131                 struct {                /* slub per cpu partial pages */
132                         struct page *next;      /* Next partial slab */
133 #ifdef CONFIG_64BIT
134                         int pages;      /* Nr of partial slabs left */
135                         int pobjects;   /* Approximate # of objects */
136 #else
137                         short int pages;
138                         short int pobjects;
139 #endif
140                 };
141
142                 struct rcu_head rcu_head;       /* Used by SLAB
143                                                  * when destroying via RCU
144                                                  */
145                 /* Tail pages of compound page */
146                 struct {
147                         unsigned long compound_head; /* If bit zero is set */
148
149                         /* First tail page only */
150 #ifdef CONFIG_64BIT
151                         /*
152                          * On 64 bit system we have enough space in struct page
153                          * to encode compound_dtor and compound_order with
154                          * unsigned int. It can help compiler generate better or
155                          * smaller code on some archtectures.
156                          */
157                         unsigned int compound_dtor;
158                         unsigned int compound_order;
159 #else
160                         unsigned short int compound_dtor;
161                         unsigned short int compound_order;
162 #endif
163                 };
164
165 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && USE_SPLIT_PMD_PTLOCKS
166                 struct {
167                         unsigned long __pad;    /* do not overlay pmd_huge_pte
168                                                  * with compound_head to avoid
169                                                  * possible bit 0 collision.
170                                                  */
171                         pgtable_t pmd_huge_pte; /* protected by page->ptl */
172                 };
173 #endif
174         };
175
176         /* Remainder is not double word aligned */
177         union {
178                 unsigned long private;          /* Mapping-private opaque data:
179                                                  * usually used for buffer_heads
180                                                  * if PagePrivate set; used for
181                                                  * swp_entry_t if PageSwapCache;
182                                                  * indicates order in the buddy
183                                                  * system if PG_buddy is set.
184                                                  */
185 #if USE_SPLIT_PTE_PTLOCKS
186 #if ALLOC_SPLIT_PTLOCKS
187                 spinlock_t *ptl;
188 #else
189                 spinlock_t ptl;
190 #endif
191 #endif
192                 struct kmem_cache *slab_cache;  /* SL[AU]B: Pointer to slab */
193         };
194
195 #ifdef CONFIG_MEMCG
196         struct mem_cgroup *mem_cgroup;
197 #endif
198
199         /*
200          * On machines where all RAM is mapped into kernel address space,
201          * we can simply calculate the virtual address. On machines with
202          * highmem some memory is mapped into kernel virtual memory
203          * dynamically, so we need a place to store that address.
204          * Note that this field could be 16 bits on x86 ... ;)
205          *
206          * Architectures with slow multiplication can define
207          * WANT_PAGE_VIRTUAL in asm/page.h
208          */
209 #if defined(WANT_PAGE_VIRTUAL)
210         void *virtual;                  /* Kernel virtual address (NULL if
211                                            not kmapped, ie. highmem) */
212 #endif /* WANT_PAGE_VIRTUAL */
213
214 #ifdef CONFIG_KMEMCHECK
215         /*
216          * kmemcheck wants to track the status of each byte in a page; this
217          * is a pointer to such a status block. NULL if not tracked.
218          */
219         void *shadow;
220 #endif
221
222 #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
223         int _last_cpupid;
224 #endif
225 }
226 /*
227  * The struct page can be forced to be double word aligned so that atomic ops
228  * on double words work. The SLUB allocator can make use of such a feature.
229  */
230 #ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE
231         __aligned(2 * sizeof(unsigned long))
232 #endif
233 ;
234
235 struct page_frag {
236         struct page *page;
237 #if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
238         __u32 offset;
239         __u32 size;
240 #else
241         __u16 offset;
242         __u16 size;
243 #endif
244 };
245
246 #define PAGE_FRAG_CACHE_MAX_SIZE        __ALIGN_MASK(32768, ~PAGE_MASK)
247 #define PAGE_FRAG_CACHE_MAX_ORDER       get_order(PAGE_FRAG_CACHE_MAX_SIZE)
248
249 struct page_frag_cache {
250         void * va;
251 #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)
252         __u16 offset;
253         __u16 size;
254 #else
255         __u32 offset;
256 #endif
257         /* we maintain a pagecount bias, so that we dont dirty cache line
258          * containing page->_refcount every time we allocate a fragment.
259          */
260         unsigned int            pagecnt_bias;
261         bool pfmemalloc;
262 };
263
264 typedef unsigned long vm_flags_t;
265
266 /*
267  * A region containing a mapping of a non-memory backed file under NOMMU
268  * conditions.  These are held in a global tree and are pinned by the VMAs that
269  * map parts of them.
270  */
271 struct vm_region {
272         struct rb_node  vm_rb;          /* link in global region tree */
273         vm_flags_t      vm_flags;       /* VMA vm_flags */
274         unsigned long   vm_start;       /* start address of region */
275         unsigned long   vm_end;         /* region initialised to here */
276         unsigned long   vm_top;         /* region allocated to here */
277         unsigned long   vm_pgoff;       /* the offset in vm_file corresponding to vm_start */
278         struct file     *vm_file;       /* the backing file or NULL */
279
280         int             vm_usage;       /* region usage count (access under nommu_region_sem) */
281         bool            vm_icache_flushed : 1; /* true if the icache has been flushed for
282                                                 * this region */
283 };
284
285 #ifdef CONFIG_USERFAULTFD
286 #define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) { NULL, })
287 struct vm_userfaultfd_ctx {
288         struct userfaultfd_ctx *ctx;
289 };
290 #else /* CONFIG_USERFAULTFD */
291 #define NULL_VM_UFFD_CTX ((struct vm_userfaultfd_ctx) {})
292 struct vm_userfaultfd_ctx {};
293 #endif /* CONFIG_USERFAULTFD */
294
295 /*
296  * This struct defines a memory VMM memory area. There is one of these
297  * per VM-area/task.  A VM area is any part of the process virtual memory
298  * space that has a special rule for the page-fault handlers (ie a shared
299  * library, the executable area etc).
300  */
301 struct vm_area_struct {
302         /* The first cache line has the info for VMA tree walking. */
303
304         unsigned long vm_start;         /* Our start address within vm_mm. */
305         unsigned long vm_end;           /* The first byte after our end address
306                                            within vm_mm. */
307
308         /* linked list of VM areas per task, sorted by address */
309         struct vm_area_struct *vm_next, *vm_prev;
310
311         struct rb_node vm_rb;
312
313         /*
314          * Largest free memory gap in bytes to the left of this VMA.
315          * Either between this VMA and vma->vm_prev, or between one of the
316          * VMAs below us in the VMA rbtree and its ->vm_prev. This helps
317          * get_unmapped_area find a free area of the right size.
318          */
319         unsigned long rb_subtree_gap;
320
321         /* Second cache line starts here. */
322
323         struct mm_struct *vm_mm;        /* The address space we belong to. */
324         pgprot_t vm_page_prot;          /* Access permissions of this VMA. */
325         unsigned long vm_flags;         /* Flags, see mm.h. */
326
327         /*
328          * For areas with an address space and backing store,
329          * linkage into the address_space->i_mmap interval tree.
330          */
331         struct {
332                 struct rb_node rb;
333                 unsigned long rb_subtree_last;
334         } shared;
335
336         /*
337          * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
338          * list, after a COW of one of the file pages.  A MAP_SHARED vma
339          * can only be in the i_mmap tree.  An anonymous MAP_PRIVATE, stack
340          * or brk vma (with NULL file) can only be in an anon_vma list.
341          */
342         struct list_head anon_vma_chain; /* Serialized by mmap_sem &
343                                           * page_table_lock */
344         struct anon_vma *anon_vma;      /* Serialized by page_table_lock */
345
346         /* Function pointers to deal with this struct. */
347         const struct vm_operations_struct *vm_ops;
348
349         /* Information about our backing store: */
350         unsigned long vm_pgoff;         /* Offset (within vm_file) in PAGE_SIZE
351                                            units */
352         struct file * vm_file;          /* File we map to (can be NULL). */
353         void * vm_private_data;         /* was vm_pte (shared mem) */
354
355 #ifndef CONFIG_MMU
356         struct vm_region *vm_region;    /* NOMMU mapping region */
357 #endif
358 #ifdef CONFIG_NUMA
359         struct mempolicy *vm_policy;    /* NUMA policy for the VMA */
360 #endif
361         struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
362 };
363
364 struct core_thread {
365         struct task_struct *task;
366         struct core_thread *next;
367 };
368
369 struct core_state {
370         atomic_t nr_threads;
371         struct core_thread dumper;
372         struct completion startup;
373 };
374
375 enum {
376         MM_FILEPAGES,   /* Resident file mapping pages */
377         MM_ANONPAGES,   /* Resident anonymous pages */
378         MM_SWAPENTS,    /* Anonymous swap entries */
379         MM_SHMEMPAGES,  /* Resident shared memory pages */
380         NR_MM_COUNTERS
381 };
382
383 #if USE_SPLIT_PTE_PTLOCKS && defined(CONFIG_MMU)
384 #define SPLIT_RSS_COUNTING
385 /* per-thread cached information, */
386 struct task_rss_stat {
387         int events;     /* for synchronization threshold */
388         int count[NR_MM_COUNTERS];
389 };
390 #endif /* USE_SPLIT_PTE_PTLOCKS */
391
392 struct mm_rss_stat {
393         atomic_long_t count[NR_MM_COUNTERS];
394 };
395
396 struct kioctx_table;
397 struct mm_struct {
398         struct vm_area_struct *mmap;            /* list of VMAs */
399         struct rb_root mm_rb;
400         u32 vmacache_seqnum;                   /* per-thread vmacache */
401 #ifdef CONFIG_MMU
402         unsigned long (*get_unmapped_area) (struct file *filp,
403                                 unsigned long addr, unsigned long len,
404                                 unsigned long pgoff, unsigned long flags);
405 #endif
406         unsigned long mmap_base;                /* base of mmap area */
407         unsigned long mmap_legacy_base;         /* base of mmap area in bottom-up allocations */
408         unsigned long task_size;                /* size of task vm space */
409         unsigned long highest_vm_end;           /* highest vma end address */
410         pgd_t * pgd;
411         atomic_t mm_users;                      /* How many users with user space? */
412         atomic_t mm_count;                      /* How many references to "struct mm_struct" (users count as 1) */
413         atomic_long_t nr_ptes;                  /* PTE page table pages */
414 #if CONFIG_PGTABLE_LEVELS > 2
415         atomic_long_t nr_pmds;                  /* PMD page table pages */
416 #endif
417         int map_count;                          /* number of VMAs */
418
419         spinlock_t page_table_lock;             /* Protects page tables and some counters */
420         struct rw_semaphore mmap_sem;
421
422         struct list_head mmlist;                /* List of maybe swapped mm's.  These are globally strung
423                                                  * together off init_mm.mmlist, and are protected
424                                                  * by mmlist_lock
425                                                  */
426
427
428         unsigned long hiwater_rss;      /* High-watermark of RSS usage */
429         unsigned long hiwater_vm;       /* High-water virtual memory usage */
430
431         unsigned long total_vm;         /* Total pages mapped */
432         unsigned long locked_vm;        /* Pages that have PG_mlocked set */
433         unsigned long pinned_vm;        /* Refcount permanently increased */
434         unsigned long data_vm;          /* VM_WRITE & ~VM_SHARED & ~VM_STACK */
435         unsigned long exec_vm;          /* VM_EXEC & ~VM_WRITE & ~VM_STACK */
436         unsigned long stack_vm;         /* VM_STACK */
437         unsigned long def_flags;
438         unsigned long start_code, end_code, start_data, end_data;
439         unsigned long start_brk, brk, start_stack;
440         unsigned long arg_start, arg_end, env_start, env_end;
441
442         unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
443
444         /*
445          * Special counters, in some configurations protected by the
446          * page_table_lock, in other configurations by being atomic.
447          */
448         struct mm_rss_stat rss_stat;
449
450         struct linux_binfmt *binfmt;
451
452         cpumask_var_t cpu_vm_mask_var;
453
454         /* Architecture-specific MM context */
455         mm_context_t context;
456
457         unsigned long flags; /* Must use atomic bitops to access the bits */
458
459         struct core_state *core_state; /* coredumping support */
460 #ifdef CONFIG_AIO
461         spinlock_t                      ioctx_lock;
462         struct kioctx_table __rcu       *ioctx_table;
463 #endif
464 #ifdef CONFIG_MEMCG
465         /*
466          * "owner" points to a task that is regarded as the canonical
467          * user/owner of this mm. All of the following must be true in
468          * order for it to be changed:
469          *
470          * current == mm->owner
471          * current->mm != mm
472          * new_owner->mm == mm
473          * new_owner->alloc_lock is held
474          */
475         struct task_struct __rcu *owner;
476 #endif
477
478         /* store ref to file /proc/<pid>/exe symlink points to */
479         struct file __rcu *exe_file;
480 #ifdef CONFIG_MMU_NOTIFIER
481         struct mmu_notifier_mm *mmu_notifier_mm;
482 #endif
483 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
484         pgtable_t pmd_huge_pte; /* protected by page_table_lock */
485 #endif
486 #ifdef CONFIG_CPUMASK_OFFSTACK
487         struct cpumask cpumask_allocation;
488 #endif
489 #ifdef CONFIG_NUMA_BALANCING
490         /*
491          * numa_next_scan is the next time that the PTEs will be marked
492          * pte_numa. NUMA hinting faults will gather statistics and migrate
493          * pages to new nodes if necessary.
494          */
495         unsigned long numa_next_scan;
496
497         /* Restart point for scanning and setting pte_numa */
498         unsigned long numa_scan_offset;
499
500         /* numa_scan_seq prevents two threads setting pte_numa */
501         int numa_scan_seq;
502 #endif
503 #if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
504         /*
505          * An operation with batched TLB flushing is going on. Anything that
506          * can move process memory needs to flush the TLB when moving a
507          * PROT_NONE or PROT_NUMA mapped page.
508          */
509         bool tlb_flush_pending;
510 #endif
511         struct uprobes_state uprobes_state;
512 #ifdef CONFIG_PREEMPT_RT_BASE
513         struct rcu_head delayed_drop;
514 #endif
515 #ifdef CONFIG_X86_INTEL_MPX
516         /* address of the bounds directory */
517         void __user *bd_addr;
518 #endif
519 #ifdef CONFIG_HUGETLB_PAGE
520         atomic_long_t hugetlb_usage;
521 #endif
522         struct work_struct async_put_work;
523 };
524
525 static inline void mm_init_cpumask(struct mm_struct *mm)
526 {
527 #ifdef CONFIG_CPUMASK_OFFSTACK
528         mm->cpu_vm_mask_var = &mm->cpumask_allocation;
529 #endif
530         cpumask_clear(mm->cpu_vm_mask_var);
531 }
532
533 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
534 static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
535 {
536         return mm->cpu_vm_mask_var;
537 }
538
539 #if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION)
540 /*
541  * Memory barriers to keep this state in sync are graciously provided by
542  * the page table locks, outside of which no page table modifications happen.
543  * The barriers below prevent the compiler from re-ordering the instructions
544  * around the memory barriers that are already present in the code.
545  */
546 static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
547 {
548         barrier();
549         return mm->tlb_flush_pending;
550 }
551 static inline void set_tlb_flush_pending(struct mm_struct *mm)
552 {
553         mm->tlb_flush_pending = true;
554
555         /*
556          * Guarantee that the tlb_flush_pending store does not leak into the
557          * critical section updating the page tables
558          */
559         smp_mb__before_spinlock();
560 }
561 /* Clearing is done after a TLB flush, which also provides a barrier. */
562 static inline void clear_tlb_flush_pending(struct mm_struct *mm)
563 {
564         barrier();
565         mm->tlb_flush_pending = false;
566 }
567 #else
568 static inline bool mm_tlb_flush_pending(struct mm_struct *mm)
569 {
570         return false;
571 }
572 static inline void set_tlb_flush_pending(struct mm_struct *mm)
573 {
574 }
575 static inline void clear_tlb_flush_pending(struct mm_struct *mm)
576 {
577 }
578 #endif
579
580 struct vm_fault;
581
582 struct vm_special_mapping {
583         const char *name;       /* The name, e.g. "[vdso]". */
584
585         /*
586          * If .fault is not provided, this points to a
587          * NULL-terminated array of pages that back the special mapping.
588          *
589          * This must not be NULL unless .fault is provided.
590          */
591         struct page **pages;
592
593         /*
594          * If non-NULL, then this is called to resolve page faults
595          * on the special mapping.  If used, .pages is not checked.
596          */
597         int (*fault)(const struct vm_special_mapping *sm,
598                      struct vm_area_struct *vma,
599                      struct vm_fault *vmf);
600
601         int (*mremap)(const struct vm_special_mapping *sm,
602                      struct vm_area_struct *new_vma);
603 };
604
605 enum tlb_flush_reason {
606         TLB_FLUSH_ON_TASK_SWITCH,
607         TLB_REMOTE_SHOOTDOWN,
608         TLB_LOCAL_SHOOTDOWN,
609         TLB_LOCAL_MM_SHOOTDOWN,
610         TLB_REMOTE_SEND_IPI,
611         NR_TLB_FLUSH_REASONS,
612 };
613
614  /*
615   * A swap entry has to fit into a "unsigned long", as the entry is hidden
616   * in the "index" field of the swapper address space.
617   */
618 typedef struct {
619         unsigned long val;
620 } swp_entry_t;
621
622 #endif /* _LINUX_MM_TYPES_H */