From owner-freebsd-arch@FreeBSD.ORG Thu Sep 25 02:57:20 2014 Return-Path: Delivered-To: arch@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 11BE54AD for ; Thu, 25 Sep 2014 02:57:20 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E6802132 for ; Thu, 25 Sep 2014 02:57:19 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.9/8.14.9) with ESMTP id s8P2vJBB033650 for ; Thu, 25 Sep 2014 02:57:19 GMT (envelope-from bdrewery@freefall.freebsd.org) Received: (from bdrewery@localhost) by freefall.freebsd.org (8.14.9/8.14.9/Submit) id s8P2vJFu033649 for arch@FreeBSD.org; Thu, 25 Sep 2014 02:57:19 GMT (envelope-from bdrewery) Received: (qmail 87317 invoked from network); 24 Sep 2014 21:57:17 -0500 Received: from unknown (HELO blah) (freebsd@shatow.net@10.10.1.90) by sweb.xzibition.com with ESMTPA; 24 Sep 2014 21:57:17 -0500 Message-ID: <5423848D.9050602@FreeBSD.org> Date: Wed, 24 Sep 2014 21:57:17 -0500 From: Bryan Drewery Organization: FreeBSD User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: arch@FreeBSD.org Subject: Re: KASSERT_WARN for asserting malloc(M_WAITOK) not in a non-sleepable thread References: <54236CD6.4050807@FreeBSD.org> In-Reply-To: <54236CD6.4050807@FreeBSD.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Sep 2014 02:57:20 -0000 On 9/24/14, 8:16 PM, Bryan Drewery wrote: > Hi, > > I've placed 2 reviews out in relation to > https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=193696: > > Add KASSERT_WARN which will work just like KASSERT except that no panic > will occur. My own expectation would be that any use of it would > eventually be promoted to a full KASSERT. It would only be used where > the impact is not known yet on all hardware/devices. We don't want to > go adding a KASSERT and break boot for a whole class of systems. > > https://reviews.freebsd.org/D829 - KASSERT_WARN > > > Add the KASSERT_WARN to malloc(9) and uma_zalloc_arg(9) to ensure they > are not called from a non-sleepable thread. This is currently violated > by cam, namely xpt_done_td() [see bug 193696]. > > https://reviews.freebsd.org/D830 - Use KASSERT_WARN in malloc(9) and > uma_zalloc_arg(9) > > One flaw of this is that the KASSERT_WARN in malloc(9) is called, prints > to console, continues, and then the uma_zalloc_arg(9) is called and does > the same. I thought perhaps the KASSERT_WARN could only be added in > uma_zalloc_arg(9) for now and later the full KASSERT could be added in > malloc(9), but I think this could miss some cases for memguard and maybe > redzone uses. > > By the way, it was mentioned to me that the interrupt assert may be > wrong but from my understanding the thread is in an interrupt context if > td_intr_nesting_level>0, so the check seems fine to me. > > Example output: > >> ada3: s/n STF605MH1THSXW detached >> KASSERT failed: malloc(M_WAITOK) in no_sleeping context >> KDB: stack backtrace: >> db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe349829a340 >> kdb_backtrace() at kdb_backtrace+0x39/frame 0xfffffe349829a3f0 >> _kassert_panic() at _kassert_panic+0xd7/frame 0xfffffe349829a470 >> malloc() at malloc+0x2e4/frame 0xfffffe349829a4c0 >> g_post_event_x() at g_post_event_x+0x84/frame 0xfffffe349829a510 >> g_post_event() at g_post_event+0x5d/frame 0xfffffe349829a580 >> adacleanup() at adacleanup+0x62/frame 0xfffffe349829a5a0 >> cam_periph_release_locked_buses() at cam_periph_release_locked_buses+0xde/frame 0xfffffe349829aaa0 >> cam_periph_release_locked() at cam_periph_release_locked+0x1b/frame 0xfffffe349829aac0 >> adadone() at adadone+0x26e/frame 0xfffffe349829ab20 >> xpt_done_process() at xpt_done_process+0x3a4/frame 0xfffffe349829ab60 >> xpt_done_td() at xpt_done_td+0x136/frame 0xfffffe349829abb0 >> fork_exit() at fork_exit+0x84/frame 0xfffffe349829abf0 >> fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe349829abf0 >> --- trap 0, rip = 0, rsp = 0xfffffe349829acb0, rbp = 0 --- >> KASSERT failed: uma_zalloc_arg(M_WAITOK) in no_sleeping context >> KDB: stack backtrace: >> db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe349829a2d0 >> kdb_backtrace() at kdb_backtrace+0x39/frame 0xfffffe349829a380 >> _kassert_panic() at _kassert_panic+0xd7/frame 0xfffffe349829a400 >> uma_zalloc_arg() at uma_zalloc_arg+0x6c5/frame 0xfffffe349829a470 >> malloc() at malloc+0x1c7/frame 0xfffffe349829a4c0 >> g_post_event_x() at g_post_event_x+0x84/frame 0xfffffe349829a510 >> g_post_event() at g_post_event+0x5d/frame 0xfffffe349829a580 >> adacleanup() at adacleanup+0x62/frame 0xfffffe349829a5a0 >> cam_periph_release_locked_buses() at cam_periph_release_locked_buses+0xde/frame 0xfffffe349829aaa0 >> cam_periph_release_locked() at cam_periph_release_locked+0x1b/frame 0xfffffe349829aac0 >> adadone() at adadone+0x26e/frame 0xfffffe349829ab20 >> xpt_done_process() at xpt_done_process+0x3a4/frame 0xfffffe349829ab60 >> xpt_done_td() at xpt_done_td+0x136/frame 0xfffffe349829abb0 >> fork_exit() at fork_exit+0x84/frame 0xfffffe349829abf0 >> fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe349829abf0 >> --- trap 0, rip = 0, rsp = 0xfffffe349829acb0, rbp = 0 --- >> (ada3:ahcich3:0:0:0): Periph destroyed > > Here's another one... > KASSERT failed: malloc(M_WAITOK) in no_sleeping context > KDB: stack backtrace: > db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe3509bd7800 > kdb_backtrace() at kdb_backtrace+0x39/frame 0xfffffe3509bd78b0 > _kassert_panic() at _kassert_panic+0xd7/frame 0xfffffe3509bd7930 > malloc() at malloc+0x2e4/frame 0xfffffe3509bd7980 > zfs_dbgmsg() at zfs_dbgmsg+0x6d/frame 0xfffffe3509bd7a00 > spa_deadman() at spa_deadman+0x70/frame 0xfffffe3509bd7a30 > softclock_call_cc() at softclock_call_cc+0x19c/frame 0xfffffe3509bd7b10 > softclock() at softclock+0x47/frame 0xfffffe3509bd7b30 > intr_event_execute_handlers() at intr_event_execute_handlers+0x93/frame 0xfffffe3509bd7b70 > ithread_loop() at ithread_loop+0xa6/frame 0xfffffe3509bd7bb0 > fork_exit() at fork_exit+0x84/frame 0xfffffe3509bd7bf0 > fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe3509bd7bf0 -- Regards, Bryan Drewery