ia64/xen-unstable

changeset 14300:800f7904d6a4

[IA64] Follow dynamic grant_table for PV-on-HVM on IPF

Signed-off-by: Tsunehisa Doi <Doi.Tsunehisa@jp.fujitsu.com>
author awilliam@xenbuild2.aw
date Mon Mar 12 08:43:56 2007 -0600 (2007-03-12)
parents dc6fbe46ec91
children 9ea0c5f469c8
files xen/arch/ia64/xen/mm.c
line diff
     1.1 --- a/xen/arch/ia64/xen/mm.c	Mon Mar 12 08:42:11 2007 -0600
     1.2 +++ b/xen/arch/ia64/xen/mm.c	Mon Mar 12 08:43:56 2007 -0600
     1.3 @@ -2090,18 +2090,33 @@ arch_memory_op(int op, XEN_GUEST_HANDLE(
     1.4              break;
     1.5          case XENMAPSPACE_grant_table:
     1.6              spin_lock(&d->grant_table->lock);
     1.7 +
     1.8 +            if ((xatp.idx >= nr_grant_frames(d->grant_table)) &&
     1.9 +                (xatp.idx < max_nr_grant_frames))
    1.10 +                gnttab_grow_table(d, xatp.idx + 1);
    1.11 +
    1.12              if (xatp.idx < nr_grant_frames(d->grant_table))
    1.13 -                mfn = virt_to_mfn(d->grant_table->shared) + xatp.idx;
    1.14 +                mfn = virt_to_mfn(d->grant_table->shared[xatp.idx]);
    1.15 +
    1.16              spin_unlock(&d->grant_table->lock);
    1.17              break;
    1.18          default:
    1.19              break;
    1.20          }
    1.21  
    1.22 +        if (mfn == 0) {
    1.23 +            put_domain(d);
    1.24 +            return -EINVAL;
    1.25 +        }
    1.26 +
    1.27          LOCK_BIGLOCK(d);
    1.28  
    1.29 +        /* Check remapping necessity */
    1.30 +        prev_mfn = gmfn_to_mfn(d, xatp.gpfn);
    1.31 +        if (mfn == prev_mfn)
    1.32 +            goto out;
    1.33 +
    1.34          /* Remove previously mapped page if it was present. */
    1.35 -        prev_mfn = gmfn_to_mfn(d, xatp.gpfn);
    1.36          if (prev_mfn && mfn_valid(prev_mfn)) {
    1.37              if (IS_XEN_HEAP_FRAME(mfn_to_page(prev_mfn)))
    1.38                  /* Xen heap frames are simply unhooked from this phys slot. */
    1.39 @@ -2113,12 +2128,31 @@ arch_memory_op(int op, XEN_GUEST_HANDLE(
    1.40  
    1.41          /* Unmap from old location, if any. */
    1.42          gpfn = get_gpfn_from_mfn(mfn);
    1.43 -        if (gpfn != INVALID_M2P_ENTRY)
    1.44 +        if (gpfn != INVALID_M2P_ENTRY) {
    1.45 +            /*
    1.46 +             * guest_physmap_remove_page() (for IPF) descrements page
    1.47 +             * counter and unset PGC_allocated flag,
    1.48 +             * so pre-increment page counter and post-set flag inserted
    1.49 +             */
    1.50 +            /* pre-increment page counter */
    1.51 +            if (!get_page(mfn_to_page(mfn), d))
    1.52 +                goto out;
    1.53 +
    1.54              guest_physmap_remove_page(d, gpfn, mfn);
    1.55  
    1.56 +            /* post-set PGC_allocated flag */
    1.57 +            if ((mfn_to_page(mfn)->count_info & PGC_count_mask) != 1) {
    1.58 +                /* no one but us is using this page */
    1.59 +                put_page(mfn_to_page(mfn));
    1.60 +                goto out;
    1.61 +            }
    1.62 +            set_bit(_PGC_allocated, &mfn_to_page(mfn)->count_info);
    1.63 +        }
    1.64 +
    1.65          /* Map at new location. */
    1.66          guest_physmap_add_page(d, xatp.gpfn, mfn);
    1.67  
    1.68 +    out:
    1.69          UNLOCK_BIGLOCK(d);
    1.70          
    1.71          put_domain(d);