NetBSD Problem Report #18789

Received: (qmail 21439 invoked by uid 605); 24 Oct 2002 10:53:40 -0000
Message-Id: <200210241041.g9OAfmB00498@k2.vaasje.org>
Date: Thu, 24 Oct 2002 12:41:48 +0200 (CEST)
From: fvdl@wasabisystems.com
Sender: gnats-bugs-owner@netbsd.org
Reply-To: fvdl@wasabisystems.com
To: gnats-bugs@gnats.netbsd.org
Subject: amap_lookups panic after uvm_map changes
X-Send-Pr-Version: 3.95

>Number:         18789
>Category:       kern
>Synopsis:       amap_lookups panic after uvm_map changes
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    atatat
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 24 10:54:00 +0000 2002
>Closed-Date:    Thu Oct 24 20:50:27 +0000 2002
>Last-Modified:  Thu Oct 24 20:50:27 +0000 2002
>Originator:     Frank van der Linden
>Release:        NetBSD 1.6J
>Organization:
poor
>Environment:
System: NetBSD k2 1.6J NetBSD 1.6J (K2) #1: Thu Oct 24 12:26:27 CEST 2002 fvdl@k2:/work/trees/current/sys/arch/i386/compile/K2 i386
Architecture: i386
Machine: i386
>Description:
	A certain series of events makes the kernel panic with the following
	trace (which is unfortunately not very interesting):

panic: amap_lookups: offset out of range
Stopped in pid 467 (java_vm) at cpu_Debugger+0x4:       leave
db{1}> 
db{1}> t
cpu_Debugger(e64ded18,8,3,0,e6361448) at cpu_Debugger+0x4
panic(c0333ea0,1,e64bee40,c0208138,e647e2c8) at panic+0xad
amap_lookups(e647e2f8,49000,e64beef4,8,e64ded18,c0334d80,2cf,0) at amap_lookups+0x51
uvm_fault(e636138c,4fd7c000,0,2,0) at uvm_fault+0x3b8
trap() at trap+0x5aa
--- trap (number 6) ---
0x4825d29d:

>How-To-Repeat:
	Install the netscape7 pkg (Linux binary), including Java support.
	Relevant packages:

suse_base-7.3       Linux compatibility package
suse_x11-7.3        Linux compatibility package for X11 binaries
suse_gtk-7.3        Linux compatibility package for GTK binaries
netscape7-0nb2      Netscape Browser/Mail- and Newsreader suite version 7

	Start the browser.
	Open http://news.bbc.co.uk/
	When you get to the main page, watch the crash.
>Fix:
	Reverting to uvm_map.c revision 1.120 prevents the panic.
>Release-Note:
>Audit-Trail:

From: enami tsugutomo <enami@sm.sony.co.jp>
To: fvdl@wasabisystems.com
Cc: gnats-bugs@gnats.netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: kern/18789: amap_lookups panic after uvm_map changes
Date: 24 Oct 2002 20:34:03 +0900

 fvdl@wasabisystems.com writes:

 > panic: amap_lookups: offset out of range
 	:
 > >Fix:
 > 	Reverting to uvm_map.c revision 1.120 prevents the panic.

 If the merge was bi-merge, and the prev_entry has amap, need to extend
 amap again?

 enami.

From: Andrew Brown <atatat@atatdot.net>
To: enami tsugutomo <enami@sm.sony.co.jp>
Cc: fvdl@wasabisystems.com, gnats-bugs@gnats.netbsd.org,
  netbsd-bugs@netbsd.org
Subject: Re: kern/18789: amap_lookups panic after uvm_map changes
Date: Thu, 24 Oct 2002 09:01:10 -0400

 >> panic: amap_lookups: offset out of range
 >	:
 >> >Fix:
 >> 	Reverting to uvm_map.c revision 1.120 prevents the panic.
 >
 >If the merge was bi-merge, and the prev_entry has amap, need to extend
 >amap again?

 bimerge only currently occurs in the kernel, where no amaps are
 involved.

 entries involving amaps aren't forward (or bi) merged, only possibly
 back merged.

 -- 
 |-----< "CODE WARRIOR" >-----|
 codewarrior@daemon.org             * "ah!  i see you have the internet
 twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
 werdna@squooshy.com       * "information is power -- share the wealth."

From: enami tsugutomo <enami@but-b.or.jp>
To: Andrew Brown <atatat@atatdot.net>
Cc: fvdl@wasabisystems.com, gnats-bugs@gnats.netbsd.org,
  netbsd-bugs@netbsd.org
Subject: Re: kern/18789: amap_lookups panic after uvm_map changes
Date: Thu, 24 Oct 2002 22:42:33 +0900 (JST)

 > bimerge only currently occurs in the kernel, where no amaps are
 > involved.

 Doesn't it occur theoretically, or just stat counter doesn't count up?

 > entries involving amaps aren't forward (or bi) merged, only possibly
 > back merged.

 I can read the code that forwared merge won't occur if next entry has
 amap, but can't find the code to inhibit bimerge when prev_entry has
 amap.

 enami.
 Index: uvm_map.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/uvm/uvm_map.c,v
 retrieving revision 1.121
 diff -u -r1.121 uvm_map.c
 --- uvm_map.c	2002/10/18 13:18:42	1.121
 +++ uvm_map.c	2002/10/24 13:35:58
 @@ -776,11 +776,10 @@
  				UVMCNT_DECR(map_kbackmerge);
  				UVMCNT_INCR(map_kbimerge);
  			} else {
 -				UVMCNT_DECR(map_kbackmerge);
 -				UVMCNT_INCR(map_kbimerge);
 +				UVMCNT_DECR(map_ubackmerge);
 +				UVMCNT_INCR(map_ubimerge);
  			}
 -		}
 -		else {
 +		} else {
  			if (kmap)
  				UVMCNT_INCR(map_kforwmerge);
  			else

From: Andrew Brown <atatat@atatdot.net>
To: enami tsugutomo <enami@but-b.or.jp>
Cc: fvdl@wasabisystems.com, gnats-bugs@gnats.netbsd.org,
  netbsd-bugs@netbsd.org
Subject: Re: kern/18789: amap_lookups panic after uvm_map changes
Date: Thu, 24 Oct 2002 10:31:53 -0400

 >> bimerge only currently occurs in the kernel, where no amaps are
 >> involved.
 >
 >Doesn't it occur theoretically, or just stat counter doesn't count up?

 currently, since amaps are not extended *backwards*, there's no way to
 merge a new entry forwards with an existing entry *if* the following
 entry is backed by an amap.  a bimerge is simply a new allocation that
 filled the gap between two existing allocations.  plain forward merges
 actually occur rather infrequently.

 since kernels don't use amaps, only object references to the kernel
 object, forward merges (which are usually bimerges) can occur there.

 regular applications typically don't make allocations that are
 candidates for forward merges (ie, user space allocations usually
 proceed in a forwards direction, are usually backed by amaps, and thus
 only incur backmerges).

 >> entries involving amaps aren't forward (or bi) merged, only possibly
 >> back merged.
 >
 >I can read the code that forwared merge won't occur if next entry has
 >amap, but can't find the code to inhibit bimerge when prev_entry has
 >amap.

 bimerge is simply a backmerge followed by a forward merge.  the
 backward merge probably occurs happily, and then the forward merge
 fails because the following entry has an amap (if it has nothing
 backing it, it will actually succeed, but this is exceedingly rare).

 take a look at the stats i gathered over a period of three days at

 	http://www.graffiti.com/uvm.html

 the userspace forward merges and forward merge failures indicated
 there were all incurred by a program i specifically wrote to exercise
 that code path.  note that no bimerges occurred.

 >Index: uvm_map.c
 >===================================================================
 >RCS file: /cvsroot/syssrc/sys/uvm/uvm_map.c,v
 >retrieving revision 1.121
 >diff -u -r1.121 uvm_map.c
 >--- uvm_map.c	2002/10/18 13:18:42	1.121
 >+++ uvm_map.c	2002/10/24 13:35:58
 >@@ -776,11 +776,10 @@
 > 				UVMCNT_DECR(map_kbackmerge);
 > 				UVMCNT_INCR(map_kbimerge);
 > 			} else {
 >-				UVMCNT_DECR(map_kbackmerge);
 >-				UVMCNT_INCR(map_kbimerge);
 >+				UVMCNT_DECR(map_ubackmerge);
 >+				UVMCNT_INCR(map_ubimerge);
 > 			}


 ah.  good point.  thanks.

 >-		}
 >-		else {
 >+		} else {
 > 			if (kmap)
 > 				UVMCNT_INCR(map_kforwmerge);
 > 			else

 heh.  style nits.  cool.

 -- 
 |-----< "CODE WARRIOR" >-----|
 codewarrior@daemon.org             * "ah!  i see you have the internet
 twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
 werdna@squooshy.com       * "information is power -- share the wealth."

From: enami tsugutomo <enami@but-b.or.jp>
To: Andrew Brown <atatat@atatdot.net>
Cc: fvdl@wasabisystems.com, gnats-bugs@gnats.netbsd.org,
  netbsd-bugs@netbsd.org
Subject: Re: kern/18789: amap_lookups panic after uvm_map changes
Date: Thu, 24 Oct 2002 23:52:41 +0900 (JST)

 > currently, since amaps are not extended *backwards*, there's no way to
 > merge a new entry forwards with an existing entry *if* the following
 > entry is backed by an amap.  a bimerge is simply a new allocation that
 > filled the gap between two existing allocations.  plain forward merges
 > actually occur rather infrequently.

 Suppose following case:

 prev_entry wi/ amap | gap will be filled by new entry | next_entry w/o amap 

 	   A			  B				   C

 The resulting entry covers A+B+C but amap only covers A+B, doesn't it?

 enami.

From: Andrew Brown <atatat@atatdot.net>
To: enami tsugutomo <enami@but-b.or.jp>
Cc: fvdl@wasabisystems.com, gnats-bugs@gnats.netbsd.org,
  netbsd-bugs@netbsd.org
Subject: Re: kern/18789: amap_lookups panic after uvm_map changes
Date: Thu, 24 Oct 2002 11:40:48 -0400

 >> currently, since amaps are not extended *backwards*, there's no way to
 >> merge a new entry forwards with an existing entry *if* the following
 >> entry is backed by an amap.  a bimerge is simply a new allocation that
 >> filled the gap between two existing allocations.  plain forward merges
 >> actually occur rather infrequently.
 >
 >Suppose following case:
 >
 >prev_entry wi/ amap | gap will be filled by new entry | next_entry w/o amap 
 >
 >	   A			  B				   C
 >
 >The resulting entry covers A+B+C but amap only covers A+B, doesn't it?

 an excellent idea!  let me try it out...

 -- 
 |-----< "CODE WARRIOR" >-----|
 codewarrior@daemon.org             * "ah!  i see you have the internet
 twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
 werdna@squooshy.com       * "information is power -- share the wealth."

From: Andrew Brown <atatat@atatdot.net>
To: enami tsugutomo <enami@but-b.or.jp>
Cc: fvdl@wasabisystems.com, gnats-bugs@gnats.netbsd.org,
  netbsd-bugs@netbsd.org
Subject: Re: kern/18789: amap_lookups panic after uvm_map changes
Date: Thu, 24 Oct 2002 12:07:21 -0400

 >>Suppose following case:
 >>
 >>prev_entry wi/ amap | gap will be filled by new entry | next_entry w/o amap 
 >>
 >>	   A			  B				   C
 >>
 >>The resulting entry covers A+B+C but amap only covers A+B, doesn't it?
 >
 >an excellent idea!  let me try it out...

 wonderful.  this program:

 #define BASE ((void*)0x80000000)
 #define PAGE 4096
 int
 main(int argc, char *argv[])
 {
 	int *a, *b, *c;
 	/* allocate the "first" page */
 	a = mmap(BASE + 0 * PAGE, PAGE, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
 	/* cause it to be backed by an amap */
 	a[0] = 1;
 	/* allocate the "last" page */
 	c = mmap(BASE + 2 * PAGE, PAGE, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
 	/* allocate the "middle" page, which gets bimerged */
 	b = mmap(BASE + 1 * PAGE, PAGE, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
 	/* die, you gravy sucking pig dog */
 	c[0] = 1;
 }

 will cause the same problem.  patch forthcoming.  thanks.  :)

 -- 
 |-----< "CODE WARRIOR" >-----|
 codewarrior@daemon.org             * "ah!  i see you have the internet
 twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
 werdna@squooshy.com       * "information is power -- share the wealth."

From: Andrew Brown <atatat@netbsd.org>
To: gnats-bugs@gnats.netbsd.org
Cc:  
Subject: pr/18789 CVS commit: syssrc/sys/uvm
Date: Thu, 24 Oct 2002 23:38:01 +0300 (EEST)

 Module Name:	syssrc
 Committed By:	atatat
 Date:		Thu Oct 24 20:38:00 UTC 2002

 Modified Files:
 	syssrc/sys/uvm: uvm_map.c

 Log Message:
 Call amap_extend() a second time in the case of a bimerge (both
 backwards and forwards) if the previous entry was backed by an amap.

 Fixes pr kern/18789, where netscape 7 + a java applet actually manage
 to incur forward and bimerges in userspace.

 Code reviewed by fvdl and thorpej.


 To generate a diff of this commit:
 cvs rdiff -r1.121 -r1.122 syssrc/sys/uvm/uvm_map.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed 
State-Changed-By: atatat 
State-Changed-When: Thu Oct 24 13:49:08 PDT 2002 
State-Changed-Why:  
the bug has been fixed, along with incorporating enami's suggested tweaks. 


Responsible-Changed-From-To: kern-bug-people->atatat 
Responsible-Changed-By: atatat 
Responsible-Changed-When: Thu Oct 24 13:49:08 PDT 2002 
Responsible-Changed-Why:  
the problem was in my code, and i've fixed it (with enami's help, for which 
i am very grateful). 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.