direct-io.hg

changeset 11857:e292f0df2d96

[SOLARIS] Don't mlock() hypercall buffers.

On solaris mlock requires a page aligned address and mlock doesn't
ensure the pages won't minor page fault.

Signed-off-by: Mark Johnson <mark.johnson@sun.com>
author kfraser@localhost.localdomain
date Mon Oct 23 09:52:51 2006 +0100 (2006-10-23)
parents 8113c55a6efd
children da5997fcc070
files tools/libxc/xc_acm.c tools/libxc/xc_domain.c tools/libxc/xc_evtchn.c tools/libxc/xc_hvm_build.c tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_linux_save.c tools/libxc/xc_misc.c tools/libxc/xc_private.c tools/libxc/xc_private.h tools/libxc/xc_tbuf.c tools/libxc/xg_private.c tools/misc/xenperf.c
line diff
     1.1 --- a/tools/libxc/xc_acm.c	Sun Oct 22 17:38:59 2006 +0100
     1.2 +++ b/tools/libxc/xc_acm.c	Mon Oct 23 09:52:51 2006 +0100
     1.3 @@ -24,12 +24,12 @@ int xc_acm_op(int xc_handle, int cmd, vo
     1.4      hypercall.arg[0] = cmd;
     1.5      hypercall.arg[1] = (unsigned long) arg;
     1.6  
     1.7 -    if (mlock(arg, arg_size) != 0) {
     1.8 -        PERROR("xc_acm_op: arg mlock failed");
     1.9 +    if (lock_pages(arg, arg_size) != 0) {
    1.10 +        PERROR("xc_acm_op: arg lock failed");
    1.11          goto out;
    1.12      }
    1.13      ret = do_xen_hypercall(xc_handle, &hypercall);
    1.14 -    safe_munlock(arg, arg_size);
    1.15 +    unlock_pages(arg, arg_size);
    1.16   out:
    1.17      return ret;
    1.18  }
     2.1 --- a/tools/libxc/xc_domain.c	Sun Oct 22 17:38:59 2006 +0100
     2.2 +++ b/tools/libxc/xc_domain.c	Mon Oct 23 09:52:51 2006 +0100
     2.3 @@ -72,7 +72,7 @@ int xc_domain_shutdown(int xc_handle,
     2.4      arg.domain_id = domid;
     2.5      arg.reason = reason;
     2.6  
     2.7 -    if ( mlock(&arg, sizeof(arg)) != 0 )
     2.8 +    if ( lock_pages(&arg, sizeof(arg)) != 0 )
     2.9      {
    2.10          PERROR("Could not lock memory for Xen hypercall");
    2.11          goto out1;
    2.12 @@ -80,7 +80,7 @@ int xc_domain_shutdown(int xc_handle,
    2.13  
    2.14      ret = do_xen_hypercall(xc_handle, &hypercall);
    2.15  
    2.16 -    safe_munlock(&arg, sizeof(arg));
    2.17 +    unlock_pages(&arg, sizeof(arg));
    2.18  
    2.19   out1:
    2.20      return ret;
    2.21 @@ -103,7 +103,7 @@ int xc_vcpu_setaffinity(int xc_handle,
    2.22                           (uint8_t *)&cpumap);
    2.23      domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
    2.24      
    2.25 -    if ( mlock(&cpumap, sizeof(cpumap)) != 0 )
    2.26 +    if ( lock_pages(&cpumap, sizeof(cpumap)) != 0 )
    2.27      {
    2.28          PERROR("Could not lock memory for Xen hypercall");
    2.29          goto out;
    2.30 @@ -111,7 +111,7 @@ int xc_vcpu_setaffinity(int xc_handle,
    2.31  
    2.32      ret = do_domctl(xc_handle, &domctl);
    2.33  
    2.34 -    safe_munlock(&cpumap, sizeof(cpumap));
    2.35 +    unlock_pages(&cpumap, sizeof(cpumap));
    2.36  
    2.37   out:
    2.38      return ret;
    2.39 @@ -134,7 +134,7 @@ int xc_vcpu_getaffinity(int xc_handle,
    2.40                           (uint8_t *)cpumap);
    2.41      domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8;
    2.42      
    2.43 -    if ( mlock(cpumap, sizeof(*cpumap)) != 0 )
    2.44 +    if ( lock_pages(cpumap, sizeof(*cpumap)) != 0 )
    2.45      {
    2.46          PERROR("Could not lock memory for Xen hypercall");
    2.47          goto out;
    2.48 @@ -142,7 +142,7 @@ int xc_vcpu_getaffinity(int xc_handle,
    2.49  
    2.50      ret = do_domctl(xc_handle, &domctl);
    2.51  
    2.52 -    safe_munlock(cpumap, sizeof(*cpumap));
    2.53 +    unlock_pages(cpumap, sizeof(*cpumap));
    2.54  
    2.55   out:
    2.56      return ret;
    2.57 @@ -213,7 +213,7 @@ int xc_domain_getinfolist(int xc_handle,
    2.58      int ret = 0;
    2.59      DECLARE_SYSCTL;
    2.60  
    2.61 -    if ( mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
    2.62 +    if ( lock_pages(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
    2.63          return -1;
    2.64  
    2.65      sysctl.cmd = XEN_SYSCTL_getdomaininfolist;
    2.66 @@ -226,8 +226,7 @@ int xc_domain_getinfolist(int xc_handle,
    2.67      else
    2.68          ret = sysctl.u.getdomaininfolist.num_domains;
    2.69  
    2.70 -    if ( munlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
    2.71 -        ret = -1;
    2.72 +    unlock_pages(info, max_domains*sizeof(xc_domaininfo_t));
    2.73  
    2.74      return ret;
    2.75  }
    2.76 @@ -245,12 +244,12 @@ int xc_vcpu_getcontext(int xc_handle,
    2.77      domctl.u.vcpucontext.vcpu   = (uint16_t)vcpu;
    2.78      set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
    2.79  
    2.80 -    if ( (rc = mlock(ctxt, sizeof(*ctxt))) != 0 )
    2.81 +    if ( (rc = lock_pages(ctxt, sizeof(*ctxt))) != 0 )
    2.82          return rc;
    2.83  
    2.84      rc = do_domctl(xc_handle, &domctl);
    2.85  
    2.86 -    safe_munlock(ctxt, sizeof(*ctxt));
    2.87 +    unlock_pages(ctxt, sizeof(*ctxt));
    2.88  
    2.89      return rc;
    2.90  }
    2.91 @@ -512,12 +511,12 @@ int xc_vcpu_setcontext(int xc_handle,
    2.92      domctl.u.vcpucontext.vcpu = vcpu;
    2.93      set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
    2.94  
    2.95 -    if ( (rc = mlock(ctxt, sizeof(*ctxt))) != 0 )
    2.96 +    if ( (rc = lock_pages(ctxt, sizeof(*ctxt))) != 0 )
    2.97          return rc;
    2.98  
    2.99      rc = do_domctl(xc_handle, &domctl);
   2.100  
   2.101 -    safe_munlock(ctxt, sizeof(*ctxt));
   2.102 +    unlock_pages(ctxt, sizeof(*ctxt));
   2.103  
   2.104      return rc;
   2.105  
     3.1 --- a/tools/libxc/xc_evtchn.c	Sun Oct 22 17:38:59 2006 +0100
     3.2 +++ b/tools/libxc/xc_evtchn.c	Mon Oct 23 09:52:51 2006 +0100
     3.3 @@ -18,16 +18,16 @@ static int do_evtchn_op(int xc_handle, i
     3.4      hypercall.arg[0] = cmd;
     3.5      hypercall.arg[1] = (unsigned long)arg;
     3.6  
     3.7 -    if ( mlock(arg, arg_size) != 0 )
     3.8 +    if ( lock_pages(arg, arg_size) != 0 )
     3.9      {
    3.10 -        PERROR("do_evtchn_op: arg mlock failed");
    3.11 +        PERROR("do_evtchn_op: arg lock failed");
    3.12          goto out;
    3.13      }
    3.14  
    3.15      if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
    3.16          ERROR("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d", ret);
    3.17  
    3.18 -    safe_munlock(arg, arg_size);
    3.19 +    unlock_pages(arg, arg_size);
    3.20   out:
    3.21      return ret;
    3.22  }
     4.1 --- a/tools/libxc/xc_hvm_build.c	Sun Oct 22 17:38:59 2006 +0100
     4.2 +++ b/tools/libxc/xc_hvm_build.c	Mon Oct 23 09:52:51 2006 +0100
     4.3 @@ -38,13 +38,13 @@ static void xc_set_hvm_param(int handle,
     4.4      arg.domid = dom;
     4.5      arg.index = param;
     4.6      arg.value = value;
     4.7 -    if ( mlock(&arg, sizeof(arg)) != 0 )
     4.8 +    if ( lock_pages(&arg, sizeof(arg)) != 0 )
     4.9      {
    4.10          PERROR("Could not lock memory for set parameter");
    4.11          return;
    4.12      }
    4.13      rc = do_xen_hypercall(handle, &hypercall);
    4.14 -    safe_munlock(&arg, sizeof(arg));
    4.15 +    unlock_pages(&arg, sizeof(arg));
    4.16      if (rc < 0)
    4.17          PERROR("set HVM parameter failed (%d)", rc);
    4.18  }
    4.19 @@ -403,7 +403,7 @@ static int xc_hvm_build_internal(int xc_
    4.20          goto error_out;
    4.21      }
    4.22  
    4.23 -    if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
    4.24 +    if ( lock_pages(&st_ctxt, sizeof(st_ctxt) ) )
    4.25      {
    4.26          PERROR("%s: ctxt mlock failed", __func__);
    4.27          return 1;
     5.1 --- a/tools/libxc/xc_linux_build.c	Sun Oct 22 17:38:59 2006 +0100
     5.2 +++ b/tools/libxc/xc_linux_build.c	Mon Oct 23 09:52:51 2006 +0100
     5.3 @@ -1140,9 +1140,9 @@ static int xc_linux_build_internal(int x
     5.4      memset(&st_ctxt, 0, sizeof(st_ctxt));
     5.5  #endif
     5.6  
     5.7 -    if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
     5.8 +    if ( lock_pages(&st_ctxt, sizeof(st_ctxt) ) )
     5.9      {
    5.10 -        PERROR("%s: ctxt mlock failed", __func__);
    5.11 +        PERROR("%s: ctxt lock failed", __func__);
    5.12          return 1;
    5.13      }
    5.14  
     6.1 --- a/tools/libxc/xc_linux_restore.c	Sun Oct 22 17:38:59 2006 +0100
     6.2 +++ b/tools/libxc/xc_linux_restore.c	Mon Oct 23 09:52:51 2006 +0100
     6.3 @@ -162,9 +162,9 @@ int xc_linux_restore(int xc_handle, int 
     6.4          return 1;
     6.5      }
     6.6  
     6.7 -    if (mlock(&ctxt, sizeof(ctxt))) {
     6.8 +    if (lock_pages(&ctxt, sizeof(ctxt))) {
     6.9          /* needed for build domctl, but might as well do early */
    6.10 -        ERROR("Unable to mlock ctxt");
    6.11 +        ERROR("Unable to lock ctxt");
    6.12          return 1;
    6.13      }
    6.14  
    6.15 @@ -251,8 +251,8 @@ int xc_linux_restore(int xc_handle, int 
    6.16          goto out;
    6.17      }
    6.18  
    6.19 -    if (mlock(region_mfn, sizeof(xen_pfn_t) * MAX_BATCH_SIZE)) {
    6.20 -        ERROR("Could not mlock region_mfn");
    6.21 +    if (lock_pages(region_mfn, sizeof(xen_pfn_t) * MAX_BATCH_SIZE)) {
    6.22 +        ERROR("Could not lock region_mfn");
    6.23          goto out;
    6.24      }
    6.25  
     7.1 --- a/tools/libxc/xc_linux_save.c	Sun Oct 22 17:38:59 2006 +0100
     7.2 +++ b/tools/libxc/xc_linux_save.c	Mon Oct 23 09:52:51 2006 +0100
     7.3 @@ -628,8 +628,8 @@ int xc_linux_save(int xc_handle, int io_
     7.4          return 1;
     7.5      }
     7.6  
     7.7 -    if (mlock(&ctxt, sizeof(ctxt))) {
     7.8 -        ERROR("Unable to mlock ctxt");
     7.9 +    if (lock_pages(&ctxt, sizeof(ctxt))) {
    7.10 +        ERROR("Unable to lock ctxt");
    7.11          return 1;
    7.12      }
    7.13  
    7.14 @@ -767,14 +767,14 @@ int xc_linux_save(int xc_handle, int io_
    7.15  
    7.16      memset(to_send, 0xff, BITMAP_SIZE);
    7.17  
    7.18 -    if (mlock(to_send, BITMAP_SIZE)) {
    7.19 -        ERROR("Unable to mlock to_send");
    7.20 +    if (lock_pages(to_send, BITMAP_SIZE)) {
    7.21 +        ERROR("Unable to lock to_send");
    7.22          return 1;
    7.23      }
    7.24  
    7.25      /* (to fix is local only) */
    7.26 -    if (mlock(to_skip, BITMAP_SIZE)) {
    7.27 -        ERROR("Unable to mlock to_skip");
    7.28 +    if (lock_pages(to_skip, BITMAP_SIZE)) {
    7.29 +        ERROR("Unable to lock to_skip");
    7.30          return 1;
    7.31      }
    7.32  
    7.33 @@ -790,8 +790,8 @@ int xc_linux_save(int xc_handle, int io_
    7.34          goto out;
    7.35      }
    7.36  
    7.37 -    if (mlock(pfn_type, MAX_BATCH_SIZE * sizeof(*pfn_type))) {
    7.38 -        ERROR("Unable to mlock");
    7.39 +    if (lock_pages(pfn_type, MAX_BATCH_SIZE * sizeof(*pfn_type))) {
    7.40 +        ERROR("Unable to lock");
    7.41          goto out;
    7.42      }
    7.43  
     8.1 --- a/tools/libxc/xc_misc.c	Sun Oct 22 17:38:59 2006 +0100
     8.2 +++ b/tools/libxc/xc_misc.c	Mon Oct 23 09:52:51 2006 +0100
     8.3 @@ -21,13 +21,13 @@ int xc_readconsolering(int xc_handle,
     8.4      sysctl.u.readconsole.count  = nr_chars;
     8.5      sysctl.u.readconsole.clear  = clear;
     8.6  
     8.7 -    if ( (ret = mlock(buffer, nr_chars)) != 0 )
     8.8 +    if ( (ret = lock_pages(buffer, nr_chars)) != 0 )
     8.9          return ret;
    8.10  
    8.11      if ( (ret = do_sysctl(xc_handle, &sysctl)) == 0 )
    8.12          *pnr_chars = sysctl.u.readconsole.count;
    8.13  
    8.14 -    safe_munlock(buffer, nr_chars);
    8.15 +    unlock_pages(buffer, nr_chars);
    8.16  
    8.17      return ret;
    8.18  }
     9.1 --- a/tools/libxc/xc_private.c	Sun Oct 22 17:38:59 2006 +0100
     9.2 +++ b/tools/libxc/xc_private.c	Mon Oct 23 09:52:51 2006 +0100
     9.3 @@ -7,7 +7,23 @@
     9.4  #include <inttypes.h>
     9.5  #include "xc_private.h"
     9.6  
     9.7 -/* NB: arr must be mlock'ed */
     9.8 +int lock_pages(void *addr, size_t len)
     9.9 +{
    9.10 +      int e = 0;
    9.11 +#ifndef __sun__
    9.12 +      e = mlock(addr, len);
    9.13 +#endif
    9.14 +      return (e);
    9.15 +}
    9.16 +
    9.17 +void unlock_pages(void *addr, size_t len)
    9.18 +{
    9.19 +#ifndef __sun__
    9.20 +	safe_munlock(addr, len);
    9.21 +#endif
    9.22 +}
    9.23 +
    9.24 +/* NB: arr must be locked */
    9.25  int xc_get_pfn_type_batch(int xc_handle,
    9.26                            uint32_t dom, int num, unsigned long *arr)
    9.27  {
    9.28 @@ -51,7 +67,7 @@ int xc_mmuext_op(
    9.29      hypercall.arg[2] = (unsigned long)0;
    9.30      hypercall.arg[3] = (unsigned long)dom;
    9.31  
    9.32 -    if ( mlock(op, nr_ops*sizeof(*op)) != 0 )
    9.33 +    if ( lock_pages(op, nr_ops*sizeof(*op)) != 0 )
    9.34      {
    9.35          PERROR("Could not lock memory for Xen hypercall");
    9.36          goto out1;
    9.37 @@ -59,7 +75,7 @@ int xc_mmuext_op(
    9.38  
    9.39      ret = do_xen_hypercall(xc_handle, &hypercall);
    9.40  
    9.41 -    safe_munlock(op, nr_ops*sizeof(*op));
    9.42 +    unlock_pages(op, nr_ops*sizeof(*op));
    9.43  
    9.44   out1:
    9.45      return ret;
    9.46 @@ -79,9 +95,9 @@ static int flush_mmu_updates(int xc_hand
    9.47      hypercall.arg[2] = 0;
    9.48      hypercall.arg[3] = mmu->subject;
    9.49  
    9.50 -    if ( mlock(mmu->updates, sizeof(mmu->updates)) != 0 )
    9.51 +    if ( lock_pages(mmu->updates, sizeof(mmu->updates)) != 0 )
    9.52      {
    9.53 -        PERROR("flush_mmu_updates: mmu updates mlock failed");
    9.54 +        PERROR("flush_mmu_updates: mmu updates lock_pages failed");
    9.55          err = 1;
    9.56          goto out;
    9.57      }
    9.58 @@ -94,7 +110,7 @@ static int flush_mmu_updates(int xc_hand
    9.59  
    9.60      mmu->idx = 0;
    9.61  
    9.62 -    safe_munlock(mmu->updates, sizeof(mmu->updates));
    9.63 +    unlock_pages(mmu->updates, sizeof(mmu->updates));
    9.64  
    9.65   out:
    9.66      return err;
    9.67 @@ -149,62 +165,62 @@ int xc_memory_op(int xc_handle,
    9.68      case XENMEM_increase_reservation:
    9.69      case XENMEM_decrease_reservation:
    9.70      case XENMEM_populate_physmap:
    9.71 -        if ( mlock(reservation, sizeof(*reservation)) != 0 )
    9.72 +        if ( lock_pages(reservation, sizeof(*reservation)) != 0 )
    9.73          {
    9.74 -            PERROR("Could not mlock");
    9.75 +            PERROR("Could not lock");
    9.76              goto out1;
    9.77          }
    9.78          get_xen_guest_handle(extent_start, reservation->extent_start);
    9.79          if ( (extent_start != NULL) &&
    9.80 -             (mlock(extent_start,
    9.81 +             (lock_pages(extent_start,
    9.82                      reservation->nr_extents * sizeof(xen_pfn_t)) != 0) )
    9.83          {
    9.84 -            PERROR("Could not mlock");
    9.85 -            safe_munlock(reservation, sizeof(*reservation));
    9.86 +            PERROR("Could not lock");
    9.87 +            unlock_pages(reservation, sizeof(*reservation));
    9.88              goto out1;
    9.89          }
    9.90          break;
    9.91      case XENMEM_machphys_mfn_list:
    9.92 -        if ( mlock(xmml, sizeof(*xmml)) != 0 )
    9.93 +        if ( lock_pages(xmml, sizeof(*xmml)) != 0 )
    9.94          {
    9.95 -            PERROR("Could not mlock");
    9.96 +            PERROR("Could not lock");
    9.97              goto out1;
    9.98          }
    9.99          get_xen_guest_handle(extent_start, xmml->extent_start);
   9.100 -        if ( mlock(extent_start,
   9.101 +        if ( lock_pages(extent_start,
   9.102                     xmml->max_extents * sizeof(xen_pfn_t)) != 0 )
   9.103          {
   9.104 -            PERROR("Could not mlock");
   9.105 -            safe_munlock(xmml, sizeof(*xmml));
   9.106 +            PERROR("Could not lock");
   9.107 +            unlock_pages(xmml, sizeof(*xmml));
   9.108              goto out1;
   9.109          }
   9.110          break;
   9.111      case XENMEM_add_to_physmap:
   9.112 -        if ( mlock(arg, sizeof(struct xen_add_to_physmap)) )
   9.113 +        if ( lock_pages(arg, sizeof(struct xen_add_to_physmap)) )
   9.114          {
   9.115 -            PERROR("Could not mlock");
   9.116 +            PERROR("Could not lock");
   9.117              goto out1;
   9.118          }
   9.119          break;
   9.120      case XENMEM_translate_gpfn_list:
   9.121 -        if ( mlock(trans, sizeof(*trans)) != 0 )
   9.122 +        if ( lock_pages(trans, sizeof(*trans)) != 0 )
   9.123          {
   9.124 -            PERROR("Could not mlock");
   9.125 +            PERROR("Could not lock");
   9.126              goto out1;
   9.127          }
   9.128          get_xen_guest_handle(gpfn_list, trans->gpfn_list);
   9.129 -        if ( mlock(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
   9.130 +        if ( lock_pages(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
   9.131          {
   9.132 -            PERROR("Could not mlock");
   9.133 -            safe_munlock(trans, sizeof(*trans));
   9.134 +            PERROR("Could not lock");
   9.135 +            unlock_pages(trans, sizeof(*trans));
   9.136              goto out1;
   9.137          }
   9.138          get_xen_guest_handle(mfn_list, trans->mfn_list);
   9.139 -        if ( mlock(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
   9.140 +        if ( lock_pages(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
   9.141          {
   9.142 -            PERROR("Could not mlock");
   9.143 -            safe_munlock(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
   9.144 -            safe_munlock(trans, sizeof(*trans));
   9.145 +            PERROR("Could not lock");
   9.146 +            unlock_pages(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
   9.147 +            unlock_pages(trans, sizeof(*trans));
   9.148              goto out1;
   9.149          }
   9.150          break;
   9.151 @@ -217,27 +233,27 @@ int xc_memory_op(int xc_handle,
   9.152      case XENMEM_increase_reservation:
   9.153      case XENMEM_decrease_reservation:
   9.154      case XENMEM_populate_physmap:
   9.155 -        safe_munlock(reservation, sizeof(*reservation));
   9.156 +        unlock_pages(reservation, sizeof(*reservation));
   9.157          get_xen_guest_handle(extent_start, reservation->extent_start);
   9.158          if ( extent_start != NULL )
   9.159 -            safe_munlock(extent_start,
   9.160 +            unlock_pages(extent_start,
   9.161                           reservation->nr_extents * sizeof(xen_pfn_t));
   9.162          break;
   9.163      case XENMEM_machphys_mfn_list:
   9.164 -        safe_munlock(xmml, sizeof(*xmml));
   9.165 +        unlock_pages(xmml, sizeof(*xmml));
   9.166          get_xen_guest_handle(extent_start, xmml->extent_start);
   9.167 -        safe_munlock(extent_start,
   9.168 +        unlock_pages(extent_start,
   9.169                       xmml->max_extents * sizeof(xen_pfn_t));
   9.170          break;
   9.171      case XENMEM_add_to_physmap:
   9.172 -        safe_munlock(arg, sizeof(struct xen_add_to_physmap));
   9.173 +        unlock_pages(arg, sizeof(struct xen_add_to_physmap));
   9.174          break;
   9.175      case XENMEM_translate_gpfn_list:
   9.176              get_xen_guest_handle(mfn_list, trans->mfn_list);
   9.177 -            safe_munlock(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
   9.178 +            unlock_pages(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
   9.179              get_xen_guest_handle(gpfn_list, trans->gpfn_list);
   9.180 -            safe_munlock(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
   9.181 -            safe_munlock(trans, sizeof(*trans));
   9.182 +            unlock_pages(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
   9.183 +            unlock_pages(trans, sizeof(*trans));
   9.184          break;
   9.185      }
   9.186  
   9.187 @@ -279,15 +295,15 @@ int xc_get_pfn_list(int xc_handle,
   9.188      memset(pfn_buf, 0, max_pfns * sizeof(xen_pfn_t));
   9.189  #endif
   9.190  
   9.191 -    if ( mlock(pfn_buf, max_pfns * sizeof(xen_pfn_t)) != 0 )
   9.192 +    if ( lock_pages(pfn_buf, max_pfns * sizeof(xen_pfn_t)) != 0 )
   9.193      {
   9.194 -        PERROR("xc_get_pfn_list: pfn_buf mlock failed");
   9.195 +        PERROR("xc_get_pfn_list: pfn_buf lock failed");
   9.196          return -1;
   9.197      }
   9.198  
   9.199      ret = do_domctl(xc_handle, &domctl);
   9.200  
   9.201 -    safe_munlock(pfn_buf, max_pfns * sizeof(xen_pfn_t));
   9.202 +    unlock_pages(pfn_buf, max_pfns * sizeof(xen_pfn_t));
   9.203  
   9.204  #if 0
   9.205  #ifdef DEBUG
   9.206 @@ -419,7 +435,7 @@ int xc_version(int xc_handle, int cmd, v
   9.207          break;
   9.208      }
   9.209  
   9.210 -    if ( (argsize != 0) && (mlock(arg, argsize) != 0) )
   9.211 +    if ( (argsize != 0) && (lock_pages(arg, argsize) != 0) )
   9.212      {
   9.213          PERROR("Could not lock memory for version hypercall");
   9.214          return -ENOMEM;
   9.215 @@ -433,7 +449,7 @@ int xc_version(int xc_handle, int cmd, v
   9.216      rc = do_xen_version(xc_handle, cmd, arg);
   9.217  
   9.218      if ( argsize != 0 )
   9.219 -        safe_munlock(arg, argsize);
   9.220 +        unlock_pages(arg, argsize);
   9.221  
   9.222      return rc;
   9.223  }
    10.1 --- a/tools/libxc/xc_private.h	Sun Oct 22 17:38:59 2006 +0100
    10.2 +++ b/tools/libxc/xc_private.h	Mon Oct 23 09:52:51 2006 +0100
    10.3 @@ -66,6 +66,9 @@ do {                                    
    10.4      errno = __saved_errno;                      \
    10.5  } while (0)
    10.6  
    10.7 +int lock_pages(void *addr, size_t len);
    10.8 +void unlock_pages(void *addr, size_t len);
    10.9 +
   10.10  #define PERROR(_m, _a...)                               \
   10.11  do {                                                    \
   10.12      int __saved_errno = errno;                          \
   10.13 @@ -104,7 +107,7 @@ static inline int do_domctl(int xc_handl
   10.14      hypercall.op     = __HYPERVISOR_domctl;
   10.15      hypercall.arg[0] = (unsigned long)domctl;
   10.16  
   10.17 -    if ( mlock(domctl, sizeof(*domctl)) != 0 )
   10.18 +    if ( lock_pages(domctl, sizeof(*domctl)) != 0 )
   10.19      {
   10.20          PERROR("Could not lock memory for Xen hypercall");
   10.21          goto out1;
   10.22 @@ -117,7 +120,7 @@ static inline int do_domctl(int xc_handl
   10.23                      " rebuild the user-space tool set?\n");
   10.24      }
   10.25  
   10.26 -    safe_munlock(domctl, sizeof(*domctl));
   10.27 +    unlock_pages(domctl, sizeof(*domctl));
   10.28  
   10.29   out1:
   10.30      return ret;
   10.31 @@ -133,7 +136,7 @@ static inline int do_sysctl(int xc_handl
   10.32      hypercall.op     = __HYPERVISOR_sysctl;
   10.33      hypercall.arg[0] = (unsigned long)sysctl;
   10.34  
   10.35 -    if ( mlock(sysctl, sizeof(*sysctl)) != 0 )
   10.36 +    if ( lock_pages(sysctl, sizeof(*sysctl)) != 0 )
   10.37      {
   10.38          PERROR("Could not lock memory for Xen hypercall");
   10.39          goto out1;
   10.40 @@ -146,7 +149,7 @@ static inline int do_sysctl(int xc_handl
   10.41                      " rebuild the user-space tool set?\n");
   10.42      }
   10.43  
   10.44 -    safe_munlock(sysctl, sizeof(*sysctl));
   10.45 +    unlock_pages(sysctl, sizeof(*sysctl));
   10.46  
   10.47   out1:
   10.48      return ret;
    11.1 --- a/tools/libxc/xc_tbuf.c	Sun Oct 22 17:38:59 2006 +0100
    11.2 +++ b/tools/libxc/xc_tbuf.c	Mon Oct 23 09:52:51 2006 +0100
    11.3 @@ -104,7 +104,7 @@ int xc_tbuf_set_cpu_mask(int xc_handle, 
    11.4      set_xen_guest_handle(sysctl.u.tbuf_op.cpu_mask.bitmap, (uint8_t *)&mask);
    11.5      sysctl.u.tbuf_op.cpu_mask.nr_cpus = sizeof(mask) * 8;
    11.6  
    11.7 -    if ( mlock(&mask, sizeof(mask)) != 0 )
    11.8 +    if ( lock_pages(&mask, sizeof(mask)) != 0 )
    11.9      {
   11.10          PERROR("Could not lock memory for Xen hypercall");
   11.11          goto out;
   11.12 @@ -112,7 +112,7 @@ int xc_tbuf_set_cpu_mask(int xc_handle, 
   11.13  
   11.14      ret = do_sysctl(xc_handle, &sysctl);
   11.15  
   11.16 -    safe_munlock(&mask, sizeof(mask));
   11.17 +    unlock_pages(&mask, sizeof(mask));
   11.18  
   11.19   out:
   11.20      return ret;
    12.1 --- a/tools/libxc/xg_private.c	Sun Oct 22 17:38:59 2006 +0100
    12.2 +++ b/tools/libxc/xg_private.c	Mon Oct 23 09:52:51 2006 +0100
    12.3 @@ -11,6 +11,22 @@
    12.4  
    12.5  #include "xg_private.h"
    12.6  
    12.7 +int lock_pages(void *addr, size_t len)
    12.8 +{
    12.9 +    int e = 0;
   12.10 +#ifndef __sun__
   12.11 +    e = mlock(addr, len);
   12.12 +#endif
   12.13 +    return (e);
   12.14 +}
   12.15 +
   12.16 +void unlock_pages(void *addr, size_t len)
   12.17 +{
   12.18 +#ifndef __sun__
   12.19 +    safe_munlock(addr, len);
   12.20 +#endif
   12.21 +}
   12.22 +
   12.23  char *xc_read_image(const char *filename, unsigned long *size)
   12.24  {
   12.25      int kernel_fd = -1;
    13.1 --- a/tools/misc/xenperf.c	Sun Oct 22 17:38:59 2006 +0100
    13.2 +++ b/tools/misc/xenperf.c	Mon Oct 23 09:52:51 2006 +0100
    13.3 @@ -18,6 +18,22 @@
    13.4  #include <errno.h>
    13.5  #include <string.h>
    13.6  
    13.7 +int lock_pages(void *addr, size_t len)
    13.8 +{
    13.9 +    int e = 0;
   13.10 +#ifndef __sun__
   13.11 +    e = mlock(addr, len);
   13.12 +#endif
   13.13 +    return (e);
   13.14 +}
   13.15 +
   13.16 +void unlock_pages(void *addr, size_t len)
   13.17 +{
   13.18 +#ifndef __sun__
   13.19 +	munlock(addr, len);
   13.20 +#endif
   13.21 +}
   13.22 +
   13.23  int main(int argc, char *argv[])
   13.24  {
   13.25      int              i, j, xc_handle;
   13.26 @@ -87,11 +103,11 @@ int main(int argc, char *argv[])
   13.27  	pcv = malloc(sizeof(*pcv) * num_val);
   13.28  
   13.29      if ( pcd == NULL
   13.30 -		 || mlock(pcd, sizeof(*pcd) * num_desc) != 0
   13.31 +		 || lock_pages(pcd, sizeof(*pcd) * num_desc) != 0
   13.32  		 || pcv == NULL
   13.33 -		 || mlock(pcd, sizeof(*pcv) * num_val) != 0)
   13.34 +		 || lock_pages(pcd, sizeof(*pcv) * num_val) != 0)
   13.35      {
   13.36 -        fprintf(stderr, "Could not alloc or mlock buffers: %d (%s)\n",
   13.37 +        fprintf(stderr, "Could not alloc or lock buffers: %d (%s)\n",
   13.38                  errno, strerror(errno));
   13.39          exit(-1);
   13.40      }
   13.41 @@ -104,8 +120,8 @@ int main(int argc, char *argv[])
   13.42          return 1;
   13.43      }
   13.44  
   13.45 -    munlock(pcd, sizeof(*pcd) * num_desc);
   13.46 -    munlock(pcv, sizeof(*pcv) * num_val);
   13.47 +    unlock_pages(pcd, sizeof(*pcd) * num_desc);
   13.48 +    unlock_pages(pcv, sizeof(*pcv) * num_val);
   13.49  
   13.50  	val = pcv;
   13.51      for ( i = 0; i < num_desc; i++ )