41 /*
  42  * VM - address spaces.
  43  */
  44 
  45 #include <sys/types.h>
  46 #include <sys/t_lock.h>
  47 #include <sys/param.h>
  48 #include <sys/errno.h>
  49 #include <sys/systm.h>
  50 #include <sys/mman.h>
  51 #include <sys/sysmacros.h>
  52 #include <sys/cpuvar.h>
  53 #include <sys/sysinfo.h>
  54 #include <sys/kmem.h>
  55 #include <sys/vnode.h>
  56 #include <sys/vmsystm.h>
  57 #include <sys/cmn_err.h>
  58 #include <sys/debug.h>
  59 #include <sys/tnf_probe.h>
  60 #include <sys/vtrace.h>
  61 
  62 #include <vm/hat.h>
  63 #include <vm/as.h>
  64 #include <vm/seg.h>
  65 #include <vm/seg_vn.h>
  66 #include <vm/seg_dev.h>
  67 #include <vm/seg_kmem.h>
  68 #include <vm/seg_map.h>
  69 #include <vm/seg_spt.h>
  70 #include <vm/page.h>
  71 
  72 clock_t deadlk_wait = 1; /* number of ticks to wait before retrying */
  73 
  74 static struct kmem_cache *as_cache;
  75 
  76 static void as_setwatchprot(struct as *, caddr_t, size_t, uint_t);
  77 static void as_clearwatchprot(struct as *, caddr_t, size_t);
  78 int as_map_locked(struct as *, caddr_t, size_t, int ((*)()), void *);
  79 
  80 
 
 
 833         forkedproc->p_as = newas;
 834         return (0);
 835 }
 836 
 837 /*
 838  * Handle a ``fault'' at addr for size bytes.
 839  */
 840 faultcode_t
 841 as_fault(struct hat *hat, struct as *as, caddr_t addr, size_t size,
 842     enum fault_type type, enum seg_rw rw)
 843 {
 844         struct seg *seg;
 845         caddr_t raddr;                  /* rounded down addr */
 846         size_t rsize;                   /* rounded up size */
 847         size_t ssize;
 848         faultcode_t res = 0;
 849         caddr_t addrsav;
 850         struct seg *segsav;
 851         int as_lock_held;
 852         klwp_t *lwp = ttolwp(curthread);
 853 
 854 
 855 
 856 retry:
 857         /*
 858          * Indicate that the lwp is not to be stopped while waiting for a
 859          * pagefault.  This is to avoid deadlock while debugging a process
 860          * via /proc over NFS (in particular).
 861          */
 862         if (lwp != NULL)
 863                 lwp->lwp_nostop++;
 864 
 865         /*
 866          * same length must be used when we softlock and softunlock.  We
 867          * don't support softunlocking lengths less than the original length
 868          * when there is largepage support.  See seg_dev.c for more
 869          * comments.
 870          */
 871         switch (type) {
 872 
 873         case F_SOFTLOCK:
 874                 CPU_STATS_ADD_K(vm, softlock, 1);
 875                 break;
 876 
 877         case F_SOFTUNLOCK:
 878                 break;
 879 
 880         case F_PROT:
 881                 CPU_STATS_ADD_K(vm, prot_fault, 1);
 882                 break;
 883 
 884         case F_INVAL:
 885                 CPU_STATS_ENTER_K();
 886                 CPU_STATS_ADDQ(CPU, vm, as_fault, 1);
 887                 if (as == &kas)
 888                         CPU_STATS_ADDQ(CPU, vm, kernel_asflt, 1);
 889                 CPU_STATS_EXIT_K();
 890                 break;
 891         }
 892 
 893         /* Kernel probe */
 894         TNF_PROBE_3(address_fault, "vm pagefault", /* CSTYLED */,
 895             tnf_opaque, address,        addr,
 896             tnf_fault_type,     fault_type,     type,
 897             tnf_seg_access,     access,         rw);
 898 
 899         raddr = (caddr_t)((uintptr_t)addr & (uintptr_t)PAGEMASK);
 900         rsize = (((size_t)(addr + size) + PAGEOFFSET) & PAGEMASK) -
 901             (size_t)raddr;
 902 
 903         /*
 904          * XXX -- Don't grab the as lock for segkmap. We should grab it for
 905          * correctness, but then we could be stuck holding this lock for
 906          * a LONG time if the fault needs to be resolved on a slow
 907          * filesystem, and then no-one will be able to exec new commands,
 908          * as exec'ing requires the write lock on the as.
 909          */
 
 | 
 
 
  41 /*
  42  * VM - address spaces.
  43  */
  44 
  45 #include <sys/types.h>
  46 #include <sys/t_lock.h>
  47 #include <sys/param.h>
  48 #include <sys/errno.h>
  49 #include <sys/systm.h>
  50 #include <sys/mman.h>
  51 #include <sys/sysmacros.h>
  52 #include <sys/cpuvar.h>
  53 #include <sys/sysinfo.h>
  54 #include <sys/kmem.h>
  55 #include <sys/vnode.h>
  56 #include <sys/vmsystm.h>
  57 #include <sys/cmn_err.h>
  58 #include <sys/debug.h>
  59 #include <sys/tnf_probe.h>
  60 #include <sys/vtrace.h>
  61 #include <sys/ddi.h>
  62 
  63 #include <vm/hat.h>
  64 #include <vm/as.h>
  65 #include <vm/seg.h>
  66 #include <vm/seg_vn.h>
  67 #include <vm/seg_dev.h>
  68 #include <vm/seg_kmem.h>
  69 #include <vm/seg_map.h>
  70 #include <vm/seg_spt.h>
  71 #include <vm/page.h>
  72 
  73 clock_t deadlk_wait = 1; /* number of ticks to wait before retrying */
  74 
  75 static struct kmem_cache *as_cache;
  76 
  77 static void as_setwatchprot(struct as *, caddr_t, size_t, uint_t);
  78 static void as_clearwatchprot(struct as *, caddr_t, size_t);
  79 int as_map_locked(struct as *, caddr_t, size_t, int ((*)()), void *);
  80 
  81 
 
 
 834         forkedproc->p_as = newas;
 835         return (0);
 836 }
 837 
 838 /*
 839  * Handle a ``fault'' at addr for size bytes.
 840  */
 841 faultcode_t
 842 as_fault(struct hat *hat, struct as *as, caddr_t addr, size_t size,
 843     enum fault_type type, enum seg_rw rw)
 844 {
 845         struct seg *seg;
 846         caddr_t raddr;                  /* rounded down addr */
 847         size_t rsize;                   /* rounded up size */
 848         size_t ssize;
 849         faultcode_t res = 0;
 850         caddr_t addrsav;
 851         struct seg *segsav;
 852         int as_lock_held;
 853         klwp_t *lwp = ttolwp(curthread);
 854         zone_t *zonep = curzone;
 855 
 856 retry:
 857         /*
 858          * Indicate that the lwp is not to be stopped while waiting for a
 859          * pagefault.  This is to avoid deadlock while debugging a process
 860          * via /proc over NFS (in particular).
 861          */
 862         if (lwp != NULL)
 863                 lwp->lwp_nostop++;
 864 
 865         /*
 866          * same length must be used when we softlock and softunlock.  We
 867          * don't support softunlocking lengths less than the original length
 868          * when there is largepage support.  See seg_dev.c for more
 869          * comments.
 870          */
 871         switch (type) {
 872 
 873         case F_SOFTLOCK:
 874                 CPU_STATS_ADD_K(vm, softlock, 1);
 875                 break;
 876 
 877         case F_SOFTUNLOCK:
 878                 break;
 879 
 880         case F_PROT:
 881                 CPU_STATS_ADD_K(vm, prot_fault, 1);
 882                 break;
 883 
 884         case F_INVAL:
 885                 CPU_STATS_ENTER_K();
 886                 CPU_STATS_ADDQ(CPU, vm, as_fault, 1);
 887                 if (as == &kas)
 888                         CPU_STATS_ADDQ(CPU, vm, kernel_asflt, 1);
 889                 CPU_STATS_EXIT_K();
 890                 if (zonep->zone_pg_flt_delay != 0) {
 891                         /*
 892                          * The zone in which this process is running
 893                          * is currently over it's physical memory cap.
 894                          * Throttle page faults to help the user-land
 895                          * memory capper catch up. Note that
 896                          * drv_usectohz() rounds up.
 897                          */
 898                         atomic_add_64(&zonep->zone_pf_throttle, 1);
 899                         atomic_add_64(&zonep->zone_pf_throttle_usec,
 900                             zonep->zone_pg_flt_delay);
 901                         if (zonep->zone_pg_flt_delay < TICK_TO_USEC(1))
 902                                 drv_usecwait(zonep->zone_pg_flt_delay);
 903                         else
 904                                 delay(drv_usectohz(zonep->zone_pg_flt_delay));
 905                 }
 906                 break;
 907         }
 908 
 909         /* Kernel probe */
 910         TNF_PROBE_3(address_fault, "vm pagefault", /* CSTYLED */,
 911             tnf_opaque, address,        addr,
 912             tnf_fault_type,     fault_type,     type,
 913             tnf_seg_access,     access,         rw);
 914 
 915         raddr = (caddr_t)((uintptr_t)addr & (uintptr_t)PAGEMASK);
 916         rsize = (((size_t)(addr + size) + PAGEOFFSET) & PAGEMASK) -
 917             (size_t)raddr;
 918 
 919         /*
 920          * XXX -- Don't grab the as lock for segkmap. We should grab it for
 921          * correctness, but then we could be stuck holding this lock for
 922          * a LONG time if the fault needs to be resolved on a slow
 923          * filesystem, and then no-one will be able to exec new commands,
 924          * as exec'ing requires the write lock on the as.
 925          */
 
 |