Module Name:    src
Committed By:   riz
Date:           Mon Jun 11 21:25:02 UTC 2012

Modified Files:
        src/sys/uvm [netbsd-6]: uvm_vnode.c
        src/tests/lib/libc/sys [netbsd-6]: t_mmap.c

Log Message:
Pull up following revision(s) (requested by martin in ticket #301):
        sys/uvm/uvm_vnode.c: revision 1.98
        tests/lib/libc/sys/t_mmap.c: revision 1.3
        tests/lib/libc/sys/t_mmap.c: revision 1.4
        tests/lib/libc/sys/t_mmap.c: revision 1.5
        tests/lib/libc/sys/t_mmap.c: revision 1.6
Only use generic readahead on VREG vnodes, the space used to store the
context is not valid on other types.
Prevents the crash reported in PR kern/38889, but does not fix the
mmap of block devices, more work is needed (no size on VBLK vnodes).
Do not skip the block device mmap test, as it does not crash
the kernel any more. Mark it as expected failure instead.
mmap_block:
do not use a hardcoded block device list, but query the kernel for attached
disks instead, then try to mmap the raw partition.
Use atf_tc_skip().
A test case for serious PR kern/38889: crash on open/mmap/close of block
device. The test case is skipped for the time being as it replicates the
panic described in the PR (tested on NetBSD/amd64 6.0 BETA).


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.97.8.1 src/sys/uvm/uvm_vnode.c
cvs rdiff -u -r1.2 -r1.2.4.1 src/tests/lib/libc/sys/t_mmap.c

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

Modified files:

Index: src/sys/uvm/uvm_vnode.c
diff -u src/sys/uvm/uvm_vnode.c:1.97 src/sys/uvm/uvm_vnode.c:1.97.8.1
--- src/sys/uvm/uvm_vnode.c:1.97	Tue Sep  6 16:41:55 2011
+++ src/sys/uvm/uvm_vnode.c	Mon Jun 11 21:25:02 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_vnode.c,v 1.97 2011/09/06 16:41:55 matt Exp $	*/
+/*	$NetBSD: uvm_vnode.c,v 1.97.8.1 2012/06/11 21:25:02 riz Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.97 2011/09/06 16:41:55 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.97.8.1 2012/06/11 21:25:02 riz Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -170,7 +170,8 @@ uvn_get(struct uvm_object *uobj, voff_t 
 
 	UVMHIST_LOG(ubchist, "vp %p off 0x%x", vp, (int)offset, 0,0);
 
-	if ((access_type & VM_PROT_WRITE) == 0 && (flags & PGO_LOCKED) == 0) {
+	if (vp->v_type == VREG && (access_type & VM_PROT_WRITE) == 0
+	    && (flags & PGO_LOCKED) == 0) {
 		vn_ra_allocctx(vp);
 		uvm_ra_request(vp->v_ractx, advice, uobj, offset,
 		    *npagesp << PAGE_SHIFT);

Index: src/tests/lib/libc/sys/t_mmap.c
diff -u src/tests/lib/libc/sys/t_mmap.c:1.2 src/tests/lib/libc/sys/t_mmap.c:1.2.4.1
--- src/tests/lib/libc/sys/t_mmap.c:1.2	Thu Jul 14 11:08:45 2011
+++ src/tests/lib/libc/sys/t_mmap.c	Mon Jun 11 21:25:02 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.2 2011/07/14 11:08:45 jruoho Exp $ */
+/* $NetBSD: t_mmap.c,v 1.2.4.1 2012/06/11 21:25:02 riz Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mmap.c,v 1.2 2011/07/14 11:08:45 jruoho Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.2.4.1 2012/06/11 21:25:02 riz Exp $");
 
 #include <sys/param.h>
 #include <sys/mman.h>
@@ -67,9 +67,12 @@ __RCSID("$NetBSD: t_mmap.c,v 1.2 2011/07
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <paths.h>
+#include <machine/disklabel.h>
 
 static long	page = 0;
 static char	path[] = "mmap";
@@ -152,6 +155,52 @@ map_sighandler(int signo)
 	_exit(signo);
 }
 
+ATF_TC(mmap_block);
+ATF_TC_HEAD(mmap_block, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test mmap(2) with a block device");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(mmap_block, tc)
+{
+	static const int mib[] = { CTL_HW, HW_DISKNAMES };
+	static const unsigned int miblen = __arraycount(mib);
+	char *map, *dk, *drives, dev[PATH_MAX];
+	size_t len;
+	int fd = -1;
+
+	atf_tc_expect_signal(SIGSEGV, "mmap of block devices does not work "
+	    "(PR kern/38889)");
+
+	ATF_REQUIRE(sysctl(mib, miblen, NULL, &len, NULL, 0) == 0);
+	drives = malloc(len);
+	ATF_REQUIRE(drives != NULL);
+	ATF_REQUIRE(sysctl(mib, miblen, drives, &len, NULL, 0) == 0);
+	for (dk = strtok(drives, " "); dk != NULL; dk = strtok(NULL, " ")) {
+		sprintf(dev, _PATH_DEV "%s%c", dk, 'a'+RAW_PART);
+		fprintf(stderr, "trying: %s\n", dev);
+
+		if ((fd = open(dev, O_RDONLY)) >= 0) {
+			(void)fprintf(stderr, "using %s\n", dev);
+			break;
+		}
+	}
+	free(drives);
+
+	if (fd < 0)
+		atf_tc_skip("failed to find suitable block device");
+
+	map = mmap(NULL, 4096, PROT_READ, MAP_FILE, fd, 0);
+	ATF_REQUIRE(map != MAP_FAILED);
+
+	(void)fprintf(stderr, "first byte %x\n", *map);
+	ATF_REQUIRE(close(fd) == 0);
+	(void)fprintf(stderr, "first byte %x\n", *map);
+
+	ATF_REQUIRE(munmap(map, 4096) == 0);
+}
+
 ATF_TC(mmap_err);
 ATF_TC_HEAD(mmap_err, tc)
 {
@@ -444,6 +493,7 @@ ATF_TP_ADD_TCS(tp)
 	page = sysconf(_SC_PAGESIZE);
 	ATF_REQUIRE(page >= 0);
 
+	ATF_TP_ADD_TC(tp, mmap_block);
 	ATF_TP_ADD_TC(tp, mmap_err);
 	ATF_TP_ADD_TC(tp, mmap_loan);
 	ATF_TP_ADD_TC(tp, mmap_prot_1);

Reply via email to