From tegge@trondheim.fast.no  Sat Nov 18 10:16:34 2000
Return-Path: <tegge@trondheim.fast.no>
Received: from innenfor.trondheim.fast.no (ext-gw.trd.fast.no [213.188.8.2])
	by hub.freebsd.org (Postfix) with ESMTP id 4350037B479
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 18 Nov 2000 10:16:33 -0800 (PST)
Received: from not.trondheim.fast.no (not.trondheim.fast.no [192.168.8.12])
	by innenfor.trondheim.fast.no (8.9.3/8.9.3) with ESMTP id TAA61637
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 18 Nov 2000 19:16:31 +0100 (CET)
	(envelope-from tegge@not.trondheim.fast.no)
Received: (from tegge@localhost)
	by not.trondheim.fast.no (8.11.1/8.8.8) id eAIIGVH00724;
	Sat, 18 Nov 2000 19:16:31 +0100 (CET)
	(envelope-from tegge@not.trondheim.fast.no)
Message-Id: <200011181816.eAIIGVH00724@not.trondheim.fast.no>
Date: Sat, 18 Nov 2000 19:16:31 +0100 (CET)
From: tegge@trondheim.fast.no
Reply-To: tegge@trondheim.fast.no
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: isa_dmainit fails on machines with 512MB memory or more
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         22944
>Category:       i386
>Synopsis:       [vm] [patch] isa_dmainit fails on machines with 512MB memory or more
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    alc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 18 10:20:01 PST 2000
>Closed-Date:    Thu Feb 17 20:00:07 UTC 2011
>Last-Modified:  Thu Feb 17 20:00:07 UTC 2011
>Originator:     Tor Egge
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Fast Search & Transfer ASA
>Environment:
System: FreeBSD not.trondheim.fast.no 5.0-CURRENT FreeBSD 5.0-CURRENT #9: Sat Nov 18 18:29:33 CET 2000 root@not.trondheim.fast.no:/usr/src/sys/compile/NOT_SMP i386

>Description:

On machines with lots of memory (>= 512 MB), all of the ISA memory might be
allocated before the device probes has completed.  This causes ISA devices to
fail during DMA buffer allocation:

 isa_probe_children: probing non-PnP devices
 fdc0: <NEC 72065B or clone> at port 0x3f0-0x3f5,0x3f7 irq 6 drq 2 on isa0
 isa_dmainit(2, 1024) failed
 fdc0: FIFO enabled, 8 bytes threshold
 fd0: <1440-KB 3.5" drive> on fdc0 drive 0

The ISA memory has been used by

	kernel text, data, bss
	arrays allocated by vm_page_startup()
	memory allocated via kmem_alloc()
	memory allocated via malloc() with M_ZERO

Printing the number of free ISA memory pages at the end of vm_mem_init() showed
that with 512 MB memory and a standard kernel, only 165 pages were available at
that time.  Later during probing, the floppy driver failed to allocate ISA
memory.

Attempts to access the floppy device causes an instant panic:

not# dd if=/dev/rfd0a of=/dev/null bs=512 count=1
panic: isa_dmastart: bad bounce buffer

syncing disks... 1 1 

>How-To-Repeat:

Use the floppy device on a -current machine with 512 MB or more memory.

>Fix:

Ensure that the largest memory region described by phys_avail[] doesn't
contain the ISA memory.  This increases the number of free ISA pages 
at end of vm_mem_init() from 165 to 2341.

Change vm_add_new_page to alternate between adding to the head and the
tail of the page queues.  This further increases the number of free ISA 
pages at end of vm_mem_init() from 2341 to 2789.

Index: sys/i386/i386/machdep.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/machdep.c,v
retrieving revision 1.420
diff -u -r1.420 machdep.c
--- sys/i386/i386/machdep.c	2000/10/27 11:45:23	1.420
+++ sys/i386/i386/machdep.c	2000/11/18 18:09:15
@@ -120,6 +120,8 @@
 #include <sys/ptrace.h>
 #include <machine/sigframe.h>
 
+#include	"isa.h"
+
 extern void init386 __P((int first));
 extern void dblfault_handler __P((void));
 
@@ -1807,6 +1811,31 @@
 	phys_avail[pa_indx] -= round_page(MSGBUF_SIZE);
 
 	avail_end = phys_avail[pa_indx];
+
+#if NISA > 0
+#define ISA_MEM_END (16 * 1024 * 1024)
+#define ISA_MEM_CONSERVELIM (128 * 1024 * 1024)
+	if (pa_indx + 2 < PHYS_AVAIL_ARRAY_END) {
+		for (i = pa_indx; i >= 1; i -= 2)
+			if (phys_avail[i - 1] < ISA_MEM_END &&
+			    phys_avail[i] > ISA_MEM_CONSERVELIM)
+				break;
+		if (i >= 1) {
+			phys_avail[pa_indx + 4] = 0;
+			phys_avail[pa_indx + 3] = 0;
+			for (i = pa_indx; i >= 1; i-= 2) {
+				phys_avail[i + 2] = phys_avail[i];
+				phys_avail[i + 1] = phys_avail[i -1];
+				if (phys_avail[i - 1] < ISA_MEM_END &&
+				    phys_avail[i] > ISA_MEM_CONSERVELIM) {
+					phys_avail[i + 1] = ISA_MEM_END;
+					phys_avail[i] = ISA_MEM_END;
+					break;
+				}
+			}
+		}
+	}
+#endif
 }
 
 void
@@ -1943,7 +1972,6 @@
 	 */
 	cninit();
 
-#include	"isa.h"
 #if	NISA >0
 	isa_defaultirq();
 #endif
Index: sys/vm/vm_page.c
===================================================================
RCS file: /home/ncvs/src/sys/vm/vm_page.c,v
retrieving revision 1.153
diff -u -r1.153 vm_page.c
--- sys/vm/vm_page.c	2000/07/04 04:32:40	1.153
+++ sys/vm/vm_page.c	2000/11/18 17:29:30
@@ -161,7 +163,10 @@
 	m->flags = 0;
 	m->pc = (pa >> PAGE_SHIFT) & PQ_L2_MASK;
 	m->queue = m->pc + PQ_FREE;
-	TAILQ_INSERT_HEAD(&vm_page_queues[m->queue].pl, m, pageq);
+	if (((pa >> PAGE_SHIFT) & 1) == 0)
+		TAILQ_INSERT_HEAD(&vm_page_queues[m->queue].pl, m, pageq);
+	else
+		TAILQ_INSERT_TAIL(&vm_page_queues[m->queue].pl, m, pageq);
 	vm_page_queues[m->queue].lcnt++;
 	return (m);
 }

>Release-Note:
>Audit-Trail:

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: tegge@trondheim.fast.no
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: i386/22944: isa_dmainit fails on machines with 512MB memory or more 
Date: Sat, 18 Nov 2000 23:00:39 +0100

 Thanks!  I can confirm this one, with only 384 MB RAM.
 
 >Attempts to access the floppy device causes an instant panic:
 >
 >not# dd if=/dev/rfd0a of=/dev/null bs=512 count=1
 >panic: isa_dmastart: bad bounce buffer
 
 We need somebody to hunt down that bug too.  We shouldn't panic
 unless there is nothing else we can do.
 
 --
 Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
 phk@FreeBSD.ORG         | TCP/IP since RFC 956
 FreeBSD committer       | BSD since 4.3-tahoe    
 Never attribute to malice what can adequately be explained by incompetence.
 
State-Changed-From-To: open->feedback 
State-Changed-By: iedowse 
State-Changed-When: Sun Apr 17 22:24:13 GMT 2005 
State-Changed-Why:  

Is this PR still relevant? 


Responsible-Changed-From-To: freebsd-bugs->tegge 
Responsible-Changed-By: iedowse 
Responsible-Changed-When: Sun Apr 17 22:24:13 GMT 2005 
Responsible-Changed-Why:  

Assign to submitter. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22944 

From: dpk <dpk@dpk.net>
To: bug-followup@FreeBSD.org, tegge@trondheim.fast.no
Cc:  
Subject: Re: i386/22944: isa_dmainit fails on machines with 512MB memory or
 more
Date: Wed, 8 Jun 2005 10:32:28 -0700 (PDT)

 Yes, this PR still appears to be relevant. FreeBSD 5.4-RELEASE, when
 installing from the 3-floppy set (well, 4..), gives the isa_dmainit error
 before eventually panicing the server when it tries to use an isa bounce
 buffer. This is with 2GB of RAM in a modern P4 server (SuperMicro board).
 
 Have not been able to get 5.4-RELEASE installed due to this and possibly
 other issues, so I don't know if it can be fixed with a kernel config
 modification.

From: dpk <dpk@dpk.net>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: i386/22944: isa_dmainit fails on machines with 512MB memory or
 more
Date: Wed, 8 Jun 2005 10:35:07 -0700 (PDT)

 As it's been 4.5 years, email addresses change. The submitter address
 "tegge@trondheim.fast.no" now bounces. May want to update that so we can
 get this bug resolved.
State-Changed-From-To: feedback->suspended 
State-Changed-By: linimon 
State-Changed-When: Sun Oct 23 18:33:56 GMT 2005 
State-Changed-Why:  
Feedback was received some time ago.  Mark as 'suspended' since nothing 
seems to have happened on this in a while. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22944 
State-Changed-From-To: suspended->patched 
State-Changed-By: alc 
State-Changed-When: Thu Nov 22 21:44:17 UTC 2007 
State-Changed-Why:  
This should be fixed by the new physical memory allocator 
in RELENG_7 and beyond.  However, I cannot foresee an MFC 
to earlier branches. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22944 
Responsible-Changed-From-To: tegge->alc 
Responsible-Changed-By: remko 
Responsible-Changed-When: Sun Dec 9 20:36:58 UTC 2007 
Responsible-Changed-Why:  
reassign to alc, who committed the update to -current and releng_7 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22944 
State-Changed-From-To: patched->suspended 
State-Changed-By: linimon 
State-Changed-When: Sat Jan 26 15:04:33 UTC 2008 
State-Changed-Why:  
With bugmeister hat on, mark this one as suspended. 

The problem has been fixed by a rewrite in FreeBSD 7.X, but no MFC to 
6 is planned.  If someone is interested in trying to pick up the 
original patch from this and apply it to RELENG_6, it is worth 
keeping this PR around.  Otherwise, the correct response is probably 
to tell prospective users to consider upgrading to 7.0. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22944 
State-Changed-From-To: suspended->closed 
State-Changed-By: brucec 
State-Changed-When: Thu Feb 17 19:59:31 UTC 2011 
State-Changed-Why:  
Fixed in all supported releases. 

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