Bug 81301

Summary: problems with new "contigmalloc" routine
Product: Base System Reporter: Hans Petter Selasky <hselasky>
Component: kernAssignee: Alan Cox <alc>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 6.0-CURRENT   
Hardware: Any   
OS: Any   

Description Hans Petter Selasky 2005-05-20 12:30:11 UTC
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

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.
Comment 1 dfilter service freebsd_committer freebsd_triage 2007-04-19 06:40:00 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"
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2007-07-05 22:22:50 UTC
State Changed
From-To: open->patched

It seems a patch has already been committed and is awaiting MFC. 


Comment 3 Mark Linimon freebsd_committer freebsd_triage 2007-07-05 22:22:50 UTC
Responsible Changed
From-To: freebsd-bugs->alc
Comment 4 Alan Cox freebsd_committer freebsd_triage 2007-07-19 23:48:39 UTC
State Changed
From-To: patched->closed

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.