From owner-freebsd-current@FreeBSD.ORG Tue Sep 14 01:10:17 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A73641065670 for ; Tue, 14 Sep 2010 01:10:17 +0000 (UTC) (envelope-from freebsd-current@m.gmane.org) Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mx1.freebsd.org (Postfix) with ESMTP id 63E6C8FC1B for ; Tue, 14 Sep 2010 01:10:17 +0000 (UTC) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OvK2I-000696-BH for freebsd-current@freebsd.org; Tue, 14 Sep 2010 03:10:14 +0200 Received: from k.saper.info ([91.121.151.35]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 14 Sep 2010 03:10:14 +0200 Received: from saper by k.saper.info with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 14 Sep 2010 03:10:14 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: freebsd-current@freebsd.org From: Marcin Cieslak Date: Tue, 14 Sep 2010 01:10:01 +0000 (UTC) Organization: http://saper.info Lines: 36 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: k.saper.info User-Agent: slrn/0.9.9p1 (FreeBSD) X-Mailman-Approved-At: Tue, 14 Sep 2010 02:02:11 +0000 Subject: tun(4) in -CURRENT: No buffer space available - race condition patch X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 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, 14 Sep 2010 01:10:17 -0000 Output queue of tun(4) gets full after some time when sending lots of data. I have been observing this on -CURRENT at least since March this year. Looks like it's a race condition (same in tun(4) and tap(4)), the following patch seems to address the issue: Index: if_tap.c =================================================================== --- if_tap.c (revision 212217) +++ if_tap.c (working copy) @@ -881,8 +881,7 @@ mtx_lock(&tp->tap_mtx); tp->tap_flags |= TAP_RWAIT; - mtx_unlock(&tp->tap_mtx); - error = tsleep(tp,PCATCH|(PZERO+1),"taprd",0); + error = mtx_sleep(tp, &tp->tap_mtx, PDROP|PCATCH|(PZERO+1), "taprd", 0); if (error) return (error); } Index: if_tun.c =================================================================== --- if_tun.c (revision 212217) +++ if_tun.c (working copy) @@ -836,8 +836,7 @@ } mtx_lock(&tp->tun_mtx); tp->tun_flags |= TUN_RWAIT; - mtx_unlock(&tp->tun_mtx); - if ((error = tsleep(tp, PCATCH | (PZERO + 1), + if ((error = mtx_sleep(tp, &tp->tun_mtx, PDROP | PCATCH | (PZERO + 1), "tunread", 0)) != 0) { splx(s); return (error); --Marcin