From nobody@FreeBSD.org  Wed Feb 20 14:30:56 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 5B91716A401
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Feb 2008 14:30:56 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 44A0913C45B
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Feb 2008 14:30:56 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m1KESNZY005034
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Feb 2008 14:28:23 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m1KESNdO005033;
	Wed, 20 Feb 2008 14:28:23 GMT
	(envelope-from nobody)
Message-Id: <200802201428.m1KESNdO005033@www.freebsd.org>
Date: Wed, 20 Feb 2008 14:28:23 GMT
From: Tobias Mohrlueder <mail@tobiasmo.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: bktr driver always stores the contigmalloc'ed memory pointers
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         120884
>Category:       kern
>Synopsis:       [bktr] [patch] bktr driver always stores the contigmalloc'ed memory pointers
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 20 14:40:02 UTC 2008
>Closed-Date:    
>Last-Modified:  Wed Feb 20 21:05:19 UTC 2008
>Originator:     Tobias Mohrlueder
>Release:        RELENG_7
>Organization:
>Environment:
FreeBSD acheron.local.lan 7.0-PRERELEASE FreeBSD 7.0-PRERELEASE #0: Fri Feb  8 19:54:00 CET 2008 tobiasmo@acheron.local.lan:/usr/obj/usr/src/sys/ACHERON  i386
>Description:
While building world on my machine, I experienced a problem with the bktr
driver module. One contigmalloc() call failed and as a result, the module
was left in a defective state. Any further load attempts were futile,
because the bktr memory loader cannot be unloaded (and the driver keeps
thinking that there already is enough memory allocated).

From /var/log/messages:
Jan 15 17:01:13 acheron kernel: bktr0: Unable to allocate 3555328 bytes of memory.

bktr_mem.c's sole purpose is to avoid the situation of having to
contigmalloc() memory everytime the bktr module is loaded, so maybe this
is a known "problem" and the solution is to load the module at boot time.
>How-To-Repeat:
Although not an exact guide how to repeat the problem;

1) Put the machine under load (e.g. make buildworld)

2) kldload bktr
>Fix:
Load the module at boot time.

Or: Maybe the attached patch helps. It looks like a trivial problem, but
I am not a seasoned programmer.

Patch attached with submission follows:

--- /usr/src/sys/dev/bktr/bktr_core.c	2005-12-04 11:06:03.000000000 +0100
+++ bktr_core.c	2008-02-19 17:15:01.000000000 +0100
@@ -528,11 +528,17 @@
 
 /* If this is a module, save the current contiguous memory */
 #if defined(BKTR_FREEBSD_MODULE)
-bktr_store_address(unit, BKTR_MEM_DMA_PROG,     bktr->dma_prog);
-bktr_store_address(unit, BKTR_MEM_ODD_DMA_PROG, bktr->odd_dma_prog);
-bktr_store_address(unit, BKTR_MEM_VBIDATA,      bktr->vbidata);
-bktr_store_address(unit, BKTR_MEM_VBIBUFFER,    bktr->vbibuffer);
-bktr_store_address(unit, BKTR_MEM_BUF,          buf);
+
+	/* Only save when all relevant get_bktr_mem() calls succeeded */
+	if ( bktr->dma_prog != 0 && bktr->odd_dma_prog != 0 &&
+	     bktr->vbidata != 0 && bktr->vbibuffer != 0 &&
+	     ( BROOKTREE_ALLOC ? buf != 0 : 1 ) ) {
+		bktr_store_address(unit, BKTR_MEM_DMA_PROG,     bktr->dma_prog);
+		bktr_store_address(unit, BKTR_MEM_ODD_DMA_PROG, bktr->odd_dma_prog);
+		bktr_store_address(unit, BKTR_MEM_VBIDATA,      bktr->vbidata);
+		bktr_store_address(unit, BKTR_MEM_VBIBUFFER,    bktr->vbibuffer);
+		bktr_store_address(unit, BKTR_MEM_BUF,          buf);
+	}
 #endif
 
 


>Release-Note:
>Audit-Trail:
>Unformatted:
