From 9e4828ca8b5d6e39023f8cf580b4446a19cc1dcd Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Wed, 9 Apr 2008 16:24:46 +0100 Subject: [PATCH] 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 --- tools/libxc/xc_domain.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 073fe95175..a39f73071f 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -7,6 +7,7 @@ */ #include "xc_private.h" +#include "xg_save_restore.h" #include #include @@ -301,18 +302,27 @@ int xc_vcpu_getcontext(int xc_handle, { int rc; DECLARE_DOMCTL; + size_t sz = sizeof(vcpu_guest_context_either_t); domctl.cmd = XEN_DOMCTL_getvcpucontext; domctl.domain = (domid_t)domid; domctl.u.vcpucontext.vcpu = (uint16_t)vcpu; set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt); - if ( (rc = lock_pages(ctxt, sizeof(*ctxt))) != 0 ) - return rc; + /* + * We may be asked to lock either a 32-bit or a 64-bit context. Lock the + * larger of the two if possible, otherwise fall back to native size. + */ + if ( (rc = lock_pages(ctxt, sz)) != 0 ) + { + sz = sizeof(*ctxt); + if ( (rc = lock_pages(ctxt, sz)) != 0 ) + return rc; + } rc = do_domctl(xc_handle, &domctl); - unlock_pages(ctxt, sizeof(*ctxt)); + unlock_pages(ctxt, sz); return rc; } @@ -620,19 +630,28 @@ int xc_vcpu_setcontext(int xc_handle, { DECLARE_DOMCTL; int rc; + size_t sz = sizeof(vcpu_guest_context_either_t); domctl.cmd = XEN_DOMCTL_setvcpucontext; domctl.domain = domid; domctl.u.vcpucontext.vcpu = vcpu; set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt); - if ( (ctxt != NULL) && ((rc = lock_pages(ctxt, sizeof(*ctxt))) != 0) ) - return rc; + /* + * We may be asked to lock either a 32-bit or a 64-bit context. Lock the + * larger of the two if possible, otherwise fall back to native size. + */ + if ( (ctxt != NULL) && (rc = lock_pages(ctxt, sz)) != 0 ) + { + sz = sizeof(*ctxt); + if ( (rc = lock_pages(ctxt, sz)) != 0 ) + return rc; + } rc = do_domctl(xc_handle, &domctl); if ( ctxt != NULL ) - unlock_pages(ctxt, sizeof(*ctxt)); + unlock_pages(ctxt, sz); return rc; } -- 2.39.5