From: bluhm Date: Thu, 18 Jan 2018 18:08:51 +0000 (+0000) Subject: While booting it does not make sense to wait for memory, there is X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a97ba27b3153adcbfb3d800439a2e57d1435f534;p=openbsd While booting it does not make sense to wait for memory, there is no other process which could free it. Better panic in malloc(9) or pool_get(9) instead of sleeping forever. tested by visa@ patrick@ Jan Klemkow suggested by kettenis@; OK deraadt@ --- diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 1df4acfdcc0..5ea2bc176ae 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_malloc.c,v 1.132 2018/01/02 06:07:21 guenther Exp $ */ +/* $OpenBSD: kern_malloc.c,v 1.133 2018/01/18 18:08:51 bluhm Exp $ */ /* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */ /* @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -205,6 +206,11 @@ malloc(size_t size, int type, int flags) mtx_leave(&malloc_mtx); return (NULL); } +#ifdef DIAGNOSTIC + if (ISSET(flags, M_WAITOK) && curproc == &proc0) + panic("%s: cannot sleep for memory during boot", + __func__); +#endif if (ksp->ks_limblocks < 65535) ksp->ks_limblocks++; msleep(ksp, &malloc_mtx, PSWP+2, memname[type], 0); diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index 54688dfe0ea..cbcbffbfa3b 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.220 2017/08/13 20:26:33 guenther Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.221 2018/01/18 18:08:51 bluhm Exp $ */ /* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */ /*- @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -596,6 +597,11 @@ pool_get(struct pool *pp, int flags) struct pool_get_memory mem = { .v = NULL }; struct pool_request pr; +#ifdef DIAGNOSTIC + if (ISSET(flags, PR_WAITOK) && curproc == &proc0) + panic("%s: cannot sleep for memory during boot", + __func__); +#endif pl_init(pp, &mem.lock); pool_request_init(&pr, pool_get_done, &mem); pool_request(pp, &pr); diff --git a/sys/uvm/uvm_pdaemon.c b/sys/uvm/uvm_pdaemon.c index 822b5e23633..c0368f66815 100644 --- a/sys/uvm/uvm_pdaemon.c +++ b/sys/uvm/uvm_pdaemon.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_pdaemon.c,v 1.78 2017/02/14 10:31:15 mpi Exp $ */ +/* $OpenBSD: uvm_pdaemon.c,v 1.79 2018/01/18 18:08:51 bluhm Exp $ */ /* $NetBSD: uvm_pdaemon.c,v 1.23 2000/08/20 10:24:14 bjh21 Exp $ */ /* @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -111,6 +112,11 @@ uvm_wait(const char *wmsg) { int timo = 0; +#ifdef DIAGNOSTIC + if (curproc == &proc0) + panic("%s: cannot sleep for memory during boot", __func__); +#endif + /* check for page daemon going to sleep (waiting for itself) */ if (curproc == uvm.pagedaemon_proc) { printf("uvm_wait emergency bufbackoff\n");