From hselasky@c2i.net  Fri May 20 11:25:26 2005
Return-Path: <hselasky@c2i.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id 7766016A4CE; Fri, 20 May 2005 11:25:26 +0000 (GMT)
Received: from swip.net (mailfe05.swip.net [212.247.154.129])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id 9B0A943D83; Fri, 20 May 2005 11:25:24 +0000 (GMT)
	(envelope-from hselasky@c2i.net)
Received: from mp-217-203-10.daxnet.no ([193.217.203.10] verified)
  by mailfe05.swip.net (CommuniGate Pro SMTP 4.3c5)
  with ESMTP id 174532189; Fri, 20 May 2005 13:23:15 +0200
Message-Id: <200505201324.03820.hselasky@c2i.net>
Date: Fri, 20 May 2005 13:24:02 +0200
From: Hans Petter Selasky <hselasky@c2i.net>
Reply-To: hselasky@c2i.net
To: FreeBSD-gnats-submit@freebsd.org, imp@freebsd.org
Subject: problems with new "contigmalloc" routine

>Number:         81301
>Category:       kern
>Synopsis:       problems with new "contigmalloc" routine
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    alc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 20 11:30:11 GMT 2005
>Closed-Date:    Thu Jul 19 22:55:57 GMT 2007
>Last-Modified:  Thu Jul 19 22:55:57 GMT 2007
>Originator:     HPS
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD 6.0-CURRENT FreeBSD 6.0-CURRENT #149: Tue May 10 20:43:15 CEST 
2005 root@:/usr/obj/usr/src/sys/custom i386

>Description:

The new "contigmalloc" routine have got three problems. First it locks Giant, 
which will cause lock order reversal problems. Secondly it sleeps even if 
flag M_NOWAIT is passed. Thirdly flag M_ZERO does not have any effect. 

1st problem:

May 20 12:33:44  kernel: lock order reversal
May 20 12:33:44  kernel: 1st 0xc175a6c8 ugen lock (ugen lock) 
@ /usr/mnt3/src/sys/dev/usb2/_ugen.c:1452
May 20 12:33:44  kernel: 2nd 0xc09bdde0 Giant (Giant) 
@ /usr/mnt3/src/sys/vm/vm_contig.c:550
May 20 12:33:44  kernel: KDB: stack backtrace:
May 20 12:33:44  kernel: witness_checkorder(c09bdde0,9,c08e34af,226) at 
witness_checkorder+0x50c
May 20 12:33:44  kernel: _mtx_lock_flags(c09bdde0,0,c08e34af,226,8) at 
_mtx_lock_flags+0x40
May 20 12:33:44  kernel: contigmalloc(184ec,c0952c60,1,0,ffffffff) at 
contigmalloc+0x45
May 20 12:33:44  kernel: bus_dmamem_alloc(c1aacc00,d4cd7974,5,d4cd7978) at 
bus_dmamem_alloc+0x61
May 20 12:33:44  kernel: usb_alloc_mem(184e0,4,8,8,d4164ae4) at 
usb_alloc_mem+0x53

2nd problem:

May 20 12:33:44  kernel: malloc(M_WAITOK) of "g_bio", forcing M_NOWAIT with 
the following non-sleepable locks held:
May 20 12:33:44  kernel: exclusive sleep mutex ugen lock r = 0 (0xc175a6c8) 
locked @ /usr/mnt3/src/sys/dev/usb2/_ugen.c:1452
May 20 12:33:44  kernel: KDB: stack backtrace:
May 20 12:33:46  kernel: witness_warn(5,0,c08e3022,c08c3c87) at 
witness_warn+0x1a8
May 20 12:33:46  kernel: uma_zalloc_arg(c103dc60,0,102) at uma_zalloc_arg+0x4b
May 20 12:33:46  kernel: g_allotpages(c1af918c,d4cd783c,1,1,d4cd7800) at 
swap_pager_putpages+0x413
May 20 12:33:46  kernel: vm_pageout_flush(d4cd783c,1,1,c1460d88,c1461058) at 
vm_pageout_flush+0xf5
May 20 12:33:46  kernel: vm_contig_launder_page(e269,0,c0a0b8d0,ffffffff,f) at 
vm_contig_launder_page+0xa8
May 20 12:33:46  kernel: vm_page_alloc_contig(19,0,0,ffffffff,10) at 
vm_page_alloc_contig+0x204
May 20 12:33:46  kernel: contigmalloc(184ec,c0952c60,1,0,ffffffff) at 
contigmalloc+0x337
May 20 12:33:46  kernel: bus_dmamem_alloc(c1aacc00,d4cd7974,5,d4cd7978) at 
bus_dmamem_alloc+0x61
May 20 12:33:46  kernel: usb_alloc_mem(184e0,4,8,8,d4164ae4) at 
usb_alloc_mem+0x53

>How-To-Repeat:

>Fix:

The flags passed to "contigmalloc" must be passed on, and should not be 
ignored. If unused flags are passed to "contigmalloc", it should warn. 
"Giant" should not be locked during memory allocation.
>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/81301: commit references a PR
Date: Thu, 19 Apr 2007 05:40:00 +0000 (UTC)

 alc         2007-04-19 05:39:54 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/vm               vm_contig.c 
   Log:
   Correct contigmalloc2()'s implementation of M_ZERO.  Specifically,
   contigmalloc2() was always testing the first physical page for PG_ZERO,
   not the current page of interest.
   
   Submitted by: Michael Plass
   PR: 81301
   MFC after: 1 week
   
   Revision  Changes    Path
   1.58      +1 -1      src/sys/vm/vm_contig.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: linimon 
State-Changed-When: Thu Jul 5 21:22:50 UTC 2007 
State-Changed-Why:  
It seems a patch has already been committed and is awaiting MFC. 


Responsible-Changed-From-To: freebsd-bugs->alc 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Jul 5 21:22:50 UTC 2007 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=81301 
State-Changed-From-To: patched->closed 
State-Changed-By: alc 
State-Changed-When: Thu Jul 19 22:48:39 UTC 2007 
State-Changed-Why:  
All three of the issues raised in this PR are addressed by 
the new implementation of contigmalloc(9) that is now in 
HEAD and will appear in FreeBSD 7.0.  Due to the extent of 
the changes, I cannot foresee an MFC to RELENG_6.  However, 
the bug in the implementation of M_ZERO has been corrected 
in RELENG_6. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=81301 
>Unformatted:
