Skip to content

Commit f0aa661

Browse files
committed
vmalloc: implement vm_area_register_early()
Impact: allow multiple early vm areas There are places where kernel VM area needs to be allocated before vmalloc is initialized. This is done by allocating static vm_struct, initializing several fields and linking it to vmlist and later vmalloc initialization picking up these from vmlist. This is currently done manually and if there's more than one such areas, there's no defined way to arbitrate who gets which address. This patch implements vm_area_register_early(), which takes vm_area struct with flags and size initialized, assigns address to it and puts it on the vmlist. This way, multiple early vm areas can determine which addresses they should use. The only current user - alpha mm init - is converted to use it. Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent f2a8205 commit f0aa661

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

‎arch/alpha/mm/init.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,21 @@ callback_init(void * kernel_end)
189189

190190
if (alpha_using_srm) {
191191
static struct vm_struct console_remap_vm;
192-
unsigned long vaddr = VMALLOC_START;
192+
unsigned long nr_pages = 0;
193+
unsigned long vaddr;
193194
unsigned long i, j;
194195

196+
/* calculate needed size */
197+
for (i = 0; i < crb->map_entries; ++i)
198+
nr_pages += crb->map[i].count;
199+
200+
/* register the vm area */
201+
console_remap_vm.flags = VM_ALLOC;
202+
console_remap_vm.size = nr_pages << PAGE_SHIFT;
203+
vm_area_register_early(&console_remap_vm);
204+
205+
vaddr = (unsigned long)consle_remap_vm.addr;
206+
195207
/* Set up the third level PTEs and update the virtual
196208
addresses of the CRB entries. */
197209
for (i = 0; i < crb->map_entries; ++i) {
@@ -213,12 +225,6 @@ callback_init(void * kernel_end)
213225
vaddr += PAGE_SIZE;
214226
}
215227
}
216-
217-
/* Let vmalloc know that we've allocated some space. */
218-
console_remap_vm.flags = VM_ALLOC;
219-
console_remap_vm.addr = (void *) VMALLOC_START;
220-
console_remap_vm.size = vaddr - VMALLOC_START;
221-
vmlist = &console_remap_vm;
222228
}
223229

224230
callback_init_done = 1;

‎include/linux/vmalloc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@ extern long vwrite(char *buf, char *addr, unsigned long count);
106106
*/
107107
extern rwlock_t vmlist_lock;
108108
extern struct vm_struct *vmlist;
109+
extern __init void vm_area_register_early(struct vm_struct *vm);
109110

110111
#endif /* _LINUX_VMALLOC_H */

‎mm/vmalloc.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/radix-tree.h>
2525
#include <linux/rcupdate.h>
2626
#include <linux/bootmem.h>
27+
#include <linux/pfn.h>
2728

2829
#include <asm/atomic.h>
2930
#include <asm/uaccess.h>
@@ -982,6 +983,29 @@ void *vm_map_ram(struct page **pages, unsigned int count, int node, pgprot_t pro
982983
}
983984
EXPORT_SYMBOL(vm_map_ram);
984985

986+
/**
987+
* vm_area_register_early - register vmap area early during boot
988+
* @vm: vm_struct to register
989+
* @size: size of area to register
990+
*
991+
* This function is used to register kernel vm area before
992+
* vmalloc_init() is called. @vm->size and @vm->flags should contain
993+
* proper values on entry and other fields should be zero. On return,
994+
* vm->addr contains the allocated address.
995+
*
996+
* DO NOT USE THIS FUNCTION UNLESS YOU KNOW WHAT YOU'RE DOING.
997+
*/
998+
void __init vm_area_register_early(struct vm_struct *vm)
999+
{
1000+
static size_t vm_init_off __initdata;
1001+
1002+
vm->addr = (void *)VMALLOC_START + vm_init_off;
1003+
vm_init_off = PFN_ALIGN(vm_init_off + vm->size);
1004+
1005+
vm->next = vmlist;
1006+
vmlist = vm;
1007+
}
1008+
9851009
void __init vmalloc_init(void)
9861010
{
9871011
struct vmap_area *va;

0 commit comments

Comments
 (0)