NetBSD Problem Report #11125

Received: (qmail 29176 invoked from network); 4 Oct 2000 00:32:17 -0000
Message-Id: <200010040033.JAA18043@wonder2.aist-nara.ac.jp>
Date: Wed, 4 Oct 2000 09:33:59 +0900 (JST)
From: itohy@netbsd.org (ITOH Yasufumi)
Reply-To: itohy@netbsd.org
To: gnats-bugs@gnats.netbsd.org
Subject: UVM leaves stale vm map hint
X-Send-Pr-Version: 3.95

>Number:         11125
>Category:       kern
>Synopsis:       UVM leaves stale vm map hint
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    thorpej
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 04 00:33:01 +0000 2000
>Closed-Date:    Mon Feb 26 00:54:24 +0000 2001
>Last-Modified:  Mon Feb 26 00:54:24 +0000 2001
>Originator:     ITOH Yasufumi
>Release:        1.5G (Oct. 3, 2000)
>Organization:

>Environment:
System: NetBSD acha.my.domain 1.5G NetBSD 1.5G (ACHA) #58: Tue Oct 3 21:06:48 JST 2000 itohy@pino.my.domain:/usr/src/sys/arch/x68k/compile/ACHA x68k
Machine: X68030, MPU: MC68030 (25MHz), Main memory: 12MB

>Description:
	The UVM may possibly leave stale vm map hint,
	which points at freed vm map entry.

	This causes random crashes and any sort of inconsistency
	in the kernel.
	The 1.4 and 1.5 trees are also affected.

>How-To-Repeat:
	I'm not sure.
	However, fortunately(?), cdrecord-1.9 (pkgsrc/sysutils/cdrecord) pkg
	crashes my x68k in more than 95% probability.

	Here is a script (crash.sh):

	  #! /bin/sh
	  ulimit -d unlimited; ulimit -m unlimited; ulimit -s unlimited
	  cdrecord -dummy -v dev=/dev/rcd0c driver=cdr_simul speed=2 fs=2m -

	You need not have a CD-R drive connected to your machine.
	System crashes before opening the device.
	I think the mlockall(2) call helps the problem to appear.

	# sh crash.sh
	Cdrecord 1.9 (--) Copyright (C) 1995-2000 Jorg Schilling
	TOC-Type: CD-ROM
	uvm_fault(0x15ace4, 0x20620000, 0, 0x1) -> 0x1
	  type 8, code [mmu,,ssw]: 401074d
	trap type 8, code = 0x401074d, v = 0x2062000b
	kernel program counter = 0xf665e
	kernel: MMU fault trap
	pid = 16, pc = 000F665E, ps = 2009, sfc = 1, dfc = 1
	Registers:
	(register dump)

	Kernel stack (006A1D04):
	(stack dump)
	panic: MMU fault
	Stopped in cdrecord at	_cpu_Debugger+0x6:	unlk	a6
	db> t
	_cpu_Debugger(...) + 6
	_panic(...) + 60
	_trap(8,401074d,c50af0b) + 244
	_uvm_map_lookup_entry(665384,ffffa000,6a1efc) + 4e
	_uvm_fault(665384,ffffa000,0,3) + e0
	_trap(8,4020709,ffffafc0) + 55a
	faultstkadj() + 0
	db>

>Fix:
	uvm_map_entry_unlink() deletes an entry from the vm map,
	and if the hint points at the entry, the hint becomes stale.

	Here's a fix.
	I confirmed this case occurs and that this change fixes the problem,
	but I don't know
		whether the locking is necessary,
		whether the "if (map->hint == entry)" is necessary,
		what value should be set to the hint,
		etc...,
	and I'll leave it to the UVM gru.

diff -uF^[a-zA-Z_][a-z 	A-Z0-9_]*([^;]*$ sys/uvm/uvm_map.c.orig sys/uvm/uvm_map.c
--- sys/uvm/uvm_map.c.orig	Thu Sep 14 13:21:17 2000
+++ sys/uvm/uvm_map.c	Wed Oct  4 00:11:55 2000
@@ -1089,6 +1089,13 @@ uvm_unmap_remove(map, start, end, entry_
 		 * that we've nuked.  then go do next entry.
 		 */
 		UVMHIST_LOG(maphist, "  removed map entry 0x%x", entry, 0, 0,0);
+
+		/* critical!  prevents stale hint */
+		simple_lock(&map->hint_lock);
+		if (map->hint == entry)
+			map->hint = entry->prev;
+		simple_unlock(&map->hint_lock);
+
 		uvm_map_entry_unlink(map, entry);
 		map->size -= len;
 		entry->next = first_entry;
>Release-Note:
>Audit-Trail:

From: Jason R Thorpe <thorpej@zembu.com>
To: ITOH Yasufumi <itohy@netbsd.org>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/11125: UVM leaves stale vm map hint
Date: Tue, 3 Oct 2000 19:57:26 -0700

 On Wed, Oct 04, 2000 at 09:33:59AM +0900, ITOH Yasufumi wrote:

  > >Description:
  > 	The UVM may possibly leave stale vm map hint,
  > 	which points at freed vm map entry.

 Wow, good find.

  > >Fix:
  > 	uvm_map_entry_unlink() deletes an entry from the vm map,
  > 	and if the hint points at the entry, the hint becomes stale.
  > 
  > 	Here's a fix.
  > 	I confirmed this case occurs and that this change fixes the problem,
  > 	but I don't know
  > 		whether the locking is necessary,
  > 		whether the "if (map->hint == entry)" is necessary,
  > 		what value should be set to the hint,
  > 		etc...,
  > 	and I'll leave it to the UVM gru.

 No, I think your patch is completely correct, and I am going to commit it.

 -- 
         -- Jason R. Thorpe <thorpej@zembu.com>

From: Jason R Thorpe <thorpej@zembu.com>
To: ITOH Yasufumi <itohy@netbsd.org>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/11125: UVM leaves stale vm map hint
Date: Tue, 3 Oct 2000 20:08:10 -0700

 On Wed, Oct 04, 2000 at 09:33:59AM +0900, ITOH Yasufumi wrote:

  > 	Here's a fix.
  > 	I confirmed this case occurs and that this change fixes the problem,
  > 	but I don't know
  > 		whether the locking is necessary,
  > 		whether the "if (map->hint == entry)" is necessary,
  > 		what value should be set to the hint,
  > 		etc...,
  > 	and I'll leave it to the UVM gru.

 Actually, I think the check is necessary in more places where an entry
 is unlinked.  Not strictly necessary, but you can end up leaving a bogus
 hint otherwise (which is not fatal, just not optimal).

 -- 
         -- Jason R. Thorpe <thorpej@zembu.com>
Responsible-Changed-From-To: kern-bug-people->thorpej 
Responsible-Changed-By: thorpej 
Responsible-Changed-When: Wed Oct 11 10:11:25 PDT 2000 
Responsible-Changed-Why:  
I have a fix to commit, and will take responsibility 
for the bug. 
State-Changed-From-To: open->closed 
State-Changed-By: itohy 
State-Changed-When: Sun Feb 25 16:50:41 PST 2001 
State-Changed-Why:  
Jason fixed this problem by following deltas, and I confirmed the fix.  Thanks. 

-current 
sys/uvm/uvm_map.c	1.82 

netbsd-1-5 branch 
sys/uvm/uvm_map.c	1.77.2.2 
>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.