Commit 0ff2587f authored by Tejun Heo's avatar Tejun Heo

x86: prepare setup_pcpu_lpage() for pageattr fix

Make the following changes in preparation of coming pageattr updates.

* Define and use array of struct pcpul_ent instead of array of
  pointers.  The only difference is ->cpu field which is set but
  unused yet.

* Rename variables according to the above change.

* Rename local variable vm to pcpul_vm and move it out of the
  function.

[ Impact: no functional difference ]
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Jan Beulich <JBeulich@novell.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Ingo Molnar <mingo@elte.hu>
parent 97c9bf06
...@@ -137,8 +137,14 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size, ...@@ -137,8 +137,14 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
* better than only using 4k mappings while still being NUMA friendly. * better than only using 4k mappings while still being NUMA friendly.
*/ */
#ifdef CONFIG_NEED_MULTIPLE_NODES #ifdef CONFIG_NEED_MULTIPLE_NODES
struct pcpul_ent {
unsigned int cpu;
void *ptr;
};
static size_t pcpul_size __initdata; static size_t pcpul_size __initdata;
static void **pcpul_ptrs __initdata; static struct pcpul_ent *pcpul_map __initdata;
static struct vm_struct pcpul_vm;
static struct page * __init pcpul_get_page(unsigned int cpu, int pageno) static struct page * __init pcpul_get_page(unsigned int cpu, int pageno)
{ {
...@@ -147,13 +153,12 @@ static struct page * __init pcpul_get_page(unsigned int cpu, int pageno) ...@@ -147,13 +153,12 @@ static struct page * __init pcpul_get_page(unsigned int cpu, int pageno)
if (off >= pcpul_size) if (off >= pcpul_size)
return NULL; return NULL;
return virt_to_page(pcpul_ptrs[cpu] + off); return virt_to_page(pcpul_map[cpu].ptr + off);
} }
static ssize_t __init setup_pcpu_lpage(size_t static_size) static ssize_t __init setup_pcpu_lpage(size_t static_size)
{ {
static struct vm_struct vm; size_t map_size, dyn_size;
size_t ptrs_size, dyn_size;
unsigned int cpu; unsigned int cpu;
ssize_t ret; ssize_t ret;
...@@ -180,12 +185,14 @@ static ssize_t __init setup_pcpu_lpage(size_t static_size) ...@@ -180,12 +185,14 @@ static ssize_t __init setup_pcpu_lpage(size_t static_size)
dyn_size = pcpul_size - static_size - PERCPU_FIRST_CHUNK_RESERVE; dyn_size = pcpul_size - static_size - PERCPU_FIRST_CHUNK_RESERVE;
/* allocate pointer array and alloc large pages */ /* allocate pointer array and alloc large pages */
ptrs_size = PFN_ALIGN(num_possible_cpus() * sizeof(pcpul_ptrs[0])); map_size = PFN_ALIGN(num_possible_cpus() * sizeof(pcpul_map[0]));
pcpul_ptrs = alloc_bootmem(ptrs_size); pcpul_map = alloc_bootmem(map_size);
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
pcpul_ptrs[cpu] = pcpu_alloc_bootmem(cpu, PMD_SIZE, PMD_SIZE); pcpul_map[cpu].cpu = cpu;
if (!pcpul_ptrs[cpu]) pcpul_map[cpu].ptr = pcpu_alloc_bootmem(cpu, PMD_SIZE,
PMD_SIZE);
if (!pcpul_map[cpu].ptr)
goto enomem; goto enomem;
/* /*
...@@ -196,42 +203,43 @@ static ssize_t __init setup_pcpu_lpage(size_t static_size) ...@@ -196,42 +203,43 @@ static ssize_t __init setup_pcpu_lpage(size_t static_size)
* not well-specified to have a PAT-incompatible area * not well-specified to have a PAT-incompatible area
* (unmapped RAM, device memory, etc.) in that hole. * (unmapped RAM, device memory, etc.) in that hole.
*/ */
free_bootmem(__pa(pcpul_ptrs[cpu] + pcpul_size), free_bootmem(__pa(pcpul_map[cpu].ptr + pcpul_size),
PMD_SIZE - pcpul_size); PMD_SIZE - pcpul_size);
memcpy(pcpul_ptrs[cpu], __per_cpu_load, static_size); memcpy(pcpul_map[cpu].ptr, __per_cpu_load, static_size);
} }
/* allocate address and map */ /* allocate address and map */
vm.flags = VM_ALLOC; pcpul_vm.flags = VM_ALLOC;
vm.size = num_possible_cpus() * PMD_SIZE; pcpul_vm.size = num_possible_cpus() * PMD_SIZE;
vm_area_register_early(&vm, PMD_SIZE); vm_area_register_early(&pcpul_vm, PMD_SIZE);
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
pmd_t *pmd; pmd_t *pmd, pmd_v;
pmd = populate_extra_pmd((unsigned long)vm.addr pmd = populate_extra_pmd((unsigned long)pcpul_vm.addr +
+ cpu * PMD_SIZE); cpu * PMD_SIZE);
set_pmd(pmd, pfn_pmd(page_to_pfn(virt_to_page(pcpul_ptrs[cpu])), pmd_v = pfn_pmd(page_to_pfn(virt_to_page(pcpul_map[cpu].ptr)),
PAGE_KERNEL_LARGE)); PAGE_KERNEL_LARGE);
set_pmd(pmd, pmd_v);
} }
/* we're ready, commit */ /* we're ready, commit */
pr_info("PERCPU: Remapped at %p with large pages, static data " pr_info("PERCPU: Remapped at %p with large pages, static data "
"%zu bytes\n", vm.addr, static_size); "%zu bytes\n", pcpul_vm.addr, static_size);
ret = pcpu_setup_first_chunk(pcpul_get_page, static_size, ret = pcpu_setup_first_chunk(pcpul_get_page, static_size,
PERCPU_FIRST_CHUNK_RESERVE, dyn_size, PERCPU_FIRST_CHUNK_RESERVE, dyn_size,
PMD_SIZE, vm.addr, NULL); PMD_SIZE, pcpul_vm.addr, NULL);
goto out_free_ar; goto out_free_map;
enomem: enomem:
for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
if (pcpul_ptrs[cpu]) if (pcpul_map[cpu].ptr)
free_bootmem(__pa(pcpul_ptrs[cpu]), pcpul_size); free_bootmem(__pa(pcpul_map[cpu].ptr), pcpul_size);
ret = -ENOMEM; ret = -ENOMEM;
out_free_ar: out_free_map:
free_bootmem(__pa(pcpul_ptrs), ptrs_size); free_bootmem(__pa(pcpul_map), map_size);
return ret; return ret;
} }
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment