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); _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"