ia64/xen-unstable

changeset 11866:22885e4c1275

[XEN] Don't kill shadowed guest for writing bogus PTEs.

If a guest writes a "bad" pagetable entry and we fail to unshadow the
page, don't kill the guest. This makes the behaviour the same as
if the bad PTE were already in place when we shadowed the page.

Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Tue Oct 17 11:07:11 2006 +0100 (2006-10-17)
parents 3cc0b589c235
children 37ee88ca1440
files xen/arch/x86/mm/shadow/common.c xen/arch/x86/mm/shadow/multi.c xen/include/asm-x86/shadow.h
line diff
     1.1 --- a/xen/arch/x86/mm/shadow/common.c	Tue Oct 17 09:59:11 2006 +0100
     1.2 +++ b/xen/arch/x86/mm/shadow/common.c	Tue Oct 17 11:07:11 2006 +0100
     1.3 @@ -343,8 +343,11 @@ shadow_validate_guest_pt_write(struct vc
     1.4      if ( rc & SHADOW_SET_ERROR ) 
     1.5      {
     1.6          /* This page is probably not a pagetable any more: tear it out of the 
     1.7 -         * shadows, along with any tables that reference it */
     1.8 -        shadow_remove_all_shadows_and_parents(v, gmfn);
     1.9 +         * shadows, along with any tables that reference it.  
    1.10 +         * Since the validate call above will have made a "safe" (i.e. zero) 
    1.11 +         * shadow entry, we can let the domain live even if we can't fully 
    1.12 +         * unshadow the page. */
    1.13 +        sh_remove_shadows(v, gmfn, 0, 0);
    1.14      }
    1.15  }
    1.16  
    1.17 @@ -2058,17 +2061,20 @@ static int sh_remove_shadow_via_pointer(
    1.18      return rc;
    1.19  }
    1.20  
    1.21 -void sh_remove_shadows(struct vcpu *v, mfn_t gmfn, int all)
    1.22 +void sh_remove_shadows(struct vcpu *v, mfn_t gmfn, int fast, int all)
    1.23  /* Remove the shadows of this guest page.  
    1.24 - * If all != 0, find all shadows, if necessary by walking the tables.
    1.25 - * Otherwise, just try the (much faster) heuristics, which will remove 
    1.26 - * at most one reference to each shadow of the page. */
    1.27 + * If fast != 0, just try the quick heuristic, which will remove 
    1.28 + * at most one reference to each shadow of the page.  Otherwise, walk
    1.29 + * all the shadow tables looking for refs to shadows of this gmfn.
    1.30 + * If all != 0, kill the domain if we can't find all the shadows.
    1.31 + * (all != 0 implies fast == 0)
    1.32 + */
    1.33  {
    1.34      struct page_info *pg;
    1.35      mfn_t smfn;
    1.36      u32 sh_flags;
    1.37      unsigned char t;
    1.38 -
    1.39 +    
    1.40      /* Dispatch table for getting per-type functions: each level must
    1.41       * be called with the function to remove a lower-level shadow. */
    1.42      static hash_callback_t callbacks[16] = {
    1.43 @@ -2128,6 +2134,7 @@ void sh_remove_shadows(struct vcpu *v, m
    1.44      };
    1.45  
    1.46      ASSERT(shadow_lock_is_acquired(v->domain));
    1.47 +    ASSERT(!(all && fast));
    1.48  
    1.49      pg = mfn_to_page(gmfn);
    1.50  
    1.51 @@ -2147,20 +2154,20 @@ void sh_remove_shadows(struct vcpu *v, m
    1.52       * call will remove at most one shadow, and terminate immediately when
    1.53       * it does remove it, so we never walk the hash after doing a deletion.  */
    1.54  #define DO_UNSHADOW(_type) do {                                 \
    1.55 -    t = (_type) >> PGC_SH_type_shift;                          \
    1.56 -    smfn = shadow_hash_lookup(v, mfn_x(gmfn), t);              \
    1.57 -    if ( !sh_remove_shadow_via_pointer(v, smfn) && all )       \
    1.58 +    t = (_type) >> PGC_SH_type_shift;                           \
    1.59 +    smfn = shadow_hash_lookup(v, mfn_x(gmfn), t);               \
    1.60 +    if ( !sh_remove_shadow_via_pointer(v, smfn) && !fast )      \
    1.61          hash_foreach(v, masks[t], callbacks, smfn);             \
    1.62  } while (0)
    1.63  
    1.64      /* Top-level shadows need to be unpinned */
    1.65 -#define DO_UNPIN(_type) do {                                             \
    1.66 +#define DO_UNPIN(_type) do {                                            \
    1.67      t = (_type) >> PGC_SH_type_shift;                                   \
    1.68      smfn = shadow_hash_lookup(v, mfn_x(gmfn), t);                       \
    1.69      if ( mfn_to_page(smfn)->count_info & PGC_SH_pinned )                \
    1.70          sh_unpin(v, smfn);                                              \
    1.71      if ( (_type) == PGC_SH_l3_pae_shadow )                              \
    1.72 -        SHADOW_INTERNAL_NAME(sh_unpin_all_l3_subshadows,3,3)(v, smfn); \
    1.73 +        SHADOW_INTERNAL_NAME(sh_unpin_all_l3_subshadows,3,3)(v, smfn);  \
    1.74  } while (0)
    1.75  
    1.76      if ( sh_flags & SHF_L1_32 )   DO_UNSHADOW(PGC_SH_l1_32_shadow);
    1.77 @@ -2190,11 +2197,13 @@ void sh_remove_shadows(struct vcpu *v, m
    1.78  #endif
    1.79  
    1.80      /* If that didn't catch the shadows, something is wrong */
    1.81 -    if ( all && (pg->count_info & PGC_page_table) )
    1.82 +    if ( !fast && (pg->count_info & PGC_page_table) )
    1.83      {
    1.84 -        SHADOW_ERROR("can't find all shadows of mfn %05lx (shadow_flags=%08x)\n",
    1.85 +        SHADOW_ERROR("can't find all shadows of mfn %05lx "
    1.86 +                     "(shadow_flags=%08x)\n",
    1.87                        mfn_x(gmfn), pg->shadow_flags);
    1.88 -        domain_crash(v->domain);
    1.89 +        if ( all ) 
    1.90 +            domain_crash(v->domain);
    1.91      }
    1.92  }
    1.93  
     2.1 --- a/xen/arch/x86/mm/shadow/multi.c	Tue Oct 17 09:59:11 2006 +0100
     2.2 +++ b/xen/arch/x86/mm/shadow/multi.c	Tue Oct 17 11:07:11 2006 +0100
     2.3 @@ -2825,7 +2825,7 @@ static inline void check_for_early_unsha
     2.4          if ( !(flags & (SHF_L2_32|SHF_L3_PAE|SHF_L4_64)) )
     2.5          {
     2.6              perfc_incrc(shadow_early_unshadow);
     2.7 -            sh_remove_shadows(v, gmfn, 0 /* Can fail to unshadow */ );
     2.8 +            sh_remove_shadows(v, gmfn, 1, 0 /* Fast, can fail to unshadow */ );
     2.9              return;
    2.10          }
    2.11          /* SHF_unhooked_mappings is set to make sure we only unhook
     3.1 --- a/xen/include/asm-x86/shadow.h	Tue Oct 17 09:59:11 2006 +0100
     3.2 +++ b/xen/include/asm-x86/shadow.h	Tue Oct 17 11:07:11 2006 +0100
     3.3 @@ -549,13 +549,13 @@ shadow_remove_all_shadows_and_parents(st
     3.4   * Unshadow it, and recursively unshadow pages that reference it. */
     3.5  
     3.6  /* Remove all shadows of the guest mfn. */
     3.7 -extern void sh_remove_shadows(struct vcpu *v, mfn_t gmfn, int all);
     3.8 +extern void sh_remove_shadows(struct vcpu *v, mfn_t gmfn, int fast, int all);
     3.9  static inline void shadow_remove_all_shadows(struct vcpu *v, mfn_t gmfn)
    3.10  {
    3.11      int was_locked = shadow_lock_is_acquired(v->domain);
    3.12      if ( !was_locked )
    3.13          shadow_lock(v->domain);
    3.14 -    sh_remove_shadows(v, gmfn, 1);
    3.15 +    sh_remove_shadows(v, gmfn, 0, 1);
    3.16      if ( !was_locked )
    3.17          shadow_unlock(v->domain);
    3.18  }