Sat Jun 20 19:24:27 2009 UTC ()
add a workaround for drm:

for device mmap()'s, if the D_NEGOFFSAFE flag is set, do not check
if the offset is negative.

this should go away with the test itself when all drivers are audited
and checked to not fail with negative offsets.


(mrg)
diff -r1.134 -r1.135 src/sys/sys/conf.h
diff -r1.55 -r1.56 src/sys/uvm/uvm_device.c

cvs diff -r1.134 -r1.135 src/sys/sys/conf.h (expand / switch to unified diff)

--- src/sys/sys/conf.h 2009/02/02 14:00:27 1.134
+++ src/sys/sys/conf.h 2009/06/20 19:24:27 1.135
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: conf.h,v 1.134 2009/02/02 14:00:27 haad Exp $ */ 1/* $NetBSD: conf.h,v 1.135 2009/06/20 19:24:27 mrg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990, 1993 4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc. 6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed 7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph 8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc. 10 * the permission of UNIX System Laboratories, Inc.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -51,26 +51,27 @@ struct lwp; @@ -51,26 +51,27 @@ struct lwp;
51struct tty; 51struct tty;
52struct uio; 52struct uio;
53struct vnode; 53struct vnode;
54 54
55/* 55/*
56 * Types for d_type 56 * Types for d_type
57 */ 57 */
58#define D_OTHER 0x0000 58#define D_OTHER 0x0000
59#define D_TAPE 0x0001 59#define D_TAPE 0x0001
60#define D_DISK 0x0002 60#define D_DISK 0x0002
61#define D_TTY 0x0003 61#define D_TTY 0x0003
62#define D_TYPEMASK 0x00ff 62#define D_TYPEMASK 0x00ff
63#define D_MPSAFE 0x0100 63#define D_MPSAFE 0x0100
 64#define D_NEGOFFSAFE 0x0200
64 65
65/* 66/*
66 * Block device switch table 67 * Block device switch table
67 */ 68 */
68struct bdevsw { 69struct bdevsw {
69 int (*d_open)(dev_t, int, int, struct lwp *); 70 int (*d_open)(dev_t, int, int, struct lwp *);
70 int (*d_close)(dev_t, int, int, struct lwp *); 71 int (*d_close)(dev_t, int, int, struct lwp *);
71 void (*d_strategy)(struct buf *); 72 void (*d_strategy)(struct buf *);
72 int (*d_ioctl)(dev_t, u_long, void *, int, struct lwp *); 73 int (*d_ioctl)(dev_t, u_long, void *, int, struct lwp *);
73 int (*d_dump)(dev_t, daddr_t, void *, size_t); 74 int (*d_dump)(dev_t, daddr_t, void *, size_t);
74 int (*d_psize)(dev_t); 75 int (*d_psize)(dev_t);
75 int d_flag; 76 int d_flag;
76}; 77};

cvs diff -r1.55 -r1.56 src/sys/uvm/uvm_device.c (expand / switch to unified diff)

--- src/sys/uvm/uvm_device.c 2008/12/17 20:51:39 1.55
+++ src/sys/uvm/uvm_device.c 2009/06/20 19:24:27 1.56
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: uvm_device.c,v 1.55 2008/12/17 20:51:39 cegger Exp $ */ 1/* $NetBSD: uvm_device.c,v 1.56 2009/06/20 19:24:27 mrg Exp $ */
2 2
3/* 3/*
4 * 4 *
5 * Copyright (c) 1997 Charles D. Cranor and Washington University. 5 * Copyright (c) 1997 Charles D. Cranor and Washington University.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -29,27 +29,27 @@ @@ -29,27 +29,27 @@
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * 33 *
34 * from: Id: uvm_device.c,v 1.1.2.9 1998/02/06 05:11:47 chs Exp 34 * from: Id: uvm_device.c,v 1.1.2.9 1998/02/06 05:11:47 chs Exp
35 */ 35 */
36 36
37/* 37/*
38 * uvm_device.c: the device pager. 38 * uvm_device.c: the device pager.
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: uvm_device.c,v 1.55 2008/12/17 20:51:39 cegger Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: uvm_device.c,v 1.56 2009/06/20 19:24:27 mrg Exp $");
43 43
44#include "opt_uvmhist.h" 44#include "opt_uvmhist.h"
45 45
46#include <sys/param.h> 46#include <sys/param.h>
47#include <sys/systm.h> 47#include <sys/systm.h>
48#include <sys/conf.h> 48#include <sys/conf.h>
49#include <sys/proc.h> 49#include <sys/proc.h>
50#include <sys/malloc.h> 50#include <sys/malloc.h>
51#include <sys/vnode.h> 51#include <sys/vnode.h>
52 52
53#include <uvm/uvm.h> 53#include <uvm/uvm.h>
54#include <uvm/uvm_device.h> 54#include <uvm/uvm_device.h>
55 55
@@ -133,27 +133,28 @@ udv_attach(void *arg, vm_prot_t accesspr @@ -133,27 +133,28 @@ udv_attach(void *arg, vm_prot_t accesspr
133 cdev = cdevsw_lookup(device); 133 cdev = cdevsw_lookup(device);
134 if (cdev == NULL) { 134 if (cdev == NULL) {
135 return (NULL); 135 return (NULL);
136 } 136 }
137 mapfn = cdev->d_mmap; 137 mapfn = cdev->d_mmap;
138 if (mapfn == NULL || mapfn == nommap || mapfn == nullmmap) { 138 if (mapfn == NULL || mapfn == nommap || mapfn == nullmmap) {
139 return(NULL); 139 return(NULL);
140 } 140 }
141 141
142 /* 142 /*
143 * Negative offsets on the object are not allowed. 143 * Negative offsets on the object are not allowed.
144 */ 144 */
145 145
146 if (off != UVM_UNKNOWN_OFFSET && off < 0) 146 if ((cdev->d_flag & D_NEGOFFSAFE) == 0 &&
 147 off != UVM_UNKNOWN_OFFSET && off < 0)
147 return(NULL); 148 return(NULL);
148 149
149 /* 150 /*
150 * Check that the specified range of the device allows the 151 * Check that the specified range of the device allows the
151 * desired protection. 152 * desired protection.
152 * 153 *
153 * XXX assumes VM_PROT_* == PROT_* 154 * XXX assumes VM_PROT_* == PROT_*
154 * XXX clobbers off and size, but nothing else here needs them. 155 * XXX clobbers off and size, but nothing else here needs them.
155 */ 156 */
156 157
157 while (size != 0) { 158 while (size != 0) {
158 if (cdev_mmap(device, off, accessprot) == -1) { 159 if (cdev_mmap(device, off, accessprot) == -1) {
159 return (NULL); 160 return (NULL);