From owner-freebsd-current@freebsd.org Sat Mar 25 03:31:49 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A745FD1B4EF for ; Sat, 25 Mar 2017 03:31:49 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebi.us (glebi.us [96.95.210.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "cell.glebi.us", Issuer "cell.glebi.us" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 904F3861 for ; Sat, 25 Mar 2017 03:31:48 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from cell.glebi.us (localhost [127.0.0.1]) by cell.glebi.us (8.15.2/8.15.2) with ESMTPS id v2P3Vg0j096258 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 24 Mar 2017 20:31:42 -0700 (PDT) (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by cell.glebi.us (8.15.2/8.15.2/Submit) id v2P3Vg5X096257; Fri, 24 Mar 2017 20:31:42 -0700 (PDT) (envelope-from glebius@FreeBSD.org) X-Authentication-Warning: cell.glebi.us: glebius set sender to glebius@FreeBSD.org using -f Date: Fri, 24 Mar 2017 20:31:42 -0700 From: Gleb Smirnoff To: Darren Cc: Konstantin Belousov , "freebsd-current@freebsd.org" Subject: Re: r315684 panic: sleepq_add: td 0xfffff80003c01a40 to sleep on wchan 0xfffff80006f0873c with sleeping prohibited Message-ID: <20170325033142.GA23308@FreeBSD.org> References: <1824572972.3096988.1490377215756.ref@mail.yahoo.com> <1824572972.3096988.1490377215756@mail.yahoo.com> <20170325010314.GG43712@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ibvzjYYg+QDzMCy1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20170325010314.GG43712@kib.kiev.ua> User-Agent: Mutt/1.7.2 (2016-11-26) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 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: Sat, 25 Mar 2017 03:31:49 -0000 --ibvzjYYg+QDzMCy1 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Darren, On Sat, Mar 25, 2017 at 03:03:14AM +0200, Konstantin Belousov wrote: K> On Fri, Mar 24, 2017 at 05:40:15PM +0000, Darren wrote: K> > I am getting this panic every hour to every couple of hours. K> > K> > FreeBSD asrock 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r315684: Thu Mar 23 14:56:45 EDT 2017     darren@asrock:/usr/obj/usr/src/sys/GENERIC  amd64 K> > I manually typed out the following, apologize for any typos. K> > K> > K> > panic: sleepq_add: td 0xfffff80003c01a40 to sleep on wchan 0xfffff80006f0873c with sleeping prohibited K> > cpuid = 0 K> > time = 1490372797 K> > KDB: stack backtrace: K> > db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe0072e33690 K> > vpanic() at vpanic+0x19c/frame 0xfffffe0072e33710 K> > kassert_panic() at kassert_panic+0x126/frame 0xfffffe0072e33780 K> > sleepq_add() at sleepq_add+0x34f/frame 0xfffffe0072337d0 K> > _sleep() at _sleep+0x28d/frame 0xfffffe0072e33870 K> > soclose() at soclose+0xda/frame 0xfffffe0072e338b0 K> > _fdrop() at _fdrop+0x1a/frame 0xfffffe0072e338d0 K> > sendfile_iodone() at sendfile_iodone+0x19d/frame 0xfffffe0072e33910 K> > vnode_pager_generic_getpages_done_async() at vnode_pager_generic_getpages_done_async+037/frame 0xfffffe0072e33930 K> > bufdone() at bufdone+0x64/frame 0xfffffe0072e33960 K> > g_io_deliver() at g_io_deliver+0x276/frame 0xfffffe0072e339b0 K> > g_io_deliver() at g_io_deliver+0x276/frame 0xfffffe0072e33a00 K> > g_disk_done() at g_disk_done+0x104/frame 0xfffffe0072e33a40 K> > xpt_done_process() at xpt_done_process+0x35f/frame 0xfffffe0072e33a80 K> > xpt_done_direct() at ahci_ch_intr_direct+0xd5/frame 0xfffffe0072e33af0 K> > ahci_itr() at ahci_intr+0x102/frame 0xfffffe0072e33b20 K> > intr_event_execute_handlers() at intr_event_execute_handlers+0x99/frame 0xfffffe0072e33b60 K> > ithread_loop() at ithread_loop+0xb6/frame 0xfffffe0072e33bb0 K> > fork_exit() at fork_exit+0x84/frame 0xfffffe0072e33bf0 K> > fork_trampoline() at fork_trampoline+0xe/frame 0xfffffe0072e33bf0 K> > --- trap 0, rip = 0, rsp = 0, rbp = 0 --- K> > KDB: enter: panic K> > [ thread pid 12 tid 100038 ] K> > Stopped at      kdb_enter+0x3b: movq    $0,kdb_why K> > db> K> K> Indeed, the context where sendfile_iodone() is executed, cannot call fdrop(). Can you please test the attached patch? -- Totus tuus, Glebius. --ibvzjYYg+QDzMCy1 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="sendfile_sleep.diff" Index: sys/kern/kern_sendfile.c =================================================================== --- sys/kern/kern_sendfile.c (revision 315926) +++ sys/kern/kern_sendfile.c (working copy) @@ -296,8 +296,9 @@ sendfile_iodone(void *arg, vm_page_t *pg, int coun CURVNET_RESTORE(); } - /* XXXGL: curthread */ - fdrop(sfio->sock_fp, curthread); + ACCEPT_LOCK(); + SOCK_LOCK(so); + sorele(so); free(sfio, M_TEMP); } @@ -860,7 +861,9 @@ prepend_header: } else { sfio->sock_fp = sock_fp; sfio->npages = npages; - fhold(sock_fp); + SOCK_LOCK(so); + soref(so); + SOCK_UNLOCK(so); error = (*so->so_proto->pr_usrreqs->pru_send) (so, PRUS_NOTREADY, m, NULL, NULL, td); sendfile_iodone(sfio, NULL, 0, 0); --ibvzjYYg+QDzMCy1--