14 unsigned int cpu,
int page_idx)
41 static struct page **pcpu_get_pages_and_bitmap(
struct pcpu_chunk *chunk,
42 unsigned long **bitmapp,
46 static unsigned long *
bitmap;
47 size_t pages_size = pcpu_nr_units * pcpu_unit_pages *
sizeof(pages[0]);
49 sizeof(
unsigned long);
51 if (!pages || !bitmap) {
52 if (may_alloc && !pages)
53 pages = pcpu_mem_zalloc(pages_size);
54 if (may_alloc && !bitmap)
55 bitmap = pcpu_mem_zalloc(bitmap_size);
56 if (!pages || !bitmap)
60 bitmap_copy(bitmap, chunk->
populated, pcpu_unit_pages);
77 static void pcpu_free_pages(
struct pcpu_chunk *chunk,
78 struct page **pages,
unsigned long *populated,
79 int page_start,
int page_end)
85 for (i = page_start; i < page_end; i++) {
86 struct page *
page = pages[pcpu_page_idx(cpu, i)];
106 static int pcpu_alloc_pages(
struct pcpu_chunk *chunk,
107 struct page **pages,
unsigned long *populated,
108 int page_start,
int page_end)
115 for (i = page_start; i < page_end; i++) {
116 struct page **pagep = &pages[pcpu_page_idx(cpu, i)];
118 *pagep = alloc_pages_node(
cpu_to_node(cpu), gfp, 0);
120 pcpu_free_pages(chunk, pages, populated,
121 page_start, page_end);
141 static void pcpu_pre_unmap_flush(
struct pcpu_chunk *chunk,
142 int page_start,
int page_end)
145 pcpu_chunk_addr(chunk, pcpu_low_unit_cpu, page_start),
146 pcpu_chunk_addr(chunk, pcpu_high_unit_cpu, page_end));
149 static void __pcpu_unmap_pages(
unsigned long addr,
int nr_pages)
168 static void pcpu_unmap_pages(
struct pcpu_chunk *chunk,
169 struct page **pages,
unsigned long *populated,
170 int page_start,
int page_end)
176 for (i = page_start; i < page_end; i++) {
179 page = pcpu_chunk_page(chunk, cpu, i);
181 pages[pcpu_page_idx(cpu, i)] =
page;
183 __pcpu_unmap_pages(pcpu_chunk_addr(chunk, cpu, page_start),
184 page_end - page_start);
187 bitmap_clear(populated, page_start, page_end - page_start);
203 static void pcpu_post_unmap_tlb_flush(
struct pcpu_chunk *chunk,
204 int page_start,
int page_end)
207 pcpu_chunk_addr(chunk, pcpu_low_unit_cpu, page_start),
208 pcpu_chunk_addr(chunk, pcpu_high_unit_cpu, page_end));
211 static int __pcpu_map_pages(
unsigned long addr,
struct page **pages,
234 static int pcpu_map_pages(
struct pcpu_chunk *chunk,
235 struct page **pages,
unsigned long *populated,
236 int page_start,
int page_end)
238 unsigned int cpu, tcpu;
242 err = __pcpu_map_pages(pcpu_chunk_addr(chunk, cpu, page_start),
243 &pages[pcpu_page_idx(cpu, page_start)],
244 page_end - page_start);
250 for (i = page_start; i < page_end; i++) {
252 pcpu_set_page_chunk(pages[pcpu_page_idx(cpu, i)],
263 __pcpu_unmap_pages(pcpu_chunk_addr(chunk, tcpu, page_start),
264 page_end - page_start);
281 static void pcpu_post_map_flush(
struct pcpu_chunk *chunk,
282 int page_start,
int page_end)
285 pcpu_chunk_addr(chunk, pcpu_low_unit_cpu, page_start),
286 pcpu_chunk_addr(chunk, pcpu_high_unit_cpu, page_end));
301 static int pcpu_populate_chunk(
struct pcpu_chunk *chunk,
int off,
int size)
304 int page_end =
PFN_UP(off + size);
305 int free_end = page_start, unmap_end = page_start;
307 unsigned long *populated;
313 pcpu_next_pop(chunk, &rs, &re, page_end);
314 if (rs == page_start && re == page_end)
320 pages = pcpu_get_pages_and_bitmap(chunk, &populated,
true);
326 rc = pcpu_alloc_pages(chunk, pages, populated, rs, re);
333 rc = pcpu_map_pages(chunk, pages, populated, rs, re);
338 pcpu_post_map_flush(chunk, page_start, page_end);
341 bitmap_copy(chunk->
populated, populated, pcpu_unit_pages);
344 memset((
void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size);
348 pcpu_pre_unmap_flush(chunk, page_start, unmap_end);
350 pcpu_unmap_pages(chunk, pages, populated, rs, re);
351 pcpu_post_unmap_tlb_flush(chunk, page_start, unmap_end);
354 pcpu_free_pages(chunk, pages, populated, rs, re);
371 static
void pcpu_depopulate_chunk(
struct pcpu_chunk *chunk,
int off,
int size)
374 int page_end =
PFN_UP(off + size);
376 unsigned long *populated;
381 pcpu_next_unpop(chunk, &rs, &re, page_end);
382 if (rs == page_start && re == page_end)
393 pages = pcpu_get_pages_and_bitmap(chunk, &populated,
false);
397 pcpu_pre_unmap_flush(chunk, page_start, page_end);
400 pcpu_unmap_pages(chunk, pages, populated, rs, re);
405 pcpu_free_pages(chunk, pages, populated, rs, re);
408 bitmap_copy(chunk->populated, populated, pcpu_unit_pages);
416 chunk = pcpu_alloc_chunk();
420 vms = pcpu_get_vm_areas(pcpu_group_offsets, pcpu_group_sizes,
421 pcpu_nr_groups, pcpu_atom_size);
423 pcpu_free_chunk(chunk);
432 static void pcpu_destroy_chunk(
struct pcpu_chunk *chunk)
434 if (chunk && chunk->
data)
435 pcpu_free_vm_areas(chunk->
data, pcpu_nr_groups);
436 pcpu_free_chunk(chunk);
439 static struct page *pcpu_addr_to_page(
void *
addr)