Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys eliminate uvm_useracc() in favor of checking the return ...



details:   https://anonhg.NetBSD.org/src/rev/2886e951ccc4
branches:  trunk
changeset: 555272:2886e951ccc4
user:      chs <chs%NetBSD.org@localhost>
date:      Thu Nov 13 03:09:28 2003 +0000

description:
eliminate uvm_useracc() in favor of checking the return value of
copyin() or copyout().

uvm_useracc() tells us whether the mapping permissions allow access to
the desired part of an address space, and many callers assume that
this is the same as knowing whether an attempt to access that part of
the address space will succeed.  however, access to user space can
fail for reasons other than insufficient permission, most notably that
paging in any non-resident data can fail due to i/o errors.  most of
the callers of uvm_useracc() make the above incorrect assumption.  the
rest are all misguided optimizations, which optimize for the case
where an operation will fail.  we'd rather optimize for operations
succeeding, in which case we should just attempt the access and handle
failures due to insufficient permissions the same way we handle i/o
errors.  since there appear to be no good uses of uvm_useracc(), we'll
just remove it.

diffstat:

 sys/arch/alpha/alpha/trap.c               |   41 +++--------
 sys/arch/arm/iomd/vidcvideo.c             |   87 +++++++++++++++----------
 sys/arch/hpcmips/dev/ite8181.c            |   27 ++++---
 sys/arch/hpcmips/dev/mq200.c              |   22 ++----
 sys/arch/hpcmips/dev/plumvideo.c          |   67 ++++++++-----------
 sys/arch/hpcmips/tx/tx3912video.c         |   34 ++++-----
 sys/arch/hpcsh/dev/hd64461/hd64461video.c |   66 ++++++++----------
 sys/arch/luna68k/dev/lunafb.c             |   47 +++++++------
 sys/arch/macppc/dev/ofb.c                 |   29 +++++---
 sys/arch/newsmips/apbus/xafb.c            |   32 +++++---
 sys/arch/prep/pci/gten.c                  |   38 ++++------
 sys/arch/sparc/dev/cgfourteen.c           |   85 +++++++++++-------------
 sys/arch/sparc64/sparc64/machdep.c        |   20 +----
 sys/compat/irix/irix_swap.c               |    8 +-
 sys/compat/irix/irix_sysmp.c              |    9 +-
 sys/compat/irix/irix_syssgi.c             |   15 +---
 sys/compat/mach/mach_vm.c                 |    8 +-
 sys/dev/hpc/bivideo.c                     |   28 ++++---
 sys/dev/hpc/video_subr.c                  |    6 +-
 sys/dev/ic/bt463.c                        |   70 ++++++++++++--------
 sys/dev/ic/bt485.c                        |   79 +++++++++++++----------
 sys/dev/ic/ibm561.c                       |   30 +++++---
 sys/dev/ic/igsfb.c                        |   77 ++++++++++++----------
 sys/dev/pci/tga.c                         |   30 +++++---
 sys/dev/sbus/zx.c                         |   24 +++---
 sys/dev/sun/bt_subr.c                     |   20 +----
 sys/dev/sun/cgsix.c                       |   28 ++++---
 sys/dev/tc/cfb.c                          |   85 +++++++++++++++----------
 sys/dev/tc/mfb.c                          |   38 +++++++----
 sys/dev/tc/sfb.c                          |   84 +++++++++++++++---------
 sys/dev/tc/sfbplus.c                      |   85 +++++++++++++++----------
 sys/dev/tc/stic.c                         |   99 +++++++++++++++-------------
 sys/dev/tc/sticvar.h                      |    5 +-
 sys/dev/tc/tfb.c                          |   87 +++++++++++++++----------
 sys/dev/tc/xcfb.c                         |  101 ++++++++++++++++++-----------
 sys/kern/kern_time.c                      |   14 +--
 sys/kern/uipc_syscalls.c                  |   12 +--
 sys/uvm/uvm_extern.h                      |    3 +-
 sys/uvm/uvm_glue.c                        |   31 +--------
 39 files changed, 860 insertions(+), 811 deletions(-)

diffs (truncated from 3409 to 300 lines):

diff -r ee14ca98d11e -r 2886e951ccc4 sys/arch/alpha/alpha/trap.c
--- a/sys/arch/alpha/alpha/trap.c       Thu Nov 13 03:06:40 2003 +0000
+++ b/sys/arch/alpha/alpha/trap.c       Thu Nov 13 03:09:28 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.88 2003/10/29 05:16:26 mycroft Exp $ */
+/* $NetBSD: trap.c,v 1.89 2003/11/13 03:09:28 chs Exp $ */
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.88 2003/10/29 05:16:26 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.89 2003/11/13 03:09:28 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -872,14 +872,13 @@
        const char *type;       /* opcode name */
        int fixable;            /* fixable, 0 if fixup not supported */
        int size;               /* size, 0 if unknown */
-       int acc;                /* useracc type; B_READ or B_WRITE */
 };
 
-#define        UNKNOWN()       { "0x%lx", 0, 0, 0 }
-#define        FIX_LD(n,s)     { n, 1, s, B_READ }
-#define        FIX_ST(n,s)     { n, 1, s, B_WRITE }
-#define        NOFIX_LD(n,s)   { n, 0, s, B_READ }
-#define        NOFIX_ST(n,s)   { n, 0, s, B_WRITE }
+#define        UNKNOWN()       { "0x%lx", 0, 0 }
+#define        FIX_LD(n,s)     { n, 1, s }
+#define        FIX_ST(n,s)     { n, 1, s }
+#define        NOFIX_LD(n,s)   { n, 0, s }
+#define        NOFIX_ST(n,s)   { n, 0, s }
 
 int
 unaligned_fixup(u_long va, u_long opcode, u_long reg, struct lwp *l)
@@ -943,21 +942,6 @@
                selected_tab = tab_unknown;
 
        /*
-        * See if the user can access the memory in question.
-        * If it's an unknown opcode, we don't know whether to
-        * read or write, so we don't check.
-        *
-        * We adjust the PC backwards so that the instruction will
-        * be re-run.
-        */
-       if (selected_tab->size != 0 &&
-          !uvm_useracc((caddr_t)va, selected_tab->size, selected_tab->acc)) {
-               l->l_md.md_tf->tf_regs[FRAME_PC] -= 4;
-               signal = SIGSEGV;
-               goto out;
-       }
-
-       /*
         * If we're supposed to be noisy, squawk now.
         */
        if (doprint) {
@@ -975,16 +959,16 @@
        /*
         * If we should try to fix it and know how, give it a shot.
         *
-        * We never allow bad data to be unknowingly used by the
-        * user process.  That is, if we decide not to fix up an
-        * access we cause a SIGBUS rather than letting the user
-        * process go on without warning.
+        * We never allow bad data to be unknowingly used by the user process.
+        * That is, if we can't access the address needed to fix up the trap,
+        * we cause a SIGSEGV rather than letting the user process go on
+        * without warning.
         *
         * If we're trying to do a fixup, we assume that things
         * will be botched.  If everything works out OK, 
         * unaligned_{load,store}_* clears the signal flag.
         */
-       signal = SIGBUS;
+       signal = SIGSEGV;
        if (dofix && selected_tab->fixable) {
                switch (opcode) {
                case 0x0c:                      /* ldwu */
@@ -1062,7 +1046,6 @@
        if (dosigbus)
                signal = SIGBUS;
 
-out:
        /*
         * Write back USP.
         */
diff -r ee14ca98d11e -r 2886e951ccc4 sys/arch/arm/iomd/vidcvideo.c
--- a/sys/arch/arm/iomd/vidcvideo.c     Thu Nov 13 03:06:40 2003 +0000
+++ b/sys/arch/arm/iomd/vidcvideo.c     Thu Nov 13 03:09:28 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vidcvideo.c,v 1.19 2003/11/07 18:29:30 he Exp $ */
+/* $NetBSD: vidcvideo.c,v 1.20 2003/11/13 03:09:28 chs Exp $ */
 
 /*
  * Copyright (c) 2001 Reinoud Zandijk
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: vidcvideo.c,v 1.19 2003/11/07 18:29:30 he Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vidcvideo.c,v 1.20 2003/11/13 03:09:28 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -766,20 +766,19 @@
        struct wsdisplay_cmap *p;
 {
        u_int index = p->index, count = p->count;
+       int error;
 
        if (index >= CMAP_SIZE || count > CMAP_SIZE - index)
                return (EINVAL);
 
-       if (!uvm_useracc(p->red, count, B_WRITE) ||
-           !uvm_useracc(p->green, count, B_WRITE) ||
-           !uvm_useracc(p->blue, count, B_WRITE))
-               return (EFAULT);
-
-       copyout(&sc->sc_dc->dc_cmap.r[index], p->red, count);
-       copyout(&sc->sc_dc->dc_cmap.g[index], p->green, count);
-       copyout(&sc->sc_dc->dc_cmap.b[index], p->blue, count);
-
-       return (0);
+       error = copyout(&sc->sc_dc->dc_cmap.r[index], p->red, count);
+       if (error)
+               return error;
+       error = copyout(&sc->sc_dc->dc_cmap.g[index], p->green, count);
+       if (error)
+               return error;
+       error = copyout(&sc->sc_dc->dc_cmap.b[index], p->blue, count);
+       return error;
 }
 
 
@@ -789,19 +788,25 @@
        struct wsdisplay_cmap *p;
 {
        struct fb_devconfig *dc = sc->sc_dc;
+       struct hwcmap256 cmap;
        u_int index = p->index, count = p->count;
+       int error;
 
        if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
                return (EINVAL);
 
-       if (!uvm_useracc(p->red, count, B_READ) ||
-           !uvm_useracc(p->green, count, B_READ) ||
-           !uvm_useracc(p->blue, count, B_READ))
-               return (EFAULT);
-
-       copyin(p->red, &dc->dc_cmap.r[index], count);
-       copyin(p->green, &dc->dc_cmap.g[index], count);
-       copyin(p->blue, &dc->dc_cmap.b[index], count);
+       error = copyin(p->red, &cmap.r[index], count);
+       if (error)
+               return error;
+       error = copyin(p->green, &cmap.g[index], count);
+       if (error)
+               return error;
+       error = copyin(p->blue, &cmap.b[index], count);
+       if (error)
+               return error;
+       memcpy(&dc->dc_cmap.r[index], &cmap.r[index], count);
+       memcpy(&dc->dc_cmap.g[index], &cmap.g[index], count);
+       memcpy(&dc->dc_cmap.b[index], &cmap.b[index], count);
        dc->dc_changed |= WSDISPLAY_CMAP_DOLUT;
        return (0);
 }
@@ -814,7 +819,9 @@
 {
 #define        cc (&dc->dc_cursor)
        struct fb_devconfig *dc = sc->sc_dc;
-       u_int v, index, count, icount;
+       u_int v, index = 0, count = 0, icount = 0;
+       uint8_t r[2], g[2], b[2], image[512], mask[512];
+       int error;
 
        /* XXX gcc does not detect identical conditions */
        index = count = icount = 0;
@@ -823,20 +830,30 @@
        if (v & WSDISPLAY_CURSOR_DOCMAP) {
                index = p->cmap.index;
                count = p->cmap.count;
-               if (index >= CURSOR_MAX_COLOURS || (index + count) > CURSOR_MAX_COLOURS)
+               if (index >= CURSOR_MAX_COLOURS ||
+                   (index + count) > CURSOR_MAX_COLOURS)
                        return (EINVAL);
-               if (!uvm_useracc(p->cmap.red, count, B_READ) ||
-                   !uvm_useracc(p->cmap.green, count, B_READ) ||
-                   !uvm_useracc(p->cmap.blue, count, B_READ))
-                       return (EFAULT);
+               error = copyin(p->cmap.red, &r[index], count);
+               if (error)
+                       return error;
+               error = copyin(p->cmap.green, &g[index], count);
+               if (error)
+                       return error;
+               error = copyin(p->cmap.blue, &b[index], count);
+               if (error)
+                       return error;
        }
        if (v & WSDISPLAY_CURSOR_DOSHAPE) {
-               if (p->size.x > CURSOR_MAX_WIDTH || p->size.y > CURSOR_MAX_HEIGHT)
+               if (p->size.x > CURSOR_MAX_WIDTH ||
+                   p->size.y > CURSOR_MAX_HEIGHT)
                        return (EINVAL);
                icount = sizeof(u_int32_t) * p->size.y;
-               if (!uvm_useracc(p->image, icount, B_READ) ||
-                   !uvm_useracc(p->mask, icount, B_READ))
-                       return (EFAULT);
+               error = copyin(p->image, &image, icount);
+               if (error)
+                       return error;
+               error = copyin(p->mask, &mask, icount);
+               if (error)
+                       return error;
        }
 
        if (v & WSDISPLAY_CURSOR_DOCUR) 
@@ -846,16 +863,16 @@
        if (v & WSDISPLAY_CURSOR_DOHOT)
                cc->cc_hot = p->hot;
        if (v & WSDISPLAY_CURSOR_DOCMAP) {
-               copyin(p->cmap.red, &cc->cc_color[index], count);
-               copyin(p->cmap.green, &cc->cc_color[index + 2], count);
-               copyin(p->cmap.blue, &cc->cc_color[index + 4], count);
+               memcpy(&cc->cc_color[index], &r[index], count);
+               memcpy(&cc->cc_color[index + 2], &g[index], count);
+               memcpy(&cc->cc_color[index + 4], &b[index], count);
        }
        if (v & WSDISPLAY_CURSOR_DOSHAPE) {
                cc->cc_size = p->size;
                memset(cc->cc_image, 0, sizeof cc->cc_image);
+               memcpy(cc->cc_image, image, icount);
                memset(cc->cc_mask, 0, sizeof cc->cc_mask);
-               copyin(p->image, cc->cc_image, icount);
-               copyin(p->mask, cc->cc_mask, icount);
+               memcpy(cc->cc_mask, mask, icount);
        }
        dc->dc_changed |= v;
 
diff -r ee14ca98d11e -r 2886e951ccc4 sys/arch/hpcmips/dev/ite8181.c
--- a/sys/arch/hpcmips/dev/ite8181.c    Thu Nov 13 03:06:40 2003 +0000
+++ b/sys/arch/hpcmips/dev/ite8181.c    Thu Nov 13 03:09:28 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ite8181.c,v 1.19 2003/07/15 02:29:29 lukem Exp $       */
+/*     $NetBSD: ite8181.c,v 1.20 2003/11/13 03:09:28 chs Exp $ */
 
 /*-
  * Copyright (c) 2000,2001 SATO Kazumi
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ite8181.c,v 1.19 2003/07/15 02:29:29 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ite8181.c,v 1.20 2003/11/13 03:09:28 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -640,10 +640,11 @@
        struct hpcfb_dspconf *dspconf;
        struct wsdisplay_cmap *cmap;
        struct wsdisplay_param *dispparam;
+       int error;
 
        switch (cmd) {
        case WSDISPLAYIO_GETCMAP:
-               cmap = (struct wsdisplay_cmap*)data;
+               cmap = (struct wsdisplay_cmap *)data;
 
                if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
                    sc->sc_fbconf.hf_pack_width != 8 ||
@@ -651,16 +652,18 @@
                    256 - cmap->index < cmap->count)
                        return (EINVAL);
 
-               if (!uvm_useracc(cmap->red, cmap->count, B_WRITE) ||
-                   !uvm_useracc(cmap->green, cmap->count, B_WRITE) ||
-                   !uvm_useracc(cmap->blue, cmap->count, B_WRITE))
-                       return (EFAULT);
-
 #ifdef ITE8181_WINCE_CMAP
-               copyout(&bivideo_cmap_r[cmap->index], cmap->red, cmap->count);
-               copyout(&bivideo_cmap_g[cmap->index], cmap->green,cmap->count);
-               copyout(&bivideo_cmap_b[cmap->index], cmap->blue, cmap->count);
-               return (0);
+               error = copyout(&bivideo_cmap_r[cmap->index], cmap->red,
+                               cmap->count);
+               if (error)
+                       return error;
+               error = copyout(&bivideo_cmap_g[cmap->index], cmap->green,
+                               cmap->count);
+               if (error)
+                       return error;
+               error = copyout(&bivideo_cmap_b[cmap->index], cmap->blue,
+                               cmap->count);



Home | Main Index | Thread Index | Old Index