Blame view

include/linux/vmalloc.h 7.71 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
  #ifndef _LINUX_VMALLOC_H
  #define _LINUX_VMALLOC_H
  
  #include <linux/spinlock.h>
db64fe022   Nick Piggin   mm: rewrite vmap ...
6
  #include <linux/init.h>
13ba3fcbb   Atsushi Kumagai   kexec, vmalloc: e...
7
  #include <linux/list.h>
80c4bd7a5   Chris Wilson   mm/vmalloc: keep ...
8
  #include <linux/llist.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
  #include <asm/page.h>		/* pgprot_t */
13ba3fcbb   Atsushi Kumagai   kexec, vmalloc: e...
10
  #include <linux/rbtree.h>
3b3b1a29e   Kees Cook   mm: Use overflow ...
11
  #include <linux/overflow.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12

1f059dfdf   Ingo Molnar   mm/vmalloc: Add e...
13
  #include <asm/vmalloc.h>
605d9288b   Hugh Dickins   mm: VM_flags comm...
14
  struct vm_area_struct;		/* vma defining user mapping in mm_types.h */
4da56b99d   Chris Wilson   mm/vmap: Add a no...
15
  struct notifier_block;		/* in notifier.h */
833423143   Nick Piggin   [PATCH] mm: intro...
16

605d9288b   Hugh Dickins   mm: VM_flags comm...
17
  /* bits in flags of vmalloc's vm_struct below */
20fc02b47   Zhang Yanfei   mm/vmalloc.c: ren...
18
19
20
21
  #define VM_IOREMAP		0x00000001	/* ioremap() and friends */
  #define VM_ALLOC		0x00000002	/* vmalloc() */
  #define VM_MAP			0x00000004	/* vmap()ed pages */
  #define VM_USERMAP		0x00000008	/* suitable for remap_vmalloc_range */
fe9041c24   Christoph Hellwig   vmalloc: lift the...
22
  #define VM_DMA_COHERENT		0x00000010	/* dma_alloc_coherent */
20fc02b47   Zhang Yanfei   mm/vmalloc.c: ren...
23
  #define VM_UNINITIALIZED	0x00000020	/* vm_struct is not fully initialized */
71394fe50   Andrey Ryabinin   mm: vmalloc: add ...
24
  #define VM_NO_GUARD		0x00000040      /* don't add guard page */
a5af5aa8b   Andrey Ryabinin   kasan, module, vm...
25
  #define VM_KASAN		0x00000080      /* has allocated kasan shadow memory */
b944afc9d   Christoph Hellwig   mm: add a VM_MAP_...
26
  #define VM_MAP_PUT_PAGES	0x00000100	/* put pages and free array in vfree */
3c5c3cfb9   Daniel Axtens   kasan: support ba...
27
28
29
30
31
32
33
34
35
36
37
  
  /*
   * VM_KASAN is used slighly differently depending on CONFIG_KASAN_VMALLOC.
   *
   * If IS_ENABLED(CONFIG_KASAN_VMALLOC), VM_KASAN is set on a vm_struct after
   * shadow memory has been mapped. It's used to handle allocation errors so that
   * we don't try to poision shadow on free if it was never allocated.
   *
   * Otherwise, VM_KASAN is set for kasan_module_alloc() allocations and used to
   * determine which allocations need the module shadow freed.
   */
868b104d7   Rick Edgecombe   mm/vmalloc: Add f...
38
39
40
41
42
  /*
   * Memory with VM_FLUSH_RESET_PERMS cannot be freed in an interrupt or with
   * vfree_atomic().
   */
  #define VM_FLUSH_RESET_PERMS	0x00000100      /* Reset direct map and flush TLB on unmap */
fe9041c24   Christoph Hellwig   vmalloc: lift the...
43

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
  /* bits [20..32] reserved for arch specific ioremap internals */
fd195c49f   Deepak Saxena   [PATCH] arm: allo...
45
46
47
48
49
50
51
  /*
   * Maximum alignment for ioremap() regions.
   * Can be overriden by arch-specific value.
   */
  #ifndef IOREMAP_MAX_ORDER
  #define IOREMAP_MAX_ORDER	(7 + PAGE_SHIFT)	/* 128 pages */
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
  struct vm_struct {
2b4ac44e7   Eric Dumazet   [PATCH] vmalloc: ...
53
  	struct vm_struct	*next;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
55
56
57
58
  	void			*addr;
  	unsigned long		size;
  	unsigned long		flags;
  	struct page		**pages;
  	unsigned int		nr_pages;
ffa71f33a   Kenji Kaneshige   x86, ioremap: Fix...
59
  	phys_addr_t		phys_addr;
5e6cafc83   Marek Szyprowski   mm: vmalloc: use ...
60
  	const void		*caller;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
  };
13ba3fcbb   Atsushi Kumagai   kexec, vmalloc: e...
62
63
64
  struct vmap_area {
  	unsigned long va_start;
  	unsigned long va_end;
68ad4a330   Uladzislau Rezki (Sony)   mm/vmalloc.c: kee...
65

13ba3fcbb   Atsushi Kumagai   kexec, vmalloc: e...
66
67
  	struct rb_node rb_node;         /* address sorted rbtree */
  	struct list_head list;          /* address sorted list */
688fcbfc0   Pengfei Li   mm/vmalloc: modif...
68
69
70
71
72
73
74
75
76
77
78
79
80
  
  	/*
  	 * The following three variables can be packed, because
  	 * a vmap_area object is always one of the three states:
  	 *    1) in "free" tree (root is vmap_area_root)
  	 *    2) in "busy" tree (root is free_vmap_area_root)
  	 *    3) in purge list  (head is vmap_purge_list)
  	 */
  	union {
  		unsigned long subtree_max_size; /* in "free" tree */
  		struct vm_struct *vm;           /* in "busy" tree */
  		struct llist_node purge_list;   /* in purge list */
  	};
13ba3fcbb   Atsushi Kumagai   kexec, vmalloc: e...
81
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
  /*
   *	Highlevel APIs for driver use
   */
db64fe022   Nick Piggin   mm: rewrite vmap ...
85
  extern void vm_unmap_ram(const void *mem, unsigned int count);
d4efd79a8   Christoph Hellwig   mm: remove the pr...
86
  extern void *vm_map_ram(struct page **pages, unsigned int count, int node);
db64fe022   Nick Piggin   mm: rewrite vmap ...
87
88
89
90
  extern void vm_unmap_aliases(void);
  
  #ifdef CONFIG_MMU
  extern void __init vmalloc_init(void);
97105f0ab   Roman Gushchin   mm: vmalloc: show...
91
  extern unsigned long vmalloc_nr_pages(void);
db64fe022   Nick Piggin   mm: rewrite vmap ...
92
93
94
95
  #else
  static inline void vmalloc_init(void)
  {
  }
97105f0ab   Roman Gushchin   mm: vmalloc: show...
96
  static inline unsigned long vmalloc_nr_pages(void) { return 0; }
db64fe022   Nick Piggin   mm: rewrite vmap ...
97
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
  extern void *vmalloc(unsigned long size);
e1ca7788d   Dave Young   mm: add vzalloc()...
99
  extern void *vzalloc(unsigned long size);
833423143   Nick Piggin   [PATCH] mm: intro...
100
  extern void *vmalloc_user(unsigned long size);
930fc45a4   Christoph Lameter   [PATCH] vmalloc_node
101
  extern void *vmalloc_node(unsigned long size, int node);
e1ca7788d   Dave Young   mm: add vzalloc()...
102
  extern void *vzalloc_node(unsigned long size, int node);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
  extern void *vmalloc_32(unsigned long size);
833423143   Nick Piggin   [PATCH] mm: intro...
104
  extern void *vmalloc_32_user(unsigned long size);
88dca4ca5   Christoph Hellwig   mm: remove the pg...
105
  extern void *__vmalloc(unsigned long size, gfp_t gfp_mask);
d0a21265d   David Rientjes   mm: unify module_...
106
107
  extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
  			unsigned long start, unsigned long end, gfp_t gfp_mask,
cb9e3c292   Andrey Ryabinin   mm: vmalloc: pass...
108
109
  			pgprot_t prot, unsigned long vm_flags, int node,
  			const void *caller);
2b9059489   Christoph Hellwig   mm: remove __vmal...
110
111
  void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask,
  		int node, const void *caller);
cb9e3c292   Andrey Ryabinin   mm: vmalloc: pass...
112

b3bdda02a   Christoph Lameter   vmalloc: add cons...
113
  extern void vfree(const void *addr);
bf22e37a6   Andrey Ryabinin   mm: add vfree_ato...
114
  extern void vfree_atomic(const void *addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
117
  
  extern void *vmap(struct page **pages, unsigned int count,
  			unsigned long flags, pgprot_t prot);
3e9a9e256   Christoph Hellwig   mm: add a vmap_pf...
118
  void *vmap_pfn(unsigned long *pfns, unsigned int count, pgprot_t prot);
b3bdda02a   Christoph Lameter   vmalloc: add cons...
119
  extern void vunmap(const void *addr);
833423143   Nick Piggin   [PATCH] mm: intro...
120

e69e9d4ae   HATAYAMA Daisuke   vmalloc: introduc...
121
122
  extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
  				       unsigned long uaddr, void *kaddr,
bdebd6a28   Jann Horn   vmalloc: fix rema...
123
  				       unsigned long pgoff, unsigned long size);
e69e9d4ae   HATAYAMA Daisuke   vmalloc: introduc...
124

833423143   Nick Piggin   [PATCH] mm: intro...
125
126
  extern int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
  							unsigned long pgoff);
763802b53   Joerg Roedel   x86/mm: split vma...
127

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128
  /*
2ba3e6947   Joerg Roedel   mm/vmalloc: track...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
   * Architectures can set this mask to a combination of PGTBL_P?D_MODIFIED values
   * and let generic vmalloc and ioremap code know when arch_sync_kernel_mappings()
   * needs to be called.
   */
  #ifndef ARCH_PAGE_TABLE_SYNC_MASK
  #define ARCH_PAGE_TABLE_SYNC_MASK 0
  #endif
  
  /*
   * There is no default implementation for arch_sync_kernel_mappings(). It is
   * relied upon the compiler to optimize calls out if ARCH_PAGE_TABLE_SYNC_MASK
   * is 0.
   */
  void arch_sync_kernel_mappings(unsigned long start, unsigned long end);
  
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
145
146
   *	Lowlevel-APIs (not for driver use!)
   */
9585116ba   Jeremy Fitzhardinge   i386: fix iounmap...
147
148
149
  
  static inline size_t get_vm_area_size(const struct vm_struct *area)
  {
71394fe50   Andrey Ryabinin   mm: vmalloc: add ...
150
151
152
153
154
  	if (!(area->flags & VM_NO_GUARD))
  		/* return actual size without guard page */
  		return area->size - PAGE_SIZE;
  	else
  		return area->size;
9585116ba   Jeremy Fitzhardinge   i386: fix iounmap...
155
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
  extern struct vm_struct *get_vm_area(unsigned long size, unsigned long flags);
230169693   Christoph Lameter   vmallocinfo: add ...
157
  extern struct vm_struct *get_vm_area_caller(unsigned long size,
5e6cafc83   Marek Szyprowski   mm: vmalloc: use ...
158
  					unsigned long flags, const void *caller);
c29686129   Benjamin Herrenschmidt   vmalloc: add __ge...
159
160
161
  extern struct vm_struct *__get_vm_area_caller(unsigned long size,
  					unsigned long flags,
  					unsigned long start, unsigned long end,
5e6cafc83   Marek Szyprowski   mm: vmalloc: use ...
162
  					const void *caller);
301fa9f2d   Christoph Hellwig   mm: remove alloc_...
163
  void free_vm_area(struct vm_struct *area);
b3bdda02a   Christoph Lameter   vmalloc: add cons...
164
  extern struct vm_struct *remove_vm_area(const void *addr);
e9da6e990   Marek Szyprowski   ARM: dma-mapping:...
165
  extern struct vm_struct *find_vm_area(const void *addr);
c19c03fc7   Benjamin Herrenschmidt   [POWERPC] unmap_v...
166

b554cb426   Graf Yang   NOMMU: support SM...
167
  #ifdef CONFIG_MMU
8fc489850   Tejun Heo   vmalloc: add un/m...
168
169
  extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
  				    pgprot_t prot, struct page **pages);
ed1f324c5   Christoph Hellwig   mm: remove map_vm...
170
171
  int map_kernel_range(unsigned long start, unsigned long size, pgprot_t prot,
  		struct page **pages);
8fc489850   Tejun Heo   vmalloc: add un/m...
172
  extern void unmap_kernel_range_noflush(unsigned long addr, unsigned long size);
c19c03fc7   Benjamin Herrenschmidt   [POWERPC] unmap_v...
173
  extern void unmap_kernel_range(unsigned long addr, unsigned long size);
868b104d7   Rick Edgecombe   mm/vmalloc: Add f...
174
175
176
177
178
179
180
  static inline void set_vm_flush_reset_perms(void *addr)
  {
  	struct vm_struct *vm = find_vm_area(addr);
  
  	if (vm)
  		vm->flags |= VM_FLUSH_RESET_PERMS;
  }
b554cb426   Graf Yang   NOMMU: support SM...
181
182
183
184
185
186
187
  #else
  static inline int
  map_kernel_range_noflush(unsigned long start, unsigned long size,
  			pgprot_t prot, struct page **pages)
  {
  	return size >> PAGE_SHIFT;
  }
ed1f324c5   Christoph Hellwig   mm: remove map_vm...
188
  #define map_kernel_range map_kernel_range_noflush
b554cb426   Graf Yang   NOMMU: support SM...
189
190
191
192
  static inline void
  unmap_kernel_range_noflush(unsigned long addr, unsigned long size)
  {
  }
ed1f324c5   Christoph Hellwig   mm: remove map_vm...
193
  #define unmap_kernel_range unmap_kernel_range_noflush
868b104d7   Rick Edgecombe   mm/vmalloc: Add f...
194
195
196
  static inline void set_vm_flush_reset_perms(void *addr)
  {
  }
b554cb426   Graf Yang   NOMMU: support SM...
197
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
198

69beeb1d3   KOSAKI Motohiro   mm: make vread() ...
199
200
201
  /* for /dev/kmem */
  extern long vread(char *buf, char *addr, unsigned long count);
  extern long vwrite(char *buf, char *addr, unsigned long count);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
202
203
204
  /*
   *	Internals.  Dont't use..
   */
f1c4069e1   Joonsoo Kim   mm, vmalloc: expo...
205
  extern struct list_head vmap_area_list;
be9b7335e   Nicolas Pitre   mm: add vm_area_a...
206
  extern __init void vm_area_add_early(struct vm_struct *vm);
c0c0a2937   Tejun Heo   vmalloc: add @ali...
207
  extern __init void vm_area_register_early(struct vm_struct *vm, size_t align);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208

4f8b02b4e   Tejun Heo   vmalloc: pcpu_get...
209
  #ifdef CONFIG_SMP
b554cb426   Graf Yang   NOMMU: support SM...
210
  # ifdef CONFIG_MMU
ca23e405e   Tejun Heo   vmalloc: implemen...
211
212
  struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
  				     const size_t *sizes, int nr_vms,
ec3f64fc9   David Rientjes   mm: remove gfp ma...
213
  				     size_t align);
ca23e405e   Tejun Heo   vmalloc: implemen...
214
215
  
  void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
b554cb426   Graf Yang   NOMMU: support SM...
216
217
218
219
220
221
222
223
224
225
226
227
228
229
  # else
  static inline struct vm_struct **
  pcpu_get_vm_areas(const unsigned long *offsets,
  		const size_t *sizes, int nr_vms,
  		size_t align)
  {
  	return NULL;
  }
  
  static inline void
  pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
  {
  }
  # endif
4f8b02b4e   Tejun Heo   vmalloc: pcpu_get...
230
  #endif
ca23e405e   Tejun Heo   vmalloc: implemen...
231

db3808c1b   Joonsoo Kim   mm, vmalloc: move...
232
233
  #ifdef CONFIG_MMU
  #define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
db3808c1b   Joonsoo Kim   mm, vmalloc: move...
234
  #else
db3808c1b   Joonsoo Kim   mm, vmalloc: move...
235
  #define VMALLOC_TOTAL 0UL
db3808c1b   Joonsoo Kim   mm, vmalloc: move...
236
  #endif
4da56b99d   Chris Wilson   mm/vmap: Add a no...
237
238
  int register_vmap_purge_notifier(struct notifier_block *nb);
  int unregister_vmap_purge_notifier(struct notifier_block *nb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
239
  #endif /* _LINUX_VMALLOC_H */