Re: "panic: malloc(M_WAITOK) in non-sleepable context" after r364296 -> r364341

From: Mateusz Guzik <mjguzik_at_gmail.com>
Date: Tue, 18 Aug 2020 15:24:52 +0200
Try this:

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
_at__at_ -618,8 +618,8 _at__at_ 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
_at__at_ -3355,8 +3355,8 _at__at_ 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/18/20, David Wolfskill <david_at_catwhisker.org> wrote:
> On Tue, Aug 18, 2020 at 02:48:47PM +0200, Mateusz Guzik wrote:
>> see https://reviews.freebsd.org/D26027
>> ....
>
> Right; I was just reviewing the list of updated files and noted
> src/sys/kern/kern_malloc.c, and its svn log showed:
>
> ------------------------------------------------------------------------
> r364310 | glebius | 2020-08-17 08:37:08 -0700 (Mon, 17 Aug 2020) | 8
> lines
>
> 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
>
> ------------------------------------------------------------------------
>
> And if we were still going in to the office, I'd discuss it with Gleb.  :-)
>
> But in the mean time: I'm not a committer; I didn't cause the error.
> Seems I can't try running head now with a GENERIC kernel.
>
> Peace,
> david
> --
> David H. Wolfskill				david_at_catwhisker.org
> Donald Trump is either ignorant of how to govern or is refusing to do so.
>
> See http://www.catwhisker.org/~david/publickey.gpg for my public key.
>


-- 
Mateusz Guzik <mjguzik gmail.com>
Received on Tue Aug 18 2020 - 11:24:56 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:24 UTC