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
This commit is contained in:
Gleb Smirnoff 2020-08-17 15:37:08 +00:00
parent c119ccdbfd
commit 1921bb7b68
2 changed files with 9 additions and 0 deletions

View File

@ -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)

View File

@ -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;
@ -3352,6 +3355,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);