Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/vax/vax Allow allocation of PTE space to fail in pm...



details:   https://anonhg.NetBSD.org/src/rev/d85d76012736
branches:  trunk
changeset: 831428:d85d76012736
user:      ragge <ragge%NetBSD.org@localhost>
date:      Fri Mar 30 08:34:35 2018 +0000

description:
Allow allocation of PTE space to fail in pmap_enter if PMAP_CANFAIL is set.
This fixes the panic part of PR port-vax/28379.

diffstat:

 sys/arch/vax/vax/pmap.c |  34 ++++++++++++++++++++++------------
 1 files changed, 22 insertions(+), 12 deletions(-)

diffs (121 lines):

diff -r ab43366c39b2 -r d85d76012736 sys/arch/vax/vax/pmap.c
--- a/sys/arch/vax/vax/pmap.c   Fri Mar 30 08:25:06 2018 +0000
+++ b/sys/arch/vax/vax/pmap.c   Fri Mar 30 08:34:35 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.185 2017/05/22 16:53:05 ragge Exp $    */
+/*     $NetBSD: pmap.c,v 1.186 2018/03/30 08:34:35 ragge Exp $    */
 /*
  * Copyright (c) 1994, 1998, 1999, 2003 Ludd, University of Lule}, Sweden.
  * All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.185 2017/05/22 16:53:05 ragge Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.186 2018/03/30 08:34:35 ragge Exp $");
 
 #include "opt_ddb.h"
 #include "opt_cputype.h"
@@ -765,10 +765,8 @@
 
 /*
  * Allocate space for user page tables, from ptemap.
- * This routine should never fail; use the same algorithm as when processes
- * are swapped.
  * Argument is needed space, in bytes.
- * Returns a pointer to the newly allocated space.
+ * Returns a pointer to the newly allocated space, or 0 if failed.
  */
 static vaddr_t
 pmap_getusrptes(pmap_t pm, vsize_t nsize)
@@ -781,9 +779,7 @@
 #endif
        while (((rv = pmap_extwrap(nsize)) == 0) && (pmap_rmproc(pm) != 0))
                ;
-       if (rv)
-               return rv;
-       panic("usrptmap space leakage");
+       return rv;
 }
 
 /*
@@ -804,7 +800,7 @@
        *ptpp = 0;
 }
 
-static void 
+static int 
 grow_p0(struct pmap *pm, int reqlen)
 {
        vaddr_t nptespc;
@@ -823,6 +819,8 @@
        nptespc = pmap_getusrptes(pm, len);
        RECURSESTART;
  
+       if (nptespc == 0)
+               return 0;
        /*
         * Copy the old ptes to the new space.
         * Done by moving on system page table.
@@ -846,10 +844,11 @@
        /* Remove the old after update_pcbs() (for multi-CPU propagation) */
        if (inuse)
                extent_free(ptemap, p0br, p0lr*PPTESZ, EX_WAITOK);
+       return 1;
 }
 
 
-static void
+static int
 grow_p1(struct pmap *pm, int len)
 {
        vaddr_t nptespc, optespc;
@@ -862,6 +861,9 @@
        RECURSEEND;
        nptespc = pmap_getusrptes(pm, nlen);
        RECURSESTART;
+       if (nptespc == 0)
+               return 0;
+
        olen = (NPTEPERREG*PPTESZ) - (pm->pm_p1lr * PPTESZ);
        optespc = (vaddr_t)pm->pm_p1ap;
 
@@ -881,6 +883,7 @@
 
        if (optespc)
                extent_free(ptemap, optespc, olen, EX_WAITOK);
+       return 1;
 }
 
 /*
@@ -1096,14 +1099,16 @@
 
        case P0SEG:
                if (vax_btop(v) >= pmap->pm_p0lr)
-                       grow_p0(pmap, vax_btop(v));
+                       if (grow_p0(pmap, vax_btop(v)) == 0)
+                               goto growfail;
                pteptr = (int *)pmap->pm_p0br + vax_btop(v);
                newpte = (prot & VM_PROT_WRITE ? PG_RW : PG_RO);
                break;
 
        case P1SEG:
                if (vax_btop(v - 0x40000000) < pmap->pm_p1lr)
-                       grow_p1(pmap, vax_btop(v - 0x40000000));
+                       if (grow_p1(pmap, vax_btop(v - 0x40000000)) == 0)
+                               goto growfail;
                pteptr = (int *)pmap->pm_p1br + vax_btop(v - 0x40000000);
                newpte = (prot & VM_PROT_WRITE ? PG_RW : PG_RO);
                break;
@@ -1214,6 +1219,11 @@
 
        mtpr(0, PR_TBIA); /* Always; safety belt */
        return 0;
+
+growfail:
+       if (flags & PMAP_CANFAIL)
+               return ENOMEM;
+       panic("usrptmap space leakage");
 }
 
 vaddr_t



Home | Main Index | Thread Index | Old Index