Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Jan 2008 01:44:04 GMT
From:      pluknet <pluknet@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/119704: [patch] unbrake sysutils/pmap on 7.0
Message-ID:  <200801160144.m0G1i4ke080456@www.freebsd.org>
Resent-Message-ID: <200801160150.m0G1o19r040075@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         119704
>Category:       ports
>Synopsis:       [patch] unbrake sysutils/pmap on 7.0
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 16 01:50:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     pluknet
>Release:        7.0-PRE
>Organization:
>Environment:
FreeBSD 7.0-PRERELEASE #0: Fri Jan 11 17:05:44 MSK 2008     root@notebook.h3:/media/obj/media/src/sys/MYKERNEL
>Description:
sysutils/pmap is broken on ${OSVERSION} >= 700000
This patch unbrakes port compilation and provides properly synchronization in kernel.
>How-To-Repeat:
Try to build the port. It's broken at least on 7.0 with an error:
pmap_helper.c:210: error: 'AUE_NULL' undeclared here (not in a function)

pmap_helper.kld has a LOR:
lock order reversal: (sleepable after non-sleepable)
 1st 0xc3e39894 process lock (process lock) @ /media/src/sys/kern/kern_proc.c:247
 2nd 0xc3ab3ec4 user map (user map) @ pmap_helper.c:102

and finally panics with:
Kernel page fault with the following non-sleepable locks held:
exclusive sleep mutex process lock r = 0 (0xc3e39894) locked @ /media/src/sys/kern/kern_proc.c:247

>Fix:
Apply the patch.

Patch attached with submission follows:

--- pmap_helper/pmap_helper.c.orig	2006-06-22 15:55:17.000000000 +0400
+++ pmap_helper/pmap_helper.c	2008-01-16 04:00:46.000000000 +0300
@@ -43,6 +43,7 @@
 #include <sys/lock.h>
 #include <sys/vnode.h>
 #include <sys/malloc.h>
+#include <sys/sysproto.h>
 
 #include <vm/vm.h>
 #include <vm/pmap.h>
@@ -77,7 +78,6 @@
 	struct proc *p;
 	static struct vm_map *map;
 	struct vm_map_entry *entry;
-	pmap_t pmap;
 	int nmaps = 0;
 	int error;
 	struct pmh pmh;
@@ -91,17 +91,16 @@
 		return EINVAL;
 
 	p = pfind(pmh.pid); /* XXX Locks p! */
+	PROC_UNLOCK(p);	/* locked by pfind(9) */
+
 	if (p == NULL)
 		return ESRCH;
 
 	/* map points to description of MI virtual address space */
 	map = &p->p_vmspace->vm_map;
 
-       if (map != &curthread->td_proc->p_vmspace->vm_map)
-               vm_map_lock_read(map);
+	vm_map_lock_read(map);
  
-	/* pmap points to private physiscal map for whole process space */
-	pmap = vmspace_pmap(p->p_vmspace);
 	error = 0;
 
 	for (entry = map->header.next; entry != &map->header; 
@@ -129,7 +128,7 @@
 		addr = entry->start;
 		/* estimate number of phys. resident pages in map */
 		while (addr < entry->end) {
-			if (pmap_extract(pmap, addr))
+			if (pmap_extract(map->pmap, addr))
 				resident++;
 			addr += PAGE_SIZE;
 		}
@@ -163,7 +162,9 @@
 					free(freepath, M_TEMP);
 			}
 		}
+		vm_map_unlock_read(map);
 		error = copyout(&pmhm, &pmh.maps[nmaps], sizeof pmh.maps[nmaps]);
+		vm_map_lock_read(map);
 		if (error)
 			break;
 		nmaps++;
@@ -171,10 +172,7 @@
 			break;
 	}
 
-        if (map != &curthread->td_proc->p_vmspace->vm_map)
-               vm_map_unlock_read(map);
-
-	PROC_UNLOCK(p);	/* locked by pfind(9) */
+	vm_map_unlock_read(map);
 
 	if (error == 0)
 		error = copyout(&nmaps, &uap->pmh->nmaps, sizeof uap->pmh->nmaps);


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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801160144.m0G1i4ke080456>