Date: Mon, 17 Aug 2020 15:37:08 +0000 (UTC) From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r364310 - in head/sys: kern vm Message-ID: <202008171537.07HFb8a6058296@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: glebius Date: Mon Aug 17 15:37:08 2020 New Revision: 364310 URL: https://svnweb.freebsd.org/changeset/base/364310 Log: With INVARIANTS panic immediately if M_WAITOK is requested in a non-sleepable context. Previously only _sleep() would panic. This will catch misuse of M_WAITOK at development stage rather than at stress load stage. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D26027 Modified: head/sys/kern/kern_malloc.c head/sys/vm/uma_core.c Modified: head/sys/kern/kern_malloc.c ============================================================================== --- head/sys/kern/kern_malloc.c Mon Aug 17 15:11:46 2020 (r364309) +++ head/sys/kern/kern_malloc.c Mon Aug 17 15:37:08 2020 (r364310) @@ -618,6 +618,9 @@ void * unsigned long osize = size; #endif + KASSERT((flags & M_WAITOK) == 0 || THREAD_CAN_SLEEP(), + ("malloc(M_WAITOK) in non-sleepable context")); + #ifdef MALLOC_DEBUG va = NULL; if (malloc_dbg(&va, &size, mtp, flags) != 0) Modified: head/sys/vm/uma_core.c ============================================================================== --- head/sys/vm/uma_core.c Mon Aug 17 15:11:46 2020 (r364309) +++ head/sys/vm/uma_core.c Mon Aug 17 15:37:08 2020 (r364310) @@ -3328,6 +3328,9 @@ uma_zalloc_smr(uma_zone_t zone, int flags) uma_cache_bucket_t bucket; uma_cache_t cache; + KASSERT((flags & M_WAITOK) == 0 || THREAD_CAN_SLEEP(), + ("uma_zalloc_smr(M_WAITOK) in non-sleepable context")); + #ifdef UMA_ZALLOC_DEBUG void *item; @@ -3351,6 +3354,9 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int flags { uma_cache_bucket_t bucket; uma_cache_t cache; + + KASSERT((flags & M_WAITOK) == 0 || THREAD_CAN_SLEEP(), + ("uma_zalloc(M_WAITOK) in non-sleepable context")); /* Enable entropy collection for RANDOM_ENABLE_UMA kernel option */ random_harvest_fast_uma(&zone, sizeof(zone), RANDOM_UMA);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202008171537.07HFb8a6058296>