ia64/xen-unstable

changeset 17425:c99dee5e44d6

x86 libxc: Fix mlock sizes in libxc around vcpu context hypercalls
backing off to the old behaviour if we fail.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Apr 09 16:24:46 2008 +0100 (2008-04-09)
parents 64f81cd158d4
children f410fa7f379c
files tools/libxc/xc_domain.c
line diff
     1.1 --- a/tools/libxc/xc_domain.c	Wed Apr 09 16:11:34 2008 +0100
     1.2 +++ b/tools/libxc/xc_domain.c	Wed Apr 09 16:24:46 2008 +0100
     1.3 @@ -7,6 +7,7 @@
     1.4   */
     1.5  
     1.6  #include "xc_private.h"
     1.7 +#include "xg_save_restore.h"
     1.8  #include <xen/memory.h>
     1.9  #include <xen/hvm/hvm_op.h>
    1.10  
    1.11 @@ -301,18 +302,27 @@ int xc_vcpu_getcontext(int xc_handle,
    1.12  {
    1.13      int rc;
    1.14      DECLARE_DOMCTL;
    1.15 +    size_t sz = sizeof(vcpu_guest_context_either_t);
    1.16  
    1.17      domctl.cmd = XEN_DOMCTL_getvcpucontext;
    1.18      domctl.domain = (domid_t)domid;
    1.19      domctl.u.vcpucontext.vcpu   = (uint16_t)vcpu;
    1.20      set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
    1.21  
    1.22 -    if ( (rc = lock_pages(ctxt, sizeof(*ctxt))) != 0 )
    1.23 -        return rc;
    1.24 +    /*
    1.25 +     * We may be asked to lock either a 32-bit or a 64-bit context. Lock the
    1.26 +     * larger of the two if possible, otherwise fall back to native size.
    1.27 +     */
    1.28 +    if ( (rc = lock_pages(ctxt, sz)) != 0 )
    1.29 +    {
    1.30 +        sz = sizeof(*ctxt);
    1.31 +        if ( (rc = lock_pages(ctxt, sz)) != 0 )
    1.32 +            return rc;
    1.33 +    }
    1.34  
    1.35      rc = do_domctl(xc_handle, &domctl);
    1.36  
    1.37 -    unlock_pages(ctxt, sizeof(*ctxt));
    1.38 +    unlock_pages(ctxt, sz);
    1.39  
    1.40      return rc;
    1.41  }
    1.42 @@ -620,19 +630,28 @@ int xc_vcpu_setcontext(int xc_handle,
    1.43  {
    1.44      DECLARE_DOMCTL;
    1.45      int rc;
    1.46 +    size_t sz = sizeof(vcpu_guest_context_either_t);
    1.47  
    1.48      domctl.cmd = XEN_DOMCTL_setvcpucontext;
    1.49      domctl.domain = domid;
    1.50      domctl.u.vcpucontext.vcpu = vcpu;
    1.51      set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
    1.52  
    1.53 -    if ( (ctxt != NULL) && ((rc = lock_pages(ctxt, sizeof(*ctxt))) != 0) )
    1.54 -        return rc;
    1.55 +    /*
    1.56 +     * We may be asked to lock either a 32-bit or a 64-bit context. Lock the
    1.57 +     * larger of the two if possible, otherwise fall back to native size.
    1.58 +     */
    1.59 +    if ( (ctxt != NULL) && (rc = lock_pages(ctxt, sz)) != 0 )
    1.60 +    {
    1.61 +        sz = sizeof(*ctxt);
    1.62 +        if ( (rc = lock_pages(ctxt, sz)) != 0 )
    1.63 +            return rc;
    1.64 +    }
    1.65  
    1.66      rc = do_domctl(xc_handle, &domctl);
    1.67  
    1.68      if ( ctxt != NULL )
    1.69 -        unlock_pages(ctxt, sizeof(*ctxt));
    1.70 +        unlock_pages(ctxt, sz);
    1.71  
    1.72      return rc;
    1.73  }