diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2017-05-11 00:42:06 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2017-05-11 00:42:06 +0000 |
commit | 6121d88afc791b6530ebf00613a5c001afe54f8a (patch) | |
tree | cf4b02c8c11bc19f0812c39b4b919dbfdf3a2535 /sys/uvm | |
parent | 0843714eb3319e0d62022966c0337deea0ed1f6b (diff) |
reorder uvm init to avoid use before initialisation.
the particular use before init was in uvm_init step 6, which calls
kmeminit to set up malloc(9), which calls uvm_km_zalloc, which calls
pmap_enter, which calls pool_get, which tries to allocate a page
using km_alloc, which isnt initalised until step 9 in uvm_init.
uvm_km_page_init calls kthread_create though, which uses malloc
internally, so it cant be reordered before malloc init.
to cope with this, uvm_km_page_init is split up. it sets up the
subsystem, and is called before kmeminit. the thread init is moved
to uvm_km_page_lateinit, which is called after kmeminit in uvm_init.
Diffstat (limited to 'sys/uvm')
-rw-r--r-- | sys/uvm/uvm_init.c | 19 | ||||
-rw-r--r-- | sys/uvm/uvm_km.c | 12 | ||||
-rw-r--r-- | sys/uvm/uvm_km.h | 3 |
3 files changed, 25 insertions, 9 deletions
diff --git a/sys/uvm/uvm_init.c b/sys/uvm/uvm_init.c index 9f8300976e0..908031fbdb8 100644 --- a/sys/uvm/uvm_init.c +++ b/sys/uvm/uvm_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_init.c,v 1.39 2015/03/14 03:38:53 jsg Exp $ */ +/* $OpenBSD: uvm_init.c,v 1.40 2017/05/11 00:42:05 dlg Exp $ */ /* $NetBSD: uvm_init.c,v 1.14 2000/06/27 17:29:23 mrg Exp $ */ /* @@ -114,30 +114,35 @@ uvm_init(void) pmap_init(); /* - * step 6: init the kernel memory allocator. after this call the + * step 6: init uvm_km_page allocator memory. + */ + uvm_km_page_init(); + + /* + * step 7: init the kernel memory allocator. after this call the * kernel memory allocator (malloc) can be used. */ kmeminit(); /* - * step 6.5: init the dma allocator, which is backed by pools. + * step 7.5: init the dma allocator, which is backed by pools. */ dma_alloc_init(); /* - * step 7: init all pagers and the pager_map. + * step 8: init all pagers and the pager_map. */ uvm_pager_init(); /* - * step 8: init anonymous memory system + * step 9: init anonymous memory system */ amap_init(); /* - * step 9: init uvm_km_page allocator memory. + * step 10: start uvm_km_page allocator thread. */ - uvm_km_page_init(); + uvm_km_page_lateinit(); /* * the VM system is now up! now that malloc is up we can diff --git a/sys/uvm/uvm_km.c b/sys/uvm/uvm_km.c index f76bd87c493..fe733c73353 100644 --- a/sys/uvm/uvm_km.c +++ b/sys/uvm/uvm_km.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_km.c,v 1.128 2015/09/26 17:55:00 kettenis Exp $ */ +/* $OpenBSD: uvm_km.c,v 1.129 2017/05/11 00:42:05 dlg Exp $ */ /* $NetBSD: uvm_km.c,v 1.42 2001/01/14 02:10:01 thorpej Exp $ */ /* @@ -605,6 +605,12 @@ uvm_km_page_init(void) /* nothing */ } +void +uvm_km_page_latethread(void) +{ + /* nothing */ +} + #else /* * uvm_km_page allocator, non __HAVE_PMAP_DIRECT archs @@ -678,7 +684,11 @@ uvm_km_page_init(void) /* tone down if really high */ if (uvm_km_pages.lowat > 512) uvm_km_pages.lowat = 512; +} +void +uvm_km_page_lateinit(void) +{ kthread_create_deferred(uvm_km_createthread, NULL); } diff --git a/sys/uvm/uvm_km.h b/sys/uvm/uvm_km.h index c851067a0e0..fe7d3951941 100644 --- a/sys/uvm/uvm_km.h +++ b/sys/uvm/uvm_km.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_km.h,v 1.14 2015/02/07 08:21:24 miod Exp $ */ +/* $OpenBSD: uvm_km.h,v 1.15 2017/05/11 00:42:05 dlg Exp $ */ /* $NetBSD: uvm_km.h,v 1.9 1999/06/21 17:25:11 thorpej Exp $ */ /* @@ -45,6 +45,7 @@ void uvm_km_init(vaddr_t, vaddr_t, vaddr_t); void uvm_km_page_init(void); +void uvm_km_page_lateinit(void); void uvm_km_pgremove(struct uvm_object *, vaddr_t, vaddr_t); void uvm_km_pgremove_intrsafe(vaddr_t, vaddr_t); |