"panic: malloc(M_WAITOK) in non-sleepable context" when inserting usb stick

Mateusz Guzik mjguzik at gmail.com
Tue Aug 18 13:31:46 UTC 2020


Hello,

this sould take care of it (in that it will print the warning, but not
panic the box):

diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 46eb1c4347c..7b94ca7b880 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -618,8 +618,8 @@ void *
        unsigned long osize = size;
 #endif

-       KASSERT((flags & M_WAITOK) == 0 || THREAD_CAN_SLEEP(),
-           ("malloc(M_WAITOK) in non-sleepable context"));
+       if ((flags & M_WAITOK) != 0)
+               WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, __func__);

 #ifdef MALLOC_DEBUG
        va = NULL;
diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c
index 37d78354200..2e1267ec02f 100644
--- a/sys/vm/uma_core.c
+++ b/sys/vm/uma_core.c
@@ -3355,8 +3355,8 @@ 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"));
+       if ((flags & M_WAITOK) != 0)
+               WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, __func__);

        /* Enable entropy collection for RANDOM_ENABLE_UMA kernel option */
        random_harvest_fast_uma(&zone, sizeof(zone), RANDOM_UMA);

On 8/17/20, moridin at mm.st <moridin at mm.st> wrote:
> r364323, previously I think it was just a warning from witness.  Happens
> both on boot with stick already inserted, and when inserting the stick in
> booted system.
>
> Looks like my swap partition is no longer big enough for dump, translating
> from screen:
>
> umass0 numa-domain 0 on uhub4
> umass0:2:0: Attached to scbus2
> panic: malloc(M_WAITOK) in non-sleepable context
>
> vpanic()
> panic()
> malloc()
> disk_alloc()
> daregister()
> cam_periph_alloc()
> daasync()
> xpt_async_process_dev()
> xpt_async_process()
> xpt_done_process()
> xpt_done_td()
> fork_exit()
> fork_trampoline()
> _______________________________________________
> freebsd-current at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe at freebsd.org"
>


-- 
Mateusz Guzik <mjguzik gmail.com>


More information about the freebsd-current mailing list