ia64/xen-unstable

changeset 10944:43ff88825b1a

[XEN] Allow add_to_physmap to be applied to DOMID_SELF.
Also sanitise handling of existing mappings of Xen heap
frames.
Signed-off-by: Steven Smith <ssmith@xensource.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu Aug 03 14:20:45 2006 +0100 (2006-08-03)
parents d7242c3a2906
children 164ad1411255
files xen/arch/x86/mm.c
line diff
     1.1 --- a/xen/arch/x86/mm.c	Thu Aug 03 14:02:29 2006 +0100
     1.2 +++ b/xen/arch/x86/mm.c	Thu Aug 03 14:20:45 2006 +0100
     1.3 @@ -2976,13 +2976,20 @@ long arch_memory_op(int op, XEN_GUEST_HA
     1.4      case XENMEM_add_to_physmap:
     1.5      {
     1.6          struct xen_add_to_physmap xatp;
     1.7 -        unsigned long mfn = 0, gpfn;
     1.8 +        unsigned long prev_mfn, mfn = 0, gpfn;
     1.9          struct domain *d;
    1.10  
    1.11          if ( copy_from_guest(&xatp, arg, 1) )
    1.12              return -EFAULT;
    1.13  
    1.14 -        if ( (d = find_domain_by_id(xatp.domid)) == NULL )
    1.15 +        if ( xatp.domid == DOMID_SELF )
    1.16 +        {
    1.17 +            d = current->domain;
    1.18 +            get_knownalive_domain(d);
    1.19 +        }
    1.20 +        else if ( !IS_PRIV(current->domain) )
    1.21 +            return -EPERM;
    1.22 +        else if ( (d = find_domain_by_id(xatp.domid)) == NULL )
    1.23              return -ESRCH;
    1.24  
    1.25          switch ( xatp.space )
    1.26 @@ -3008,8 +3015,16 @@ long arch_memory_op(int op, XEN_GUEST_HA
    1.27          LOCK_BIGLOCK(d);
    1.28  
    1.29          /* Remove previously mapped page if it was present. */
    1.30 -        if ( mfn_valid(gmfn_to_mfn(d, xatp.gpfn)) )
    1.31 -            guest_remove_page(d, xatp.gpfn);
    1.32 +        prev_mfn = gmfn_to_mfn(d, xatp.gpfn);
    1.33 +        if ( mfn_valid(prev_mfn) )
    1.34 +        {
    1.35 +            if ( IS_XEN_HEAP_FRAME(mfn_to_page(prev_mfn)) )
    1.36 +                /* Xen heap frames are simply unhooked from this phys slot. */
    1.37 +                guest_physmap_remove_page(d, xatp.gpfn, prev_mfn);
    1.38 +            else
    1.39 +                /* Normal domain memory is freed, to avoid leaking memory. */
    1.40 +                guest_remove_page(d, xatp.gpfn);
    1.41 +        }
    1.42  
    1.43          /* Unmap from old location, if any. */
    1.44          gpfn = get_gpfn_from_mfn(mfn);