Source-Changes-HG archive

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

[src/netbsd-9]: src/sys/arch/powerpc/ibm4xx Pull up following revision(s) (re...



details:   https://anonhg.NetBSD.org/src/rev/9e4e25d20851
branches:  netbsd-9
changeset: 1001572:9e4e25d20851
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Mar 09 11:52:14 2020 +0000

description:
Pull up following revision(s) (requested by rin in ticket #772):

        sys/arch/powerpc/ibm4xx/copyinstr.c: revision 1.12
        sys/arch/powerpc/ibm4xx/copyinstr.c: revision 1.13
        sys/arch/powerpc/ibm4xx/copyoutstr.c: revision 1.10
        sys/arch/powerpc/ibm4xx/copyoutstr.c: revision 1.11
        sys/arch/powerpc/ibm4xx/copyoutstr.c: revision 1.12
        sys/arch/powerpc/ibm4xx/copyoutstr.c: revision 1.13
        sys/arch/powerpc/ibm4xx/copyinstr.c: revision 1.10
        sys/arch/powerpc/ibm4xx/copyinstr.c: revision 1.11

copy{in,out}str: sync style with booke.
- early return in case of len == 0
- *done = 0 on fault

copy{in,out}str: Correctly return ENAMETOOLONG if source is not
NUL-terminated.

Use dcbst instead of dcbf to flush cache; the former does not invalidate
the cache line, which should be used immediately in most cases.

Cosmetic changes. No binary changes.

diffstat:

 sys/arch/powerpc/ibm4xx/copyinstr.c  |  73 +++++++++++++++++++----------------
 sys/arch/powerpc/ibm4xx/copyoutstr.c |  73 +++++++++++++++++++----------------
 2 files changed, 80 insertions(+), 66 deletions(-)

diffs (216 lines):

diff -r 7768006c4776 -r 9e4e25d20851 sys/arch/powerpc/ibm4xx/copyinstr.c
--- a/sys/arch/powerpc/ibm4xx/copyinstr.c       Mon Mar 09 10:39:43 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/copyinstr.c       Mon Mar 09 11:52:14 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: copyinstr.c,v 1.9 2010/03/20 23:31:29 chs Exp $        */
+/*     $NetBSD: copyinstr.c,v 1.9.64.1 2020/03/09 11:52:14 martin Exp $        */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copyinstr.c,v 1.9 2010/03/20 23:31:29 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copyinstr.c,v 1.9.64.1 2020/03/09 11:52:14 martin Exp $");
 
 #include <sys/param.h>
 #include <uvm/uvm_extern.h>
@@ -46,14 +46,20 @@
 copyinstr(const void *udaddr, void *kaddr, size_t len, size_t *done)
 {
        struct pmap *pm = curproc->p_vmspace->vm_map.pmap;
-       int rv, msr, pid, tmp, ctx;
+       size_t resid;
+       int rv, msr, pid, data, ctx;
        struct faultbuf env;
 
+       if (__predict_false(len == 0)) {
+               if (done)
+                       *done = 0;
+               return 0;
+       }
+
        if ((rv = setfault(&env))) {
                curpcb->pcb_onfault = NULL;
-               /* XXXX -- len may be lost on a fault */
                if (done)
-                       *done = len;
+                       *done = 0;
                return rv;
        }
 
@@ -63,36 +69,37 @@
                ctx = pm->pm_ctx;
        }
 
-       if (len) {
-               __asm volatile("mtctr %3;"              /* Set up counter */
-                       "mfmsr %0;"                     /* Save MSR */
-                       "li %1,0x20; "
-                       "andc %1,%0,%1; mtmsr %1;"      /* Disable IMMU */
-                       "mfpid %1;"                     /* Save old PID */
-                       "sync; isync;"
-
-                       "li %3,0;"                      /* Clear len */
+       resid = len;
+       __asm volatile(
+               "mtctr %3;"                     /* Set up counter */
+               "mfmsr %0;"                     /* Save MSR */
+               "li %1,0x20;"
+               "andc %1,%0,%1; mtmsr %1;"      /* Disable IMMU */
+               "mfpid %1;"                     /* Save old PID */
+               "sync; isync;"
 
-                       "1: "
-                       "mtpid %4; sync;"               /* Load user ctx */
-                       "lbz %2,0(%5); addi %5,%5,1;"   /* Load byte */
-                       "sync; isync;"
-                       "mtpid %1;sync;"
-                       "stb %2,0(%6);  dcbf 0,%6; addi %6,%6,1;"       /* Store kernel byte */
-                       "sync; isync;"
-                       "addi %3,%3,1;"                 /* Inc len */
-                       "or. %2,%2,%2;"
-                       "bdnzf 2,1b;"                   /*
-                                                        * while(ctr-- && !zero)
-                                                        */
+               "1: "
+               "mtpid %4; sync;"               /* Load user ctx */
+               "lbz %2,0(%5); addi %5,%5,1;"   /* Load byte */
+               "sync; isync;"
+               "mtpid %1; sync;"
+               "stb %2,0(%6); dcbst 0,%6; addi %6,%6,1;"
+                                               /* Store kernel byte */
+               "sync; isync;"
+               "or. %2,%2,%2;"
+               "bdnzf 2,1b;"                   /* while(ctr-- && !zero) */
 
-                       "mtpid %1; mtmsr %0;"           /* Restore PID, MSR */
-                       "sync; isync;"
-                       : "=&r" (msr), "=&r" (pid), "=&r" (tmp), "+b" (len)
-                       : "r" (ctx), "b" (udaddr), "b" (kaddr));
-       }
+               "mtpid %1; mtmsr %0;"           /* Restore PID, MSR */
+               "sync; isync;"
+               "mfctr %3;"                     /* Restore resid */
+               : "=&r" (msr), "=&r" (pid), "=&r" (data), "+r" (resid)
+               : "r" (ctx), "b" (udaddr), "b" (kaddr));
+
        curpcb->pcb_onfault = NULL;
        if (done)
-               *done = len;
-       return 0;
+               *done = len - resid;
+       if (resid == 0 && (char)data != '\0')
+               return ENAMETOOLONG;
+       else
+               return 0;
 }
diff -r 7768006c4776 -r 9e4e25d20851 sys/arch/powerpc/ibm4xx/copyoutstr.c
--- a/sys/arch/powerpc/ibm4xx/copyoutstr.c      Mon Mar 09 10:39:43 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/copyoutstr.c      Mon Mar 09 11:52:14 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: copyoutstr.c,v 1.9 2010/03/20 23:31:29 chs Exp $       */
+/*     $NetBSD: copyoutstr.c,v 1.9.64.1 2020/03/09 11:52:14 martin Exp $       */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copyoutstr.c,v 1.9 2010/03/20 23:31:29 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copyoutstr.c,v 1.9.64.1 2020/03/09 11:52:14 martin Exp $");
 
 #include <sys/param.h>
 #include <uvm/uvm_extern.h>
@@ -46,14 +46,20 @@
 copyoutstr(const void *kaddr, void *udaddr, size_t len, size_t *done)
 {
        struct pmap *pm = curproc->p_vmspace->vm_map.pmap;
-       int rv, msr, pid, tmp, ctx;
+       size_t resid;
+       int rv, msr, pid, data, ctx;
        struct faultbuf env;
 
+       if (__predict_false(len == 0)) {
+               if (done)
+                       *done = 0;
+               return 0;
+       }
+
        if ((rv = setfault(&env))) {
                curpcb->pcb_onfault = NULL;
-               /* XXXX -- len may be lost on a fault */
                if (done)
-                       *done = len;
+                       *done = 0;
                return rv;
        }
 
@@ -63,36 +69,37 @@
                ctx = pm->pm_ctx;
        }
 
-       if (len) {
-               __asm volatile("mtctr %3;"              /* Set up counter */
-                       "mfmsr %0;"                     /* Save MSR */
-                       "li %1,0x20; "
-                       "andc %1,%0,%1; mtmsr %1;"      /* Disable IMMU */
-                       "mfpid %1;"                     /* Save old PID */
-                       "sync; isync;"
-
-                       "li %3,0;"                      /* Clear len */
+       resid = len;
+       __asm volatile(
+               "mtctr %3;"                     /* Set up counter */
+               "mfmsr %0;"                     /* Save MSR */
+               "li %1,0x20;"
+               "andc %1,%0,%1; mtmsr %1;"      /* Disable IMMU */
+               "mfpid %1;"                     /* Save old PID */
+               "sync; isync;"
 
-                       "1:"
-                       "mtpid %1;sync;"
-                       "lbz %2,0(%6); addi %6,%6,1;"   /* Store kernel byte */
-                       "sync; isync;"
-                       "mtpid %4; sync;"               /* Load user ctx */
-                       "stb %2,0(%5);  dcbf 0,%5; addi %5,%5,1;"       /* Load byte */
-                       "sync; isync;"
-                       "addi %3,%3,1;"                 /* Inc len */
-                       "or. %2,%2,%2;"
-                       "bdnzf 2,1b;"                   /*
-                                                        * while(ctr-- && !zero)
-                                                        */
+               "1:"
+               "mtpid %1; sync;"
+               "lbz %2,0(%6); addi %6,%6,1;"   /* Store kernel byte */
+               "sync; isync;"
+               "mtpid %4; sync;"               /* Load user ctx */
+               "stb %2,0(%5); dcbst 0,%5; addi %5,%5,1;"
+                                               /* Load byte */
+               "sync; isync;"
+               "or. %2,%2,%2;"
+               "bdnzf 2,1b;"                   /* while(ctr-- && !zero) */
 
-                       "mtpid %1; mtmsr %0;"           /* Restore PID, MSR */
-                       "sync; isync;"
-                       : "=&r" (msr), "=&r" (pid), "=&r" (tmp), "+b" (len)
-                       : "r" (ctx), "b" (udaddr), "b" (kaddr));
-       }
+               "mtpid %1; mtmsr %0;"           /* Restore PID, MSR */
+               "sync; isync;"
+               "mfctr %3;"                     /* Restore resid */
+               : "=&r" (msr), "=&r" (pid), "=&r" (data), "+r" (resid)
+               : "r" (ctx), "b" (udaddr), "b" (kaddr));
+
        curpcb->pcb_onfault = NULL;
        if (done)
-               *done = len;
-       return 0;
+               *done = len - resid;
+       if (resid == 0 && (char)data != '\0')
+               return ENAMETOOLONG;
+       else
+               return 0;
 }



Home | Main Index | Thread Index | Old Index