From owner-freebsd-current@freebsd.org Tue Aug 18 14:04:24 2020 Return-Path: Delivered-To: freebsd-current@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BBCA43BD2F4 for ; Tue, 18 Aug 2020 14:04:24 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mailman.nyi.freebsd.org (unknown [127.0.1.3]) by mx1.freebsd.org (Postfix) with ESMTP id 4BWCMX3h78z46cZ for ; Tue, 18 Aug 2020 14:04:24 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mailman.nyi.freebsd.org (Postfix) id 7E7013BD2F3; Tue, 18 Aug 2020 14:04:24 +0000 (UTC) Delivered-To: current@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7E3433BD474 for ; Tue, 18 Aug 2020 14:04:24 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BWCMW5j4Fz46Ln for ; Tue, 18 Aug 2020 14:04:23 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-qk1-x744.google.com with SMTP id j187so18279155qke.11 for ; Tue, 18 Aug 2020 07:04:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=rfOGAUSEH0p+ZzB6b6meRDo8eTtRmAhJ29W+wu7MNsQ=; b=HQ1qgRB7R8JILJSaSFDrk85u2OcKKdlIcqllFlQtnqGpBtdyHJDoEemGGgM9G7Jybo uXfRHpWfUOtxUZbnMygQ0r7TNxn2zAEd9wD7orcBOLWjjUYiSdwRR4GLXxOWdTB2BgDQ azjrqna5Et1VV3yzfMyx0CRFl10of82XMHMMq1QJRTvBD4ru8cJp1eyPHxhCAfFrLu4P I030ljk6yV34g/2kVhVslHaANGMPipFHWZrIueRXBHYzgXz8oWSLu18HvdFKlpwNiK8E d/GFsn4y34+ofdHVHlQjzDJJYpbFHQ/5oYnjgK8fmtkbYzi97i5BasBCVcgcRuOagJn8 s5FA== X-Gm-Message-State: AOAM5301kmf6/ngpkLxZqsW/t2RiSCqNqGKHGbY18fvjrkGQpAxpvGLh jpyNw/5XN4VmaEZANpgvtHaE6QRKJ2w= X-Google-Smtp-Source: ABdhPJwmAhRnpP24l+JUWTurbOm6eipOEvWcRA4bt5izlrUpneg51uuc08hueUOi6aYjL7XqDaJ8AA== X-Received: by 2002:a05:620a:1a:: with SMTP id j26mr17576259qki.183.1597759461902; Tue, 18 Aug 2020 07:04:21 -0700 (PDT) Received: from raichu (toroon0560w-lp130-08-67-71-176-35.dsl.bell.ca. [67.71.176.35]) by smtp.gmail.com with ESMTPSA id a8sm21963954qth.69.2020.08.18.07.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2020 07:04:21 -0700 (PDT) Sender: Mark Johnston Date: Tue, 18 Aug 2020 10:04:19 -0400 From: Mark Johnston To: Mateusz Guzik Cc: current@freebsd.org Subject: Re: "panic: malloc(M_WAITOK) in non-sleepable context" after r364296 -> r364341 Message-ID: <20200818140419.GB28906@raichu> References: <20200818124419.GO1394@albert.catwhisker.org> <20200818125825.GP1394@albert.catwhisker.org> <20200818134900.GA28906@raichu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4BWCMW5j4Fz46Ln X-Spamd-Bar: / X-Spamd-Result: default: False [-0.17 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[current@freebsd.org]; DMARC_NA(0.00)[freebsd.org]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::744:from]; NEURAL_HAM_SHORT(-0.47)[-0.473]; MID_RHS_NOT_FQDN(0.50)[]; FREEMAIL_TO(0.00)[gmail.com]; FORGED_SENDER(0.30)[markj@freebsd.org,markjdb@gmail.com]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[markj@freebsd.org,markjdb@gmail.com]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[current] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Aug 2020 14:04:24 -0000 On Tue, Aug 18, 2020 at 03:55:15PM +0200, Mateusz Guzik wrote: > On 8/18/20, Mark Johnston wrote: > > On Tue, Aug 18, 2020 at 03:24:52PM +0200, Mateusz Guzik wrote: > >> 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 > >> @@ -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); > > > > Doesn't it only print a warning if non-sleepable locks are held? > > THREAD_CAN_SLEEP() catches other cases, like epoch sections and worker > > threads that are not allowed to sleep (CAM doneq threads in this case). > > Otherwise uma_zalloc_debug() already checks with WITNESS. > > > > I'm inclined to simply revert the commit for now. Alternately, > > disk_alloc() could be modified to handle M_NOWAIT/M_WAITOK flags, and > > that could be used in daregister() and other CAM periph drivers. > > daregister() already uses M_NOWAIT to allocate the driver softc itself. > > > > If WITNESS_WARN(.., WARN_SLEEPOK) does not check for all possible > blockers for going off CPU that's a bug. I do support reverting the > patch for now until the dust settles. I don't propose the above hack > as the final fix. Well, IMO the bug is that we have no subroutine to perform all of these checks (which includes those done by WITNESS_WARN(..., WARN_SLEEPOK)). WITNESS' responsibilities are more narrow. I just meant that your patch effectively reverts Gleb's commit. > As for the culrpit at hand, given the backtrace: > devfs_alloc() at devfs_alloc+0x28/frame 0xffffffff8218d570 > make_dev_sv() at make_dev_sv+0x97/frame 0xffffffff8218d600 > make_dev_s() at make_dev_s+0x3b/frame 0xffffffff8218d660 > passregister() at passregister+0x3e7/frame 0xffffffff8218d8b0 > > I think this is missing wait flags, resulting in M_WAITOK later, i.e.: Ah, I was looking at a different report. All the more reason to revert for now.